Skip to content

Commit

Permalink
[FIX] Apply review ideas
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrKrzem committed Oct 18, 2024
1 parent f6074cd commit 540a07c
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 102 deletions.
1 change: 0 additions & 1 deletion src/core/include/openvino/opsets/opset15_tbl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ _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(STFT, ov::op::v15)
_OPENVINO_OP_REG(StringTensorUnpack, ov::op::v15)
_OPENVINO_OP_REG(StringTensorPack, ov::op::v15)
Expand Down
7 changes: 1 addition & 6 deletions src/core/reference/include/openvino/reference/identity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,16 @@

#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.
**/
void identity(const char* input, char* output, const size_t size_in_bytes) {
static inline void identity(const char* input, char* output, const size_t size_in_bytes) {
std::memcpy(output, input, size_in_bytes);
}
} // namespace identity
} // namespace reference
} // namespace ov
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "openvino/op/identity.hpp"

#include <cstring>

#include "itt.hpp"
#include "openvino/core/attribute_visitor.hpp"
#include "openvino/op/identity.hpp"
#include "openvino/core/validation_util.hpp"
#include "openvino/op/util/op_types.hpp"
#include "openvino/reference/identity.hpp"

Expand Down Expand Up @@ -37,4 +39,6 @@ std::shared_ptr<Node> Identity::Identity::clone_with_new_inputs(const OutputVect

return std::make_shared<Identity>(new_args.at(0));
}
} // namespace v15
} // namespace op
} // namespace ov
17 changes: 11 additions & 6 deletions src/core/tests/type_prop/identity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "openvino/op/Identity.hpp"
#include "openvino/op/identity.hpp"

#include <gtest/gtest.h>

Expand All @@ -12,16 +12,21 @@

using namespace testing;

class TypePropIdentityV15Test : public TypePropOpTest<ov::op::v15::Identity> {};
namespace ov {
namespace test {

class TypePropIdentityV15Test : public TypePropOpTest<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 data = op::v0::Constant::create(element::f64, Shape{2, 2}, {1.0f, 1.0f, 1.0f, 1.0f});
const auto op = make_op();
op->set_arguments(ov::OutputVector{data});
op->set_arguments(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_output_element_type(0), element::f64);
EXPECT_EQ(op->get_output_partial_shape(0), PartialShape({2, 2}));
}
} // namespace test
} // namespace ov
8 changes: 6 additions & 2 deletions src/core/tests/visitors/op/identity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "openvino/op/Identity.hpp"
#include "openvino/op/identity.hpp"

#include <gtest/gtest.h>

#include "openvino/op/unique.hpp"
#include "visitors/visitors.hpp"

using ov::test::NodeBuilder;
namespace ov {
namespace test {

TEST(attributes, Identity) {
NodeBuilder::opset().insert<ov::op::v15::Identity>();
Expand All @@ -22,3 +23,6 @@ TEST(attributes, Identity) {
constexpr auto expected_attr_count = 0;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
}

} // namespace test
} // namespace ov
62 changes: 13 additions & 49 deletions src/plugins/template/backend/ops/identity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,31 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "openvino/reference/Identity.hpp"
#include "openvino/reference/identity.hpp"

#include "Identity_shape_inference.hpp"
#include "evaluate_node.hpp"
#include "openvino/core/type/element_iterator.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)};
const auto total_size = get_shape_size(out_shape);
const auto total_size_in_bytes = total_size * inputs[0].get_dtype().get_element_size();

outputs[0].set_shape(input_shapes[0]);

ov::reference::Identity(static_cast<const char*>(inputs[0].data()), static_cast<char*>(outputs[0].data()), total_size_in_bytes);
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().");
}
const auto input_shape = inputs[0].get_shape();
const auto total_elements =
std::accumulate(input_shape.begin(), input_shape.end(), static_cast<size_t>(1), std::multiplies<size_t>());
const auto total_size_in_bytes = get_memory_size(inputs[0].get_element_type(), total_elements);

outputs[0].set_shape(input_shape);

ov::reference::identity(static_cast<const char*>(inputs[0].data()),
static_cast<char*>(outputs[0].data()),
total_size_in_bytes);
return true;
}
49 changes: 12 additions & 37 deletions src/plugins/template/tests/functional/op_reference/identity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,33 @@
#include "openvino/op/parameter.hpp"

namespace {
struct IdentityParams {
IdentityParams(const reference_tests::Tensor& matrices, bool copy, std::string name)
: matrices{matrices},
test_case_name{std::move(name)} {}

reference_tests::Tensor matrices;
std::string test_case_name;
};
using IdentityParams = std::tuple<reference_tests::Tensor, std::string>;

class ReferenceIdentity : public testing::TestWithParam<IdentityParams>, public reference_tests::CommonReferenceTest {
public:
void SetUp() override {
const auto& params = GetParam();
const auto& matrices = std::get<0>(params);
function = CreateFunction(params);
inputData = {params.matrices.data};
refOutData = {params.matrices.data};
inputData = {matrices.data};
refOutData = {matrices.data};
}

static std::string getTestCaseName(const testing::TestParamInfo<IdentityParams>& obj) {
std::ostringstream name;
name << obj.param.test_case_name;
const auto& matrices = std::get<0>(obj.param);
name << std::get<1>(obj.param);
name << "_input_type_";
name << obj.param.matrices.type;
name << matrices.type;
name << "_shape_";
name << obj.param.matrices.shape;
name << matrices.shape;
return name.str();
}

private:
static std::shared_ptr<ov::Model> CreateFunction(const IdentityParams& params) {
const auto in_matrices = std::make_shared<ov::op::v0::Parameter>(params.matrices.type, params.matrices.shape);
const auto& matrices = std::get<0>(params);
const auto in_matrices = std::make_shared<ov::op::v0::Parameter>(matrices.type, matrices.shape);
const auto identity = std::make_shared<ov::op::v15::Identity>(in_matrices);
return std::make_shared<ov::Model>(identity->outputs(), ov::ParameterVector{in_matrices});
}
Expand All @@ -52,29 +48,11 @@ std::vector<IdentityParams> generateIdentityParams() {
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<VT>{0.5f, 1.0f, 3.0f, 2.0f});
reference_tests::Tensor matrices_2_2(matrices_2_2_shape, ET, std::vector<VT>{1, 2, 4, 5});

reference_tests::Tensor matrices_2_3_3(matrices_2_3_3_shape,
ET,
std::vector<VT>{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<VT>{1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 4, 5, 3, 1, 2, 6});

std::vector<IdentityParams> params;
params.emplace_back(matrices_2_2, "single");
Expand All @@ -89,13 +67,10 @@ std::vector<IdentityParams> generateIdentityParams() {
generateIdentityParams<ov::element::f16>(),
generateIdentityParams<ov::element::f64>(),
generateIdentityParams<ov::element::f32>(),
generateIdentityParams<ov::element::i4>(),
generateIdentityParams<ov::element::i8>(),
generateIdentityParams<ov::element::i16>(),
generateIdentityParams<ov::element::i32>(),
generateIdentityParams<ov::element::i64>(),
generateIdentityParams<ov::element::u1>(),
generateIdentityParams<ov::element::u4>(),
generateIdentityParams<ov::element::u8>(),
generateIdentityParams<ov::element::u16>(),
generateIdentityParams<ov::element::u32>(),
Expand Down
34 changes: 34 additions & 0 deletions thirdparty/level_zero/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#

set(BUILD_SHARED_LIBS OFF)


# We have to avoid linking against loader with debug postfix due it's a part of driver
# and the name will be the same for release and debug configurations
set(CMAKE_DEBUG_POSTFIX "")

# Skip warnings as errors for thirdparty
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
ov_add_compiler_flags(/WX-)
# solve pdb access issue
set(USE_Z7 ON)
# Close spectre for ze loader
add_compile_options("/Qspectre-")
elseif(CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG)
ov_add_compiler_flags(-Wno-error)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-Wno-undef \
-Wno-missing-declarations")
if(UNUSED_BUT_SET_VARIABLE_SUPPORTED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-but-set-variable")
endif()
endif()
set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)
add_subdirectory(level-zero EXCLUDE_FROM_ALL)

set_property(TARGET ze_loader APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/level-zero/include>)

# This VERSION file created by L0 may cause compilation issue of oneTBB headers, so remove it
file(REMOVE "${CMAKE_BINARY_DIR}/VERSION")

0 comments on commit 540a07c

Please sign in to comment.