From 540a07c8a784c5c65b683181f30f18a19a41f76c Mon Sep 17 00:00:00 2001 From: Roboreptile Date: Fri, 18 Oct 2024 02:58:03 +0000 Subject: [PATCH] [FIX] Apply review ideas --- .../include/openvino/opsets/opset15_tbl.hpp | 1 - .../include/openvino/reference/identity.hpp | 7 +-- .../src/op/{identity.hpp => identity.cpp} | 6 +- src/core/tests/type_prop/identity.cpp | 17 +++-- src/core/tests/visitors/op/identity.cpp | 8 ++- src/plugins/template/backend/ops/identity.cpp | 62 ++++--------------- .../functional/op_reference/identity.cpp | 49 ++++----------- thirdparty/level_zero/CMakeLists.txt | 34 ++++++++++ 8 files changed, 82 insertions(+), 102 deletions(-) rename src/core/src/op/{identity.hpp => identity.cpp} (92%) create mode 100644 thirdparty/level_zero/CMakeLists.txt diff --git a/src/core/include/openvino/opsets/opset15_tbl.hpp b/src/core/include/openvino/opsets/opset15_tbl.hpp index 51d32e11fddc65..2d1f7e7e6d1bd5 100644 --- a/src/core/include/openvino/opsets/opset15_tbl.hpp +++ b/src/core/include/openvino/opsets/opset15_tbl.hpp @@ -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) diff --git a/src/core/reference/include/openvino/reference/identity.hpp b/src/core/reference/include/openvino/reference/identity.hpp index 319cf2bb3eb1a7..510ab76776acbe 100644 --- a/src/core/reference/include/openvino/reference/identity.hpp +++ b/src/core/reference/include/openvino/reference/identity.hpp @@ -6,21 +6,16 @@ #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. **/ -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 diff --git a/src/core/src/op/identity.hpp b/src/core/src/op/identity.cpp similarity index 92% rename from src/core/src/op/identity.hpp rename to src/core/src/op/identity.cpp index db4a3de389c00b..06f8640e801000 100644 --- a/src/core/src/op/identity.hpp +++ b/src/core/src/op/identity.cpp @@ -2,11 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/identity.hpp" + #include #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" @@ -37,4 +39,6 @@ std::shared_ptr Identity::Identity::clone_with_new_inputs(const OutputVect return std::make_shared(new_args.at(0)); } +} // namespace v15 +} // namespace op } // namespace ov diff --git a/src/core/tests/type_prop/identity.cpp b/src/core/tests/type_prop/identity.cpp index 65c9fe462585b5..74283be050143b 100644 --- a/src/core/tests/type_prop/identity.cpp +++ b/src/core/tests/type_prop/identity.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "openvino/op/Identity.hpp" +#include "openvino/op/identity.hpp" #include @@ -12,16 +12,21 @@ using namespace testing; -class TypePropIdentityV15Test : public TypePropOpTest {}; +namespace ov { +namespace test { + +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 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 diff --git a/src/core/tests/visitors/op/identity.cpp b/src/core/tests/visitors/op/identity.cpp index ced50d57a69892..0885b472cb195f 100644 --- a/src/core/tests/visitors/op/identity.cpp +++ b/src/core/tests/visitors/op/identity.cpp @@ -2,14 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "openvino/op/Identity.hpp" +#include "openvino/op/identity.hpp" #include #include "openvino/op/unique.hpp" #include "visitors/visitors.hpp" -using ov::test::NodeBuilder; +namespace ov { +namespace test { TEST(attributes, Identity) { NodeBuilder::opset().insert(); @@ -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 diff --git a/src/plugins/template/backend/ops/identity.cpp b/src/plugins/template/backend/ops/identity.cpp index 0c40ee5569fc5f..f78909e252a68d 100644 --- a/src/plugins/template/backend/ops/identity.cpp +++ b/src/plugins/template/backend/ops/identity.cpp @@ -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 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)}; - 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(inputs[0].data()), static_cast(outputs[0].data()), total_size_in_bytes); - 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()."); - } + const auto input_shape = inputs[0].get_shape(); + const auto total_elements = + std::accumulate(input_shape.begin(), input_shape.end(), static_cast(1), std::multiplies()); + 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(inputs[0].data()), + static_cast(outputs[0].data()), + total_size_in_bytes); + return true; } diff --git a/src/plugins/template/tests/functional/op_reference/identity.cpp b/src/plugins/template/tests/functional/op_reference/identity.cpp index fc9a249851539c..febf6e40618054 100644 --- a/src/plugins/template/tests/functional/op_reference/identity.cpp +++ b/src/plugins/template/tests/functional/op_reference/identity.cpp @@ -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; class ReferenceIdentity : public testing::TestWithParam, 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& 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 CreateFunction(const IdentityParams& params) { - const auto in_matrices = std::make_shared(params.matrices.type, params.matrices.shape); + const auto& matrices = std::get<0>(params); + const auto in_matrices = std::make_shared(matrices.type, matrices.shape); const auto identity = std::make_shared(in_matrices); return std::make_shared(identity->outputs(), ov::ParameterVector{in_matrices}); } @@ -52,29 +48,11 @@ std::vector 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{0.5f, 1.0f, 3.0f, 2.0f}); + reference_tests::Tensor matrices_2_2(matrices_2_2_shape, ET, std::vector{1, 2, 4, 5}); 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{1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 4, 5, 3, 1, 2, 6}); std::vector params; params.emplace_back(matrices_2_2, "single"); @@ -89,13 +67,10 @@ std::vector generateIdentityParams() { generateIdentityParams(), generateIdentityParams(), generateIdentityParams(), - generateIdentityParams(), generateIdentityParams(), generateIdentityParams(), generateIdentityParams(), generateIdentityParams(), - generateIdentityParams(), - generateIdentityParams(), generateIdentityParams(), generateIdentityParams(), generateIdentityParams(), diff --git a/thirdparty/level_zero/CMakeLists.txt b/thirdparty/level_zero/CMakeLists.txt new file mode 100644 index 00000000000000..4bd953e812f07f --- /dev/null +++ b/thirdparty/level_zero/CMakeLists.txt @@ -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 $) + +# This VERSION file created by L0 may cause compilation issue of oneTBB headers, so remove it +file(REMOVE "${CMAKE_BINARY_DIR}/VERSION")