From 50d484db58c357e7a900595eaf85aabfe5667fb6 Mon Sep 17 00:00:00 2001 From: Oleg Pipikin Date: Thu, 28 Dec 2023 12:32:56 +0100 Subject: [PATCH] Remove openvino_builders (#21637) * Remove openvino_builders * Apply comments --------- Co-authored-by: Pavel Durandin --- src/CMakeLists.txt | 2 + src/cmake/openvino.cmake | 1 - src/common/transformations/CMakeLists.txt | 2 +- src/core/CMakeLists.txt | 7 +- .../include/ngraph/builder/autobroadcast.hpp | 229 ---------- .../include/ngraph/builder/make_constant.hpp | 142 ------- .../builder/include/ngraph/builder/norm.hpp | 89 ---- .../include/ngraph/builder/reduce_ops.hpp | 78 ---- .../include/ngraph/builder/reshape.hpp | 80 ---- .../builder/src/builder/autobroadcast.cpp | 400 ------------------ .../builder/src/builder/make_constant.cpp | 72 ---- src/core/builder/src/builder/norm.cpp | 130 ------ src/core/builder/src/builder/reduce_ops.cpp | 127 ------ src/core/builder/src/builder/reshape.cpp | 200 --------- src/core/builder/src/builder/split.cpp | 27 -- src/core/builder/src/precomp.hpp | 16 - src/core/tests/build_graph.cpp | 14 +- src/core/tests/type_prop/tensor_iterator.cpp | 22 +- .../tests/visitors/op/tensor_iterator.cpp | 12 +- src/frontends/onnx/frontend/src/op/add.cpp | 1 - src/frontends/onnx/frontend/src/op/affine.cpp | 1 - src/frontends/onnx/frontend/src/op/clip.cpp | 1 - .../src/op/com.microsoft/attention.cpp | 8 +- .../src/op/com.microsoft/fusedgemm.cpp | 1 - .../onnx/frontend/src/op/compress.cpp | 4 +- src/frontends/onnx/frontend/src/op/conv.cpp | 2 +- .../onnx/frontend/src/op/conv_transpose.cpp | 3 +- src/frontends/onnx/frontend/src/op/crop.cpp | 1 - .../frontend/src/op/dequantize_linear.cpp | 1 - src/frontends/onnx/frontend/src/op/div.hpp | 1 - .../src/op/dynamic_quantize_linear.cpp | 1 - .../onnx/frontend/src/op/flatten.cpp | 4 +- src/frontends/onnx/frontend/src/op/gemm.cpp | 10 +- src/frontends/onnx/frontend/src/op/gru.cpp | 8 +- .../onnx/frontend/src/op/hardmax.cpp | 4 +- .../onnx/frontend/src/op/instance_norm.cpp | 2 - .../onnx/frontend/src/op/log_softmax.cpp | 4 +- .../onnx/frontend/src/op/lp_norm.cpp | 4 +- .../onnx/frontend/src/op/lp_pool.cpp | 8 +- src/frontends/onnx/frontend/src/op/lstm.cpp | 18 +- src/frontends/onnx/frontend/src/op/mul.hpp | 1 - .../src/op/org.openvinotoolkit/group_norm.cpp | 2 - src/frontends/onnx/frontend/src/op/pad.cpp | 4 +- .../onnx/frontend/src/op/quantize_linear.cpp | 6 +- src/frontends/onnx/frontend/src/op/reduce.cpp | 1 - src/frontends/onnx/frontend/src/op/rnn.cpp | 4 +- .../onnx/frontend/src/op/softmax.cpp | 4 +- src/frontends/onnx/frontend/src/op/split.cpp | 12 +- src/frontends/onnx/frontend/src/op/sub.hpp | 1 - .../onnx/frontend/src/op/transpose.cpp | 5 +- .../onnx/frontend/src/utils/conv_factory.cpp | 2 +- .../onnx/frontend/src/utils/recurrent.cpp | 11 +- .../onnx/frontend/src/utils/reshape.cpp | 5 +- src/plugins/template/backend/CMakeLists.txt | 6 +- src/tests/ov_helpers/ov_models/CMakeLists.txt | 4 + .../ov_models/ov_builders}/CMakeLists.txt | 16 +- .../ov_models/ov_builders/broadcast.hpp | 17 + .../include/ov_models/ov_builders/norm.hpp | 30 ++ .../include/ov_models/ov_builders/reshape.hpp | 45 ++ .../include/ov_models/ov_builders}/split.hpp | 44 +- .../ov_models/ov_builders/src/broadcast.cpp | 89 ++++ .../ov_models/ov_builders/src/norm.cpp | 164 +++++++ .../ov_models/ov_builders/src/reshape.cpp | 126 ++++++ .../ov_models/ov_builders/src/split.cpp | 31 ++ .../ov_models/src/ov_builder/broadcast.cpp | 89 ++++ .../ov_models/src/ov_builder/split.cpp | 31 ++ .../common_test_utils/CMakeLists.txt | 1 + .../mock_mo_frontend/CMakeLists.txt | 2 +- 68 files changed, 739 insertions(+), 1751 deletions(-) delete mode 100644 src/core/builder/include/ngraph/builder/autobroadcast.hpp delete mode 100644 src/core/builder/include/ngraph/builder/make_constant.hpp delete mode 100644 src/core/builder/include/ngraph/builder/norm.hpp delete mode 100644 src/core/builder/include/ngraph/builder/reduce_ops.hpp delete mode 100644 src/core/builder/include/ngraph/builder/reshape.hpp delete mode 100644 src/core/builder/src/builder/autobroadcast.cpp delete mode 100644 src/core/builder/src/builder/make_constant.cpp delete mode 100644 src/core/builder/src/builder/norm.cpp delete mode 100644 src/core/builder/src/builder/reduce_ops.cpp delete mode 100644 src/core/builder/src/builder/reshape.cpp delete mode 100644 src/core/builder/src/builder/split.cpp delete mode 100644 src/core/builder/src/precomp.hpp rename src/{core/builder => tests/ov_helpers/ov_models/ov_builders}/CMakeLists.txt (76%) create mode 100644 src/tests/ov_helpers/ov_models/ov_builders/include/ov_models/ov_builders/broadcast.hpp create mode 100644 src/tests/ov_helpers/ov_models/ov_builders/include/ov_models/ov_builders/norm.hpp create mode 100644 src/tests/ov_helpers/ov_models/ov_builders/include/ov_models/ov_builders/reshape.hpp rename src/{core/builder/include/ngraph/builder => tests/ov_helpers/ov_models/ov_builders/include/ov_models/ov_builders}/split.hpp (53%) create mode 100644 src/tests/ov_helpers/ov_models/ov_builders/src/broadcast.cpp create mode 100644 src/tests/ov_helpers/ov_models/ov_builders/src/norm.cpp create mode 100644 src/tests/ov_helpers/ov_models/ov_builders/src/reshape.cpp create mode 100644 src/tests/ov_helpers/ov_models/ov_builders/src/split.cpp create mode 100644 src/tests/ov_helpers/ov_models/src/ov_builder/broadcast.cpp create mode 100644 src/tests/ov_helpers/ov_models/src/ov_builder/split.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 67ed291ff62..3d7e164d1f9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,4 +23,6 @@ add_subdirectory(bindings) if(ENABLE_TESTS) add_subdirectory(core/tests) add_subdirectory(tests) +else() + add_subdirectory(tests/ov_helpers/ov_models/ov_builders) endif() diff --git a/src/cmake/openvino.cmake b/src/cmake/openvino.cmake index dec7fcbe7e5..04867095248 100644 --- a/src/cmake/openvino.cmake +++ b/src/cmake/openvino.cmake @@ -42,7 +42,6 @@ target_include_directories(${TARGET_NAME} PUBLIC $) target_link_libraries(${TARGET_NAME} PRIVATE openvino::reference - openvino::builders openvino::shape_inference openvino::pugixml ${CMAKE_DL_LIBS} diff --git a/src/common/transformations/CMakeLists.txt b/src/common/transformations/CMakeLists.txt index 0eea2cdbfbd..10ed5fa6eea 100644 --- a/src/common/transformations/CMakeLists.txt +++ b/src/common/transformations/CMakeLists.txt @@ -25,7 +25,7 @@ ov_build_target_faster(${TARGET_NAME}_obj PCH PRIVATE "src/precomp.hpp" ) -target_link_libraries(${TARGET_NAME}_obj PRIVATE openvino::reference openvino::itt openvino::builders openvino::core::dev openvino::shape_inference) +target_link_libraries(${TARGET_NAME}_obj PRIVATE openvino::reference openvino::itt openvino::core::dev openvino::shape_inference) target_include_directories(${TARGET_NAME}_obj PRIVATE "${PUBLIC_HEADERS_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/src") diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 5db5eea652c..15767de2481 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -15,7 +15,6 @@ file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp file(GLOB_RECURSE PUBLIC_HEADERS ${OV_CORE_INCLUDE_PATH}/*.hpp) file(GLOB_RECURSE DEV_HEADERS ${OV_CORE_DEV_API_PATH}/*.hpp) -add_subdirectory(builder) add_subdirectory(reference) add_subdirectory(shape_inference) @@ -88,7 +87,7 @@ ov_build_target_faster(ngraph_obj ov_add_version_defines(src/version.cpp ngraph_obj) -target_link_libraries(ngraph_obj PRIVATE openvino::builders openvino::reference openvino::util +target_link_libraries(ngraph_obj PRIVATE openvino::reference openvino::util openvino::pugixml openvino::shape_inference openvino::core::dev) ov_mark_target_as_cc(ngraph_obj) @@ -106,12 +105,12 @@ if(NOT BUILD_SHARED_LIBS) endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - # ngraph is linked against openvino::builders, openvino::reference, openvino::shape_inference static libraries + # ngraph is linked against openvino::reference, openvino::shape_inference static libraries # which include ngraph headers with dllimport attribute. Linker complains about it # but no way to fix this: linking with no attribute defaults to dllexport and we have # multiple defitions for ngraph symbols. # - # The possible way is to use object libraries for openvino::builders, openvino::reference + # The possible way is to use object libraries for openvino::reference # but it's not convinient since these libraries are exported from build tree # and it's better to use them as static libraries in 3rd party projects if(BUILD_SHARED_LIBS) diff --git a/src/core/builder/include/ngraph/builder/autobroadcast.hpp b/src/core/builder/include/ngraph/builder/autobroadcast.hpp deleted file mode 100644 index 53929a5a1a5..00000000000 --- a/src/core/builder/include/ngraph/builder/autobroadcast.hpp +++ /dev/null @@ -1,229 +0,0 @@ -// Copyright (C) 2018-2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "ngraph/except.hpp" -#include "ngraph/node.hpp" -#include "ngraph/op/broadcast.hpp" -#include "ngraph/op/constant.hpp" - -namespace ngraph { -namespace builder { -class numpy_autobroadcast_incompatible_shapes : public ngraph::ngraph_error { -public: - numpy_autobroadcast_incompatible_shapes(const ngraph::Shape& shape1, const ngraph::Shape& shape2); - -private: - const ngraph::Shape m_shape1; - const ngraph::Shape m_shape2; - - static std::string error_str(const ngraph::Shape& shape1, const ngraph::Shape& shape2); -}; - -/// -/// \brief Broadcast all values, if necessary, to obtain equal shapes according -/// to NumPy's auto-broadcasting scheme. -/// -/// \note There are some shape combinations which the autobroadcast algoritm cannot -/// handle. An exception is thrown when such combinations are provided to this -/// function. -/// -/// \param values Vector of output values. -/// -/// \exception ngraph::builder::numpy_autobroadcast_incompatible_shapes -/// -/// \return Vector of broadcasted values. -/// -OutputVector numpy_broadcast_outputs(const OutputVector& values); - -/// -/// \brief Broadcast input value to provided shape using NumPy's auto-broadcasting -/// rules. -/// -/// \param value Input value -/// \param shape Requested output shape -/// -/// \return Node producing values with requested shape. -/// -std::shared_ptr numpy_broadcast(const Output& value, const Shape& shape); - -/// \brief Wrap two graph values, if necessary, to obtain values with identical shapes, -/// using NumPy's auto-broadcast rules. -/// -/// The elements in the std::pair returned by this function correspond to those supplied -/// in the std::pair provided via \p args. -/// -/// If \p args.first and \p args.second produce identical shapes, then the returned -/// std::pair will have the same value as \p args. -/// -/// If \p args.first and \p args.second produce different shapes, then this function creates -/// new ngraph::op::Reshape and/or ngraph::op::Broadcast nodes, as needed, to wrap -/// \p args.first and/or \p args.second in a manner that yields values with the same shape. -/// -/// There are some shape combinations which the autobroadcast algoritm cannot handle. -/// An exception is thrown when such combinations are provided to this function. -/// -/// \pre -/// - \p args.first is not null -/// - \p args.second is not null -/// -/// \post -/// - The ngraph::Node objects pointed to by \p args.first and \p args.second have not been -/// altered by this function, except by possibly having added consumers of their values. -/// -/// - If an exception was not thrown, then the return value's \p first and \p second -/// elements point to ngraph::Node objects whose output values have the same shape. -/// -/// \exception ngraph::builder::numpy_autobroadcast_incompatible_shapes -std::pair, std::shared_ptr> numpy_broadcast( - const std::pair, Output>& args); - -/// \brief Broadcast shape of two nodes to make them compatible for a matrix -/// multiplication. -/// -/// \note This function is reflecting broadcasting behaviour of NumPy's `matmul` -/// operation. -/// (https://docs.scipy.org/doc/numpy/reference/generated/numpy.matmul.html) -/// This mean that only \"stack of matrices\" axes are bidirectionally -/// broadcasted. The last two dimension are left untouched. -/// -/// \param[in] left The Node providing data for the left-hand side of matrix -/// multiplication. -/// \param[in] right The Node providing data for the right-hand side of matrix -/// multiplication. -/// -/// \return The vector containing both outputs broadcasted. -/// -OutputVector numpy_broadcast_for_matmul_operation(const Output& left, const Output& right); - -/// \brief Cast shape of all input nodes for an element-wise operation that requires -/// shape-compatibility -/// -/// \param inputs Original list of inputs -/// \param axis Index starting to align -/// -/// \return pdpd-style broadcasted list of nodes. -OutputVector pdpd_broadcast(const OutputVector& inputs, int64_t axis); - -/// \brief Generate a list of broadcast axes. -/// -/// \details Informally, a broadcast "adds" axes to the input tensor, replicating -/// elements from the input tensor as needed to fill the new dimensions. -/// Function calculate which of the output axes are added in this way. -/// -/// \param output_shape The new shape for the output tensor. -/// \param input_shape The shape of input tensor. -/// \param start_match_axis The axis along which we want to replicate elements. -/// The starting axis position (0-based) int the output -/// shape from which the current shape of the tensor -/// matches the desired new shape. -/// -/// \return The indices of added axes. -std::shared_ptr calculate_broadcast_axes(const Shape& output_shape, - const Shape& input_shape, - std::size_t start_match_axis); - -/// -/// \brief Calculate the output shape of numpy-style broadcast operation for all input -/// shapes. -/// -/// This function finds the maximum tensor shape that will be the result of -/// element-wise operation that will be applied to the input shapes vector. -/// The function also prepares the shape of each input for the element-wise -/// operation by left-padding those shapes so that their rank is equal to the -/// left_shape's rank. -/// -/// \param input_shapes A vector of input shapes for which a common shape should be -/// found -/// -/// \return A pair that contains the target shape as its first object and a vector of -/// padded input shapes ready to be broadcasted as the second object -/// -std::pair> get_numpy_broadcast_shapes(const std::vector& input_shapes); - -inline std::shared_ptr make_broadcast_node(const Output& value, - const Shape& new_shape, - std::size_t start_match_axis) { - auto shape_const = op::Constant::create(element::u64, Shape{new_shape.size()}, new_shape); - return std::make_shared( - value, - shape_const, - calculate_broadcast_axes(new_shape, value.get_shape(), start_match_axis)); -} - -namespace opset1 { -/// -/// \brief Broadcast right node to left node's shape using legacy scheme. -/// -/// \param[in] left The left hand side node of binary operation. -/// \param[in] right The right hand side node of binary operation. The one -/// to be broadcasted. -/// \param[in] start_match_axis The axis index starting mutually equal shapes -/// of both nodes. -/// -/// \return The Output object connected to node producing broadcasted right node. -/// -Output legacy_broadcast_for_binary_operation(const Output& left, - const Output& right, - size_t start_match_axis); - -/// -/// \brief Reconstructs axes mapping vector for Broadcast:v1 operation. -/// -/// \param[in] output_shape The output shape of Broadcast operation. -/// \param[in] broadcast_axes The broadcast axes used for Broadcast:v0 operator. -/// -/// \return The vector with axes indexes mapping . -/// -std::vector get_axes_mapping(const Shape& output_shape, const AxisSet& broadcast_axes); - -/// -/// \brief Creates Node returning the axes mapping for Broadcast:v1 operation. -/// -/// \param[in] output_shape The output shape of Broadcast operation. -/// \param[in] input_shape The input shape. -/// \param[in] start_match_axis The axis index at which input shape starts to be -/// identical as the output shape. -/// -/// \return Returns the Output object pointing to node with the axes mapping. -/// -Output get_axes_mapping_output(const Shape& output_shape, const Shape& input_shape, std::size_t start_match_axis); - -/// -/// \brief Creates Node returning the axes mapping for Broadcast operation. -/// \note Shapes' ranks need to be static. -/// -/// \param[in] output_shape The output shape of Broadcast operation. -/// \param[in] input_shape The input shape. -/// \param[in] start_match_axis The axis index at which input shape starts to be -/// identical to consecutive subset of output shape -/// dimensions. -/// -/// \return Returns the Output object pointing to node with the axes mapping. -/// -Output get_axes_mapping_output(const PartialShape& output_shape, - const PartialShape& input_shape, - std::size_t start_match_axis); - -/// -/// \brief Creates Node returning the axes mapping for Broadcast:v1 operation. -/// -/// \param[in] output_shape The output shape of Broadcast operation. -/// \param[in] broadcast_axes The broadcast axes used for Broadcast:v0 operator. -/// -/// \return The Output object with Node returning axes mapping. -/// -Output get_axes_mapping_output(const Shape& output_shape, const AxisSet& broadcast_axes); - -Output make_broadcast(const Output& node, const Shape& target_shape, const AxisSet& broadcast_axes); - -Output make_broadcast(const Output& node, const Shape& target_shape, std::size_t start_match_axis); - -} // namespace opset1 -} // namespace builder -} // namespace ngraph diff --git a/src/core/builder/include/ngraph/builder/make_constant.hpp b/src/core/builder/include/ngraph/builder/make_constant.hpp deleted file mode 100644 index 169fefa5ce1..00000000000 --- a/src/core/builder/include/ngraph/builder/make_constant.hpp +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (C) 2018-2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "autobroadcast.hpp" -#include "ngraph/node.hpp" -#include "ngraph/op/broadcast.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/type/float16.hpp" - -namespace ngraph { -namespace builder { -template -std::shared_ptr make_constant(const element::Type& type, const Shape& shape, const T& num) { - std::shared_ptr val = nullptr; - -#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8) -# pragma GCC diagnostic push -# pragma GCC diagnostic error "-Wswitch" -# pragma GCC diagnostic error "-Wswitch-enum" -#endif - std::string unsupported_data_type; - switch (type) { - case element::Type_t::f32: - val = - std::make_shared(type, ngraph::Shape{}, std::vector{static_cast(num)}); - break; - case element::Type_t::f64: - val = std::make_shared(type, - ngraph::Shape{}, - std::vector{static_cast(num)}); - break; - case element::Type_t::f16: - val = std::make_shared( - type, - ngraph::Shape{}, - std::vector{ngraph::float16(static_cast(num))}); - break; - case element::Type_t::bf16: - val = std::make_shared( - type, - ngraph::Shape{}, - std::vector{ngraph::bfloat16(static_cast(num))}); - break; - case element::Type_t::i64: - val = std::make_shared(type, - ngraph::Shape{}, - std::vector{static_cast(num)}); - break; - case element::Type_t::i32: - val = std::make_shared(type, - ngraph::Shape{}, - std::vector{static_cast(num)}); - break; - case element::Type_t::i16: - val = std::make_shared(type, - ngraph::Shape{}, - std::vector{static_cast(num)}); - break; - case element::Type_t::i8: - val = std::make_shared(type, - ngraph::Shape{}, - std::vector{static_cast(num)}); - break; - case element::Type_t::u64: - val = std::make_shared(type, - ngraph::Shape{}, - std::vector{static_cast(num)}); - break; - case element::Type_t::u32: - val = std::make_shared(type, - ngraph::Shape{}, - std::vector{static_cast(num)}); - break; - case element::Type_t::u16: - val = std::make_shared(type, - ngraph::Shape{}, - std::vector{static_cast(num)}); - break; - case element::Type_t::u8: - val = std::make_shared(type, - ngraph::Shape{}, - std::vector{static_cast(num)}); - break; - case element::Type_t::dynamic: - unsupported_data_type = "dynamic"; - break; - case element::Type_t::boolean: - unsupported_data_type = "boolean"; - break; - case element::Type_t::u1: - unsupported_data_type = "u1"; - break; - case element::Type_t::i4: - unsupported_data_type = "i4"; - break; - case element::Type_t::u4: - unsupported_data_type = "u4"; - break; - case element::Type_t::nf4: - unsupported_data_type = "nf4"; - break; - case element::Type_t::string: - unsupported_data_type = "string"; - break; - case element::Type_t::undefined: - unsupported_data_type = "undefined"; - break; - } - if (!unsupported_data_type.empty()) - OPENVINO_THROW("make_constant: Unsupported element type '", unsupported_data_type, "'"); - -#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8) -# pragma GCC diagnostic pop -#endif - - if (shape.size() > 0) { - ngraph::AxisSet axes; - for (size_t i = 0; i < shape.size(); i++) { - axes.insert(i); - } - val = builder::opset1::make_broadcast(val, shape, axes).get_node_shared_ptr(); - } - - return val; -} - -/// \brief Create constant filled with double value -/// -/// \note If num value exeeds capacity of type, the value is clamped. -/// -/// \param[in] type The type of produced Constant node. -/// \param[in] shape The shape of produced Constant node. -/// \param[in] num The value used to fill Constant node. -/// -/// \return The Constant node which have expected type, shape and value. -/// -std::shared_ptr make_constant_from_double(const element::Type& type, const Shape& shape, double num); -} // namespace builder -} // namespace ngraph diff --git a/src/core/builder/include/ngraph/builder/norm.hpp b/src/core/builder/include/ngraph/builder/norm.hpp deleted file mode 100644 index 6e10459dbf9..00000000000 --- a/src/core/builder/include/ngraph/builder/norm.hpp +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (C) 2018-2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "ngraph/axis_set.hpp" -#include "ngraph/node.hpp" - -namespace ngraph { -namespace builder { -/// \brief Specifies method of bias application to avoid numerical problems -enum class BiasMode { - // Add bias to intermediate result - ADD, - // Calculate max of intermediate result and bias - MAX -}; - -namespace opset1 { -/// \brief Calculates L-0 norm of input tensor. -/// -/// \note The L-0 norm represents the cardinality of elements different -/// from zero. This actually is not a "true" norm. -/// -/// \param[in] value The input tensor. -/// \param[in] reduction_axes The axes along which we calculate norm. -/// \param[in] keep_dims The flag indicates if axes will be removed or kept. -/// -/// \return L-0 norm of value. The output sub-graph is composed of v1 ops. -/// -std::shared_ptr l0_norm(const Output& value, const Output& reduction_axes, bool keep_dims = false); - -/// \brief Calculates L-1 norm of a value. -/// -/// \note The L-1 norm represents the sum of absolute values. -/// -/// \param[in] value The input tensor. -/// \param[in] reduction_axes The axes along which we calculate norm. -/// \param[in] bias The bias added to the calculated sum. -/// \param[in] keep_dims The flag indicates if axes will be removed or kept. -/// -/// \return L-1 norm of value. The output sub-graph is composed of v1 ops. -/// -std::shared_ptr l1_norm(const Output& value, - const Output& reduction_axes, - float bias = 0.f, - bool keep_dims = false); - -/// \brief Calculates L-2 norm of input tensor. -/// -/// \note The L-2 norm represents the square root of sum of squares of each -/// individual element. -/// -/// \param[in] value The input tensor. -/// \param[in] reduction_axes The axes along which we calculate norm. -/// \param[in] bias The bias combined with calculated sum. -/// \param[in] bias_mode The method of bias application. -/// \param[in] keep_dims The flag indicates if axes will be removed or kept. -/// -/// \return L-2 norm of value. The output sub-graph is composed of v1 ops. -/// -std::shared_ptr l2_norm(const Output& value, - const Output& reduction_axes, - float bias = 0.f, - BiasMode bias_mode = BiasMode::ADD, - bool keep_dims = false); - -/// \brief Creates node which calculates L-p norm on input tensor. -/// -/// \param[in] value The input tensor. -/// \param[in] reduction_axes The axes along which we calculate norm. -/// \param[in] p_norm The p norm to calculate. -/// \param[in] bias The bias added to the calculated sum. -/// \param[in] keep_dims The flag indicates if axes will be removed or kept. -/// -/// \return L-p norm of value. The output sub-graph is composed of v1 ops. -/// -std::shared_ptr lp_norm(const Output& value, - const Output& reduction_axes, - std::size_t p_norm = 2, - float bias = 0.f, - bool keep_dims = false); -} // namespace opset1 -} // namespace builder -} // namespace ngraph diff --git a/src/core/builder/include/ngraph/builder/reduce_ops.hpp b/src/core/builder/include/ngraph/builder/reduce_ops.hpp deleted file mode 100644 index f21fc4cb15a..00000000000 --- a/src/core/builder/include/ngraph/builder/reduce_ops.hpp +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (C) 2018-2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "ngraph/axis_set.hpp" -#include "ngraph/node.hpp" - -namespace ngraph { -namespace builder { -namespace opset1 { -// clang-format off - /// \brief Sum-based Mean of a Tensor. - /// - /// Calculates - /// - /// \f$\sum_{i=1}^{N} \frac{x_i}{N}\f$ - /// - /// Where `i` traverses all of the axes provided in `reduction_axes` - /// - /// ## Inputs - /// - /// | | Type | Description | | - /// | ---------------- | --------------------------------- | -------------------------------------------------------| - /// | `node` | \f$E[d_1,\dots,d_n]~(n \geq 0)\f$ | An input tensor of any shape | - /// | `reduction_axes` | AxesSet | The axes to eliminate through reduction (0 indexed). | - /// | `keep_dims` | bool | If set to true it holds reduced axes. | - /// - /// ## Output - /// - /// | Type | Description | - /// | ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | - /// | \f$E[\textit{delete}(A,d_1,\dots,d_n)]\f$ | The tensor \f$T\f$, where \f$T\f$ is the input tensor with the `reduction_axes` \f$A\f$ eliminated by reduction. | -// clang-format on -std::shared_ptr mean(const Output& node, const AxisSet& reduction_axes, bool keep_dims = false); - -std::shared_ptr mean(const Output& node, const Output& reduction_axes, bool keep_dims = false); - -// clang-format off - /// \brief Sum-based Variance of a Tensor. - /// - /// If bessel_correct is true, calculates - /// - /// \f$\frac{\sum_{i=1}^{N}\left(x_i-\bar{x}\right)^2}{N-1}\f$ - /// - /// else, calculates - /// - /// \f$\frac{\sum_{i=1}^{N}\left(x_i-\bar{x}\right)^2}{N}\f$ - /// - /// Where `i` traverses all of the axes provided in `reduction_axes` and \f$\bar{x} = \sum_{i=1}^{N} \frac{x_i}{N}\f$ - /// - /// ## Inputs - /// - /// | | Type | Description | - /// | ------------------- | --------------------------------- | ------------------------------------------------------------ | - /// | `value | \f$E[d_1,\dots,d_n]~(n \geq 0)\f$ | An input tensor of any shape | - /// | `reduction_axes` | AxesSet | The axes to eliminate through reduction (0 indexed). | - /// | `bessel_correction` | bool (default = false) | Enable Bessel's correction to std_dev for Small sample sizes | - /// - /// ## Output - /// - /// | Type | Description | - /// | ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | - /// | \f$E[\textit{delete}(A,d_1,\dots,d_n)]\f$ | The tensor \f$T\f$, where \f$T\f$ is the input tensor with the `reduction_axes` \f$A\f$ eliminated by reduction. | -// clang-format on -std::shared_ptr variance(const Output& value, - const AxisSet& reduction_axes, - const bool bessel_correction = false); - -std::shared_ptr variance(const Output& value, - const Output& reduction_axes, - bool keep_dims = false, - bool bessel_correction = false); -} // namespace opset1 - -} // namespace builder -} // namespace ngraph diff --git a/src/core/builder/include/ngraph/builder/reshape.hpp b/src/core/builder/include/ngraph/builder/reshape.hpp deleted file mode 100644 index efa1501e843..00000000000 --- a/src/core/builder/include/ngraph/builder/reshape.hpp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (C) 2018-2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "ngraph/node.hpp" -#include "ngraph/shape.hpp" - -namespace ngraph { -namespace builder { -namespace opset1 { -/// \brief Change shape of a value -/// -/// \param[in] value The value to be reshaped. -/// \param[in] shape The new shape. -/// -/// \return Reshape:v1 op. -std::shared_ptr reshape(const Output& value, const Shape& shape); - -/// \brief Permute axes according to specified axes_order parameter. -/// -/// \param The vlaue whose axes we want to permute. -/// \param axes_order The permutation of axes. -/// -/// \return Transpose:v1 op. -std::shared_ptr reorder_axes(const Output& value, std::vector axes_order = {}); - -/// \brief Return transposed value (with axes in reversed order). -/// -/// \param Value to transpose. -/// -/// \return Transpose:v1 op. -std::shared_ptr transpose(const Output& value); - -/// \brief Flatten a value into a 2D matrix, with a static dividing axis. -/// -/// \param The tensor to be flattened. -/// \param The axis dividing shape. -/// -/// \return The new value will be a 2D matrix representing the flattened input -/// node. -std::shared_ptr flatten(const Output& value, int axis); - -/// \brief Expands node tensor shape with empty axis at -/// specified position. -/// -/// \param[in] value The value to be expanded. -/// \param[in] axis The position in the expanded axes where the -/// new axis is placed. -/// -/// \return Reshape:v1 op. -std::shared_ptr expand_dims(const Output& value, std::size_t axis = 0); - -/// \brief Remove empty axes from input tensor. -/// -/// \param[in] value The value to be squeezed. -/// \param[in] axes The vector defining indexes of axes to be removed. -/// -/// \return Reshape:v1 op. -std::shared_ptr squeeze(const Output& value, std::vector axes = {0}); - -/// \brief Collapse specified axes into single one. -/// -/// \note Collapsed axes create a continuous range starting from outermost axis. -/// -/// \param[in] value The value to be reshaped. -/// \param[in] start_axis The start axis index. -/// \param[in] end_axis The end axis (inclusive) index. -/// -/// \return The node with collapsed specified axes. -/// -std::shared_ptr collapse(const Output& value, const std::size_t start_axis, const std::size_t end_axis); -} // namespace opset1 -} // namespace builder -} // namespace ngraph diff --git a/src/core/builder/src/builder/autobroadcast.cpp b/src/core/builder/src/builder/autobroadcast.cpp deleted file mode 100644 index ecfd79c2a43..00000000000 --- a/src/core/builder/src/builder/autobroadcast.cpp +++ /dev/null @@ -1,400 +0,0 @@ -// Copyright (C) 2018-2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "ngraph/builder/autobroadcast.hpp" - -#include -#include -#include - -#include "ngraph/axis_vector.hpp" -#include "ngraph/builder/reshape.hpp" -#include "ngraph/check.hpp" -#include "ngraph/op/broadcast.hpp" -#include "ngraph/op/reshape.hpp" -#include "ngraph/opsets/opset7.hpp" -#include "ngraph/util.hpp" - -using namespace std; - -namespace ngraph { -namespace builder { -OPENVINO_SUPPRESS_DEPRECATED_START -numpy_autobroadcast_incompatible_shapes::numpy_autobroadcast_incompatible_shapes(const Shape& shape1, - const Shape& shape2) - : ngraph_error(error_str(shape1, shape2)), - m_shape1(shape1), - m_shape2(shape2) {} - -string numpy_autobroadcast_incompatible_shapes::error_str(const Shape& shape1, const Shape& shape2) { - ostringstream os; - os << "Auto-broadcast not possible for these input shapes:" - << " shape1=" << vector_to_string(shape1) << " shape2=" << vector_to_string(shape2); - return os.str(); -} -OPENVINO_SUPPRESS_DEPRECATED_END - -/// -/// \brief Calculate the output shape of numpy-style broadcast operation for two -/// shapes. -/// -/// \note More info: -/// https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html#general-broadcasting-rules -/// Example: left: [3, 1, 10] right: [5, 1] return: [3, 5, 10] -/// -/// \param lhs_shape First input shape. -/// \param rhs_shape Second input Shape. -/// -/// \return Broadcast shape of input shapes. -/// -static Shape calculate_broadcast_shape(Shape lhs_shape, Shape rhs_shape) { - Shape result; - auto lhs_rank = lhs_shape.size(); - auto rhs_rank = rhs_shape.size(); - auto max_rank = max(lhs_rank, rhs_rank); - - // left-pad the lhs_shape with ones - lhs_shape.insert(begin(lhs_shape), max_rank - lhs_rank, 1); - // left-pad the rhs_shape with ones - rhs_shape.insert(begin(rhs_shape), max_rank - rhs_rank, 1); - - for (size_t index = 0; index < max_rank; ++index) { - size_t lhs_dim = lhs_shape.at(index); - size_t rhs_dim = rhs_shape.at(index); - - if (lhs_dim != rhs_dim && lhs_dim != 1 && rhs_dim != 1) { - throw numpy_autobroadcast_incompatible_shapes(lhs_shape, rhs_shape); - } - - result.push_back(max(lhs_dim, rhs_dim)); - } - - return result; -}; - -pair> get_numpy_broadcast_shapes(const vector& input_shapes) { - Shape target_shape = accumulate(begin(input_shapes), end(input_shapes), Shape{}, calculate_broadcast_shape); - - vector full_shapes; - for (const Shape& input : input_shapes) { - Shape padded_shape{input}; - padded_shape.insert(begin(padded_shape), target_shape.size() - padded_shape.size(), 1); - full_shapes.push_back(std::move(padded_shape)); - } - - return {target_shape, full_shapes}; -} - -static pair> get_numpy_broadcast_shapes(const OutputVector& values) { - vector input_shapes; - - for (const auto& input : values) { - input_shapes.push_back(input.get_shape()); - } - - return get_numpy_broadcast_shapes(input_shapes); -} - -/// \brief Broadcast input node. -/// -/// \note The source shape does not have to be the actual shape of input node. However -/// it should be a superset of it (containing it as a continuous subset). This -/// implies we may expand the number of axes of input node. The ranks of -/// source_shape and output_shape must be equal. This means that the -/// source_shape has to be padded with ones for this operation. -/// -/// \param[in] value The input Node to be broadcast. -/// \param[in] output_shape The output shape. -/// \param[in] source_shape The source shape from which we want to broadcast input node. -/// -/// \return The broadcasted Node. -/// -static shared_ptr numpy_broadcast_node(const Output& value, - const Shape& output_shape, - const Shape& source_shape) { - shared_ptr broadcasted_node = value.get_node_shared_ptr(); - // If node already has the required shape, return original node - if (output_shape == value.get_shape()) { - return broadcasted_node; - } - - NGRAPH_CHECK(source_shape.size() == output_shape.size(), - "Ranks of source_shape and output_shape dont match: ", - source_shape.size(), - " vs ", - output_shape.size()); - - AxisVector broadcast_axes; - Shape squeezed_shape; - // Positions of axes which have length of 1 are needed to calculate broadcast_axes - // for nGraph broadcast operation. We need to remove ones from source shape - // to avoid broadcasting axis conflict. - for (size_t index = 0; index < output_shape.size(); ++index) { - if (source_shape.at(index) == 1 && output_shape.at(index) != 1) { - broadcast_axes.push_back(index); - } else { - squeezed_shape.push_back(source_shape.at(index)); - } - } - - if (squeezed_shape != value.get_shape()) { - broadcasted_node = builder::opset1::reshape(value, squeezed_shape); - } - - if (!broadcast_axes.empty()) { - auto shape_const = op::Constant::create(element::u64, Shape{output_shape.size()}, output_shape); - broadcasted_node = - make_shared(broadcasted_node, - shape_const, - opset1::get_axes_mapping_output(output_shape, broadcast_axes)); - } - - return broadcasted_node; -} - -/// \brief Broadcast input node. -/// -/// \param[in] value The input Node to be broadcast. -/// \param[in] output_shape The output shape. -/// \param[in] axis The start index to align with output_shape -/// -/// \return The broadcasted Node. -/// -static shared_ptr broadcast_value_pdpd_style(const Output& value, const Shape& output_shape, int64_t axis) { - auto value_shape = value.get_shape(); - - // If node already has the required shape, return original node - if (output_shape == value_shape) { - return value.get_node_shared_ptr(); - } - - if (axis == -1) { - axis = output_shape.size() - value_shape.size(); - } - - auto trimmed_value_shape = value_shape; - while (trimmed_value_shape.size() > 0 && trimmed_value_shape.back() == 1) { - trimmed_value_shape.pop_back(); - } - - AxisSet axes; - for (int64_t i = 0; i < axis; ++i) { - axes.insert(static_cast(i)); - } - - for (size_t i = axis + trimmed_value_shape.size(); i < output_shape.size(); ++i) { - axes.insert(i); - } - - auto trimmed_value = value; - if (value_shape != trimmed_value_shape) { - trimmed_value = builder::opset1::reshape(value, trimmed_value_shape); - } - - auto shape_const = op::Constant::create(element::u64, Shape{output_shape.size()}, output_shape); - auto value_bcast = - make_shared(trimmed_value, shape_const, opset1::get_axes_mapping_output(output_shape, axes)); - - return std::move(value_bcast); -} - -pair, shared_ptr> numpy_broadcast(const pair, Output>& args) { - NGRAPH_CHECK(args.first.get_node()); - NGRAPH_CHECK(args.second.get_node()); - - const Shape& arg1_in_shape = args.first.get_shape(); - const Shape& arg2_in_shape = args.second.get_shape(); - - // Handle the trivial case... - if (arg1_in_shape == arg2_in_shape) { - return make_pair(args.first.get_node_shared_ptr(), args.second.get_node_shared_ptr()); - } - - NodeVector bcasted_outputs = as_node_vector(numpy_broadcast_outputs({args.first, args.second})); - - return make_pair(bcasted_outputs.at(0), bcasted_outputs.at(1)); -} - -OutputVector numpy_broadcast_outputs(const OutputVector& values) { - if (values.size() <= 1) { - return values; - } - - // find the output tensor's shape, then broadcast all inputs so that they are compatible - auto bcast_shapes = get_numpy_broadcast_shapes(values); - - OutputVector broadcasted_inputs; - for (size_t i = 0; i < values.size(); ++i) { - broadcasted_inputs.push_back(numpy_broadcast_node(values[i], bcast_shapes.first, bcast_shapes.second[i])); - } - return broadcasted_inputs; -} - -shared_ptr numpy_broadcast(const Output& value, const Shape& shape) { - auto bcast_shape = get_numpy_broadcast_shapes({value.get_shape(), shape}); - return numpy_broadcast_node(value, bcast_shape.first, bcast_shape.second[0]); -} - -OutputVector numpy_broadcast_for_matmul_operation(const Output& left, const Output& right) { - const auto& left_shape = left.get_shape(); - const auto& right_shape = right.get_shape(); - // Broadcast only _stack of matrices_ axes. - const auto& numpy_shapes = get_numpy_broadcast_shapes( - {Shape{begin(left_shape), next(end(left_shape), -2)}, Shape{begin(right_shape), next(end(right_shape), -2)}}); - - // Prepare tensors output shapes with broadcasted _stack of matrices_ axes. - auto left_output_shape = numpy_shapes.first; - auto right_output_shape = numpy_shapes.first; - // Append the last two axes original dimensions. - left_output_shape.insert(end(left_output_shape), next(begin(left_shape), left_shape.size() - 2), end(left_shape)); - right_output_shape.insert(end(right_output_shape), - next(begin(right_shape), right_shape.size() - 2), - end(right_shape)); - - auto left_full_shape = numpy_shapes.second.at(0); - auto right_full_shape = numpy_shapes.second.at(1); - // Append the last two axes original dimensions. - left_full_shape.insert(end(left_full_shape), next(begin(left_shape), left_shape.size() - 2), end(left_shape)); - right_full_shape.insert(end(right_full_shape), next(begin(right_shape), right_shape.size() - 2), end(right_shape)); - - return {numpy_broadcast_node(left, left_output_shape, left_full_shape), - numpy_broadcast_node(right, right_output_shape, right_full_shape)}; -} - -OutputVector pdpd_broadcast(const OutputVector& inputs, int64_t axis) { - if (inputs.size() <= 1) { - return inputs; - } - - OutputVector broadcasted_inputs{inputs[0]}; - for (size_t i = 1; i < inputs.size(); ++i) { - broadcasted_inputs.push_back(broadcast_value_pdpd_style(inputs[i], inputs[0].get_shape(), axis)); - } - return broadcasted_inputs; -} - -std::shared_ptr calculate_broadcast_axes(const Shape& output_shape, - const Shape& input_shape, - size_t start_match_axis) { - vector axes(output_shape.size() - input_shape.size()); - // Populate the axes vector with monotonic increasing series from 0 until - // output_shape_size, excluding values in range: - // [start_match_axis, start_match_axis + input_shape.size()] - iota(begin(axes), begin(axes) + start_match_axis, 0); - iota(begin(axes) + start_match_axis, end(axes), start_match_axis + input_shape.size()); - - auto axes_mapping = opset1::get_axes_mapping(output_shape, axes); - return op::Constant::create(element::i64, Shape{axes_mapping.size()}, axes_mapping); -} - -namespace opset1 { -Output legacy_broadcast_for_binary_operation(const Output& left, - const Output& right, - size_t start_match_axis) { - const auto& left_shape = left.get_shape(); - const auto& right_shape = right.get_shape(); - - bool dimensions_identical = (left_shape == right_shape); - if (dimensions_identical) { - return right; - } - - // Prepare new shape of right operand for broadcasting - // Remove dimensions with length=1 from back - auto new_right_shape = right_shape; - for (int dimension = static_cast(new_right_shape.size()) - 1; dimension >= 0; --dimension) { - if (new_right_shape.at(dimension) == 1) { - new_right_shape.pop_back(); - } else { - break; - } - } - - // Find first dimensions at front with length different from 1 - size_t num_ones = 0; - for (size_t dimension : new_right_shape) { - if (dimension == 1) { - ++num_ones; - } else { - break; - } - } - - // Remove dimensions with length=1 from front - new_right_shape.erase(begin(new_right_shape), next(begin(new_right_shape), num_ones)); - - auto reshape_right = reshape(right, new_right_shape); - - // Move broadcast start axis parameter to right - start_match_axis += num_ones; - - return make_broadcast(reshape_right, left_shape, start_match_axis); -} - -vector get_axes_mapping(const Shape& output_shape, const AxisSet& broadcast_axes) { - NGRAPH_CHECK((broadcast_axes.size() <= output_shape.size())); - vector axes_mapping(output_shape.size()); - iota(axes_mapping.begin(), axes_mapping.end(), 0); - for (auto i = broadcast_axes.rbegin(); i != broadcast_axes.rend(); ++i) { - axes_mapping.erase(axes_mapping.begin() + *i); - } - return axes_mapping; -} - -Output get_axes_mapping_output(const PartialShape& output_shape, - const PartialShape& input_shape, - std::size_t start_match_axis) { - NGRAPH_CHECK((input_shape.rank().is_static() && output_shape.rank().is_static()), - "Tensor's rank has to be static."); - NGRAPH_CHECK( - (input_shape.rank().get_length() + static_cast(start_match_axis) <= output_shape.rank().get_length()), - "Unable to figure out axes mapping."); - - vector mapping(input_shape.rank().get_length()); - iota(begin(mapping), end(mapping), start_match_axis); - - return op::Constant::create(element::i64, Shape{mapping.size()}, mapping); -} - -Output get_axes_mapping_output(const Shape& output_shape, const AxisSet& broadcast_axes) { - vector axes_mapping{get_axes_mapping(output_shape, broadcast_axes)}; - return op::Constant::create(element::i64, Shape{axes_mapping.size()}, axes_mapping); -} - -static Output get_axes_mapping_output(const PartialShape& output_shape, - const Output& input_shape, - std::size_t start_match_axis) { - const auto one_node = opset7::Constant::create(element::i64, Shape{}, {1}); - const auto zero_node = opset7::Constant::create(element::i64, Shape{}, {0}); - const auto start_match_axis_node = opset7::Constant::create(element::i64, Shape{}, {start_match_axis}); - const auto target_shape_rank_node = - builder::opset1::reshape(std::make_shared(input_shape), Shape{}); - - const auto range_node = std::make_shared(zero_node, target_shape_rank_node, one_node, element::i64); - - // workaround for GPU plugin type incompatibility - const auto range_node_converted = - std::make_shared(range_node, start_match_axis_node->get_element_type()); - // end of workaround - - const auto result = std::make_shared(range_node_converted, start_match_axis_node); - return result; -} - -Output make_broadcast(const Output& node, const Shape& target_shape, const AxisSet& broadcast_axes) { - return make_shared(node, - op::Constant::create(element::i64, Shape{target_shape.size()}, target_shape), - get_axes_mapping_output(target_shape, broadcast_axes)); -} - -Output make_broadcast(const Output& node, const Shape& target_shape, size_t start_match_axis) { - const auto node_shape = std::make_shared(node); - return make_shared(node, - op::Constant::create(element::i64, Shape{target_shape.size()}, target_shape), - get_axes_mapping_output(target_shape, node_shape, start_match_axis)); -} - -} // namespace opset1 -} // namespace builder -} // namespace ngraph diff --git a/src/core/builder/src/builder/make_constant.cpp b/src/core/builder/src/builder/make_constant.cpp deleted file mode 100644 index aea4bfd16b8..00000000000 --- a/src/core/builder/src/builder/make_constant.cpp +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (C) 2018-2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "ngraph/builder/make_constant.hpp" - -NGRAPH_SUPPRESS_DEPRECATED_START -namespace ngraph { -namespace builder { -std::shared_ptr make_constant_from_double(const element::Type& type, const Shape& shape, double num) { - auto ceil_func = [](double x) { - return ceil(x); - }; - - std::shared_ptr result = nullptr; - switch (type) { - case element::Type_t::i8: { - result = std::make_shared(type, shape, double_to_int(num, ceil_func)); - break; - } - case element::Type_t::i16: { - result = std::make_shared(type, shape, double_to_int(num, ceil_func)); - break; - } - case element::Type_t::i32: { - result = std::make_shared(type, shape, double_to_int(num, ceil_func)); - break; - } - case element::Type_t::i64: { - result = std::make_shared(type, shape, double_to_int(num, ceil_func)); - break; - } - case element::Type_t::u8: { - result = std::make_shared(type, shape, double_to_int(num, ceil_func)); - break; - } - case element::Type_t::u16: { - result = std::make_shared(type, shape, double_to_int(num, ceil_func)); - break; - } - case element::Type_t::u32: { - result = std::make_shared(type, shape, double_to_int(num, ceil_func)); - break; - } - case element::Type_t::u64: { - result = std::make_shared(type, shape, double_to_int(num, ceil_func)); - break; - } - case element::Type_t::f16: { - result = builder::make_constant(type, shape, static_cast(num)); - break; - } - case element::Type_t::bf16: { - result = builder::make_constant(type, shape, static_cast(num)); - break; - } - case element::Type_t::f32: { - result = builder::make_constant(type, shape, static_cast(num)); - break; - } - case element::Type_t::f64: { - result = builder::make_constant(type, shape, num); - break; - } - default: - OPENVINO_THROW("Unsupported data type during make_constant_from_double"); - break; - } - return result; -} -} // namespace builder -} // namespace ngraph diff --git a/src/core/builder/src/builder/norm.cpp b/src/core/builder/src/builder/norm.cpp deleted file mode 100644 index b2561ebf4d6..00000000000 --- a/src/core/builder/src/builder/norm.cpp +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (C) 2018-2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "ngraph/builder/norm.hpp" - -#include "ngraph/op/abs.hpp" -#include "ngraph/op/add.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/op/convert.hpp" -#include "ngraph/op/maximum.hpp" -#include "ngraph/op/multiply.hpp" -#include "ngraph/op/not_equal.hpp" -#include "ngraph/op/power.hpp" -#include "ngraph/op/reduce_sum.hpp" -#include "ngraph/op/sqrt.hpp" -#include "ngraph/opsets/opset1.hpp" -#include "ngraph/shape.hpp" - -using namespace std; - -namespace ngraph { -namespace builder { -namespace detail { -namespace opset1 { -namespace { -shared_ptr lp_norm(const Output& value, - size_t p_norm, - const Output& reduction_axes, - float bias, - bool keep_dims) { - // In general "entrywise" lp-norm for matrix `A` is defined as following double - // sum: - // ||A||_p = ||vec(A)||_p = [sum_{i=1}^m sum_{j=1}^n abs(a_{i,j})^p]^{1/p} - shared_ptr abs_values{make_shared(value)}; - shared_ptr p_node = ngraph::opset1::Constant::create(value.get_element_type(), Shape{}, {p_norm}); - - // Get inner part of equation: abs_values^p_node, then sum over reduction_axes. - shared_ptr values{make_shared(abs_values, p_node)}; - values = make_shared(values, reduction_axes, keep_dims); - - shared_ptr bias_node{ngraph::opset1::Constant::create(values->get_element_type(), Shape{}, {bias})}; - - values = make_shared(values, bias_node); - - // Get outer part of equation: raise values to 1/p_norm exponent. - shared_ptr inv_p_node = ngraph::opset1::Constant::create(values->get_element_type(), Shape{}, {1.f / p_norm}); - - return {make_shared(values, inv_p_node)}; -} -} // namespace -} // namespace opset1 -} // namespace detail - -shared_ptr builder::opset1::l0_norm(const Output& value, - const Output& reduction_axes, - bool keep_dims) { - // L0 norm returns number of elements different from zero. - const shared_ptr zero_node{ngraph::opset1::Constant::create(value.get_element_type(), Shape{}, {0.f})}; - - // Convert bool values to input node data type. - const shared_ptr non_zero_values = - make_shared(make_shared(value, zero_node), - value.get_element_type()); - - return make_shared(non_zero_values, reduction_axes, keep_dims); -} - -shared_ptr builder::opset1::l1_norm(const Output& value, - const Output& reduction_axes, - float bias, - bool keep_dims) { - const shared_ptr values{ - make_shared(make_shared(value), reduction_axes, keep_dims)}; - - const shared_ptr bias_node{ngraph::opset1::Constant::create(values->get_element_type(), Shape{}, {bias})}; - - return make_shared(values, bias_node); -} - -shared_ptr builder::opset1::l2_norm(const Output& value, - const Output& reduction_axes, - float bias, - BiasMode bias_mode, - bool keep_dims) { - shared_ptr pow = - make_shared(value, - make_shared(value.get_element_type(), Shape{}, 2)); - shared_ptr values{make_shared(pow, reduction_axes, keep_dims)}; - - shared_ptr bias_node{ngraph::opset1::Constant::create(values->get_element_type(), Shape{}, {bias})}; - shared_ptr result; - switch (bias_mode) { - case BiasMode::MAX: { - result = make_shared(make_shared(values, bias_node)); - break; - } - case BiasMode::ADD: - default: - result = make_shared(make_shared(values, bias_node)); - } - return result; -} - -shared_ptr builder::opset1::lp_norm(const Output& value, - const Output& reduction_axes, - size_t p_norm, - float bias, - bool keep_dims) { - // The number of non-zero elements - if (p_norm == 0) { - return opset1::l0_norm(value, reduction_axes, keep_dims); - } - // sum of absolute values. - else if (p_norm == 1) { - return opset1::l1_norm(value, reduction_axes, bias, keep_dims); - } - // sqrt of sum of squares - Euclidean norm - else if (p_norm == 2) { - return opset1::l2_norm(value, reduction_axes, bias, BiasMode::ADD, keep_dims); - } - // generic case - else { - return detail::opset1::lp_norm(value, p_norm, reduction_axes, bias, keep_dims); - } -} - -} // namespace builder - -} // namespace ngraph diff --git a/src/core/builder/src/builder/reduce_ops.cpp b/src/core/builder/src/builder/reduce_ops.cpp deleted file mode 100644 index 7f809ab5fe9..00000000000 --- a/src/core/builder/src/builder/reduce_ops.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (C) 2018-2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "ngraph/builder/reduce_ops.hpp" - -#include - -#include "ngraph/axis_set.hpp" -#include "ngraph/builder/autobroadcast.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/op/divide.hpp" -#include "ngraph/op/multiply.hpp" -#include "ngraph/op/reshape.hpp" -#include "ngraph/op/sqrt.hpp" -#include "ngraph/op/subtract.hpp" -#include "ngraph/opsets/opset1.hpp" -#include "ngraph/util.hpp" - -namespace ngraph { -namespace builder { -namespace { -size_t get_num_elements(const Shape& shape, const AxisSet& reduction_axes) { - size_t N = 1; - for (auto a : reduction_axes) { - N *= shape[a]; - } - return N; -} - -std::shared_ptr get_num_elements(const Output& value, const Output& reduction_axes) { - const auto value_shape = std::make_shared(value); - const auto dim_values = - std::make_shared(value_shape, - reduction_axes, - ngraph::opset1::Constant::create(element::i64, {}, {0})); - - return std::make_shared(dim_values, - ngraph::opset1::Constant::create(element::i64, {}, {0})); -} - -} // namespace - -std::shared_ptr builder::opset1::mean(const Output& value, const AxisSet& reduction_axes, bool keep_dims) { - std::shared_ptr elems_number; - const auto value_elem_type = value.get_element_type(); - const auto reduction_axes_const = - ngraph::opset1::Constant::create(element::i64, Shape{reduction_axes.size()}, reduction_axes.to_vector()); - const auto value_elems_sum = std::make_shared(value, reduction_axes_const, keep_dims); - if (value.get_partial_shape().is_static()) { - const auto elems_number_value = get_num_elements(value.get_shape(), reduction_axes); - elems_number = ngraph::opset1::Constant::create(value_elem_type, Shape{}, {elems_number_value}); - } else { - elems_number = get_num_elements(value, reduction_axes_const); - elems_number = std::make_shared(elems_number, value_elem_type); - } - - return std::make_shared(value_elems_sum, elems_number); -} - -std::shared_ptr builder::opset1::mean(const Output& value, - const Output& reduction_axes, - bool keep_dims) { - std::shared_ptr elems_number; - const auto value_elem_type = value.get_element_type(); - const auto value_elems_sum = std::make_shared(value, reduction_axes, keep_dims); - elems_number = get_num_elements(value, reduction_axes); - elems_number = std::make_shared(elems_number, value_elem_type); - - return std::make_shared(value_elems_sum, elems_number); -} - -std::shared_ptr builder::opset1::variance(const Output& value, - const AxisSet& reduction_axes, - const bool bessel_correction) { - const bool keep_dims = true; - std::shared_ptr mu = opset1::mean(value, reduction_axes, keep_dims); - - Output diff = std::make_shared(value, mu); - - diff = std::make_shared( - std::make_shared(diff, diff), - ngraph::opset1::Constant::create(element::i64, Shape{reduction_axes.size()}, reduction_axes.to_vector()), - false); - - const auto& et = value.get_element_type(); - const auto N = get_num_elements(value.get_shape(), reduction_axes); - - std::shared_ptr result; - if (bessel_correction) { - const auto N1const = ngraph::opset1::Constant::create(et, Shape{}, {N - 1}); - result = std::make_shared(diff, N1const); - } else { - const auto Nconst = ngraph::opset1::Constant::create(et, Shape{}, {N}); - result = std::make_shared(diff, Nconst); - } - return result; -} - -std::shared_ptr builder::opset1::variance(const Output& value, - const Output& reduction_axes, - bool keep_dims, - bool bessel_correction) { - std::shared_ptr mu = opset1::mean(value, reduction_axes, keep_dims); - - Output diff = std::make_shared(value, mu); - - diff = std::make_shared(std::make_shared(diff, diff), - reduction_axes, - keep_dims); - - const auto& et = value.get_element_type(); - auto N = get_num_elements(value, reduction_axes); - N = std::make_shared(N, et); - - std::shared_ptr result; - if (bessel_correction) { - const auto one = std::make_shared(et, Shape{}, 1); - N = std::make_shared(N, one); - } - - result = std::make_shared(diff, N); - return result; -} - -} // namespace builder -} // namespace ngraph diff --git a/src/core/builder/src/builder/reshape.cpp b/src/core/builder/src/builder/reshape.cpp deleted file mode 100644 index 11cc31fe980..00000000000 --- a/src/core/builder/src/builder/reshape.cpp +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright (C) 2018-2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "ngraph/builder/reshape.hpp" - -#include -#include -#include -#include - -#include "ngraph/axis_vector.hpp" -#include "ngraph/op/concat.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/op/reduce_prod.hpp" -#include "ngraph/op/reshape.hpp" -#include "ngraph/op/shape_of.hpp" -#include "ngraph/op/squeeze.hpp" -#include "ngraph/op/transpose.hpp" -#include "ngraph/op/variadic_split.hpp" -#include "ngraph/opsets/opset1.hpp" -#include "ngraph/util.hpp" -#include "ngraph/validation_util.hpp" - -using namespace ngraph; -using namespace std; - -shared_ptr builder::opset1::reshape(const Output& value, const Shape& shape) { - if (value.get_partial_shape().same_scheme(shape)) { - return value.get_node_shared_ptr(); - } else if (is_scalar(shape)) { - auto value_rank = value.get_shape().size(); - AxisVector axes_vector(value_rank); - std::iota(axes_vector.begin(), axes_vector.end(), 0); - auto axes = op::Constant::create(element::i64, Shape{value_rank}, axes_vector); - return std::make_shared(value, axes); - } else { - auto out_pattern = - op::Constant::create(element::i64, Shape{shape.size()}, vector(shape.begin(), shape.end())); - - return make_shared(value, out_pattern, false); - } -} - -shared_ptr builder::opset1::reorder_axes(const Output& value, vector axes_order) { - const auto axes_order_const = op::Constant::create(element::i64, - Shape{axes_order.size()}, - vector(axes_order.begin(), axes_order.end())); - return make_shared(value, axes_order_const); -} - -shared_ptr builder::opset1::transpose(const Output& value) { - // This part is left to preserve backward compatibility and ensure passing ONNX tests. - if (value.get_partial_shape().is_static()) { - vector axes_order(value.get_shape().size()); - iota(begin(axes_order), end(axes_order), 0); - reverse(begin(axes_order), end(axes_order)); - return builder::opset1::reorder_axes(value, axes_order); - } - - const auto input_rank = std::make_shared(std::make_shared(value)); - const auto neg_one = ngraph::opset1::Constant::create(element::i64, Shape{}, {-1}); - const auto start_node = std::make_shared(input_rank, neg_one); - const auto reverse_axes_order = std::make_shared(reshape(start_node, Shape{}), // start - neg_one, // stop (exclusive) - neg_one); // step - return std::make_shared(value, reverse_axes_order); -} - -namespace ngraph { -namespace builder { -namespace opset1 { -namespace { -/// -/// \brief Return the node representing normalized axis with respect to -/// provided rank. -/// -/// \param[in] node_rank The node representing rank used for normalization. -/// \param[in] axis The axis value to be normalized. -/// -/// \return The new Constant node representing normalized axis value. -/// -std::shared_ptr get_normalized_axis_node(const std::shared_ptr node_rank, int64_t axis) { - auto axis_node = ngraph::opset1::Constant::create(element::i64, Shape{1}, {axis}); - // shortcut for already positive value - if (axis >= 0) { - return axis_node; - } - - // TODO: What if axis value is beyond acceptable values? [-node_rank, - // node_rank-1] - return make_shared(node_rank, axis_node); -} -} // namespace -} // namespace opset1 -} // namespace builder -} // namespace ngraph - -shared_ptr builder::opset1::flatten(const Output& value, int axis) { - // First dimension of output tensor is the product of [d_0, ... d_{axis-1}] dimensions of - // input tensor. The last dimension is the product of the rest of input tensor dimensions: - // [d_{axis}, ..., d_n] - shared_ptr output_shape; - if (axis == 0) { - output_shape = ngraph::opset1::Constant::create(element::i64, Shape{2}, {1, -1}); - } else if (axis == 1) { - output_shape = ngraph::opset1::Constant::create(element::i64, Shape{2}, {0, -1}); - } else { - const auto value_shape = make_shared(value); - const auto value_rank = make_shared(value_shape); - const auto axis_node = get_normalized_axis_node(value_rank, axis); - - const auto first_part_dims = - make_shared(value_shape, - ngraph::opset1::Constant::create(element::i64, {1}, {0}), - axis_node, - vector{0}, - vector{0}); - const auto first_part_dims_length = - make_shared(first_part_dims, - ngraph::opset1::Constant::create(element::i64, {}, {0}), - true); - - const auto remaining_part_length = ngraph::opset1::Constant::create(element::i64, {1}, {-1}); - - output_shape = - make_shared(OutputVector{first_part_dims_length, remaining_part_length}, 0); - } - return make_shared(value, output_shape, true); -} - -shared_ptr builder::opset1::expand_dims(const Output& value, size_t axis) { - Shape output_shape(value.get_shape()); - // Add empty axis at specified position. - auto empty_axis_it = begin(output_shape); - advance(empty_axis_it, axis); - output_shape.insert(empty_axis_it, 1); - return builder::opset1::reshape(value, output_shape); -} - -shared_ptr builder::opset1::squeeze(const Output& value, vector axes) { - if (axes.empty()) { - return value.get_node_shared_ptr(); - } - - Shape in_shape{value.get_shape()}; - for (size_t idx = 0; idx < axes.size(); ++idx) { - in_shape.at(axes.at(idx)) = 0; - } - Shape output_shape; - for (auto axis : in_shape) { - if (axis != 0) { - output_shape.push_back(axis); - } - } - return builder::opset1::reshape(value, output_shape); -} - -shared_ptr builder::opset1::collapse(const Output& value, const size_t start_axis, const size_t end_axis) { - if (start_axis == end_axis) { - return value.get_node_shared_ptr(); - } - - if (value.get_partial_shape().is_static()) { - auto shape = value.get_shape(); - // Multiply all elements of shape from start_axis to end_axis inclusive - size_t collapsed_axis_size = accumulate(next(begin(shape), start_axis), - next(begin(shape), end_axis + 1), - size_t{1}, - multiplies()); - Shape output_shape{}; - output_shape.insert(begin(output_shape), begin(shape), next(begin(shape), start_axis)); - output_shape.insert(end(output_shape), collapsed_axis_size); - output_shape.insert(end(output_shape), next(begin(shape), end_axis + 1), end(shape)); - return builder::opset1::reshape(value, output_shape); - } - - const auto shape = make_shared(value); - const auto rank = make_shared(shape); - - // Split lengths used in VariadicSplit - const auto start_axis_node = ngraph::opset1::Constant::create(element::i64, {1}, {start_axis}); - const auto end_axis_node = ngraph::opset1::Constant::create(element::i64, {1}, {end_axis + 1}); - const auto collapsed_axis = make_shared(end_axis_node, start_axis_node); - const auto post_axis = make_shared(rank, end_axis_node); - - const auto split_lengths = - make_shared(OutputVector{start_axis_node, collapsed_axis, post_axis}, 0); - const auto split_axis = ngraph::opset1::Constant::create(element::i64, {}, {0}); - const auto split_node = make_shared(shape, split_axis, split_lengths); - - const auto reduced_axis = ngraph::opset1::Constant::create(element::i64, {1}, {0}); - const auto collapsed_axis_size = make_shared(split_node->output(1), reduced_axis, true); - - const auto collapsed_shape = make_shared( - OutputVector{split_node->output(0), collapsed_axis_size, split_node->output(2)}, - 0); - - return make_shared(value, collapsed_shape, false); -} diff --git a/src/core/builder/src/builder/split.cpp b/src/core/builder/src/builder/split.cpp deleted file mode 100644 index 95216e53e1d..00000000000 --- a/src/core/builder/src/builder/split.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2018-2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "ngraph/builder/split.hpp" - -#include "ngraph/opsets/opset1.hpp" - -using namespace ngraph; - -OutputVector builder::opset1::split(const Output& value, - const std::vector& split_lengths, - int64_t axis) { - const auto axis_node = ngraph::opset1::Constant::create(element::i64, Shape{}, {axis}); - const auto split_lengths_node = - ngraph::opset1::Constant::create(element::i64, Shape{split_lengths.size()}, split_lengths); - const auto variadic_split = std::make_shared(value, axis_node, split_lengths_node); - - return variadic_split->outputs(); -} - -OutputVector builder::opset1::split(const Output& value, int64_t num_splits, int64_t axis) { - const auto axis_node = ngraph::opset1::Constant::create(element::i64, Shape{}, {axis}); - const auto split = std::make_shared(value, axis_node, num_splits); - - return split->outputs(); -} diff --git a/src/core/builder/src/precomp.hpp b/src/core/builder/src/precomp.hpp deleted file mode 100644 index ca7d02c9115..00000000000 --- a/src/core/builder/src/precomp.hpp +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2018-2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -#include diff --git a/src/core/tests/build_graph.cpp b/src/core/tests/build_graph.cpp index 7fdebc1799c..c6714fcb715 100644 --- a/src/core/tests/build_graph.cpp +++ b/src/core/tests/build_graph.cpp @@ -9,7 +9,6 @@ #include "common_test_utils/graph_comparator.hpp" #include "common_test_utils/test_tools.hpp" #include "common_test_utils/type_prop.hpp" -#include "ngraph/builder/autobroadcast.hpp" #include "ngraph/graph_util.hpp" #include "openvino/core/except.hpp" #include "openvino/op/abs.hpp" @@ -26,6 +25,7 @@ #include "openvino/op/split.hpp" #include "openvino/op/squeeze.hpp" #include "openvino/op/util/variable.hpp" +#include "ov_models/ov_builders/broadcast.hpp" using namespace std; using namespace ov; @@ -36,8 +36,8 @@ TEST(build_graph, build_simple) { auto arg1 = make_shared(element::f32, Shape{3}); auto arg2 = make_shared(element::f32, Shape{32, 7}); auto arg3 = make_shared(element::f32, Shape{32, 7}); - auto broadcast_1 = ngraph::builder::opset1::make_broadcast(arg3, Shape{10, 32, 7}, AxisSet{0}); - auto b1 = ngraph::builder::opset1::make_broadcast(arg3, Shape{10, 32, 7}, AxisSet{0}); + auto broadcast_1 = ov::op::util::make_broadcast(arg3, Shape{10, 32, 7}, AxisSet{0}); + auto b1 = ov::op::util::make_broadcast(arg3, Shape{10, 32, 7}, AxisSet{0}); auto dot = make_shared(arg2, arg0); ASSERT_EQ(dot->input_value(0).get_node_shared_ptr(), arg2); ASSERT_EQ(dot->input_value(1).get_node_shared_ptr(), arg0); @@ -92,8 +92,8 @@ TEST(build_graph, function_undeclared_parameters) { auto arg1 = make_shared(element::f32, Shape{3}); auto arg2 = make_shared(element::f32, Shape{32, 7}); auto arg3 = make_shared(element::f32, Shape{32, 7}); - auto broadcast_1 = ngraph::builder::opset1::make_broadcast(arg3, Shape{10, 32, 7}, AxisSet{0}); - auto b1 = ngraph::builder::opset1::make_broadcast(arg3, Shape{10, 32, 7}, AxisSet{0}); + auto broadcast_1 = ov::op::util::make_broadcast(arg3, Shape{10, 32, 7}, AxisSet{0}); + auto b1 = ov::op::util::make_broadcast(arg3, Shape{10, 32, 7}, AxisSet{0}); auto dot = make_shared(arg2, arg0); ASSERT_EQ(dot->input_values()[0].get_node_shared_ptr(), arg2); ASSERT_EQ(dot->input_values()[1].get_node_shared_ptr(), arg0); @@ -438,8 +438,8 @@ TEST(build_graph, build_graph_parameters_autodetection) { auto arg1 = make_shared(element::f32, Shape{3}); auto arg2 = make_shared(element::f32, Shape{32, 7}); auto arg3 = make_shared(element::f32, Shape{32, 7}); - auto broadcast_1 = ngraph::builder::opset1::make_broadcast(arg3, Shape{10, 32, 7}, AxisSet{0}); - auto b1 = ngraph::builder::opset1::make_broadcast(arg3, Shape{10, 32, 7}, AxisSet{0}); + auto broadcast_1 = ov::op::util::make_broadcast(arg3, Shape{10, 32, 7}, AxisSet{0}); + auto b1 = ov::op::util::make_broadcast(arg3, Shape{10, 32, 7}, AxisSet{0}); auto dot = make_shared(arg2, arg0); auto f = make_shared(OutputVector{dot}); diff --git a/src/core/tests/type_prop/tensor_iterator.cpp b/src/core/tests/type_prop/tensor_iterator.cpp index bab7c4265c6..64bd9df2428 100644 --- a/src/core/tests/type_prop/tensor_iterator.cpp +++ b/src/core/tests/type_prop/tensor_iterator.cpp @@ -7,9 +7,9 @@ #include #include "common_test_utils/type_prop.hpp" -#include "ngraph/builder/reshape.hpp" #include "openvino/core/model.hpp" #include "openvino/opsets/opset5.hpp" +#include "ov_models/ov_builders/reshape.hpp" using namespace std; using namespace ov; @@ -34,14 +34,14 @@ TEST(type_prop, tensor_iterator_lstm) { auto X = make_shared(element::f32, Shape{N, 1, I}); auto W_body = make_shared(element::f32, Shape{4 * H, I}); auto R_body = make_shared(element::f32, Shape{4 * H, H}); - auto LSTM_cell = make_shared(ngraph::builder::opset1::reshape(X, Shape{N, I}), - ngraph::builder::opset1::reshape(H_t, Shape{N, H}), - ngraph::builder::opset1::reshape(C_t, Shape{N, H}), + auto LSTM_cell = make_shared(ov::op::util::reshape(X, Shape{N, I}), + ov::op::util::reshape(H_t, Shape{N, H}), + ov::op::util::reshape(C_t, Shape{N, H}), W_body, R_body, H); - auto H_o = ngraph::builder::opset1::reshape(LSTM_cell->output(0), Shape{N, 1, H}); - auto C_o = ngraph::builder::opset1::reshape(LSTM_cell->output(1), Shape{N, 1, H}); + auto H_o = ov::op::util::reshape(LSTM_cell->output(0), Shape{N, 1, H}); + auto C_o = ov::op::util::reshape(LSTM_cell->output(1), Shape{N, 1, H}); auto body = make_shared(OutputVector{H_o, C_o}, ParameterVector{X, H_t, C_t, W_body, R_body}); auto tensor_iterator = make_shared(); @@ -197,14 +197,14 @@ TEST(type_prop, tensor_iterator_with_dynamic_reshape) { auto X = make_shared(element::f32, Shape{N, 1, I}); auto W_body = make_shared(element::f32, Shape{4 * H, I}); auto R_body = make_shared(element::f32, Shape{4 * H, H}); - auto LSTM_cell = make_shared(ngraph::builder::opset1::reshape(X, Shape{N, I}), - ngraph::builder::opset1::reshape(H_t, Shape{N, H}), - ngraph::builder::opset1::reshape(C_t, Shape{N, H}), + auto LSTM_cell = make_shared(ov::op::util::reshape(X, Shape{N, I}), + ov::op::util::reshape(H_t, Shape{N, H}), + ov::op::util::reshape(C_t, Shape{N, H}), W_body, R_body, H); - auto H_o = ngraph::builder::opset1::reshape(LSTM_cell->output(0), Shape{N, 1, H}); - auto C_o = ngraph::builder::opset1::reshape(LSTM_cell->output(1), Shape{N, 1, H}); + auto H_o = ov::op::util::reshape(LSTM_cell->output(0), Shape{N, 1, H}); + auto C_o = ov::op::util::reshape(LSTM_cell->output(1), Shape{N, 1, H}); auto body = make_shared(OutputVector{H_o, C_o}, ParameterVector{X, H_t, C_t, W_body, R_body}); auto tensor_iterator = make_shared(); diff --git a/src/core/tests/visitors/op/tensor_iterator.cpp b/src/core/tests/visitors/op/tensor_iterator.cpp index 8d2c7baf639..5b7a836ab6d 100644 --- a/src/core/tests/visitors/op/tensor_iterator.cpp +++ b/src/core/tests/visitors/op/tensor_iterator.cpp @@ -6,10 +6,10 @@ #include -#include "ngraph/builder/reshape.hpp" #include "openvino/op/add.hpp" #include "openvino/op/lstm_cell.hpp" #include "openvino/op/multiply.hpp" +#include "ov_models/ov_builders/reshape.hpp" #include "visitors/visitors.hpp" using namespace std; @@ -39,14 +39,14 @@ TEST(attributes, tensor_iterator_lstm) { auto X = make_shared(element::f32, Shape{N, 1, I}); auto W_body = make_shared(element::f32, Shape{4 * H, I}); auto R_body = make_shared(element::f32, Shape{4 * H, H}); - auto LSTM_cell = make_shared(ngraph::builder::opset1::reshape(X, Shape{N, I}), - ngraph::builder::opset1::reshape(H_t, Shape{N, H}), - ngraph::builder::opset1::reshape(C_t, Shape{N, H}), + auto LSTM_cell = make_shared(ov::op::util::reshape(X, Shape{N, I}), + ov::op::util::reshape(H_t, Shape{N, H}), + ov::op::util::reshape(C_t, Shape{N, H}), W_body, R_body, H); - auto H_o = ngraph::builder::opset1::reshape(LSTM_cell->output(0), Shape{N, 1, H}); - auto C_o = ngraph::builder::opset1::reshape(LSTM_cell->output(1), Shape{N, 1, H}); + auto H_o = ov::op::util::reshape(LSTM_cell->output(0), Shape{N, 1, H}); + auto C_o = ov::op::util::reshape(LSTM_cell->output(1), Shape{N, 1, H}); auto body = make_shared(OutputVector{H_o, C_o}, ParameterVector{X, H_t, C_t, W_body, R_body}); auto tensor_iterator = make_shared(); diff --git a/src/frontends/onnx/frontend/src/op/add.cpp b/src/frontends/onnx/frontend/src/op/add.cpp index 453b41fa80e..61ac900e731 100644 --- a/src/frontends/onnx/frontend/src/op/add.cpp +++ b/src/frontends/onnx/frontend/src/op/add.cpp @@ -6,7 +6,6 @@ #include "default_opset.hpp" #include "exceptions.hpp" -#include "ngraph/builder/autobroadcast.hpp" #include "ngraph/shape.hpp" #include "utils/common.hpp" diff --git a/src/frontends/onnx/frontend/src/op/affine.cpp b/src/frontends/onnx/frontend/src/op/affine.cpp index 1c7a2feaded..443a353ff85 100644 --- a/src/frontends/onnx/frontend/src/op/affine.cpp +++ b/src/frontends/onnx/frontend/src/op/affine.cpp @@ -6,7 +6,6 @@ #include "default_opset.hpp" #include "exceptions.hpp" -#include "ngraph/builder/autobroadcast.hpp" #include "ngraph/shape.hpp" OPENVINO_SUPPRESS_DEPRECATED_START diff --git a/src/frontends/onnx/frontend/src/op/clip.cpp b/src/frontends/onnx/frontend/src/op/clip.cpp index cf469b4b366..ca3cde2036d 100644 --- a/src/frontends/onnx/frontend/src/op/clip.cpp +++ b/src/frontends/onnx/frontend/src/op/clip.cpp @@ -8,7 +8,6 @@ #include #include "default_opset.hpp" -#include "ngraph/builder/make_constant.hpp" #include "ngraph/validation_util.hpp" #include "onnx_import/core/null_node.hpp" diff --git a/src/frontends/onnx/frontend/src/op/com.microsoft/attention.cpp b/src/frontends/onnx/frontend/src/op/com.microsoft/attention.cpp index df075686196..bc9e9b256e8 100644 --- a/src/frontends/onnx/frontend/src/op/com.microsoft/attention.cpp +++ b/src/frontends/onnx/frontend/src/op/com.microsoft/attention.cpp @@ -5,8 +5,8 @@ #include "op/com.microsoft/attention.hpp" #include "default_opset.hpp" -#include "ngraph/builder/split.hpp" #include "onnx_import/core/null_node.hpp" +#include "ov_models/ov_builders/split.hpp" namespace ngraph { namespace onnx_import { @@ -122,7 +122,7 @@ NodeVector split_to_QKV(const std::shared_ptr& node, // head_size = hidden_size / num_heads head_size = std::make_shared(hidden_size, num_heads_node); // split the node into 3 even parts Q, K, V with shape (batch_size, sequence_len, hidden_size) - split = ngraph::builder::opset1::split(node, 3, 2); + split = ov::op::util::split(node, 3, 2); // and reshape each part to new shape (batch_size, sequence_len, num_heads, head_size) auto new_shape = std::make_shared(NodeVector{batch_size_seq_len, num_heads_node, head_size}, 0); @@ -141,7 +141,7 @@ NodeVector split_to_QKV(const std::shared_ptr& node, // Q: (batch_size, sequence_len, qkv_hidden_sizes[0]) // K: (batch_size, sequence_len, qkv_hidden_sizes[1]) // V: (batch_size, sequence_len, qkv_hidden_sizes[2]) - split = ngraph::builder::opset1::split(node, qkv_hidden_sizes, 2); + split = ov::op::util::split(node, qkv_hidden_sizes, 2); // and reshape each part to new shape (batch_size, sequence_len, num_heads, head_size) for (size_t i = 0; i < split.size(); i++) { auto new_shape = std::make_shared( @@ -455,7 +455,7 @@ std::shared_ptr attention_softmax(const OutputVector& op_inputs, // (2, batch_size, num_heads, past_sequence_length + sequence_length, head_size) // so we need to split it into two parts, remove first dimension from each part and concatenate first part // with current K and second part with current V - const auto split = ngraph::builder::opset1::split(past, 2, 0); + const auto split = ov::op::util::split(past, 2, 0); const auto past_K = std::make_shared(split[0], zero); K = std::make_shared(NodeVector{past_K, K}, 2); const auto past_V = std::make_shared(split[1], zero); diff --git a/src/frontends/onnx/frontend/src/op/com.microsoft/fusedgemm.cpp b/src/frontends/onnx/frontend/src/op/com.microsoft/fusedgemm.cpp index b7d3300bad5..75c12141d0a 100644 --- a/src/frontends/onnx/frontend/src/op/com.microsoft/fusedgemm.cpp +++ b/src/frontends/onnx/frontend/src/op/com.microsoft/fusedgemm.cpp @@ -7,7 +7,6 @@ #include #include "default_opset.hpp" -#include "ngraph/builder/reshape.hpp" #include "ngraph/op/add.hpp" #include "ngraph/op/constant.hpp" #include "ngraph/op/matmul.hpp" diff --git a/src/frontends/onnx/frontend/src/op/compress.cpp b/src/frontends/onnx/frontend/src/op/compress.cpp index 7960d4e16e4..d1d31f02a19 100644 --- a/src/frontends/onnx/frontend/src/op/compress.cpp +++ b/src/frontends/onnx/frontend/src/op/compress.cpp @@ -7,7 +7,7 @@ #include #include "default_opset.hpp" -#include "ngraph/builder/reshape.hpp" +#include "ov_models/ov_builders/reshape.hpp" OPENVINO_SUPPRESS_DEPRECATED_START namespace ngraph { @@ -22,7 +22,7 @@ OutputVector compress(const Node& node) { if (node.has_attribute("axis")) { axis = node.get_attribute_value("axis"); } else { - data = std::make_shared(ngraph::builder::opset1::flatten(data, static_cast(axis))); + data = std::make_shared(ov::op::util::flatten(data, static_cast(axis))); } auto axis_node = default_opset::Constant::create(element::i64, Shape{}, {axis}); auto zero_node = default_opset::Constant::create(element::i64, Shape{}, {0}); diff --git a/src/frontends/onnx/frontend/src/op/conv.cpp b/src/frontends/onnx/frontend/src/op/conv.cpp index 48b1007a4a4..e5efdbabb9f 100644 --- a/src/frontends/onnx/frontend/src/op/conv.cpp +++ b/src/frontends/onnx/frontend/src/op/conv.cpp @@ -10,10 +10,10 @@ #include "default_opset.hpp" #include "exceptions.hpp" -#include "ngraph/builder/reshape.hpp" #include "ngraph/op/group_conv.hpp" #include "ngraph/op/util/attr_types.hpp" #include "onnx_import/core/null_node.hpp" +#include "ov_models/ov_builders/reshape.hpp" #include "utils/conv_factory.hpp" #include "utils/convpool.hpp" #include "utils/reshape.hpp" diff --git a/src/frontends/onnx/frontend/src/op/conv_transpose.cpp b/src/frontends/onnx/frontend/src/op/conv_transpose.cpp index 09f59bc2394..0fcd58d900f 100644 --- a/src/frontends/onnx/frontend/src/op/conv_transpose.cpp +++ b/src/frontends/onnx/frontend/src/op/conv_transpose.cpp @@ -13,14 +13,13 @@ #include "default_opset.hpp" #include "exceptions.hpp" -#include "ngraph/builder/autobroadcast.hpp" -#include "ngraph/builder/reshape.hpp" #include "ngraph/coordinate_diff.hpp" #include "ngraph/op/util/attr_types.hpp" #include "ngraph/output_vector.hpp" #include "ngraph/partial_shape.hpp" #include "ngraph/shape.hpp" #include "ngraph/validation_util.hpp" +#include "ov_models/ov_builders/reshape.hpp" #include "utils/convpool.hpp" OPENVINO_SUPPRESS_DEPRECATED_START diff --git a/src/frontends/onnx/frontend/src/op/crop.cpp b/src/frontends/onnx/frontend/src/op/crop.cpp index e7aeda12f4f..175b18bf218 100644 --- a/src/frontends/onnx/frontend/src/op/crop.cpp +++ b/src/frontends/onnx/frontend/src/op/crop.cpp @@ -6,7 +6,6 @@ #include "default_opset.hpp" #include "exceptions.hpp" -#include "ngraph/builder/autobroadcast.hpp" #include "ngraph/shape.hpp" OPENVINO_SUPPRESS_DEPRECATED_START diff --git a/src/frontends/onnx/frontend/src/op/dequantize_linear.cpp b/src/frontends/onnx/frontend/src/op/dequantize_linear.cpp index 0647e1f6adb..84e885f35a0 100644 --- a/src/frontends/onnx/frontend/src/op/dequantize_linear.cpp +++ b/src/frontends/onnx/frontend/src/op/dequantize_linear.cpp @@ -9,7 +9,6 @@ #include "default_opset.hpp" #include "ngraph/axis_set.hpp" -#include "ngraph/builder/make_constant.hpp" #include "ngraph/op/convert.hpp" #include "ngraph/shape.hpp" #include "ngraph/validation_util.hpp" diff --git a/src/frontends/onnx/frontend/src/op/div.hpp b/src/frontends/onnx/frontend/src/op/div.hpp index 1da6ae3bc4d..8d37bae67a8 100644 --- a/src/frontends/onnx/frontend/src/op/div.hpp +++ b/src/frontends/onnx/frontend/src/op/div.hpp @@ -10,7 +10,6 @@ OPENVINO_SUPPRESS_DEPRECATED_START #include #include "default_opset.hpp" -#include "ngraph/builder/autobroadcast.hpp" #include "ngraph/node.hpp" #include "ngraph/shape.hpp" #include "onnx_import/core/node.hpp" diff --git a/src/frontends/onnx/frontend/src/op/dynamic_quantize_linear.cpp b/src/frontends/onnx/frontend/src/op/dynamic_quantize_linear.cpp index e147f825ee0..74a33816db2 100644 --- a/src/frontends/onnx/frontend/src/op/dynamic_quantize_linear.cpp +++ b/src/frontends/onnx/frontend/src/op/dynamic_quantize_linear.cpp @@ -9,7 +9,6 @@ #include "default_opset.hpp" #include "ngraph/axis_set.hpp" -#include "ngraph/builder/make_constant.hpp" #include "ngraph/op/convert.hpp" #include "ngraph/shape.hpp" #include "ngraph/validation_util.hpp" diff --git a/src/frontends/onnx/frontend/src/op/flatten.cpp b/src/frontends/onnx/frontend/src/op/flatten.cpp index 2a8d445be1f..ebf4499a279 100644 --- a/src/frontends/onnx/frontend/src/op/flatten.cpp +++ b/src/frontends/onnx/frontend/src/op/flatten.cpp @@ -7,8 +7,8 @@ #include #include "exceptions.hpp" -#include "ngraph/builder/reshape.hpp" #include "ngraph/validation_util.hpp" +#include "ov_models/ov_builders/reshape.hpp" OPENVINO_SUPPRESS_DEPRECATED_START namespace ngraph { @@ -28,7 +28,7 @@ OutputVector flatten(const Node& node) { axis = ngraph::normalize_axis(node.get_description(), axis, data_rank_value, -data_rank_value, data_rank_value); OPENVINO_SUPPRESS_DEPRECATED_END } - return {ngraph::builder::opset1::flatten(data, static_cast(axis))}; + return {ov::op::util::flatten(data, static_cast(axis))}; } } // namespace set_1 diff --git a/src/frontends/onnx/frontend/src/op/gemm.cpp b/src/frontends/onnx/frontend/src/op/gemm.cpp index c05f1963b99..7807539f72f 100644 --- a/src/frontends/onnx/frontend/src/op/gemm.cpp +++ b/src/frontends/onnx/frontend/src/op/gemm.cpp @@ -7,11 +7,11 @@ #include #include "default_opset.hpp" -#include "ngraph/builder/reshape.hpp" #include "ngraph/op/add.hpp" #include "ngraph/op/constant.hpp" #include "ngraph/op/matmul.hpp" #include "ngraph/op/multiply.hpp" +#include "ov_models/ov_builders/reshape.hpp" OPENVINO_SUPPRESS_DEPRECATED_START namespace ngraph { @@ -37,15 +37,15 @@ OutputVector gemm(const Node& node) { const bool trans_b = node.get_attribute_value("transB", 0); if (trans_a) { - input_a = ngraph::builder::opset1::transpose(input_a); + input_a = ov::op::util::transpose(input_a); } if (trans_b) { - input_b = ngraph::builder::opset1::transpose(input_b); + input_b = ov::op::util::transpose(input_b); } - input_a = ngraph::builder::opset1::flatten(input_a, 1); - input_b = ngraph::builder::opset1::flatten(input_b, 1); + input_a = ov::op::util::flatten(input_a, 1); + input_b = ov::op::util::flatten(input_b, 1); std::shared_ptr matmul_node = std::make_shared(input_a, input_b); diff --git a/src/frontends/onnx/frontend/src/op/gru.cpp b/src/frontends/onnx/frontend/src/op/gru.cpp index 62453ffe293..d21c32aa8c7 100644 --- a/src/frontends/onnx/frontend/src/op/gru.cpp +++ b/src/frontends/onnx/frontend/src/op/gru.cpp @@ -8,10 +8,10 @@ #include #include "default_opset.hpp" -#include "ngraph/builder/reshape.hpp" -#include "ngraph/builder/split.hpp" #include "ngraph/shape.hpp" #include "onnx_import/core/null_node.hpp" +#include "ov_models/ov_builders/reshape.hpp" +#include "ov_models/ov_builders/split.hpp" #include "utils/recurrent.hpp" OPENVINO_SUPPRESS_DEPRECATED_START @@ -33,7 +33,7 @@ struct GRUInputMap : public recurrent::OpInputMap { auto bias = ng_inputs.at(3); // gates_count * 2 since B is: [Wb, Rb] const int split_parts = 2 * 3; - const auto split_bias = builder::opset1::split(bias, split_parts, 1); + const auto split_bias = ov::op::util::split(bias, split_parts, 1); const auto wr_z_bias = std::make_shared(split_bias.at(0), split_bias.at(3)); const auto wr_r_bias = std::make_shared(split_bias.at(1), split_bias.at(4)); // The result has shape: [num_directions, 4 * hidden_size] @@ -98,7 +98,7 @@ OutputVector gru(const Node& node) { const auto Y = gru_sequence->output(0); const auto Y_h = gru_sequence->output(1); - return {builder::opset1::reorder_axes(Y, {2, 1, 0, 3}), builder::opset1::reorder_axes(Y_h, {1, 0, 2})}; + return {ov::op::util::reorder_axes(Y, {2, 1, 0, 3}), ov::op::util::reorder_axes(Y_h, {1, 0, 2})}; } } // namespace set_1 diff --git a/src/frontends/onnx/frontend/src/op/hardmax.cpp b/src/frontends/onnx/frontend/src/op/hardmax.cpp index 8200ffbc2db..8079e8cf1fa 100644 --- a/src/frontends/onnx/frontend/src/op/hardmax.cpp +++ b/src/frontends/onnx/frontend/src/op/hardmax.cpp @@ -5,10 +5,10 @@ #include "op/hardmax.hpp" #include "exceptions.hpp" -#include "ngraph/builder/reshape.hpp" #include "ngraph/op/one_hot.hpp" #include "ngraph/op/topk.hpp" #include "ngraph/validation_util.hpp" +#include "ov_models/ov_builders/reshape.hpp" #include "utils/common.hpp" #include "utils/reshape.hpp" @@ -29,7 +29,7 @@ OutputVector hardmax(const Node& node) { } // reshape to 2D - "batch size" x "input feature dimensions" (NxD) - const auto coerced_tensor = ngraph::builder::opset1::flatten(input, static_cast(axis)); + const auto coerced_tensor = ov::op::util::flatten(input, static_cast(axis)); const auto coerced_tensor_shape = std::make_shared(coerced_tensor); Output row_size = diff --git a/src/frontends/onnx/frontend/src/op/instance_norm.cpp b/src/frontends/onnx/frontend/src/op/instance_norm.cpp index e738940d659..a082aed15cd 100644 --- a/src/frontends/onnx/frontend/src/op/instance_norm.cpp +++ b/src/frontends/onnx/frontend/src/op/instance_norm.cpp @@ -10,8 +10,6 @@ #include "default_opset.hpp" #include "exceptions.hpp" #include "ngraph/axis_set.hpp" -#include "ngraph/builder/autobroadcast.hpp" -#include "ngraph/builder/reduce_ops.hpp" #include "ngraph/op/add.hpp" #include "ngraph/op/divide.hpp" #include "ngraph/op/multiply.hpp" diff --git a/src/frontends/onnx/frontend/src/op/log_softmax.cpp b/src/frontends/onnx/frontend/src/op/log_softmax.cpp index e1f4ef9167c..76d0c1c4a8e 100644 --- a/src/frontends/onnx/frontend/src/op/log_softmax.cpp +++ b/src/frontends/onnx/frontend/src/op/log_softmax.cpp @@ -7,15 +7,15 @@ #include #include "default_opset.hpp" -#include "ngraph/builder/reshape.hpp" #include "ngraph/validation_util.hpp" +#include "ov_models/ov_builders/reshape.hpp" OPENVINO_SUPPRESS_DEPRECATED_START namespace ngraph { namespace onnx_import { namespace { std::shared_ptr onnx_logsoftmax(const Output data, const int64_t axis) { - const auto coerced_data = ngraph::builder::opset1::flatten(data, static_cast(axis)); + const auto coerced_data = ov::op::util::flatten(data, static_cast(axis)); const auto result = std::make_shared(coerced_data, 1); const auto data_shape = std::make_shared(data); return std::make_shared(result, data_shape, false); diff --git a/src/frontends/onnx/frontend/src/op/lp_norm.cpp b/src/frontends/onnx/frontend/src/op/lp_norm.cpp index 62d86dd2169..76b899304c5 100644 --- a/src/frontends/onnx/frontend/src/op/lp_norm.cpp +++ b/src/frontends/onnx/frontend/src/op/lp_norm.cpp @@ -13,9 +13,9 @@ #include "default_opset.hpp" #include "exceptions.hpp" #include "ngraph/axis_set.hpp" -#include "ngraph/builder/norm.hpp" #include "ngraph/op/divide.hpp" #include "ngraph/validation_util.hpp" +#include "ov_models/ov_builders/norm.hpp" OPENVINO_SUPPRESS_DEPRECATED_START namespace ngraph { @@ -42,7 +42,7 @@ OutputVector lp_norm(const Node& node) { const auto normalize_axis_const = default_opset::Constant::create(element::i64, {}, {normalize_axis}); std::shared_ptr norm = - ngraph::builder::opset1::lp_norm(data, normalize_axis_const, static_cast(p_norm), 0.0f, true); + ov::op::util::lp_norm(data, normalize_axis_const, static_cast(p_norm), 0.0f, true); return {std::make_shared(data, norm)}; } diff --git a/src/frontends/onnx/frontend/src/op/lp_pool.cpp b/src/frontends/onnx/frontend/src/op/lp_pool.cpp index b8dbf6a974d..16d92ac9d01 100644 --- a/src/frontends/onnx/frontend/src/op/lp_pool.cpp +++ b/src/frontends/onnx/frontend/src/op/lp_pool.cpp @@ -11,9 +11,9 @@ #include "default_opset.hpp" #include "exceptions.hpp" #include "ngraph/axis_set.hpp" -#include "ngraph/builder/norm.hpp" -#include "ngraph/builder/split.hpp" #include "ngraph/util.hpp" +#include "ov_models/ov_builders/norm.hpp" +#include "ov_models/ov_builders/split.hpp" #include "utils/common.hpp" OPENVINO_SUPPRESS_DEPRECATED_START @@ -36,13 +36,13 @@ OutputVector global_lp_pool(const Node& node) { CHECK_VALID_NODE(node, p_norm >= 0, "Only positive (including zero) values are supported for 'p' attribute."); - OutputVector slices = ngraph::builder::opset1::split(data, channels_count, channel_axis); + OutputVector slices = ov::op::util::split(data, channels_count, channel_axis); for (auto& slice : slices) { // all dimensions except spatial/feature const auto reduction_axes = common::get_monotonic_range_along_node_rank(data, 2); - slice = ngraph::builder::opset1::lp_norm(slice, reduction_axes, static_cast(p_norm)); + slice = ov::op::util::lp_norm(slice, reduction_axes, static_cast(p_norm)); // output shape is all ones except N channel Shape output_shape(data_shape.rank().get_length(), 1); diff --git a/src/frontends/onnx/frontend/src/op/lstm.cpp b/src/frontends/onnx/frontend/src/op/lstm.cpp index 93bfcae6363..5f4cceaeba8 100644 --- a/src/frontends/onnx/frontend/src/op/lstm.cpp +++ b/src/frontends/onnx/frontend/src/op/lstm.cpp @@ -13,8 +13,6 @@ #include "default_opset.hpp" #include "exceptions.hpp" -#include "ngraph/builder/reshape.hpp" -#include "ngraph/builder/split.hpp" #include "ngraph/enum_names.hpp" #include "ngraph/log.hpp" #include "ngraph/op/add.hpp" @@ -25,6 +23,8 @@ #include "ngraph/shape.hpp" #include "ngraph/type/element_type.hpp" #include "onnx_import/core/null_node.hpp" +#include "ov_models/ov_builders/reshape.hpp" +#include "ov_models/ov_builders/split.hpp" OPENVINO_SUPPRESS_DEPRECATED_START namespace ngraph { @@ -55,7 +55,7 @@ struct LSTMNgInputMap { // Packed input sequences. // ONNX Shape: [seq_length, batch_size, input_size] // OpenVino Shape: [batch_size, seq_length, input_size] - m_input_map[LSTMInput::LSTM_INPUT_X] = builder::opset1::reorder_axes(ng_inputs.at(0), {1, 0, 2}); + m_input_map[LSTMInput::LSTM_INPUT_X] = ov::op::util::reorder_axes(ng_inputs.at(0), {1, 0, 2}); // Weight tensor for the gates. // Shape: [num_directions, 4*hidden_size, input_size] @@ -101,7 +101,7 @@ struct LSTMNgInputMap { // OpenVino Shape: [num_directions, 4*hidden_size] if (ng_inputs.size() > 3 && !ngraph::op::is_null(ng_inputs.at(3))) { auto bias = ng_inputs.at(3); - auto split_bias = builder::opset1::split(bias, 2, 1); + auto split_bias = ov::op::util::split(bias, 2, 1); m_input_map[LSTMInput::LSTM_INPUT_B] = std::make_shared(split_bias.at(0), split_bias.at(1)); m_input_map[LSTMInput::LSTM_INPUT_B] = @@ -132,7 +132,7 @@ struct LSTMNgInputMap { // ONNX Shape: [num_directions, batch_size, hidden_size] // OpenVino Shape: [batch_size, num_directions, hidden_size] if (ng_inputs.size() > 5 && !ngraph::op::is_null(ng_inputs.at(5))) { - m_input_map[LSTMInput::LSTM_INPUT_INIT_H] = builder::opset1::reorder_axes(ng_inputs.at(5), {1, 0, 2}); + m_input_map[LSTMInput::LSTM_INPUT_INIT_H] = ov::op::util::reorder_axes(ng_inputs.at(5), {1, 0, 2}); } else { auto init_h_shape = std::make_shared( OutputVector{batch_size_node, num_directions_node, hidden_size_node}, @@ -145,7 +145,7 @@ struct LSTMNgInputMap { // ONNX Shape: [num_directions, batch_size, hidden_size] // OpenVino Shape: [batch_size, num_directions, hidden_size] if (ng_inputs.size() > 6 && !ngraph::op::is_null(ng_inputs.at(6))) { - m_input_map[LSTMInput::LSTM_INPUT_INIT_C] = builder::opset1::reorder_axes(ng_inputs.at(6), {1, 0, 2}); + m_input_map[LSTMInput::LSTM_INPUT_INIT_C] = ov::op::util::reorder_axes(ng_inputs.at(6), {1, 0, 2}); } else { auto init_c_shape = std::make_shared( OutputVector{batch_size_node, num_directions_node, hidden_size_node}, @@ -258,9 +258,9 @@ OutputVector lstm(const Node& node) { const auto Y_h = lstm_sequence->output(1); const auto Y_c = lstm_sequence->output(2); - return {builder::opset1::reorder_axes(Y, {2, 1, 0, 3}), - builder::opset1::reorder_axes(Y_h, {1, 0, 2}), - builder::opset1::reorder_axes(Y_c, {1, 0, 2})}; + return {ov::op::util::reorder_axes(Y, {2, 1, 0, 3}), + ov::op::util::reorder_axes(Y_h, {1, 0, 2}), + ov::op::util::reorder_axes(Y_c, {1, 0, 2})}; } } // namespace set_1 diff --git a/src/frontends/onnx/frontend/src/op/mul.hpp b/src/frontends/onnx/frontend/src/op/mul.hpp index 51b4d8cb4cb..f9a1d01a236 100644 --- a/src/frontends/onnx/frontend/src/op/mul.hpp +++ b/src/frontends/onnx/frontend/src/op/mul.hpp @@ -10,7 +10,6 @@ OPENVINO_SUPPRESS_DEPRECATED_START #include #include "default_opset.hpp" -#include "ngraph/builder/autobroadcast.hpp" #include "ngraph/node.hpp" #include "ngraph/op/broadcast.hpp" #include "ngraph/op/multiply.hpp" diff --git a/src/frontends/onnx/frontend/src/op/org.openvinotoolkit/group_norm.cpp b/src/frontends/onnx/frontend/src/op/org.openvinotoolkit/group_norm.cpp index ea0110c7837..9fa72a999a4 100644 --- a/src/frontends/onnx/frontend/src/op/org.openvinotoolkit/group_norm.cpp +++ b/src/frontends/onnx/frontend/src/op/org.openvinotoolkit/group_norm.cpp @@ -5,8 +5,6 @@ #include "op/org.openvinotoolkit/group_norm.hpp" #include "default_opset.hpp" -#include "ngraph/builder/reduce_ops.hpp" -#include "ngraph/builder/split.hpp" #include "ngraph/node.hpp" #include "ngraph/opsets/opset5.hpp" #include "onnx_import/core/node.hpp" diff --git a/src/frontends/onnx/frontend/src/op/pad.cpp b/src/frontends/onnx/frontend/src/op/pad.cpp index 326d652aa3c..54d2f979ad4 100644 --- a/src/frontends/onnx/frontend/src/op/pad.cpp +++ b/src/frontends/onnx/frontend/src/op/pad.cpp @@ -8,7 +8,6 @@ #include "default_opset.hpp" #include "exceptions.hpp" -#include "ngraph/builder/split.hpp" #include "ngraph/coordinate_diff.hpp" #include "ngraph/op/constant.hpp" #include "ngraph/op/convert.hpp" @@ -16,6 +15,7 @@ #include "ngraph/shape.hpp" #include "onnx_import/core/null_node.hpp" #include "op/pad.hpp" +#include "ov_models/ov_builders/split.hpp" #include "utils/convpool.hpp" #include "utils/reshape.hpp" @@ -91,7 +91,7 @@ OutputVector pad(const Node& node) { padding_begin = default_opset::Constant::create(element::i64, ngraph::Shape{half_size}, padding_begin_values); padding_end = default_opset::Constant::create(element::i64, ngraph::Shape{half_size}, padding_end_values); } else { - OutputVector padding = builder::opset1::split(pads, 2, 0); + OutputVector padding = ov::op::util::split(pads, 2, 0); padding_begin = padding.at(0); padding_end = padding.at(1); diff --git a/src/frontends/onnx/frontend/src/op/quantize_linear.cpp b/src/frontends/onnx/frontend/src/op/quantize_linear.cpp index 9468a579e16..22d5e832173 100644 --- a/src/frontends/onnx/frontend/src/op/quantize_linear.cpp +++ b/src/frontends/onnx/frontend/src/op/quantize_linear.cpp @@ -12,10 +12,10 @@ #include "default_opset.hpp" #include "exceptions.hpp" #include "ngraph/axis_set.hpp" -#include "ngraph/builder/reshape.hpp" #include "ngraph/shape.hpp" #include "ngraph/type/element_type.hpp" #include "ngraph/validation_util.hpp" +#include "ov_models/ov_builders/reshape.hpp" #include "utils/reshape.hpp" OPENVINO_SUPPRESS_DEPRECATED_START @@ -196,7 +196,7 @@ OutputVector quantize_linear(Output x, Shape target_shape(x_shape.rank().get_length(), 1); target_shape[axis] = static_cast(x_shape[axis].get_length()); - y_scale = builder::opset1::reshape(y_scale, target_shape); + y_scale = ov::op::util::reshape(y_scale, target_shape); } if (y_zero_point_shape.rank().is_static() && y_zero_point_shape.rank().get_length() == 1 && @@ -211,7 +211,7 @@ OutputVector quantize_linear(Output x, Shape target_shape(x_shape.rank().get_length(), 1); target_shape[axis] = static_cast(x_shape[axis].get_length()); - y_zero_point = builder::opset1::reshape(y_zero_point, target_shape); + y_zero_point = ov::op::util::reshape(y_zero_point, target_shape); } return {detail::make_fake_quantize(y_scale, y_zero_point, x)}; diff --git a/src/frontends/onnx/frontend/src/op/reduce.cpp b/src/frontends/onnx/frontend/src/op/reduce.cpp index 9e70e09f4bd..39b1d430f2c 100644 --- a/src/frontends/onnx/frontend/src/op/reduce.cpp +++ b/src/frontends/onnx/frontend/src/op/reduce.cpp @@ -9,7 +9,6 @@ #include "default_opset.hpp" #include "exceptions.hpp" -#include "ngraph/builder/norm.hpp" #include "ngraph/node.hpp" #include "op/identity.hpp" #include "utils/common.hpp" diff --git a/src/frontends/onnx/frontend/src/op/rnn.cpp b/src/frontends/onnx/frontend/src/op/rnn.cpp index b1c43a45a20..26f8349223b 100644 --- a/src/frontends/onnx/frontend/src/op/rnn.cpp +++ b/src/frontends/onnx/frontend/src/op/rnn.cpp @@ -7,7 +7,7 @@ #include #include "default_opset.hpp" -#include "ngraph/builder/reshape.hpp" +#include "ov_models/ov_builders/reshape.hpp" #include "utils/recurrent.hpp" OPENVINO_SUPPRESS_DEPRECATED_START @@ -50,7 +50,7 @@ OutputVector rnn(const Node& node) { const auto Y = rnn_sequence->output(0); const auto Y_h = rnn_sequence->output(1); - return {builder::opset1::reorder_axes(Y, {2, 1, 0, 3}), builder::opset1::reorder_axes(Y_h, {1, 0, 2})}; + return {ov::op::util::reorder_axes(Y, {2, 1, 0, 3}), ov::op::util::reorder_axes(Y_h, {1, 0, 2})}; } } // namespace set_1 } // namespace op diff --git a/src/frontends/onnx/frontend/src/op/softmax.cpp b/src/frontends/onnx/frontend/src/op/softmax.cpp index df8769f7181..9b028950084 100644 --- a/src/frontends/onnx/frontend/src/op/softmax.cpp +++ b/src/frontends/onnx/frontend/src/op/softmax.cpp @@ -7,15 +7,15 @@ #include #include "default_opset.hpp" -#include "ngraph/builder/reshape.hpp" #include "ngraph/validation_util.hpp" +#include "ov_models/ov_builders/reshape.hpp" OPENVINO_SUPPRESS_DEPRECATED_START namespace ngraph { namespace onnx_import { namespace { std::shared_ptr onnx_softmax(const Output data, const int64_t axis) { - const auto coerced_data = ngraph::builder::opset1::flatten(data, static_cast(axis)); + const auto coerced_data = ov::op::util::flatten(data, static_cast(axis)); const auto result = std::make_shared(coerced_data, 1); const auto data_shape = std::make_shared(data); const bool special_zero = false; diff --git a/src/frontends/onnx/frontend/src/op/split.cpp b/src/frontends/onnx/frontend/src/op/split.cpp index 8da89e4f06f..8a90f5a318b 100644 --- a/src/frontends/onnx/frontend/src/op/split.cpp +++ b/src/frontends/onnx/frontend/src/op/split.cpp @@ -2,12 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/builder/split.hpp" +#include "op/split.hpp" #include #include "default_opset.hpp" -#include "op/split.hpp" +#include "ov_models/ov_builders/split.hpp" OPENVINO_SUPPRESS_DEPRECATED_START namespace ngraph { @@ -20,10 +20,10 @@ OutputVector split(const Node& node) { if (node.has_attribute("split")) { const auto splits = node.get_attribute_value>("split"); - return ngraph::builder::opset1::split(input, splits, axis); + return ov::op::util::split(input, splits, axis); } else { const auto outputs_number = node.get_output_names().size(); - return ngraph::builder::opset1::split(input, outputs_number, axis); + return ov::op::util::split(input, outputs_number, axis); } } @@ -36,7 +36,7 @@ OutputVector split(const Node& node) { if (inputs.size() < 2) { const auto outputs_number = node.get_output_names().size(); - return ngraph::builder::opset1::split(inputs.at(0), outputs_number, axis); + return ov::op::util::split(inputs.at(0), outputs_number, axis); } else { const auto axis_node = default_opset::Constant::create(element::Type_t::i64, Shape{}, {axis}); return {std::make_shared(inputs.at(0), axis_node, inputs.at(1))->outputs()}; @@ -49,4 +49,4 @@ OutputVector split(const Node& node) { } // namespace onnx_import } // namespace ngraph -OPENVINO_SUPPRESS_DEPRECATED_END +OPENVINO_SUPPRESS_DEPRECATED_END \ No newline at end of file diff --git a/src/frontends/onnx/frontend/src/op/sub.hpp b/src/frontends/onnx/frontend/src/op/sub.hpp index 0e0ac4e2b73..b625bdd70e4 100644 --- a/src/frontends/onnx/frontend/src/op/sub.hpp +++ b/src/frontends/onnx/frontend/src/op/sub.hpp @@ -8,7 +8,6 @@ OPENVINO_SUPPRESS_DEPRECATED_START #include "default_opset.hpp" -#include "ngraph/builder/autobroadcast.hpp" #include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" diff --git a/src/frontends/onnx/frontend/src/op/transpose.cpp b/src/frontends/onnx/frontend/src/op/transpose.cpp index 74272483f7e..5c3eb212ca2 100644 --- a/src/frontends/onnx/frontend/src/op/transpose.cpp +++ b/src/frontends/onnx/frontend/src/op/transpose.cpp @@ -7,8 +7,8 @@ #include #include -#include "ngraph/builder/reshape.hpp" #include "ngraph/node.hpp" +#include "ov_models/ov_builders/reshape.hpp" OPENVINO_SUPPRESS_DEPRECATED_START namespace ngraph { @@ -20,8 +20,7 @@ OutputVector transpose(const Node& node) { auto permute_axes = node.get_attribute_value>("perm", {}); - return {(permute_axes.empty()) ? ngraph::builder::opset1::transpose(data) - : ngraph::builder::opset1::reorder_axes(data, permute_axes)}; + return {(permute_axes.empty()) ? ov::op::util::transpose(data) : ov::op::util::reorder_axes(data, permute_axes)}; } } // namespace set_1 diff --git a/src/frontends/onnx/frontend/src/utils/conv_factory.cpp b/src/frontends/onnx/frontend/src/utils/conv_factory.cpp index 3a421463882..617ae6d3eab 100644 --- a/src/frontends/onnx/frontend/src/utils/conv_factory.cpp +++ b/src/frontends/onnx/frontend/src/utils/conv_factory.cpp @@ -6,10 +6,10 @@ #include "default_opset.hpp" #include "exceptions.hpp" -#include "ngraph/builder/reshape.hpp" #include "ngraph/op/group_conv.hpp" #include "ngraph/op/util/attr_types.hpp" #include "onnx_import/core/null_node.hpp" +#include "ov_models/ov_builders/reshape.hpp" #include "utils/conv_factory.hpp" #include "utils/convpool.hpp" #include "utils/reshape.hpp" diff --git a/src/frontends/onnx/frontend/src/utils/recurrent.cpp b/src/frontends/onnx/frontend/src/utils/recurrent.cpp index 14a414dfa2a..889d6f87b0e 100644 --- a/src/frontends/onnx/frontend/src/utils/recurrent.cpp +++ b/src/frontends/onnx/frontend/src/utils/recurrent.cpp @@ -9,12 +9,11 @@ #include #include "default_opset.hpp" -#include "ngraph/builder/autobroadcast.hpp" -#include "ngraph/builder/reshape.hpp" -#include "ngraph/builder/split.hpp" #include "ngraph/check.hpp" #include "ngraph/enum_names.hpp" #include "onnx_import/core/null_node.hpp" +#include "ov_models/ov_builders/reshape.hpp" +#include "ov_models/ov_builders/split.hpp" OPENVINO_SUPPRESS_DEPRECATED_START namespace ngraph { @@ -23,7 +22,7 @@ namespace recurrent { OpInputMap::OpInputMap(const onnx_import::Node& node, std::size_t gates_count) { const auto& ng_inputs = node.get_ng_inputs(); - m_map[OpInput::X] = builder::opset1::reorder_axes(ng_inputs.at(0), {1, 0, 2}); + m_map[OpInput::X] = ov::op::util::reorder_axes(ng_inputs.at(0), {1, 0, 2}); m_map[OpInput::W] = ng_inputs.at(1); m_map[OpInput::R] = ng_inputs.at(2); @@ -56,7 +55,7 @@ OpInputMap::OpInputMap(const onnx_import::Node& node, std::size_t gates_count) { // ------ Optional inputs ------ if (ng_inputs.size() > 3 && !ngraph::op::is_null(ng_inputs.at(3))) { auto bias = ng_inputs.at(3); - auto split_bias = builder::opset1::split(bias, 2, 1); + auto split_bias = ov::op::util::split(bias, 2, 1); m_map[OpInput::B] = std::make_shared(split_bias.at(0), split_bias.at(1)); } else { auto b_shape = std::make_shared( @@ -76,7 +75,7 @@ OpInputMap::OpInputMap(const onnx_import::Node& node, std::size_t gates_count) { } // The initial value of the hidden. if (ng_inputs.size() > 5 && !ngraph::op::is_null(ng_inputs.at(5))) { - m_map[OpInput::INIT_H] = builder::opset1::reorder_axes(ng_inputs.at(5), {1, 0, 2}); + m_map[OpInput::INIT_H] = ov::op::util::reorder_axes(ng_inputs.at(5), {1, 0, 2}); } else { auto init_h_shape = std::make_shared( OutputVector{batch_size_node, num_directions_node, hidden_size_node}, diff --git a/src/frontends/onnx/frontend/src/utils/reshape.cpp b/src/frontends/onnx/frontend/src/utils/reshape.cpp index d4ab7a4cc7a..d1fad12c8fa 100644 --- a/src/frontends/onnx/frontend/src/utils/reshape.cpp +++ b/src/frontends/onnx/frontend/src/utils/reshape.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/builder/reshape.hpp" +#include "ov_models/ov_builders/reshape.hpp" #include #include @@ -10,7 +10,6 @@ #include #include "default_opset.hpp" -#include "ngraph/builder/make_constant.hpp" #include "ngraph/op/util/op_types.hpp" #include "ngraph/shape.hpp" #include "utils/reshape.hpp" @@ -79,7 +78,7 @@ Output interpret_as_scalar(const Output& node) { return std::make_shared(node.get_element_type(), ngraph::Shape{}, value); } - return builder::opset1::reshape(node, Shape{}); + return ov::op::util::reshape(node, Shape{}); } Output reshape_channel_shaped_node_to_nchw(const Output& node, diff --git a/src/plugins/template/backend/CMakeLists.txt b/src/plugins/template/backend/CMakeLists.txt index 0dc03242b55..4af6c8664fc 100644 --- a/src/plugins/template/backend/CMakeLists.txt +++ b/src/plugins/template/backend/CMakeLists.txt @@ -13,8 +13,8 @@ set (SRC backend.hpp executable.cpp executable.hpp - int_backend.cpp - int_executable.cpp + int_backend.cpp + int_executable.cpp evaluates_map.cpp ) @@ -39,7 +39,7 @@ target_compile_definitions(${TARGET_NAME} SHARED_LIB_PREFIX="${CMAKE_SHARED_LIBRARY_PREFIX}" SHARED_LIB_SUFFIX="${OV_BUILD_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}" ) -target_link_libraries(${TARGET_NAME} PRIVATE openvino::builders openvino::reference openvino::util openvino::runtime::dev openvino::shape_inference) +target_link_libraries(${TARGET_NAME} PRIVATE openvino::reference openvino::util openvino::runtime::dev openvino::shape_inference) target_include_directories(${TARGET_NAME} PUBLIC $ $ diff --git a/src/tests/ov_helpers/ov_models/CMakeLists.txt b/src/tests/ov_helpers/ov_models/CMakeLists.txt index 69631bd82ba..8203855b2bd 100644 --- a/src/tests/ov_helpers/ov_models/CMakeLists.txt +++ b/src/tests/ov_helpers/ov_models/CMakeLists.txt @@ -23,6 +23,8 @@ ov_add_target( openvino::runtime::dev common_test_utils ADD_CLANG_FORMAT + EXCLUDED_SOURCE_PATHS + "${CMAKE_CURRENT_SOURCE_DIR}/ov_builders" ) ov_build_target_faster(${TARGET_NAME} @@ -34,3 +36,5 @@ ov_build_target_faster(${TARGET_NAME} ov_developer_package_export_targets(TARGET ${TARGET_NAME} INSTALL_INCLUDE_DIRECTORIES "${PUBLIC_HEADERS_DIR}/") + +add_subdirectory(ov_builders) \ No newline at end of file diff --git a/src/core/builder/CMakeLists.txt b/src/tests/ov_helpers/ov_models/ov_builders/CMakeLists.txt similarity index 76% rename from src/core/builder/CMakeLists.txt rename to src/tests/ov_helpers/ov_models/ov_builders/CMakeLists.txt index ee87ece0365..fa65f42d554 100644 --- a/src/core/builder/CMakeLists.txt +++ b/src/tests/ov_helpers/ov_models/ov_builders/CMakeLists.txt @@ -1,8 +1,8 @@ -# Copyright (C) 2018-2023 Intel Corporation +# Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 # -set(TARGET_NAME "openvino_builders") +set(TARGET_NAME ov_builders) set(BUILDER_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include/) @@ -21,9 +21,7 @@ add_library(${TARGET_NAME} STATIC ${LIBRARY_SRC} ${PUBLIC_HEADERS}) add_library(openvino::builders ALIAS ${TARGET_NAME}) set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME builders) -ov_build_target_faster(${TARGET_NAME} - UNITY - PCH PRIVATE "src/precomp.hpp") +ov_build_target_faster(${TARGET_NAME} UNITY) target_include_directories(${TARGET_NAME} PUBLIC $ @@ -33,11 +31,13 @@ if(NOT BUILD_SHARED_LIBS) target_compile_definitions(${TARGET_NAME} PUBLIC OPENVINO_STATIC_LIBRARY) endif() +target_link_libraries(${TARGET_NAME} PRIVATE openvino::runtime) + ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}) # install & export -ov_install_static_lib(openvino_builders ${OV_CPACK_COMP_CORE}) +ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE}) -ov_developer_package_export_targets(TARGET openvino::builders - INSTALL_INCLUDE_DIRECTORIES "${BUILDER_INCLUDE_DIR}/") +ov_developer_package_export_targets(TARGET ${TARGET_NAME} + INSTALL_INCLUDE_DIRECTORIES "${BUILDER_INCLUDE_DIR}/") \ No newline at end of file diff --git a/src/tests/ov_helpers/ov_models/ov_builders/include/ov_models/ov_builders/broadcast.hpp b/src/tests/ov_helpers/ov_models/ov_builders/include/ov_models/ov_builders/broadcast.hpp new file mode 100644 index 00000000000..364198387fc --- /dev/null +++ b/src/tests/ov_helpers/ov_models/ov_builders/include/ov_models/ov_builders/broadcast.hpp @@ -0,0 +1,17 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/core/node.hpp" + +namespace ov { +namespace op { +namespace util { +Output make_broadcast(const Output& node, const Shape& target_shape, const AxisSet& broadcast_axes); + +Output make_broadcast(const Output& node, const Shape& target_shape, std::size_t start_match_axis); +} // namespace util +} // namespace op +} // namespace ov diff --git a/src/tests/ov_helpers/ov_models/ov_builders/include/ov_models/ov_builders/norm.hpp b/src/tests/ov_helpers/ov_models/ov_builders/include/ov_models/ov_builders/norm.hpp new file mode 100644 index 00000000000..964becc2f0d --- /dev/null +++ b/src/tests/ov_helpers/ov_models/ov_builders/include/ov_models/ov_builders/norm.hpp @@ -0,0 +1,30 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#pragma once + +#include + +#include "openvino/core/node.hpp" + +namespace ov { +namespace op { +namespace util { +/// \brief Creates node which calculates L-p norm on input tensor. +/// +/// \param[in] value The input tensor. +/// \param[in] reduction_axes The axes along which we calculate norm. +/// \param[in] p_norm The p norm to calculate. +/// \param[in] bias The bias added to the calculated sum. +/// \param[in] keep_dims The flag indicates if axes will be removed or kept. +/// +/// \return L-p norm of value. The output sub-graph is composed of v1 ops. +/// +std::shared_ptr lp_norm(const Output& value, + const Output& reduction_axes, + std::size_t p_norm = 2, + float bias = 0.f, + bool keep_dims = false); +} // namespace util +} // namespace op +} // namespace ov diff --git a/src/tests/ov_helpers/ov_models/ov_builders/include/ov_models/ov_builders/reshape.hpp b/src/tests/ov_helpers/ov_models/ov_builders/include/ov_models/ov_builders/reshape.hpp new file mode 100644 index 00000000000..0e1be4a7c76 --- /dev/null +++ b/src/tests/ov_helpers/ov_models/ov_builders/include/ov_models/ov_builders/reshape.hpp @@ -0,0 +1,45 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/core/node.hpp" + +namespace ov { +namespace op { +namespace util { +/// \brief Change shape of a value +/// +/// \param[in] value The value to be reshaped. +/// \param[in] shape The new shape. +/// +/// \return Reshape:v1 op. +std::shared_ptr reshape(const Output& value, const Shape& shape); + +/// \brief Permute axes according to specified axes_order parameter. +/// +/// \param The vlaue whose axes we want to permute. +/// \param axes_order The permutation of axes. +/// +/// \return Transpose:v1 op. +std::shared_ptr reorder_axes(const Output& value, std::vector axes_order = {}); + +/// \brief Return transposed value (with axes in reversed order). +/// +/// \param Value to transpose. +/// +/// \return Transpose:v1 op. +std::shared_ptr transpose(const Output& value); + +/// \brief Flatten a value into a 2D matrix, with a static dividing axis. +/// +/// \param The tensor to be flattened. +/// \param The axis dividing shape. +/// +/// \return The new value will be a 2D matrix representing the flattened input +/// node. +std::shared_ptr flatten(const Output& value, int axis); +} // namespace util +} // namespace op +} // namespace ov diff --git a/src/core/builder/include/ngraph/builder/split.hpp b/src/tests/ov_helpers/ov_models/ov_builders/include/ov_models/ov_builders/split.hpp similarity index 53% rename from src/core/builder/include/ngraph/builder/split.hpp rename to src/tests/ov_helpers/ov_models/ov_builders/include/ov_models/ov_builders/split.hpp index 7bf1ebd18b1..086cf635d78 100644 --- a/src/core/builder/include/ngraph/builder/split.hpp +++ b/src/tests/ov_helpers/ov_models/ov_builders/include/ov_models/ov_builders/split.hpp @@ -1,43 +1,13 @@ // Copyright (C) 2018-2022 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // - #pragma once -#include -#include "ngraph/node.hpp" +#include "openvino/core/node.hpp" -namespace ngraph { -namespace builder { -/// \brief Split value on specified axis into multiple parts. -/// -/// \param value The value to be split. -/// \param length_parts The vector defining the lengths of each split part. -/// \param axis The axis we split input node on. Default value is zero axis. -/// -/// \return The vector containing multiple nodes we split input node into. -/// -NGRAPH_DEPRECATED("This builder was deprecated.") -OutputVector split(const Output& value, const std::vector& length_parts, int64_t axis = 0); - -/// \brief Split node on specified axis into multiple parts. -/// -/// \param value The value to split. -/// \param split_parts The number of parts we want to split output at given -/// axis. The length of the axis to split must be divisible by -/// this value. -/// \param axis The axis we split input node on. Default value is zero axis. -/// -/// \note This implementation supports negative `axis` values (similar to NumPy -/// indexing). This means that the axis to split on will be counted from -/// the back of the tensor (negative values are subtracted from its rank). -/// -/// \return The vector containing multiple outputs we split input node into. -/// -NGRAPH_DEPRECATED("This builder was deprecated.") -OutputVector split(const Output& value, int64_t split_parts, int axis = 0); - -namespace opset1 { +namespace ov { +namespace op { +namespace util { /// \brief Split value on specified axis into multiple parts. /// /// \param value The value to be split. @@ -70,6 +40,6 @@ OutputVector split(const Output& value, const std::vector& split_ /// The vector is output of VariadicSplit:v1 op /// OutputVector split(const Output& value, int64_t num_splits, int64_t axis = 0); -} // namespace opset1 -} // namespace builder -} // namespace ngraph +} // namespace util +} // namespace op +} // namespace ov diff --git a/src/tests/ov_helpers/ov_models/ov_builders/src/broadcast.cpp b/src/tests/ov_helpers/ov_models/ov_builders/src/broadcast.cpp new file mode 100644 index 00000000000..3b6e6c8be44 --- /dev/null +++ b/src/tests/ov_helpers/ov_models/ov_builders/src/broadcast.cpp @@ -0,0 +1,89 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ov_models/ov_builders/broadcast.hpp" + +#include "openvino/op/add.hpp" +#include "openvino/op/broadcast.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/convert.hpp" +#include "openvino/op/range.hpp" +#include "openvino/op/reshape.hpp" +#include "openvino/op/shape_of.hpp" +#include "ov_models/ov_builders/reshape.hpp" + +namespace ov { +namespace op { +namespace util { +namespace { +/// +/// \brief Reconstructs axes mapping vector for Broadcast:v1 operation. +/// +/// \param[in] output_shape The output shape of Broadcast operation. +/// \param[in] broadcast_axes The broadcast axes used for Broadcast:v0 operator. +/// +/// \return The vector with axes indexes mapping . +/// +std::vector get_axes_mapping(const Shape& output_shape, const AxisSet& broadcast_axes) { + NGRAPH_CHECK((broadcast_axes.size() <= output_shape.size())); + std::vector axes_mapping(output_shape.size()); + iota(axes_mapping.begin(), axes_mapping.end(), 0); + for (auto i = broadcast_axes.rbegin(); i != broadcast_axes.rend(); ++i) { + axes_mapping.erase(axes_mapping.begin() + *i); + } + return axes_mapping; +} + +/// +/// \brief Creates Node returning the axes mapping for Broadcast:v1 operation. +/// +/// \param[in] output_shape The output shape of Broadcast operation. +/// \param[in] broadcast_axes The broadcast axes used for Broadcast:v0 operator. +/// +/// \return The Output object with Node returning axes mapping. +/// +Output get_axes_mapping_output(const Shape& output_shape, const AxisSet& broadcast_axes) { + std::vector axes_mapping{get_axes_mapping(output_shape, broadcast_axes)}; + return ov::op::v0::Constant::create(element::i64, Shape{axes_mapping.size()}, axes_mapping); +} + +static Output get_axes_mapping_output(const PartialShape& output_shape, + const Output& input_shape, + std::size_t start_match_axis) { + const auto one_node = ov::op::v0::Constant::create(element::i64, Shape{}, {1}); + const auto zero_node = ov::op::v0::Constant::create(element::i64, Shape{}, {0}); + const auto start_match_axis_node = ov::op::v0::Constant::create(element::i64, Shape{}, {start_match_axis}); + const auto target_shape_rank_node = + ov::op::util::reshape(std::make_shared(input_shape), Shape{}); + + const auto range_node = + std::make_shared(zero_node, target_shape_rank_node, one_node, element::i64); + + // workaround for GPU plugin type incompatibility + const auto range_node_converted = + std::make_shared(range_node, start_match_axis_node->get_element_type()); + // end of workaround + + const auto result = std::make_shared(range_node_converted, start_match_axis_node); + return result; +} +} // namespace + +Output make_broadcast(const Output& node, const Shape& target_shape, const AxisSet& broadcast_axes) { + return std::make_shared( + node, + ov::op::v0::Constant::create(element::i64, Shape{target_shape.size()}, target_shape), + get_axes_mapping_output(target_shape, broadcast_axes)); +} + +Output make_broadcast(const Output& node, const Shape& target_shape, size_t start_match_axis) { + const auto node_shape = std::make_shared(node); + return std::make_shared( + node, + ov::op::v0::Constant::create(element::i64, Shape{target_shape.size()}, target_shape), + get_axes_mapping_output(target_shape, node_shape, start_match_axis)); +} +} // namespace util +} // namespace op +} // namespace ov diff --git a/src/tests/ov_helpers/ov_models/ov_builders/src/norm.cpp b/src/tests/ov_helpers/ov_models/ov_builders/src/norm.cpp new file mode 100644 index 00000000000..7719443e4a8 --- /dev/null +++ b/src/tests/ov_helpers/ov_models/ov_builders/src/norm.cpp @@ -0,0 +1,164 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ov_models/ov_builders/norm.hpp" + +#include "openvino/op/abs.hpp" +#include "openvino/op/add.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/convert.hpp" +#include "openvino/op/maximum.hpp" +#include "openvino/op/multiply.hpp" +#include "openvino/op/not_equal.hpp" +#include "openvino/op/power.hpp" +#include "openvino/op/reduce_sum.hpp" +#include "openvino/op/sqrt.hpp" + +namespace ov { +namespace op { +namespace util { +namespace { +/// \brief Specifies method of bias application to avoid numerical problems +enum class BiasMode { + // Add bias to intermediate result + ADD, + // Calculate max of intermediate result and bias + MAX +}; + +std::shared_ptr lp_norm(const Output& value, + size_t p_norm, + const Output& reduction_axes, + float bias, + bool keep_dims) { + // In general "entrywise" lp-norm for matrix `A` is defined as following double + // sum: + // ||A||_p = ||vec(A)||_p = [sum_{i=1}^m sum_{j=1}^n abs(a_{i,j})^p]^{1/p} + std::shared_ptr abs_values{std::make_shared(value)}; + std::shared_ptr p_node = ov::op::v0::Constant::create(value.get_element_type(), Shape{}, {p_norm}); + + // Get inner part of equation: abs_values^p_node, then sum over reduction_axes. + std::shared_ptr values{std::make_shared(abs_values, p_node)}; + values = std::make_shared(values, reduction_axes, keep_dims); + + std::shared_ptr bias_node{ov::op::v0::Constant::create(values->get_element_type(), Shape{}, {bias})}; + + values = std::make_shared(values, bias_node); + + // Get outer part of equation: raise values to 1/p_norm exponent. + std::shared_ptr inv_p_node = + ov::op::v0::Constant::create(values->get_element_type(), Shape{}, {1.f / p_norm}); + + return {std::make_shared(values, inv_p_node)}; +} + +/// \brief Calculates L-0 norm of input tensor. +/// +/// \note The L-0 norm represents the cardinality of elements different +/// from zero. This actually is not a "true" norm. +/// +/// \param[in] value The input tensor. +/// \param[in] reduction_axes The axes along which we calculate norm. +/// \param[in] keep_dims The flag indicates if axes will be removed or kept. +/// +/// \return L-0 norm of value. The output sub-graph is composed of v1 ops. +/// +std::shared_ptr l0_norm(const Output& value, const Output& reduction_axes, bool keep_dims) { + // L0 norm returns number of elements different from zero. + const std::shared_ptr zero_node{ov::op::v0::Constant::create(value.get_element_type(), Shape{}, {0.f})}; + + // Convert bool values to input node data type. + const std::shared_ptr non_zero_values = + std::make_shared(std::make_shared(value, zero_node), + value.get_element_type()); + + return std::make_shared(non_zero_values, reduction_axes, keep_dims); +} + +/// \brief Calculates L-1 norm of a value. +/// +/// \note The L-1 norm represents the sum of absolute values. +/// +/// \param[in] value The input tensor. +/// \param[in] reduction_axes The axes along which we calculate norm. +/// \param[in] bias The bias added to the calculated sum. +/// \param[in] keep_dims The flag indicates if axes will be removed or kept. +/// +/// \return L-1 norm of value. The output sub-graph is composed of v1 ops. +/// +std::shared_ptr l1_norm(const Output& value, + const Output& reduction_axes, + float bias, + bool keep_dims) { + const std::shared_ptr values{ + std::make_shared(std::make_shared(value), reduction_axes, keep_dims)}; + + const std::shared_ptr bias_node{ov::op::v0::Constant::create(values->get_element_type(), Shape{}, {bias})}; + + return std::make_shared(values, bias_node); +} + +/// \brief Calculates L-2 norm of input tensor. +/// +/// \note The L-2 norm represents the square root of sum of squares of each +/// individual element. +/// +/// \param[in] value The input tensor. +/// \param[in] reduction_axes The axes along which we calculate norm. +/// \param[in] bias The bias combined with calculated sum. +/// \param[in] bias_mode The method of bias application. +/// \param[in] keep_dims The flag indicates if axes will be removed or kept. +/// +/// \return L-2 norm of value. The output sub-graph is composed of v1 ops. +/// +std::shared_ptr l2_norm(const Output& value, + const Output& reduction_axes, + float bias, + BiasMode bias_mode, + bool keep_dims) { + std::shared_ptr pow = std::make_shared( + value, + std::make_shared(value.get_element_type(), Shape{}, 2)); + std::shared_ptr values{std::make_shared(pow, reduction_axes, keep_dims)}; + + std::shared_ptr bias_node{ov::op::v0::Constant::create(values->get_element_type(), Shape{}, {bias})}; + std::shared_ptr result; + switch (bias_mode) { + case BiasMode::MAX: { + result = std::make_shared(std::make_shared(values, bias_node)); + break; + } + case BiasMode::ADD: + default: + result = std::make_shared(std::make_shared(values, bias_node)); + } + return result; +} +} // namespace + +std::shared_ptr lp_norm(const Output& value, + const Output& reduction_axes, + size_t p_norm, + float bias, + bool keep_dims) { + // The number of non-zero elements + if (p_norm == 0) { + return l0_norm(value, reduction_axes, keep_dims); + } + // sum of absolute values. + else if (p_norm == 1) { + return l1_norm(value, reduction_axes, bias, keep_dims); + } + // sqrt of sum of squares - Euclidean norm + else if (p_norm == 2) { + return l2_norm(value, reduction_axes, bias, BiasMode::ADD, keep_dims); + } + // generic case + else { + return lp_norm(value, p_norm, reduction_axes, bias, keep_dims); + } +} +} // namespace util +} // namespace op +} // namespace ov diff --git a/src/tests/ov_helpers/ov_models/ov_builders/src/reshape.cpp b/src/tests/ov_helpers/ov_models/ov_builders/src/reshape.cpp new file mode 100644 index 00000000000..ef3471bf819 --- /dev/null +++ b/src/tests/ov_helpers/ov_models/ov_builders/src/reshape.cpp @@ -0,0 +1,126 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ov_models/ov_builders/reshape.hpp" + +#include "openvino/op/add.hpp" +#include "openvino/op/broadcast.hpp" +#include "openvino/op/concat.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/convert.hpp" +#include "openvino/op/range.hpp" +#include "openvino/op/reduce_prod.hpp" +#include "openvino/op/reshape.hpp" +#include "openvino/op/shape_of.hpp" +#include "openvino/op/squeeze.hpp" +#include "openvino/op/strided_slice.hpp" +#include "openvino/op/subtract.hpp" +#include "openvino/op/transpose.hpp" +#include "openvino/op/variadic_split.hpp" + +namespace ov { +namespace op { +namespace util { +std::shared_ptr reshape(const Output& value, const Shape& shape) { + if (value.get_partial_shape().same_scheme(shape)) { + return value.get_node_shared_ptr(); + } else if (is_scalar(shape)) { + auto value_rank = value.get_shape().size(); + AxisVector axes_vector(value_rank); + std::iota(axes_vector.begin(), axes_vector.end(), 0); + auto axes = ov::op::v0::Constant::create(element::i64, Shape{value_rank}, axes_vector); + return std::make_shared(value, axes); + } else { + auto out_pattern = ov::op::v0::Constant::create(element::i64, + Shape{shape.size()}, + std::vector(shape.begin(), shape.end())); + + return std::make_shared(value, out_pattern, false); + } +} + +std::shared_ptr reorder_axes(const Output& value, std::vector axes_order) { + const auto axes_order_const = + ov::op::v0::Constant::create(element::i64, + Shape{axes_order.size()}, + std::vector(axes_order.begin(), axes_order.end())); + return std::make_shared(value, axes_order_const); +} + +std::shared_ptr transpose(const Output& value) { + // This part is left to preserve backward compatibility and ensure passing ONNX tests. + if (value.get_partial_shape().is_static()) { + std::vector axes_order(value.get_shape().size()); + std::iota(begin(axes_order), end(axes_order), 0); + std::reverse(begin(axes_order), end(axes_order)); + return reorder_axes(value, axes_order); + } + + const auto input_rank = std::make_shared(std::make_shared(value)); + const auto neg_one = ov::op::v0::Constant::create(element::i64, Shape{}, {-1}); + const auto start_node = std::make_shared(input_rank, neg_one); + const auto reverse_axes_order = std::make_shared(reshape(start_node, Shape{}), // start + neg_one, // stop (exclusive) + neg_one); // step + return std::make_shared(value, reverse_axes_order); +} + +namespace { +/// +/// \brief Return the node representing normalized axis with respect to +/// provided rank. +/// +/// \param[in] node_rank The node representing rank used for normalization. +/// \param[in] axis The axis value to be normalized. +/// +/// \return The new Constant node representing normalized axis value. +/// +std::shared_ptr get_normalized_axis_node(const std::shared_ptr node_rank, int64_t axis) { + auto axis_node = ov::op::v0::Constant::create(element::i64, Shape{1}, {axis}); + // shortcut for already positive value + if (axis >= 0) { + return axis_node; + } + + // TODO: What if axis value is beyond acceptable values? [-node_rank, + // node_rank-1] + return std::make_shared(node_rank, axis_node); +} +} // namespace + +std::shared_ptr flatten(const Output& value, int axis) { + // First dimension of output tensor is the product of [d_0, ... d_{axis-1}] dimensions of + // input tensor. The last dimension is the product of the rest of input tensor dimensions: + // [d_{axis}, ..., d_n] + std::shared_ptr output_shape; + if (axis == 0) { + output_shape = ov::op::v0::Constant::create(element::i64, Shape{2}, {1, -1}); + } else if (axis == 1) { + output_shape = ov::op::v0::Constant::create(element::i64, Shape{2}, {0, -1}); + } else { + const auto value_shape = std::make_shared(value); + const auto value_rank = std::make_shared(value_shape); + const auto axis_node = get_normalized_axis_node(value_rank, axis); + + const auto first_part_dims = + std::make_shared(value_shape, + ov::op::v0::Constant::create(element::i64, {1}, {0}), + axis_node, + std::vector{0}, + std::vector{0}); + const auto first_part_dims_length = + std::make_shared(first_part_dims, + ov::op::v0::Constant::create(element::i64, {}, {0}), + true); + + const auto remaining_part_length = ov::op::v0::Constant::create(element::i64, {1}, {-1}); + + output_shape = + std::make_shared(OutputVector{first_part_dims_length, remaining_part_length}, 0); + } + return std::make_shared(value, output_shape, true); +} +} // namespace util +} // namespace op +} // namespace ov diff --git a/src/tests/ov_helpers/ov_models/ov_builders/src/split.cpp b/src/tests/ov_helpers/ov_models/ov_builders/src/split.cpp new file mode 100644 index 00000000000..af87cf8781f --- /dev/null +++ b/src/tests/ov_helpers/ov_models/ov_builders/src/split.cpp @@ -0,0 +1,31 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ov_models/ov_builders/split.hpp" + +#include "openvino/op/constant.hpp" +#include "openvino/op/split.hpp" +#include "openvino/op/variadic_split.hpp" + +namespace ov { +namespace op { +namespace util { +OutputVector split(const Output& value, const std::vector& split_lengths, int64_t axis) { + const auto axis_node = ov::op::v0::Constant::create(element::i64, Shape{}, {axis}); + const auto split_lengths_node = + ov::op::v0::Constant::create(element::i64, Shape{split_lengths.size()}, split_lengths); + const auto variadic_split = std::make_shared(value, axis_node, split_lengths_node); + + return variadic_split->outputs(); +} + +OutputVector split(const Output& value, int64_t num_splits, int64_t axis) { + const auto axis_node = ov::op::v0::Constant::create(element::i64, Shape{}, {axis}); + const auto split = std::make_shared(value, axis_node, num_splits); + + return split->outputs(); +} +} // namespace util +} // namespace op +} // namespace ov diff --git a/src/tests/ov_helpers/ov_models/src/ov_builder/broadcast.cpp b/src/tests/ov_helpers/ov_models/src/ov_builder/broadcast.cpp new file mode 100644 index 00000000000..3b6e6c8be44 --- /dev/null +++ b/src/tests/ov_helpers/ov_models/src/ov_builder/broadcast.cpp @@ -0,0 +1,89 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ov_models/ov_builders/broadcast.hpp" + +#include "openvino/op/add.hpp" +#include "openvino/op/broadcast.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/convert.hpp" +#include "openvino/op/range.hpp" +#include "openvino/op/reshape.hpp" +#include "openvino/op/shape_of.hpp" +#include "ov_models/ov_builders/reshape.hpp" + +namespace ov { +namespace op { +namespace util { +namespace { +/// +/// \brief Reconstructs axes mapping vector for Broadcast:v1 operation. +/// +/// \param[in] output_shape The output shape of Broadcast operation. +/// \param[in] broadcast_axes The broadcast axes used for Broadcast:v0 operator. +/// +/// \return The vector with axes indexes mapping . +/// +std::vector get_axes_mapping(const Shape& output_shape, const AxisSet& broadcast_axes) { + NGRAPH_CHECK((broadcast_axes.size() <= output_shape.size())); + std::vector axes_mapping(output_shape.size()); + iota(axes_mapping.begin(), axes_mapping.end(), 0); + for (auto i = broadcast_axes.rbegin(); i != broadcast_axes.rend(); ++i) { + axes_mapping.erase(axes_mapping.begin() + *i); + } + return axes_mapping; +} + +/// +/// \brief Creates Node returning the axes mapping for Broadcast:v1 operation. +/// +/// \param[in] output_shape The output shape of Broadcast operation. +/// \param[in] broadcast_axes The broadcast axes used for Broadcast:v0 operator. +/// +/// \return The Output object with Node returning axes mapping. +/// +Output get_axes_mapping_output(const Shape& output_shape, const AxisSet& broadcast_axes) { + std::vector axes_mapping{get_axes_mapping(output_shape, broadcast_axes)}; + return ov::op::v0::Constant::create(element::i64, Shape{axes_mapping.size()}, axes_mapping); +} + +static Output get_axes_mapping_output(const PartialShape& output_shape, + const Output& input_shape, + std::size_t start_match_axis) { + const auto one_node = ov::op::v0::Constant::create(element::i64, Shape{}, {1}); + const auto zero_node = ov::op::v0::Constant::create(element::i64, Shape{}, {0}); + const auto start_match_axis_node = ov::op::v0::Constant::create(element::i64, Shape{}, {start_match_axis}); + const auto target_shape_rank_node = + ov::op::util::reshape(std::make_shared(input_shape), Shape{}); + + const auto range_node = + std::make_shared(zero_node, target_shape_rank_node, one_node, element::i64); + + // workaround for GPU plugin type incompatibility + const auto range_node_converted = + std::make_shared(range_node, start_match_axis_node->get_element_type()); + // end of workaround + + const auto result = std::make_shared(range_node_converted, start_match_axis_node); + return result; +} +} // namespace + +Output make_broadcast(const Output& node, const Shape& target_shape, const AxisSet& broadcast_axes) { + return std::make_shared( + node, + ov::op::v0::Constant::create(element::i64, Shape{target_shape.size()}, target_shape), + get_axes_mapping_output(target_shape, broadcast_axes)); +} + +Output make_broadcast(const Output& node, const Shape& target_shape, size_t start_match_axis) { + const auto node_shape = std::make_shared(node); + return std::make_shared( + node, + ov::op::v0::Constant::create(element::i64, Shape{target_shape.size()}, target_shape), + get_axes_mapping_output(target_shape, node_shape, start_match_axis)); +} +} // namespace util +} // namespace op +} // namespace ov diff --git a/src/tests/ov_helpers/ov_models/src/ov_builder/split.cpp b/src/tests/ov_helpers/ov_models/src/ov_builder/split.cpp new file mode 100644 index 00000000000..af87cf8781f --- /dev/null +++ b/src/tests/ov_helpers/ov_models/src/ov_builder/split.cpp @@ -0,0 +1,31 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ov_models/ov_builders/split.hpp" + +#include "openvino/op/constant.hpp" +#include "openvino/op/split.hpp" +#include "openvino/op/variadic_split.hpp" + +namespace ov { +namespace op { +namespace util { +OutputVector split(const Output& value, const std::vector& split_lengths, int64_t axis) { + const auto axis_node = ov::op::v0::Constant::create(element::i64, Shape{}, {axis}); + const auto split_lengths_node = + ov::op::v0::Constant::create(element::i64, Shape{split_lengths.size()}, split_lengths); + const auto variadic_split = std::make_shared(value, axis_node, split_lengths_node); + + return variadic_split->outputs(); +} + +OutputVector split(const Output& value, int64_t num_splits, int64_t axis) { + const auto axis_node = ov::op::v0::Constant::create(element::i64, Shape{}, {axis}); + const auto split = std::make_shared(value, axis_node, num_splits); + + return split->outputs(); +} +} // namespace util +} // namespace op +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/CMakeLists.txt b/src/tests/test_utils/common_test_utils/CMakeLists.txt index 1112ccd0855..7514aa476ad 100644 --- a/src/tests/test_utils/common_test_utils/CMakeLists.txt +++ b/src/tests/test_utils/common_test_utils/CMakeLists.txt @@ -31,6 +31,7 @@ function(add_common_utils ADD_TARGET_NAME) ov_models openvino::runtime openvino::runtime::dev + openvino::builders PRIVATE openvino::util openvino::shape_inference diff --git a/tools/mo/unit_tests/mock_mo_frontend/mock_mo_frontend/CMakeLists.txt b/tools/mo/unit_tests/mock_mo_frontend/mock_mo_frontend/CMakeLists.txt index cb86b4016ee..0fff4428700 100644 --- a/tools/mo/unit_tests/mock_mo_frontend/mock_mo_frontend/CMakeLists.txt +++ b/tools/mo/unit_tests/mock_mo_frontend/mock_mo_frontend/CMakeLists.txt @@ -15,7 +15,7 @@ add_library(${TARGET_FE_NAME} SHARED ${LIBRARY_SRC} ${LIBRARY_HEADERS}) target_include_directories(${TARGET_FE_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(${TARGET_FE_NAME} PUBLIC openvino::runtime PRIVATE openvino::builders) +target_link_libraries(${TARGET_FE_NAME} PUBLIC openvino::runtime) ov_add_clang_format_target(${TARGET_FE_NAME}_clang FOR_TARGETS ${TARGET_FE_NAME})