forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a904d9b
commit 0cb3885
Showing
14 changed files
with
393 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Node>& data, const bool copy = false); | ||
|
||
bool visit_attributes(AttributeVisitor& visitor) override; | ||
void validate_and_infer_types() override; | ||
std::shared_ptr<Node> 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/core/reference/include/openvino/reference/identity.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include <cstring> | ||
|
||
#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 <typename T> | ||
void identity(const T** input, T** output, const Shape& shape, const bool copy) { | ||
const auto total_elements = shape_size<Shape>(shape); | ||
|
||
if (!copy) { | ||
*output = *input; | ||
} else { | ||
std::memcpy(*output, *input, total_elements * sizeof(T)); | ||
} | ||
} | ||
} // namespace identity | ||
} // namespace reference | ||
} // namespace ov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include <cstring> | ||
|
||
#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<Node>& 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<Node> 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<Identity>(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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "openvino/op/Identity.hpp" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#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<ov::op::v15::Identity> {}; | ||
|
||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "openvino/op/Identity.hpp" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "openvino/op/unique.hpp" | ||
#include "visitors/visitors.hpp" | ||
|
||
using ov::test::NodeBuilder; | ||
|
||
TEST(attributes, Identity) { | ||
NodeBuilder::opset().insert<ov::op::v15::Identity>(); | ||
const auto data = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{2, 2}); | ||
|
||
const auto op = std::make_shared<ov::op::v15::Identity>(data, true); | ||
NodeBuilder builder(op, {data}); | ||
auto g_identity = ov::as_type_ptr<ov::op::v15::Identity>(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()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <ov::element::Type_t ET> | ||
inline bool evaluate(const std::shared_ptr<ov::op::v15::Identity>& op, | ||
ov::TensorVector& outputs, | ||
const ov::TensorVector& inputs) { | ||
using T = typename ov::element_type_traits<ET>::value_type; | ||
|
||
const std::vector<ov::PartialShape> input_shapes{op->get_input_shape(0)}; | ||
outputs[0].set_shape(input_shapes[0]); | ||
|
||
ov::reference::Identity<T>(inputs[0].data<const T>(), outputs[0].data<T>(), out_shape, op->get_copy()); | ||
return true; | ||
} | ||
|
||
template <> | ||
bool evaluate_node<ov::op::v15::Identity>(std::shared_ptr<ov::Node> node, | ||
ov::TensorVector& outputs, | ||
const ov::TensorVector& inputs) { | ||
switch (node->get_input_element_type(0)) { | ||
case ov::element::boolean: | ||
return evaluate<ov::element::boolean>(ov::as_type_ptr<ov::op::v15::Identity>(node), outputs, inputs); | ||
case ov::element::bf16: | ||
return evaluate<ov::element::bf16>(ov::as_type_ptr<ov::op::v15::Identity>(node), outputs, inputs); | ||
case ov::element::f16: | ||
return evaluate<ov::element::f16>(ov::as_type_ptr<ov::op::v15::Identity>(node), outputs, inputs); | ||
case ov::element::f64: | ||
return evaluate<ov::element::f64>(ov::as_type_ptr<ov::op::v15::Identity>(node), outputs, inputs); | ||
case ov::element::f32: | ||
return evaluate<ov::element::f32>(ov::as_type_ptr<ov::op::v15::Identity>(node), outputs, inputs); | ||
case ov::element::i4: | ||
return evaluate<ov::element::i4>(ov::as_type_ptr<ov::op::v15::Identity>(node), outputs, inputs); | ||
case ov::element::i8: | ||
return evaluate<ov::element::i8>(ov::as_type_ptr<ov::op::v15::Identity>(node), outputs, inputs); | ||
case ov::element::i16: | ||
return evaluate<ov::element::i16>(ov::as_type_ptr<ov::op::v15::Identity>(node), outputs, inputs); | ||
case ov::element::i32: | ||
return evaluate<ov::element::i32>(ov::as_type_ptr<ov::op::v15::Identity>(node), outputs, inputs); | ||
case ov::element::i64: | ||
return evaluate<ov::element::i64>(ov::as_type_ptr<ov::op::v15::Identity>(node), outputs, inputs); | ||
case ov::element::u1: | ||
return evaluate<ov::element::u1>(ov::as_type_ptr<ov::op::v15::Identity>(node), outputs, inputs); | ||
case ov::element::u4: | ||
return evaluate<ov::element::u4>(ov::as_type_ptr<ov::op::v15::Identity>(node), outputs, inputs); | ||
case ov::element::u8: | ||
return evaluate<ov::element::u8>(ov::as_type_ptr<ov::op::v15::Identity>(node), outputs, inputs); | ||
case ov::element::u16: | ||
return evaluate<ov::element::u16>(ov::as_type_ptr<ov::op::v15::Identity>(node), outputs, inputs); | ||
case ov::element::u32: | ||
return evaluate<ov::element::u32>(ov::as_type_ptr<ov::op::v15::Identity>(node), outputs, inputs); | ||
case ov::element::u64: | ||
return evaluate<ov::element::u64>(ov::as_type_ptr<ov::op::v15::Identity>(node), outputs, inputs); | ||
default: | ||
OPENVINO_THROW("Unhandled input data type ", | ||
node->get_input_element_type(0).get_type_name(), | ||
" in evaluate_node()."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.