OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[CPU | GPU] Identity op implementation (#27680)
Piotr Krzemiński28d6bee7c179
diff --git a/src/common/transformations/include/transformations/common_optimizations/nop_elimination.hpp b/src/common/transformations/include/transformations/common_optimizations/nop_elimination.hppindex 87828c8976c..d7295563204 100644--- a/src/common/transformations/include/transformations/common_optimizations/nop_elimination.hpp+++ b/src/common/transformations/include/transformations/common_optimizations/nop_elimination.hpp@@ -13,6 +13,7 @@ namespace pass {class TRANSFORMATIONS_API EliminateConcat;class TRANSFORMATIONS_API EliminateConcatStridedSlice;class TRANSFORMATIONS_API EliminateConvert;+class TRANSFORMATIONS_API EliminateIdentityConvert;class TRANSFORMATIONS_API EliminateConvertNonZero;class TRANSFORMATIONS_API EliminateEltwise;class TRANSFORMATIONS_API EliminateScatterUpdate;@@ -28,6 +29,7 @@ class TRANSFORMATIONS_API EliminateSliceBeforeGatherElements;class TRANSFORMATIONS_API EliminateStridedSlice;class TRANSFORMATIONS_API EliminateSlice;class TRANSFORMATIONS_API EliminateStridedSliceByShape;+class TRANSFORMATIONS_API EliminateIdentity;class TRANSFORMATIONS_API NopElimination;class TRANSFORMATIONS_API PrepareShapeOpsForEliminationAroundBE;@@ -64,6 +66,17 @@ public:EliminateConvert();};+/**+ * @ingroup ov_transformation_common_api+ * @brief EliminateIdentityConvert eliminates convert that before and after Identity+ * have the same input and output types+ */+class ov::pass::EliminateIdentityConvert : public ov::pass::MatcherPass {+public:+ OPENVINO_MATCHER_PASS_RTTI("EliminateIdentityConvert");+ EliminateIdentityConvert();+};+/*** @ingroup ov_transformation_common_api* @brief EliminateConvertNonZero eliminates convert before NonZero@@ -266,3 +279,13 @@ public:OPENVINO_MATCHER_PASS_RTTI("PrepareShapeOpsForEliminationAroundBE");PrepareShapeOpsForEliminationAroundBE();};++/**+ * @ingroup ov_transformation_common_api+ * @brief EliminateIdentity eliminates identity that does nothing+ */+class ov::pass::EliminateIdentity : public ov::pass::MatcherPass {+public:+ OPENVINO_MATCHER_PASS_RTTI("EliminateIdentity");+ EliminateIdentity();+};diff --git a/src/common/transformations/src/transformations/common_optimizations/nop_elimination.cpp b/src/common/transformations/src/transformations/common_optimizations/nop_elimination.cppindex 0b9fcb6d1c9..bf3ac34c14d 100644--- a/src/common/transformations/src/transformations/common_optimizations/nop_elimination.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/nop_elimination.cpp@@ -22,6 +22,7 @@#include "openvino/op/gather.hpp"#include "openvino/op/gather_elements.hpp"#include "openvino/op/gru_sequence.hpp"+#include "openvino/op/identity.hpp"#include "openvino/op/lstm_sequence.hpp"#include "openvino/op/multiply.hpp"#include "openvino/op/non_zero.hpp"@@ -479,6 +480,30 @@ pass::EliminateConvert::EliminateConvert() {this->register_matcher(m, callback);}+pass::EliminateIdentityConvert::EliminateIdentityConvert() {+ MATCHER_SCOPE(EliminateIdentityConvert);+ auto convert_pattern = pattern::wrap_type<ov::op::v0::Convert>();+ auto convert_identity_pattern = pattern::wrap_type<ov::op::v16::Identity>(convert_pattern);+ auto convert_identity_convert_pattern = pattern::wrap_type<ov::op::v0::Convert>(convert_identity_pattern);++ matcher_pass_callback callback = [=](pattern::Matcher& m) {+ const auto& pattern_map = m.get_pattern_map();+ auto convert_begin = pattern_map.at(convert_pattern);+ auto identity = pattern_map.at(convert_identity_pattern);+ auto convert_end = pattern_map.at(convert_identity_convert_pattern);++ if (convert_begin->get_input_element_type(0) == convert_end->get_element_type()) {+ convert_begin->output(0).replace(convert_begin->input_value(0));+ identity->validate_and_infer_types();+ convert_end->output(0).replace(identity->output(0));+ return true;+ }+ return false;+ };+ auto m = make_shared<pattern::Matcher>(convert_identity_convert_pattern, matcher_name);+ this->register_matcher(m, callback);+}+pass::EliminateConvertNonZero::EliminateConvertNonZero() {MATCHER_SCOPE(EliminateConvertNonZero);auto convert_pattern = pattern::wrap_type<ov::op::v0::Convert>(pattern::consumers_count(1));@@ -822,6 +847,22 @@ pass::EliminateSqueeze::EliminateSqueeze() {this->register_matcher(m, callback);}+pass::EliminateIdentity::EliminateIdentity() {+ MATCHER_SCOPE(EliminateIdentity);+ auto identity_pattern = pattern::wrap_type<ov::op::v16::Identity>();++ matcher_pass_callback callback = [](pattern::Matcher& m) {+ auto identity = ov::as_type_ptr<ov::op::v16::Identity>(m.get_match_root());+ if (!identity) {+ return false;+ }+ return replace_output_update_name(identity->output(0), identity->input_value(0));+ };++ auto m = make_shared<pattern::Matcher>(identity_pattern, matcher_name);+ this->register_matcher(m, callback);+}+namespace {int64_t make_positive(int64_t value, const Output<Node>& node) {const auto& rank = node.get_partial_shape().rank();@@ -1360,6 +1401,7 @@ ov::pass::NopElimination::NopElimination(bool use_shape_for_elimination) {ADD_MATCHER_FOR_THIS(EliminateStridedSlice)ADD_MATCHER_FOR_THIS(EliminateSlice)ADD_MATCHER_FOR_THIS(EliminateConcatStridedSlice)+ ADD_MATCHER_FOR_THIS(EliminateIdentity)// shape-dependent transformationsif (use_shape_for_elimination) {diff --git a/src/core/reference/include/openvino/reference/identity.hpp b/src/core/reference/include/openvino/reference/identity.hppindex 6adf41b6637..a2d6da0ab2c 100644--- a/src/core/reference/include/openvino/reference/identity.hpp+++ b/src/core/reference/include/openvino/reference/identity.hpp@@ -4,7 +4,9 @@#pragma once+#include <algorithm>#include <cstring>+#include <string>namespace ov {namespace reference {@@ -18,9 +20,23 @@ namespace reference {static inline void identity(const char* input, char* output, const size_t size_in_bytes) {if (input == output) {return;- } else {- std::memcpy(output, input, size_in_bytes);}+ std::memcpy(output, input, size_in_bytes);}++/**+ * @brief Identity operation computes the identity of the input tensor.+ *+ * @param input Input matrix (matrices) pointer.+ * @param output Output matrix (matrices) pointer.+ * @param shape_size Size of the input tensor shape.+ **/+static inline void identity(const std::string* input, std::string* output, const size_t shape_size) {+ if (input == output) {+ return;+ }+ std::copy_n(input, shape_size, output);+}+} // namespace reference} // namespace ovdiff --git a/src/core/shape_inference/include/identity_shape_inference.hpp b/src/core/shape_inference/include/identity_shape_inference.hppnew file mode 100644index 00000000000..47f7174bc6e--- /dev/null+++ b/src/core/shape_inference/include/identity_shape_inference.hpp@@ -0,0 +1,17 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/op/identity.hpp"+#include "utils.hpp"++namespace ov::op::v16 {+template <class TShape, class TRShape = result_shape_t<TShape>>+std::vector<TRShape> shape_infer(const Identity* op, const std::vector<TShape>& input_shapes) {+ NODE_VALIDATION_CHECK(op, input_shapes.size() == 1);++ return {input_shapes[0]};+}+} // namespace ov::op::v16diff --git a/src/frontends/onnx/frontend/src/op/identity.cpp b/src/frontends/onnx/frontend/src/op/identity.cppindex 798e16780f4..2fb70029808 100644--- a/src/frontends/onnx/frontend/src/op/identity.cpp+++ b/src/frontends/onnx/frontend/src/op/identity.cpp@@ -2,20 +2,27 @@// SPDX-License-Identifier: Apache-2.0//+#include "openvino/op/identity.hpp"+#include "core/operator_set.hpp"+#include "openvino/core/type.hpp"+#include "openvino/op/constant.hpp"#include "utils/common.hpp"+using namespace ov::op;+namespace ov {namespace frontend {namespace onnx {namespace ai_onnx {namespace opset_1 {ov::OutputVector identity(const ov::frontend::onnx::Node& node) {- ov::OutputVector outputs = node.get_ov_inputs();- for (auto& out : outputs) {- common::mark_as_optimized_out(out);+ ov::Output<ov::Node> input = node.get_ov_inputs().at(0);+ if (ov::is_type<v0::Constant>(input.get_node())) {+ common::mark_as_optimized_out(input);+ return {input};}- return outputs;+ return {std::make_shared<v16::Identity>(input)};}ONNX_OP("Identity", OPSET_SINCE(1), ai_onnx::opset_1::identity);} // namespace opset_1diff --git a/src/frontends/onnx/frontend/src/op/loop.cpp b/src/frontends/onnx/frontend/src/op/loop.cppindex ae534ae619a..a56d1dccb40 100644--- a/src/frontends/onnx/frontend/src/op/loop.cpp+++ b/src/frontends/onnx/frontend/src/op/loop.cpp@@ -10,7 +10,9 @@#include "exceptions.hpp"#include "openvino/core/graph_util.hpp"#include "openvino/core/model.hpp"+#include "openvino/core/type.hpp"#include "openvino/op/constant.hpp"+#include "openvino/op/identity.hpp"#include "openvino/op/unsqueeze.hpp"#include "openvino/op/util/op_types.hpp"#include "translate_session.hpp"@@ -37,6 +39,9 @@ namespace {////// \return true if termination condition is not modified during loop iterations, false otherwise.bool is_termination_condition_always_true(const ov::Node* cond_in, const ov::Node* cond_out) {+ if (auto identity = ov::as_type<const op::v16::Identity>(cond_out)) {+ cond_out = identity->input_value(0).get_node();+ }return cond_in == cond_out;}} // namespace@@ -101,9 +106,18 @@ ov::OutputVector loop_legacy(const ov::frontend::onnx::Node& node) {const auto& cond_in = body_inputs[1];const auto& cond_out = body_outputs[0];+ bool needs_condition_param = true;+ ov::ParameterVector body_params;// optimization allow to improve nG Loop shape inferenceif (is_termination_condition_always_true(cond_in.get(), cond_out.get_node())) {body_outputs[0] = v0::Constant::create(ov::element::boolean, {1}, {true});+ // Construct body_params without the condition parameter (body_inputs[1])+ body_params = ov::ParameterVector{body_inputs[0]};+ body_params.insert(body_params.end(), body_inputs.begin() + 2, body_inputs.end());+ needs_condition_param = false;+ } else {+ // Construct body_params with all body_inputs+ body_params = ov::ParameterVector(body_inputs.begin(), body_inputs.end());}CHECK_VALID_NODE(node,@@ -123,15 +137,15 @@ ov::OutputVector loop_legacy(const ov::frontend::onnx::Node& node) {") is not greater than number of outputs. Required at least: ",loop_carried_dependencies.size() + 1);- ov::ParameterVector body_params(body_inputs.begin() + 2, body_inputs.end());- body_params.emplace(body_params.begin(),- body_inputs[0]); // current iteration body inputconst auto body = std::make_shared<ov::Model>(body_outputs, body_params);auto loop = std::make_shared<v5::Loop>(trip_count, termination_cond);v5::Loop::SpecialBodyPorts spec_ports{0, 0};loop->set_special_body_ports(spec_ports);loop->set_function(body);-+ // Add condition+ if (needs_condition_param) {+ loop->set_merged_input(*std::next(body_inputs.begin(), 1), ng_inputs.at(1), *body_outputs.begin());+ }// Setting up other Loop body inputs.// body_inputs[0] is iteration number, body_inputs[1] is termination conditionauto body_inputs_it = std::next(body_inputs.begin(), 2);diff --git a/src/frontends/onnx/tests/onnx_tensor_names.cpp b/src/frontends/onnx/tests/onnx_tensor_names.cppindex 933bb12cde1..66a01318544 100644--- a/src/frontends/onnx/tests/onnx_tensor_names.cpp+++ b/src/frontends/onnx/tests/onnx_tensor_names.cpp@@ -9,6 +9,7 @@#include "onnx_utils.hpp"#include "openvino/op/abs.hpp"#include "openvino/op/convolution.hpp"+#include "openvino/op/identity.hpp"#include "openvino/op/matmul.hpp"#include "openvino/op/parameter.hpp"#include "openvino/op/relu.hpp"@@ -58,13 +59,14 @@ OPENVINO_TEST(onnx_tensor_names, simple_model) {const auto model = convert_model("tensor_names.onnx");const auto ops = model->get_ordered_ops();- EXPECT_TRUE(- matching_node_found_in_graph<op::v0::Parameter>(ops, "identity_on_input", {"input", "identity_on_input"}));+ EXPECT_TRUE(matching_node_found_in_graph<op::v0::Parameter>(ops, "input", {"input"}));+ EXPECT_TRUE(matching_node_found_in_graph<op::v16::Identity>(ops, "identity_node_on_input", {"identity_on_input"}));EXPECT_TRUE(matching_node_found_in_graph<op::v0::Relu>(ops, "relu", {"relu_t"}));- EXPECT_TRUE(matching_node_found_in_graph<op::v0::Abs>(ops, "final_output", {"abs_t", "final_output"}));+ EXPECT_TRUE(matching_node_found_in_graph<op::v0::Abs>(ops, "abs", {"abs_t"}));+ EXPECT_TRUE(matching_node_found_in_graph<op::v16::Identity>(ops, "final_output", {"final_output"}));EXPECT_TRUE(matching_node_found_in_graph<op::v0::Result>(model->get_results(),"final_output/sink_port_0",- {"abs_t", "final_output"}));+ {"final_output"}));}OPENVINO_TEST(onnx_tensor_names, node_multiple_outputs) {diff --git a/src/plugins/intel_cpu/src/cpu_types.cpp b/src/plugins/intel_cpu/src/cpu_types.cppindex b7535d3c3cc..be2329e486d 100644--- a/src/plugins/intel_cpu/src/cpu_types.cpp+++ b/src/plugins/intel_cpu/src/cpu_types.cpp@@ -235,6 +235,7 @@ static const TypeToNameMap& get_type_to_name_tbl() {{"ExperimentalDetectronGenerateProposalsSingleImage", Type::ExperimentalDetectronGenerateProposalsSingleImage},{"ExtractImagePatches", Type::ExtractImagePatches},{"GenerateProposals", Type::GenerateProposals},+ {"Identity", Type::Identity},{"Inverse", Type::Inverse},{"NonMaxSuppression", Type::NonMaxSuppression},{"NonMaxSuppressionIEInternal", Type::NonMaxSuppression},@@ -374,6 +375,7 @@ std::string NameFromType(const Type type) {CASE(ExperimentalDetectronPriorGridGenerator);CASE(ExperimentalDetectronGenerateProposalsSingleImage);CASE(GenerateProposals);+ CASE(Identity);CASE(Inverse);CASE(ExtractImagePatches);CASE(NonMaxSuppression);diff --git a/src/plugins/intel_cpu/src/cpu_types.h b/src/plugins/intel_cpu/src/cpu_types.hindex 438a41d7ee4..95af24e5940 100644--- a/src/plugins/intel_cpu/src/cpu_types.h+++ b/src/plugins/intel_cpu/src/cpu_types.h@@ -114,6 +114,7 @@ enum class Type : uint8_t {ExperimentalDetectronGenerateProposalsSingleImage,ExtractImagePatches,GenerateProposals,+ Identity,Inverse,NonMaxSuppression,MatrixNms,diff --git a/src/plugins/intel_cpu/src/nodes/identity.cpp b/src/plugins/intel_cpu/src/nodes/identity.cppnew file mode 100644index 00000000000..30ab6c37e63--- /dev/null+++ b/src/plugins/intel_cpu/src/nodes/identity.cpp@@ -0,0 +1,98 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "identity.hpp"++#include <functional>+#include <memory>+#include <numeric>+#include <oneapi/dnnl/dnnl_common.hpp>+#include <string>++#include "cpu_types.h"+#include "graph_context.h"+#include "memory_desc/cpu_memory_desc.h"+#include "node.h"+#include "nodes/common/cpu_memcpy.h"+#include "onednn/iml_type_mapper.h"+#include "openvino/core/except.hpp"+#include "openvino/core/node.hpp"+#include "openvino/op/identity.hpp"+#include "shape_inference/shape_inference_cpu.hpp"++namespace ov::intel_cpu::node {++bool Identity::isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::string& errorMessage) noexcept {+ try {+ if (op->get_type_info() != op::v16::Identity::get_type_info_static()) {+ errorMessage = "Only Identity operation from the opset16 is supported by the CPU plugin.";+ return false;+ }+ } catch (...) {+ return false;+ }+ return true;+}++Identity::Identity(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr& context)+ : Node(op, context, NgraphShapeInferFactory(op)) {+ std::string errorMessage;+ if (!isSupportedOperation(op, errorMessage)) {+ OPENVINO_THROW_NOT_IMPLEMENTED(errorMessage);+ }+}++void Identity::getSupportedDescriptors() {+ if (getParentEdges().size() != 1) {+ CPU_NODE_THROW("has incorrect number of input edges.");+ }+ if (getChildEdges().empty()) {+ CPU_NODE_THROW("has incorrect number of output edges.");+ }+}++void Identity::initSupportedPrimitiveDescriptors() {+ auto in_prc = getOriginalInputPrecisionAtPort(0);+ auto out_prc = getOriginalOutputPrecisionAtPort(0);++ if (in_prc != out_prc) {+ CPU_NODE_THROW("has to have the same dtype for input and output nodes. src: ", in_prc, ", dst: ", out_prc);+ }++ m_out_prc = out_prc;++ addSupportedPrimDesc({{LayoutType::ncsp, in_prc}}, {{LayoutType::ncsp, out_prc}}, ref_any);+}++void Identity::prepareParams() {+ VectorDims out_shape = getDstMemoryAtPort(0)->getShape().getStaticDims();+ m_element_num = std::accumulate(out_shape.begin(), out_shape.end(), 1UL, std::multiplies<>());+}++bool Identity::isExecutable() const {+ return !isInputTensorAtPortEmpty(0);+}++bool Identity::created() const {+ return getType() == Type::Identity;+}++bool Identity::canBeInPlace() const {+ return getSrcMemoryAtPort(0) == getDstMemoryAtPort(0);+}++void Identity::execute([[maybe_unused]] const dnnl::stream& strm) {+ if (!canBeInPlace()) {+ auto* input = getSrcDataAtPort(0);+ auto* output = getDstDataAtPort(0);++ cpu_parallel_memcpy(output, input, m_out_prc.size() * m_element_num);+ }+}++void Identity::executeDynamicImpl(const dnnl::stream& strm) {+ execute(strm);+}++} // namespace ov::intel_cpu::nodediff --git a/src/plugins/intel_cpu/src/nodes/identity.hpp b/src/plugins/intel_cpu/src/nodes/identity.hppnew file mode 100644index 00000000000..9bac6436b79--- /dev/null+++ b/src/plugins/intel_cpu/src/nodes/identity.hpp@@ -0,0 +1,38 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include <node.h>++namespace ov::intel_cpu::node {++class Identity : public Node {+public:+ Identity(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr& context);++ void getSupportedDescriptors() override;++ void initSupportedPrimitiveDescriptors() override;++ void prepareParams() override;++ void execute(const dnnl::stream& strm) override;++ void executeDynamicImpl(const dnnl::stream& strm) override;++ bool isExecutable() const override;++ bool created() const override;++ bool canBeInPlace() const override;++ static bool isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::string& errorMessage) noexcept;++private:+ element::Type m_out_prc;+ size_t m_element_num = 0;+};++} // namespace ov::intel_cpu::nodediff --git a/src/plugins/intel_cpu/src/nodes_factory.cpp b/src/plugins/intel_cpu/src/nodes_factory.cppindex ee0065ba292..f59dfd25b7e 100644--- a/src/plugins/intel_cpu/src/nodes_factory.cpp+++ b/src/plugins/intel_cpu/src/nodes_factory.cpp@@ -43,6 +43,7 @@#include "nodes/gather_tree.h"#include "nodes/generate_proposals.h"#include "nodes/grn.h"+#include "nodes/identity.hpp"#include "nodes/if.h"#include "nodes/input.h"#include "nodes/interpolate.h"@@ -215,6 +216,7 @@ Node::NodesFactory::NodesFactory() : Factory("NodesFactory") {INTEL_CPU_NODE(Ngram, Type::Ngram);INTEL_CPU_NODE(RoPE, Type::RoPE);INTEL_CPU_NODE(CausalMaskPreprocess, Type::CausalMaskPreprocess);+ INTEL_CPU_NODE(Identity, Type::Identity);INTEL_CPU_NODE(Interpolate, Type::Interpolate);INTEL_CPU_NODE(Inverse, Type::Inverse);INTEL_CPU_NODE(RandomUniform, Type::RandomUniform);diff --git a/src/plugins/intel_cpu/src/shape_inference/shape_inference.cpp b/src/plugins/intel_cpu/src/shape_inference/shape_inference.cppindex 90fb9af2898..0a01d5047fe 100644--- a/src/plugins/intel_cpu/src/shape_inference/shape_inference.cpp+++ b/src/plugins/intel_cpu/src/shape_inference/shape_inference.cpp@@ -67,6 +67,7 @@#include "gru_cell_shape_inference.hpp"#include "gru_sequence_shape_inference.hpp"#include "i420_shape_inference.hpp"+#include "identity_shape_inference.hpp"#include "interpolate_shape_inference.hpp"#include "inverse_shape_inference.hpp"#include "irdft_shape_inference.hpp"@@ -133,6 +134,7 @@#include "openvino/op/hard_sigmoid.hpp"#include "openvino/op/i420_to_bgr.hpp"#include "openvino/op/i420_to_rgb.hpp"+#include "openvino/op/identity.hpp"#include "openvino/op/idft.hpp"#include "openvino/op/interpolate.hpp"#include "openvino/op/inverse.hpp"@@ -581,6 +583,7 @@ const IStaticShapeInferFactory::TRegistry IStaticShapeInferFactory::registry{OV_OP_SHAPE_INFER_MASK_REG(op::v16::ISTFT, ShapeInferTA, util::bit::mask(2, 3, 4)),OV_OP_SHAPE_INFER_MASK_REG(op::v16::SegmentMax, ShapeInferTA, util::bit::mask(1, 2)),OV_OP_SHAPE_INFER_MASK_REG(op::v16::SparseFillEmptyRows, ShapeInferTA, util::bit::mask(1, 2)),+ OV_OP_SHAPE_INFER_MASK_REG(op::v16::Identity, ShapeInferTA, util::bit::mask()),// opset15OV_OP_SHAPE_INFER_MASK_REG(op::v15::Squeeze, ShapeInferTA, util::bit::mask(1)),OV_OP_SHAPE_INFER_MASK_REG(op::v15::SearchSorted, ShapeInferTA, util::bit::mask()),diff --git a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cppindex dee3b4ec90c..eb032ae22ae 100644--- a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp+++ b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp@@ -1,4 +1,4 @@-// Copyright (C) 2022 Intel Corporation+// Copyright (C) 2018-2025 Intel Corporation// SPDX-License-Identifier: Apache-2.0//@@ -652,6 +652,7 @@ void Transformations::PreLpt(const std::vector<ov::element::Type>& defaultPrecisconvert_input_output_precision);CPU_REGISTER_PASS_COMMON(manager, ov::pass::EliminateConvert);+ CPU_REGISTER_PASS_COMMON(manager, ov::pass::EliminateIdentityConvert);CPU_REGISTER_PASS_COMMON(manager, SwapConvertTranspose);CPU_REGISTER_PASS_X64(manager, ConvertToInteraction);CPU_REGISTER_PASS_X64(manager, ConvertInteractionInt8);diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/identity.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/identity.cppnew file mode 100644index 00000000000..fadb2db04e5--- /dev/null+++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/identity.cpp@@ -0,0 +1,80 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "identity.hpp"+#include "openvino/op/identity.hpp"+#include "utils/general_utils.h"+#include "common_test_utils/node_builders/constant.hpp"++using namespace CPUTestUtils;++namespace ov::test {++std::string IdentityLayerTestCPU::getTestCaseName(const testing::TestParamInfo<IdentityLayerTestCPUParamSet>& obj) {+ std::ostringstream result;++ result << "IS=" << std::get<0>(obj.param);+ result << "_Prc=" << std::get<1>(obj.param);+ result << "_ConstIn=" << utils::bool2str(std::get<2>(obj.param));+ result << CPUTestsBase::getTestCaseName(std::get<3>(obj.param));++ const auto& config = std::get<4>(obj.param);+ if (!config.empty()) {+ result << "_PluginConf={";+ for (const auto& conf_item : config) {+ result << "_" << conf_item.first << "=";+ conf_item.second.print(result);+ }+ result << "}";+ }++ return result.str();+}++void IdentityLayerTestCPU::SetUp() {+ targetDevice = utils::DEVICE_CPU;++ const auto& [output_shape, output_precision, const_input, cpu_params, additionalConfig] = this->GetParam();++ std::tie(inFmts, outFmts, priority, selectedType) = cpu_params;++ configuration.insert(additionalConfig.begin(), additionalConfig.end());+ if (ov::intel_cpu::contains_key_value(additionalConfig, {ov::hint::inference_precision.name(), ov::element::bf16})) {+ selectedType = makeSelectedTypeStr(selectedType, ElementType::bf16);+ } else {+ selectedType = makeSelectedTypeStr(selectedType, output_precision);+ }++ std::vector<InputShape> in_shapes;++ if (!const_input) {+ in_shapes.push_back({{}, {{output_shape}}});+ } else {+ in_shapes.push_back({{output_shape}, {{output_shape}}});+ }+ init_input_shapes(in_shapes);++ const auto data = std::make_shared<ov::op::v0::Parameter>(output_precision, output_shape);+ data->set_friendly_name("data");++ const auto op = std::make_shared<ov::op::v16::Identity>(data);+ const ov::ResultVector results{std::make_shared<ov::op::v0::Result>(op)};++ function = std::make_shared<ov::Model>(results, ParameterVector{data}, "IdentityLayerTestCPU");+}++void IdentityLayerTestCPU::generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) {+ inputs.clear();+ const auto& func_inputs = function->inputs();+ const auto& func_input = func_inputs[0];+ auto tensor = ov::test::utils::create_and_fill_tensor(func_input.get_element_type(), targetInputStaticShapes[0], utils::InputGenerateData());+ inputs.insert({func_input.get_node_shared_ptr(), tensor});+}++TEST_P(IdentityLayerTestCPU, CompareWithRefs) {+ run();+ CheckPluginRelatedResults(compiledModel, "Identity");+}++} // namespace ov::testdiff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/identity.hpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/identity.hppnew file mode 100644index 00000000000..3b772436e3e--- /dev/null+++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/identity.hpp@@ -0,0 +1,30 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "shared_test_classes/base/ov_subgraph.hpp"+#include "utils/cpu_test_utils.hpp"++namespace ov::test {++typedef std::tuple<+ ov::Shape, // Input/Output shape+ ov::test::ElementType, // Data precision+ bool, // Is input constant+ CPUTestUtils::CPUSpecificParams, // CPU specific params+ ov::AnyMap // Additional plugin configuration+> IdentityLayerTestCPUParamSet;++class IdentityLayerTestCPU : public testing::WithParamInterface<IdentityLayerTestCPUParamSet>,+ public ov::test::SubgraphBaseTest, public CPUTestUtils::CPUTestsBase {+public:+ static std::string getTestCaseName(const testing::TestParamInfo<IdentityLayerTestCPUParamSet>& obj);++protected:+ void SetUp() override;++ void generate_inputs(const std::vector<ov::Shape>& target_shapes) override;+};+} // namespace ov::testdiff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/common/identity.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/common/identity.cppnew file mode 100644index 00000000000..53b6acb1c70--- /dev/null+++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/common/identity.cpp@@ -0,0 +1,44 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "custom/single_layer_tests/classes/identity.hpp"++using namespace CPUTestUtils;++namespace ov::test::identity {++const CPUSpecificParams cpuParamsRef{{}, {}, {"ref_any"}, "ref_any"};+static const std::vector<ov::Shape> shapes = {+ {500},+ {4, 3, 210}+};++static const std::vector<ElementType> prc = {+ ElementType::f32,+ ElementType::f16,+ ElementType::bf16,+ ElementType::i32,+ ElementType::u16,+ ElementType::boolean+};++INSTANTIATE_TEST_SUITE_P(smoke_Param, IdentityLayerTestCPU,+ ::testing::Combine(+ ::testing::ValuesIn(shapes),+ ::testing::ValuesIn(prc),+ ::testing::Values(false),+ ::testing::Values(cpuParamsRef),+ ::testing::Values(empty_plugin_config)),+ IdentityLayerTestCPU::getTestCaseName);++INSTANTIATE_TEST_SUITE_P(smoke_ParamConst, IdentityLayerTestCPU,+ ::testing::Combine(+ ::testing::ValuesIn(shapes),+ ::testing::ValuesIn(prc),+ ::testing::Values(true),+ ::testing::Values(cpuParamsRef),+ ::testing::Values(empty_plugin_config)),+ IdentityLayerTestCPU::getTestCaseName);++} // namespace ov::test::identitydiff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/identity.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/identity.cppnew file mode 100644index 00000000000..7acacd17f5a--- /dev/null+++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/identity.cpp@@ -0,0 +1,68 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <vector>++#include "single_op_tests/identity.hpp"+#include "common_test_utils/test_constants.hpp"++using ov::test::IdentityLayerTest;++namespace {+const std::vector<ov::element::Type> model_types = {+ ov::element::f32,+ ov::element::f16,+ ov::element::i64,+ ov::element::i32,+ ov::element::i16,+ ov::element::i8,+ ov::element::u8,+};++std::vector<std::vector<ov::Shape>> input_shape_static_2D = {{{2, 10}}, {{10, 2}}, {{10, 10}}};++INSTANTIATE_TEST_SUITE_P(smoke_Identity2D, IdentityLayerTest,+ ::testing::Combine(+ ::testing::ValuesIn(model_types),+ ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shape_static_2D)),+ ::testing::Values(ov::test::utils::DEVICE_CPU)),+ IdentityLayerTest::getTestCaseName);++std::vector<std::vector<ov::Shape>> input_shape_static_3D = {{{2, 8, 10}}, {{10, 8, 2}}, {{8, 2, 10}}};++INSTANTIATE_TEST_SUITE_P(smoke_Identity3D, IdentityLayerTest,+ ::testing::Combine(+ ::testing::ValuesIn(model_types),+ ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shape_static_3D)),+ ::testing::Values(ov::test::utils::DEVICE_CPU)),+ IdentityLayerTest::getTestCaseName);++std::vector<std::vector<ov::Shape>> input_shape_static_4D = {{{2, 2, 2, 2}}, {{1, 10, 2, 3}}, {{2, 3, 4, 5}}};++INSTANTIATE_TEST_SUITE_P(smoke_Identity4D, IdentityLayerTest,+ ::testing::Combine(+ ::testing::ValuesIn(model_types),+ ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shape_static_4D)),+ ::testing::Values(ov::test::utils::DEVICE_CPU)),+ IdentityLayerTest::getTestCaseName);++std::vector<std::vector<ov::Shape>> input_shape_static_5D = {{{2, 2, 2, 2, 2}}, {{1, 10, 2, 3, 4}}, {{2, 3, 4, 5, 6}}};++INSTANTIATE_TEST_SUITE_P(smoke_Identity5D, IdentityLayerTest,+ ::testing::Combine(+ ::testing::ValuesIn(model_types),+ ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shape_static_5D)),+ ::testing::Values(ov::test::utils::DEVICE_CPU)),+ IdentityLayerTest::getTestCaseName);++std::vector<std::vector<ov::Shape>> input_shape_static_6D = {{{2, 2, 2, 2, 2, 2}}, {{1, 10, 2, 3, 4, 5}}, {{2, 3, 4, 5, 6, 7}}};++INSTANTIATE_TEST_SUITE_P(smoke_Identity6D, IdentityLayerTest,+ ::testing::Combine(+ ::testing::ValuesIn(model_types),+ ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shape_static_6D)),+ ::testing::Values(ov::test::utils::DEVICE_CPU)),+ IdentityLayerTest::getTestCaseName);++} // namespacediff --git a/src/plugins/intel_cpu/tests/unit/shape_inference_test/identity_shape_inference_test.cpp b/src/plugins/intel_cpu/tests/unit/shape_inference_test/identity_shape_inference_test.cppnew file mode 100644index 00000000000..ad6bc7f2f11--- /dev/null+++ b/src/plugins/intel_cpu/tests/unit/shape_inference_test/identity_shape_inference_test.cpp@@ -0,0 +1,69 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "identity_shape_inference.hpp"++#include <gtest/gtest.h>++#include "utils.hpp"++using namespace ov::intel_cpu;++class Identityv16StaticShapeInferenceTest : public OpStaticShapeInferenceTest<ov::op::v16::Identity> {+protected:+};++TEST_F(Identityv16StaticShapeInferenceTest, Identity_default_ctor) {+ op = make_op();+ input_shapes = StaticShapeVector{{2, 2}};++ auto output_shapes = shape_inference(op.get(), input_shapes);+ EXPECT_EQ(output_shapes.size(), 1);+ EXPECT_EQ(output_shapes[0], StaticShape({2, 2}));+}++TEST_F(Identityv16StaticShapeInferenceTest, Identity_4_4_small_matrix) {+ auto data = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape::dynamic(2));+ auto op = make_op(data);+ input_shapes = StaticShapeVector{{4, 4}};++ auto output_shapes = shape_inference(op.get(), input_shapes);+ EXPECT_EQ(output_shapes[0], StaticShape({4, 4}));+}++TEST_F(Identityv16StaticShapeInferenceTest, Identity_10_10_big_matrix) {+ auto data = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape::dynamic(2));+ auto op = make_op(data);+ input_shapes = StaticShapeVector{{10, 10}};++ auto output_shapes = shape_inference(op.get(), input_shapes);+ EXPECT_EQ(output_shapes[0], StaticShape({10, 10}));+}++TEST_F(Identityv16StaticShapeInferenceTest, Identity_10_1_1_keep_batch_when_single_cell_matrix) {+ auto data = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape::dynamic(3));+ auto op = make_op(data);+ input_shapes = StaticShapeVector{{10, 1, 1}};++ auto output_shapes = shape_inference(op.get(), input_shapes);+ EXPECT_EQ(output_shapes[0], StaticShape({10, 1, 1}));+}++TEST_F(Identityv16StaticShapeInferenceTest, Identity_10_9_9_keep_batch_big_matrix) {+ auto data = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape::dynamic(3));+ auto op = make_op(data);+ input_shapes = StaticShapeVector{{10, 9, 9}};++ auto output_shapes = shape_inference(op.get(), input_shapes);+ EXPECT_EQ(output_shapes[0], StaticShape({10, 9, 9}));+}++TEST_F(Identityv16StaticShapeInferenceTest, Identity_10_5_3_2_2_complex_multi_dim_matrix) {+ auto data = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape::dynamic(5));+ auto op = make_op(data);+ input_shapes = StaticShapeVector{{10, 5, 3, 2, 2}};++ auto output_shapes = shape_inference(op.get(), input_shapes);+ EXPECT_EQ(output_shapes[0], StaticShape({10, 5, 3, 2, 2}));+}diff --git a/src/plugins/intel_gpu/include/intel_gpu/plugin/primitives_list.hpp b/src/plugins/intel_gpu/include/intel_gpu/plugin/primitives_list.hppindex 37734352b9f..90363864062 100644--- a/src/plugins/intel_gpu/include/intel_gpu/plugin/primitives_list.hpp+++ b/src/plugins/intel_gpu/include/intel_gpu/plugin/primitives_list.hpp@@ -284,6 +284,7 @@ REGISTER_FACTORY(v16, ISTFT);REGISTER_FACTORY(v16, SparseFillEmptyRows);REGISTER_FACTORY(v16, AvgPool);REGISTER_FACTORY(v16, OneHot);+REGISTER_FACTORY(v16, Identity);// --------------------------- Supported internal ops --------------------------- //REGISTER_FACTORY(internal, NonMaxSuppressionIEInternal);diff --git a/src/plugins/intel_gpu/src/plugin/ops/identity.cpp b/src/plugins/intel_gpu/src/plugin/ops/identity.cppnew file mode 100644index 00000000000..5d4b384aac0--- /dev/null+++ b/src/plugins/intel_gpu/src/plugin/ops/identity.cpp@@ -0,0 +1,25 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "openvino/op/identity.hpp"++#include "intel_gpu/plugin/common_utils.hpp"+#include "intel_gpu/plugin/program_builder.hpp"+#include "intel_gpu/primitives/reorder.hpp"++namespace ov::intel_gpu {++static void CreateIdentityOp(ProgramBuilder& p, const std::shared_ptr<ov::op::v16::Identity>& op) {+ validate_inputs_count(op, {1});+ auto inputs = p.GetInputInfo(op);+ std::string layerName = layer_type_name_ID(op);++ auto reorderPrim = cldnn::reorder(layerName, inputs[0], cldnn::format::any, op->get_element_type());+ reorderPrim.output_data_types = get_output_data_types(op);+ p.add_primitive(*op, reorderPrim);+}++REGISTER_FACTORY_IMPL(v16, Identity);++} // namespace ov::intel_gpudiff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/identity.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/identity.cppnew file mode 100644index 00000000000..0092f1d4932--- /dev/null+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/identity.cpp@@ -0,0 +1,58 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "single_op_tests/identity.hpp"++#include "common_test_utils/test_constants.hpp"+#include "shared_test_classes/single_op/identity.hpp"++namespace {+using ov::test::IdentityLayerTest;++const std::vector<ov::element::Type> netPrecisions = {+ ov::element::f32,+ ov::element::f16,+ ov::element::i64,+ ov::element::i32,+ ov::element::i16,+ ov::element::i8,+ ov::element::u8,+};++/**+ * 4D Identity tests+ */+const std::vector<std::vector<ov::Shape>> inputShapes = {+ {{1, 3, 100, 100}},+ {{2, 8, 64, 64}},+ {{2, 5, 64, 64}},+ {{2, 8, 64, 5}},+ {{2, 5, 64, 5}},+};++INSTANTIATE_TEST_SUITE_P(smoke_Identity,+ IdentityLayerTest,+ testing::Combine(testing::ValuesIn(netPrecisions),+ testing::ValuesIn(ov::test::static_shapes_to_test_representation(inputShapes)),+ testing::Values(ov::test::utils::DEVICE_GPU)),+ IdentityLayerTest::getTestCaseName);++/**+ * 5D Identity tests+ */+const std::vector<std::vector<ov::Shape>> inputShapes5D = {+ {{2, 3, 4, 12, 64}},+ {{2, 5, 11, 32, 32}},+ {{2, 8, 64, 32, 5}},+ {{2, 5, 64, 32, 5}},+};++INSTANTIATE_TEST_SUITE_P(smoke_Identity_5D,+ IdentityLayerTest,+ testing::Combine(testing::ValuesIn(netPrecisions),+ testing::ValuesIn(ov::test::static_shapes_to_test_representation(inputShapes5D)),+ testing::Values(ov::test::utils::DEVICE_GPU)),+ IdentityLayerTest::getTestCaseName);++} // namespacediff --git a/src/plugins/template/backend/ops/identity.cpp b/src/plugins/template/backend/ops/identity.cppindex acaa08fa0e2..72d3e9a950a 100644--- a/src/plugins/template/backend/ops/identity.cpp+++ b/src/plugins/template/backend/ops/identity.cpp@@ -15,9 +15,18 @@ bool evaluate_node<ov::op::v16::Identity>(std::shared_ptr<ov::Node> node,const auto input_shape = inputs[0].get_shape();outputs[0].set_shape(input_shape);+ auto element_type = node->get_element_type();++ if (element_type == ov::element::string) {+ ov::reference::identity(inputs[0].data<const std::string>(),+ outputs[0].data<std::string>(),+ inputs[0].get_size());++ } else {+ ov::reference::identity(static_cast<const char*>(inputs[0].data()),+ static_cast<char*>(outputs[0].data()),+ inputs[0].get_byte_size());+ }- ov::reference::identity(static_cast<const char*>(inputs[0].data()),- static_cast<char*>(outputs[0].data()),- inputs[0].get_byte_size());return true;}diff --git a/src/tests/functional/plugin/shared/include/shared_test_classes/single_op/identity.hpp b/src/tests/functional/plugin/shared/include/shared_test_classes/single_op/identity.hppnew file mode 100644index 00000000000..52305ecd267--- /dev/null+++ b/src/tests/functional/plugin/shared/include/shared_test_classes/single_op/identity.hpp@@ -0,0 +1,29 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include <tuple>+#include <string>+#include <vector>+#include <memory>++#include "shared_test_classes/base/ov_subgraph.hpp"++namespace ov::test {+typedef std::tuple<+ ov::element::Type, // Model type+ std::vector<InputShape>, // Input shapes+ std::string // Target device name+> identityParams;++class IdentityLayerTest : public testing::WithParamInterface<identityParams>,+ virtual public ov::test::SubgraphBaseTest {+public:+ static std::string getTestCaseName(const testing::TestParamInfo<identityParams>& obj);++protected:+ void SetUp() override;+};+} // namespace ov::testdiff --git a/src/tests/functional/plugin/shared/src/single_op/identity.cpp b/src/tests/functional/plugin/shared/src/single_op/identity.cppnew file mode 100644index 00000000000..33c398da0d9--- /dev/null+++ b/src/tests/functional/plugin/shared/src/single_op/identity.cpp@@ -0,0 +1,43 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "shared_test_classes/single_op/identity.hpp"+#include "openvino/op/identity.hpp"++namespace ov::test {+std::string IdentityLayerTest::getTestCaseName(const testing::TestParamInfo<identityParams>& obj) {+ const auto& [modelType, input_shapes, targetDevice] = obj.param;+ std::ostringstream result;+ result << "IS=(";+ for (size_t i = 0lu; i < input_shapes.size(); i++) {+ result << ov::test::utils::partialShape2str({input_shapes[i].first})+ << (i < input_shapes.size() - 1lu ? "_" : "");+ }+ result << ")_TS=";+ for (size_t i = 0lu; i < input_shapes.front().second.size(); i++) {+ result << "{";+ for (size_t j = 0lu; j < input_shapes.size(); j++) {+ result << ov::test::utils::vec2str(input_shapes[j].second[i]) << (j < input_shapes.size() - 1lu ? "_" : "");+ }+ result << "}_";+ }+ result << "modelType=" << modelType.to_string() << "_";+ result << "trgDev=" << targetDevice;+ return result.str();+}++void IdentityLayerTest::SetUp() {+ const auto& [model_type, input_shapes, _targetDevice] = this->GetParam();+ targetDevice = _targetDevice;++ init_input_shapes({input_shapes});++ const auto param = std::make_shared<ov::op::v0::Parameter>(model_type, inputDynamicShapes.front());+ param->set_friendly_name("param");++ const auto op = std::make_shared<ov::op::v16::Identity>(param);+ const ov::ResultVector results{std::make_shared<ov::op::v0::Result>(op)};+ function = std::make_shared<ov::Model>(results, ov::ParameterVector{param}, "Identity");+}+} // namespace ov::test