From 0cb38855480ecfb74555a9792af1851cc2c6a28c Mon Sep 17 00:00:00 2001 From: Roboreptile Date: Fri, 20 Sep 2024 18:51:09 +0000 Subject: [PATCH 1/4] [ADD] Identity operation --- src/core/include/openvino/op/identity.hpp | 39 ++++++ src/core/include/openvino/op/ops.hpp | 1 + .../include/openvino/opsets/opset15_tbl.hpp | 1 + .../include/openvino/reference/identity.hpp | 35 +++++ src/core/src/op/identity.hpp | 49 +++++++ src/core/tests/opset.cpp | 2 +- src/core/tests/type_prop/identity.cpp | 28 ++++ src/core/tests/visitors/op/identity.cpp | 25 ++++ src/plugins/template/backend/ops/identity.cpp | 65 ++++++++++ .../template/backend/ops/ops_evaluates.hpp | 5 + .../template/backend/opset_int_tbl.hpp | 2 +- .../functional/op_reference/identity.cpp | 121 ++++++++++++++++++ .../src/op_impl_check/single_op_graph.cpp | 7 + .../include/single_op_tests/identity.hpp | 15 +++ 14 files changed, 393 insertions(+), 2 deletions(-) create mode 100644 src/core/include/openvino/op/identity.hpp create mode 100644 src/core/reference/include/openvino/reference/identity.hpp create mode 100644 src/core/src/op/identity.hpp create mode 100644 src/core/tests/type_prop/identity.cpp create mode 100644 src/core/tests/visitors/op/identity.cpp create mode 100644 src/plugins/template/backend/ops/identity.cpp create mode 100644 src/plugins/template/tests/functional/op_reference/identity.cpp create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/identity.hpp diff --git a/src/core/include/openvino/op/identity.hpp b/src/core/include/openvino/op/identity.hpp new file mode 100644 index 00000000000000..6fc625340f46aa --- /dev/null +++ b/src/core/include/openvino/op/identity.hpp @@ -0,0 +1,39 @@ +// Copyright (C) 2018-2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/op/op.hpp" + +namespace ov { +namespace op { +namespace v15 { +/// \brief Identity operation is used as a placeholder op. +/// +/// \ingroup ov_ops_cpp_api +class OPENVINO_API Identity : public Op { +public: + OPENVINO_OP("Identity", "opset15"); + Identity() = default; + /** + * @brief Identity operation is used as a placeholder. It either passes the tensor down to the next layer, + * or copies the tensor to the output. + * + * @param copy Boolean that determines whether to copy the input to the output, or just return the output. + */ + Identity(const Output& data, const bool copy = false); + + bool visit_attributes(AttributeVisitor& visitor) override; + void validate_and_infer_types() override; + std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; + + bool get_copy() const; + void set_copy(const bool copy); + +private: + bool m_copy; +}; +} // namespace v15 +} // namespace op +} // namespace ov \ No newline at end of file diff --git a/src/core/include/openvino/op/ops.hpp b/src/core/include/openvino/op/ops.hpp index 4e2cde0882db9d..b783dae95fbc50 100644 --- a/src/core/include/openvino/op/ops.hpp +++ b/src/core/include/openvino/op/ops.hpp @@ -88,6 +88,7 @@ #include "openvino/op/hswish.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/if.hpp" #include "openvino/op/interpolate.hpp" diff --git a/src/core/include/openvino/opsets/opset15_tbl.hpp b/src/core/include/openvino/opsets/opset15_tbl.hpp index 50c8603cf2046c..88be276e102e82 100644 --- a/src/core/include/openvino/opsets/opset15_tbl.hpp +++ b/src/core/include/openvino/opsets/opset15_tbl.hpp @@ -18,3 +18,4 @@ _OPENVINO_OP_REG(ScatterNDUpdate, ov::op::v15) _OPENVINO_OP_REG(EmbeddingBagPacked, ov::op::v15) _OPENVINO_OP_REG(EmbeddingBagOffsets, ov::op::v15) _OPENVINO_OP_REG(Col2Im, ov::op::v15) +_OPENVINO_OP_REG(Identity, ov::op::v15) diff --git a/src/core/reference/include/openvino/reference/identity.hpp b/src/core/reference/include/openvino/reference/identity.hpp new file mode 100644 index 00000000000000..d33c5249a80e8b --- /dev/null +++ b/src/core/reference/include/openvino/reference/identity.hpp @@ -0,0 +1,35 @@ +// Copyright (C) 2018-2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include + +#include "openvino/core/shape.hpp" + +namespace ov { +namespace reference { +namespace identity { + +/** + * @brief Identity operation computes the identity of the input tensor. + * + * @param input Input matrix (matrices) pointer. + * @param output Output matrix (matrices) pointer. + * @param copy Boolean that determines whether to return the input as output or + * copy the input to a new memory address. + **/ +template +void identity(const T** input, T** output, const Shape& shape, const bool copy) { + const auto total_elements = shape_size(shape); + + if (!copy) { + *output = *input; + } else { + std::memcpy(*output, *input, total_elements * sizeof(T)); + } +} +} // namespace identity +} // namespace reference +} // namespace ov diff --git a/src/core/src/op/identity.hpp b/src/core/src/op/identity.hpp new file mode 100644 index 00000000000000..800e5034fa0c30 --- /dev/null +++ b/src/core/src/op/identity.hpp @@ -0,0 +1,49 @@ +// Copyright (C) 2018-2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "itt.hpp" +#include "openvino/core/attribute_visitor.hpp" +#include "openvino/op/identity.hpp" +#include "openvino/op/util/op_types.hpp" +#include "openvino/reference/identity.hpp" + +namespace ov { +namespace op { +namespace v15 { + +Identity::Identity(const Output& data, const bool copy) : Op({data}), m_copy(copy) { + constructor_validate_and_infer_types(); +} + +bool Identity::Identity::visit_attributes(AttributeVisitor& visitor) { + OV_OP_SCOPE(v15_Identity_visit_attributes); + visitor.on_attribute("copy", m_copy); + return true; +} + +void Identity::Identity::validate_and_infer_types() { + OV_OP_SCOPE(v15_Identity_validate_and_infer_types); + + const auto input_shapes = ov::util::get_node_input_partial_shapes(*this); + + set_output_type(0, get_input_element_type(0), input_shapes[0]); +} + +std::shared_ptr Identity::Identity::clone_with_new_inputs(const OutputVector& new_args) const { + OV_OP_SCOPE(v15_Identity_clone_with_new_inputs); + check_new_args_count(this, new_args); + + return std::make_shared(new_args.at(0), m_copy); +} + +bool Identity::get_copy() const { + return m_copy; +} + +void Identity::set_copy(const bool copy) { + m_copy = copy; +} +} // namespace ov diff --git a/src/core/tests/opset.cpp b/src/core/tests/opset.cpp index c63b4759287a2a..c555834e0dab9f 100644 --- a/src/core/tests/opset.cpp +++ b/src/core/tests/opset.cpp @@ -75,7 +75,7 @@ INSTANTIATE_TEST_SUITE_P(opset, OpsetTestParams{ov::get_opset12, 178}, OpsetTestParams{ov::get_opset13, 186}, OpsetTestParams{ov::get_opset14, 188}, - OpsetTestParams{ov::get_opset15, 8}), + OpsetTestParams{ov::get_opset15, 9}), OpsetTestNameGenerator{}); class MyOpOld : public ov::op::Op { diff --git a/src/core/tests/type_prop/identity.cpp b/src/core/tests/type_prop/identity.cpp new file mode 100644 index 00000000000000..8764ecb0e68373 --- /dev/null +++ b/src/core/tests/type_prop/identity.cpp @@ -0,0 +1,28 @@ +// Copyright (C) 2018-2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/op/Identity.hpp" + +#include + +#include "common_test_utils/test_assertions.hpp" +#include "common_test_utils/type_prop.hpp" +#include "openvino/op/constant.hpp" + +using namespace testing; + +class TypePropIdentityV15Test : public TypePropOpTest {}; + +TEST_F(TypePropIdentityV15Test, default_ctor) { + const auto data = ov::op::v0::Constant::create(ov::element::f64, ov::Shape{2, 2}, {1.0f, 1.0f, 1.0f, 1.0f}); + const auto op = make_op(); + op->set_arguments(ov::OutputVector{data}); + op->validate_and_infer_types(); + + EXPECT_EQ(op->get_input_size(), 1); + EXPECT_EQ(op->get_output_size(), 1); + EXPECT_EQ(op->get_output_element_type(0), ov::element::f64); + EXPECT_EQ(op->get_output_partial_shape(0), ov::PartialShape({2, 2})); + EXPECT_EQ(op->get_copy(), false); +} diff --git a/src/core/tests/visitors/op/identity.cpp b/src/core/tests/visitors/op/identity.cpp new file mode 100644 index 00000000000000..ade79b499fd6e2 --- /dev/null +++ b/src/core/tests/visitors/op/identity.cpp @@ -0,0 +1,25 @@ +// Copyright (C) 2018-2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/op/Identity.hpp" + +#include + +#include "openvino/op/unique.hpp" +#include "visitors/visitors.hpp" + +using ov::test::NodeBuilder; + +TEST(attributes, Identity) { + NodeBuilder::opset().insert(); + const auto data = std::make_shared(ov::element::f32, ov::Shape{2, 2}); + + const auto op = std::make_shared(data, true); + NodeBuilder builder(op, {data}); + auto g_identity = ov::as_type_ptr(builder.create()); + + constexpr auto expected_attr_count = 1; + EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); + EXPECT_EQ(op->get_copy(), g_identity->get_copy()); +} diff --git a/src/plugins/template/backend/ops/identity.cpp b/src/plugins/template/backend/ops/identity.cpp new file mode 100644 index 00000000000000..9fab43a2db867d --- /dev/null +++ b/src/plugins/template/backend/ops/identity.cpp @@ -0,0 +1,65 @@ +// Copyright (C) 2018-2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/reference/Identity.hpp" + +#include "Identity_shape_inference.hpp" +#include "evaluate_node.hpp" + +template +inline bool evaluate(const std::shared_ptr& op, + ov::TensorVector& outputs, + const ov::TensorVector& inputs) { + using T = typename ov::element_type_traits::value_type; + + const std::vector input_shapes{op->get_input_shape(0)}; + outputs[0].set_shape(input_shapes[0]); + + ov::reference::Identity(inputs[0].data(), outputs[0].data(), out_shape, op->get_copy()); + return true; +} + +template <> +bool evaluate_node(std::shared_ptr node, + ov::TensorVector& outputs, + const ov::TensorVector& inputs) { + switch (node->get_input_element_type(0)) { + case ov::element::boolean: + return evaluate(ov::as_type_ptr(node), outputs, inputs); + case ov::element::bf16: + return evaluate(ov::as_type_ptr(node), outputs, inputs); + case ov::element::f16: + return evaluate(ov::as_type_ptr(node), outputs, inputs); + case ov::element::f64: + return evaluate(ov::as_type_ptr(node), outputs, inputs); + case ov::element::f32: + return evaluate(ov::as_type_ptr(node), outputs, inputs); + case ov::element::i4: + return evaluate(ov::as_type_ptr(node), outputs, inputs); + case ov::element::i8: + return evaluate(ov::as_type_ptr(node), outputs, inputs); + case ov::element::i16: + return evaluate(ov::as_type_ptr(node), outputs, inputs); + case ov::element::i32: + return evaluate(ov::as_type_ptr(node), outputs, inputs); + case ov::element::i64: + return evaluate(ov::as_type_ptr(node), outputs, inputs); + case ov::element::u1: + return evaluate(ov::as_type_ptr(node), outputs, inputs); + case ov::element::u4: + return evaluate(ov::as_type_ptr(node), outputs, inputs); + case ov::element::u8: + return evaluate(ov::as_type_ptr(node), outputs, inputs); + case ov::element::u16: + return evaluate(ov::as_type_ptr(node), outputs, inputs); + case ov::element::u32: + return evaluate(ov::as_type_ptr(node), outputs, inputs); + case ov::element::u64: + return evaluate(ov::as_type_ptr(node), outputs, inputs); + default: + OPENVINO_THROW("Unhandled input data type ", + node->get_input_element_type(0).get_type_name(), + " in evaluate_node()."); + } +} diff --git a/src/plugins/template/backend/ops/ops_evaluates.hpp b/src/plugins/template/backend/ops/ops_evaluates.hpp index 8e7d24f82092a5..094ada02c18739 100644 --- a/src/plugins/template/backend/ops/ops_evaluates.hpp +++ b/src/plugins/template/backend/ops/ops_evaluates.hpp @@ -510,6 +510,11 @@ extern template bool evaluate_node(std::shared extern template bool evaluate_node(std::shared_ptr node, ov::TensorVector& outputs, const ov::TensorVector& inputs); + +extern template bool evaluate_node(std::shared_ptr node, + ov::TensorVector& outputs, + const ov::TensorVector& inputs); + extern template bool evaluate_node(std::shared_ptr node, ov::TensorVector& outputs, const ov::TensorVector& inputs); diff --git a/src/plugins/template/backend/opset_int_tbl.hpp b/src/plugins/template/backend/opset_int_tbl.hpp index 6174e65f76444c..dad6a26463f7ad 100644 --- a/src/plugins/template/backend/opset_int_tbl.hpp +++ b/src/plugins/template/backend/opset_int_tbl.hpp @@ -164,10 +164,10 @@ _OPENVINO_OP_REG(AvgPool, ov::op::v14) _OPENVINO_OP_REG(MaxPool, ov::op::v14) _OPENVINO_OP_REG(ROIAlignRotated, ov::op::v15) - _OPENVINO_OP_REG(EmbeddingBagOffsets, op::v15) _OPENVINO_OP_REG(EmbeddingBagPacked, op::v15) _OPENVINO_OP_REG(Col2Im, ov::op::v15) +_OPENVINO_OP_REG(Identity, ov::op::v15) _OPENVINO_OP_REG(AUGRUCell, ov::op::internal) _OPENVINO_OP_REG(AUGRUSequence, ov::op::internal) diff --git a/src/plugins/template/tests/functional/op_reference/identity.cpp b/src/plugins/template/tests/functional/op_reference/identity.cpp new file mode 100644 index 00000000000000..405fd45e42cf50 --- /dev/null +++ b/src/plugins/template/tests/functional/op_reference/identity.cpp @@ -0,0 +1,121 @@ +// Copyright (C) 2018-2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/op/identity.hpp" + +#include "base_reference_test.hpp" +#include "gtest/gtest.h" +#include "openvino/op/parameter.hpp" + +namespace { +struct IdentityParams { + IdentityParams(const reference_tests::Tensor& matrices, bool copy, std::string name) + : matrices{matrices}, + copy(copy), + test_case_name{std::move(name)} {} + + reference_tests::Tensor matrices; + bool copy; + std::string test_case_name; +}; + +class ReferenceIdentity : public testing::TestWithParam, public reference_tests::CommonReferenceTest { +public: + void SetUp() override { + const auto& params = GetParam(); + function = CreateFunction(params); + inputData = {params.matrices.data}; + refOutData = {params.matrices.data}; + m_copy = params.copy; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + std::ostringstream name; + name << obj.param.test_case_name; + name << "_input_type_"; + name << obj.param.matrices.type; + name << "_shape_"; + name << obj.param.matrices.shape; + name << "_copy_"; + name << obj.param.copy; + return name.str(); + } + + void Validate() { + CommonReferenceTest::Validate(); + + bool pointers_match = refOutData[0].data() == actualOutData[0].data(); + ASSERT_EQ(pointers_match, !m_copy); + } + +private: + static std::shared_ptr CreateFunction(const IdentityParams& params) { + const auto in_matrices = std::make_shared(params.matrices.type, params.matrices.shape); + const auto identity = std::make_shared(in_matrices, params.copy); + return std::make_shared(identity->outputs(), ov::ParameterVector{in_matrices}); + } + + bool m_copy; +}; + +template +std::vector generateIdentityParams() { + using VT = typename ov::element_type_traits::value_type; + + const ov::Shape matrices_2_2_shape{2, 2}; + const ov::Shape matrices_2_3_3_shape{2, 3, 3}; + + reference_tests::Tensor matrices_2_2(matrices_2_2_shape, ET, std::vector{0.5f, 1.0f, 3.0f, 2.0f}); + + reference_tests::Tensor matrices_2_3_3(matrices_2_3_3_shape, + ET, + std::vector{2.0f, + -1.0f, + 0.0f, + -1.0f, + 2.0f, + -1.0f, + 0.0f, + -1.0f, + 2.0f, + + 3.0f, + 1.0f, + 2.0f, + 0.0f, + 4.0f, + 1.0f, + 2.0f, + -2.0f, + 0.0f}); + + std::vector params; + params.emplace_back(matrices_2_2, false, "single_simple"); + params.emplace_back(matrices_2_2, true, "single_simple"); + params.emplace_back(matrices_2_3_3, false, "many_simple"); + params.emplace_back(matrices_2_3_3, true, "many_simple"); + + return params; +} + +std::vector generateIdentityParams() { + std::vector> combo_params{generateIdentityParams(), + generateIdentityParams(), + generateIdentityParams(), + generateIdentityParams()}; + std::vector test_params; + for (auto& params : combo_params) + std::move(params.begin(), params.end(), std::back_inserter(test_params)); + return test_params; +} +} // namespace + +TEST_P(ReferenceIdentity, CompareWithRefs) { + Exec(); +} + +INSTANTIATE_TEST_SUITE_P(smoke, + ReferenceIdentity, + ::testing::ValuesIn(generateIdentityParams()), + ReferenceIdentity::getTestCaseName); diff --git a/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/op_impl_check/single_op_graph.cpp b/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/op_impl_check/single_op_graph.cpp index 98c3d234914be8..d3e043d5bfe570 100644 --- a/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/op_impl_check/single_op_graph.cpp +++ b/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/op_impl_check/single_op_graph.cpp @@ -525,6 +525,13 @@ std::shared_ptr generate(const std::shared_ptr(results, params, "Interpolat-1"); } +std::shared_ptr generate(const std::shared_ptr& node) { + ov::ParameterVector params{std::make_shared(ov::element::f32, ov::Shape{4, 4, 4})}; + const auto identity = std::make_shared(params[0], false); + ov::ResultVector results{std::make_shared(identity)}; + return std::make_shared(results, params, "Identity"); +} + std::shared_ptr generate(const std::shared_ptr &node) { using InterpolateAttrs = op::v4::Interpolate::InterpolateAttrs; using InterpolateMode = op::v4::Interpolate::InterpolateMode; diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/identity.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/identity.hpp new file mode 100644 index 00000000000000..5ad551569fdf17 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/identity.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/identity.hpp" + +namespace ov { +namespace test { +TEST_P(IdentityLayerTest, Inference) { + run(); +}; +} // namespace test +} // namespace ov From 1d8ee20109193ed95f134c0808365f9349f82123 Mon Sep 17 00:00:00 2001 From: Roboreptile Date: Fri, 20 Sep 2024 19:12:16 +0000 Subject: [PATCH 2/4] [ADD] Remaining dtypes for tests --- .../include/openvino/opsets/opset15_tbl.hpp | 1 - .../functional/op_reference/identity.cpp | 19 ++++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/core/include/openvino/opsets/opset15_tbl.hpp b/src/core/include/openvino/opsets/opset15_tbl.hpp index b411e36cd4ca36..e14697b385fe53 100644 --- a/src/core/include/openvino/opsets/opset15_tbl.hpp +++ b/src/core/include/openvino/opsets/opset15_tbl.hpp @@ -25,4 +25,3 @@ _OPENVINO_OP_REG(BitwiseLeftShift, ov::op::v15) _OPENVINO_OP_REG(BitwiseRightShift, ov::op::v15) _OPENVINO_OP_REG(SliceScatter, ov::op::v15) _OPENVINO_OP_REG(Identity, ov::op::v15) - diff --git a/src/plugins/template/tests/functional/op_reference/identity.cpp b/src/plugins/template/tests/functional/op_reference/identity.cpp index 524bc674dbb2e9..a5a2e51e751ce7 100644 --- a/src/plugins/template/tests/functional/op_reference/identity.cpp +++ b/src/plugins/template/tests/functional/op_reference/identity.cpp @@ -100,13 +100,22 @@ std::vector generateIdentityParams() { } std::vector generateIdentityParams() { - std::vector> combo_params{generateIdentityParams(), - generateIdentityParams(), - generateIdentityParams(), + std::vector> combo_params{generateIdentityParams(), generateIdentityParams(), - generateIdentityParams(), + generateIdentityParams(), + generateIdentityParams(), + generateIdentityParams(), + generateIdentityParams(), + generateIdentityParams(), + generateIdentityParams(), generateIdentityParams(), - generateIdentityParams()}; + generateIdentityParams(), + generateIdentityParams(), + generateIdentityParams(), + generateIdentityParams(), + generateIdentityParams(), + generateIdentityParams(), + generateIdentityParams()}; std::vector test_params; for (auto& params : combo_params) std::move(params.begin(), params.end(), std::back_inserter(test_params)); From 850b37446af3b88d68083986c67ddeda2c37d92f Mon Sep 17 00:00:00 2001 From: Roboreptile Date: Fri, 20 Sep 2024 19:19:25 +0000 Subject: [PATCH 3/4] [ADD] Python API for Identity --- .../src/openvino/runtime/opset15/__init__.py | 2 ++ .../src/openvino/runtime/opset15/ops.py | 23 ++++++++++++++ .../python/tests/test_graph/test_identity.py | 30 +++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 src/bindings/python/tests/test_graph/test_identity.py diff --git a/src/bindings/python/src/openvino/runtime/opset15/__init__.py b/src/bindings/python/src/openvino/runtime/opset15/__init__.py index 1349508e84b381..aadfde1d43f204 100644 --- a/src/bindings/python/src/openvino/runtime/opset15/__init__.py +++ b/src/bindings/python/src/openvino/runtime/opset15/__init__.py @@ -15,3 +15,5 @@ from openvino.runtime.opset15.ops import string_tensor_unpack from openvino.runtime.opset15.ops import bitwise_left_shift from openvino.runtime.opset15.ops import bitwise_right_shift +from openvino.runtime.opset15.ops import identity + diff --git a/src/bindings/python/src/openvino/runtime/opset15/ops.py b/src/bindings/python/src/openvino/runtime/opset15/ops.py index 777fc165443f7f..96a410212def4e 100644 --- a/src/bindings/python/src/openvino/runtime/opset15/ops.py +++ b/src/bindings/python/src/openvino/runtime/opset15/ops.py @@ -251,6 +251,29 @@ def bitwise_left_shift( ) +@nameable_op +def bitwise_right_shift( + data: NodeInput, + copy: bool = False, + name: Optional[str] = None, +) -> Node: + """Identity operation is used as a placeholder. It either passes down the input, + or creates a copy of the input to forward to the output. + + :param data: Tensor with data. + :param copy: Boolean that defines the behavior of Identity. If false, input is passed as output, otherwise, a copy of input is created. Defaults to False. + + :return: The new node performing BitwiseRightShift operation. + """ + return _get_node_factory_opset15().create( + "Identity", + as_nodes(data, name=name), + { + "copy": copy, + }, + ) + + @binary_op def bitwise_right_shift( arg0: NodeInput, diff --git a/src/bindings/python/tests/test_graph/test_identity.py b/src/bindings/python/tests/test_graph/test_identity.py new file mode 100644 index 00000000000000..70720be0c381a7 --- /dev/null +++ b/src/bindings/python/tests/test_graph/test_identity.py @@ -0,0 +1,30 @@ +# Copyright (C) 2018-2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import numpy as np +import pytest + +import openvino.runtime.opset14 as ops +from openvino import PartialShape, Type + + +@pytest.mark.parametrize( + ("input_shape", "copy", "expected_output_shape"), + [ + ([4, 4], False, PartialShape([4, 4])), + ([10, 8, 8], True, PartialShape([10, 8, 8])), + ([-1, -1, -1], True, PartialShape([-1, -1, -1])), + ([10, -1, -1], True, PartialShape([10, -1, -1])), + ], +) +@pytest.mark.parametrize("op_name", ["identity", "identityOpset15"]) +def test_inverse_param_inputs(input_shape, copy, expected_output_shape, op_name): + data = ops.parameter(input_shape, dtype=np.float32) + + op = ops.inverse(data, copy=copy, name=op_name) + assert op.get_output_size() == 1 + assert op.get_type_name() == "Identity" + assert op.get_friendly_name() == op_name + assert op.get_output_element_type(0) == Type.f32 + assert op.get_output_partial_shape(0) == expected_output_shape + From 6d2a872bdfd02857336d9dfa53234c8ae3f5fe8d Mon Sep 17 00:00:00 2001 From: Roboreptile Date: Fri, 20 Sep 2024 19:39:04 +0000 Subject: [PATCH 4/4] [ADD] Opset15, Identity specification --- .../operation-sets/available-opsets.rst | 3 + .../available-opsets/opset15.rst | 206 ++++++++++++++++++ .../operation-sets/operation-specs.rst | 1 + .../activation/identity-15.rst | 66 ++++++ 4 files changed, 276 insertions(+) create mode 100644 docs/articles_en/documentation/openvino-ir-format/operation-sets/available-opsets/opset15.rst create mode 100644 docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/activation/identity-15.rst diff --git a/docs/articles_en/documentation/openvino-ir-format/operation-sets/available-opsets.rst b/docs/articles_en/documentation/openvino-ir-format/operation-sets/available-opsets.rst index a3028755299b45..41becb1a69fd97 100644 --- a/docs/articles_en/documentation/openvino-ir-format/operation-sets/available-opsets.rst +++ b/docs/articles_en/documentation/openvino-ir-format/operation-sets/available-opsets.rst @@ -10,6 +10,7 @@ Available Operation Sets :maxdepth: 1 :hidden: + available-opsets/opset15 available-opsets/opset14 available-opsets/opset13 available-opsets/opset12 @@ -35,6 +36,8 @@ This topic provides a complete list of available sets of operations supported in * - OpenVINO™ Version - Actual Operations Set + * - 2024.5 + - :doc:`opset15 ` * - 2024.0 - :doc:`opset14 ` * - 2023.2 diff --git a/docs/articles_en/documentation/openvino-ir-format/operation-sets/available-opsets/opset15.rst b/docs/articles_en/documentation/openvino-ir-format/operation-sets/available-opsets/opset15.rst new file mode 100644 index 00000000000000..65f630cd2358b3 --- /dev/null +++ b/docs/articles_en/documentation/openvino-ir-format/operation-sets/available-opsets/opset15.rst @@ -0,0 +1,206 @@ +opset14 +======= + + +.. meta:: + :description: Explore the examples of operation instances expressed as IR + XML snippets in the opset14 operation set, supported in OpenVINO™ + toolkit. + +This specification document describes the ``opset14`` operation set supported in OpenVINO™. +Support for each particular operation from the list below depends on the capabilities of an inference plugin +and may vary among different hardware platforms and devices. Examples of operation instances are provided as IR xml +snippets. The semantics match corresponding OpenVINO operation classes declared in ``namespace opset14``. + + +Table of Contents +################## + +* :doc:`Abs <../operation-specs/arithmetic/abs-1>` +* :doc:`Acos <../operation-specs/arithmetic/acos-1>` +* :doc:`Acosh <../operation-specs/arithmetic/acosh-3>` +* :doc:`AdaptiveAvgPool <../operation-specs/pooling/adaptive-avg-pool-8>` +* :doc:`AdaptiveMaxPool <../operation-specs/pooling/adaptive-max-pool-8>` +* :doc:`Add <../operation-specs/arithmetic/add-1>` +* :doc:`Asin <../operation-specs/arithmetic/asin-1>` +* :doc:`Asinh <../operation-specs/arithmetic/asinh-3>` +* :doc:`Assign <../operation-specs/infrastructure/assign-3>` +* :doc:`Atan <../operation-specs/arithmetic/atan-1>` +* :doc:`Atanh <../operation-specs/arithmetic/atanh-3>` +* :doc:`AvgPool <../operation-specs/pooling/avg-pool-14>` +* :doc:`BatchNormInference <../operation-specs/normalization/batch-norm-inference-5>` +* :doc:`BatchToSpace <../operation-specs/movement/batch-to-space-2>` +* :doc:`BinaryConvolution <../operation-specs/convolution/binary-convolution-1>` +* :doc:`BitwiseAnd <../operation-specs/bitwise/bitwise-and-13>` +* :doc:`BitwiseOr <../operation-specs/bitwise/bitwise-or-13>` +* :doc:`BitwiseXor <../operation-specs/bitwise/bitwise-xor-13>` +* :doc:`BitwiseNot <../operation-specs/bitwise/bitwise-not-13>` +* :doc:`Broadcast <../operation-specs/movement/broadcast-3>` +* :doc:`Bucketize <../operation-specs/condition/bucketize-3>` +* :doc:`CTCGreedyDecoder <../operation-specs/sequence/ctc-greedy-decoder-1>` +* :doc:`CTCGreedyDecoderSeqLen <../operation-specs/sequence/ctc-greedy-decoder-seq-len-6>` +* :doc:`CTCLoss <../operation-specs/sequence/ctc-loss-4>` +* :doc:`Ceiling <../operation-specs/arithmetic/ceiling-1>` +* :doc:`Clamp <../operation-specs/activation/clamp-1>` +* :doc:`Concat <../operation-specs/movement/concat-1>` +* :doc:`Constant <../operation-specs/infrastructure/constant-1>` +* :doc:`Convert <../operation-specs/type/convert-1>` +* :doc:`ConvertLike <../operation-specs/type/convert-like-1>` +* :doc:`ConvertPromoteTypes <../operation-specs/type/convert-promote-types-14>` +* :doc:`Convolution <../operation-specs/convolution/convolution-1>` +* :doc:`ConvolutionBackpropData <../operation-specs/convolution/convolution-backprop-data-1>` +* :doc:`Cos <../operation-specs/arithmetic/cos-1>` +* :doc:`Cosh <../operation-specs/arithmetic/cosh-1>` +* :doc:`CumSum <../operation-specs/arithmetic/cumsum-3>` +* :doc:`DeformableConvolution <../operation-specs/convolution/deformable-convolution-8>` +* :doc:`DeformablePSROIPooling <../operation-specs/detection/deformable-psroi-pooling-1>` +* :doc:`DepthToSpace <../operation-specs/movement/depth-to-space-1>` +* :doc:`DetectionOutput <../operation-specs/detection/detectionoutput-8>` +* :doc:`DFT <../operation-specs/signals/dft-7>` +* :doc:`Divide <../operation-specs/arithmetic/divide-1>` +* :doc:`Einsum <../operation-specs/matrix/einsum-7>` +* :doc:`Elu <../operation-specs/activation/elu-1>` +* :doc:`EmbeddingBagOffsetsSum <../operation-specs/sparse/embedding-bag-offsets-sum-3>` +* :doc:`EmbeddingBagPackedSum <../operation-specs/sparse/embedding-bag-packed-sum-3>` +* :doc:`EmbeddingSegmentsSum <../operation-specs/sparse/embedding-segments-sum-3>` +* :doc:`Equal <../operation-specs/comparison/equal-1>` +* :doc:`Erf <../operation-specs/arithmetic/erf-1>` +* :doc:`Exp <../operation-specs/activation/exp-1>` +* :doc:`ExperimentalDetectronDetectionOutput_6 <../operation-specs/detection/experimental-detectron-detection-output-6>` +* :doc:`ExperimentalDetectronGenerateProposalsSingleImage_6 <../operation-specs/detection/experimental-detectron-generate-proposals-single-image-6>` +* :doc:`ExperimentalDetectronPriorGridGenerator_6 <../operation-specs/detection/experimental-detectron-prior-grid-generator-6>` +* :doc:`ExperimentalDetectronROIFeatureExtractor_6 <../operation-specs/detection/experimental-detectron-roi-feature-extractor-6>` +* :doc:`ExperimentalDetectronTopKROIs_6 <../operation-specs/sort/experimental-detectron-top-krois-6>` +* :doc:`ExtractImagePatches <../operation-specs/movement/extract-image-patches-3>` +* :doc:`Eye <../operation-specs/generation/eye-9>` +* :doc:`FakeConvert <../operation-specs/quantization/fake-convert-13>` +* :doc:`FakeQuantize <../operation-specs/quantization/fake-quantize-1>` +* :doc:`Floor <../operation-specs/arithmetic/floor-1>` +* :doc:`FloorMod <../operation-specs/arithmetic/floormod-1>` +* :doc:`Gather <../operation-specs/movement/gather-8>` +* :doc:`GatherElements <../operation-specs/movement/gather-elements-6>` +* :doc:`GatherND <../operation-specs/movement/gather-nd-8>` +* :doc:`GatherTree <../operation-specs/movement/gather-tree-1>` +* :doc:`Gelu <../operation-specs/activation/gelu-7>` +* :doc:`GenerateProposals <../operation-specs/detection/generate-proposals-9>` +* :doc:`Greater <../operation-specs/comparison/greater-1>` +* :doc:`GreaterEqual <../operation-specs/comparison/greater-equal-1>` +* :doc:`GridSample <../operation-specs/image/grid-sample-9>` +* :doc:`GRN <../operation-specs/normalization/grn-1>` +* :doc:`GroupConvolution <../operation-specs/convolution/group-convolution-1>` +* :doc:`GroupConvolutionBackpropData <../operation-specs/convolution/group-convolution-backprop-data-1>` +* :doc:`GroupNormalization <../operation-specs/normalization/group-normalization-12>` +* :doc:`GRUCell <../operation-specs/sequence/gru-cell-3>` +* :doc:`GRUSequence <../operation-specs/sequence/gru-sequence-5>` +* :doc:`HardSigmoid <../operation-specs/activation/hard-sigmoid-1>` +* :doc:`HSigmoid <../operation-specs/activation/hsigmoid-5>` +* :doc:`HSwish <../operation-specs/activation/hswish-4>` +* :doc:`Identity <../operation-specs/activation/identity-15>` +* :doc:`IDFT <../operation-specs/signals/idft-7>` +* :doc:`I420toBGR <../operation-specs/image/i420-to-bgr-8>` +* :doc:`I420toRGB <../operation-specs/image/i420-to-rgb-8>` +* :doc:`If <../operation-specs/condition/if-8>` +* :doc:`Interpolate <../operation-specs/image/interpolate-11>` +* :doc:`Inverse <../operation-specs/matrix/inverse-14>` +* :doc:`IRDFT <../operation-specs/signals/irdft-9>` +* :doc:`IsInf <../operation-specs/comparison/isinf-10>` +* :doc:`IsNaN <../operation-specs/comparison/isnan-10>` +* :doc:`Less <../operation-specs/comparison/less-1>` +* :doc:`LessEqual <../operation-specs/comparison/lessequal-1>` +* :doc:`Log <../operation-specs/arithmetic/log-1>` +* :doc:`LogicalAnd <../operation-specs/logical/logical-and-1>` +* :doc:`LogicalNot <../operation-specs/logical/logical-not-1>` +* :doc:`LogicalOr <../operation-specs/logical/logical-or-1>` +* :doc:`LogicalXor <../operation-specs/logical/logical-xor-1>` +* :doc:`LogSoftmax <../operation-specs/activation/log-soft-max-5>` +* :doc:`Loop <../operation-specs/infrastructure/loop-5>` +* :doc:`LRN <../operation-specs/normalization/lrn-1>` +* :doc:`LSTMCell <../operation-specs/sequence/lstm-cell-1>` +* :doc:`LSTMSequence <../operation-specs/sequence/lstm-sequence-1>` +* :doc:`MatMul <../operation-specs/matrix/matmul-1>` +* :doc:`MatrixNMS <../operation-specs/sort/matrix-non-max-suppression-8>` +* :doc:`MaxPool <../operation-specs/pooling/max-pool-14>` +* :doc:`Maximum <../operation-specs/arithmetic/maximum-1>` +* :doc:`Minimum <../operation-specs/arithmetic/minimum-1>` +* :doc:`Mish <../operation-specs/activation/mish-4>` +* :doc:`Mod <../operation-specs/arithmetic/mod-1>` +* :doc:`MVN <../operation-specs/normalization/mvn-6>` +* :doc:`MulticlassNMS <../operation-specs/sort/multiclass-non-max-suppression-9>` +* :doc:`Multinomial <../operation-specs/generation/multinomial-13>` +* :doc:`Multiply <../operation-specs/arithmetic/multiply-1>` +* :doc:`Negative <../operation-specs/arithmetic/negative-1>` +* :doc:`NMSRotated <../operation-specs/sort/nms-rotated-13>` +* :doc:`NonMaxSuppression <../operation-specs/sort/non-max-suppression-9>` +* :doc:`NonZero <../operation-specs/condition/nonzero-3>` +* :doc:`NormalizeL2 <../operation-specs/normalization/normalize-l2-1>` +* :doc:`NotEqual <../operation-specs/comparison/notequal-1>` +* :doc:`NV12toBGR <../operation-specs/image/nv12-to-bgr-8>` +* :doc:`NV12toRGB <../operation-specs/image/nv12-to-rgb-8>` +* :doc:`OneHot <../operation-specs/sequence/one-hot-1>` +* :doc:`Pad <../operation-specs/movement/pad-12>` +* :doc:`Parameter <../operation-specs/infrastructure/parameter-1>` +* :doc:`Power <../operation-specs/arithmetic/power-1>` +* :doc:`PReLU <../operation-specs/activation/prelu-1>` +* :doc:`PriorBoxClustered <../operation-specs/detection/prior-box-clustered-1>` +* :doc:`PriorBox <../operation-specs/detection/prior-box-8>` +* :doc:`Proposal <../operation-specs/detection/proposal-4>` +* :doc:`PSROIPooling <../operation-specs/detection/psroi-pooling-1>` +* :doc:`RandomUniform <../operation-specs/generation/random-uniform-8>` +* :doc:`Range <../operation-specs/generation/range-4>` +* :doc:`RDFT <../operation-specs/signals/rdft-9>` +* :doc:`ReLU <../operation-specs/activation/relu-1>` +* :doc:`ReadValue <../operation-specs/infrastructure/read-value-3>` +* :doc:`ReduceL1 <../operation-specs/reduction/reduce-l1-4>` +* :doc:`ReduceL2 <../operation-specs/reduction/reduce-l2-4>` +* :doc:`ReduceLogicalAnd <../operation-specs/reduction/reduce-logical-and-1>` +* :doc:`ReduceLogicalOr <../operation-specs/reduction/reduce-logical-or-1>` +* :doc:`ReduceMax <../operation-specs/reduction/reduce-max-1>` +* :doc:`ReduceMean <../operation-specs/reduction/reduce-mean-1>` +* :doc:`ReduceMin <../operation-specs/reduction/reduce-min-1>` +* :doc:`ReduceProd <../operation-specs/reduction/reduce-prod-1>` +* :doc:`ReduceSum <../operation-specs/reduction/reduce-sum-1>` +* :doc:`RegionYolo <../operation-specs/detection/region-yolo-1>` +* :doc:`ReorgYolo <../operation-specs/detection/reorg-yolo-1>` +* :doc:`Reshape <../operation-specs/shape/reshape-1>` +* :doc:`Result <../operation-specs/infrastructure/result-1>` +* :doc:`ReverseSequence <../operation-specs/movement/reverse-sequence-1>` +* :doc:`RNNCell <../operation-specs/sequence/rnn-cell-3>` +* :doc:`RNNSequence <../operation-specs/sequence/rnn-sequence-5>` +* :doc:`ROIAlign <../operation-specs/detection/roi-align-9>` +* :doc:`ROIPooling <../operation-specs/detection/roi-pooling-1>` +* :doc:`Roll <../operation-specs/movement/roll-7>` +* :doc:`Round <../operation-specs/arithmetic/round-5>` +* :doc:`ScaledDotProductAttention <../operation-specs/sequence/scaled-dot-product-attention>` +* :doc:`ScatterElementsUpdate <../operation-specs/movement/scatter-elements-update-12>` +* :doc:`ScatterNDUpdate <../operation-specs/movement/scatter-nd-update-3>` +* :doc:`ScatterUpdate <../operation-specs/movement/scatter-update-3>` +* :doc:`Select <../operation-specs/condition/select-1>` +* :doc:`Selu <../operation-specs/activation/selu-1>` +* :doc:`ShapeOf <../operation-specs/shape/shape-of-3>` +* :doc:`ShuffleChannels <../operation-specs/movement/shuffle-channels-1>` +* :doc:`Sigmoid <../operation-specs/activation/sigmoid-1>` +* :doc:`Sign <../operation-specs/arithmetic/sign-1>` +* :doc:`Sin <../operation-specs/arithmetic/sin-1>` +* :doc:`Sinh <../operation-specs/arithmetic/sinh-1>` +* :doc:`Slice <../operation-specs/movement/slice-8>` +* :doc:`SoftMax <../operation-specs/activation/softmax-8>` +* :doc:`SoftPlus <../operation-specs/activation/softplus-4>` +* :doc:`SoftSign <../operation-specs/activation/softsign-9>` +* :doc:`SpaceToBatch <../operation-specs/movement/space-to-batch-2>` +* :doc:`SpaceToDepth <../operation-specs/movement/space-to-depth-1>` +* :doc:`Split <../operation-specs/movement/split-1>` +* :doc:`Sqrt <../operation-specs/arithmetic/sqrt-1>` +* :doc:`SquaredDifference <../operation-specs/arithmetic/squared-difference-1>` +* :doc:`Squeeze <../operation-specs/shape/squeeze-1>` +* :doc:`StridedSlice <../operation-specs/movement/strided-slice-1>` +* :doc:`Subtract <../operation-specs/arithmetic/subtract-1>` +* :doc:`Swish <../operation-specs/activation/swish-4>` +* :doc:`Tan <../operation-specs/arithmetic/tan-1>` +* :doc:`Tanh <../operation-specs/arithmetic/tanh-1>` +* :doc:`TensorIterator <../operation-specs/infrastructure/tensor-iterator-1>` +* :doc:`Tile <../operation-specs/movement/tile-1>` +* :doc:`TopK <../operation-specs/sort/top-k-11>` +* :doc:`Transpose <../operation-specs/movement/transpose-1>` +* :doc:`Unique <../operation-specs/movement/unique-10>` +* :doc:`Unsqueeze <../operation-specs/shape/unsqueeze-1>` +* :doc:`VariadicSplit <../operation-specs/movement/variadic-split-1>` diff --git a/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs.rst b/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs.rst index 2d03cf7cdce069..0d762c28faf684 100644 --- a/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs.rst +++ b/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs.rst @@ -99,6 +99,7 @@ Operation Specifications HardSigmoid-1 HSigmoid-5 HSwish-4 + Identity-15 I420toBGR-8 I420toRGB-8 IDFT-7 diff --git a/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/activation/identity-15.rst b/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/activation/identity-15.rst new file mode 100644 index 00000000000000..9bdddb2d360374 --- /dev/null +++ b/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/activation/identity-15.rst @@ -0,0 +1,66 @@ +Identity +======= + + +.. meta:: + :description: Learn about Identity-15 - a simple operation that forwards the input to the output. + +**Versioned name**: *Identity-15* + +**Category**: *Matrix* + +**Short description**: *Identity* operation forwards the input as the output, essentially computing the4 linear activation function f(x) = x. + +**Detailed description**: *Identity* operation either directly outputs the input, or returns a new Tensor with the same shape, data type and data as the input. + +This behavior is targeted to mimic the design of PyTorch and Tensorflow frameworks. PyTorch by design returns the reference of the input, whereas Tensorflow creates a copy of the input. + +Copy operation is significantly more memory- and computationally-heavy. + +**Attribute**: + +* *copy* + + * **Description**: Modifies the behavior of Identity. If false, input is passed as the output, keeping the same memory adress. If true, a copy of input is created and returned as input. + * **Range of values**: `true`, `false` + + * ``true`` - returned value is a copy of the input. Significantly slower. + * ``false`` - returned value is the input itself. + + * **Type**: `bool` + * **Default value**: `false` + * **Required**: *No* + +**Input**: + +* **1**: `input` - A tensor of any shape and type `T`. **Required.** + +**Output**: + +* **1**: `output` - A tensor with the same shape and type `T` as the input, containing the same data as the input. + +**Types** + +* **T**: any supported data type. + +*Example 1: 2D input matrix.* + +.. code-block:: xml + :force: + + + + + + 3 + 3 + + + + + 3 + 3 + + + +