Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[CPU] Optimize tail 'Convert' nodes time cost in f16 precision mark-up transformation (#30935)

Bo Liu571eadd63818
diff --git a/src/plugins/intel_cpu/src/graph.cpp b/src/plugins/intel_cpu/src/graph.cpp
index c6401428f8e..35766beb66f 100644
--- a/src/plugins/intel_cpu/src/graph.cpp
+++ b/src/plugins/intel_cpu/src/graph.cpp
@@ -1989,14 +1989,10 @@ void Graph::EnforceInferencePrecision() {
CPU_DEBUG_CAP_ENABLE(EnforceInferPrcDebug inferPrecDebug);
const auto inferPrec = getConfig().inferencePrecision;
- if (any_of(inferPrec, element::f32, element::dynamic, ov::element::f16, element::dynamic)) {
+ if (any_of(inferPrec, element::f32, element::f16, element::dynamic)) {
return; // nothing to do, only precision reduction is currently allowed
}
-#if defined(OPENVINO_ARCH_ARM) || defined(OPENVINO_ARCH_ARM64)
- if (inferPrec == ov::element::f16) {
- return; // precision of configured by ov::pass::ConvertPrecision
- }
-#endif
+
std::function<void(const NodePtr&, std::unordered_set<NodePtr>& skipNodes)> searchForNodesToSkip;
searchForNodesToSkip = [&](const NodePtr& node, std::unordered_set<NodePtr>& skipNodes) -> void {
for (size_t i = 0; i < node->getParentEdges().size(); i++) {
@@ -2017,18 +2013,6 @@ void Graph::EnforceInferencePrecision() {
Type::LLMMLP)) {
continue; // stop at significant nodes
}
- } else if (inferPrec == ov::element::f16) {
- /* list of node types that must be forced to be executed in FP16 precision
- * because of performance gains */
- if (any_of(parent->getType(),
- Type::Convolution, // conv nets
- Type::Deconvolution, // deconv
- Type::FullyConnected, // conv / bert nets
- Type::MatMul, // bert nets
- Type::Pooling,
- Type::MVN)) {
- continue; // stop at significant nodes
- }
}
const auto res = skipNodes.insert(parent);
diff --git a/src/plugins/intel_cpu/src/graph.h b/src/plugins/intel_cpu/src/graph.h
index 8ab085b0547..31157e0599a 100644
--- a/src/plugins/intel_cpu/src/graph.h
+++ b/src/plugins/intel_cpu/src/graph.h
@@ -286,6 +286,8 @@ public:
return m_outputNodesMemBlocks;
}
+ friend class GraphOptimizer;
+
protected:
void ForgetGraphData() {
status = Status::NotReady;
diff --git a/src/plugins/intel_cpu/src/graph_optimizer.cpp b/src/plugins/intel_cpu/src/graph_optimizer.cpp
index e7f843e105a..8798fced88c 100644
--- a/src/plugins/intel_cpu/src/graph_optimizer.cpp
+++ b/src/plugins/intel_cpu/src/graph_optimizer.cpp
@@ -19,6 +19,8 @@
#include <set>
#include <string>
#include <tuple>
+#include <unordered_map>
+#include <unordered_set>
#include <utility>
#include <vector>
@@ -31,6 +33,7 @@
#include "node.h"
#include "nodes/bin_conv.h"
#include "nodes/common/cpu_convert.h"
+#include "nodes/concat.h"
#include "nodes/conv.h"
#include "nodes/deconv.h"
#include "nodes/eltwise.h"
@@ -227,6 +230,9 @@ void GraphOptimizer::ApplyCommonGraphOptimizations(Graph& graph) {
void GraphOptimizer::ApplyImplSpecificGraphOptimizations(Graph& graph) {
OV_ITT_SCOPE(FIRST_INFERENCE, itt::domains::intel_cpu_LT, "GraphOptimizer::ApplyImplSpecificGraphOptimizations");
+ TailNodesPrecisionOptimize(graph);
+ graph.RemoveDroppedNodes();
+
DropDoubleReorders(graph);
graph.RemoveDroppedNodes();
@@ -3386,6 +3392,251 @@ void GraphOptimizer::DropRedundantMemoryOutput(Graph& graph) {
}
}
+void GraphOptimizer::TailNodesPrecisionOptimize(Graph& graph) {
+ const auto inferPrec = graph.getConfig().inferencePrecision;
+ if (inferPrec != ov::element::f16) {
+ return;
+ }
+#if defined(OPENVINO_ARCH_ARM) || defined(OPENVINO_ARCH_ARM64)
+ return; // precision of configured by ov::pass::ConvertPrecision
+#endif
+ const std::vector<NodePtr> outputNodes = [&] {
+ std::vector<NodePtr> nodes;
+ for (size_t i = 0; i < graph.outputsNumber(); ++i) {
+ auto node = graph.getOutputNodeByIndex(i);
+ if (node) {
+ nodes.push_back(node);
+ }
+ }
+ return nodes;
+ }();
+
+ std::function<void(const NodePtr&, std::unordered_map<NodePtr, bool>&)> searchForTailNodes;
+ searchForTailNodes = [&](const NodePtr& node, std::unordered_map<NodePtr, bool>& tailNodes) -> void {
+ for (size_t i = 0; i < node->getParentEdges().size(); i++) {
+ const auto& parent = node->getParentEdgeAt(i)->getParent();
+ if (any_of(parent->getType(),
+ Type::Convolution,
+ Type::FullyConnected,
+ Type::RNNCell,
+ Type::RNNSeq,
+ Type::MatMul,
+ Type::ROIPooling,
+ Type::Interpolate,
+ Type::PagedAttention,
+ Type::QKVProjection,
+ Type::LLMMLP,
+ Type::Pooling)) {
+ continue;
+ }
+ const auto res = tailNodes.insert({parent, false});
+ if (res.second) {
+ searchForTailNodes(parent, tailNodes);
+ }
+ }
+ };
+
+ std::unordered_map<NodePtr, bool> tailNodesMap;
+ std::unordered_set<ov::element::Type_t> outputPrecisions;
+ for (const auto& output : outputNodes) {
+ if (output->getOriginalInputPrecisionAtPort(0) == inferPrec) {
+ continue;
+ }
+ outputPrecisions.insert(output->getOriginalInputPrecisionAtPort(0));
+ searchForTailNodes(output, tailNodesMap);
+ }
+ if (outputPrecisions.empty()) {
+ return;
+ }
+
+ // Nodes that support output precision fusion, reducing internal node computation to original output precision (can
+ // be extended)
+ auto supportFuseConvert = [](Type type) {
+ return ov::intel_cpu::any_of(type, Type::Eltwise, Type::MVN);
+ };
+ // nodes which support in-place execution (can be extended)
+ auto supportInPlace = [](Type type) {
+ return ov::intel_cpu::any_of(type, Type::Reshape, Type::Concatenation, Type::Split);
+ };
+
+ auto isParentSuitableForTailOpt = [&](const NodePtr& parent) -> bool {
+ if (!parent) {
+ return false;
+ }
+ if (supportFuseConvert(parent->getType()) && tailNodesMap.count(parent) != 0U) {
+ return true;
+ }
+ if (supportInPlace(parent->getType()) && tailNodesMap.count(parent) != 0U) {
+ return parent->isInPlace();
+ }
+ return false;
+ };
+
+ std::function<bool(const NodePtr&)> suitableForTailOptimization;
+ suitableForTailOptimization = [&](const NodePtr& node) -> bool {
+ std::unordered_set<NodePtr> visited;
+ const NodePtr& cur = node;
+ while (cur) {
+ if (!visited.insert(cur).second) {
+ break;
+ }
+ size_t parentNum = cur->getParentEdges().size();
+ if (parentNum == 0) {
+ return false;
+ }
+ for (size_t i = 0; i < parentNum; ++i) {
+ auto parent = cur->getParentEdgeAt(i)->getParent();
+ if (!isParentSuitableForTailOpt(parent)) {
+ return false;
+ }
+ if (supportInPlace(parent->getType()) && tailNodesMap.count(parent) != 0U) {
+ if (!suitableForTailOptimization(parent)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ return false;
+ };
+
+ std::function<void(const NodePtr&, const ov::element::Type_t&)> resetTailPrecision;
+ resetTailPrecision = [&](const NodePtr& node, const ov::element::Type_t& outputPrecision) -> void {
+ for (size_t i = 0; i < node->getParentEdges().size(); ++i) {
+ auto parent = node->getParentEdgeAt(i)->getParent();
+ if (!parent) {
+ continue;
+ }
+ OPENVINO_ASSERT(tailNodesMap.count(parent),
+ "resetTailPrecision: node ",
+ parent->getName(),
+ " with type ",
+ NameFromType(parent->getType()),
+ " is not in suitableForTailOptimization set");
+ if (tailNodesMap[parent]) {
+ continue;
+ }
+ tailNodesMap[parent] = true;
+ if (supportFuseConvert(parent->getType())) {
+ for (size_t j = 0; j < parent->getOriginalOutputsNumber(); ++j) {
+ parent->setOriginalOutputPrecisionAtPort(j, outputPrecision);
+ }
+ } else {
+ for (size_t j = 0; j < parent->getOriginalInputsNumber(); ++j) {
+ parent->setOriginalInputPrecisionAtPort(j, outputPrecision);
+ }
+ for (size_t j = 0; j < parent->getOriginalOutputsNumber(); ++j) {
+ parent->setOriginalOutputPrecisionAtPort(j, outputPrecision);
+ }
+ resetTailPrecision(parent, outputPrecision);
+ }
+ }
+ };
+ std::vector<NodePtr> optimizedNodes;
+ std::vector<NodePtr> concatConvertfusedNodes;
+
+ std::function<void(const NodePtr&)> tailNodesPrecisionOptimizeMain;
+ tailNodesPrecisionOptimizeMain = [&](const NodePtr& node) -> void {
+ for (size_t i = 0; i < node->getParentEdges().size(); i++) {
+ bool concatConvertfuse = false;
+ const auto& parent = node->getParentEdgeAt(i)->getParent();
+ if (!tailNodesMap.count(parent)) {
+ continue;
+ }
+ if (any_of(parent->getType(), Type::Input, Type::Output, Type::MemoryInput, Type::MemoryOutput)) {
+ continue;
+ }
+ if (parent->keepOrigPrecision()) {
+ continue;
+ }
+ if ((parent->getType() == Type::Convert) && (parent->getOriginalInputPrecisionAtPort(0) == inferPrec) &&
+ outputPrecisions.count(parent->getOriginalOutputPrecisionAtPort(0)) != 0U) {
+ bool suitableCase = false;
+ auto outprecision = parent->getOriginalOutputPrecisionAtPort(0);
+ NodePtr concatConvertfusedNode;
+ for (size_t i = 0; i < parent->getParentEdges().size(); ++i) {
+ auto p = parent->getParentEdgeAt(i)->getParent();
+ if (!p) {
+ continue;
+ }
+ if (supportInPlace(p->getType()) && tailNodesMap.count(parent) != 0U) {
+ if (!p->isInPlace()) {
+ // if FuseConvert method implement, we can fuse the following convert into this node
+ auto* concat = dynamic_cast<node::Concat*>(p.get());
+ if (concat && (outprecision == ov::element::f32) && concat->supportConvertFusion()) {
+ concatConvertfuse = true;
+ concatConvertfusedNode = p;
+ }
+ suitableCase = false;
+ break;
+ }
+ if (suitableForTailOptimization(p)) {
+ suitableCase = true;
+ continue;
+ }
+ } else if (supportFuseConvert(p->getType())) {
+ suitableCase = true;
+ continue;
+ }
+ }
+ if (concatConvertfuse) {
+ for (size_t j = 0; j < concatConvertfusedNode->getOriginalOutputsNumber(); ++j) {
+ concatConvertfusedNode->setOriginalOutputPrecisionAtPort(j, outprecision);
+ }
+ concatConvertfusedNodes.push_back(concatConvertfusedNode);
+ graph.DropNode(parent);
+ }
+ if (suitableCase) {
+ resetTailPrecision(parent, outprecision);
+ graph.DropNode(parent);
+ }
+ continue;
+ }
+ tailNodesPrecisionOptimizeMain(parent);
+ }
+ };
+
+ for (const auto& output : outputNodes) {
+ if (output->getOriginalInputPrecisionAtPort(0) == inferPrec) {
+ continue;
+ }
+ tailNodesPrecisionOptimizeMain(output);
+ }
+
+ for (const auto& [node, optimized] : tailNodesMap) {
+ if (optimized) {
+ optimizedNodes.push_back(node);
+ }
+ }
+
+ optimizedNodes.insert(optimizedNodes.end(), concatConvertfusedNodes.begin(), concatConvertfusedNodes.end());
+
+ for (auto& node : optimizedNodes) {
+ node->init();
+ }
+ for (auto& node : optimizedNodes) {
+ node->getSupportedDescriptors();
+ // Clear existing primitive descriptors to reinitialize them
+ node->supportedPrimitiveDescriptors.clear();
+ node->initSupportedPrimitiveDescriptors();
+ node->filterSupportedPrimitiveDescriptors();
+ }
+ for (auto& node : optimizedNodes) {
+ node->selectOptimalPrimitiveDescriptor();
+ }
+ for (auto& node : optimizedNodes) {
+ node->resolveInPlaceDirection();
+ }
+ for (auto& node : optimizedNodes) {
+ node->initOptimalPrimitiveDescriptor();
+ }
+ // Only resolve edge conflicts if nodes were actually optimized
+ // to avoid unnecessary overhead when no tail nodes precision changes occurred
+ if (!optimizedNodes.empty()) {
+ graph.ResolveEdgeConflicts();
+ }
+}
+
} // namespace ov::intel_cpu
// NOLINTEND(modernize-loop-convert)
diff --git a/src/plugins/intel_cpu/src/graph_optimizer.h b/src/plugins/intel_cpu/src/graph_optimizer.h
index 408cab96335..07aa76b2b94 100644
--- a/src/plugins/intel_cpu/src/graph_optimizer.h
+++ b/src/plugins/intel_cpu/src/graph_optimizer.h
@@ -92,6 +92,24 @@ private:
const NodePtr& reshapeNode,
const NodePtr& reorderNode,
bool reverseOrder);
+ // Method optimizes tail nodes inference performance under FP16 inference precision through two main approaches:
+ // 1. Inplace Tail Nodes Optimization:
+ // For inplace tail node scenarios (including Eltwise and Concat nodes), the model output type is fused into
+ // the nearest tail node, ensuring all tail nodes in the path maintain consistent types with the model output.
+ // Since inplace nodes don't perform actual data movement, this type alignment doesn't introduce additional
+ // overhead while eliminating the convert node as well as the f32->f16 instruction overhead within the tail
+ // nodes.
+ // 2. Non-inplace Tail Nodes Fusion:
+ // For non-inplace tail node scenarios, Convert operations are fused into its input (data movement) nodes.
+ // Currently implemented Concat fusion kernel support, with future extensibility to other node types.
+ // Examples:
+ // 1. Inplace optimization (Concat):
+ // Before: Eltwise(f16,f16)->Concat(f16,f16)->Convert(f16->f32)->Output(f32) (when concat is inplace)
+ // After: Eltwise(f16,f32)->Concat(f32,f32)->Output(f32) (Convert node eliminated, Concat directly outputs f32)
+ // 2. Non-inplace fusion (Concat):
+ // Before: Concat(f16,f16)->Convert(f16->f32)->Output(f32) (when concat is non-inplace)
+ // After: ConcatWithFuseConvert(f16,f32)->Output(f32) (Convert fused into Concat)
+ static void TailNodesPrecisionOptimize(Graph& graph);
};
} // namespace ov::intel_cpu
diff --git a/src/plugins/intel_cpu/src/nodes/concat.cpp b/src/plugins/intel_cpu/src/nodes/concat.cpp
index 735ab3514d9..4c2b6320a01 100644
--- a/src/plugins/intel_cpu/src/nodes/concat.cpp
+++ b/src/plugins/intel_cpu/src/nodes/concat.cpp
@@ -27,6 +27,7 @@
#include <vector>
#include "common/blocked_desc_creator.h"
+#include "common/cpu_convert.h"
#include "common/cpu_memcpy.h"
#include "cpu_types.h"
#include "dnnl_extension_utils.h"
@@ -40,6 +41,7 @@
#include "openvino/core/parallel.hpp"
#include "openvino/core/type.hpp"
#include "openvino/core/type/element_type.hpp"
+#include "openvino/core/type/float16.hpp"
#include "openvino/op/concat.hpp"
#include "shape_inference/shape_inference_cpu.hpp"
#include "utils/debug_capabilities.h"
@@ -127,7 +129,17 @@ void Concat::initSupportedPrimitiveDescriptors() {
}
const auto& originInputPrecisions = getOriginalInputPrecisions();
+ const auto& originOutputPrecision = getOriginalOutputPrecisionAtPort(0);
inputPrecision = originInputPrecisions[0];
+
+ // Check if all inputs are FP16 and output is FP32
+ bool allInputsFP16 =
+ std::all_of(originInputPrecisions.begin(), originInputPrecisions.end(), [](const ov::element::Type& type) {
+ return type == ov::element::f16;
+ });
+ bool outputFP32 = (originOutputPrecision == ov::element::f32);
+ doFuseConvert = allInputsFP16 && outputFP32;
+
bool isMixedPrecision = false;
for (size_t i = 1; i < inputShapes.size(); i++) {
if (originInputPrecisions[0] != originInputPrecisions[i]) {
@@ -136,13 +148,20 @@ void Concat::initSupportedPrimitiveDescriptors() {
}
}
+ // Handle type conversion case: FP16 inputs -> FP32 output
+ if (doFuseConvert && supportFuseConvert) {
+ inputPrecision = ov::element::f16;
+ outputPrecision = ov::element::f32;
+ }
// Concat doesn't support different precision on inputs so fallback on FP32 in such case
- if (isMixedPrecision) {
+ else if (isMixedPrecision) {
inputPrecision = ov::element::f32;
+ outputPrecision = inputPrecision;
+ }
+ // Normal case: Concat supports only equal precisions for inputs and output
+ else {
+ outputPrecision = inputPrecision;
}
-
- // Concat supports only equal precisions for inputs and output
- outputPrecision = inputPrecision;
const auto& dstShape = getOutputShapeAtPort(0);
std::vector<LayoutType> tdCreatorTypes = {LayoutType::ncsp, LayoutType::nspc};
@@ -377,7 +396,9 @@ void Concat::prepareParams() {
const auto& outputStrides = dstMemDesc->getStrides();
size_t curConcatOffset = 0;
- const size_t elemSize = DnnlExtensionUtils::sizeOfDataType(dstMemPtr->getDataType());
+ const size_t elemSize_in = DnnlExtensionUtils::sizeOfDataType(getSrcMemoryAtPort(0)->getDataType());
+ const size_t elemSize_out = DnnlExtensionUtils::sizeOfDataType(dstMemPtr->getDataType());
+
const auto& src0BlkMemDesc = getSrcMemoryAtPort(0)->getDescPtr()->as<BlockedMemoryDesc>();
const auto& outputOrder = src0BlkMemDesc->getOrder();
for (size_t i = 0; i < outputOrder.size(); i++) {
@@ -394,7 +415,7 @@ void Concat::prepareParams() {
}
canOptimize1DCase = false;
- if (outputShape.size() == 1 && outputStrides[0] == 1 && outputShape[0] <= 64 && elemSize == 4) {
+ if (outputShape.size() == 1 && outputStrides[0] == 1 && outputShape[0] <= 64 && elemSize_out == 4) {
// output is small 1d vector (which is typical in shape inference subgraph),
// in this case, inputs are also small 1d vector and single thread naive impl is faster
canOptimize1DCase = true;
@@ -427,15 +448,15 @@ void Concat::prepareParams() {
const auto& inputShape = srcMemDesc->getBlockDims();
const auto& strides = srcMemDesc->getStrides();
inputStrides[i].resize(MAX_RANK_REF, 0);
- std::transform(strides.begin(), strides.end(), inputStrides[i].begin(), [&elemSize](const Dim& i) {
- return i * elemSize;
+ std::transform(strides.begin(), strides.end(), inputStrides[i].begin(), [&elemSize_in](const Dim& i) {
+ return i * elemSize_in;
});
size_t nElem = 1;
for (size_t j = reorderedAxis; j < inputShape.size(); j++) {
nElem *= inputShape[j];
}
- nelemToCopy[i] = nElem * elemSize;
- dstOffset[i] = outputStrides[reorderedAxis] * curConcatOffset * elemSize;
+ nelemToCopy[i] = nElem * elemSize_in;
+ dstOffset[i] = outputStrides[reorderedAxis] * curConcatOffset * elemSize_out;
curConcatOffset += inputShape[reorderedAxis];
nelemTotal += nelemToCopy[i];
} else {
@@ -515,6 +536,16 @@ void Concat::initOptimalPrimitiveDescriptor() {
dstOffset.resize(getParentEdges().size());
inputStrides.resize(getParentEdges().size());
srcPtrs.resize(getParentEdges().size());
+ } else if (doFuseConvert) {
+ supportFuseConvert = false;
+ doFuseConvert = false;
+ auto config = selected_pd->getConfig();
+ // if !canExecRef, disable fuse convert
+ for (size_t i = 0; i < config.outConfs.size(); i++) {
+ config.outConfs[i].setMemDesc(
+ getConsistentOutputDesc(config, i)->getMemDesc()->cloneWithNewPrecision(inputPrecision));
+ }
+ initDescriptor(config);
}
// check if selected Tensor descriptor has nspc layout and concat axis is C
canOptimizeNspc =
@@ -624,6 +655,11 @@ void Concat::execRef() {
srcPtrs[i] = srcMem.getDataAs<const uint8_t>();
}
+ // Handle FP16 to FP32 type conversion case
+ if (doFuseConvert) {
+ execWithFuseConvert();
+ return;
+ }
if (!hasOuterLoop) {
if (nelemTotal < 64 * 1024 || parallel_get_max_threads() == 1) {
for (size_t a = 0; a < srcPtrs.size(); ++a) {
@@ -721,6 +757,100 @@ void Concat::execRef() {
}
}
+void Concat::execWithFuseConvert() {
+ const size_t numSrc = getParentEdges().size();
+ const auto& dstMemory = getChildEdgeAt(0)->getMemory();
+ auto* dstPtr = dstMemory.getDataAs<float>(); // Output is FP32
+
+ for (size_t i = 0; i < numSrc; i++) {
+ const auto& srcMem = getParentEdgeAt(i)->getMemory();
+ srcPtrs[i] = srcMem.getDataAs<const uint8_t>();
+ }
+
+ if (!hasOuterLoop) {
+ if (nelemTotal < 64 * 1024 || parallel_get_max_threads() == 1) {
+ for (size_t a = 0; a < srcPtrs.size(); ++a) {
+ if (srcPtrs[a] == nullptr) {
+ continue;
+ }
+
+ const auto* inputDataFP16 = reinterpret_cast<const ov::float16*>(srcPtrs[a]);
+ auto* outputDataFP32 = reinterpret_cast<float*>(&reinterpret_cast<uint8_t*>(dstPtr)[dstOffset[a]]);
+
+ size_t numElementsFP16 = nelemToCopy[a] / sizeof(ov::float16);
+
+ cpu_convert(inputDataFP16, outputDataFP32, ov::element::f16, ov::element::f32, numElementsFP16);
+ }
+ } else {
+ // Multi-threaded execution
+ int nthr = parallel_get_max_threads();
+ parallel_nt(nthr, [&](int ithr, int nthr) {
+ for (size_t a = 0; a < srcPtrs.size(); ++a) {
+ if (srcPtrs[a] == nullptr) {
+ continue; // Skip zero memory
+ }
+
+ size_t numElementsFP16 = nelemToCopy[a] / sizeof(ov::float16);
+ size_t start = 0;
+ size_t end = 0;
+ splitter(numElementsFP16, nthr, ithr, start, end);
+
+ const auto* inputDataFP16 = reinterpret_cast<const ov::float16*>(srcPtrs[a]) + start;
+ auto* outputDataFP32 =
+ reinterpret_cast<float*>(&reinterpret_cast<uint8_t*>(dstPtr)[dstOffset[a]]) + start;
+
+ cpu_convert(inputDataFP16, outputDataFP32, ov::element::f16, ov::element::f32, end - start);
+ }
+ });
+ }
+ } else {
+ // Complex case: multi-dimensional concatenation with type conversion
+ const size_t elemSize = DnnlExtensionUtils::sizeOfDataType(dstMemory.getDataType());
+ auto* const dstMemBlkDesc = dstMemory.getDescPtr()->as<BlockedMemoryDesc>();
+ const auto& outputShape = dstMemBlkDesc->getBlockDims();
+
+ // Calculate output strides in bytes (already calculated in prepareParams based on FP32)
+ size_t outputStrides[MAX_RANK_REF] = {0};
+ const auto strides = dstMemBlkDesc->getStrides();
+ std::transform(strides.begin(), strides.end(), outputStrides, [&elemSize](const Dim& i) {
+ return i * elemSize;
+ });
+
+ size_t physDims[5] = {1, 1, 1, 1, 1};
+ for (size_t i = 0; i < reorderedAxis; i++) {
+ physDims[i] = outputShape[i];
+ }
+
+ parallel_for6d(
+ physDims[0],
+ physDims[1],
+ physDims[2],
+ physDims[3],
+ physDims[4],
+ numSrc,
+ [&](size_t n0, size_t n1, size_t n2, size_t n3, size_t n4, size_t a) {
+ // check if zero memory
+ if (srcPtrs[a] == nullptr) {
+ return;
+ }
+
+ size_t inOff = inputStrides[a][0] * n0 + inputStrides[a][1] * n1 + inputStrides[a][2] * n2 +
+ inputStrides[a][3] * n3 + inputStrides[a][4] * n4;
+ size_t outOff = outputStrides[0] * n0 + outputStrides[1] * n1 + outputStrides[2] * n2 +
+ outputStrides[3] * n3 + outputStrides[4] * n4;
+
+ const auto* inputDataFP16 = reinterpret_cast<const ov::float16*>(&srcPtrs[a][inOff]);
+ auto* outputDataFP32 =
+ reinterpret_cast<float*>(&reinterpret_cast<uint8_t*>(dstPtr)[dstOffset[a] + outOff]);
+
+ // Convert number of bytes to number of elements for this slice
+ size_t numElementsFP16 = nelemToCopy[a] / sizeof(ov::float16);
+
+ cpu_convert(inputDataFP16, outputDataFP32, ov::element::f16, ov::element::f32, numElementsFP16);
+ });
+ }
+}
+
void Concat::resolveInPlaceEdges(Edge::LOOK look) {
if (!(look & Edge::LOOK_DOWN) || !isInPlace()) {
Node::resolveInPlaceEdges(look);
diff --git a/src/plugins/intel_cpu/src/nodes/concat.h b/src/plugins/intel_cpu/src/nodes/concat.h
index 32a81c21470..819c740080e 100644
--- a/src/plugins/intel_cpu/src/nodes/concat.h
+++ b/src/plugins/intel_cpu/src/nodes/concat.h
@@ -41,6 +41,10 @@ public:
[[nodiscard]] bool isExecutable() const override;
[[nodiscard]] bool needPrepareParams() const override;
void prepareParams() override;
+ // TODO: Move to base Node class when more nodes support fuse convert
+ bool supportConvertFusion() const {
+ return supportFuseConvert;
+ }
private:
size_t axis = 0;
@@ -49,6 +53,7 @@ private:
bool canOptimizeNspc = false;
bool canOptimize1DCase = false;
void execRef();
+ void execWithFuseConvert(); // Handle FP16 to FP32 conversion
static size_t inverseOrder(const VectorDims& order, size_t axis);
void execNspcSpecCase();
void exec1DCase();
@@ -61,6 +66,8 @@ private:
ov::element::Type inputPrecision = ov::element::f32;
ov::element::Type outputPrecision = ov::element::f32;
bool canExecRef = false;
+ bool supportFuseConvert = true; // support FP16 to FP32 conversion
+ bool doFuseConvert = false; // whether to perform FP16 to FP32 conversion
static constexpr size_t MAX_RANK_REF = 6;
dnnl::primitive prim;
};
diff --git a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/tail_optimization_concat_convert_fusion.cpp b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/tail_optimization_concat_convert_fusion.cpp
new file mode 100644
index 00000000000..f122b503e88
--- /dev/null
+++ b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/tail_optimization_concat_convert_fusion.cpp
@@ -0,0 +1,158 @@
+// Copyright (C) 2018-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "openvino/op/concat.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/convert.hpp"
+#include "openvino/op/convolution.hpp"
+#include "openvino/op/multiply.hpp"
+#include "openvino/op/parameter.hpp"
+#include "openvino/op/reshape.hpp"
+#include "openvino/op/result.hpp"
+#include "openvino/op/sigmoid.hpp"
+#include "shared_test_classes/base/ov_subgraph.hpp"
+#include "utils/cpu_test_utils.hpp"
+
+using namespace CPUTestUtils;
+
+namespace ov {
+namespace test {
+
+// Define test parameter structure
+struct ConcatTestParams {
+ std::vector<InputShape> inputShapes;
+ int concatAxis;
+ std::string testName;
+ std::vector<int> reshapePattern;
+ std::vector<int> mulConstShape;
+};
+
+using TailOptimizationConcatConvertFusionTestParams = ConcatTestParams;
+
+class TailOptimizationConcatConvertFusionTest
+ : public testing::WithParamInterface<TailOptimizationConcatConvertFusionTestParams>,
+ virtual public SubgraphBaseTest {
+public:
+ static std::string getTestCaseName(testing::TestParamInfo<TailOptimizationConcatConvertFusionTestParams> obj) {
+ auto params = obj.param;
+ std::ostringstream result;
+ result << params.testName << "_";
+ result << "axis" << params.concatAxis << "_";
+ result << "IS=";
+ for (const auto& shape : params.inputShapes) {
+ result << ov::test::utils::partialShape2str({shape.first}) << "_";
+ }
+ return result.str();
+ }
+
+ void SetUp() override {
+ targetDevice = ov::test::utils::DEVICE_CPU;
+ configuration = {{ov::hint::inference_precision.name(), ov::element::f16}};
+
+ auto params = this->GetParam();
+ init_input_shapes(params.inputShapes);
+
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, inputDynamicShapes[0]);
+ ov::Shape weights_shape = {16, 16, 1, 1}; // OIHW for 1x1 conv
+
+ auto weights = ov::op::v0::Constant::create(ov::element::f16, weights_shape, {1.0f});
+ auto conv = std::make_shared<ov::op::v1::Convolution>(input,
+ weights,
+ ov::Strides{1, 1},
+ ov::CoordinateDiff{0, 0},
+ ov::CoordinateDiff{0, 0},
+ ov::Strides{1, 1});
+ conv->set_friendly_name("conv_node");
+
+ // Set reshape pattern according to parameters
+ auto pattern = ov::op::v0::Constant::create(ov::element::i64,
+ ov::Shape{params.reshapePattern.size()},
+ params.reshapePattern);
+ auto reshape = std::make_shared<ov::op::v1::Reshape>(conv, pattern, false);
+
+ // Set mul_const shape according to parameters
+ auto mul_const =
+ ov::op::v0::Constant::create(ov::element::f16,
+ ov::Shape(params.mulConstShape.begin(), params.mulConstShape.end()),
+ {2.0f});
+ auto mul = std::make_shared<ov::op::v1::Multiply>(reshape, mul_const);
+
+ auto sigmoid = std::make_shared<ov::op::v0::Sigmoid>(reshape);
+
+ // Use concat axis from parameters
+ auto concat = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{mul, sigmoid}, params.concatAxis);
+
+ auto convert_to_f32 = std::make_shared<ov::op::v0::Convert>(concat, ov::element::f32);
+
+ auto result = std::make_shared<ov::op::v0::Result>(convert_to_f32);
+
+ function = std::make_shared<ov::Model>(ov::ResultVector{result},
+ ov::ParameterVector{input},
+ "enforce_inference_precision_fp16_tail_" + params.testName);
+ }
+
+ void checkResults() {
+ for (const auto& node : compiledModel.get_runtime_model()->get_ops()) {
+ if (node->get_friendly_name() == "conv_node") {
+ ASSERT_EQ(node->get_output_element_type(0), ElementType::f16);
+ }
+ }
+ CheckNumberOfNodesWithType(compiledModel, "Convert", 0);
+ }
+};
+
+namespace {
+TEST_P(TailOptimizationConcatConvertFusionTest, CompareWithRefs) {
+ if (!ov::with_cpu_x86_avx512_core_amx_fp16())
+ GTEST_SKIP() << "Skipping test, only fp16 runtime inference precision platform needed" << std::endl;
+ run();
+ checkResults();
+}
+
+// Define test parameters
+const std::vector<ConcatTestParams> concatTestParams = {
+ // 1. InPlace case (concat axis=0, dimension 0 is static)
+ {
+ {{{16, 16, 16, -1}, {{16, 16, 16, 8}, {16, 16, 16, 12}}}},
+ 0, // concat axis=0, dimension 0 is static, triggers inplace
+ "InPlace",
+ {256, 16, -1}, // reshape pattern: [256, 16, W]
+ {256, 1, 1} // mul_const shape: [256, 1, 1]
+ },
+
+ // 2. Non-InPlace hasOuterLoop case
+ {
+ {{{16, 16, 16, -1}, {{16, 16, 16, 8}, {16, 16, 16, 12}}}},
+ 1, // concat axis=1, has outer dimension 0, so hasOuterLoop=true
+ "HasOuterLoop",
+ {16, 256, -1}, // reshape pattern: [16, 256, W]
+ {1, 256, 1} // mul_const shape: [1, 256, 1]
+ },
+
+ // 3. Non-InPlace !hasOuterLoop small data case (concat axis=0, dimension 0 is dynamic)
+ {
+ {{{-1, 16, 16, -1}, {{2, 16, 16, 2}, {2, 16, 16, 2}}}}, // dimension 0 is dynamic, small W value
+ 0, // concat axis=0, outermost dimension, but dimension 0 is dynamic, so non-inplace
+ "SmallData",
+ {-1, 256, 4}, // reshape pattern: [N, 256, 4]
+ {1, 256, 1} // mul_const shape: [1, 256, 1]
+ },
+
+ // 4. Non-InPlace !hasOuterLoop large data case (concat axis=0, dimension 0 is dynamic)
+ {
+ {{{-1, 16, 16, -1}, {{16, 16, 16, 64}, {16, 16, 16, 64}}}}, // dimension 0 is dynamic, large W value
+ 0, // concat axis=0, outermost dimension, but dimension 0 is dynamic, so non-inplace
+ "LargeData",
+ {-1, 256, 128}, // reshape pattern: [N, 256, 128]
+ {1, 256, 1} // mul_const shape: [1, 256, 1]
+ }};
+
+INSTANTIATE_TEST_SUITE_P(smoke_TailOptimizationConcatConvertFusion,
+ TailOptimizationConcatConvertFusionTest,
+ ::testing::ValuesIn(concatTestParams),
+ TailOptimizationConcatConvertFusionTest::getTestCaseName);
+
+} // namespace
+} // namespace test
+} // namespace ov
\ No newline at end of file