From 08fa27762ec37ea475df47ee27228876e9fb2255 Mon Sep 17 00:00:00 2001 From: Oleg Pipikin Date: Wed, 22 Nov 2023 12:47:33 +0100 Subject: [PATCH] Refactor ngraph builders 6 (#21133) * Refactor make_convolution builders * refactor make_activation builders * Refactor make_eltwise builder * Refactor make_embedding_bag_offsets_sum * Refactor make_embedding_bag_packed_sum * Refactor make_embedding_segments_sum * Fix * Apply comments --- .../single_layer_tests/convolution.cpp | 7 +- .../convolution_backprop_data.cpp | 9 +- .../single_layer_tests/group_convolution.cpp | 6 +- .../group_convolution_backprop_data.cpp | 10 +- .../single_layer/embedding_bag_packed_sum.cpp | 6 +- .../src/single_op/activation.cpp | 6 +- .../src/single_op/binary_convolution.cpp | 3 +- .../single_op/convolution_backprop_data.cpp | 14 +- .../src/single_op/eltwise.cpp | 4 +- .../single_op/embedding_bag_offsets_sum.cpp | 4 +- .../src/single_op/embedding_segments_sum.cpp | 20 +- .../src/single_op/group_convolution.cpp | 6 +- .../group_convolution_backprop_data.cpp | 10 +- .../node_builders/activation.hpp | 22 +++ .../node_builders/binary_convolution.hpp | 22 +++ .../node_builders/convolution.hpp | 37 ++++ .../convolution_backprop_data.hpp | 54 ++++++ .../node_builders/eltwise.hpp | 16 ++ .../embedding_bag_offsets_sum.hpp | 20 ++ .../embedding_bag_packed_sum.hpp | 17 ++ .../node_builders/embedding_segments_sum.hpp | 21 +++ .../node_builders/group_convolution.hpp | 36 ++++ .../group_convolution_backprop_data.hpp | 54 ++++++ .../src/node_builders/activation.cpp | 170 +++++++++++++++++ .../src/node_builders/binary_convolution.cpp | 55 ++++++ .../src/node_builders/convolution.cpp | 101 ++++++++++ .../convolution_backprop_data.cpp | 163 ++++++++++++++++ .../src/node_builders/eltwise.cpp | 61 ++++++ .../embedding_bag_offsets_sum.cpp | 52 ++++++ .../embedding_bag_packed_sum.cpp | 39 ++++ .../node_builders/embedding_segments_sum.cpp | 60 ++++++ .../src/node_builders/group_convolution.cpp | 86 +++++++++ .../group_convolution_backprop_data.cpp | 174 ++++++++++++++++++ 33 files changed, 1312 insertions(+), 53 deletions(-) create mode 100644 src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/activation.hpp create mode 100644 src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/binary_convolution.hpp create mode 100644 src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/convolution.hpp create mode 100644 src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/convolution_backprop_data.hpp create mode 100644 src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/eltwise.hpp create mode 100644 src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_bag_offsets_sum.hpp create mode 100644 src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_bag_packed_sum.hpp create mode 100644 src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_segments_sum.hpp create mode 100644 src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/group_convolution.hpp create mode 100644 src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/group_convolution_backprop_data.hpp create mode 100644 src/tests/test_utils/common_test_utils/src/node_builders/activation.cpp create mode 100644 src/tests/test_utils/common_test_utils/src/node_builders/binary_convolution.cpp create mode 100644 src/tests/test_utils/common_test_utils/src/node_builders/convolution.cpp create mode 100644 src/tests/test_utils/common_test_utils/src/node_builders/convolution_backprop_data.cpp create mode 100644 src/tests/test_utils/common_test_utils/src/node_builders/eltwise.cpp create mode 100644 src/tests/test_utils/common_test_utils/src/node_builders/embedding_bag_offsets_sum.cpp create mode 100644 src/tests/test_utils/common_test_utils/src/node_builders/embedding_bag_packed_sum.cpp create mode 100644 src/tests/test_utils/common_test_utils/src/node_builders/embedding_segments_sum.cpp create mode 100644 src/tests/test_utils/common_test_utils/src/node_builders/group_convolution.cpp create mode 100644 src/tests/test_utils/common_test_utils/src/node_builders/group_convolution_backprop_data.cpp diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/convolution.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/convolution.cpp index 85c5cd35b11..aed06f2840d 100755 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/convolution.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/convolution.cpp @@ -8,7 +8,7 @@ #include "test_utils/fusing_test_utils.hpp" #include "shared_test_classes/base/ov_subgraph.hpp" #include "ov_models/utils/ov_helpers.hpp" -#include "ov_models/builders.hpp" +#include "common_test_utils/node_builders/convolution.hpp" #include "openvino/core/visibility.hpp" #include #include "utils/general_utils.h" @@ -203,8 +203,9 @@ protected: ov::ParameterVector inputParams; for (auto&& shape : inputDynamicShapes) inputParams.push_back(std::make_shared(ov::element::f32, shape)); - auto convolutionNode = ngraph::builder::makeConvolution(inputParams[0], netType, kernel, stride, padBegin, - padEnd, dilation, padType, convOutChannels); + + auto convolutionNode = ov::test::utils::make_convolution(inputParams[0], netType, kernel, stride, padBegin, + padEnd, dilation, padType, convOutChannels); function = makeNgraphFunction(netType, inputParams, convolutionNode, "Convolution"); } diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/convolution_backprop_data.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/convolution_backprop_data.cpp index 40e53640e34..265ab3da1bd 100755 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/convolution_backprop_data.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/convolution_backprop_data.cpp @@ -13,6 +13,7 @@ #include "test_utils/cpu_test_utils.hpp" #include "test_utils/filter_cpu_info.hpp" #include "test_utils/fusing_test_utils.hpp" +#include "common_test_utils/node_builders/convolution_backprop_data.hpp" using namespace CPUTestUtils; using namespace ov::test; @@ -164,11 +165,11 @@ public: std::shared_ptr deconv; if (!outShapeData.empty()) { OPENVINO_ASSERT(outShapeNode != nullptr); - deconv = ngraph::builder::makeConvolutionBackpropData(params[0], outShapeNode, prec, kernel, stride, padBegin, - padEnd, dilation, padType, convOutChannels); + deconv = ov::test::utils::make_convolution_backprop_data(params[0], outShapeNode, prec, kernel, stride, padBegin, + padEnd, dilation, padType, convOutChannels); } else { - deconv = ngraph::builder::makeConvolutionBackpropData(params[0], prec, kernel, stride, padBegin, - padEnd, dilation, padType, convOutChannels, false, outPadding); + deconv = ov::test::utils::make_convolution_backprop_data(params[0], prec, kernel, stride, padBegin, + padEnd, dilation, padType, convOutChannels, false, outPadding); } return makeNgraphFunction(prec, params, deconv, "DeconvCPU"); diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/group_convolution.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/group_convolution.cpp index b03fb47371a..c3a140384d5 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/group_convolution.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/group_convolution.cpp @@ -8,6 +8,7 @@ #include "test_utils/convolution_params.hpp" #include "test_utils/fusing_test_utils.hpp" #include "test_utils/filter_cpu_info.hpp" +#include "common_test_utils/node_builders/group_convolution.hpp" using namespace InferenceEngine; using namespace CPUTestUtils; @@ -197,9 +198,8 @@ protected: for (auto&& shape : inputDynamicShapes) params.push_back(std::make_shared(netType, shape)); - auto groupConv = std::dynamic_pointer_cast( - ngraph::builder::makeGroupConvolution(params[0], netType, kernel, stride, padBegin, - padEnd, dilation, padType, convOutChannels, numGroups)); + auto groupConv = ov::test::utils::make_group_convolution(params[0], netType, kernel, stride, padBegin, + padEnd, dilation, padType, convOutChannels, numGroups); function = makeNgraphFunction(netType, params, groupConv, "groupConvolution"); } }; diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/group_convolution_backprop_data.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/group_convolution_backprop_data.cpp index 060aaac5659..cfdb4ee8bc0 100755 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/group_convolution_backprop_data.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/group_convolution_backprop_data.cpp @@ -8,9 +8,9 @@ #include "test_utils/fusing_test_utils.hpp" #include "shared_test_classes/base/ov_subgraph.hpp" #include -#include "ov_models/builders.hpp" #include #include "openvino/core/preprocess/pre_post_process.hpp" +#include "common_test_utils/node_builders/group_convolution_backprop_data.hpp" using namespace CPUTestUtils; using namespace ov::test; @@ -183,11 +183,11 @@ public: std::shared_ptr deconv; if (!outShapeData.empty()) { OPENVINO_ASSERT(outShapeNode != nullptr); - deconv = ngraph::builder::makeGroupConvolutionBackpropData(params[0], outShapeNode, prec, kernel, stride, padBegin, - padEnd, dilation, padType, convOutChannels, groupNum); + deconv = ov::test::utils::make_group_convolution_backprop_data(params[0], outShapeNode, prec, kernel, stride, padBegin, + padEnd, dilation, padType, convOutChannels, groupNum); } else { - deconv = ngraph::builder::makeGroupConvolutionBackpropData(params[0], prec, kernel, stride, padBegin, - padEnd, dilation, padType, convOutChannels, groupNum, false, outPadding); + deconv = ov::test::utils::make_group_convolution_backprop_data(params[0], prec, kernel, stride, padBegin, + padEnd, dilation, padType, convOutChannels, groupNum, false, outPadding); } return makeNgraphFunction(prec, params, deconv, "GroupDeconvCPU"); diff --git a/src/tests/functional/shared_test_classes/src/single_layer/embedding_bag_packed_sum.cpp b/src/tests/functional/shared_test_classes/src/single_layer/embedding_bag_packed_sum.cpp index 262ff84cbd6..4f8deac2409 100644 --- a/src/tests/functional/shared_test_classes/src/single_layer/embedding_bag_packed_sum.cpp +++ b/src/tests/functional/shared_test_classes/src/single_layer/embedding_bag_packed_sum.cpp @@ -3,7 +3,7 @@ // #include "shared_test_classes/single_layer/embedding_bag_packed_sum.hpp" -#include "ov_models/builders.hpp" +#include "common_test_utils/node_builders/embedding_bag_packed_sum.hpp" namespace LayerTestsDefinitions { @@ -42,9 +42,7 @@ void EmbeddingBagPackedSumLayerTest::SetUp() { auto emb_table_node = std::make_shared(ngPrc, ngraph::Shape(embTableShape)); ngraph::ParameterVector params = {emb_table_node}; - auto embBag = std::dynamic_pointer_cast( - ngraph::builder::makeEmbeddingBagPackedSum( - ngPrc, ngIdxPrc, emb_table_node, indices, withWeights)); + auto embBag = ov::test::utils::make_embedding_bag_packed_sum(ngPrc, ngIdxPrc, emb_table_node, indices, withWeights); ngraph::ResultVector results{std::make_shared(embBag)}; function = std::make_shared(results, params, "embeddingBagPackedSum"); } diff --git a/src/tests/functional/shared_test_classes/src/single_op/activation.cpp b/src/tests/functional/shared_test_classes/src/single_op/activation.cpp index c30c1f7d46a..b0d27e82eab 100644 --- a/src/tests/functional/shared_test_classes/src/single_op/activation.cpp +++ b/src/tests/functional/shared_test_classes/src/single_op/activation.cpp @@ -4,7 +4,7 @@ #include "shared_test_classes/single_op/activation.hpp" -#include "ov_models/builders.hpp" +#include "common_test_utils/node_builders/activation.hpp" #include "openvino/op/parameter.hpp" #include "openvino/op/constant.hpp" #include "openvino/op/result.hpp" @@ -65,7 +65,7 @@ void ActivationLayerTest::SetUp() { std::iota(constants_value.begin(), constants_value.end(), -10); } - auto activation = ngraph::builder::makeActivation(param, model_type, activationType, const_shape, constants_value); + auto activation = ov::test::utils::make_activation(param, model_type, activationType, const_shape, constants_value); auto result = std::make_shared(activation); @@ -131,7 +131,7 @@ void ActivationParamLayerTest::SetUp() { params[0]->set_friendly_name("Input"); - auto activation = ngraph::builder::makeActivation(params, model_type, activationType); + auto activation = ov::test::utils::make_activation(params, model_type, activationType); auto result = std::make_shared(activation); function = std::make_shared(result, params); } diff --git a/src/tests/functional/shared_test_classes/src/single_op/binary_convolution.cpp b/src/tests/functional/shared_test_classes/src/single_op/binary_convolution.cpp index b2f056457a8..8d2cb126181 100644 --- a/src/tests/functional/shared_test_classes/src/single_op/binary_convolution.cpp +++ b/src/tests/functional/shared_test_classes/src/single_op/binary_convolution.cpp @@ -6,6 +6,7 @@ #include "ov_models/builders.hpp" #include "common_test_utils/ov_tensor_utils.hpp" +#include "common_test_utils/node_builders/binary_convolution.hpp" namespace ov { namespace test { @@ -70,7 +71,7 @@ void BinaryConvolutionLayerTest::SetUp() { // TODO: refactor build BinaryConvolution op to accept filters input as Parameter auto bin_conv = - ngraph::builder::makeBinaryConvolution(params[0], kernel_size, strides, pads_begin, pads_end, dilations, pad_type, num_out_channels, pad_value); + ov::test::utils::make_binary_convolution(params[0], kernel_size, strides, pads_begin, pads_end, dilations, pad_type, num_out_channels, pad_value); auto result = std::make_shared(bin_conv); function = std::make_shared(ov::OutputVector{result}, params, "BinaryConvolution"); } diff --git a/src/tests/functional/shared_test_classes/src/single_op/convolution_backprop_data.cpp b/src/tests/functional/shared_test_classes/src/single_op/convolution_backprop_data.cpp index 578d2e83b99..ffc4ee580a8 100644 --- a/src/tests/functional/shared_test_classes/src/single_op/convolution_backprop_data.cpp +++ b/src/tests/functional/shared_test_classes/src/single_op/convolution_backprop_data.cpp @@ -10,7 +10,7 @@ #include "openvino/op/constant.hpp" #include "openvino/op/result.hpp" #include "openvino/op/convolution.hpp" -#include "ov_models/builders.hpp" +#include "common_test_utils/node_builders/convolution_backprop_data.hpp" namespace ov { namespace test { @@ -70,16 +70,14 @@ void ConvolutionBackpropDataLayerTest::SetUp() { ov::ParameterVector params{std::make_shared(model_type, inputDynamicShapes.front())}; - std::shared_ptr convBackpropData; + std::shared_ptr convBackpropData; if (!output_shape.empty()) { auto outShape = ov::op::v0::Constant::create(ov::element::i64, {output_shape.size()}, output_shape); - convBackpropData = std::dynamic_pointer_cast( - ngraph::builder::makeConvolutionBackpropData(params[0]->output(0), outShape, model_type, kernel, stride, pad_begin, - pad_end, dilation, pad_type, convOutChannels)); + convBackpropData = ov::test::utils::make_convolution_backprop_data( + params[0]->output(0), outShape, model_type, kernel, stride, pad_begin, pad_end, dilation, pad_type, convOutChannels); } else { - convBackpropData = std::dynamic_pointer_cast( - ngraph::builder::makeConvolutionBackpropData(params[0]->output(0), model_type, kernel, stride, pad_begin, - pad_end, dilation, pad_type, convOutChannels, false, out_padding)); + convBackpropData = ov::test::utils::make_convolution_backprop_data( + params[0]->output(0), model_type, kernel, stride, pad_begin, pad_end, dilation, pad_type, convOutChannels, false, out_padding); } function = std::make_shared(std::make_shared(convBackpropData), params, "convolutionBackpropData"); } diff --git a/src/tests/functional/shared_test_classes/src/single_op/eltwise.cpp b/src/tests/functional/shared_test_classes/src/single_op/eltwise.cpp index b05e8be0e44..f4790c91d47 100644 --- a/src/tests/functional/shared_test_classes/src/single_op/eltwise.cpp +++ b/src/tests/functional/shared_test_classes/src/single_op/eltwise.cpp @@ -6,7 +6,7 @@ #include "shared_test_classes/single_op/eltwise.hpp" #include "common_test_utils/ov_tensor_utils.hpp" -#include "ov_models/builders.hpp" +#include "common_test_utils/node_builders/eltwise.hpp" namespace ov { namespace test { @@ -128,7 +128,7 @@ void EltwiseLayerTest::SetUp() { parameters[0]->set_friendly_name("param0"); secondary_input->set_friendly_name("param1"); - auto eltwise = ngraph::builder::makeEltwise(parameters[0], secondary_input, eltwise_type); + auto eltwise = ov::test::utils::makeEltwise(parameters[0], secondary_input, eltwise_type); function = std::make_shared(eltwise, parameters, "Eltwise"); } } // namespace test diff --git a/src/tests/functional/shared_test_classes/src/single_op/embedding_bag_offsets_sum.cpp b/src/tests/functional/shared_test_classes/src/single_op/embedding_bag_offsets_sum.cpp index acbcda3a108..eaf7d015d74 100644 --- a/src/tests/functional/shared_test_classes/src/single_op/embedding_bag_offsets_sum.cpp +++ b/src/tests/functional/shared_test_classes/src/single_op/embedding_bag_offsets_sum.cpp @@ -3,7 +3,7 @@ // #include "shared_test_classes/single_op/embedding_bag_offsets_sum.hpp" -#include "ov_models/builders.hpp" +#include "common_test_utils/node_builders/embedding_bag_offsets_sum.hpp" namespace ov { namespace test { @@ -56,7 +56,7 @@ void EmbeddingBagOffsetsSumLayerTest::SetUp() { auto param = std::make_shared(model_type, inputDynamicShapes.front()); - auto embBag = ngraph::builder::makeEmbeddingBagOffsetsSum(model_type, ind_type, param, indices, offsets, default_index, with_weights, with_def_index); + auto embBag = ov::test::utils::make_embedding_bag_offsets_sum(model_type, ind_type, param, indices, offsets, default_index, with_weights, with_def_index); auto result = std::make_shared(embBag); function = std::make_shared(result, ov::ParameterVector{param}, "embeddingBagOffsetsSum"); diff --git a/src/tests/functional/shared_test_classes/src/single_op/embedding_segments_sum.cpp b/src/tests/functional/shared_test_classes/src/single_op/embedding_segments_sum.cpp index b3ded1f3d9a..029e9645978 100644 --- a/src/tests/functional/shared_test_classes/src/single_op/embedding_segments_sum.cpp +++ b/src/tests/functional/shared_test_classes/src/single_op/embedding_segments_sum.cpp @@ -3,7 +3,7 @@ // #include "shared_test_classes/single_op/embedding_segments_sum.hpp" -#include "ov_models/builders.hpp" +#include "common_test_utils/node_builders/embedding_segments_sum.hpp" namespace ov { @@ -59,15 +59,15 @@ void EmbeddingSegmentsSumLayerTest::SetUp() { auto param = std::make_shared(model_type, inputDynamicShapes.front()); - auto embBag = ngraph::builder::makeEmbeddingSegmentsSum(model_type, - ind_type, - param, - indices, - segment_ids, - num_segments, - default_index, - with_weights, - with_def_index); + auto embBag = ov::test::utils::make_embedding_segments_sum(model_type, + ind_type, + param, + indices, + segment_ids, + num_segments, + default_index, + with_weights, + with_def_index); auto result = std::make_shared(embBag); function = std::make_shared(result, ov::ParameterVector{param}, "embeddingSegmentsSum"); diff --git a/src/tests/functional/shared_test_classes/src/single_op/group_convolution.cpp b/src/tests/functional/shared_test_classes/src/single_op/group_convolution.cpp index f86f0014826..902adace6fe 100644 --- a/src/tests/functional/shared_test_classes/src/single_op/group_convolution.cpp +++ b/src/tests/functional/shared_test_classes/src/single_op/group_convolution.cpp @@ -4,7 +4,7 @@ #include "shared_test_classes/single_op/group_convolution.hpp" -#include "ov_models/builders.hpp" +#include "common_test_utils/node_builders/group_convolution.hpp" #include "openvino/op/parameter.hpp" #include "openvino/op/result.hpp" #include "openvino/op/constant.hpp" @@ -64,8 +64,8 @@ void GroupConvolutionLayerTest::SetUp() { auto param = std::make_shared(model_type, inputDynamicShapes.front()); - auto group_conv = ngraph::builder::makeGroupConvolution(param, model_type, kernel, stride, pad_begin, - pad_end, dilation, pad_type, conv_out_channels, num_groups); + auto group_conv = ov::test::utils::make_group_convolution( + param, model_type, kernel, stride, pad_begin, pad_end, dilation, pad_type, conv_out_channels, num_groups); auto result = std::make_shared(group_conv); function = std::make_shared(result, ov::ParameterVector{param}, "groupConvolution"); diff --git a/src/tests/functional/shared_test_classes/src/single_op/group_convolution_backprop_data.cpp b/src/tests/functional/shared_test_classes/src/single_op/group_convolution_backprop_data.cpp index a1db20a736a..4cd09211c73 100644 --- a/src/tests/functional/shared_test_classes/src/single_op/group_convolution_backprop_data.cpp +++ b/src/tests/functional/shared_test_classes/src/single_op/group_convolution_backprop_data.cpp @@ -4,7 +4,7 @@ #include "shared_test_classes/single_op/group_convolution_backprop_data.hpp" -#include "ov_models/builders.hpp" +#include "common_test_utils/node_builders/group_convolution_backprop_data.hpp" #include "openvino/op/parameter.hpp" #include "openvino/op/result.hpp" #include "openvino/op/constant.hpp" @@ -71,11 +71,11 @@ void GroupConvBackpropLayerTest::SetUp() { std::shared_ptr group_conv; if (!output_shape.empty()) { auto outShape = ov::op::v0::Constant::create(ov::element::i64, {output_shape.size()}, output_shape); - group_conv = ngraph::builder::makeGroupConvolutionBackpropData(param, outShape, model_type, kernel, stride, pad_begin, - pad_end, dilation, pad_type, conv_out_channels, num_groups, false, out_padding); + group_conv = ov::test::utils::make_group_convolution_backprop_data( + param, outShape, model_type, kernel, stride, pad_begin, pad_end, dilation, pad_type, conv_out_channels, num_groups, false, out_padding); } else { - group_conv = ngraph::builder::makeGroupConvolutionBackpropData(param, model_type, kernel, stride, pad_begin, - pad_end, dilation, pad_type, conv_out_channels, num_groups, false, out_padding); + group_conv = ov::test::utils::make_group_convolution_backprop_data( + param, model_type, kernel, stride, pad_begin, pad_end, dilation, pad_type, conv_out_channels, num_groups, false, out_padding); } auto result = std::make_shared(group_conv); diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/activation.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/activation.hpp new file mode 100644 index 00000000000..70e5fcce77c --- /dev/null +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/activation.hpp @@ -0,0 +1,22 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_test_utils/test_enums.hpp" +#include "openvino/core/node.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr make_activation(const ov::Output& in, + const element::Type& type, + ov::test::utils::ActivationTypes activation_type, + ov::Shape in_shape = {}, + std::vector constants_value = {}); + +std::shared_ptr make_activation(const ov::ParameterVector& parameters, + const element::Type& type, + ov::test::utils::ActivationTypes activation_type); +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/binary_convolution.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/binary_convolution.hpp new file mode 100644 index 00000000000..3b769443056 --- /dev/null +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/binary_convolution.hpp @@ -0,0 +1,22 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/core/node.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr make_binary_convolution(const ov::Output& in, + const std::vector& filterSize, + const std::vector& strides, + const std::vector& padsBegin, + const std::vector& padsEnd, + const std::vector& dilations, + const ov::op::PadType& autoPad, + size_t numOutChannels, + float padValue, + const std::vector& filterWeihgts = {}); +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/convolution.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/convolution.hpp new file mode 100644 index 00000000000..9060fd132a8 --- /dev/null +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/convolution.hpp @@ -0,0 +1,37 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/core/node.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr make_convolution(const ov::Output& in, + const ov::element::Type& type, + const std::vector& filterSize, + const std::vector& strides, + const std::vector& padsBegin, + const std::vector& padsEnd, + const std::vector& dilations, + const ov::op::PadType& autoPad, + size_t numOutChannels, + bool addBiases = false, + const std::vector& filterWeights = {}, + const std::vector& biasesWeights = {}); + +std::shared_ptr make_convolution(const ov::Output& in_data, + const ov::Output& in_weights, + const ov::element::Type& type, + const std::vector& filterSize, + const std::vector& strides, + const std::vector& padsBegin, + const std::vector& padsEnd, + const std::vector& dilations, + const ov::op::PadType& autoPad, + size_t numOutChannels, + bool addBiases = false, + const std::vector& biasesWeights = {}); +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/convolution_backprop_data.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/convolution_backprop_data.hpp new file mode 100644 index 00000000000..c0ae90df18b --- /dev/null +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/convolution_backprop_data.hpp @@ -0,0 +1,54 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/core/node.hpp" + +namespace ov { +namespace test { +namespace utils { + +std::shared_ptr make_convolution_backprop_data(const ov::Output& in, + const ov::element::Type& type, + const std::vector& filterSize, + const std::vector& strides, + const std::vector& padsBegin, + const std::vector& padsEnd, + const std::vector& dilations, + const ov::op::PadType& autoPad, + size_t numOutChannels, + bool addBiases = false, + const std::vector& outputPadding = {}, + const std::vector& filterWeights = {}, + const std::vector& biasesWeights = {}); + +std::shared_ptr make_convolution_backprop_data(const ov::Output& in, + const ov::Output& weights, + const ov::element::Type& type, + const std::vector& strides, + const std::vector& padsBegin, + const std::vector& padsEnd, + const std::vector& dilations, + const ov::op::PadType& autoPad, + bool addBiases = false, + const std::vector& outputPadding = {}, + const std::vector& biasesWeights = {}); + +std::shared_ptr make_convolution_backprop_data(const ov::Output& in, + const ov::Output& outputShape, + const ov::element::Type& type, + const std::vector& filterSize, + const std::vector& strides, + const std::vector& padsBegin, + const std::vector& padsEnd, + const std::vector& dilations, + const ov::op::PadType& autoPad, + size_t numOutChannels, + bool addBiases = false, + const std::vector& outputPadding = {}, + const std::vector& filterWeights = {}, + const std::vector& biasesWeights = {}); + +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/eltwise.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/eltwise.hpp new file mode 100644 index 00000000000..8b28f345b0d --- /dev/null +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/eltwise.hpp @@ -0,0 +1,16 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_test_utils/test_enums.hpp" +#include "openvino/core/node.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr makeEltwise(const ov::Output& in0, + const ov::Output& in1, + ov::test::utils::EltwiseTypes eltwise_type); +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_bag_offsets_sum.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_bag_offsets_sum.hpp new file mode 100644 index 00000000000..f05fba41f1b --- /dev/null +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_bag_offsets_sum.hpp @@ -0,0 +1,20 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/core/node.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr make_embedding_bag_offsets_sum(const element::Type& data_type, + const ov::element::Type& indices_type, + const ov::Output& emb_table_node, + const std::vector& indices, + const std::vector& offsets, + size_t default_index, + bool with_weights, + bool with_default_index); +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_bag_packed_sum.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_bag_packed_sum.hpp new file mode 100644 index 00000000000..735027efb68 --- /dev/null +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_bag_packed_sum.hpp @@ -0,0 +1,17 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/core/node.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr make_embedding_bag_packed_sum(const ov::element::Type& data_type, + const ov::element::Type& indices_type, + const ov::Output& emb_table_node, + const std::vector>& indices, + bool with_weights); +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_segments_sum.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_segments_sum.hpp new file mode 100644 index 00000000000..8c8aefd9dc7 --- /dev/null +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_segments_sum.hpp @@ -0,0 +1,21 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/core/node.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr make_embedding_segments_sum(const ov::element::Type& data_type, + const ov::element::Type& indices_type, + const ov::Output& emb_table_node, + const std::vector& indices, + const std::vector& segment_ids, + size_t num_segments, + size_t default_index, + bool with_weights, + bool with_default_index); +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/group_convolution.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/group_convolution.hpp new file mode 100644 index 00000000000..347025f2add --- /dev/null +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/group_convolution.hpp @@ -0,0 +1,36 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/core/node.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr make_group_convolution(const ov::Output& in, + const ov::element::Type& type, + const std::vector& filterSize, + const std::vector& strides, + const std::vector& padsBegin, + const std::vector& padsEnd, + const std::vector& dilations, + const ov::op::PadType& autoPad, + size_t numOutChannels, + size_t numGroups, + bool addBiases = false, + const std::vector& filterWeights = {}, + const std::vector& biasesWeights = {}); + +std::shared_ptr make_group_convolution(const ov::Output& in, + const ov::Output& weights, + const ov::element::Type& type, + const std::vector& strides, + const std::vector& padsBegin, + const std::vector& padsEnd, + const std::vector& dilations, + const ov::op::PadType& autoPad, + bool addBiases = false, + const std::vector& biasesWeights = {}); +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/group_convolution_backprop_data.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/group_convolution_backprop_data.hpp new file mode 100644 index 00000000000..14283a8a155 --- /dev/null +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/group_convolution_backprop_data.hpp @@ -0,0 +1,54 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/core/node.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr make_group_convolution_backprop_data(const ov::Output& in, + const ov::element::Type& type, + const std::vector& filterSize, + const std::vector& strides, + const std::vector& padsBegin, + const std::vector& padsEnd, + const std::vector& dilations, + const ov::op::PadType& autoPad, + size_t numOutChannels, + size_t numGroups, + bool addBiases = false, + const std::vector& outputPadding = {}, + const std::vector& filterWeights = {}, + const std::vector& biasesWeights = {}); + +std::shared_ptr make_group_convolution_backprop_data(const ov::Output& in, + const ov::Output& weights, + const ov::element::Type& type, + const std::vector& strides, + const std::vector& padsBegin, + const std::vector& padsEnd, + const std::vector& dilations, + const ov::op::PadType& autoPad, + bool addBiases = false, + const std::vector& outputPadding = {}, + const std::vector& biasesWeights = {}); + +std::shared_ptr make_group_convolution_backprop_data(const ov::Output& in, + const ov::Output& outputShape, + const ov::element::Type& type, + const std::vector& filterSize, + const std::vector& strides, + const std::vector& padsBegin, + const std::vector& padsEnd, + const std::vector& dilations, + const ov::op::PadType& autoPad, + size_t numOutChannels, + size_t numGroups, + bool addBiases = false, + const std::vector& outputPadding = {}, + const std::vector& filterWeights = {}, + const std::vector& biasesWeights = {}); +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/src/node_builders/activation.cpp b/src/tests/test_utils/common_test_utils/src/node_builders/activation.cpp new file mode 100644 index 00000000000..a24458e7fed --- /dev/null +++ b/src/tests/test_utils/common_test_utils/src/node_builders/activation.cpp @@ -0,0 +1,170 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_test_utils/node_builders/activation.hpp" + +#include "openvino/op/abs.hpp" +#include "openvino/op/acos.hpp" +#include "openvino/op/acosh.hpp" +#include "openvino/op/asin.hpp" +#include "openvino/op/asinh.hpp" +#include "openvino/op/atan.hpp" +#include "openvino/op/atanh.hpp" +#include "openvino/op/ceiling.hpp" +#include "openvino/op/clamp.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/cos.hpp" +#include "openvino/op/cosh.hpp" +#include "openvino/op/elu.hpp" +#include "openvino/op/erf.hpp" +#include "openvino/op/exp.hpp" +#include "openvino/op/floor.hpp" +#include "openvino/op/gelu.hpp" +#include "openvino/op/hard_sigmoid.hpp" +#include "openvino/op/hsigmoid.hpp" +#include "openvino/op/hswish.hpp" +#include "openvino/op/log.hpp" +#include "openvino/op/mish.hpp" +#include "openvino/op/negative.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/prelu.hpp" +#include "openvino/op/relu.hpp" +#include "openvino/op/round.hpp" +#include "openvino/op/selu.hpp" +#include "openvino/op/sigmoid.hpp" +#include "openvino/op/sign.hpp" +#include "openvino/op/sin.hpp" +#include "openvino/op/sinh.hpp" +#include "openvino/op/softplus.hpp" +#include "openvino/op/softsign.hpp" +#include "openvino/op/sqrt.hpp" +#include "openvino/op/swish.hpp" +#include "openvino/op/tan.hpp" +#include "openvino/op/tanh.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr make_activation(const ov::Output& in, + const element::Type& type, + ov::test::utils::ActivationTypes activation_type, + ov::Shape in_shape, + std::vector constants_value) { + switch (activation_type) { + case ov::test::utils::ActivationTypes::Sigmoid: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Tanh: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Relu: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::LeakyRelu: { + auto leaky_slope = std::make_shared(ov::element::f32, in_shape, constants_value); + return std::make_shared(in, leaky_slope); + } + case ov::test::utils::ActivationTypes::Exp: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Log: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Sign: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Abs: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Gelu: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Clamp: + return std::make_shared(in, constants_value[0], constants_value[1]); + case ov::test::utils::ActivationTypes::Negative: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Acos: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Acosh: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Asin: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Asinh: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Atan: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Atanh: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Cos: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Cosh: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Floor: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Sin: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Sinh: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Sqrt: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Tan: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Elu: + return std::make_shared(in, constants_value[0]); + case ov::test::utils::ActivationTypes::Erf: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::HardSigmoid: { + auto hard_sigmoid_alpha = std::make_shared(type, in_shape, constants_value[0]); + auto hard_sigmoid_beta = std::make_shared(type, in_shape, constants_value[1]); + return std::make_shared(in, hard_sigmoid_alpha, hard_sigmoid_beta); + } + case ov::test::utils::ActivationTypes::Selu: { + auto selu_alpha = std::make_shared(type, in_shape, constants_value[0]); + auto selu_lambda = std::make_shared(type, in_shape, constants_value[1]); + return std::make_shared(in, selu_alpha, selu_lambda); + } + case ov::test::utils::ActivationTypes::Ceiling: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::PReLu: { + auto negative_slope = std::make_shared(ov::element::f32, in_shape, constants_value); + return std::make_shared(in, negative_slope); + } + case ov::test::utils::ActivationTypes::Mish: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::HSwish: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::SoftPlus: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::Swish: { + auto beta = std::make_shared(type, in_shape, constants_value[0]); + return std::make_shared(in, beta); + } + case ov::test::utils::ActivationTypes::HSigmoid: + return std::make_shared(in); + case ov::test::utils::ActivationTypes::RoundHalfToEven: + return std::make_shared(in, ov::op::v5::Round::RoundMode::HALF_TO_EVEN); + case ov::test::utils::ActivationTypes::RoundHalfAwayFromZero: + return std::make_shared(in, ov::op::v5::Round::RoundMode::HALF_AWAY_FROM_ZERO); + case ov::test::utils::ActivationTypes::GeluErf: + return std::make_shared(in, ov::op::GeluApproximationMode::ERF); + case ov::test::utils::ActivationTypes::GeluTanh: + return std::make_shared(in, ov::op::GeluApproximationMode::TANH); + case ov::test::utils::ActivationTypes::SoftSign: + return std::make_shared(in); + default: + OPENVINO_THROW("Can't create layer for this activation type"); + } +} + +std::shared_ptr make_activation(const ov::ParameterVector& parameters, + const element::Type& type, + ov::test::utils::ActivationTypes activation_type) { + switch (activation_type) { + case ov::test::utils::ActivationTypes::LeakyRelu: + return std::make_shared(parameters[0], parameters[1]); + case ov::test::utils::ActivationTypes::HardSigmoid: + return std::make_shared(parameters[0], parameters[1], parameters[2]); + case ov::test::utils::ActivationTypes::Selu: + return std::make_shared(parameters[0], parameters[1], parameters[2]); + case ov::test::utils::ActivationTypes::PReLu: + return std::make_shared(parameters[0], parameters[1]); + default: + OPENVINO_THROW("It is impossible to create layer for this activation type with input as parameter"); + } +} +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/src/node_builders/binary_convolution.cpp b/src/tests/test_utils/common_test_utils/src/node_builders/binary_convolution.cpp new file mode 100644 index 00000000000..0f208e253d1 --- /dev/null +++ b/src/tests/test_utils/common_test_utils/src/node_builders/binary_convolution.cpp @@ -0,0 +1,55 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_test_utils/node_builders/binary_convolution.hpp" + +#include "common_test_utils/ov_tensor_utils.hpp" +#include "openvino/op/add.hpp" +#include "openvino/op/binary_convolution.hpp" +#include "openvino/op/constant.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr make_binary_convolution(const ov::Output& in, + const std::vector& filter_size, + const std::vector& strides, + const std::vector& pads_begin, + const std::vector& pads_end, + const std::vector& dilations, + const ov::op::PadType& auto_pad, + size_t num_out_channels, + float pad_value, + const std::vector& filter_weihgts) { + auto shape = in.get_shape(); + ov::Shape filter_weights_shape = {num_out_channels, shape[1]}; + filter_weights_shape.insert(filter_weights_shape.end(), filter_size.begin(), filter_size.end()); + + auto filter_weights_node = std::make_shared(element::u1, filter_weights_shape); + const size_t byteNum = (ov::shape_size(filter_weights_shape) + 7) / 8; + int8_t* buffer = const_cast(filter_weights_node->get_data_ptr()); + if (filter_weihgts.size() == 0) { + auto tensor = create_and_fill_tensor(ov::element::i8, filter_weights_shape); + auto weights = static_cast(tensor.data()); + for (size_t i = 0; i < byteNum; i++) + buffer[i] = weights[i]; + } else { + for (size_t i = 0; i < byteNum; i++) + buffer[i] = filter_weihgts[i]; + } + auto conv = std::make_shared( + in, + filter_weights_node, + strides, + pads_begin, + pads_end, + dilations, + ov::op::v1::BinaryConvolution::BinaryConvolutionMode::XNOR_POPCOUNT, + pad_value, + auto_pad); + return conv; +} +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/src/node_builders/convolution.cpp b/src/tests/test_utils/common_test_utils/src/node_builders/convolution.cpp new file mode 100644 index 00000000000..29592d1e053 --- /dev/null +++ b/src/tests/test_utils/common_test_utils/src/node_builders/convolution.cpp @@ -0,0 +1,101 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_test_utils/node_builders/convolution.hpp" + +#include "common_test_utils/ov_tensor_utils.hpp" +#include "openvino/op/add.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/convolution.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr make_convolution(const ov::Output& in, + const ov::element::Type& type, + const std::vector& filter_size, + const std::vector& strides, + const std::vector& pads_begin, + const std::vector& pads_end, + const std::vector& dilations, + const ov::op::PadType& auto_pad, + size_t num_out_channels, + bool add_biases, + const std::vector& filter_weights, + const std::vector& biases_weights) { + auto shape = in.get_partial_shape(); + ov::Shape filter_weights_shape = {num_out_channels, static_cast(shape[1].get_length())}; + filter_weights_shape.insert(filter_weights_shape.end(), filter_size.begin(), filter_size.end()); + + std::shared_ptr filter_weights_node; + if (!filter_weights.empty()) { + filter_weights_node = std::make_shared(type, filter_weights_shape, filter_weights); + } else { + auto tensor = create_and_fill_tensor(type, filter_weights_shape); + filter_weights_node = std::make_shared(tensor); + } + + auto conv = std::make_shared(in, + filter_weights_node, + strides, + pads_begin, + pads_end, + dilations, + auto_pad); + if (add_biases) { + std::shared_ptr biases_weights_node; + if (!biases_weights.empty()) { + biases_weights_node = + std::make_shared(type, ov::Shape{1, num_out_channels, 1, 1}, biases_weights); + } else { + auto tensor = create_and_fill_tensor(type, ov::Shape{1, num_out_channels, 1, 1}); + biases_weights_node = std::make_shared(tensor); + } + + auto add = std::make_shared(conv, biases_weights_node); + return add; + } else { + return conv; + } +} + +std::shared_ptr make_convolution(const ov::Output& in_data, + const ov::Output& in_weights, + const ov::element::Type& type, + const std::vector& filter_size, + const std::vector& strides, + const std::vector& pads_begin, + const std::vector& pads_end, + const std::vector& dilations, + const ov::op::PadType& auto_pad, + size_t num_out_channels, + bool add_biases, + const std::vector& biases_weights) { + auto shape = in_data.get_partial_shape(); + auto conv = std::make_shared(in_data, + in_weights, + strides, + pads_begin, + pads_end, + dilations, + auto_pad); + if (add_biases) { + std::shared_ptr biases_weights_node; + if (!biases_weights.empty()) { + biases_weights_node = + std::make_shared(type, ov::Shape{1, num_out_channels, 1, 1}, biases_weights); + } else { + auto tensor = create_and_fill_tensor(type, ov::Shape{1, num_out_channels, 1, 1}); + biases_weights_node = std::make_shared(tensor); + } + + auto add = std::make_shared(conv, biases_weights_node); + return add; + } else { + return conv; + } +} +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/src/node_builders/convolution_backprop_data.cpp b/src/tests/test_utils/common_test_utils/src/node_builders/convolution_backprop_data.cpp new file mode 100644 index 00000000000..75eba2d2292 --- /dev/null +++ b/src/tests/test_utils/common_test_utils/src/node_builders/convolution_backprop_data.cpp @@ -0,0 +1,163 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_test_utils/node_builders/convolution_backprop_data.hpp" + +#include "common_test_utils/ov_tensor_utils.hpp" +#include "openvino/op/add.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/convolution.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr make_convolution_backprop_data(const ov::Output& in, + const ov::element::Type& type, + const std::vector& filter_size, + const std::vector& strides, + const std::vector& pads_begin, + const std::vector& pads_end, + const std::vector& dilations, + const ov::op::PadType& auto_pad, + size_t num_out_channels, + bool add_biases, + const std::vector& output_padding, + const std::vector& filter_weights, + const std::vector& biases_weights) { + auto shape = in.get_partial_shape(); + ov::Shape filter_weights_shape = {static_cast(shape[1].get_length()), num_out_channels}; + filter_weights_shape.insert(filter_weights_shape.end(), filter_size.begin(), filter_size.end()); + + std::shared_ptr filter_weights_node; + if (!filter_weights.empty()) { + filter_weights_node = std::make_shared(type, filter_weights_shape, filter_weights); + } else { + auto tensor = create_and_fill_tensor(type, filter_weights_shape); + filter_weights_node = std::make_shared(tensor); + } + + return make_convolution_backprop_data(in, + filter_weights_node, + type, + strides, + pads_begin, + pads_end, + dilations, + auto_pad, + add_biases, + output_padding, + biases_weights); +} + +std::shared_ptr make_convolution_backprop_data(const ov::Output& in, + const ov::Output& weights, + const ov::element::Type& type, + const std::vector& strides, + const std::vector& pads_begin, + const std::vector& pads_end, + const std::vector& dilations, + const ov::op::PadType& auto_pad, + bool add_biases, + const std::vector& output_padding, + const std::vector& biases_weights) { + auto deconv = std::make_shared(in, + weights, + strides, + pads_begin, + pads_end, + dilations, + auto_pad); + + if (!output_padding.empty()) { + deconv = std::make_shared(in, + weights, + strides, + pads_begin, + pads_end, + dilations, + auto_pad, + output_padding); + } + + if (add_biases) { + std::shared_ptr biases_weights_node; + if (!biases_weights.empty()) { + biases_weights_node = std::make_shared(type, ov::Shape{}, biases_weights); + } else { + auto tensor = create_and_fill_tensor(type, ov::Shape{}); + biases_weights_node = std::make_shared(tensor); + } + + auto add = std::make_shared(deconv, biases_weights_node); + return add; + } else { + return deconv; + } +} + +std::shared_ptr make_convolution_backprop_data(const ov::Output& in, + const ov::Output& outputShape, + const ov::element::Type& type, + const std::vector& filter_size, + const std::vector& strides, + const std::vector& pads_begin, + const std::vector& pads_end, + const std::vector& dilations, + const ov::op::PadType& auto_pad, + size_t num_out_channels, + bool add_biases, + const std::vector& output_padding, + const std::vector& filter_weights, + const std::vector& biases_weights) { + auto shape = in.get_partial_shape(); + ov::Shape filter_weights_shape = {static_cast(shape[1].get_length()), num_out_channels}; + filter_weights_shape.insert(filter_weights_shape.end(), filter_size.begin(), filter_size.end()); + + std::shared_ptr filter_weights_node; + if (!filter_weights.empty()) { + filter_weights_node = std::make_shared(type, filter_weights_shape, filter_weights); + } else { + auto tensor = create_and_fill_tensor(type, filter_weights_shape); + filter_weights_node = std::make_shared(tensor); + } + + auto deconv = std::make_shared(in, + filter_weights_node, + outputShape, + strides, + pads_begin, + pads_end, + dilations, + auto_pad); + + if (!output_padding.empty()) { + deconv = std::make_shared(in, + filter_weights_node, + outputShape, + strides, + pads_begin, + pads_end, + dilations, + auto_pad, + output_padding); + } + + if (add_biases) { + std::shared_ptr biases_weights_node; + if (!biases_weights.empty()) { + biases_weights_node = std::make_shared(type, ov::Shape{}, biases_weights); + } else { + auto tensor = create_and_fill_tensor(type, ov::Shape{}); + biases_weights_node = std::make_shared(tensor); + } + + auto add = std::make_shared(deconv, biases_weights_node); + return add; + } else { + return deconv; + } +} +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/src/node_builders/eltwise.cpp b/src/tests/test_utils/common_test_utils/src/node_builders/eltwise.cpp new file mode 100644 index 00000000000..e1aa89b1543 --- /dev/null +++ b/src/tests/test_utils/common_test_utils/src/node_builders/eltwise.cpp @@ -0,0 +1,61 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_test_utils/node_builders/eltwise.hpp" + +#include "openvino/op/add.hpp" +#include "openvino/op/bitwise_and.hpp" +#include "openvino/op/bitwise_not.hpp" +#include "openvino/op/bitwise_or.hpp" +#include "openvino/op/bitwise_xor.hpp" +#include "openvino/op/divide.hpp" +#include "openvino/op/erf.hpp" +#include "openvino/op/floor_mod.hpp" +#include "openvino/op/mod.hpp" +#include "openvino/op/multiply.hpp" +#include "openvino/op/power.hpp" +#include "openvino/op/squared_difference.hpp" +#include "openvino/op/subtract.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr makeEltwise(const ov::Output& in0, + const ov::Output& in1, + ov::test::utils::EltwiseTypes eltwiseType) { + switch (eltwiseType) { + case ov::test::utils::EltwiseTypes::ADD: + return std::make_shared(in0, in1); + case ov::test::utils::EltwiseTypes::SUBTRACT: + return std::make_shared(in0, in1); + case ov::test::utils::EltwiseTypes::MULTIPLY: + return std::make_shared(in0, in1); + case ov::test::utils::EltwiseTypes::DIVIDE: + return std::make_shared(in0, in1); + case ov::test::utils::EltwiseTypes::SQUARED_DIFF: + return std::make_shared(in0, in1); + case ov::test::utils::EltwiseTypes::POWER: + return std::make_shared(in0, in1); + case ov::test::utils::EltwiseTypes::FLOOR_MOD: + return std::make_shared(in0, in1); + case ov::test::utils::EltwiseTypes::MOD: + return std::make_shared(in0, in1); + case ov::test::utils::EltwiseTypes::ERF: + return std::make_shared(in0); + case ov::test::utils::EltwiseTypes::BITWISE_AND: + return std::make_shared(in0, in1); + case ov::test::utils::EltwiseTypes::BITWISE_NOT: + return std::make_shared(in0); + case ov::test::utils::EltwiseTypes::BITWISE_OR: + return std::make_shared(in0, in1); + case ov::test::utils::EltwiseTypes::BITWISE_XOR: + return std::make_shared(in0, in1); + default: { + OPENVINO_THROW("Incorrect type of Eltwise operation"); + } + } +} +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/src/node_builders/embedding_bag_offsets_sum.cpp b/src/tests/test_utils/common_test_utils/src/node_builders/embedding_bag_offsets_sum.cpp new file mode 100644 index 00000000000..7d2d9fa0ba3 --- /dev/null +++ b/src/tests/test_utils/common_test_utils/src/node_builders/embedding_bag_offsets_sum.cpp @@ -0,0 +1,52 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_test_utils/node_builders/embedding_bag_offsets_sum.hpp" + +#include "common_test_utils/ov_tensor_utils.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/embeddingbag_offsets_sum.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr make_embedding_bag_offsets_sum(const element::Type& data_type, + const ov::element::Type& indices_type, + const ov::Output& emb_table_node, + const std::vector& indices, + const std::vector& offsets, + size_t default_index, + bool with_weights, + bool with_default_index) { + ov::Shape i_shape = {indices.size()}; + auto indices_node = std::make_shared(indices_type, i_shape, indices); + ov::Shape o_shape = {offsets.size()}; + auto offsetsNode = std::make_shared(indices_type, o_shape, offsets); + + std::shared_ptr embBag; + if (with_default_index) { + auto defIdxNode = std::make_shared(indices_type, ov::Shape{}, default_index); + if (with_weights) { + auto tensor = create_and_fill_tensor(data_type, ov::Shape{indices.size()}); + auto weights_node = std::make_shared(tensor); + + embBag = std::make_shared(emb_table_node, + indices_node, + offsetsNode, + defIdxNode, + weights_node); + } else { + embBag = std::make_shared(emb_table_node, + indices_node, + offsetsNode, + defIdxNode); + } + } else { + embBag = std::make_shared(emb_table_node, indices_node, offsetsNode); + } + return embBag; +} +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/src/node_builders/embedding_bag_packed_sum.cpp b/src/tests/test_utils/common_test_utils/src/node_builders/embedding_bag_packed_sum.cpp new file mode 100644 index 00000000000..7cd5d575687 --- /dev/null +++ b/src/tests/test_utils/common_test_utils/src/node_builders/embedding_bag_packed_sum.cpp @@ -0,0 +1,39 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_test_utils/node_builders/embedding_bag_packed_sum.hpp" + +#include "common_test_utils/ov_tensor_utils.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/embeddingbag_packedsum.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr make_embedding_bag_packed_sum(const ov::element::Type& data_type, + const ov::element::Type& indices_type, + const ov::Output& emb_table_node, + const std::vector>& indices, + bool with_weights) { + ov::Shape i_shape({indices.size(), indices[0].size()}); + size_t i_size = ov::shape_size(i_shape); + std::vector i_values(i_size); + for (int i = 0; i < indices.size(); i++) + memcpy(i_values.data() + indices[0].size() * i, indices[i].data(), indices[0].size() * sizeof(size_t)); + auto indicesNode = std::make_shared(indices_type, i_shape, i_values); + + std::shared_ptr embBag; + if (with_weights) { + auto tensor = create_and_fill_tensor(data_type, i_shape); + auto weights_node = std::make_shared(tensor); + + embBag = std::make_shared(emb_table_node, indicesNode, weights_node); + } else { + embBag = std::make_shared(emb_table_node, indicesNode); + } + return embBag; +} +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/src/node_builders/embedding_segments_sum.cpp b/src/tests/test_utils/common_test_utils/src/node_builders/embedding_segments_sum.cpp new file mode 100644 index 00000000000..0958d5b0bb0 --- /dev/null +++ b/src/tests/test_utils/common_test_utils/src/node_builders/embedding_segments_sum.cpp @@ -0,0 +1,60 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_test_utils/node_builders/embedding_segments_sum.hpp" + +#include "common_test_utils/ov_tensor_utils.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/embedding_segments_sum.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr make_embedding_segments_sum(const ov::element::Type& data_type, + const ov::element::Type& indices_type, + const ov::Output& emb_table_node, + const std::vector& indices, + const std::vector& segment_ids, + size_t num_segments, + size_t default_index, + bool with_weights, + bool with_default_index) { + ov::Shape i_shape = {indices.size()}; + auto indicesNode = std::make_shared(indices_type, i_shape, indices); + ov::Shape o_shape = {segment_ids.size()}; + auto segmentIdNode = std::make_shared(indices_type, o_shape, segment_ids); + ov::Shape shape_0 = {}; + auto segmentNumNode = std::make_shared(indices_type, shape_0, num_segments); + + std::shared_ptr embBag; + if (with_default_index) { + auto defIdxNode = std::make_shared(indices_type, shape_0, default_index); + if (with_weights) { + auto tensor = create_and_fill_tensor(data_type, ov::Shape{indices.size()}); + auto weights_node = std::make_shared(tensor); + + embBag = std::make_shared(emb_table_node, + indicesNode, + segmentIdNode, + segmentNumNode, + defIdxNode, + weights_node); + } else { + embBag = std::make_shared(emb_table_node, + indicesNode, + segmentIdNode, + segmentNumNode, + defIdxNode); + } + } else { + embBag = std::make_shared(emb_table_node, + indicesNode, + segmentIdNode, + segmentNumNode); + } + return embBag; +} +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/src/node_builders/group_convolution.cpp b/src/tests/test_utils/common_test_utils/src/node_builders/group_convolution.cpp new file mode 100644 index 00000000000..66b7717f589 --- /dev/null +++ b/src/tests/test_utils/common_test_utils/src/node_builders/group_convolution.cpp @@ -0,0 +1,86 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_test_utils/node_builders/group_convolution.hpp" + +#include "common_test_utils/ov_tensor_utils.hpp" +#include "openvino/op/add.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/group_conv.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr make_group_convolution(const ov::Output& in, + const ov::element::Type& type, + const std::vector& filter_size, + const std::vector& strides, + const std::vector& pads_begin, + const std::vector& pads_end, + const std::vector& dilations, + const ov::op::PadType& auto_pad, + size_t num_out_channels, + size_t num_groups, + bool add_biases, + const std::vector& filter_weights, + const std::vector& biases_weights) { + auto shape = in.get_partial_shape(); + ov::Shape filter_weights_shape = {num_out_channels, static_cast(shape[1].get_length())}; + OPENVINO_ASSERT(!(filter_weights_shape[0] % num_groups || filter_weights_shape[1] % num_groups), + "incorrected shape for GroupConvolution"); + filter_weights_shape[0] /= num_groups; + filter_weights_shape[1] /= num_groups; + filter_weights_shape.insert(filter_weights_shape.begin(), num_groups); + filter_weights_shape.insert(filter_weights_shape.end(), filter_size.begin(), filter_size.end()); + + std::shared_ptr filter_weights_node; + if (!filter_weights.empty()) { + filter_weights_node = std::make_shared(type, filter_weights_shape, filter_weights); + } else { + auto tensor = create_and_fill_tensor(type, filter_weights_shape); + filter_weights_node = std::make_shared(tensor); + } + + return make_group_convolution(in, + filter_weights_node, + type, + strides, + pads_begin, + pads_end, + dilations, + auto_pad, + add_biases, + biases_weights); +} + +std::shared_ptr make_group_convolution(const ov::Output& in, + const ov::Output& weights, + const ov::element::Type& type, + const std::vector& strides, + const std::vector& pads_begin, + const std::vector& pads_end, + const std::vector& dilations, + const ov::op::PadType& auto_pad, + bool add_biases, + const std::vector& biases_weights) { + auto conv = + std::make_shared(in, weights, strides, pads_begin, pads_end, dilations, auto_pad); + if (add_biases) { + std::shared_ptr biases_weights_node; + if (!biases_weights.empty()) { + biases_weights_node = std::make_shared(type, ov::Shape{}, biases_weights); + } else { + auto tensor = create_and_fill_tensor(type, ov::Shape{}); + biases_weights_node = std::make_shared(tensor); + } + + auto add = std::make_shared(conv, biases_weights_node); + return add; + } else { + return conv; + } +} +} // namespace utils +} // namespace test +} // namespace ov diff --git a/src/tests/test_utils/common_test_utils/src/node_builders/group_convolution_backprop_data.cpp b/src/tests/test_utils/common_test_utils/src/node_builders/group_convolution_backprop_data.cpp new file mode 100644 index 00000000000..2588aa8a40c --- /dev/null +++ b/src/tests/test_utils/common_test_utils/src/node_builders/group_convolution_backprop_data.cpp @@ -0,0 +1,174 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_test_utils/node_builders/group_convolution_backprop_data.hpp" + +#include "common_test_utils/ov_tensor_utils.hpp" +#include "openvino/op/add.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/group_conv.hpp" + +namespace ov { +namespace test { +namespace utils { +std::shared_ptr make_group_convolution_backprop_data(const ov::Output& in, + const ov::element::Type& type, + const std::vector& filter_size, + const std::vector& strides, + const std::vector& pads_begin, + const std::vector& pads_end, + const std::vector& dilations, + const ov::op::PadType& auto_pad, + size_t num_out_channels, + size_t num_groups, + bool add_biases, + const std::vector& output_padding, + const std::vector& filter_weights, + const std::vector& biases_weights) { + auto shape = in.get_partial_shape(); + ov::Shape filter_weights_shape = {static_cast(shape[1].get_length()), num_out_channels}; + OPENVINO_ASSERT(!(filter_weights_shape[0] % num_groups || filter_weights_shape[1] % num_groups), + "incorrected shape for GroupConvolution"); + filter_weights_shape[0] /= num_groups; + filter_weights_shape[1] /= num_groups; + filter_weights_shape.insert(filter_weights_shape.begin(), num_groups); + filter_weights_shape.insert(filter_weights_shape.end(), filter_size.begin(), filter_size.end()); + + std::shared_ptr filter_weights_node; + if (!filter_weights.empty()) { + filter_weights_node = std::make_shared(type, filter_weights_shape, filter_weights); + } else { + auto tensor = create_and_fill_tensor(type, filter_weights_shape); + filter_weights_node = std::make_shared(tensor); + } + + return make_group_convolution_backprop_data(in, + filter_weights_node, + type, + strides, + pads_begin, + pads_end, + dilations, + auto_pad, + add_biases, + output_padding, + biases_weights); +} + +std::shared_ptr make_group_convolution_backprop_data(const ov::Output& in, + const ov::Output& weights, + const ov::element::Type& type, + const std::vector& strides, + const std::vector& pads_begin, + const std::vector& pads_end, + const std::vector& dilations, + const ov::op::PadType& auto_pad, + bool add_biases, + const std::vector& output_padding, + const std::vector& biases_weights) { + auto deconv = std::make_shared(in, + weights, + strides, + pads_begin, + pads_end, + dilations, + auto_pad); + + if (!output_padding.empty()) { + deconv = std::make_shared(in, + weights, + strides, + pads_begin, + pads_end, + dilations, + auto_pad, + output_padding); + } + if (add_biases) { + std::shared_ptr biases_weights_node; + if (!biases_weights.empty()) { + biases_weights_node = std::make_shared(type, ov::Shape{}, biases_weights); + } else { + auto tensor = create_and_fill_tensor(type, ov::Shape{}); + biases_weights_node = std::make_shared(tensor); + } + + auto add = std::make_shared(deconv, biases_weights_node); + return add; + } else { + return deconv; + } +} + +std::shared_ptr make_group_convolution_backprop_data(const ov::Output& in, + const ov::Output& outputShape, + const ov::element::Type& type, + const std::vector& filter_size, + const std::vector& strides, + const std::vector& pads_begin, + const std::vector& pads_end, + const std::vector& dilations, + const ov::op::PadType& auto_pad, + size_t num_out_channels, + size_t num_groups, + bool add_biases, + const std::vector& output_padding, + const std::vector& filter_weights, + const std::vector& biases_weights) { + auto shape = in.get_partial_shape(); + ov::Shape filter_weights_shape = {static_cast(shape[1].get_length()), num_out_channels}; + if (filter_weights_shape[0] % num_groups || filter_weights_shape[1] % num_groups) + throw std::runtime_error("incorrect shape for GroupConvolutionBackpropData"); + filter_weights_shape[0] /= num_groups; + filter_weights_shape[1] /= num_groups; + filter_weights_shape.insert(filter_weights_shape.begin(), num_groups); + filter_weights_shape.insert(filter_weights_shape.end(), filter_size.begin(), filter_size.end()); + + std::shared_ptr filter_weights_node; + if (!filter_weights.empty()) { + filter_weights_node = std::make_shared(type, filter_weights_shape, filter_weights); + } else { + auto tensor = create_and_fill_tensor(type, filter_weights_shape); + filter_weights_node = std::make_shared(tensor); + } + + auto deconv = std::make_shared(in, + filter_weights_node, + outputShape, + strides, + pads_begin, + pads_end, + dilations, + auto_pad); + + if (!output_padding.empty()) { + deconv = std::make_shared(in, + filter_weights_node, + outputShape, + strides, + pads_begin, + pads_end, + dilations, + auto_pad, + output_padding); + } + + if (add_biases) { + std::shared_ptr biases_weights_node; + if (!biases_weights.empty()) { + biases_weights_node = std::make_shared(type, ov::Shape{}, biases_weights); + } else { + auto tensor = create_and_fill_tensor(type, ov::Shape{}); + biases_weights_node = std::make_shared(tensor); + } + + auto add = std::make_shared(deconv, biases_weights_node); + return add; + } else { + return deconv; + } +} +} // namespace utils +} // namespace test +} // namespace ov