From 1fa0d525d981358155719def70db8589b7cb6a51 Mon Sep 17 00:00:00 2001 From: Anastasiia Urlapova Date: Wed, 27 Oct 2021 19:08:26 +0300 Subject: [PATCH 01/12] [XXX-67099] Remove legacy from primitives priotity (#8005) --- .../primitives_priority_test.cpp | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/inference-engine/tests/functional/inference_engine/transformations/primitives_priority_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/primitives_priority_test.cpp index 070a7ef0127..9df0ba186fc 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/primitives_priority_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/primitives_priority_test.cpp @@ -17,12 +17,13 @@ #include #include #include -#include // deprecated API -#include // deprecated API - +#include +#include "transformations/rt_info/primitives_priority_attribute.hpp" #include "common_test_utils/ngraph_test_utils.hpp" using namespace testing; +using namespace InferenceEngine; +using namespace InferenceEngine::details; TEST(TransformationTests, ConvBiasFusion) { std::shared_ptr f(nullptr); @@ -39,6 +40,7 @@ TEST(TransformationTests, ConvBiasFusion) { f = std::make_shared(ngraph::NodeVector{add}, ngraph::ParameterVector{input1}); } + std::unordered_map pp; InferenceEngine::CNNNetwork network(f); @@ -48,16 +50,18 @@ TEST(TransformationTests, ConvBiasFusion) { for (auto & op : nGraph->get_ops()) { if (auto conv = std::dynamic_pointer_cast(op)) { auto & rtInfo = conv->get_rt_info(); - rtInfo["PrimitivesPriority"] = std::make_shared > ("test"); + rtInfo["PrimitivesPriority"] = std::make_shared>("test"); + pp[op->get_friendly_name()] = "test"; } } - auto clonedNetwork = std::make_shared(network); + auto clonedNetwork = InferenceEngine::details::cloneNetwork(network); + auto funcs = clonedNetwork.getFunction(); - IE_SUPPRESS_DEPRECATED_START - InferenceEngine::CNNLayerPtr conv; - clonedNetwork->getLayerByName("add", conv, nullptr); - ASSERT_TRUE(conv->params.count("PrimitivesPriority")); - ASSERT_EQ(conv->params.at("PrimitivesPriority"), "test"); - IE_SUPPRESS_DEPRECATED_END + for (auto & op : funcs->get_ops()) { + if (auto conv = std::dynamic_pointer_cast(op)) { + ASSERT_TRUE(pp.find(op->get_friendly_name()) != pp.end()); + ASSERT_EQ(pp[op->get_friendly_name()], "test"); + } + } } From f34e1e332fb9fbf9ebe41a92082a018316e2ee04 Mon Sep 17 00:00:00 2001 From: Ilya Znamenskiy Date: Wed, 27 Oct 2021 19:32:04 +0300 Subject: [PATCH 02/12] [GPU] Added mish, hardswish, exp onednn activations (#8160) Merged by agreement with Pavel --- .../clDNN/src/impls/onednn/utils.cpp | 12 ++- .../tests/test_cases/fusings_gpu_test.cpp | 98 ++++++++++++++++++- 2 files changed, 102 insertions(+), 8 deletions(-) diff --git a/inference-engine/thirdparty/clDNN/src/impls/onednn/utils.cpp b/inference-engine/thirdparty/clDNN/src/impls/onednn/utils.cpp index 8cef96e5935..f16909bd03f 100644 --- a/inference-engine/thirdparty/clDNN/src/impls/onednn/utils.cpp +++ b/inference-engine/thirdparty/clDNN/src/impls/onednn/utils.cpp @@ -210,15 +210,17 @@ dnnl::memory::format_tag get_format_by_desc(dnnl::memory::desc desc) { dnnl::algorithm convert_activation_func(cldnn::activation_func func) { switch (func) { case cldnn::activation_func::relu: return dnnl::algorithm::eltwise_relu; + case cldnn::activation_func::relu_negative_slope: return dnnl::algorithm::eltwise_relu; + case cldnn::activation_func::gelu: return dnnl::algorithm::eltwise_gelu; case cldnn::activation_func::elu: return dnnl::algorithm::eltwise_elu; + case cldnn::activation_func::mish: return dnnl::algorithm::eltwise_mish; + case cldnn::activation_func::swish: return dnnl::algorithm::eltwise_swish; + case cldnn::activation_func::hswish: return dnnl::algorithm::eltwise_hardswish; + case cldnn::activation_func::abs: return dnnl::algorithm::eltwise_abs; + case cldnn::activation_func::exp: return dnnl::algorithm::eltwise_exp; case cldnn::activation_func::logistic: return dnnl::algorithm::eltwise_logistic; case cldnn::activation_func::clamp: return dnnl::algorithm::eltwise_clip; - case cldnn::activation_func::relu_negative_slope: return dnnl::algorithm::eltwise_relu; case cldnn::activation_func::hyperbolic_tan: return dnnl::algorithm::eltwise_tanh; - case cldnn::activation_func::swish: return dnnl::algorithm::eltwise_swish; - case cldnn::activation_func::abs: return dnnl::algorithm::eltwise_abs; - case cldnn::activation_func::gelu: return dnnl::algorithm::eltwise_gelu; - case cldnn::activation_func::hswish: return dnnl::algorithm::eltwise_hardswish; default: throw std::runtime_error("Unsupported activation func for onednn primitive " + std::to_string(static_cast(func))); } } diff --git a/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp b/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp index 6b9f20fefef..0089df16947 100644 --- a/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp +++ b/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp @@ -9181,8 +9181,8 @@ INSTANTIATE_TEST_SUITE_P(fusings_gpu, conv_int8_eltwise_onednn, bc_test_params{CASE_CONV3D_S8S8_5, 3, 4}, })); -class conv_fp32_activation_onednn : public ConvFusingTestOneDNN {}; -TEST_P(conv_fp32_activation_onednn, basic) { +class conv_fp32_activation_abs_onednn : public ConvFusingTestOneDNN {}; +TEST_P(conv_fp32_activation_abs_onednn, basic) { auto p = GetParam(); create_topologies(input_layout("input", get_input_layout(p)), data("weights", get_mem(get_weights_layout(p))), @@ -9196,7 +9196,99 @@ TEST_P(conv_fp32_activation_onednn, basic) { execute(p); } -INSTANTIATE_TEST_SUITE_P(fusings_gpu, conv_fp32_activation_onednn, +INSTANTIATE_TEST_SUITE_P(fusings_gpu, conv_fp32_activation_abs_onednn, + ::testing::ValuesIn(std::vector{ + bc_test_params{CASE_CONV_FP16_1, 2, 3}, + bc_test_params{CASE_CONV_FP16_2, 2, 3}, + bc_test_params{CASE_CONV_FP16_3, 2, 3}, + bc_test_params{CASE_CONV_FP16_4, 2, 3}, + })); + +class conv_fp32_activation_mish_onednn : public ConvFusingTestOneDNN {}; +TEST_P(conv_fp32_activation_mish_onednn, basic) { + auto p = GetParam(); + create_topologies(input_layout("input", get_input_layout(p)), + data("weights", get_mem(get_weights_layout(p))), + data("bias", get_mem(get_bias_layout(p))), + convolution("conv_prim", "input", {"weights"}, {"bias"}, p.groups, p.stride, p.pad, p.dilation), + activation("activation", "conv_prim", activation_func::mish), + reorder("reorder_bfyx", "activation", p.default_format, data_types::f32) + ); + + tolerance = 1e-2f; + execute(p); +} + +INSTANTIATE_TEST_SUITE_P(fusings_gpu, conv_fp32_activation_mish_onednn, + ::testing::ValuesIn(std::vector{ + bc_test_params{CASE_CONV_FP16_1, 2, 3}, + bc_test_params{CASE_CONV_FP16_2, 2, 3}, + bc_test_params{CASE_CONV_FP16_3, 2, 3}, + bc_test_params{CASE_CONV_FP16_4, 2, 3}, + })); + +class conv_fp32_activation_swish_onednn : public ConvFusingTestOneDNN {}; +TEST_P(conv_fp32_activation_swish_onednn, basic) { + auto p = GetParam(); + create_topologies(input_layout("input", get_input_layout(p)), + data("weights", get_mem(get_weights_layout(p))), + data("bias", get_mem(get_bias_layout(p))), + convolution("conv_prim", "input", {"weights"}, {"bias"}, p.groups, p.stride, p.pad, p.dilation), + activation("activation", "conv_prim", activation_func::swish), + reorder("reorder_bfyx", "activation", p.default_format, data_types::f32) + ); + + tolerance = 1e-2f; + execute(p); +} + +INSTANTIATE_TEST_SUITE_P(fusings_gpu, conv_fp32_activation_swish_onednn, + ::testing::ValuesIn(std::vector{ + bc_test_params{CASE_CONV_FP16_1, 2, 3}, + bc_test_params{CASE_CONV_FP16_2, 2, 3}, + bc_test_params{CASE_CONV_FP16_3, 2, 3}, + bc_test_params{CASE_CONV_FP16_4, 2, 3}, + })); + +class conv_fp32_activation_hswish_onednn : public ConvFusingTestOneDNN {}; +TEST_P(conv_fp32_activation_hswish_onednn, basic) { + auto p = GetParam(); + create_topologies(input_layout("input", get_input_layout(p)), + data("weights", get_mem(get_weights_layout(p))), + data("bias", get_mem(get_bias_layout(p))), + convolution("conv_prim", "input", {"weights"}, {"bias"}, p.groups, p.stride, p.pad, p.dilation), + activation("activation", "conv_prim", activation_func::hswish), + reorder("reorder_bfyx", "activation", p.default_format, data_types::f32) + ); + + tolerance = 1e-2f; + execute(p); +} + +INSTANTIATE_TEST_SUITE_P(fusings_gpu, conv_fp32_activation_hswish_onednn, + ::testing::ValuesIn(std::vector{ + bc_test_params{CASE_CONV_FP16_1, 2, 3}, + bc_test_params{CASE_CONV_FP16_2, 2, 3}, + bc_test_params{CASE_CONV_FP16_3, 2, 3}, + bc_test_params{CASE_CONV_FP16_4, 2, 3}, + })); + +class conv_fp32_activation_exp_onednn : public ConvFusingTestOneDNN {}; +TEST_P(conv_fp32_activation_exp_onednn, basic) { + auto p = GetParam(); + create_topologies(input_layout("input", get_input_layout(p)), + data("weights", get_mem(get_weights_layout(p))), + data("bias", get_mem(get_bias_layout(p))), + convolution("conv_prim", "input", {"weights"}, {"bias"}, p.groups, p.stride, p.pad, p.dilation), + activation("activation", "conv_prim", activation_func::exp), + reorder("reorder_bfyx", "activation", p.default_format, data_types::f32) + ); + + tolerance = 1e-2f; + execute(p); +} + +INSTANTIATE_TEST_SUITE_P(fusings_gpu, conv_fp32_activation_exp_onednn, ::testing::ValuesIn(std::vector{ bc_test_params{CASE_CONV_FP16_1, 2, 3}, bc_test_params{CASE_CONV_FP16_2, 2, 3}, From a2a8969201d597ba17be06301148df9756e6c041 Mon Sep 17 00:00:00 2001 From: Mikhail Nosov Date: Wed, 27 Oct 2021 20:56:43 +0300 Subject: [PATCH 03/12] [OV20] Enable OpenCV tests and support 'u8' type for Interpolate op (#8182) * Interpolate reference implementation: - Support u8 and other numeric types - For integral types - round result to nearest integer (don't cast) Preprocessing: enable OpenCV tests and add resize conformance tests with OpenCV * Revert changes in interpolate.cpp, making them minimal needed (added u8 resize) --- .../tests/functional/CMakeLists.txt | 16 +- .../subgraph_reference/preprocess_opencv.cpp | 148 +++++++++++++++++- .../ngraph/runtime/reference/interpolate.hpp | 7 +- ngraph/core/src/op/interpolate.cpp | 17 +- 4 files changed, 168 insertions(+), 20 deletions(-) diff --git a/docs/template_plugin/tests/functional/CMakeLists.txt b/docs/template_plugin/tests/functional/CMakeLists.txt index 8267591b98f..85f40435461 100644 --- a/docs/template_plugin/tests/functional/CMakeLists.txt +++ b/docs/template_plugin/tests/functional/CMakeLists.txt @@ -21,16 +21,14 @@ addIeTargetTest( TEMPLATE ) -if(ENABLE_TEMPLATE_OPENCV_TESTS) - find_package(OpenCV QUIET COMPONENTS core imgproc) +find_package(OpenCV QUIET COMPONENTS core imgproc) - if(OpenCV_FOUND) - message("-- Reference preprocessing: OpenCV tests are enabled") - target_compile_definitions(${TARGET_NAME} PRIVATE OPENCV_TEMPLATE_TESTS) - target_link_libraries(${TARGET_NAME} PRIVATE opencv_imgproc opencv_core) - else() - message("-- Reference preprocessing: OpenCV tests are disabled") - endif() +if(OpenCV_FOUND) + message("-- Reference preprocessing: OpenCV tests are enabled") + target_compile_definitions(${TARGET_NAME} PRIVATE OPENCV_TEMPLATE_TESTS) + target_link_libraries(${TARGET_NAME} PRIVATE opencv_imgproc opencv_core) +else() + message("-- Reference preprocessing: OpenCV tests are disabled") endif() # [cmake:functional_tests] diff --git a/docs/template_plugin/tests/functional/subgraph_reference/preprocess_opencv.cpp b/docs/template_plugin/tests/functional/subgraph_reference/preprocess_opencv.cpp index 75c3a006654..cf9abb1adae 100644 --- a/docs/template_plugin/tests/functional/subgraph_reference/preprocess_opencv.cpp +++ b/docs/template_plugin/tests/functional/subgraph_reference/preprocess_opencv.cpp @@ -26,6 +26,10 @@ public: void SetUp() override { SKIP_IF_CURRENT_TEST_IS_DISABLED() } +}; + +class PreprocessOpenCVReferenceTest_NV12 : public PreprocessOpenCVReferenceTest { +public: void Validate() override { threshold = 1.f; abs_threshold = 1.f; @@ -40,7 +44,7 @@ public: } // namespace -static std::shared_ptr create_simple_function_nv12(element::Type type, const PartialShape& shape) { +static std::shared_ptr create_simple_function(element::Type type, const PartialShape& shape) { auto data1 = std::make_shared(type, shape); data1->set_friendly_name("input1"); data1->get_output_tensor(0).set_names({"tensor_input1", "input1"}); @@ -49,11 +53,11 @@ static std::shared_ptr create_simple_function_nv12(element::Type type, op->set_friendly_name("Add0"); auto res = std::make_shared(op); res->set_friendly_name("Result1"); - res->get_output_tensor(0).set_names({"tensor_output1", "Result1", "Convert1"}); + res->get_output_tensor(0).set_names({"tensor_output1", "Result1"}); return std::make_shared(ResultVector{res}, ParameterVector{data1}); } -TEST_F(PreprocessOpenCVReferenceTest, convert_nv12_full_color_range) { +TEST_F(PreprocessOpenCVReferenceTest_NV12, convert_nv12_full_color_range) { size_t height = 64; // 64/2 = 32 values for R size_t width = 64; // 64/2 = 32 values for G int b_step = 5; @@ -64,7 +68,7 @@ TEST_F(PreprocessOpenCVReferenceTest, convert_nv12_full_color_range) { auto full_height = height * b_dim; auto func_shape = Shape{1, full_height, width, 3}; - function = create_simple_function_nv12(element::u8, func_shape); + function = create_simple_function(element::u8, func_shape); inputData.clear(); @@ -90,10 +94,10 @@ TEST_F(PreprocessOpenCVReferenceTest, convert_nv12_full_color_range) { Exec(); } -TEST_F(PreprocessOpenCVReferenceTest, convert_nv12_colored) { +TEST_F(PreprocessOpenCVReferenceTest_NV12, convert_nv12_colored) { auto input_yuv = std::vector {235, 81, 235, 81, 109, 184}; auto func_shape = Shape{1, 2, 2, 3}; - function = create_simple_function_nv12(element::u8, func_shape); + function = create_simple_function(element::u8, func_shape); inputData.clear(); @@ -116,4 +120,136 @@ TEST_F(PreprocessOpenCVReferenceTest, convert_nv12_colored) { Exec(); } +TEST_F(PreprocessOpenCVReferenceTest, resize_u8_simple_linear) { + auto input_shape = Shape{1, 1, 2, 2}; + auto func_shape = Shape{1, 1, 1, 1}; + auto input_img = std::vector {5, 5, 5, 4}; + function = create_simple_function(element::u8, func_shape); + + inputData.clear(); + + function = PrePostProcessor().input(InputInfo() + .tensor(InputTensorInfo().set_spatial_static_shape(2, 2)) + .preprocess(PreProcessSteps().resize(ResizeAlgorithm::RESIZE_LINEAR)) + .network(InputNetworkInfo().set_layout("NCHW")) + ) + .build(function); + + const auto ¶m = function->get_parameters()[0]; + inputData.emplace_back(param->get_element_type(), param->get_shape(), input_img.data()); + + // Calculate reference expected values from OpenCV + cv::Mat cvPic = cv::Mat(2, 2, CV_8UC1, input_img.data()); + cv::Mat cvPicResized; + cv::resize(cvPic, cvPicResized, cv::Size(1, 1), cv::INTER_NEAREST); + refOutData.emplace_back(param->get_element_type(), func_shape, cvPicResized.data); + // Exec now + Exec(); +} + +TEST_F(PreprocessOpenCVReferenceTest, resize_u8_large_picture_linear) { + threshold = 1.f; + abs_threshold = 1.f; // Some pixels still have deviations of 1 step + const size_t input_height = 50; + const size_t input_width = 50; + const size_t func_height = 37; + const size_t func_width = 31; + auto input_shape = Shape{1, 1, input_height, input_width}; + auto func_shape = Shape{1, 1, func_height, func_width}; + auto input_img = std::vector (shape_size(input_shape)); + std::default_random_engine random(0); // hard-coded seed to make test results predictable + std::uniform_int_distribution distrib(0, 255); + for (std::size_t i = 0; i < shape_size(input_shape); i++) { + auto v = distrib(random); + input_img[i] = static_cast(v); + } + function = create_simple_function(element::u8, func_shape); + + inputData.clear(); + + function = PrePostProcessor().input(InputInfo() + .tensor(InputTensorInfo().set_spatial_static_shape(input_height, input_width)) + .preprocess(PreProcessSteps().resize(ResizeAlgorithm::RESIZE_LINEAR)) + .network(InputNetworkInfo().set_layout("NCHW")) + ) + .build(function); + + const auto ¶m = function->get_parameters()[0]; + inputData.emplace_back(param->get_element_type(), param->get_shape(), input_img.data()); + + // Calculate reference expected values from OpenCV + cv::Mat cvPic = cv::Mat(input_height, input_width, CV_8UC1, input_img.data()); + cv::Mat cvPicResized; + cv::resize(cvPic, cvPicResized, cv::Size(func_width, func_height), cv::INTER_LINEAR_EXACT); + refOutData.emplace_back(param->get_element_type(), func_shape, cvPicResized.data); + // Exec now + Exec(); +} + +TEST_F(PreprocessOpenCVReferenceTest, resize_f32_large_picture_linear) { + threshold = 0.01f; + abs_threshold = 0.01f; + const size_t input_height = 50; + const size_t input_width = 50; + const size_t func_height = 37; + const size_t func_width = 31; + auto input_shape = Shape{1, 1, input_height, input_width}; + auto func_shape = Shape{1, 1, func_height, func_width}; + auto input_img = std::vector (shape_size(input_shape)); + std::default_random_engine random(0); // hard-coded seed to make test results predictable + std::uniform_int_distribution distrib(0, 255); + for (std::size_t i = 0; i < shape_size(input_shape); i++) { + input_img[i] = static_cast(distrib(random)); + } + function = create_simple_function(element::f32, func_shape); + + inputData.clear(); + + function = PrePostProcessor().input(InputInfo() + .tensor(InputTensorInfo().set_spatial_static_shape(input_height, input_width)) + .preprocess(PreProcessSteps().resize(ResizeAlgorithm::RESIZE_LINEAR)) + .network(InputNetworkInfo().set_layout("NCHW")) + ) + .build(function); + + const auto ¶m = function->get_parameters()[0]; + inputData.emplace_back(param->get_element_type(), param->get_shape(), input_img.data()); + + // Calculate reference expected values from OpenCV + cv::Mat cvPic = cv::Mat(input_height, input_width, CV_32FC1, input_img.data()); + cv::Mat cvPicResized; + cv::resize(cvPic, cvPicResized, cv::Size(func_width, func_height), cv::INTER_LINEAR_EXACT); + refOutData.emplace_back(param->get_element_type(), func_shape, cvPicResized.data); + // Exec now + Exec(); +} + +TEST_F(PreprocessOpenCVReferenceTest, DISABLED_resize_f32_large_picture_cubic_small) { + const size_t input_height = 4; + const size_t input_width = 4; + const size_t func_height = 3; + const size_t func_width = 3; + auto input_shape = Shape{1, 1, input_height, input_width}; + auto func_shape = Shape{1, 1, func_height, func_width}; + auto element_type = element::f32; + auto input_img = std::vector {1.f, 2.f, 3.f, 4.f, 4.f, 3.f, 2.f, 1.f, 1.f, 2.f, 3.f, 4.f, 4.f, 3.f, 2.f, 1.f}; + function = create_simple_function(element_type, func_shape); + function = PrePostProcessor().input(InputInfo() + .tensor(InputTensorInfo().set_spatial_static_shape(input_height, input_width)) + .preprocess(PreProcessSteps().resize(ResizeAlgorithm::RESIZE_CUBIC)) + .network(InputNetworkInfo().set_layout("NCHW")) + ) + .build(function); + + inputData.emplace_back(element_type, input_shape, input_img.data()); + + // Calculate reference expected values from OpenCV + cv::Mat cvPic = cv::Mat(input_height, input_width, CV_32FC1, input_img.data()); + cv::Mat cvPicResized; + cv::resize(cvPic, cvPicResized, cv::Size(func_width, func_height), cv::INTER_CUBIC); + refOutData.emplace_back(element_type, func_shape, cvPicResized.data); + // Exec now + Exec(); +} + #endif // OPENCV_TEMPLATE_TESTS \ No newline at end of file diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp index 33a45e6c04a..770c94678e5 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp @@ -372,7 +372,12 @@ void InterpolateEval::linear_func(const T* input_data, T* out) { if (wsum == 0.0f) { out[output_transform.index(output_coord)] = T{}; } else { - out[output_transform.index(output_coord)] = static_cast(summa / wsum); + if (std::is_integral()) { + // Round value for integral return types + out[output_transform.index(output_coord)] = static_cast(std::round(summa / wsum)); + } else { + out[output_transform.index(output_coord)] = static_cast(summa / wsum); + } } } NGRAPH_SUPPRESS_DEPRECATED_END diff --git a/ngraph/core/src/op/interpolate.cpp b/ngraph/core/src/op/interpolate.cpp index 720233582c8..d244f265b42 100644 --- a/ngraph/core/src/op/interpolate.cpp +++ b/ngraph/core/src/op/interpolate.cpp @@ -201,10 +201,10 @@ ov::PartialShape op::v4::Interpolate::get_padded_input_shape(const ov::PartialSh void op::v4::Interpolate::validate_and_infer_types() { NGRAPH_OP_SCOPE(v4_Interpolate_validate_and_infer_types); element::Type input_et = get_input_element_type(0); - NODE_VALIDATION_CHECK( - this, - input_et == element::f32 || input_et == element::f16 || input_et == element::i8 || input_et == element::bf16, - "Input element type must be f32, f16, bf16 or i8"); + NODE_VALIDATION_CHECK(this, + input_et == element::f32 || input_et == element::f16 || input_et == element::i8 || + input_et == element::bf16 || input_et == element::u8, + "Input element type must be f32, f16, bf16, i8 or u8"); element::Type sizes_et = get_input_element_type(1); NODE_VALIDATION_CHECK( @@ -454,6 +454,14 @@ bool op::v4::Interpolate::evaluate_interpolate(const HostTensorVector& outputs, outputs[0]->get_data_ptr(), out_shape, m_attrs); + case element::Type_t::u8: + ngraph::runtime::reference::interpolate(reinterpret_cast(padded_data_ptr), + padded_input_shape, + scales, + axes, + outputs[0]->get_data_ptr(), + out_shape, + m_attrs); break; default:; } @@ -469,6 +477,7 @@ bool op::v4::Interpolate::evaluate(const HostTensorVector& outputs, const HostTe bool op::v4::Interpolate::has_evaluate() const { NGRAPH_OP_SCOPE(v4_Interpolate_has_evaluate); switch (get_input_element_type(0)) { + case ngraph::element::i8: case ngraph::element::u8: case ngraph::element::f16: case ngraph::element::f32: From 846d1e0467283c38053e4b811b005b3bcd5d84ef Mon Sep 17 00:00:00 2001 From: Mikhail Nosov Date: Wed, 27 Oct 2021 21:05:06 +0300 Subject: [PATCH 04/12] [OV2.0+Bugfix] Layout serialization + Fix caching issues with auto-generated friendly names (#8153) * Fix caching issues with auto-generated friendly names Introduce "HashPass" to calculate hash like a serialize but without auto-generated friendly names IE Compilation context: use HashPass to calculate hash of ov::Function IE Compilation context tests: removed "friendly names" from tests Layout: serialization support + tests Parameter/Result: update set/get_layout according to layout changes * Fix clang * Tiny correction of CmakeLists * Renamed VariantWrapper to LayoutAttribute Removed test for conversion from/to fully dynamic layout (allowed now and does nothing) 'set_layout' - remove layout runtime info if empty layout is passed. This allows hashes to be the same if set_layout(param->get_layout()) is called * Fix build * change size_t to uint64_t for hash value Using size_t leads to high probability of conflict for 32-bit platforms * Removed debug print * Fix hash calculation for 32-bit platforms * Fix review comment --- .../src/compilation_context.cpp | 49 +---- .../include/transformations/hash.hpp | 39 ++++ .../transformations/rt_info/attributes.cpp | 1 + .../rt_info_deserialization.cpp | 8 + .../rt_info_serialization.cpp | 16 +- .../ie_compilation_context_test.cpp | 83 +++++++-- ngraph/core/CMakeLists.txt | 1 + ngraph/core/include/openvino/core/layout.hpp | 14 +- ngraph/core/include/openvino/op/parameter.hpp | 4 +- ngraph/core/include/openvino/op/result.hpp | 4 +- ngraph/core/src/layout.cpp | 10 +- ngraph/core/src/op/parameter.cpp | 20 +- ngraph/core/src/op/result.cpp | 18 +- ngraph/core/src/pass/serialize.cpp | 175 +++++++++++++----- ngraph/test/preprocess.cpp | 18 -- ngraph/test/type_prop/parameter.cpp | 8 +- ngraph/test/type_prop/result.cpp | 24 +++ 17 files changed, 353 insertions(+), 139 deletions(-) create mode 100644 inference-engine/src/transformations/include/transformations/hash.hpp diff --git a/inference-engine/src/inference_engine/src/compilation_context.cpp b/inference-engine/src/inference_engine/src/compilation_context.cpp index 4d78374d12e..1f22668c0da 100644 --- a/inference-engine/src/inference_engine/src/compilation_context.cpp +++ b/inference-engine/src/inference_engine/src/compilation_context.cpp @@ -18,7 +18,8 @@ #include "ie_itt.hpp" #include "ngraph/opsets/opset6.hpp" #include "ngraph/variant.hpp" -#include "openvino/pass/serialize.hpp" +#include "openvino/pass/manager.hpp" +#include "transformations/hash.hpp" #include "transformations/rt_info/fused_names_attribute.hpp" #include "transformations/rt_info/primitives_priority_attribute.hpp" @@ -29,7 +30,7 @@ namespace InferenceEngine { template -static std::size_t hash_combine(std::size_t seed, const T& a) { +static uint64_t hash_combine(uint64_t seed, const T& a) { // Hash combine formula from boost return seed ^ (std::hash()(a) + 0x9e3779b9 + (seed << 6) + (seed >> 2)); } @@ -39,34 +40,10 @@ static int32_t as_int32_t(T v) { return static_cast(v); } -class OstreamHashWrapper final : public std::streambuf { - std::size_t m_res = 0; - -public: - std::size_t getResult() const { - return m_res; - } - std::streamsize xsputn(const char* s, std::streamsize n) override { - const std::int64_t* intS = (const std::int64_t*)s; - std::streamsize n64 = n / sizeof(std::int64_t); - std::streamsize i = 0; - // Using 64-bit values executes much faster than char - while (i++ < n64) { - m_res += *(intS++); - } - - std::streamsize rest = n % sizeof(std::int64_t); - for (i = 0; i < rest; i++) { - m_res += s[n - rest + i]; - } - return n; - } -}; - ////////////////////////////////////////////////// std::string NetworkCompilationContext::calculateFileInfo(const std::string& filePath) { - size_t seed = 0; + uint64_t seed = 0; auto absPath = filePath; try { absPath = FileUtils::absoluteFilePath(filePath); @@ -88,23 +65,17 @@ std::string NetworkCompilationContext::calculateFileInfo(const std::string& file std::string NetworkCompilationContext::computeHash(const CNNNetwork& network, const std::map& compileOptions) { OV_ITT_SCOPE(FIRST_INFERENCE, itt::domains::IE_LT, "NetworkCompilationContext::computeHash - CNN"); - OstreamHashWrapper xmlHash; - OstreamHashWrapper binHash; - std::ostream xml(&xmlHash); - std::ostream bin(&binHash); IE_ASSERT(network.getFunction()); - // 1. Serialize + uint64_t seed = 0; + // 1. Calculate hash on function CNNNetwork net(network); - ov::pass::Serialize serializer(xml, bin); - serializer.run_on_function(net.getFunction()); + ov::pass::Manager m; + m.register_pass(seed); + m.run_passes(net.getFunction()); // 2. Compute hash on serialized data and options - size_t seed = 0; - seed = hash_combine(seed, xmlHash.getResult()); - seed = hash_combine(seed, binHash.getResult()); - for (const auto& kvp : compileOptions) { seed = hash_combine(seed, kvp.first + kvp.second); } @@ -163,7 +134,7 @@ std::string NetworkCompilationContext::computeHash(const CNNNetwork& network, std::string NetworkCompilationContext::computeHash(const std::string& modelName, const std::map& compileOptions) { OV_ITT_SCOPE(FIRST_INFERENCE, itt::domains::IE_LT, "NetworkCompilationContext::computeHash - ModelName"); - size_t seed = 0; + uint64_t seed = 0; try { seed = hash_combine(seed, FileUtils::absoluteFilePath(modelName)); } catch (...) { diff --git a/inference-engine/src/transformations/include/transformations/hash.hpp b/inference-engine/src/transformations/include/transformations/hash.hpp new file mode 100644 index 00000000000..ad8eed2d0f6 --- /dev/null +++ b/inference-engine/src/transformations/include/transformations/hash.hpp @@ -0,0 +1,39 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include + +#include "ngraph/opsets/opset.hpp" +#include "openvino/core/function.hpp" +#include "openvino/pass/serialize.hpp" + +namespace ov { +namespace pass { + +/** + * @brief Hash transformation calculates hash value for ov::Function + */ +class NGRAPH_API Hash : public ov::pass::FunctionPass { +public: + OPENVINO_RTTI("HashPass"); + + bool run_on_function(std::shared_ptr f) override; + + /** + * @brief Hash pass constructor + * + * @param output_hash_value Reference to output value. By applying hash pass on function, resulting hash value + * will be set to this variable + */ + Hash(uint64_t& output_hash_value); + +private: + uint64_t& m_hash; +}; + + +} // namespace pass +} // namespace ov diff --git a/inference-engine/src/transformations/src/transformations/rt_info/attributes.cpp b/inference-engine/src/transformations/src/transformations/rt_info/attributes.cpp index 17d552d19a0..26c42ab0fbc 100644 --- a/inference-engine/src/transformations/src/transformations/rt_info/attributes.cpp +++ b/inference-engine/src/transformations/src/transformations/rt_info/attributes.cpp @@ -11,6 +11,7 @@ ov::pass::Attributes::Attributes() { register_factory(); register_factory(); register_factory(); + register_factory(); } ov::Variant* ov::pass::Attributes::create_by_type_info(const ov::DiscreteTypeInfo& type_info) { diff --git a/inference-engine/tests/functional/inference_engine/ir_serialization/rt_info_deserialization.cpp b/inference-engine/tests/functional/inference_engine/ir_serialization/rt_info_deserialization.cpp index 7f40d83bfc8..0dd12b3ad62 100644 --- a/inference-engine/tests/functional/inference_engine/ir_serialization/rt_info_deserialization.cpp +++ b/inference-engine/tests/functional/inference_engine/ir_serialization/rt_info_deserialization.cpp @@ -205,6 +205,7 @@ TEST_F(RTInfoDeserialization, InputAndOutputV10) { + 1 3 @@ -251,6 +252,7 @@ TEST_F(RTInfoDeserialization, InputAndOutputV10) { + 1 3 @@ -285,9 +287,11 @@ TEST_F(RTInfoDeserialization, InputAndOutputV10) { check_version(f, 10); auto param = f->get_parameters()[0]; + EXPECT_EQ(param->get_layout(), ""); check_rt_info(param->output(0).get_rt_info()); auto result = f->get_results()[0]; + EXPECT_EQ(result->get_layout(), ""); check_rt_info(result->input(0).get_rt_info()); auto add = result->get_input_node_ptr(0); @@ -562,6 +566,7 @@ TEST_F(RTInfoDeserialization, InputAndOutputV11) { + 1 3 @@ -611,6 +616,7 @@ TEST_F(RTInfoDeserialization, InputAndOutputV11) { + 1 3 @@ -660,10 +666,12 @@ TEST_F(RTInfoDeserialization, InputAndOutputV11) { auto param = f->get_parameters()[0]; check_fused_names(param->output(0).get_rt_info(), "test1,test2"); check_old_api_map(param->get_rt_info(), std::vector({}), ngraph::element::Type_t::undefined); + EXPECT_EQ(param->get_layout(), "NCHW"); auto result = f->get_result(); check_fused_names(result->input(0).get_rt_info(), "test5,test6"); check_old_api_map(result->get_rt_info(), std::vector({}), ngraph::element::Type_t::undefined); + EXPECT_EQ(f->get_results()[0]->get_layout(), "?CHW"); auto add = result->get_input_node_ptr(0); check_fused_names(add->input(0).get_rt_info(), "test2,test3"); diff --git a/inference-engine/tests/functional/inference_engine/ir_serialization/rt_info_serialization.cpp b/inference-engine/tests/functional/inference_engine/ir_serialization/rt_info_serialization.cpp index 2ac68b52c48..a851b27026f 100644 --- a/inference-engine/tests/functional/inference_engine/ir_serialization/rt_info_serialization.cpp +++ b/inference-engine/tests/functional/inference_engine/ir_serialization/rt_info_serialization.cpp @@ -62,12 +62,15 @@ TEST_F(RTInfoSerializationTest, all_attributes_latest) { std::shared_ptr function; { auto data = std::make_shared(ngraph::element::Type_t::f32, ngraph::Shape{1, 3, 10, 10}); + data->set_layout("NCHW"); auto add = std::make_shared(data, data); init_info(add->get_rt_info()); init_info(add->input(0).get_rt_info()); init_info(add->input(1).get_rt_info()); init_info(add->output(0).get_rt_info()); - function = std::make_shared(OutputVector{add}, ParameterVector{data}); + auto result = std::make_shared(add); + result->set_layout("????"); + function = std::make_shared(ResultVector{result}, ParameterVector{data}); } pass::Manager m; @@ -100,6 +103,8 @@ TEST_F(RTInfoSerializationTest, all_attributes_latest) { }; auto add = f->get_results()[0]->get_input_node_ptr(0); + EXPECT_EQ(f->get_parameters()[0]->get_layout(), "NCHW"); + EXPECT_EQ(f->get_results()[0]->get_layout(), "????"); check_info(add->get_rt_info()); check_info(add->input(0).get_rt_info()); check_info(add->input(1).get_rt_info()); @@ -117,6 +122,7 @@ TEST_F(RTInfoSerializationTest, all_attributes_v10) { std::shared_ptr function; { auto data = std::make_shared(ngraph::element::Type_t::f32, ngraph::Shape{1, 3, 10, 10}); + data->set_layout("NCHW"); auto add = std::make_shared(data, data); init_info(add->get_rt_info()); init_info(add->input(0).get_rt_info()); @@ -142,6 +148,7 @@ TEST_F(RTInfoSerializationTest, all_attributes_v10) { check_info(add->input(0).get_rt_info()); check_info(add->input(1).get_rt_info()); check_info(add->output(0).get_rt_info()); + EXPECT_EQ(f->get_parameters()[0]->get_layout(), ""); } TEST_F(RTInfoSerializationTest, all_attributes_v11) { @@ -155,12 +162,15 @@ TEST_F(RTInfoSerializationTest, all_attributes_v11) { std::shared_ptr function; { auto data = std::make_shared(ngraph::element::Type_t::f32, ngraph::Shape{1, 3, 10, 10}); + data->set_layout("NCHW"); auto add = std::make_shared(data, data); init_info(add->get_rt_info()); init_info(add->input(0).get_rt_info()); init_info(add->input(1).get_rt_info()); init_info(add->output(0).get_rt_info()); - function = std::make_shared(OutputVector{add}, ParameterVector{data}); + auto result = std::make_shared(add); + result->set_layout("????"); + function = std::make_shared(ResultVector{result}, ParameterVector{data}); } pass::Manager m; @@ -185,6 +195,8 @@ TEST_F(RTInfoSerializationTest, all_attributes_v11) { }; auto add = f->get_results()[0]->get_input_node_ptr(0); + EXPECT_EQ(f->get_parameters()[0]->get_layout(), "NCHW"); + EXPECT_EQ(f->get_results()[0]->get_layout(), "????"); check_info(add->get_rt_info()); check_info(add->input(0).get_rt_info()); check_info(add->input(1).get_rt_info()); diff --git a/inference-engine/tests/unit/inference_engine/ie_compilation_context_test.cpp b/inference-engine/tests/unit/inference_engine/ie_compilation_context_test.cpp index c415e7a1bfb..1989dd11bab 100644 --- a/inference-engine/tests/unit/inference_engine/ie_compilation_context_test.cpp +++ b/inference-engine/tests/unit/inference_engine/ie_compilation_context_test.cpp @@ -41,7 +41,7 @@ static std::string generateTestFilePrefix() { class FileGuard { std::string m_fileName; public: - FileGuard(const std::string& name): m_fileName(name) {} + explicit FileGuard(std::string name): m_fileName(std::move(name)) {} ~FileGuard() { std::remove(m_fileName.c_str()); } }; @@ -134,26 +134,16 @@ static std::shared_ptr create_simple_function() { data->get_output_tensor(0).set_names({"parameter"}); auto mul_constant = ngraph::opset6::Constant::create(ngraph::element::i8, ngraph::Shape{1}, {3}); - mul_constant->set_friendly_name("mul_constant"); - mul_constant->get_output_tensor(0).set_names({"mul_constant"}); auto mul = std::make_shared(data, mul_constant); - mul->set_friendly_name("mul"); - mul->get_output_tensor(0).set_names({"mul"}); auto add_constant = ngraph::opset6::Constant::create(ngraph::element::i8, ngraph::Shape{1}, {2}); - add_constant->set_friendly_name("add_constant"); - add_constant->get_output_tensor(0).set_names({"add_constant"}); auto add = std::make_shared(mul, add_constant); - add->set_friendly_name("add"); - add->get_output_tensor(0).set_names({"add"}); // Create opset3::Result operation auto res = std::make_shared(add); - res->set_friendly_name("res"); // Create nGraph function auto func = std::make_shared(ngraph::ResultVector{res}, ngraph::ParameterVector{data}); - func->set_friendly_name("function"); return func; } @@ -162,8 +152,15 @@ static CNNNetwork createNetwork() { return res; } -static void checkCustomRt(std::function emptyCb, - std::function nameCb) { +static CNNNetwork createNetworkWithLayout(const ov::Layout& layout) { + auto fun = create_simple_function(); + fun->get_parameters()[0]->set_layout(layout); + fun->get_results()[0]->set_layout(layout); + return CNNNetwork(fun); +} + +static void checkCustomRt(const std::function& emptyCb, + const std::function& nameCb) { auto net1 = createNetwork(); auto net2 = createNetwork(); auto & op1 = net1.getFunction()->get_ops().front()->get_rt_info(); @@ -306,6 +303,66 @@ TEST(NetworkContext_CNNNetwork, HashWithFutureRt_int64) { NetworkCompilationContext::computeHash(net3, {})); } +TEST(NetworkContext_CNNNetwork, HashWithLayout) { + auto net1 = createNetworkWithLayout("NCHW"); + auto net2 = createNetworkWithLayout("nchw"); + auto net3 = createNetworkWithLayout("?CHW"); + auto net3_1 = createNetworkWithLayout("?CH?"); + auto net4 = createNetworkWithLayout(""); + auto fun5 = create_simple_function(); + fun5->get_parameters()[0]->set_layout("NCHW"); + fun5->get_parameters()[0]->set_layout(""); + fun5->get_results()[0]->set_layout("NHCW"); + fun5->get_results()[0]->set_layout(ov::Layout()); + auto net5 = CNNNetwork(fun5); + + EXPECT_EQ(NetworkCompilationContext::computeHash(net1, {}), + NetworkCompilationContext::computeHash(net2, {})); + + EXPECT_NE(NetworkCompilationContext::computeHash(net2, {}), + NetworkCompilationContext::computeHash(net3, {})); + + EXPECT_NE(NetworkCompilationContext::computeHash(net3, {}), + NetworkCompilationContext::computeHash(net3_1, {})); + + EXPECT_NE(NetworkCompilationContext::computeHash(net3, {}), + NetworkCompilationContext::computeHash(net4, {})); + + EXPECT_EQ(NetworkCompilationContext::computeHash(net4, {}), + NetworkCompilationContext::computeHash(net5, {})); +} + +TEST(NetworkContext_CNNNetwork, HashWithTensorNames) { + auto fun1 = create_simple_function(); + auto fun2 = create_simple_function(); + auto fun3 = create_simple_function(); + std::unordered_set names1, names2; + std::vector testNames; + testNames.reserve(100); + for (int i = 0; i < 100; i++) { + testNames.push_back("test" + std::to_string(i)); + } + std::for_each(testNames.begin(), testNames.end(), [&names1](const std::string& name) { + names1.insert(name); + }); + std::for_each(testNames.rbegin(), testNames.rend(), [&names2](const std::string& name) { + names2.insert(name); + }); + + fun1->input().set_names(names1); + fun2->input().set_names(names2); + + auto net1 = CNNNetwork(fun1); + auto net2 = CNNNetwork(fun2); + auto net3 = CNNNetwork(fun3); + + ASSERT_EQ(NetworkCompilationContext::computeHash(net1, {}), + NetworkCompilationContext::computeHash(net2, {})); + + ASSERT_NE(NetworkCompilationContext::computeHash(net2, {}), + NetworkCompilationContext::computeHash(net3, {})); +} + TEST(NetworkContext_CNNNetwork, HashWithDifferentResults) { auto net1 = createNetwork(); auto net2 = createNetwork(); diff --git a/ngraph/core/CMakeLists.txt b/ngraph/core/CMakeLists.txt index 488bb200f7d..ad93fe75574 100644 --- a/ngraph/core/CMakeLists.txt +++ b/ngraph/core/CMakeLists.txt @@ -90,6 +90,7 @@ file(GLOB_RECURSE rt_info_srcs ${CMAKE_CURRENT_SOURCE_DIR}/src/pass/rt_info/*.cp set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/src/pass/convert_precision.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/pass/convert_fp32_to_fp16.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/pass/init_node_info.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/src/pass/serialize.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/op/type_relaxed.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/function.cpp" # for SmartReshape ${smart_reshape_srcs} ${rt_info_srcs} diff --git a/ngraph/core/include/openvino/core/layout.hpp b/ngraph/core/include/openvino/core/layout.hpp index 93e48c31ed7..92352ca5888 100644 --- a/ngraph/core/include/openvino/core/layout.hpp +++ b/ngraph/core/include/openvino/core/layout.hpp @@ -164,15 +164,15 @@ protected: std::string m_dump; }; -template <> -class OPENVINO_API VariantWrapper : public VariantImpl { +class OPENVINO_API LayoutAttribute : public VariantImpl { public: - static constexpr VariantTypeInfo type_info{"Variant::Layout", 0}; - const VariantTypeInfo& get_type_info() const override { - return type_info; - } + OPENVINO_RTTI("layout", "0"); - explicit VariantWrapper(const value_type& value) : VariantImpl(value) {} + LayoutAttribute() = default; + + explicit LayoutAttribute(const Layout& value) : VariantImpl(value) {} + + bool visit_attributes(AttributeVisitor& visitor) override; }; } // namespace ov diff --git a/ngraph/core/include/openvino/op/parameter.hpp b/ngraph/core/include/openvino/op/parameter.hpp index 76b31adf66f..a64030178da 100644 --- a/ngraph/core/include/openvino/op/parameter.hpp +++ b/ngraph/core/include/openvino/op/parameter.hpp @@ -55,7 +55,9 @@ public: /// \brief Returns current layout, or empty Layout if it is not set Layout get_layout() const; - /// \brief Sets layout runtime information to tensor + /// \brief Sets layout runtime information to tensor. + /// + /// \param layout Layout to set. If empty (default constructed), layout runtime information is erased. void set_layout(const Layout& layout); protected: diff --git a/ngraph/core/include/openvino/op/result.hpp b/ngraph/core/include/openvino/op/result.hpp index 6e5a5da681c..90d8dfb8136 100644 --- a/ngraph/core/include/openvino/op/result.hpp +++ b/ngraph/core/include/openvino/op/result.hpp @@ -46,7 +46,9 @@ public: /// \brief Returns current layout, or empty Layout if it is not set Layout get_layout() const; - /// \brief Sets layout runtime information to tensor + /// \brief Sets layout runtime information to tensor. + /// + /// \param layout Layout to set. If empty (default constructed), layout runtime information is erased. void set_layout(const Layout& layout); }; } // namespace v0 diff --git a/ngraph/core/src/layout.cpp b/ngraph/core/src/layout.cpp index d6193765138..2c51e5db268 100644 --- a/ngraph/core/src/layout.cpp +++ b/ngraph/core/src/layout.cpp @@ -280,6 +280,9 @@ std::vector find_permutation(const Layout& src_layout, const Rank& rank if (src_layout == dst) { return {}; // No permutation is needed } + if (src_layout.empty() || dst.empty()) { + return {}; + } OPENVINO_ASSERT(!src_layout.m_dynamic && !dst.m_dynamic, "Conversion is not supported for dynamic layouts"); OPENVINO_ASSERT(src_layout.m_left_size == src_layout.m_left_size, "Conversion is not supported for layouts with different sizes"); @@ -332,6 +335,11 @@ void AttributeAdapter::set(const std::string& value) { m_ref = Layout(value); } -constexpr VariantTypeInfo VariantWrapper::type_info; +bool LayoutAttribute::visit_attributes(AttributeVisitor& visitor) { + std::string layout_str = m_value.to_string(); + visitor.on_attribute("layout", layout_str); + m_value = Layout(layout_str); + return true; +} } // namespace ov \ No newline at end of file diff --git a/ngraph/core/src/op/parameter.cpp b/ngraph/core/src/op/parameter.cpp index df0a476c29a..ad74129c7a1 100644 --- a/ngraph/core/src/op/parameter.cpp +++ b/ngraph/core/src/op/parameter.cpp @@ -49,17 +49,25 @@ void op::Parameter::set_is_relevant_to_shapes(bool is_relevant) { } ov::Layout op::Parameter::get_layout() const { - auto it = get_output_tensor(0).get_rt_info().find("LAYOUT"); - if (it == get_output_tensor(0).get_rt_info().end()) { - return ov::Layout(); + auto it = output(0).get_rt_info().find(ov::LayoutAttribute::get_type_info_static()); + if (it == output(0).get_rt_info().end()) { + return ""; } - auto layout = std::dynamic_pointer_cast>(it->second); - OPENVINO_ASSERT(layout, "'LAYOUT' runtime info for node is invalid, use set_layout API"); + auto layout = std::dynamic_pointer_cast(it->second); + OPENVINO_ASSERT(layout, + "'", + ov::LayoutAttribute::get_type_info_static(), + "' runtime info for parameter is invalid, use set_layout API"); return layout->get(); } void op::Parameter::set_layout(const ov::Layout& layout) { - get_output_tensor(0).get_rt_info()["LAYOUT"] = std::make_shared>(layout); + if (layout.empty()) { + output(0).get_rt_info().erase(ov::LayoutAttribute::get_type_info_static()); + } else { + output(0).get_rt_info()[ov::LayoutAttribute::get_type_info_static()] = + std::make_shared(layout); + } } BWDCMP_RTTI_DEFINITION(ov::AttributeAdapter); diff --git a/ngraph/core/src/op/result.cpp b/ngraph/core/src/op/result.cpp index 5958986b8aa..09595715ca0 100644 --- a/ngraph/core/src/op/result.cpp +++ b/ngraph/core/src/op/result.cpp @@ -68,17 +68,25 @@ bool op::Result::constant_fold(OutputVector& output_values, const OutputVector& } ov::Layout op::Result::get_layout() const { - auto it = get_output_tensor(0).get_rt_info().find("LAYOUT"); - if (it == get_output_tensor(0).get_rt_info().end()) { + auto it = input(0).get_rt_info().find(ov::LayoutAttribute::get_type_info_static()); + if (it == input(0).get_rt_info().end()) { return {}; } - auto layout = std::dynamic_pointer_cast>(it->second); - OPENVINO_ASSERT(layout, "'LAYOUT' runtime info for node is invalid, use set_layout API"); + auto layout = std::dynamic_pointer_cast(it->second); + OPENVINO_ASSERT(layout, + "'", + ov::LayoutAttribute::get_type_info_static(), + "' runtime info for result is invalid, use set_layout API"); return layout->get(); } void op::Result::set_layout(const ov::Layout& layout) { - get_output_tensor(0).get_rt_info()["LAYOUT"] = std::make_shared>(layout); + if (layout.empty()) { + input(0).get_rt_info().erase(ov::LayoutAttribute::get_type_info_static()); + } else { + input(0).get_rt_info()[ov::LayoutAttribute::get_type_info_static()] = + std::make_shared(layout); + } } BWDCMP_RTTI_DEFINITION(ov::AttributeAdapter); diff --git a/ngraph/core/src/pass/serialize.cpp b/ngraph/core/src/pass/serialize.cpp index 80ad22da05d..acacdb26a20 100644 --- a/ngraph/core/src/pass/serialize.cpp +++ b/ngraph/core/src/pass/serialize.cpp @@ -19,6 +19,7 @@ #include "openvino/op/util/framework_node.hpp" #include "openvino/pass/constant_folding.hpp" #include "pugixml.hpp" +#include "transformations/hash.hpp" using namespace ngraph; @@ -121,7 +122,8 @@ void ngfunction_2_ir(pugi::xml_node& node, const ngraph::Function& f, const std::map& custom_opsets, ConstantWriter& constant_write_handler, - int64_t version); + int64_t version, + bool deterministic); // Some of the operators were added to wrong opsets. This is a mapping // that allows such operators to be serialized with proper opsets. @@ -253,6 +255,7 @@ class XmlSerializer : public ngraph::AttributeVisitor { const std::map& m_custom_opsets; ConstantWriter& m_constant_write_handler; int64_t m_version; + bool m_deterministic; template std::string create_atribute_list(ngraph::ValueAccessor>& adapter) { @@ -374,12 +377,14 @@ public: const std::string& node_type_name, const std::map& custom_opsets, ConstantWriter& constant_write_handler, - int64_t version) + int64_t version, + bool deterministic = false) : m_xml_node(data), m_node_type_name(node_type_name), m_custom_opsets(custom_opsets), m_constant_write_handler(constant_write_handler), - m_version(version) {} + m_version(version), + m_deterministic(deterministic) {} void on_adapter(const std::string& name, ngraph::ValueAccessor& adapter) override { using BodyTargetNames = std::tuple>; @@ -508,11 +513,21 @@ public: // to layer above (m_xml_node.parent()) as in ngfunction_2_ir() layer (m_xml_node) with empty attributes // is removed. pugi::xml_node xml_body = m_xml_node.parent().append_child(name.c_str()); - ngfunction_2_ir(xml_body, *adapter.get(), m_custom_opsets, m_constant_write_handler, m_version); + ngfunction_2_ir(xml_body, + *adapter.get(), + m_custom_opsets, + m_constant_write_handler, + m_version, + m_deterministic); xml_body.remove_attribute("name"); xml_body.remove_attribute("version"); } else if (name == "net") { - ngfunction_2_ir(m_xml_node, *adapter.get(), m_custom_opsets, m_constant_write_handler, m_version); + ngfunction_2_ir(m_xml_node, + *adapter.get(), + m_custom_opsets, + m_constant_write_handler, + m_version, + m_deterministic); } else { NGRAPH_CHECK(false, "Unsupported Function name."); } @@ -668,6 +683,11 @@ std::string generate_unique_name(const std::unordered_set& unique_n } } +template +bool is_name_auto_generated(const T& n) { + return n.get_friendly_name() == n.get_name(); +} + // TODO: remove when CNNNetwork will be supporting not-unique names std::string get_node_unique_name(std::unordered_set& unique_names, const ngraph::Node* n) { std::string name = n->get_friendly_name(); @@ -837,8 +857,12 @@ void ngfunction_2_ir(pugi::xml_node& netXml, const ngraph::Function& f, const std::map& custom_opsets, ConstantWriter& constant_node_write_handler, - int64_t version) { - netXml.append_attribute("name").set_value(f.get_friendly_name().c_str()); + int64_t version, + bool deterministic) { + // If determinism is not required, include auto-generated names into xml + if (!deterministic || !is_name_auto_generated(f)) { + netXml.append_attribute("name").set_value(f.get_friendly_name().c_str()); + } netXml.append_attribute("version").set_value(version); pugi::xml_node layers = netXml.append_child("layers"); @@ -878,7 +902,10 @@ void ngfunction_2_ir(pugi::xml_node& netXml, // pugi::xml_node layer = layers.append_child("layer"); layer.append_attribute("id").set_value(layer_ids.find(node)->second); - layer.append_attribute("name").set_value(get_node_unique_name(unique_names, node).c_str()); + // If determinism is not required, include auto-generated names into xml + if (!deterministic || !is_name_auto_generated(*node)) { + layer.append_attribute("name").set_value(get_node_unique_name(unique_names, node).c_str()); + } layer.append_attribute("type").set_value(translate_type_name(node_type_name).c_str()); if (!exec_graph) { layer.append_attribute("version").set_value(get_opset_name(node, custom_opsets).c_str()); @@ -984,7 +1011,7 @@ void ngfunction_2_ir(pugi::xml_node& netXml, // fill general attributes auto_pad_resolving(node); // Backward compatibility: clear padding values for nodes with auto_pad - XmlSerializer visitor(data, node_type_name, custom_opsets, constant_node_write_handler, version); + XmlSerializer visitor(data, node_type_name, custom_opsets, constant_node_write_handler, version, deterministic); NGRAPH_CHECK(node->visit_attributes(visitor), "Visitor API is not supported in ", node); rt_info::XmlSerializer{data}.serialize(node->get_rt_info()); @@ -1042,43 +1069,48 @@ std::string provide_bin_path(const std::string& xmlPath, const std::string& binP return bestPath; } +void serializeFunc(std::ostream& xml_file, + std::ostream& bin_file, + std::shared_ptr f, + ov::pass::Serialize::Version ver, + const std::map& custom_opsets, + bool deterministic = false) { + auto version = static_cast(ver); + + auto& rt_info = f->get_rt_info(); + if (rt_info.count("version")) { + auto version_var = std::dynamic_pointer_cast>(rt_info.at("version")); + version = version_var->get(); + } + + if (version != static_cast(ver) && ver != ov::pass::Serialize::Version::UNSPECIFIED) + throw ngraph_error("Cannot serialize function to incompatible IR version"); + + if (version == static_cast(ov::pass::Serialize::Version::UNSPECIFIED)) + version = static_cast(ov::pass::Serialize::Version::IR_V11); + + if (version != static_cast(ov::pass::Serialize::Version::IR_V10) && + version != static_cast(ov::pass::Serialize::Version::IR_V11)) { + throw ngraph_error("Unsupported version"); + } + std::string name = "net"; + pugi::xml_document xml_doc; + pugi::xml_node net_node = xml_doc.append_child(name.c_str()); + ConstantWriter constant_write_handler(bin_file); + XmlSerializer visitor(net_node, name, custom_opsets, constant_write_handler, version, deterministic); + visitor.on_attribute(name, f); + + xml_doc.save(xml_file); + xml_file.flush(); + bin_file.flush(); +}; + } // namespace namespace ov { bool pass::Serialize::run_on_function(std::shared_ptr f) { - auto serializeFunc = [&](std::ostream& xml_file, std::ostream& bin_file) { - auto version = static_cast(m_version); - - auto& rt_info = f->get_rt_info(); - if (rt_info.count("version")) { - auto version_var = std::dynamic_pointer_cast>(rt_info.at("version")); - version = version_var->get(); - } - - if (version != static_cast(m_version) && m_version != Serialize::Version::UNSPECIFIED) - throw ngraph_error("Cannot serialize function to incompatible IR version"); - - if (version == static_cast(Serialize::Version::UNSPECIFIED)) - version = static_cast(Serialize::Version::IR_V11); - - if (version != static_cast(Serialize::Version::IR_V10) && - version != static_cast(Serialize::Version::IR_V11)) { - throw ngraph_error("Unsupported version"); - } - std::string name = "net"; - pugi::xml_document xml_doc; - pugi::xml_node net_node = xml_doc.append_child(name.c_str()); - ConstantWriter constant_write_handler(bin_file); - XmlSerializer visitor(net_node, name, m_custom_opsets, constant_write_handler, version); - visitor.on_attribute(name, f); - - xml_doc.save(xml_file); - xml_file.flush(); - bin_file.flush(); - }; - if (m_xmlFile && m_binFile) { - serializeFunc(*m_xmlFile, *m_binFile); + serializeFunc(*m_xmlFile, *m_binFile, f, m_version, m_custom_opsets); } else { std::ofstream bin_file(m_binPath, std::ios::out | std::ios::binary); NGRAPH_CHECK(bin_file, "Can't open bin file: \"" + m_binPath + "\""); @@ -1088,9 +1120,9 @@ bool pass::Serialize::run_on_function(std::shared_ptr f) { NGRAPH_CHECK(xml_file, "Can't open xml file: \"" + m_xmlPath + "\""); try { - serializeFunc(xml_file, bin_file); + serializeFunc(xml_file, bin_file, f, m_version, m_custom_opsets); } catch (const ngraph::CheckFailure&) { - // optimization decission was made to create .bin file upfront and + // optimization decision was made to create .bin file upfront and // write to it directly instead of buffering its content in memory, // hence we need to delete it here in case of failure xml_file.close(); @@ -1123,7 +1155,6 @@ pass::Serialize::Serialize(const std::string& xmlPath, std::map custom_opsets, pass::Serialize::Version version) : m_xmlFile{nullptr}, - m_binFile{nullptr}, m_xmlPath{valid_xml_path(xmlPath)}, m_binPath{provide_bin_path(xmlPath, binPath)}, m_version{version}, @@ -1211,4 +1242,60 @@ bool pass::StreamSerialize::run_on_function(std::shared_ptr f) // Return false because we didn't change nGraph Function return false; } + +/// -------- Hash calculation pass ------------- + +namespace { +template +static uint64_t hash_combine(uint64_t seed, const T& a) { + // Hash combine formula from boost + return seed ^ (std::hash()(a) + 0x9e3779b9 + (seed << 6) + (seed >> 2)); +} + +class OstreamHashWrapper final : public std::streambuf { + uint64_t m_res = 0; + +public: + uint64_t getResult() const { + return m_res; + } + + std::streamsize xsputn(const char* s, std::streamsize n) override { + auto* intS = (const std::streamsize*)s; + std::streamsize n64 = n / static_cast(sizeof(std::streamsize)); + std::streamsize i = 0; + // Using 64-bit values executes much faster than char + while (i++ < n64) { + m_res += *(intS++); + } + + std::streamsize rest = n % static_cast(sizeof(std::streamsize)); + for (i = 0; i < rest; i++) { + m_res += s[n - rest + i]; + } + return n; + } +}; +} // namespace + +bool pass::Hash::run_on_function(std::shared_ptr f) { + OstreamHashWrapper xmlHash; + OstreamHashWrapper binHash; + std::ostream xml(&xmlHash); + std::ostream bin(&binHash); + + // Determinism is important for hash calculation + serializeFunc(xml, bin, f, Serialize::Version::UNSPECIFIED, {}, true); + + uint64_t seed = 0; + seed = hash_combine(seed, xmlHash.getResult()); + seed = hash_combine(seed, binHash.getResult()); + + m_hash = seed; + // Return false because we didn't change nGraph Function + return false; +} + +pass::Hash::Hash(uint64_t& output_hash_value) : m_hash(output_hash_value) {} + } // namespace ov diff --git a/ngraph/test/preprocess.cpp b/ngraph/test/preprocess.cpp index 51f827f9177..868a47723fe 100644 --- a/ngraph/test/preprocess.cpp +++ b/ngraph/test/preprocess.cpp @@ -881,13 +881,6 @@ TEST(pre_post_process, postprocess_set_layout_network) { EXPECT_EQ(f->get_results()[0]->get_layout(), "NCHW"); } -TEST(pre_post_process, postprocess_set_layout_tensor) { - auto f = create_simple_function(element::f32, Shape{1, 3, 2, 2}); - // no layout is specified for network, no way to implicitly convert it to user's layout - EXPECT_THROW(f = PrePostProcessor().output(OutputInfo().tensor(OutputTensorInfo().set_layout("NHWC"))).build(f), - ov::AssertFailure); -} - TEST(pre_post_process, postprocess_convert_layout_implicit) { auto f = create_simple_function(element::f32, Shape{1, 3, 2, 2}); @@ -940,17 +933,6 @@ TEST(pre_post_process, postprocess_convert_layout_same) { EXPECT_EQ(size_old, f->get_ordered_ops().size()); } -TEST(pre_post_process, postprocess_convert_layout_default_error) { - auto f = create_simple_function(element::f32, Shape{1, 3, 2, 2}); - - EXPECT_THROW(f = PrePostProcessor() - .output(OutputInfo() - .network(OutputNetworkInfo().set_layout("NCHW")) - .postprocess(PostProcessSteps().convert_layout())) - .build(f), - ov::AssertFailure); -} - TEST(pre_post_process, postprocess_convert_layout_dims) { auto f = create_simple_function(element::f32, Shape{1, 3, 480, 640}); diff --git a/ngraph/test/type_prop/parameter.cpp b/ngraph/test/type_prop/parameter.cpp index f758f13c415..cc9e11a6828 100644 --- a/ngraph/test/type_prop/parameter.cpp +++ b/ngraph/test/type_prop/parameter.cpp @@ -35,15 +35,19 @@ TEST(type_prop, param_layout) { auto a = make_shared(element::f32, PartialShape::dynamic()); a->set_layout("NHWC"); ASSERT_EQ(a->get_layout(), "NHWC"); + a->set_layout(ov::Layout()); + EXPECT_TRUE(a->get_layout().empty()); + EXPECT_EQ(a->get_output_tensor(0).get_rt_info().count(ov::LayoutAttribute::get_type_info_static()), 0); } TEST(type_prop, param_layout_empty) { auto a = make_shared(element::f32, PartialShape::dynamic()); - ASSERT_EQ(a->get_layout(), ov::Layout()); + ASSERT_TRUE(a->get_layout().empty()); } TEST(type_prop, param_layout_invalid) { auto a = make_shared(element::f32, PartialShape::dynamic()); - a->get_output_tensor(0).get_rt_info()["LAYOUT"] = ov::make_variant("NCHW"); // incorrect way + a->get_output_tensor(0).get_rt_info()[ov::LayoutAttribute::get_type_info_static()] = + ov::make_variant("NCHW"); // incorrect way ASSERT_THROW(a->get_layout(), ov::AssertFailure); } diff --git a/ngraph/test/type_prop/result.cpp b/ngraph/test/type_prop/result.cpp index c08d6b77a44..85c343d3592 100644 --- a/ngraph/test/type_prop/result.cpp +++ b/ngraph/test/type_prop/result.cpp @@ -28,3 +28,27 @@ TEST(type_prop, result_dynamic_shape) { EXPECT_EQ(result->get_output_element_type(0), element::f32); EXPECT_TRUE(result->get_output_partial_shape(0).same_scheme(PartialShape::dynamic())); } + +TEST(type_prop, result_layout) { + auto a = make_shared(element::f32, PartialShape::dynamic()); + auto result = make_shared(a); + result->set_layout("NHWC"); + EXPECT_EQ(result->get_layout(), "NHWC"); + result->set_layout(ov::Layout()); + EXPECT_TRUE(result->get_layout().empty()); + EXPECT_EQ(result->input(0).get_rt_info().count(ov::LayoutAttribute::get_type_info_static()), 0); +} + +TEST(type_prop, result_layout_empty) { + auto a = make_shared(element::f32, PartialShape::dynamic()); + auto result = make_shared(a); + EXPECT_TRUE(result->get_layout().empty()); +} + +TEST(type_prop, result_layout_invalid) { + auto a = make_shared(element::f32, PartialShape::dynamic()); + auto result = make_shared(a); + result->input(0).get_rt_info()[ov::LayoutAttribute::get_type_info_static()] = + ov::make_variant("NCHW"); // incorrect way + ASSERT_THROW(result->get_layout(), ov::AssertFailure); +} From fe457aa59ccd46abefa03bf3b0d771edc585c99d Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Wed, 27 Oct 2021 22:45:16 +0300 Subject: [PATCH 05/12] Wmissing declarations for core OpenVINO (#8242) * Fixed common libraries * Enable flags only for ngraph, FEM, plugins and IE * Fixed OpenVINOConfig.cmake * Fixes for plugins * Fixed link stage --- cmake/templates/OpenVINOConfig.cmake.in | 7 + inference-engine/src/CMakeLists.txt | 3 +- .../src/cldnn_engine/cldnn_program.h | 3 +- .../src/cldnn_engine/ops/batch_to_space.cpp | 2 +- .../src/cldnn_engine/ops/broadcast.cpp | 4 +- .../src/cldnn_engine/ops/concat.cpp | 2 +- .../src/cldnn_engine/ops/constant.cpp | 2 +- .../src/cldnn_engine/ops/convert.cpp | 4 +- .../src/cldnn_engine/ops/convolution.cpp | 12 +- .../cldnn_engine/ops/ctc_greedy_decoder.cpp | 6 +- .../src/cldnn_engine/ops/cum_sum.cpp | 2 +- .../src/cldnn_engine/ops/depth_to_space.cpp | 2 +- .../src/cldnn_engine/ops/detection_output.cpp | 2 +- .../src/cldnn_engine/ops/eltwise.cpp | 38 ++-- .../src/cldnn_engine/ops/embedding_bag.cpp | 6 +- .../ops/extract_image_patches.cpp | 2 +- .../src/cldnn_engine/ops/fake_quantize.cpp | 2 +- .../src/cldnn_engine/ops/gather tree.cpp | 2 +- .../src/cldnn_engine/ops/gather.cpp | 6 +- .../src/cldnn_engine/ops/gather_elements.cpp | 2 +- .../src/cldnn_engine/ops/gather_nd.cpp | 2 +- inference-engine/src/cldnn_engine/ops/grn.cpp | 2 +- .../src/cldnn_engine/ops/interpolate.cpp | 2 +- .../src/cldnn_engine/ops/loop.cpp | 2 +- inference-engine/src/cldnn_engine/ops/lrn.cpp | 2 +- .../src/cldnn_engine/ops/matmul.cpp | 2 +- inference-engine/src/cldnn_engine/ops/mvn.cpp | 4 +- .../cldnn_engine/ops/non_max_suppression.cpp | 2 +- .../src/cldnn_engine/ops/normalize_l2.cpp | 2 +- .../src/cldnn_engine/ops/one_hot.cpp | 2 +- inference-engine/src/cldnn_engine/ops/pad.cpp | 2 +- .../src/cldnn_engine/ops/parameter.cpp | 2 +- .../src/cldnn_engine/ops/pooling.cpp | 4 +- .../src/cldnn_engine/ops/prior_box.cpp | 4 +- .../src/cldnn_engine/ops/proposal.cpp | 2 +- .../src/cldnn_engine/ops/reduce.cpp | 20 +- .../src/cldnn_engine/ops/region_yolo.cpp | 2 +- .../src/cldnn_engine/ops/reorg_yolo.cpp | 2 +- .../src/cldnn_engine/ops/reshape.cpp | 8 +- .../src/cldnn_engine/ops/result.cpp | 2 +- .../src/cldnn_engine/ops/reverse_sequence.cpp | 2 +- inference-engine/src/cldnn_engine/ops/rnn.cpp | 6 +- .../src/cldnn_engine/ops/roi_pooling.cpp | 6 +- .../ops/scatter_elements_update.cpp | 2 +- .../cldnn_engine/ops/scatter_nd_update.cpp | 2 +- .../src/cldnn_engine/ops/scatter_update.cpp | 2 +- .../src/cldnn_engine/ops/select.cpp | 2 +- .../src/cldnn_engine/ops/shuffle_channels.cpp | 2 +- .../src/cldnn_engine/ops/softmax.cpp | 4 +- .../src/cldnn_engine/ops/space_to_batch.cpp | 2 +- .../src/cldnn_engine/ops/space_to_depth.cpp | 2 +- .../src/cldnn_engine/ops/split.cpp | 6 +- .../src/cldnn_engine/ops/strided_slice.cpp | 2 +- .../src/cldnn_engine/ops/tensor_iterator.cpp | 2 +- .../src/cldnn_engine/ops/tile.cpp | 2 +- .../src/cldnn_engine/ops/topk.cpp | 2 +- .../src/cldnn_engine/ops/transpose.cpp | 2 +- .../src/cldnn_engine/ops/unary.cpp | 72 +++---- .../src/gna_plugin/backend/make_pwl.cpp | 1 + .../src/gna_plugin/gna2_model_debug_log.cpp | 46 ++-- .../src/gna_plugin/gna2_model_helper.cpp | 4 + .../src/gna_plugin/gna_device.cpp | 2 +- .../src/gna_plugin/gna_graph_compiler.cpp | 2 +- .../src/gna_plugin/gna_helper.cpp | 196 ------------------ .../src/gna_plugin/gna_model_serial.cpp | 6 +- .../src/gna_plugin/gna_plugin.cpp | 2 +- .../src/gna_plugin/runtime/cnn.cpp | 10 +- .../src/gna_plugin/runtime/pwl.cpp | 20 +- .../handle_transposes_around_matmul.cpp | 6 +- ...lit_convolution_with_large_buffer_size.cpp | 2 +- .../src/inference_engine/src/ie_data.cpp | 10 +- .../threading/ie_parallel_custom_arena.cpp | 14 +- .../src/legacy_api/src/cnn_network_impl.cpp | 4 + .../src/convert_function_to_cnn_network.cpp | 29 +-- .../src/legacy_api/src/graph_transformer.cpp | 2 +- .../src/legacy_api/src/net_pass.cpp | 8 +- .../src/legacy_api/src/ngraph_ops/eltwise.cpp | 2 +- .../legacy_api/src/ngraph_ops/scaleshift.cpp | 2 +- .../convert_proposal_to_proposal_ie.cpp | 4 + .../reshape_1d_ops.cpp | 4 + .../low_precision_transformations/src/add.cpp | 4 + .../src/fake_quantize_decomposition.cpp | 2 + .../src/fuse_convert.cpp | 4 + .../src/fuse_fake_quantize.cpp | 2 + .../pull_reshape_through_dequantization.cpp | 2 + .../pull_transpose_through_dequantization.cpp | 2 + .../src/reshape.cpp | 8 +- .../src/strided_slice.cpp | 4 + .../src/transpose.cpp | 4 + .../convert_to_power_static.cpp | 4 + .../ngraph_transformations/reshape_1d_ops.cpp | 12 +- ...tal_detectron_roifeatureextractor_node.cpp | 4 + .../nodes/mkldnn_interpolate_node.cpp | 6 +- .../src/mkldnn_plugin/nodes/mkldnn_rnn.cpp | 6 +- .../nodes/mkldnn_scatter_update_node.cpp | 2 +- .../nodes/mkldnn_tensoriterator_node.cpp | 2 +- .../src/pruning/propagate_masks.cpp | 2 +- .../interface/ie_iplugin_internal.hpp | 27 +-- .../src/plugin_api/performance_heuristics.hpp | 2 +- .../ie_preprocess_gapi_kernels.cpp | 10 +- .../readers/ir_reader_v7/ie_ir_version.hpp | 2 +- .../src/pass/insert_movebroadcast.cpp | 8 +- .../optimize_strided_slice.hpp | 2 - .../broadcast_elementwise_fusion.cpp | 4 + .../depth_to_space_fusion.cpp | 4 + .../optimize_strided_slice.cpp | 5 +- .../shuffle_channels_fusion.cpp | 4 + .../common_optimizations/swish_fusion.cpp | 4 + .../transpose_sinking.cpp | 4 + .../transpose_to_reshape.cpp | 4 + .../op_conversions/convert_broadcast3.cpp | 4 + .../op_conversions/fq_decomposition.cpp | 4 + .../operations/dynamic_shape_resolver.cpp | 2 + .../operations/out_shape_of_reshape.cpp | 2 + .../dynamic_to_static_shape_gather_nd.cpp | 2 +- .../dynamic_to_static_shape_matmul.cpp | 4 + .../dynamic_to_static_shape_split.cpp | 2 +- .../dynamic_to_static_shape_strided_slice.cpp | 4 + .../src/frontend/custom_kernel.cpp | 159 +++++--------- .../hw/conv_tiling/hw_convolution_tiler.cpp | 1 + .../src/middleend/passes/inject_sw.cpp | 3 - .../data_contents/deconvolution_contents.cpp | 12 ++ ngraph/core/CMakeLists.txt | 4 + .../builder/src/builder/autobroadcast.cpp | 6 +- ngraph/core/builder/src/builder/norm.cpp | 2 + .../core/builder/src/builder/reduce_ops.cpp | 3 + ngraph/core/include/ngraph/ngraph.hpp | 22 -- ngraph/core/include/ngraph/version.hpp | 25 +++ .../core/include/openvino/core/function.hpp | 4 +- .../runtime/reference/scatter_update.hpp | 18 +- .../src/runtime/reference/einsum.cpp | 8 +- .../reference/src/runtime/reference/pad.cpp | 2 +- .../src/runtime/reference/random_uniform.cpp | 3 + ngraph/core/src/descriptor/tensor.cpp | 2 +- ngraph/core/src/function.cpp | 6 +- ngraph/core/src/ngraph.cpp | 12 +- ngraph/core/src/op/abs.cpp | 2 + ngraph/core/src/op/acos.cpp | 2 + ngraph/core/src/op/acosh.cpp | 2 + ngraph/core/src/op/add.cpp | 2 + ngraph/core/src/op/asin.cpp | 2 + ngraph/core/src/op/asinh.cpp | 2 + ngraph/core/src/op/atan.cpp | 2 + ngraph/core/src/op/atanh.cpp | 2 + ngraph/core/src/op/ceiling.cpp | 2 + ngraph/core/src/op/clamp.cpp | 2 + ngraph/core/src/op/convert.cpp | 2 + ngraph/core/src/op/cos.cpp | 2 + ngraph/core/src/op/cosh.cpp | 2 + ngraph/core/src/op/deformable_convolution.cpp | 2 + ngraph/core/src/op/depth_to_space.cpp | 2 + ngraph/core/src/op/divide.cpp | 2 + ngraph/core/src/op/einsum.cpp | 4 + ngraph/core/src/op/equal.cpp | 2 + ngraph/core/src/op/erf.cpp | 2 + ngraph/core/src/op/exp.cpp | 2 + ngraph/core/src/op/fake_quantize.cpp | 2 + ngraph/core/src/op/floor.cpp | 2 + ngraph/core/src/op/floor_mod.cpp | 2 + ngraph/core/src/op/gelu.cpp | 2 + ngraph/core/src/op/greater.cpp | 2 + ngraph/core/src/op/greater_eq.cpp | 2 + ngraph/core/src/op/hswish.cpp | 2 + ngraph/core/src/op/less.cpp | 2 + ngraph/core/src/op/less_eq.cpp | 2 + ngraph/core/src/op/log.cpp | 2 + ngraph/core/src/op/logical_and.cpp | 2 + ngraph/core/src/op/logical_not.cpp | 2 + ngraph/core/src/op/logical_or.cpp | 2 + ngraph/core/src/op/lstm_cell.cpp | 2 +- ngraph/core/src/op/matmul.cpp | 2 + ngraph/core/src/op/max_pool.cpp | 4 + ngraph/core/src/op/maximum.cpp | 2 + ngraph/core/src/op/minimum.cpp | 2 + ngraph/core/src/op/mish.cpp | 2 + ngraph/core/src/op/multiply.cpp | 2 + ngraph/core/src/op/negative.cpp | 2 + ngraph/core/src/op/non_zero.cpp | 2 + ngraph/core/src/op/not_equal.cpp | 2 + ngraph/core/src/op/one_hot.cpp | 2 + ngraph/core/src/op/power.cpp | 2 + ngraph/core/src/op/prelu.cpp | 2 + ngraph/core/src/op/prior_box.cpp | 2 + ngraph/core/src/op/prior_box_clustered.cpp | 2 + ngraph/core/src/op/range.cpp | 2 + ngraph/core/src/op/reduce_l1.cpp | 2 + ngraph/core/src/op/reduce_l2.cpp | 2 + ngraph/core/src/op/reduce_logical_and.cpp | 2 + ngraph/core/src/op/reduce_logical_or.cpp | 2 + ngraph/core/src/op/reduce_max.cpp | 2 + ngraph/core/src/op/reduce_mean.cpp | 2 + ngraph/core/src/op/reduce_min.cpp | 2 + ngraph/core/src/op/reduce_prod.cpp | 4 +- ngraph/core/src/op/reduce_sum.cpp | 4 +- ngraph/core/src/op/relu.cpp | 2 + ngraph/core/src/op/reshape.cpp | 2 + ngraph/core/src/op/roi_align.cpp | 4 +- ngraph/core/src/op/round.cpp | 2 + .../core/src/op/scatter_elements_update.cpp | 2 + ngraph/core/src/op/scatter_nd_update.cpp | 2 + ngraph/core/src/op/scatter_update.cpp | 2 + ngraph/core/src/op/select.cpp | 2 + ngraph/core/src/op/shape_of.cpp | 2 + ngraph/core/src/op/sigmoid.cpp | 2 + ngraph/core/src/op/sign.cpp | 2 + ngraph/core/src/op/sin.cpp | 2 + ngraph/core/src/op/sinh.cpp | 2 + ngraph/core/src/op/softplus.cpp | 2 + ngraph/core/src/op/space_to_depth.cpp | 3 + ngraph/core/src/op/split.cpp | 2 + ngraph/core/src/op/sqrt.cpp | 2 + ngraph/core/src/op/squeeze.cpp | 2 + ngraph/core/src/op/strided_slice.cpp | 2 + ngraph/core/src/op/subtract.cpp | 2 + ngraph/core/src/op/swish.cpp | 2 + ngraph/core/src/op/tan.cpp | 2 + ngraph/core/src/op/tanh.cpp | 2 + ngraph/core/src/op/topk.cpp | 2 + ngraph/core/src/op/transpose.cpp | 2 + ngraph/core/src/op/unsqueeze.cpp | 2 + .../src/op/util/convert_color_nv12_base.cpp | 2 + ngraph/core/src/op/util/gather_base.cpp | 2 + ngraph/core/src/op/variadic_split.cpp | 2 + ngraph/core/src/op/xor.cpp | 4 +- ngraph/core/src/pass/graph_rewrite.cpp | 6 +- ngraph/core/src/pass/low_latency.cpp | 4 + ngraph/core/src/pass/manager.cpp | 8 +- .../core/src/pass/smart_reshape/matmul_sr.cpp | 4 + .../proposal_scales_stridedslice.cpp | 4 + .../smart_reshape/strided_slice_squeeze.cpp | 4 + ngraph/core/src/type/bfloat16.cpp | 2 +- ngraph/core/src/type/element_type.cpp | 2 +- ngraph/core/src/validation_util.cpp | 10 +- .../frontend/frontend_manager/CMakeLists.txt | 4 + ngraph/frontend/ir/src/frontend.cpp | 3 + .../onnx/frontend/src/core/transform.cpp | 18 +- ngraph/frontend/onnx/frontend/src/onnx.cpp | 4 - .../frontend/onnx/frontend/src/op/affine.cpp | 2 + .../frontend/onnx/frontend/src/op/argmax.cpp | 2 + .../frontend/onnx/frontend/src/op/argmin.cpp | 2 + .../onnx/frontend/src/op/cast_like.cpp | 3 +- .../onnx/frontend/src/op/constant_fill.cpp | 2 + .../frontend/src/op/constant_of_shape.cpp | 2 + ngraph/frontend/onnx/frontend/src/op/crop.cpp | 2 + .../onnx/frontend/src/op/gather_nd.cpp | 2 + .../onnx/frontend/src/op/log_softmax.cpp | 6 +- .../detection_output.cpp | 2 + .../generate_proposals_single_image.cpp | 2 + .../prior_grid_generator.cpp | 2 + .../roi_feature_extractor.cpp | 2 + .../experimental_detectron/topk_rios.cpp | 2 + .../src/op/org.openvinotoolkit/swish.cpp | 2 + .../onnx/frontend/src/op/quantize_linear.cpp | 6 +- .../frontend/onnx/frontend/src/op/range.cpp | 3 +- .../frontend/onnx/frontend/src/op/reduce.cpp | 2 + .../frontend/onnx/frontend/src/op/slice.cpp | 2 + .../frontend/onnx/frontend/src/ops_bridge.cpp | 8 +- .../onnx/frontend/src/utils/convpool.cpp | 8 +- .../onnx/frontend/src/utils/onnx_internal.cpp | 15 +- .../onnx_common/src/onnx_model_validator.cpp | 8 +- ngraph/frontend/paddlepaddle/src/frontend.cpp | 2 + ngraph/frontend/paddlepaddle/src/model.cpp | 28 +-- .../frontend/tensorflow/src/decoder_proto.cpp | 2 + 263 files changed, 843 insertions(+), 679 deletions(-) delete mode 100644 inference-engine/src/gna_plugin/gna_helper.cpp diff --git a/cmake/templates/OpenVINOConfig.cmake.in b/cmake/templates/OpenVINOConfig.cmake.in index 0bfecbd5e64..818080a0ac8 100644 --- a/cmake/templates/OpenVINOConfig.cmake.in +++ b/cmake/templates/OpenVINOConfig.cmake.in @@ -46,6 +46,9 @@ # `openvino::frontend::paddlepaddle` # PaddlePaddle FrontEnd target (optional) # +# `openvino::frontend::tensorflow` +# TensorFlow FrontEnd target (optional) +# # Result variables: # ------ # @@ -63,6 +66,9 @@ # `OpenVINO_Frontend_PaddlePaddle_FOUND` # OpenVINO PaddlePaddle frontend is available # +# `OpenVINO_Frontend_TensorFlow_FOUND` +# OpenVINO TensorFlow frontend is available +# # `OpenVINO_Frontend_IR_FOUND` # OpenVINO IR frontend is available # @@ -170,6 +176,7 @@ set(${CMAKE_FIND_PACKAGE_NAME}_Runtime_FOUND ON) set(${CMAKE_FIND_PACKAGE_NAME}_ONNX_FOUND @NGRAPH_ONNX_FRONTEND_ENABLE@) set(${CMAKE_FIND_PACKAGE_NAME}_PaddlePaddle_FOUND @NGRAPH_PDPD_FRONTEND_ENABLE@) set(${CMAKE_FIND_PACKAGE_NAME}_TensorFlow_FOUND @NGRAPH_TF_FRONTEND_ENABLE@) +set(${CMAKE_FIND_PACKAGE_NAME}_IR_FOUND @NGRAPH_IR_FRONTEND_ENABLE@) set(${CMAKE_FIND_PACKAGE_NAME}_Frontend_ONNX_FOUND ${${CMAKE_FIND_PACKAGE_NAME}_ONNX_FOUND}) set(${CMAKE_FIND_PACKAGE_NAME}_Frontend_PaddlePaddle_FOUND ${${CMAKE_FIND_PACKAGE_NAME}_PaddlePaddle_FOUND}) diff --git a/inference-engine/src/CMakeLists.txt b/inference-engine/src/CMakeLists.txt index 8b198bfbf28..73e1df69a7f 100644 --- a/inference-engine/src/CMakeLists.txt +++ b/inference-engine/src/CMakeLists.txt @@ -2,8 +2,9 @@ # SPDX-License-Identifier: Apache-2.0 # -if(CMAKE_COMPILER_IS_GNUCC) +if(CMAKE_COMPILER_IS_GNUCXX) ie_add_compiler_flags(-Wall) + ie_add_compiler_flags(-Wmissing-declarations) endif() add_subdirectory(preprocessing) diff --git a/inference-engine/src/cldnn_engine/cldnn_program.h b/inference-engine/src/cldnn_engine/cldnn_program.h index 632c5bc37a2..a14635f2e49 100644 --- a/inference-engine/src/cldnn_engine/cldnn_program.h +++ b/inference-engine/src/cldnn_engine/cldnn_program.h @@ -29,12 +29,13 @@ enum class eltwise_mode : int32_t; } // namespace cldnn #define REGISTER_FACTORY_IMPL(op_version, op_name) \ +void __register ## _ ## op_name ## _ ## op_version(); \ void __register ## _ ## op_name ## _ ## op_version() { \ Program::RegisterFactory( \ [](Program& p, const std::shared_ptr& op) { \ auto op_casted = std::dynamic_pointer_cast(op); \ if (!op_casted) \ - IE_THROW() << "Invalid ngraph Node type passed into " << __PRETTY_FUNCTION__; \ + IE_THROW() << "Invalid ngraph Node type passed into " << __PRETTY_FUNCTION__; \ Create##op_name##Op(p, op_casted); \ }); \ } diff --git a/inference-engine/src/cldnn_engine/ops/batch_to_space.cpp b/inference-engine/src/cldnn_engine/ops/batch_to_space.cpp index d67f9e9888a..f25e8b65e1d 100644 --- a/inference-engine/src/cldnn_engine/ops/batch_to_space.cpp +++ b/inference-engine/src/cldnn_engine/ops/batch_to_space.cpp @@ -12,7 +12,7 @@ namespace CLDNNPlugin { -void CreateBatchToSpaceOp(Program& p, const std::shared_ptr& op) { +static void CreateBatchToSpaceOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {4}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/broadcast.cpp b/inference-engine/src/cldnn_engine/ops/broadcast.cpp index 16264a31fea..d121393e827 100644 --- a/inference-engine/src/cldnn_engine/ops/broadcast.cpp +++ b/inference-engine/src/cldnn_engine/ops/broadcast.cpp @@ -88,7 +88,7 @@ static void CreateCommonBroadcastOp(Program& p, const std::shared_ptr& op) { +static void CreateBroadcastOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2, 3}); if (op->get_broadcast_spec().m_type == ngraph::op::AutoBroadcastType::NONE && op->get_input_size() == 3) { auto axis_mapping_node = std::dynamic_pointer_cast(op->get_input_node_shared_ptr(2)); @@ -103,7 +103,7 @@ void CreateBroadcastOp(Program& p, const std::shared_ptr& op) { +static void CreateBroadcastOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2, 3}); ngraph::AxisSet axis_mapping; if (op->get_input_size() == 3) { diff --git a/inference-engine/src/cldnn_engine/ops/concat.cpp b/inference-engine/src/cldnn_engine/ops/concat.cpp index fc1e51d1981..3fbd1ceecf8 100644 --- a/inference-engine/src/cldnn_engine/ops/concat.cpp +++ b/inference-engine/src/cldnn_engine/ops/concat.cpp @@ -38,7 +38,7 @@ static cldnn::concatenation::concatenation_axis GetConcatAxis(int32_t axis, size return cldnn::concatenation::concatenation_axis::along_f; // shouldn't get here } -void CreateConcatOp(Program& p, const std::shared_ptr& op) { +static void CreateConcatOp(Program& p, const std::shared_ptr& op) { auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); auto concatPrim = cldnn::concatenation( diff --git a/inference-engine/src/cldnn_engine/ops/constant.cpp b/inference-engine/src/cldnn_engine/ops/constant.cpp index 58bc0a18d4a..d2b4a37e63c 100644 --- a/inference-engine/src/cldnn_engine/ops/constant.cpp +++ b/inference-engine/src/cldnn_engine/ops/constant.cpp @@ -78,7 +78,7 @@ static cldnn::tensor getConstTensor(const ngraph::Shape constDims) { return constTensor; } -void CreateConstantOp(Program& p, const std::shared_ptr& op) { +static void CreateConstantOp(Program& p, const std::shared_ptr& op) { auto constDims = op->get_shape(); cldnn::tensor constTensor = getConstTensor(constDims); diff --git a/inference-engine/src/cldnn_engine/ops/convert.cpp b/inference-engine/src/cldnn_engine/ops/convert.cpp index 603eb26abeb..a9fd103dd08 100644 --- a/inference-engine/src/cldnn_engine/ops/convert.cpp +++ b/inference-engine/src/cldnn_engine/ops/convert.cpp @@ -12,7 +12,7 @@ namespace CLDNNPlugin { -void CreateConvertLikeOp(Program& p, const std::shared_ptr& op) { +static void CreateConvertLikeOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); @@ -30,7 +30,7 @@ void CreateConvertLikeOp(Program& p, const std::shared_ptr& op) { +static void CreateConvertOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {1}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/convolution.cpp b/inference-engine/src/cldnn_engine/ops/convolution.cpp index e8c44693dbd..a5e37664ae2 100644 --- a/inference-engine/src/cldnn_engine/ops/convolution.cpp +++ b/inference-engine/src/cldnn_engine/ops/convolution.cpp @@ -61,7 +61,7 @@ static ConvoltuionParameters GetConvolutionParameters(const ngraph::CoordinateDi return {stride, padding, dilation, groups}; } -void CreateGroupConvolutionOp(Program& p, const std::shared_ptr& op) { +static void CreateGroupConvolutionOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inputs = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); @@ -91,7 +91,7 @@ void CreateGroupConvolutionOp(Program& p, const std::shared_ptr& op) { +static void CreateConvolutionOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inputs = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); @@ -120,7 +120,7 @@ void CreateConvolutionOp(Program& p, const std::shared_ptr& op) { +static void CreateConvolutionBackpropDataOp(Program& p, const std::shared_ptr& op) { // 3rd input is an optional output shape p.ValidateInputs(op, {2, 3}); auto inputs = p.GetInputPrimitiveIDs(op); @@ -176,7 +176,7 @@ void CreateConvolutionBackpropDataOp(Program& p, const std::shared_ptr& op) { +static void CreateGroupConvolutionBackpropDataOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inputs = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); @@ -233,7 +233,7 @@ void CreateGroupConvolutionBackpropDataOp(Program& p, const std::shared_ptr& op) { +static void CreateDeformableConvolutionOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {3}); auto inputs = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); @@ -303,7 +303,7 @@ void CreateDeformableConvolutionOp(Program& p, const std::shared_ptr& op) { +static void CreateBinaryConvolutionOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inputs = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/ctc_greedy_decoder.cpp b/inference-engine/src/cldnn_engine/ops/ctc_greedy_decoder.cpp index 4ff72462a47..b0e7af10bdc 100644 --- a/inference-engine/src/cldnn_engine/ops/ctc_greedy_decoder.cpp +++ b/inference-engine/src/cldnn_engine/ops/ctc_greedy_decoder.cpp @@ -17,7 +17,7 @@ namespace CLDNNPlugin { -void CreateCommonCTCGreedyDecoderOp(Program& p, const std::shared_ptr& op, bool ctc_merge_repeated) { +static void CreateCommonCTCGreedyDecoderOp(Program& p, const std::shared_ptr& op, bool ctc_merge_repeated) { p.ValidateInputs(op, {2, 3}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); @@ -120,11 +120,11 @@ void CreateCommonCTCGreedyDecoderOp(Program& p, const std::shared_ptr& op) { +static void CreateCTCGreedyDecoderOp(Program& p, const std::shared_ptr& op) { CreateCommonCTCGreedyDecoderOp(p, op, op->get_ctc_merge_repeated()); } -void CreateCTCGreedyDecoderSeqLenOp(Program& p, const std::shared_ptr& op) { +static void CreateCTCGreedyDecoderSeqLenOp(Program& p, const std::shared_ptr& op) { CreateCommonCTCGreedyDecoderOp(p, op, op->get_merge_repeated()); } diff --git a/inference-engine/src/cldnn_engine/ops/cum_sum.cpp b/inference-engine/src/cldnn_engine/ops/cum_sum.cpp index 9f8e2a463f2..19c26a52764 100644 --- a/inference-engine/src/cldnn_engine/ops/cum_sum.cpp +++ b/inference-engine/src/cldnn_engine/ops/cum_sum.cpp @@ -41,7 +41,7 @@ static inline cldnn::cum_sum::cum_sum_axis GetCumSumAxis(int32_t axis, uint32_t return cldnn::cum_sum::cum_sum_axis::along_f; // shouldn't get here } -void CreateCumSumOp(Program& p, const std::shared_ptr& op) { +static void CreateCumSumOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {1, 2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/depth_to_space.cpp b/inference-engine/src/cldnn_engine/ops/depth_to_space.cpp index aa762a356d7..6e0d2c2c6ed 100644 --- a/inference-engine/src/cldnn_engine/ops/depth_to_space.cpp +++ b/inference-engine/src/cldnn_engine/ops/depth_to_space.cpp @@ -22,7 +22,7 @@ static cldnn::depth_to_space_mode GetDepthMode(ngraph::op::v0::DepthToSpace::Dep return cldnn::depth_to_space_mode::blocks_first; } -void CreateDepthToSpaceOp(Program& p, const std::shared_ptr& op) { +static void CreateDepthToSpaceOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {1}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/detection_output.cpp b/inference-engine/src/cldnn_engine/ops/detection_output.cpp index 80616090655..35f19bbf796 100644 --- a/inference-engine/src/cldnn_engine/ops/detection_output.cpp +++ b/inference-engine/src/cldnn_engine/ops/detection_output.cpp @@ -26,7 +26,7 @@ static cldnn::prior_box_code_type PriorBoxCodeFromString(const std::string& str) return cldnn::prior_box_code_type::corner; } -void CreateDetectionOutputOp(Program& p, const std::shared_ptr& op) { +static void CreateDetectionOutputOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {3}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/eltwise.cpp b/inference-engine/src/cldnn_engine/ops/eltwise.cpp index f486bff593d..70ba74bb0dc 100644 --- a/inference-engine/src/cldnn_engine/ops/eltwise.cpp +++ b/inference-engine/src/cldnn_engine/ops/eltwise.cpp @@ -87,71 +87,71 @@ void CreateElementwiseOp(Program& p, const std::shared_ptr& op, cl p.AddPrimitiveToProfiler(op); } -void CreateAddOp(Program& p, const std::shared_ptr& op) { +static void CreateAddOp(Program& p, const std::shared_ptr& op) { CreateElementwiseOp(p, op, cldnn::eltwise_mode::sum); } -void CreateMultiplyOp(Program& p, const std::shared_ptr& op) { +static void CreateMultiplyOp(Program& p, const std::shared_ptr& op) { CreateElementwiseOp(p, op, cldnn::eltwise_mode::prod); } -void CreateMaximumOp(Program& p, const std::shared_ptr& op) { +static void CreateMaximumOp(Program& p, const std::shared_ptr& op) { CreateElementwiseOp(p, op, cldnn::eltwise_mode::max); } -void CreateMinimumOp(Program& p, const std::shared_ptr& op) { +static void CreateMinimumOp(Program& p, const std::shared_ptr& op) { CreateElementwiseOp(p, op, cldnn::eltwise_mode::min); } -void CreateSubtractOp(Program& p, const std::shared_ptr& op) { +static void CreateSubtractOp(Program& p, const std::shared_ptr& op) { CreateElementwiseOp(p, op, cldnn::eltwise_mode::sub); } -void CreateDivideOp(Program& p, const std::shared_ptr& op) { +static void CreateDivideOp(Program& p, const std::shared_ptr& op) { CreateElementwiseOp(p, op, cldnn::eltwise_mode::div); } -void CreateSquaredDifferenceOp(Program& p, const std::shared_ptr& op) { +static void CreateSquaredDifferenceOp(Program& p, const std::shared_ptr& op) { CreateElementwiseOp(p, op, cldnn::eltwise_mode::squared_diff); } -void CreateEqualOp(Program& p, const std::shared_ptr& op) { +static void CreateEqualOp(Program& p, const std::shared_ptr& op) { CreateElementwiseOp(p, op, cldnn::eltwise_mode::eq); } -void CreateNotEqualOp(Program& p, const std::shared_ptr& op) { +static void CreateNotEqualOp(Program& p, const std::shared_ptr& op) { CreateElementwiseOp(p, op, cldnn::eltwise_mode::ne); } -void CreateLessOp(Program& p, const std::shared_ptr& op) { +static void CreateLessOp(Program& p, const std::shared_ptr& op) { CreateElementwiseOp(p, op, cldnn::eltwise_mode::lt); } -void CreateLessEqualOp(Program& p, const std::shared_ptr& op) { +static void CreateLessEqualOp(Program& p, const std::shared_ptr& op) { CreateElementwiseOp(p, op, cldnn::eltwise_mode::le); } -void CreateGreaterOp(Program& p, const std::shared_ptr& op) { +static void CreateGreaterOp(Program& p, const std::shared_ptr& op) { CreateElementwiseOp(p, op, cldnn::eltwise_mode::gt); } -void CreateGreaterEqualOp(Program& p, const std::shared_ptr& op) { +static void CreateGreaterEqualOp(Program& p, const std::shared_ptr& op) { CreateElementwiseOp(p, op, cldnn::eltwise_mode::ge); } -void CreateLogicalAndOp(Program& p, const std::shared_ptr& op) { +static void CreateLogicalAndOp(Program& p, const std::shared_ptr& op) { CreateElementwiseOp(p, op, cldnn::eltwise_mode::logic_and); } -void CreateLogicalOrOp(Program& p, const std::shared_ptr& op) { +static void CreateLogicalOrOp(Program& p, const std::shared_ptr& op) { CreateElementwiseOp(p, op, cldnn::eltwise_mode::logic_or); } -void CreateLogicalXorOp(Program& p, const std::shared_ptr& op) { +static void CreateLogicalXorOp(Program& p, const std::shared_ptr& op) { CreateElementwiseOp(p, op, cldnn::eltwise_mode::logic_xor); } -void CreatePowerOp(Program& p, const std::shared_ptr& op) { +static void CreatePowerOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto power_node = std::dynamic_pointer_cast(op->get_input_node_shared_ptr(1)); if (power_node) { @@ -166,11 +166,11 @@ void CreatePowerOp(Program& p, const std::shared_ptr& op) CreateElementwiseOp(p, op, cldnn::eltwise_mode::pow); } -void CreateFloorModOp(Program& p, const std::shared_ptr& op) { +static void CreateFloorModOp(Program& p, const std::shared_ptr& op) { CreateElementwiseOp(p, op, cldnn::eltwise_mode::floor_mod); } -void CreateModOp(Program& p, const std::shared_ptr& op) { +static void CreateModOp(Program& p, const std::shared_ptr& op) { CreateElementwiseOp(p, op, cldnn::eltwise_mode::mod); } diff --git a/inference-engine/src/cldnn_engine/ops/embedding_bag.cpp b/inference-engine/src/cldnn_engine/ops/embedding_bag.cpp index 369c0eca44a..855e68de938 100644 --- a/inference-engine/src/cldnn_engine/ops/embedding_bag.cpp +++ b/inference-engine/src/cldnn_engine/ops/embedding_bag.cpp @@ -16,7 +16,7 @@ namespace CLDNNPlugin { -void CreateEmbeddingBagOffsetsSumOp(Program& p, const std::shared_ptr& op) { +static void CreateEmbeddingBagOffsetsSumOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {3, 4, 5}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); @@ -72,7 +72,7 @@ void CreateEmbeddingBagOffsetsSumOp(Program& p, const std::shared_ptr& op) { +static void CreateEmbeddingBagPackedSumOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2, 3}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); @@ -113,7 +113,7 @@ void CreateEmbeddingBagPackedSumOp(Program& p, const std::shared_ptr& op) { +static void CreateEmbeddingSegmentsSumOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {4, 5, 6}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/extract_image_patches.cpp b/inference-engine/src/cldnn_engine/ops/extract_image_patches.cpp index 088a0fcd413..c747df5e7ad 100644 --- a/inference-engine/src/cldnn_engine/ops/extract_image_patches.cpp +++ b/inference-engine/src/cldnn_engine/ops/extract_image_patches.cpp @@ -22,7 +22,7 @@ static inline std::string PadToString(ngraph::op::PadType pad) { return ""; } -void CreateExtractImagePatchesOp(Program& p, const std::shared_ptr& op) { +static void CreateExtractImagePatchesOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {1}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/fake_quantize.cpp b/inference-engine/src/cldnn_engine/ops/fake_quantize.cpp index 52ea33e5d3d..f2515ff83c4 100644 --- a/inference-engine/src/cldnn_engine/ops/fake_quantize.cpp +++ b/inference-engine/src/cldnn_engine/ops/fake_quantize.cpp @@ -11,7 +11,7 @@ namespace CLDNNPlugin { -void CreateFakeQuantizeOp(Program& p, const std::shared_ptr& op) { +static void CreateFakeQuantizeOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {5}); std::string layerName = layer_type_name_ID(op); auto inputPrimitives = p.GetInputPrimitiveIDs(op); diff --git a/inference-engine/src/cldnn_engine/ops/gather tree.cpp b/inference-engine/src/cldnn_engine/ops/gather tree.cpp index 5476aa40d97..2b54cd98507 100644 --- a/inference-engine/src/cldnn_engine/ops/gather tree.cpp +++ b/inference-engine/src/cldnn_engine/ops/gather tree.cpp @@ -12,7 +12,7 @@ namespace CLDNNPlugin { -void CreateGatherTreeOp(Program& p, const std::shared_ptr& op) { +static void CreateGatherTreeOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {4}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/gather.cpp b/inference-engine/src/cldnn_engine/ops/gather.cpp index bcf632f3194..90208c66d6f 100644 --- a/inference-engine/src/cldnn_engine/ops/gather.cpp +++ b/inference-engine/src/cldnn_engine/ops/gather.cpp @@ -104,21 +104,21 @@ void CreateGatherOpBase(Program& p, const std::shared_ptr& op, const int64_t p.AddPrimitiveToProfiler(op); } -void CreateGatherOp(Program& p, const std::shared_ptr& op) { +static void CreateGatherOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2, 3}); CreateGatherOpBase(p, op); } REGISTER_FACTORY_IMPL(v1, Gather); -void CreateGatherOp(Program& p, const std::shared_ptr& op) { +static void CreateGatherOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2, 3, 4}); CreateGatherOpBase(p, op, op->get_batch_dims()); } REGISTER_FACTORY_IMPL(v7, Gather); -void CreateGatherOp(Program& p, const std::shared_ptr& op) { +static void CreateGatherOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2, 3, 4}); CreateGatherOpBase(p, op, op->get_batch_dims(), true); } diff --git a/inference-engine/src/cldnn_engine/ops/gather_elements.cpp b/inference-engine/src/cldnn_engine/ops/gather_elements.cpp index 50c25c37f1c..43cc0dc335f 100644 --- a/inference-engine/src/cldnn_engine/ops/gather_elements.cpp +++ b/inference-engine/src/cldnn_engine/ops/gather_elements.cpp @@ -40,7 +40,7 @@ static cldnn::gather_elements::gather_elements_axis GetGatherAxis(int axis, unsi return cldnn::gather_elements::gather_elements_axis::along_f; // shouldn't get here } -void CreateGatherElementsOp(Program& p, const std::shared_ptr& op) { +static void CreateGatherElementsOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/gather_nd.cpp b/inference-engine/src/cldnn_engine/ops/gather_nd.cpp index 266ada7f904..4d951d76d83 100644 --- a/inference-engine/src/cldnn_engine/ops/gather_nd.cpp +++ b/inference-engine/src/cldnn_engine/ops/gather_nd.cpp @@ -12,7 +12,7 @@ namespace CLDNNPlugin { -void CreateGatherNDOp(Program& p, const std::shared_ptr& op) { +static void CreateGatherNDOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/grn.cpp b/inference-engine/src/cldnn_engine/ops/grn.cpp index c6d07fe6191..ed35f56496a 100644 --- a/inference-engine/src/cldnn_engine/ops/grn.cpp +++ b/inference-engine/src/cldnn_engine/ops/grn.cpp @@ -11,7 +11,7 @@ namespace CLDNNPlugin { -void CreateGRNOp(Program& p, const std::shared_ptr& op) { +static void CreateGRNOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {1}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/interpolate.cpp b/inference-engine/src/cldnn_engine/ops/interpolate.cpp index 190032897b4..083ff0f545b 100644 --- a/inference-engine/src/cldnn_engine/ops/interpolate.cpp +++ b/inference-engine/src/cldnn_engine/ops/interpolate.cpp @@ -100,7 +100,7 @@ static cldnn::resample::resample_axis GetInterpolationAxis(int32_t axis, uint32_ IE_THROW() << "Unsupported Interpolate axis: " << axis; } -void CreateInterpolateOp(Program& p, const std::shared_ptr& op) { +static void CreateInterpolateOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {3, 4}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/loop.cpp b/inference-engine/src/cldnn_engine/ops/loop.cpp index 604f73b7e5a..7201c143ad6 100644 --- a/inference-engine/src/cldnn_engine/ops/loop.cpp +++ b/inference-engine/src/cldnn_engine/ops/loop.cpp @@ -69,7 +69,7 @@ static std::string GetExternalInputName(const int64_t body_parameter_index, return {""}; } -void CreateLoopOp(Program& p, const std::shared_ptr& op) { +static void CreateLoopOp(Program& p, const std::shared_ptr& op) { const std::string layerName = layer_type_name_ID(op); auto inputPrimitives = p.GetInputPrimitiveIDs(op); const auto& loop_input_descs = op->get_input_descriptions(); diff --git a/inference-engine/src/cldnn_engine/ops/lrn.cpp b/inference-engine/src/cldnn_engine/ops/lrn.cpp index 28e55bf038f..a28a88050c6 100644 --- a/inference-engine/src/cldnn_engine/ops/lrn.cpp +++ b/inference-engine/src/cldnn_engine/ops/lrn.cpp @@ -20,7 +20,7 @@ static cldnn::lrn_norm_region GetNormRegion(std::vector axis_value) { } } -void CreateLRNOp(Program& p, const std::shared_ptr& op) { +static void CreateLRNOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/matmul.cpp b/inference-engine/src/cldnn_engine/ops/matmul.cpp index 53b8fecd6c2..8dc523c16ab 100644 --- a/inference-engine/src/cldnn_engine/ops/matmul.cpp +++ b/inference-engine/src/cldnn_engine/ops/matmul.cpp @@ -52,7 +52,7 @@ static std::pair get_aligned_shapes(const ngraph:: return {shape_a_aligned, shape_b_aligned}; } -void CreateMatMulOp(Program& p, const std::shared_ptr& op) { +static void CreateMatMulOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/mvn.cpp b/inference-engine/src/cldnn_engine/ops/mvn.cpp index abd2128326b..c202acb4397 100644 --- a/inference-engine/src/cldnn_engine/ops/mvn.cpp +++ b/inference-engine/src/cldnn_engine/ops/mvn.cpp @@ -31,7 +31,7 @@ static void CreateCommonMVNOp(Program& p, const std::shared_ptr& o p.AddPrimitiveToProfiler(op); } -void CreateMVNOp(Program& p, const std::shared_ptr& op) { +static void CreateMVNOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {1}); bool across_channels = op->get_across_channels(); @@ -41,7 +41,7 @@ void CreateMVNOp(Program& p, const std::shared_ptr& op) { CreateCommonMVNOp(p, op, across_channels, normalize_variance, eps); } -void CreateMVNOp(Program& p, const std::shared_ptr& op) { +static void CreateMVNOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inConst = std::dynamic_pointer_cast(op->get_input_node_shared_ptr(1)); diff --git a/inference-engine/src/cldnn_engine/ops/non_max_suppression.cpp b/inference-engine/src/cldnn_engine/ops/non_max_suppression.cpp index b5c2e05e711..64e5eccf02e 100644 --- a/inference-engine/src/cldnn_engine/ops/non_max_suppression.cpp +++ b/inference-engine/src/cldnn_engine/ops/non_max_suppression.cpp @@ -25,7 +25,7 @@ static bool GetCenterPointBox(ngraph::op::v5::NonMaxSuppression::BoxEncodingType return false; } -void CreateNonMaxSuppressionIEInternalOp(Program& p, const std::shared_ptr& op) { +static void CreateNonMaxSuppressionIEInternalOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2, 3, 4, 5, 6}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); diff --git a/inference-engine/src/cldnn_engine/ops/normalize_l2.cpp b/inference-engine/src/cldnn_engine/ops/normalize_l2.cpp index 315dee55952..61519721e1b 100644 --- a/inference-engine/src/cldnn_engine/ops/normalize_l2.cpp +++ b/inference-engine/src/cldnn_engine/ops/normalize_l2.cpp @@ -13,7 +13,7 @@ namespace CLDNNPlugin { -void CreateNormalizeL2Op(Program& p, const std::shared_ptr& op) { +static void CreateNormalizeL2Op(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/one_hot.cpp b/inference-engine/src/cldnn_engine/ops/one_hot.cpp index b7c4fe8a126..0c550c21845 100644 --- a/inference-engine/src/cldnn_engine/ops/one_hot.cpp +++ b/inference-engine/src/cldnn_engine/ops/one_hot.cpp @@ -12,7 +12,7 @@ namespace CLDNNPlugin { -void CreateOneHotOp(Program& p, const std::shared_ptr& op) { +static void CreateOneHotOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {4}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/pad.cpp b/inference-engine/src/cldnn_engine/ops/pad.cpp index 02bdeb85dd5..c1ca44a611d 100644 --- a/inference-engine/src/cldnn_engine/ops/pad.cpp +++ b/inference-engine/src/cldnn_engine/ops/pad.cpp @@ -40,7 +40,7 @@ static std::vector GetPermuteOrder(const ngraph::CoordinateDiff& ie_ord return cldnn_order; } -void CreatePadOp(Program& p, const std::shared_ptr& op) { +static void CreatePadOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {3, 4}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/parameter.cpp b/inference-engine/src/cldnn_engine/ops/parameter.cpp index 6dd43841cf3..4712339350d 100644 --- a/inference-engine/src/cldnn_engine/ops/parameter.cpp +++ b/inference-engine/src/cldnn_engine/ops/parameter.cpp @@ -16,7 +16,7 @@ using namespace InferenceEngine; namespace CLDNNPlugin { -void CreateParameterOp(Program& p, const std::shared_ptr& op) { +static void CreateParameterOp(Program& p, const std::shared_ptr& op) { auto networkInputs = p.GetNetworkInputs(); if (networkInputs.find(op->get_friendly_name()) == networkInputs.end()) { IE_THROW() << "Can't find input " << op->get_friendly_name() << " in InputsDataMap"; diff --git a/inference-engine/src/cldnn_engine/ops/pooling.cpp b/inference-engine/src/cldnn_engine/ops/pooling.cpp index 1e0db7bd204..a921a798337 100644 --- a/inference-engine/src/cldnn_engine/ops/pooling.cpp +++ b/inference-engine/src/cldnn_engine/ops/pooling.cpp @@ -57,7 +57,7 @@ static PoolingParameters GetPoolingParameters(const ngraph::Shape& kernel, return {k, s, pb, pe}; } -void CreateAvgPoolOp(Program& p, const std::shared_ptr& op) { +static void CreateAvgPoolOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {1}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); @@ -77,7 +77,7 @@ void CreateAvgPoolOp(Program& p, const std::shared_ptr& p.AddPrimitiveToProfiler(op); } -void CreateMaxPoolOp(Program& p, const std::shared_ptr& op) { +static void CreateMaxPoolOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {1}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/prior_box.cpp b/inference-engine/src/cldnn_engine/ops/prior_box.cpp index 43eb5a69941..2aa29fb03d7 100644 --- a/inference-engine/src/cldnn_engine/ops/prior_box.cpp +++ b/inference-engine/src/cldnn_engine/ops/prior_box.cpp @@ -12,7 +12,7 @@ namespace CLDNNPlugin { -void CreatePriorBoxClusteredOp(Program& p, const std::shared_ptr& op) { +static void CreatePriorBoxClusteredOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); @@ -61,7 +61,7 @@ void CreatePriorBoxClusteredOp(Program& p, const std::shared_ptr& op) { +static void CreatePriorBoxOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/proposal.cpp b/inference-engine/src/cldnn_engine/ops/proposal.cpp index 9be2f1d4e99..ffca6d4e382 100644 --- a/inference-engine/src/cldnn_engine/ops/proposal.cpp +++ b/inference-engine/src/cldnn_engine/ops/proposal.cpp @@ -13,7 +13,7 @@ namespace CLDNNPlugin { -void CreateProposalOp(Program& p, const std::shared_ptr& op) { +static void CreateProposalOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {3}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); diff --git a/inference-engine/src/cldnn_engine/ops/reduce.cpp b/inference-engine/src/cldnn_engine/ops/reduce.cpp index 47a54c70299..fdb8c49277c 100644 --- a/inference-engine/src/cldnn_engine/ops/reduce.cpp +++ b/inference-engine/src/cldnn_engine/ops/reduce.cpp @@ -22,7 +22,7 @@ namespace CLDNNPlugin { -void CreateReduceOp(Program& p, const std::shared_ptr& op, cldnn::reduce_mode mode, bool keep_dims) { +static void CreateReduceOp(Program& p, const std::shared_ptr& op, cldnn::reduce_mode mode, bool keep_dims) { p.ValidateInputs(op, {2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); @@ -127,39 +127,39 @@ void CreateReduceOp(Program& p, const std::shared_ptr& op, cldnn:: } } -void CreateReduceMaxOp(Program& p, const std::shared_ptr& op) { +static void CreateReduceMaxOp(Program& p, const std::shared_ptr& op) { CreateReduceOp(p, op, cldnn::reduce_mode::max, op->get_keep_dims()); } -void CreateReduceLogicalAndOp(Program& p, const std::shared_ptr& op) { +static void CreateReduceLogicalAndOp(Program& p, const std::shared_ptr& op) { CreateReduceOp(p, op, cldnn::reduce_mode::logical_and, op->get_keep_dims()); } -void CreateReduceLogicalOrOp(Program& p, const std::shared_ptr& op) { +static void CreateReduceLogicalOrOp(Program& p, const std::shared_ptr& op) { CreateReduceOp(p, op, cldnn::reduce_mode::logical_or, op->get_keep_dims()); } -void CreateReduceMeanOp(Program& p, const std::shared_ptr& op) { +static void CreateReduceMeanOp(Program& p, const std::shared_ptr& op) { CreateReduceOp(p, op, cldnn::reduce_mode::mean, op->get_keep_dims()); } -void CreateReduceMinOp(Program& p, const std::shared_ptr& op) { +static void CreateReduceMinOp(Program& p, const std::shared_ptr& op) { CreateReduceOp(p, op, cldnn::reduce_mode::min, op->get_keep_dims()); } -void CreateReduceProdOp(Program& p, const std::shared_ptr& op) { +static void CreateReduceProdOp(Program& p, const std::shared_ptr& op) { CreateReduceOp(p, op, cldnn::reduce_mode::prod, op->get_keep_dims()); } -void CreateReduceSumOp(Program& p, const std::shared_ptr& op) { +static void CreateReduceSumOp(Program& p, const std::shared_ptr& op) { CreateReduceOp(p, op, cldnn::reduce_mode::sum, op->get_keep_dims()); } -void CreateReduceL1Op(Program& p, const std::shared_ptr& op) { +static void CreateReduceL1Op(Program& p, const std::shared_ptr& op) { CreateReduceOp(p, op, cldnn::reduce_mode::l1, op->get_keep_dims()); } -void CreateReduceL2Op(Program& p, const std::shared_ptr& op) { +static void CreateReduceL2Op(Program& p, const std::shared_ptr& op) { CreateReduceOp(p, op, cldnn::reduce_mode::l2, op->get_keep_dims()); } diff --git a/inference-engine/src/cldnn_engine/ops/region_yolo.cpp b/inference-engine/src/cldnn_engine/ops/region_yolo.cpp index 314950027cb..f6bf4d9b282 100644 --- a/inference-engine/src/cldnn_engine/ops/region_yolo.cpp +++ b/inference-engine/src/cldnn_engine/ops/region_yolo.cpp @@ -11,7 +11,7 @@ namespace CLDNNPlugin { -void CreateRegionYoloOp(Program& p, const std::shared_ptr& op) { +static void CreateRegionYoloOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {1}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/reorg_yolo.cpp b/inference-engine/src/cldnn_engine/ops/reorg_yolo.cpp index 9c47ccc9fb0..45a8efc7d93 100644 --- a/inference-engine/src/cldnn_engine/ops/reorg_yolo.cpp +++ b/inference-engine/src/cldnn_engine/ops/reorg_yolo.cpp @@ -11,7 +11,7 @@ namespace CLDNNPlugin { -void CreateReorgYoloOp(Program& p, const std::shared_ptr& op) { +static void CreateReorgYoloOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {1}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/reshape.cpp b/inference-engine/src/cldnn_engine/ops/reshape.cpp index a4978fbae29..33cf81595c9 100644 --- a/inference-engine/src/cldnn_engine/ops/reshape.cpp +++ b/inference-engine/src/cldnn_engine/ops/reshape.cpp @@ -14,7 +14,7 @@ namespace CLDNNPlugin { -void CreateCommonReshapeOp(Program& p, const std::shared_ptr& op) { +static void CreateCommonReshapeOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {1, 2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); @@ -58,15 +58,15 @@ void CreateCommonReshapeOp(Program& p, const std::shared_ptr& op) p.AddPrimitiveToProfiler(op); } -void CreateReshapeOp(Program& p, const std::shared_ptr& op) { +static void CreateReshapeOp(Program& p, const std::shared_ptr& op) { CreateCommonReshapeOp(p, op); } -void CreateSqueezeOp(Program& p, const std::shared_ptr& op) { +static void CreateSqueezeOp(Program& p, const std::shared_ptr& op) { CreateCommonReshapeOp(p, op); } -void CreateUnsqueezeOp(Program& p, const std::shared_ptr& op) { +static void CreateUnsqueezeOp(Program& p, const std::shared_ptr& op) { CreateCommonReshapeOp(p, op); } diff --git a/inference-engine/src/cldnn_engine/ops/result.cpp b/inference-engine/src/cldnn_engine/ops/result.cpp index c1219ad8fba..cfc6331ef23 100644 --- a/inference-engine/src/cldnn_engine/ops/result.cpp +++ b/inference-engine/src/cldnn_engine/ops/result.cpp @@ -13,7 +13,7 @@ using namespace InferenceEngine; namespace CLDNNPlugin { -void CreateResultOp(Program& p, const std::shared_ptr& op) { +static void CreateResultOp(Program& p, const std::shared_ptr& op) { OutputsDataMap networkOutputs = p.GetNetworkOutputs(); p.ValidateInputs(op, {1}); diff --git a/inference-engine/src/cldnn_engine/ops/reverse_sequence.cpp b/inference-engine/src/cldnn_engine/ops/reverse_sequence.cpp index 6421a01dc75..2e33cd9123c 100644 --- a/inference-engine/src/cldnn_engine/ops/reverse_sequence.cpp +++ b/inference-engine/src/cldnn_engine/ops/reverse_sequence.cpp @@ -11,7 +11,7 @@ namespace CLDNNPlugin { -void CreateReverseSequenceOp(Program& p, const std::shared_ptr& op) { +static void CreateReverseSequenceOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/rnn.cpp b/inference-engine/src/cldnn_engine/ops/rnn.cpp index 1ebaa0a7868..5412bc4d221 100644 --- a/inference-engine/src/cldnn_engine/ops/rnn.cpp +++ b/inference-engine/src/cldnn_engine/ops/rnn.cpp @@ -16,7 +16,7 @@ #include "cldnn/primitives/concatenation.hpp" namespace CLDNNPlugin { -cldnn::activation_func GetActivationFunc(std::string name) { +static cldnn::activation_func GetActivationFunc(std::string name) { static const std::map name_mapping = { {"sigmoid", cldnn::activation_func::logistic}, {"tanh", cldnn::activation_func::hyperbolic_tan}, @@ -61,7 +61,7 @@ void GetLSTMActivationParams(const std::shared_ptr& op, } } -void CreateLSTMCellOp(Program& p, const std::shared_ptr& op) { +static void CreateLSTMCellOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {6}); int lstm_batch_size, lstm_input_size, lstm_hidden_size; bool hasBias = true; @@ -199,7 +199,7 @@ void CreateLSTMCellOp(Program& p, const std::shared_ptr& op) { +static void CreateLSTMSequenceOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {7}); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/roi_pooling.cpp b/inference-engine/src/cldnn_engine/ops/roi_pooling.cpp index 5de1a56019c..204de83727a 100644 --- a/inference-engine/src/cldnn_engine/ops/roi_pooling.cpp +++ b/inference-engine/src/cldnn_engine/ops/roi_pooling.cpp @@ -24,7 +24,7 @@ static cldnn::pooling_mode GetPoolingMode(std::string method) { return cldnn::pooling_mode::deformable_bilinear; } -void CreateDeformablePSROIPoolingOp(Program& p, const std::shared_ptr& op) { +static void CreateDeformablePSROIPoolingOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2, 3}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); @@ -63,7 +63,7 @@ void CreateDeformablePSROIPoolingOp(Program& p, const std::shared_ptr& op) { +static void CreatePSROIPoolingOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); @@ -92,7 +92,7 @@ void CreatePSROIPoolingOp(Program& p, const std::shared_ptr& op) { +static void CreateROIPoolingOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/scatter_elements_update.cpp b/inference-engine/src/cldnn_engine/ops/scatter_elements_update.cpp index 487587a2afa..6e8a93d9f2b 100644 --- a/inference-engine/src/cldnn_engine/ops/scatter_elements_update.cpp +++ b/inference-engine/src/cldnn_engine/ops/scatter_elements_update.cpp @@ -41,7 +41,7 @@ static inline cldnn::scatter_elements_update::scatter_elements_update_axis GetSc return cldnn::scatter_elements_update::scatter_elements_update_axis::along_f; // shouldn't get here } -void CreateScatterElementsUpdateOp(Program& p, const std::shared_ptr& op) { +static void CreateScatterElementsUpdateOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {4}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/scatter_nd_update.cpp b/inference-engine/src/cldnn_engine/ops/scatter_nd_update.cpp index 525cccfc32e..b57a2090f6d 100644 --- a/inference-engine/src/cldnn_engine/ops/scatter_nd_update.cpp +++ b/inference-engine/src/cldnn_engine/ops/scatter_nd_update.cpp @@ -12,7 +12,7 @@ namespace CLDNNPlugin { -void CreateScatterNDUpdateOp(Program& p, const std::shared_ptr& op) { +static void CreateScatterNDUpdateOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {3}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/scatter_update.cpp b/inference-engine/src/cldnn_engine/ops/scatter_update.cpp index 913ed452b5f..5769536e08f 100644 --- a/inference-engine/src/cldnn_engine/ops/scatter_update.cpp +++ b/inference-engine/src/cldnn_engine/ops/scatter_update.cpp @@ -41,7 +41,7 @@ static inline cldnn::scatter_update::scatter_update_axis GetScatterUpdateAxis(in return cldnn::scatter_update::scatter_update_axis::along_f; // shouldn't get here } -void CreateScatterUpdateOp(Program& p, const std::shared_ptr& op) { +static void CreateScatterUpdateOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {4}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/select.cpp b/inference-engine/src/cldnn_engine/ops/select.cpp index b47a04b5e56..7d55ef49862 100644 --- a/inference-engine/src/cldnn_engine/ops/select.cpp +++ b/inference-engine/src/cldnn_engine/ops/select.cpp @@ -13,7 +13,7 @@ namespace CLDNNPlugin { -void CreateSelectOp(Program& p, const std::shared_ptr& op) { +static void CreateSelectOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {3}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/shuffle_channels.cpp b/inference-engine/src/cldnn_engine/ops/shuffle_channels.cpp index 42976ffbc37..2ac540a5e3a 100644 --- a/inference-engine/src/cldnn_engine/ops/shuffle_channels.cpp +++ b/inference-engine/src/cldnn_engine/ops/shuffle_channels.cpp @@ -11,7 +11,7 @@ namespace CLDNNPlugin { -void CreateShuffleChannelsOp(Program& p, const std::shared_ptr& op) { +static void CreateShuffleChannelsOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {1, 2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/softmax.cpp b/inference-engine/src/cldnn_engine/ops/softmax.cpp index c8049e5800e..b9fe1ef89f7 100644 --- a/inference-engine/src/cldnn_engine/ops/softmax.cpp +++ b/inference-engine/src/cldnn_engine/ops/softmax.cpp @@ -35,7 +35,7 @@ static cldnn::softmax::dimension_t GetSoftmaxAxis(int64_t axis, size_t rank) { return cldnn::softmax::normalize_fyx; } -void CreateSoftmaxOp(Program& p, const std::shared_ptr& op) { +static void CreateSoftmaxOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {1}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); @@ -47,7 +47,7 @@ void CreateSoftmaxOp(Program& p, const std::shared_ptr& p.AddPrimitiveToProfiler(op); } -void CreateLogSoftmaxOp(Program& p, const std::shared_ptr& op) { +static void CreateLogSoftmaxOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {1}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/space_to_batch.cpp b/inference-engine/src/cldnn_engine/ops/space_to_batch.cpp index 2f51da29776..7471f3e2327 100644 --- a/inference-engine/src/cldnn_engine/ops/space_to_batch.cpp +++ b/inference-engine/src/cldnn_engine/ops/space_to_batch.cpp @@ -12,7 +12,7 @@ namespace CLDNNPlugin { -void CreateSpaceToBatchOp(Program& p, const std::shared_ptr& op) { +static void CreateSpaceToBatchOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {4}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/space_to_depth.cpp b/inference-engine/src/cldnn_engine/ops/space_to_depth.cpp index ccdb4f6bd39..8aa81351006 100644 --- a/inference-engine/src/cldnn_engine/ops/space_to_depth.cpp +++ b/inference-engine/src/cldnn_engine/ops/space_to_depth.cpp @@ -20,7 +20,7 @@ static cldnn::space_to_depth::depth_mode GetDepthMode(ngraph::op::v0::SpaceToDep return cldnn::space_to_depth::blocks_first; } -void CreateSpaceToDepthOp(Program& p, const std::shared_ptr& op) { +static void CreateSpaceToDepthOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {1}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/split.cpp b/inference-engine/src/cldnn_engine/ops/split.cpp index 247739c274a..33d3e8084e9 100644 --- a/inference-engine/src/cldnn_engine/ops/split.cpp +++ b/inference-engine/src/cldnn_engine/ops/split.cpp @@ -12,7 +12,7 @@ namespace CLDNNPlugin { -void CreateCommonSplitOp(Program& p, const std::shared_ptr& op) { +static void CreateCommonSplitOp(Program& p, const std::shared_ptr& op) { auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); @@ -58,12 +58,12 @@ void CreateCommonSplitOp(Program& p, const std::shared_ptr& op) { p.InitProfileInfo(op->get_friendly_name(), op->get_type_name(), false, InferenceEngine::InferenceEngineProfileInfo::OPTIMIZED_OUT); } -void CreateSplitOp(Program& p, const std::shared_ptr& op) { +static void CreateSplitOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); CreateCommonSplitOp(p, op); } -void CreateVariadicSplitOp(Program& p, const std::shared_ptr& op) { +static void CreateVariadicSplitOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {3}); CreateCommonSplitOp(p, op); } diff --git a/inference-engine/src/cldnn_engine/ops/strided_slice.cpp b/inference-engine/src/cldnn_engine/ops/strided_slice.cpp index 695612b073f..98b7169bf6e 100644 --- a/inference-engine/src/cldnn_engine/ops/strided_slice.cpp +++ b/inference-engine/src/cldnn_engine/ops/strided_slice.cpp @@ -14,7 +14,7 @@ namespace CLDNNPlugin { -void CreateStridedSliceOp(Program& p, const std::shared_ptr& op) { +static void CreateStridedSliceOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {4}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/tensor_iterator.cpp b/inference-engine/src/cldnn_engine/ops/tensor_iterator.cpp index 53fb5939ccb..5e3240d35a8 100644 --- a/inference-engine/src/cldnn_engine/ops/tensor_iterator.cpp +++ b/inference-engine/src/cldnn_engine/ops/tensor_iterator.cpp @@ -55,7 +55,7 @@ static void UpdateBackedge(std::vector& back_edge } } -void CreateTensorIteratorOp(Program &p, const std::shared_ptr &op) { +static void CreateTensorIteratorOp(Program &p, const std::shared_ptr &op) { auto inputPrimitives = p.GetInputPrimitiveIDs(op); // get body topology from ngraph function diff --git a/inference-engine/src/cldnn_engine/ops/tile.cpp b/inference-engine/src/cldnn_engine/ops/tile.cpp index 4d35ff0c647..e4450effd8d 100644 --- a/inference-engine/src/cldnn_engine/ops/tile.cpp +++ b/inference-engine/src/cldnn_engine/ops/tile.cpp @@ -11,7 +11,7 @@ namespace CLDNNPlugin { -void CreateTileOp(Program& p, const std::shared_ptr& op) { +static void CreateTileOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/topk.cpp b/inference-engine/src/cldnn_engine/ops/topk.cpp index fe9ae95550b..27c44b154fd 100644 --- a/inference-engine/src/cldnn_engine/ops/topk.cpp +++ b/inference-engine/src/cldnn_engine/ops/topk.cpp @@ -40,7 +40,7 @@ static cldnn::arg_max_min::axis_name GetAxis(int32_t axis, size_t in_rank) { return cldnn::arg_max_min::axis_name::batch; } -void CreateTopKOp(Program& p, const std::shared_ptr& op) { +static void CreateTopKOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/transpose.cpp b/inference-engine/src/cldnn_engine/ops/transpose.cpp index c2bf2e943d3..cff6d3e032c 100644 --- a/inference-engine/src/cldnn_engine/ops/transpose.cpp +++ b/inference-engine/src/cldnn_engine/ops/transpose.cpp @@ -12,7 +12,7 @@ namespace CLDNNPlugin { -void CreateTransposeOp(Program& p, const std::shared_ptr& op) { +static void CreateTransposeOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {1, 2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); diff --git a/inference-engine/src/cldnn_engine/ops/unary.cpp b/inference-engine/src/cldnn_engine/ops/unary.cpp index ecab7600ade..5c681aaf1df 100644 --- a/inference-engine/src/cldnn_engine/ops/unary.cpp +++ b/inference-engine/src/cldnn_engine/ops/unary.cpp @@ -54,24 +54,24 @@ void CreateUnaryEltwiseOp(Program& p, const std::shared_ptr& op, p.AddPrimitiveToProfiler(op); } -void CreateTanhOp(Program& p, const std::shared_ptr& op) { +static void CreateTanhOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::hyperbolic_tan, {}); } -void CreateEluOp(Program& p, const std::shared_ptr& op) { +static void CreateEluOp(Program& p, const std::shared_ptr& op) { auto alpha = static_cast(op->get_alpha()); CreateUnaryEltwiseOp(p, op, cldnn::activation_func::elu, {alpha}); } -void CreateSigmoidOp(Program& p, const std::shared_ptr& op) { +static void CreateSigmoidOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::logistic, {}); } -void CreateReluOp(Program& p, const std::shared_ptr& op) { +static void CreateReluOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::relu, {}); } -void CreatePReluOp(Program& p, const std::shared_ptr& op) { +static void CreatePReluOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto slope_node = std::dynamic_pointer_cast(op->get_input_node_shared_ptr(1)); @@ -96,65 +96,65 @@ void CreatePReluOp(Program& p, const std::shared_ptr& op) } } -void CreateClampOp(Program& p, const std::shared_ptr& op) { +static void CreateClampOp(Program& p, const std::shared_ptr& op) { float min = static_cast(op->get_min()); float max = static_cast(op->get_max()); CreateUnaryEltwiseOp(p, op, cldnn::activation_func::clamp, {min, max}); } -void CreateExpOp(Program& p, const std::shared_ptr& op) { +static void CreateExpOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::exp, {}); } -void CreateLogicalNotOp(Program& p, const std::shared_ptr& op) { +static void CreateLogicalNotOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::negation, {}); } -void CreateAsinOp(Program& p, const std::shared_ptr& op) { +static void CreateAsinOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::asin, {}); } -void CreateAsinhOp(Program& p, const std::shared_ptr& op) { +static void CreateAsinhOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::asinh, {}); } -void CreateAcosOp(Program& p, const std::shared_ptr& op) { +static void CreateAcosOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::acos, {}); } -void CreateAcoshOp(Program& p, const std::shared_ptr& op) { +static void CreateAcoshOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::acosh, {}); } -void CreateAtanOp(Program& p, const std::shared_ptr& op) { +static void CreateAtanOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::atan, {}); } -void CreateAtanhOp(Program& p, const std::shared_ptr& op) { +static void CreateAtanhOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::atanh, {}); } -void CreateAbsOp(Program& p, const std::shared_ptr& op) { +static void CreateAbsOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::abs, {}); } -void CreateFloorOp(Program& p, const std::shared_ptr& op) { +static void CreateFloorOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::floor, {}); } -void CreateCeilingOp(Program& p, const std::shared_ptr& op) { +static void CreateCeilingOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::ceil, {}); } -void CreateSqrtOp(Program& p, const std::shared_ptr& op) { +static void CreateSqrtOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::sqrt, {}); } -void CreateErfOp(Program& p, const std::shared_ptr& op) { +static void CreateErfOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::erf, {}); } -void CreateHardSigmoidOp(Program& p, const std::shared_ptr& op) { +static void CreateHardSigmoidOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {3}); auto alpha_node = std::dynamic_pointer_cast(op->get_input_node_shared_ptr(1)); auto beta_node = std::dynamic_pointer_cast(op->get_input_node_shared_ptr(2)); @@ -172,15 +172,15 @@ void CreateHardSigmoidOp(Program& p, const std::shared_ptr& op) { +static void CreateLogOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::log, {}); } -void CreateNegativeOp(Program& p, const std::shared_ptr& op) { +static void CreateNegativeOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::negative, {}); } -void CreateSeluOp(Program& p, const std::shared_ptr& op) { +static void CreateSeluOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {3}); auto alpha_node = std::dynamic_pointer_cast(op->get_input_node_shared_ptr(1)); auto lambda_node = std::dynamic_pointer_cast(op->get_input_node_shared_ptr(2)); @@ -200,31 +200,31 @@ void CreateSeluOp(Program& p, const std::shared_ptr& op) { } } -void CreateSoftPlusOp(Program& p, const std::shared_ptr& op) { +static void CreateSoftPlusOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::softplus, {}); } -void CreateTanOp(Program& p, const std::shared_ptr& op) { +static void CreateTanOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::tan, {}); } -void CreateSinOp(Program& p, const std::shared_ptr& op) { +static void CreateSinOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::sin, {}); } -void CreateSinhOp(Program& p, const std::shared_ptr& op) { +static void CreateSinhOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::sinh, {}); } -void CreateCosOp(Program& p, const std::shared_ptr& op) { +static void CreateCosOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::cos, {}); } -void CreateCoshOp(Program& p, const std::shared_ptr& op) { +static void CreateCoshOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::cosh, {}); } -void CreateSwishOp(Program& p, const std::shared_ptr& op) { +static void CreateSwishOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {1, 2}); if (op->get_input_size() == 2) { auto beta_node = std::dynamic_pointer_cast(op->get_input_node_shared_ptr(1)); @@ -246,27 +246,27 @@ void CreateSwishOp(Program& p, const std::shared_ptr& op) } } -void CreateHSwishOp(Program& p, const std::shared_ptr& op) { +static void CreateHSwishOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::hswish, {}); } -void CreateMishOp(Program& p, const std::shared_ptr& op) { +static void CreateMishOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::mish, {}); } -void CreateGeluOp(Program& p, const std::shared_ptr& op) { +static void CreateGeluOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::gelu, {}); } -void CreateSignOp(Program& p, const std::shared_ptr& op) { +static void CreateSignOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::sign, {}); } -void CreateHSigmoidOp(Program& p, const std::shared_ptr& op) { +static void CreateHSigmoidOp(Program& p, const std::shared_ptr& op) { CreateUnaryEltwiseOp(p, op, cldnn::activation_func::hsigmoid, {}); } -void CreateRoundOp(Program& p, const std::shared_ptr& op) { +static void CreateRoundOp(Program& p, const std::shared_ptr& op) { auto func = cldnn::activation_func::none; switch (op->get_mode()) { case ngraph::op::v5::Round::RoundMode::HALF_TO_EVEN : func = cldnn::activation_func::round_half_to_even; break; diff --git a/inference-engine/src/gna_plugin/backend/make_pwl.cpp b/inference-engine/src/gna_plugin/backend/make_pwl.cpp index c4f98e88c2b..c171e6cc191 100644 --- a/inference-engine/src/gna_plugin/backend/make_pwl.cpp +++ b/inference-engine/src/gna_plugin/backend/make_pwl.cpp @@ -8,6 +8,7 @@ #include #include "runtime/pwl.h" +#include "make_pwl.hpp" #include "gna_slope_scale.h" #include "dnn_types.h" #include "backend/gna_types.h" diff --git a/inference-engine/src/gna_plugin/gna2_model_debug_log.cpp b/inference-engine/src/gna_plugin/gna2_model_debug_log.cpp index f7e81092304..9ba52cd9471 100644 --- a/inference-engine/src/gna_plugin/gna2_model_debug_log.cpp +++ b/inference-engine/src/gna_plugin/gna2_model_debug_log.cpp @@ -19,6 +19,8 @@ #include #include +namespace { + std::string GetLayerType(Gna2OperationType type) { switch (type) { case Gna2OperationTypeFullyConnectedAffine: return "Gna2OperationTypeFullyConnectedAffine"; @@ -92,6 +94,8 @@ int32_t GetValue(const Gna2Tensor& tensor, const T & elementIndex) { return intValue; } +} // namespace + void WriteInputAndOutputTextGNAImpl(const Gna2Model & gnaModel, const std::string dumpFolderNameGNA, const std::string refFolderName) { for (uint32_t i = 0; i < gnaModel.NumberOfOperations; i++) { const auto & operation = gnaModel.Operations[i]; @@ -161,6 +165,8 @@ void WriteInputAndOutputTextGNAImpl(const Gna2Model & gnaModel, const std::strin } } +namespace { + template static std::string GetName(T name, size_t index) { return name; @@ -172,7 +178,7 @@ std::string GetName<>(std::vector names, size_t index) { } template -static std::string FindInMapOrReturnUnknown(MapType map, typename MapType::key_type key, size_t index = 0) { +std::string FindInMapOrReturnUnknown(MapType map, typename MapType::key_type key, size_t index = 0) { auto value = map.find(key); if (value != map.end()) { return GetName(value->second, index); @@ -180,8 +186,8 @@ static std::string FindInMapOrReturnUnknown(MapType map, typename MapType::key_t return std::string {"unknown"}; } -static std::string GetOperandType(Gna2DataType type) { - const std::map operandTypeMap = { +std::string GetOperandType(Gna2DataType type) { + static const std::map operandTypeMap = { {Gna2DataTypeNone, "Gna2DataTypeNone"}, {Gna2DataTypeBoolean, "Gna2DataTypeBoolean"}, {Gna2DataTypeInt4, "Gna2DataTypeInt4"}, @@ -200,8 +206,8 @@ static std::string GetOperandType(Gna2DataType type) { return FindInMapOrReturnUnknown(operandTypeMap, type); } -static std::string GetOperandName(Gna2OperationType type, size_t index) { - const std::map> operationOperandNamesMap = { +std::string GetOperandName(Gna2OperationType type, size_t index) { + static const std::map> operationOperandNamesMap = { {Gna2OperationTypeConvolution, {"inputs", "outputs", "filters", "biases", "activationFunction"}}, {Gna2OperationTypeCopy, {"inputs", "outputs"}}, {Gna2OperationTypeFullyConnectedAffine, {"inputs", "outputs", "weights", "biases", "activationFunction", "weightScaleFactors"}}, @@ -213,8 +219,8 @@ static std::string GetOperandName(Gna2OperationType type, size_t index) { return FindInMapOrReturnUnknown(operationOperandNamesMap, type, index); } -static std::string GetBiasMode(Gna2BiasMode mode) { - const std::map biasModeMap = { +std::string GetBiasMode(Gna2BiasMode mode) { + static const std::map biasModeMap = { {Gna2BiasModeDefault, "Gna2BiasModeDefault"}, {Gna2BiasModePerStride, "Gna2BiasModePerStride"}, {Gna2BiasModeGrouping, "Gna2BiasModeGrouping"} @@ -222,8 +228,8 @@ static std::string GetBiasMode(Gna2BiasMode mode) { return FindInMapOrReturnUnknown(biasModeMap, mode); } -static std::string GetPoolingMode(Gna2PoolingMode mode) { - const std::map poolingModeMap = { +std::string GetPoolingMode(Gna2PoolingMode mode) { + static const std::map poolingModeMap = { {Gna2PoolingModeDisabled, "Gna2PoolingModeDisabled"}, {Gna2PoolingModeMax, "Gna2PoolingModeMax"}, {Gna2PoolingModeSum, "Gna2PoolingModeSum"} @@ -231,7 +237,7 @@ static std::string GetPoolingMode(Gna2PoolingMode mode) { return FindInMapOrReturnUnknown(poolingModeMap, mode); } -static void DumpShape(std::ostream& dumpFile, Gna2Shape* shape, const std::string paramName) { +void DumpShape(std::ostream& dumpFile, Gna2Shape* shape, const std::string paramName) { dumpFile << "\tParameter name: " << paramName << ", "; dumpFile << "parameter type: Gna2Shape\n"; dumpFile << "\t\tNumber of dimensions: " << shape->NumberOfDimensions; @@ -242,7 +248,7 @@ static void DumpShape(std::ostream& dumpFile, Gna2Shape* shape, const std::strin dumpFile << "]\n"; } -static void DumpConvolutionParameters(std::ostream& dumpFile, void** parameters, size_t knownParamCount, const std::vector paramNames) { +void DumpConvolutionParameters(std::ostream& dumpFile, void** parameters, size_t knownParamCount, const std::vector paramNames) { size_t i = 0; while (i < knownParamCount) { @@ -263,12 +269,12 @@ static void DumpConvolutionParameters(std::ostream& dumpFile, void** parameters, } } -static void DumpCopyParameters(std::ostream& dumpFile, void** parameters, size_t knownParamCount, const std::vector paramNames) { +void DumpCopyParameters(std::ostream& dumpFile, void** parameters, size_t knownParamCount, const std::vector paramNames) { Gna2Shape* subTensorShape = reinterpret_cast(parameters[CopyShapeParamIdx]); DumpShape(dumpFile, subTensorShape, paramNames[CopyShapeParamIdx]); } -static void DumpFCAffineParameters(std::ostream& dumpFile, void** parameters, size_t knownParamCount, const std::vector paramNames) { +void DumpFCAffineParameters(std::ostream& dumpFile, void** parameters, size_t knownParamCount, const std::vector paramNames) { size_t i = 0; while (i < knownParamCount) { @@ -285,13 +291,13 @@ static void DumpFCAffineParameters(std::ostream& dumpFile, void** parameters, si } } -static void DumpIntParameter(std::ostream& dumpFile, void** parameters, size_t knownParamCount, const std::vector paramNames) { +void DumpIntParameter(std::ostream& dumpFile, void** parameters, size_t knownParamCount, const std::vector paramNames) { uint32_t* param = reinterpret_cast(parameters[0]); if (param != nullptr) dumpFile << "\tParameter name: " << paramNames[0] << ", value: " << *param << "\n"; } -static std::vector GetParamaterNames(Gna2OperationType type) { +std::vector GetParamaterNames(Gna2OperationType type) { // This map must be aligned with dumpParamMap in this file const std::map> operationParamaterNamesMap = { {Gna2OperationTypeConvolution, {"convolutionStride", "biasMode", "poolingMode", "poolingWindow", "poolingStride", "zeroPadding"}}, @@ -306,7 +312,7 @@ static std::vector GetParamaterNames(Gna2OperationType type) { typedef void (*dumpParameters) (std::ostream&, void**, size_t, const std::vector); -static dumpParameters GetParamDumpFunc(Gna2OperationType type) { +dumpParameters GetParamDumpFunc(Gna2OperationType type) { // This map must be aligned with operationParamaterNamesMap in this file static const std::map dumpParamMap = { {Gna2OperationTypeConvolution, DumpConvolutionParameters}, @@ -318,7 +324,7 @@ static dumpParameters GetParamDumpFunc(Gna2OperationType type) { return dumpParamMap.find(type) != dumpParamMap.end() ? dumpParamMap.find(type)->second : nullptr; } -static void DumpPwl(std::ostream& dumpFile, const Gna2Tensor& activation) { +void DumpPwl(std::ostream& dumpFile, const Gna2Tensor& activation) { const Gna2PwlSegment* const segments = static_cast(activation.Data); const uint32_t numberOfSegments = activation.Shape.Dimensions[0]; @@ -342,7 +348,7 @@ static void DumpPwl(std::ostream& dumpFile, const Gna2Tensor& activation) { } } -static void DumpCompoundBias(std::ostream& dumpFile, const Gna2Tensor& tensor) { +void DumpCompoundBias(std::ostream& dumpFile, const Gna2Tensor& tensor) { auto i = 0; while (i < tensor.Shape.Dimensions[0]) { @@ -352,7 +358,7 @@ static void DumpCompoundBias(std::ostream& dumpFile, const Gna2Tensor& tensor) { } } -static void DumpCharArray(std::ostream& dumpFile, const char *carray, size_t count) { +void DumpCharArray(std::ostream& dumpFile, const char *carray, size_t count) { auto i = 0; while (*(carray + i) != 0 && i < count) { dumpFile << *(carray + i) << " "; @@ -361,6 +367,8 @@ static void DumpCharArray(std::ostream& dumpFile, const char *carray, size_t co dumpFile << "\n"; } +} // namespace + void DumpGna2Model(const Gna2Model& gnaModel, const std::string dumpFolderNameGNA, bool dumpData) { std::stringstream dumpFileName; uint32_t opsNo = gnaModel.NumberOfOperations; diff --git a/inference-engine/src/gna_plugin/gna2_model_helper.cpp b/inference-engine/src/gna_plugin/gna2_model_helper.cpp index 3775ac6748c..a2c25b8c5ca 100644 --- a/inference-engine/src/gna_plugin/gna2_model_helper.cpp +++ b/inference-engine/src/gna_plugin/gna2_model_helper.cpp @@ -59,6 +59,8 @@ Gna2Tensor HelperGna2TensorInit3D(uint32_t x, uint32_t y, uint32_t z, Gna2DataTy return t; } +namespace { + Gna2DataType FromOvDataType(OvGnaType t) { static const std::map< OvGnaType, Gna2DataType> m = { {OvGnaTypeInt8, Gna2DataTypeInt8}, @@ -85,6 +87,8 @@ Gna2Tensor HelperGna2TensorInit(OvGnaTensor tensor, void* data) { return t; } +} // namespace + Gna2Tensor * createGna2Tensor1D(uint32_t x, uint32_t byteSize, void* data) { const auto input = reinterpret_cast(gnaUserAllocator(sizeof(Gna2Tensor))); IE_ASSERT(input != nullptr); diff --git a/inference-engine/src/gna_plugin/gna_device.cpp b/inference-engine/src/gna_plugin/gna_device.cpp index d57a4a5cc9c..f7c400e01d9 100644 --- a/inference-engine/src/gna_plugin/gna_device.cpp +++ b/inference-engine/src/gna_plugin/gna_device.cpp @@ -117,7 +117,7 @@ uint32_t GNADeviceHelper::propagate(const uint32_t requestConfigId, Gna2Accelera return reqId; } -void enforceLegacyCnn(Gna2Operation& operation) { +inline void enforceLegacyCnn(Gna2Operation& operation) { snprintf( const_cast(operation.Operands[1]->Layout), sizeof(operation.Operands[1]->Layout) / sizeof(char), diff --git a/inference-engine/src/gna_plugin/gna_graph_compiler.cpp b/inference-engine/src/gna_plugin/gna_graph_compiler.cpp index 9421e5ddecc..6f8b455e9b8 100644 --- a/inference-engine/src/gna_plugin/gna_graph_compiler.cpp +++ b/inference-engine/src/gna_plugin/gna_graph_compiler.cpp @@ -2101,7 +2101,7 @@ void GNAGraphCompiler::PermutePrimitive(InferenceEngine::CNNLayerPtr layer) { connectOutput(layer, ptr_outputs, num_data_bytes_out); } -void SKIP(GNAGraphCompiler*, CNNLayerPtr) {} +inline void SKIP(GNAGraphCompiler*, CNNLayerPtr) {} void GNAGraphCompiler::CreateLayerPrimitive(CNNLayerPtr layer) { static const LayersBuilder layersBuilder[] = { diff --git a/inference-engine/src/gna_plugin/gna_helper.cpp b/inference-engine/src/gna_plugin/gna_helper.cpp deleted file mode 100644 index acd22bb8450..00000000000 --- a/inference-engine/src/gna_plugin/gna_helper.cpp +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -// gna_helper.cpp : various GNA-related utility functions -// - -#include -#include -#include -#include -#include -#include -#include "backend/gna_types.h" -#include "gna_plugin_log.hpp" - -#include "gna_lib_ver_selector.hpp" - - -void PrintMatrixInt16(const char *ptr_name, int16_t *ptr_matrix, int num_rows, int num_cols, int lda, float scale) { - printf("%s: %dx%d lda %d\n", ptr_name, num_rows, num_cols, lda); - for (int i = 0; i < num_rows; i++) { - for (int j = 0; j < num_cols; j++) { - printf("[%d,%d]: %e\n", i, j, *(ptr_matrix + i*lda + j) / scale); - } - } -} - -void PrintMatrixInt32(char *ptr_name, int32_t *ptr_matrix, int num_rows, int num_cols, int lda, float scale) { - printf("%s: %dx%d lda %d\n", ptr_name, num_rows, num_cols, lda); - for (int i = 0; i < num_rows; i++) { - for (int j = 0; j < num_cols; j++) { - printf("[%d,%d]: %e\n", i, j, *(ptr_matrix + i*lda + j) / scale); - } - } -} - -void PrintMatrixFloat32(char *ptr_name, float *ptr_matrix, int num_rows, int num_cols, int lda) { -#if (defined _WIN32 || defined _WIN64) && (_MSC_VER < 1900) - _set_output_format(_TWO_DIGIT_EXPONENT); -#endif - printf("%s: %dx%d lda %d\n", ptr_name, num_rows, num_cols, lda); - for (int i = 0; i < num_rows; i++) { - for (int j = 0; j < num_cols; j++) { - printf("[%d,%d]: %e\n", i, j, *(ptr_matrix + i*lda + j)); - } - } -} - - -typedef struct { - std::string sName; - std::string sType; // if wgt/bias/filt/pwl is writeable, then do not write it to file - void *pAddress; - uint32_t nBytes; -} intel_memory_region_t; - -void AddBufferEntry(std::vector &vBuffer, - const std::string &sName, - const std::string &sType, - void *pBuffer, - uint32_t nBytes) { - if (pBuffer != NULL) { - intel_memory_region_t region; - region.sName = sName; - region.sType = sType; - region.pAddress = pBuffer; - region.nBytes = nBytes; - vBuffer.push_back(region); - } -} - -std::string BufferNameFromAddress(std::vector &vBuffer, void *pBuffer) { - std::stringstream ss; - std::string sAddr, sName; - void *pParentBuffer = pBuffer; - bool found = false; - bool found_persistent = false; - bool found_output = false; - for (uint32_t i = 0; i < vBuffer.size(); i++) { - uint8_t *pBufferStart = reinterpret_cast(pBuffer); - uint8_t *pEntryBufferStart = reinterpret_cast(vBuffer.at(i).pAddress); - uint8_t *pEntryBufferEnd = reinterpret_cast(vBuffer.at(i).pAddress) + vBuffer.at(i).nBytes; - if ((pBufferStart >= pEntryBufferStart) && (pBufferStart < pEntryBufferEnd)) { - found = true; - if (pBufferStart > pEntryBufferStart) { - pParentBuffer = pEntryBufferStart; - } - if ((vBuffer.at(i).sType.compare("pOutputs") == 0) - || (vBuffer.at(i).sType.compare("pOutputsIntermediate") == 0)) { - found_output = true; - } else if (vBuffer.at(i).sType.compare("pWeights") == 0) { - sName = "wgt_"; - found_persistent = true; - } else if (vBuffer.at(i).sType.compare("pBiases") == 0) { - sName = "bias_"; - found_persistent = true; - } else if (vBuffer.at(i).sType.compare("pSegments") == 0) { - sName = "pwl_"; - found_persistent = true; - } - } - } - if (found) { - if ((found_output) || (!found_persistent)) { - sName = "buf_"; - } - ss << (int64_t) pParentBuffer; - sAddr = ss.str(); - sName.append(sAddr); - } else { - fprintf(stderr, "Error: buffer address does not exist in BufferNameFromAddress!\n"); - exit(EXIT_FAILURE); - } - return (sName); -} - -uint32_t BufferOffsetFromAddress(std::vector &vBuffer, void *pBuffer) { - uint32_t nOffsetBytes = 0; - for (uint32_t i = 0; i < vBuffer.size(); i++) { - uint8_t *pBufferStart = reinterpret_cast(pBuffer); - uint8_t *pEntryBufferStart = reinterpret_cast(vBuffer.at(i).pAddress); - uint8_t *pEntryBufferEnd = reinterpret_cast(vBuffer.at(i).pAddress) + vBuffer.at(i).nBytes; - if ((pBufferStart >= pEntryBufferStart) && (pBufferStart < pEntryBufferEnd)) { - if (pBufferStart > pEntryBufferStart) { - nOffsetBytes = (uint32_t) (pBufferStart - pEntryBufferStart); - } - } - } - return (nOffsetBytes); -} - -std::string LayerName(gna_nnet_layer_t *pLayer) { - const auto nKind = pLayer->nLayerKind; - std::string sKind; - if (nKind == INTEL_AFFINE) { - sKind = "affine"; - } else if (nKind == INTEL_AFFINE_DIAGONAL) { - sKind = "diagonal"; - } else if (nKind == INTEL_INTERLEAVE) { - sKind = "interleave"; - } else if (nKind == INTEL_DEINTERLEAVE) { - sKind = "deinterleave"; - } else { - fprintf(stderr, "Error: nLayerKind not supported in LayerName()!\n"); - exit(EXIT_FAILURE); - } - return (sKind); -} - -uint32_t NumInputs(gna_nnet_layer_t *pLayer) { - const auto nKind = pLayer->nLayerKind; - uint32_t nInputs; - if ((nKind == INTEL_AFFINE) || (nKind == INTEL_AFFINE_DIAGONAL)) { - nInputs = pLayer->nInputRows; - } else if (nKind == INTEL_INTERLEAVE) { - nInputs = pLayer->nInputColumns; - } else if (nKind == INTEL_DEINTERLEAVE) { - nInputs = pLayer->nInputRows; - } else { - fprintf(stderr, "Error: nLayerKind not supported in NumInputs()!\n"); - exit(EXIT_FAILURE); - } - return (nInputs); -} - -uint32_t NumOutputs(gna_nnet_layer_t *pLayer) { - const auto nKind = pLayer->nLayerKind; - uint32_t nOutputs; - if ((nKind == INTEL_AFFINE) || (nKind == INTEL_AFFINE_DIAGONAL)) { - nOutputs = pLayer->nOutputRows; - } else if (nKind == INTEL_INTERLEAVE) { - nOutputs = pLayer->nOutputRows; - } else if (nKind == INTEL_DEINTERLEAVE) { - nOutputs = pLayer->nOutputColumns; - } else { - fprintf(stderr, "Error: nLayerKind not supported in NumInputs()!\n"); - exit(EXIT_FAILURE); - } - return (nOutputs); -} - -uint32_t NumGroupSize(gna_nnet_layer_t *pLayer) { - const auto nKind = pLayer->nLayerKind; - uint32_t nGroupSize; - if ((nKind == INTEL_AFFINE) || (nKind == INTEL_AFFINE_DIAGONAL)) { - nGroupSize = pLayer->nOutputColumns; - } else if (nKind == INTEL_INTERLEAVE) { - nGroupSize = pLayer->nOutputColumns; - } else if (nKind == INTEL_DEINTERLEAVE) { - nGroupSize = pLayer->nOutputRows; - } else { - fprintf(stderr, "Error: nLayerKind not supported in NumGroupSize()!\n"); - exit(EXIT_FAILURE); - } - return (nGroupSize); -} diff --git a/inference-engine/src/gna_plugin/gna_model_serial.cpp b/inference-engine/src/gna_plugin/gna_model_serial.cpp index 388a3c9d82b..62b37fdd991 100644 --- a/inference-engine/src/gna_plugin/gna_model_serial.cpp +++ b/inference-engine/src/gna_plugin/gna_model_serial.cpp @@ -69,7 +69,7 @@ union { uint8_t c[2]; } constexpr static LECheck {1}; -bool is_little_endian() { +inline bool is_little_endian() { return LECheck.c[0] == 1; } @@ -195,7 +195,7 @@ getOffsetFromBase(field, #field) #if GNA_LIB_VER == 2 -bool IsEmptyTensor(const Gna2Tensor& t) { +inline bool IsEmptyTensor(const Gna2Tensor& t) { return t.Type == Gna2DataTypeNone && t.Data == nullptr && t.Layout[0] == '\0' && @@ -203,7 +203,7 @@ bool IsEmptyTensor(const Gna2Tensor& t) { t.Shape.NumberOfDimensions == 0; } -const std::map> GnaParamSize{ +static const std::map> GnaParamSize{ {Gna2OperationTypeFullyConnectedAffine, {sizeof(Gna2BiasMode), sizeof(uint32_t)}}, {Gna2OperationTypeConvolution, { sizeof(Gna2Shape), diff --git a/inference-engine/src/gna_plugin/gna_plugin.cpp b/inference-engine/src/gna_plugin/gna_plugin.cpp index 21d4b326292..91e22b6ace6 100644 --- a/inference-engine/src/gna_plugin/gna_plugin.cpp +++ b/inference-engine/src/gna_plugin/gna_plugin.cpp @@ -77,7 +77,7 @@ #if GNA_LIB_VER == 2 #include -uint32_t ToByteSize(const Gna2DataType type) { +inline uint32_t ToByteSize(const Gna2DataType type) { switch (type) { case Gna2DataTypeInt8: case Gna2DataTypeUint8: diff --git a/inference-engine/src/gna_plugin/runtime/cnn.cpp b/inference-engine/src/gna_plugin/runtime/cnn.cpp index 2e0071040f9..78e04c3e5eb 100644 --- a/inference-engine/src/gna_plugin/runtime/cnn.cpp +++ b/inference-engine/src/gna_plugin/runtime/cnn.cpp @@ -48,6 +48,8 @@ void CNNFilter32(intel_dnn_component_t *component) { } } +namespace { + void CNNMaxPoolLegacy(intel_dnn_component_t *component, intel_dnn_number_type_t number_type, const bool sumPoolingOverRide) { const uint32_t num_inputs = component->op.maxpool.inCHW[0] * component->op.maxpool.inCHW[1] * component->op.maxpool.inCHW[2]; const uint32_t in_c = component->op.maxpool.inCHW[0]; @@ -128,14 +130,12 @@ void CNNMaxPoolLegacy(intel_dnn_component_t *component, intel_dnn_number_type_t } } -namespace { // a1: fastest changing index // A - size neede template T getQubeIndex(T a1, T a2, T a3, T A2, T A3) { return a1 * A2 * A3 + a2 * A3 + a3; } -} // namespace float MaxPool2D32SingleHWC(const unsigned poolWinH, const unsigned poolWinW, const float* input, const unsigned IH, const unsigned IW, const unsigned IC, @@ -184,8 +184,12 @@ void CNNMaxPool2DFloat(intel_dnn_component_t* component) { } } +} // namespace + #if GNA_LIB_VER == 2 +namespace { + bool matchesPaddedArea(unsigned filterIndex, unsigned outputIndex, unsigned inputSize, unsigned paddingSize, unsigned stride) { const auto paddedIndex = stride * outputIndex + filterIndex; if (paddedIndex >= inputSize + 2 * paddingSize) { @@ -231,6 +235,8 @@ float CNN2DFilter32SingleHWC(const float bias, const float* filter, const unsign return output; } +} // namespace + void CNN2DFilter32(intel_dnn_component_t* component) { float* ptr_filters = reinterpret_cast(component->op.conv2D.ptr_filters); float* ptr_biases = reinterpret_cast(component->op.conv2D.ptr_biases); diff --git a/inference-engine/src/gna_plugin/runtime/pwl.cpp b/inference-engine/src/gna_plugin/runtime/pwl.cpp index f60b3a2d7d1..d214f06413b 100644 --- a/inference-engine/src/gna_plugin/runtime/pwl.cpp +++ b/inference-engine/src/gna_plugin/runtime/pwl.cpp @@ -30,12 +30,12 @@ #include "round_float_define.hpp" double first_deriv_tanh(const double x) { return(1.0 - tanh(x) * tanh(x)); } -double first_deriv_exp(const double x) { return(exp(x)); } -double first_deriv_log(const double x) { return(1.0 / x); } -double neglog(const double x) { return(-1.0*log(x)); } -double neghalflog(const double x) { return(-0.5*log(x)); } -double first_deriv_neglog(const double x) { return(-1.0 / x); } -double first_deriv_neghalflog(const double x) { return(-0.5 / x); } +inline double first_deriv_exp(const double x) { return(exp(x)); } +inline double first_deriv_log(const double x) { return(1.0 / x); } +inline double neglog(const double x) { return(-1.0*log(x)); } +inline double neghalflog(const double x) { return(-0.5*log(x)); } +inline double first_deriv_neglog(const double x) { return(-1.0 / x); } +inline double first_deriv_neghalflog(const double x) { return(-0.5 / x); } double sigmoid(const double x) { return(0.5 * (1.0 + tanh(x / 2))); } double first_deriv_sigmoid(const double x) { return(sigmoid(x) * (1.0 - sigmoid(x))); } double softsign(const double x) { return(x / (1.0 + fabs(x))); } @@ -44,12 +44,12 @@ double relu(const double x) { if (x < 0) { return(0.0); } else { return(x); } } double leaky_relu(const double x) { if (x < 0.0) { return(LEAKYRELU_SLOPE*x); } else { return(x); } } double clipping(const double x, const double lbound, const double ubound) { return((x < lbound)?lbound:((x > ubound)?ubound:x)); } -double first_deriv_power(const double x, const std::tuple& args) { +inline double first_deriv_power(const double x, const std::tuple& args) { //scale * exponent * (offset + scale * x)^(exponent - 1) return (std::get<1>(args) * std::get<0>(args) * pow(std::get<2>(args) + std::get<1>(args) * x, std::get<0>(args) - 1)); } -double power(const double x, const std::tuple& args) { +inline double power(const double x, const std::tuple& args) { return (pow(std::get<2>(args) + std::get<1>(args) * x, std::get<0>(args))); } @@ -272,7 +272,7 @@ double calculate_error_pct(const DnnActivation& activation_type, return(100.0 * fabs(offset) / (max_val - min_val)); } -double get_break_bound(const DnnActivation& activation_type) { +inline double get_break_bound(const DnnActivation& activation_type) { double break_bound = 0.0; switch (activation_type) { case kActExp: @@ -287,7 +287,7 @@ double get_break_bound(const DnnActivation& activation_type) { return break_bound; } -bool split_search(const DnnActivation& activation_type, +inline bool split_search(const DnnActivation& activation_type, const double l_bound, const double u_bound) { bool is_split = false; diff --git a/inference-engine/src/gna_plugin/transformations/handle_transposes_around_matmul.cpp b/inference-engine/src/gna_plugin/transformations/handle_transposes_around_matmul.cpp index 24dc28efe1a..3d40dec4a30 100644 --- a/inference-engine/src/gna_plugin/transformations/handle_transposes_around_matmul.cpp +++ b/inference-engine/src/gna_plugin/transformations/handle_transposes_around_matmul.cpp @@ -22,6 +22,8 @@ NGRAPH_RTTI_DEFINITION(HandleTransposesAroundMatMul, "HandleTransposesAroundMatM NGRAPH_RTTI_DEFINITION(HandleTransposeBeforeMatMul, "HandleTransposeBeforeMatMul", 0); NGRAPH_RTTI_DEFINITION(HandleTransposeAfterMatMul, "HandleTransposeAfterMatMul", 0); +namespace { + void ReplaceTransposeWithReshape(std::shared_ptr transpose_node) { auto shape = transpose_node->get_output_shape(0); auto reshape_const = std::make_shared(ngraph::element::Type_t::i64, @@ -61,12 +63,14 @@ void InsertTranspose(std::shared_ptr prev_node, const std::string& } } -static bool VerifyReshape(const ngraph::Output& reshape_out) { +bool VerifyReshape(const ngraph::Output& reshape_out) { auto in_shape = reshape_out.get_node_shared_ptr()->get_input_shape(0); auto out_shape = reshape_out.get_node_shared_ptr()->get_output_shape(0); return in_shape[0] != out_shape[0]; } +} // namespace + HandleTransposeBeforeMatMul::HandleTransposeBeforeMatMul() { auto constant = ngraph::pattern::wrap_type(); auto fq = ngraph::pattern::wrap_type({constant, ngraph::pattern::any_input(), diff --git a/inference-engine/src/gna_plugin/transformations/split_convolution_with_large_buffer_size.cpp b/inference-engine/src/gna_plugin/transformations/split_convolution_with_large_buffer_size.cpp index 1f757740274..d36519e54c5 100644 --- a/inference-engine/src/gna_plugin/transformations/split_convolution_with_large_buffer_size.cpp +++ b/inference-engine/src/gna_plugin/transformations/split_convolution_with_large_buffer_size.cpp @@ -42,7 +42,7 @@ static bool shouldSplitCnn(const ngraph::Output& node) { return true; } -std::shared_ptr getConvForMatcher() { +static std::shared_ptr getConvForMatcher() { return ngraph::pattern::wrap_type({ ngraph::pattern::any_input(), ngraph::pattern::any_input() }, [](const ngraph::Output& convolution) { return shouldSplitCnn(convolution); diff --git a/inference-engine/src/inference_engine/src/ie_data.cpp b/inference-engine/src/inference_engine/src/ie_data.cpp index 96ad5c9cb26..269d28fe8ae 100644 --- a/inference-engine/src/inference_engine/src/ie_data.cpp +++ b/inference-engine/src/inference_engine/src/ie_data.cpp @@ -205,15 +205,19 @@ const SizeVector& Data::getDims() const { namespace InferenceEngine { -INFERENCE_ENGINE_API_CPP(CNNLayerWeakPtr&) getCreatorLayer(const DataPtr& data) { +INFERENCE_ENGINE_API_CPP(CNNLayerWeakPtr&) getCreatorLayer(const DataPtr& data); +INFERENCE_ENGINE_API_CPP(std::map&) getInputTo(const DataPtr& data); +INFERENCE_ENGINE_API_CPP(std::map&) getInputTo(Data* data); + +CNNLayerWeakPtr& getCreatorLayer(const DataPtr& data) { return data->_impl->creatorLayer; } -INFERENCE_ENGINE_API_CPP(std::map&) getInputTo(const DataPtr& data) { +std::map& getInputTo(const DataPtr& data) { return data->_impl->inputTo; } -INFERENCE_ENGINE_API_CPP(std::map&) getInputTo(Data* data) { +std::map& getInputTo(Data* data) { return data->_impl->inputTo; } diff --git a/inference-engine/src/inference_engine/src/threading/ie_parallel_custom_arena.cpp b/inference-engine/src/inference_engine/src/threading/ie_parallel_custom_arena.cpp index 4d02c83a100..e9e05436c17 100644 --- a/inference-engine/src/inference_engine/src/threading/ie_parallel_custom_arena.cpp +++ b/inference-engine/src/inference_engine/src/threading/ie_parallel_custom_arena.cpp @@ -38,7 +38,7 @@ void __TBB_internal_restore_affinity(binding_handler* handler_ptr, int slot_num) int __TBB_internal_get_default_concurrency(int numa_id, int core_type_id, int max_threads_per_core); } -int get_processors_group_num() { +static int get_processors_group_num() { # if defined(_WIN32) || defined(_WIN64) SYSTEM_INFO si; GetNativeSystemInfo(&si); @@ -57,7 +57,7 @@ int get_processors_group_num() { return 1; } -bool is_binding_environment_valid() { +static bool is_binding_environment_valid() { # if defined(_WIN32) && !defined(_WIN64) static bool result = [] { // For 32-bit Windows applications, process affinity masks can only support up to 32 logical CPUs. @@ -79,7 +79,7 @@ static int* numa_nodes_indexes = nullptr; static int core_types_count = 0; static int* core_types_indexes = nullptr; -void initialize_system_topology() { +static void initialize_system_topology() { static std::once_flag is_topology_initialized; std::call_once(is_topology_initialized, [&] { @@ -120,7 +120,7 @@ void binding_observer::on_scheduler_exit(bool) { detail::__TBB_internal_restore_affinity(my_binding_handler, tbb::this_task_arena::current_thread_index()); } -binding_oberver_ptr construct_binding_observer(tbb::task_arena& ta, int num_slots, const constraints& c) { +static binding_oberver_ptr construct_binding_observer(tbb::task_arena& ta, int num_slots, const constraints& c) { binding_oberver_ptr observer{}; if (detail::is_binding_environment_valid() && ((c.core_type >= 0 && info::core_types().size() > 1) || (c.numa_id >= 0 && info::numa_nodes().size() > 1) || @@ -131,10 +131,8 @@ binding_oberver_ptr construct_binding_observer(tbb::task_arena& ta, int num_slot return observer; } -# endif /*USE_TBBBIND_2_4*/ - -# if TBB_NUMA_SUPPORT_PRESENT -tbb::task_arena::constraints convert_constraints(const custom::task_arena::constraints& c) { +# elif TBB_NUMA_SUPPORT_PRESENT +static tbb::task_arena::constraints convert_constraints(const custom::task_arena::constraints& c) { tbb::task_arena::constraints result{}; # if TBB_HYBRID_CPUS_SUPPORT_PRESENT result.core_type = c.core_type; diff --git a/inference-engine/src/legacy_api/src/cnn_network_impl.cpp b/inference-engine/src/legacy_api/src/cnn_network_impl.cpp index a7309caca69..c560c894818 100644 --- a/inference-engine/src/legacy_api/src/cnn_network_impl.cpp +++ b/inference-engine/src/legacy_api/src/cnn_network_impl.cpp @@ -38,6 +38,8 @@ using namespace std; using namespace InferenceEngine; using namespace InferenceEngine::details; +namespace { + std::map getConstLayersMap(const CNNNetwork& network) { std::map result; @@ -86,6 +88,8 @@ std::map getConstLayersMap(const CNNNetwork& network) { return result; } +} // namespace + CNNNetworkImpl::CNNNetworkImpl() {} CNNNetworkImpl::CNNNetworkImpl(const CNNNetwork & cnnnetwork) { diff --git a/inference-engine/src/legacy_api/src/convert_function_to_cnn_network.cpp b/inference-engine/src/legacy_api/src/convert_function_to_cnn_network.cpp index 1639873a595..a3cfd843144 100644 --- a/inference-engine/src/legacy_api/src/convert_function_to_cnn_network.cpp +++ b/inference-engine/src/legacy_api/src/convert_function_to_cnn_network.cpp @@ -96,7 +96,7 @@ std::string asString(const float& value) { } // namespace Builder namespace InferenceEngine { -namespace details { +namespace { // helper for adding creators with a specific exception #define REQUIRED_IE_CONVERSION_CREATOR(type_name, ie_type_name)\ @@ -348,12 +348,12 @@ public: void on_adapter(const std::string& name, ::ngraph::ValueAccessor>& adapter) override { auto shape = adapter.get(); - params[name] = joinVec(shape); + params[name] = details::joinVec(shape); } void on_adapter(const std::string& name, ::ngraph::ValueAccessor>& adapter) override { auto shape = adapter.get(); - params[name] = joinVec(shape); + params[name] = details::joinVec(shape); } void on_adapter(const std::string& name, ::ngraph::ValueAccessor& adapter) override { @@ -382,7 +382,7 @@ public: void on_adapter(const std::string& name, ngraph::ValueAccessor>& adapter) override { auto data = adapter.get(); - params[name] = joinVec(data); + params[name] = details::joinVec(data); } void on_adapter(const std::string& name, ::ngraph::ValueAccessor>& adapter) override { @@ -396,7 +396,7 @@ private: std::map creators; }; -void InferenceEngine::details::CNNLayerCreator::on_adapter(const std::string& name, +void CNNLayerCreator::on_adapter(const std::string& name, ::ngraph::ValueAccessor& adapter) { if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter<::ngraph::element::Type>>(&adapter)) { auto type = static_cast<::ngraph::element::Type&>(*a); @@ -411,13 +411,13 @@ void InferenceEngine::details::CNNLayerCreator::on_adapter(const std::string& na params[name] = dims; } else if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter<::ngraph::Shape>>(&adapter)) { auto shape = static_cast<::ngraph::Shape&>(*a); - params[name] = joinVec(shape); + params[name] = details::joinVec(shape); } else if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter<::ngraph::Strides>>(&adapter)) { auto shape = static_cast<::ngraph::Strides&>(*a); - params[name] = joinVec(shape); + params[name] = details::joinVec(shape); } else if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter>>(& adapter)) { auto data = a->get(); - params[name] = joinVec(data); + params[name] = details::joinVec(data); } else if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter>>(& adapter)) { params[name] = a->get()->get_info().variable_id; } else if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter>(& adapter)) { const auto & attrs = a->get(); - params[name] = joinVec(attrs); + params[name] = details::joinVec(attrs); } else { IE_THROW() << "Error converting ngraph to CNN network. " "Attribute adapter can not be found for " << name << " parameter"; } } -InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr<::ngraph::Node>& node): node(node) { +CNNLayerCreator::CNNLayerCreator(const std::shared_ptr<::ngraph::Node>& node): node(node) { addSpecificCreator({"Parameter"}, [](const std::shared_ptr<::ngraph::Node>& node, const std::map& params) -> CNNLayerPtr { LayerParams attrs = {node->get_friendly_name(), "Input", @@ -635,7 +635,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr res->params["pad_value"] = Builder::asString(castedLayer->get_pad_value()); const auto weightsNode = castedLayer->input(1).get_source_output().get_node_shared_ptr(); - InferenceEngine::details::addBlob(weightsNode, res, InferenceEngine::details::weights); + addBlob(weightsNode, res, InferenceEngine::details::weights); return res; }); @@ -1776,7 +1776,7 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr }); } -CNNLayerPtr InferenceEngine::details::CNNLayerCreator::create() { +CNNLayerPtr CNNLayerCreator::create() { LayerParams attrs = {node->get_friendly_name(), node->description(), details::convertPrecision(node->get_output_element_type(0))}; if (creators.find(node->description()) != creators.end()) @@ -1787,6 +1787,9 @@ CNNLayerPtr InferenceEngine::details::CNNLayerCreator::create() { return res; } +} // namespace + +namespace details { void convertFunctionToICNNNetwork(const std::shared_ptr &graph, const CNNNetwork &network, CNNNetworkImpl* cnnNetworkImpl, @@ -2165,7 +2168,7 @@ void convertFunctionToICNNNetwork(const std::shared_ptr convertFunctionToICNNNetwork(const std::shared_ptr &graph, const CNNNetwork &network, bool keep_constant_inputs) { - auto cnnNetworkImpl = std::make_shared(); + auto cnnNetworkImpl = std::make_shared(); convertFunctionToICNNNetwork(graph, network, cnnNetworkImpl.get(), keep_constant_inputs); return cnnNetworkImpl; } diff --git a/inference-engine/src/legacy_api/src/graph_transformer.cpp b/inference-engine/src/legacy_api/src/graph_transformer.cpp index 4505a51230c..5360f48db12 100644 --- a/inference-engine/src/legacy_api/src/graph_transformer.cpp +++ b/inference-engine/src/legacy_api/src/graph_transformer.cpp @@ -24,7 +24,7 @@ using namespace InferenceEngine::details; namespace InferenceEngine { -bool isForFakeQuantize(const CNNLayer& layer) { +inline bool isForFakeQuantize(const CNNLayer& layer) { for (const DataPtr data : layer.outData) { for (const auto it : getInputTo(data)) { const CNNLayerPtr childLayer = it.second; diff --git a/inference-engine/src/legacy_api/src/net_pass.cpp b/inference-engine/src/legacy_api/src/net_pass.cpp index 79bdd0c0d09..81d202384ef 100644 --- a/inference-engine/src/legacy_api/src/net_pass.cpp +++ b/inference-engine/src/legacy_api/src/net_pass.cpp @@ -293,7 +293,7 @@ static RuleClassSet classifyOutputRules(const TensorIterator& ti) { * @param master * @param slave */ -void CombineData(DataPtr& master, DataPtr& slave) { +static void CombineData(DataPtr& master, DataPtr& slave) { for (auto& kvp : getInputTo(slave)) { auto& slave_layer = kvp.second; for (auto& slv_ins_wptr : slave_layer->insData) { @@ -325,7 +325,7 @@ void SaveOutputDataName(InferenceEngine::DataPtr in_data, InferenceEngine::DataP * void SaveOutputDataName(InferenceEngine::DataPtr in_data, InferenceEngine::DataPtr out_data, NET &net), where * NET = CNNNetwork */ -void SaveOutputDataName(InferenceEngine::DataPtr in_data, InferenceEngine::DataPtr out_data, CNNNetwork& net) { +static void SaveOutputDataName(InferenceEngine::DataPtr in_data, InferenceEngine::DataPtr out_data, CNNNetwork& net) { if (getInputTo(out_data).empty()) { InferenceEngine::OutputsDataMap outputs_data_map = net.getOutputsInfo(); auto out_data_name = out_data->getName(); @@ -522,7 +522,7 @@ bool convertToRNNSeq(CNNLayerPtr cur, const N& net) { return true; } -bool unrollTI(CNNLayerPtr cur, CNNNetwork& net) { +static bool unrollTI(CNNLayerPtr cur, CNNNetwork& net) { IE_SUPPRESS_DEPRECATED_START auto & icnnnet = static_cast(net); IE_SUPPRESS_DEPRECATED_END @@ -1282,7 +1282,7 @@ std::vector TopolSort(const details::CNNSubnet& net) { return details::CNNSubnetSortTopologically(net); } -void restore_net_consistency(CNNNetwork& net) { +static void restore_net_consistency(CNNNetwork& net) { IE_SUPPRESS_DEPRECATED_START auto & icnnnet = static_cast(net); auto inet = dynamic_cast(&icnnnet); diff --git a/inference-engine/src/legacy_api/src/ngraph_ops/eltwise.cpp b/inference-engine/src/legacy_api/src/ngraph_ops/eltwise.cpp index e8a57796000..fba4c23af3c 100644 --- a/inference-engine/src/legacy_api/src/ngraph_ops/eltwise.cpp +++ b/inference-engine/src/legacy_api/src/ngraph_ops/eltwise.cpp @@ -80,7 +80,7 @@ bool op::Eltwise::visit_attributes(AttributeVisitor &visitor) { visitor.on_attribute("operation", eltwise_type); return true; } -std::ostream &operator<<(std::ostream &s, const ELTWISE_TYPE &type) { +std::ostream &ngraph::operator<<(std::ostream &s, const ELTWISE_TYPE &type) { return s << as_string(type); } diff --git a/inference-engine/src/legacy_api/src/ngraph_ops/scaleshift.cpp b/inference-engine/src/legacy_api/src/ngraph_ops/scaleshift.cpp index ad0d7635dfd..9ca8116509a 100644 --- a/inference-engine/src/legacy_api/src/ngraph_ops/scaleshift.cpp +++ b/inference-engine/src/legacy_api/src/ngraph_ops/scaleshift.cpp @@ -12,7 +12,7 @@ using namespace std; using namespace ngraph; -element::Type getMaxBitwidth(const std::vector& types) { +inline element::Type getMaxBitwidth(const std::vector& types) { if (types.empty()) { return element::undefined; } diff --git a/inference-engine/src/legacy_api/src/transformations/convert_opset1_to_legacy/convert_proposal_to_proposal_ie.cpp b/inference-engine/src/legacy_api/src/transformations/convert_opset1_to_legacy/convert_proposal_to_proposal_ie.cpp index 4a0a90851e0..1e20877d54d 100644 --- a/inference-engine/src/legacy_api/src/transformations/convert_opset1_to_legacy/convert_proposal_to_proposal_ie.cpp +++ b/inference-engine/src/legacy_api/src/transformations/convert_opset1_to_legacy/convert_proposal_to_proposal_ie.cpp @@ -13,6 +13,8 @@ #include #include +namespace { + bool convert_to_proposal_ie(std::shared_ptr proposal, bool infer_probs = false) { ngraph::Output last; // 2D tensor of size [1, 3-4] with im_info will be retrieved from this node ngraph::NodeVector ops_to_replace, new_ops; @@ -46,6 +48,8 @@ bool convert_to_proposal_ie(std::shared_ptr proposal, return true; } +} // namespace + NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertProposalToLegacyMatcher, "ConvertProposalToLegacyMatcher", 0); ngraph::pass::ConvertProposalToLegacyMatcher::ConvertProposalToLegacyMatcher() { diff --git a/inference-engine/src/legacy_api/src/transformations/convert_opset1_to_legacy/reshape_1d_ops.cpp b/inference-engine/src/legacy_api/src/transformations/convert_opset1_to_legacy/reshape_1d_ops.cpp index 0c9a2079425..ae52fd0dd05 100644 --- a/inference-engine/src/legacy_api/src/transformations/convert_opset1_to_legacy/reshape_1d_ops.cpp +++ b/inference-engine/src/legacy_api/src/transformations/convert_opset1_to_legacy/reshape_1d_ops.cpp @@ -16,6 +16,8 @@ using namespace ngraph; +namespace { + template std::shared_ptr convert(const Output & data, std::shared_ptr node, NodeVector & new_ops); @@ -149,6 +151,8 @@ matcher_pass_callback get_callback() { }; } +} // namespace + NGRAPH_RTTI_DEFINITION(ngraph::pass::Reshape1DOps, "Reshape1DOps", 0); NGRAPH_RTTI_DEFINITION(ngraph::pass::Reshape1DConvolution, "Reshape1DConvolution", 0); diff --git a/inference-engine/src/low_precision_transformations/src/add.cpp b/inference-engine/src/low_precision_transformations/src/add.cpp index e4068c74a51..0928e355e14 100644 --- a/inference-engine/src/low_precision_transformations/src/add.cpp +++ b/inference-engine/src/low_precision_transformations/src/add.cpp @@ -22,6 +22,8 @@ namespace low_precision { NGRAPH_RTTI_DEFINITION(AddTransformation, "AddTransformation", 0); +namespace { + std::shared_ptr replaceToSubtract(const std::shared_ptr& op) { // TODO: separate this part to standalone transformation: AddToSubtractTransformation // motivation: @@ -90,6 +92,8 @@ std::shared_ptr fuseWithSubtract(const std::shared_ptr& return newSubtract; } +} // namespace + AddTransformation::AddTransformation(const Params& params) : EltwiseBaseTransformation(params) { auto matcher = ngraph::pattern::wrap_type(); diff --git a/inference-engine/src/low_precision_transformations/src/fake_quantize_decomposition.cpp b/inference-engine/src/low_precision_transformations/src/fake_quantize_decomposition.cpp index 932c7066f55..18429587d18 100644 --- a/inference-engine/src/low_precision_transformations/src/fake_quantize_decomposition.cpp +++ b/inference-engine/src/low_precision_transformations/src/fake_quantize_decomposition.cpp @@ -37,6 +37,7 @@ FakeQuantizeDecompositionTransformation::FakeQuantizeDecompositionTransformation } namespace fq_decomposition { +namespace { // get precision details, depends on: // 1. FakeQuantize operation parameters (QuantizationDetails::getDetails & LayerTransformation::getPrecisionDetails) @@ -266,6 +267,7 @@ std::tuple, std::shared_ptr> decomposeFakeQuantize( return std::make_tuple(dequantize, newFQ); } +} // namespace } // namespace fq_decomposition bool FakeQuantizeDecompositionTransformation::transform(TransformationContext& context, ngraph::pattern::Matcher& m) { diff --git a/inference-engine/src/low_precision_transformations/src/fuse_convert.cpp b/inference-engine/src/low_precision_transformations/src/fuse_convert.cpp index 07f56f8b572..365478eb7d5 100644 --- a/inference-engine/src/low_precision_transformations/src/fuse_convert.cpp +++ b/inference-engine/src/low_precision_transformations/src/fuse_convert.cpp @@ -38,6 +38,8 @@ FuseConvertTransformation::FuseConvertTransformation(const Params& params) : Lay this->register_matcher(matcher, callback); } +namespace { + std::shared_ptr removeConvertIfPossibleForSubtract( const std::shared_ptr& convert, const std::shared_ptr& subtract) { @@ -56,6 +58,8 @@ std::shared_ptr removeConvertIfPossibleForSubtract( return newSubtract; } +} // namespace + bool FuseConvertTransformation::transform(TransformationContext& context, ngraph::pattern::Matcher &m) { const auto op = m.get_match_root(); if (!canBeTransformed(context, op)) { diff --git a/inference-engine/src/low_precision_transformations/src/fuse_fake_quantize.cpp b/inference-engine/src/low_precision_transformations/src/fuse_fake_quantize.cpp index bb59172ff3a..758557c7b48 100644 --- a/inference-engine/src/low_precision_transformations/src/fuse_fake_quantize.cpp +++ b/inference-engine/src/low_precision_transformations/src/fuse_fake_quantize.cpp @@ -39,6 +39,7 @@ bool FuseFakeQuantizeTransformation::transform(TransformationContext& context, n } namespace fuse_fq { +namespace { std::shared_ptr updateShape(std::shared_ptr op, const PartialShape& targetPShape) { assert(targetPShape.is_static()); @@ -111,6 +112,7 @@ bool eltwiseWithConstant(const std::shared_ptr& eltwise) { return getDataNode(eltwise) != nullptr; } +} // namespace } // namespace fuse_fq std::shared_ptr FuseFakeQuantizeTransformation::handle( diff --git a/inference-engine/src/low_precision_transformations/src/pull_reshape_through_dequantization.cpp b/inference-engine/src/low_precision_transformations/src/pull_reshape_through_dequantization.cpp index 42afb73e21b..40ca0e7514e 100644 --- a/inference-engine/src/low_precision_transformations/src/pull_reshape_through_dequantization.cpp +++ b/inference-engine/src/low_precision_transformations/src/pull_reshape_through_dequantization.cpp @@ -18,6 +18,7 @@ using namespace ngraph; NGRAPH_RTTI_DEFINITION(ngraph::pass::low_precision::PullReshapeThroughDequantization, "PullReshapeThroughDequantizationFusion", 0); namespace pull_reshape_through_dequantization { +namespace { std::shared_ptr moveThroughElementwise(const std::shared_ptr& reshape, const std::shared_ptr& elementwise) { const auto reshapeValues = reshape->get_input_node_shared_ptr(1); @@ -87,6 +88,7 @@ void fuseConstant(const std::shared_ptr& reshape, const std::shared_ptr moveThroughElementwise(const std::shared_ptr& transpose, const std::shared_ptr& elementwise) { const auto transposeValues = transpose->get_input_node_shared_ptr(1); @@ -85,6 +86,7 @@ void fuseConstant(const std::shared_ptr& transpose, const std::shared_ptr< copy_runtime_info({ constant, transpose }, newConstant); } +} // namespace } // namespace pull_transpose_through_dequantization ngraph::pass::low_precision::PullTransposeThroughDequantization::PullTransposeThroughDequantization( diff --git a/inference-engine/src/low_precision_transformations/src/reshape.cpp b/inference-engine/src/low_precision_transformations/src/reshape.cpp index 11d098aebab..65c700d352b 100644 --- a/inference-engine/src/low_precision_transformations/src/reshape.cpp +++ b/inference-engine/src/low_precision_transformations/src/reshape.cpp @@ -54,6 +54,8 @@ ReshapeTransformation::ReshapeTransformation(const Params& params) : LayerTransf this->register_matcher(m, callback); } +namespace { + void reshapeDequantizationConstant(const std::shared_ptr& reshape) { // Reshape dequantization operation Constant. // 1. Calculate result dequantization Constant shape for broadcast based on original dequantization Constant shape and Reshape output. @@ -141,6 +143,8 @@ void reshapeDequantizationConstant(const std::shared_ptr& resha } } +} // namespace + bool ReshapeTransformation::transform(TransformationContext& context, ngraph::pattern::Matcher &m) { std::shared_ptr reshape = ov::as_type_ptr(m.get_match_root()); if (NetworkHelper::isConstantPath(reshape)) { @@ -161,7 +165,7 @@ bool ReshapeTransformation::isPrecisionPreserved(std::shared_ptr op) const return true; } -size_t getLastNotBroadcastedDimension(const Shape& shape) { +inline size_t getLastNotBroadcastedDimension(const Shape& shape) { for (int i = static_cast(shape.size()) - 1; i >= 0; --i) { if (shape[i] != 1ul) { return i; @@ -170,7 +174,7 @@ size_t getLastNotBroadcastedDimension(const Shape& shape) { return 0; } -size_t getFirstChangedDimension(const PartialShape& shape1, const PartialShape& shape2) { +inline size_t getFirstChangedDimension(const PartialShape& shape1, const PartialShape& shape2) { const size_t minSize = std::min(shape1.rank().get_length(), shape2.rank().get_length()); size_t i = 0; for (; i < minSize; ++i) { diff --git a/inference-engine/src/low_precision_transformations/src/strided_slice.cpp b/inference-engine/src/low_precision_transformations/src/strided_slice.cpp index a8c709cd31e..eb8effc9b4e 100644 --- a/inference-engine/src/low_precision_transformations/src/strided_slice.cpp +++ b/inference-engine/src/low_precision_transformations/src/strided_slice.cpp @@ -16,6 +16,8 @@ namespace low_precision { NGRAPH_RTTI_DEFINITION(ngraph::pass::low_precision::StridedSliceTransformation, "StridedSliceTransformation", 0); +namespace { + std::shared_ptr stridedSliceDeqConstant( const std::shared_ptr strSlice, const std::shared_ptr dequantizaitonConstant) { @@ -74,6 +76,8 @@ std::shared_ptr stridedSliceDeqConstant( return ov::as_type_ptr(NetworkHelper::toScalarIfPossible(result)); } +} // namespace + StridedSliceTransformation::StridedSliceTransformation(const Params& params) : LayerTransformation(params) { auto matcher = ngraph::pattern::wrap_type(); diff --git a/inference-engine/src/low_precision_transformations/src/transpose.cpp b/inference-engine/src/low_precision_transformations/src/transpose.cpp index 518b945b088..6ecde095cd6 100644 --- a/inference-engine/src/low_precision_transformations/src/transpose.cpp +++ b/inference-engine/src/low_precision_transformations/src/transpose.cpp @@ -33,6 +33,8 @@ TransposeTransformation::TransposeTransformation(const Params& params) : LayerTr this->register_matcher(m, callback); } +namespace { + void transposeDequantizationConstant(std::shared_ptr& transpose) { const FakeQuantizeDequantization dequantization = NetworkHelper::getDequantization(transpose); @@ -79,6 +81,8 @@ void transposeDequantizationConstant(std::shared_ptr& transpose) { } } +} // namespace + bool TransposeTransformation::transform(TransformationContext& context, ngraph::pattern::Matcher &m) { std::shared_ptr transpose = m.get_match_root(); if (!canBeTransformed(context, transpose)) { diff --git a/inference-engine/src/mkldnn_plugin/ngraph_transformations/convert_to_power_static.cpp b/inference-engine/src/mkldnn_plugin/ngraph_transformations/convert_to_power_static.cpp index a2ce3f87d3d..4f71bf85f3c 100644 --- a/inference-engine/src/mkldnn_plugin/ngraph_transformations/convert_to_power_static.cpp +++ b/inference-engine/src/mkldnn_plugin/ngraph_transformations/convert_to_power_static.cpp @@ -14,6 +14,8 @@ #include "op/fully_connected.hpp" #include "utils/general_utils.h" +namespace { + int getConstPort(const std::shared_ptr &node) { const auto const1 = std::dynamic_pointer_cast(node->get_input_node_shared_ptr(0)); const auto const2 = std::dynamic_pointer_cast(node->get_input_node_shared_ptr(1)); @@ -93,6 +95,8 @@ std::shared_ptr convert(const std::shared_ptr &node) { } } +} // namespace + NGRAPH_RTTI_DEFINITION(MKLDNNPlugin::ConvertToPowerStatic, "ConvertToPowerStatic", 0); MKLDNNPlugin::ConvertToPowerStatic::ConvertToPowerStatic() { diff --git a/inference-engine/src/mkldnn_plugin/ngraph_transformations/reshape_1d_ops.cpp b/inference-engine/src/mkldnn_plugin/ngraph_transformations/reshape_1d_ops.cpp index 13f8a6726ae..85321404785 100644 --- a/inference-engine/src/mkldnn_plugin/ngraph_transformations/reshape_1d_ops.cpp +++ b/inference-engine/src/mkldnn_plugin/ngraph_transformations/reshape_1d_ops.cpp @@ -15,7 +15,7 @@ #include "transformations/utils/utils.hpp" -namespace Reshape1DOps { +namespace { template std::shared_ptr convert(const ngraph::Output & data, std::shared_ptr node, ngraph::NodeVector &new_ops) { auto new_strides = node->get_strides(); @@ -177,7 +177,7 @@ ngraph::matcher_pass_callback get_callback() { return true; }; } -} // namespace Reshape1DOps +} // namespace NGRAPH_RTTI_DEFINITION(MKLDNNPlugin::Reshape1DConvolution, "Reshape1DConvolution", 0); @@ -186,7 +186,7 @@ MKLDNNPlugin::Reshape1DConvolution::Reshape1DConvolution() { auto weights = ngraph::pattern::any_input(ngraph::pattern::has_static_rank()); auto conv = ngraph::pattern::wrap_type({ activations, weights }); auto m = std::make_shared(conv, "Reshape1DConvolution"); - this->register_matcher(m, Reshape1DOps::get_callback()); + this->register_matcher(m, get_callback()); } NGRAPH_RTTI_DEFINITION(MKLDNNPlugin::Reshape1DGroupConvolution, "Reshape1DGroupConvolution", 0); @@ -196,7 +196,7 @@ MKLDNNPlugin::Reshape1DGroupConvolution::Reshape1DGroupConvolution() { auto weights = ngraph::pattern::any_input(ngraph::pattern::has_static_rank()); auto group_conv = ngraph::pattern::wrap_type({ activations, weights }); auto m = std::make_shared(group_conv, "Reshape1DGroupConvolution"); - this->register_matcher(m, Reshape1DOps::get_callback()); + this->register_matcher(m, get_callback()); } NGRAPH_RTTI_DEFINITION(MKLDNNPlugin::Reshape1DAvgPool, "Reshape1DAvgPool", 0); @@ -205,7 +205,7 @@ MKLDNNPlugin::Reshape1DAvgPool::Reshape1DAvgPool() { auto input = ngraph::pattern::any_input(ngraph::pattern::has_static_rank()); auto pool = ngraph::pattern::wrap_type({ input }); auto m = std::make_shared(pool, "Reshape1DAvgPool"); - this->register_matcher(m, Reshape1DOps::get_callback()); + this->register_matcher(m, get_callback()); } NGRAPH_RTTI_DEFINITION(MKLDNNPlugin::Reshape1DMaxPool, "Reshape1DMaxPool", 0); @@ -214,5 +214,5 @@ MKLDNNPlugin::Reshape1DMaxPool::Reshape1DMaxPool() { auto input = ngraph::pattern::any_input(ngraph::pattern::has_static_rank()); auto pool = ngraph::pattern::wrap_type({ input }); auto m = std::make_shared(pool, "Reshape1DMaxPool"); - this->register_matcher(m, Reshape1DOps::get_callback()); + this->register_matcher(m, get_callback()); } diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_experimental_detectron_roifeatureextractor_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_experimental_detectron_roifeatureextractor_node.cpp index 17a8caadbfb..2d841ef9d08 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_experimental_detectron_roifeatureextractor_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_experimental_detectron_roifeatureextractor_node.cpp @@ -14,6 +14,8 @@ using namespace MKLDNNPlugin; using namespace InferenceEngine; +namespace { + // implementation taken from Caffe2 template struct PreCalc { @@ -304,6 +306,8 @@ void reorder_rois(const float *rois, const int* ids, int* mapping, const int roi } } +} // namespace + bool MKLDNNExperimentalDetectronROIFeatureExtractorNode::isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept { try { diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_interpolate_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_interpolate_node.cpp index 0190392ccb5..4f90a6461d5 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_interpolate_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_interpolate_node.cpp @@ -1604,7 +1604,7 @@ private: // shapeND: n c d h w // blockND: ncdhw cdhw dhw hw w 1 // index : 0 1 2 3 4 5 -SizeVector getBlockND(SizeVector& shape) { +inline SizeVector getBlockND(SizeVector& shape) { int shapeRank = shape.size(); SizeVector blockND(shapeRank + 1, 1); for (int i = shapeRank - 1; i >= 0; i--) { @@ -1613,7 +1613,7 @@ SizeVector getBlockND(SizeVector& shape) { return blockND; } // w/hw/ncw/nchw/ncdhw to ncdhw -SizeVector to5Dim(SizeVector casesDim) { +inline SizeVector to5Dim(SizeVector casesDim) { size_t caseSize = casesDim.size(); SizeVector dim5(5, 1lu); dim5[4] = casesDim[caseSize - 1]; @@ -2059,7 +2059,7 @@ void MKLDNNInterpolateNode::createPrimitive() { } } -int clipCoord(int pos, int length) { +inline int clipCoord(int pos, int length) { return std::max(static_cast(0), std::min(pos, length - 1)); } diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp index fb3fc07d8dc..d4367bb4837 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp @@ -71,7 +71,7 @@ static mkldnn::algorithm ie2dnnl(const std::shared_ptr& op) } } -size_t gatesCount(mkldnn::algorithm alg) { +inline size_t gatesCount(mkldnn::algorithm alg) { switch (alg) { case mkldnn::algorithm::vanilla_rnn: return 1; case mkldnn::algorithm::vanilla_gru: @@ -83,7 +83,7 @@ size_t gatesCount(mkldnn::algorithm alg) { } } -size_t statesCount(mkldnn::algorithm alg) { +inline size_t statesCount(mkldnn::algorithm alg) { switch (alg) { case mkldnn::algorithm::vanilla_rnn: case mkldnn::algorithm::vanilla_gru: @@ -95,7 +95,7 @@ size_t statesCount(mkldnn::algorithm alg) { } } -bool haveCellState(mkldnn::algorithm alg) { +inline bool haveCellState(mkldnn::algorithm alg) { return alg == mkldnn::algorithm::vanilla_lstm; } diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_scatter_update_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_scatter_update_node.cpp index 1bce5ea3ea9..bb68ecfdfc0 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_scatter_update_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_scatter_update_node.cpp @@ -245,7 +245,7 @@ int64_t MKLDNNScatterUpdateNode::getIndicesValue(uint8_t *indices, size_t offset // shapeND: n c d h w // blockND: ncdhw cdhw dhw hw w 1 // index : 0 1 2 3 4 5 -std::vector getBlockND(const SizeVector& shape) { +static std::vector getBlockND(const SizeVector& shape) { size_t shapeRank = shape.size(); std::vector blockND(shapeRank + 1, 1); for (int i = shapeRank - 1; i >= 0; i--) { diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_tensoriterator_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_tensoriterator_node.cpp index f87108e3654..fd4f658a80a 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_tensoriterator_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_tensoriterator_node.cpp @@ -197,7 +197,7 @@ private: } // namespace MKLDNNPlugin -int getNumIteration(const std::shared_ptr& op, const std::vector& inputPortMap, const std::vector& outputPortMap) { +static int getNumIteration(const std::shared_ptr& op, const std::vector& inputPortMap, const std::vector& outputPortMap) { const auto isIterable = [](const PortMap& rule) { return rule.axis != -1; }; const auto getNumIterations = [](const PortMap& rule, const std::vector& dimensions) -> int { diff --git a/inference-engine/src/offline_transformations/src/pruning/propagate_masks.cpp b/inference-engine/src/offline_transformations/src/pruning/propagate_masks.cpp index e944ffff57b..765f51c23bc 100644 --- a/inference-engine/src/offline_transformations/src/pruning/propagate_masks.cpp +++ b/inference-engine/src/offline_transformations/src/pruning/propagate_masks.cpp @@ -30,7 +30,7 @@ class Concat; } // namespace pass } // namespace ngraph -ngraph::Shape broadcast_shape_to_rank(ngraph::Shape shape_to_broadcast, int64_t dst_rank) { +static ngraph::Shape broadcast_shape_to_rank(ngraph::Shape shape_to_broadcast, int64_t dst_rank) { auto initial_rank = static_cast(shape_to_broadcast.size()); auto num_of_broadcased_dims = dst_rank - initial_rank; std::vector dims(num_of_broadcased_dims, 1); diff --git a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iplugin_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iplugin_internal.hpp index 0333b41c41f..5f15cbb6bf7 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iplugin_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iplugin_internal.hpp @@ -340,17 +340,18 @@ public: * @brief Defines the exported `CreatePluginEngine` function which is used to create a plugin instance * @ingroup ie_dev_api_plugin_api */ -#define IE_DEFINE_PLUGIN_CREATE_FUNCTION(PluginType, version, ...) \ - INFERENCE_PLUGIN_API(void) \ - IE_CREATE_PLUGIN(::std::shared_ptr<::InferenceEngine::IInferencePlugin>& plugin) noexcept(false) { \ - try { \ - plugin = ::std::make_shared(__VA_ARGS__); \ - } catch (const InferenceEngine::Exception&) { \ - throw; \ - } catch (const std::exception& ex) { \ - IE_THROW() << ex.what(); \ - } catch (...) { \ - IE_THROW(Unexpected); \ - } \ - plugin->SetVersion(version); \ +#define IE_DEFINE_PLUGIN_CREATE_FUNCTION(PluginType, version, ...) \ + INFERENCE_PLUGIN_API(void) \ + IE_CREATE_PLUGIN(::std::shared_ptr<::InferenceEngine::IInferencePlugin>& plugin) noexcept(false); \ + void IE_CREATE_PLUGIN(::std::shared_ptr<::InferenceEngine::IInferencePlugin>& plugin) noexcept(false) { \ + try { \ + plugin = ::std::make_shared(__VA_ARGS__); \ + } catch (const InferenceEngine::Exception&) { \ + throw; \ + } catch (const std::exception& ex) { \ + IE_THROW() << ex.what(); \ + } catch (...) { \ + IE_THROW(Unexpected); \ + } \ + plugin->SetVersion(version); \ } diff --git a/inference-engine/src/plugin_api/performance_heuristics.hpp b/inference-engine/src/plugin_api/performance_heuristics.hpp index cace1dd4185..3b58ae88570 100644 --- a/inference-engine/src/plugin_api/performance_heuristics.hpp +++ b/inference-engine/src/plugin_api/performance_heuristics.hpp @@ -21,7 +21,7 @@ struct MemBandwidthPressure { static constexpr float LIMITED = 0.5f; // conservatively assume 1/2 utilization of the cache }; -MemBandwidthPressure MemBandwidthPressureTolerance( +static MemBandwidthPressure MemBandwidthPressureTolerance( const std::shared_ptr nGraphFunc, const float L2_cache_size, const float L3_cache_size, diff --git a/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.cpp b/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.cpp index 7aa5bcb1b85..abb1fb4ce13 100644 --- a/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.cpp +++ b/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.cpp @@ -61,23 +61,23 @@ using isas_set = typelist< //as the search for supported ISA is performed until first match scalar_tag>; #ifdef HAVE_AVX512 - bool is_present(avx512_tag) { return with_cpu_x86_avx512f(); } + inline bool is_present(avx512_tag) { return with_cpu_x86_avx512f(); } #endif // HAVE_AVX512 #ifdef HAVE_AVX2 - bool is_present(avx2_tag) { return with_cpu_x86_avx2(); } + inline bool is_present(avx2_tag) { return with_cpu_x86_avx2(); } #endif // HAVE_AVX2 #ifdef HAVE_SSE - bool is_present(sse42_tag) { return with_cpu_x86_sse42(); } + inline bool is_present(sse42_tag) { return with_cpu_x86_sse42(); } #endif // HAVE_SSE #ifdef HAVE_NEON - bool is_present(neon_tag) { return true; } + inline bool is_present(neon_tag) { return true; } #endif // HAVE_NEON //scalar version of kernels is always available -bool is_present(scalar_tag) { return true; } +inline bool is_present(scalar_tag) { return true; } struct is_isa_present { template< typename isa_tag_t> diff --git a/inference-engine/src/readers/ir_reader_v7/ie_ir_version.hpp b/inference-engine/src/readers/ir_reader_v7/ie_ir_version.hpp index bb319155b19..6d9a457462c 100644 --- a/inference-engine/src/readers/ir_reader_v7/ie_ir_version.hpp +++ b/inference-engine/src/readers/ir_reader_v7/ie_ir_version.hpp @@ -18,7 +18,7 @@ inline size_t GetIRVersion(pugi::xml_node& root) { * @param model Models stream * @return IR version, 0 if model does represent IR */ -size_t GetIRVersion(std::istream& model) { +inline size_t GetIRVersion(std::istream& model) { std::array header = {}; model.seekg(0, model.beg); diff --git a/inference-engine/src/snippets/src/pass/insert_movebroadcast.cpp b/inference-engine/src/snippets/src/pass/insert_movebroadcast.cpp index 048859391fe..93640195ab4 100644 --- a/inference-engine/src/snippets/src/pass/insert_movebroadcast.cpp +++ b/inference-engine/src/snippets/src/pass/insert_movebroadcast.cpp @@ -15,7 +15,9 @@ using namespace ngraph; -static std::shared_ptr numpy_broadcast_node(const ngraph::Output& value, +namespace { + +std::shared_ptr numpy_broadcast_node(const ngraph::Output& value, const ngraph::Shape& output_shape, const ngraph::Shape& source_shape) { std::shared_ptr broadcasted_node = value.get_node_shared_ptr(); @@ -69,7 +71,7 @@ static std::shared_ptr numpy_broadcast_node(const ngraph::Output& op) -> void { } } +} // namespace + // adds explicit broadcasts if needed // ToDO: this indeed make model not reshapable, need to come up with more clever way to insert fake broadcast, // well on the other hand, if we replace scalar constant with Scalar op / or ShapeOf, we could have broadcasts that are reshapable diff --git a/inference-engine/src/transformations/include/transformations/common_optimizations/optimize_strided_slice.hpp b/inference-engine/src/transformations/include/transformations/common_optimizations/optimize_strided_slice.hpp index 3cbefcf88a0..9b4f7f80d7f 100644 --- a/inference-engine/src/transformations/include/transformations/common_optimizations/optimize_strided_slice.hpp +++ b/inference-engine/src/transformations/include/transformations/common_optimizations/optimize_strided_slice.hpp @@ -71,5 +71,3 @@ public: NGRAPH_RTTI_DECLARATION; bool run_on_function(std::shared_ptr f) override; }; - -ngraph::SlicePlan get_slice_plan(std::shared_ptr slice); \ No newline at end of file diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/broadcast_elementwise_fusion.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/broadcast_elementwise_fusion.cpp index 3a43980cfcb..6c0af2eb9b7 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/broadcast_elementwise_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/broadcast_elementwise_fusion.cpp @@ -10,6 +10,8 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::BroadcastElementwiseFusion, "BroadcastElementwiseFusion", 0); +namespace { + bool can_eliminate_broadcast(const ngraph::Output& eltwise, const ngraph::PartialShape & input_shape, const ngraph::PartialShape & broadcast_shape) { @@ -51,6 +53,8 @@ bool can_eliminate_broadcast(const ngraph::Output& eltwise, return true; } +} // namespace + ngraph::pass::BroadcastElementwiseFusion::BroadcastElementwiseFusion() { MATCHER_SCOPE(BroadcastElementwiseFusion); auto broadcast_input = pattern::any_input(); diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/depth_to_space_fusion.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/depth_to_space_fusion.cpp index 8ca7a9b42ca..c9c3025a881 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/depth_to_space_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/depth_to_space_fusion.cpp @@ -11,6 +11,8 @@ #include #include +namespace { + bool check_block_first(const ngraph::Shape& shape_input, const ngraph::Shape& shape_reshape_before, const ngraph::AxisVector& permutation, const ngraph::Shape& shape_reshape_after, size_t& possible_block_size) { @@ -82,6 +84,8 @@ bool check_depth_first(const ngraph::Shape& shape_input, const ngraph::Shape& sh return is_transformation_valid; } +} // namespace + NGRAPH_RTTI_DEFINITION(ngraph::pass::DepthToSpaceFusion, "DepthToSpaceFusion", 0); ngraph::pass::DepthToSpaceFusion::DepthToSpaceFusion() { diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/optimize_strided_slice.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/optimize_strided_slice.cpp index f2ec035b604..f7b92fb0315 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/optimize_strided_slice.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/optimize_strided_slice.cpp @@ -41,6 +41,8 @@ bool ngraph::pass::UselessStridedSliceEraser::run_on_function(std::shared_ptr slice) { auto convert_mask_to_axis_set = [](const std::vector& mask) { ngraph::AxisSet axis_set{}; @@ -76,7 +78,6 @@ ngraph::SlicePlan get_slice_plan(std::shared_ptr s return plan; } - bool strided_slices_perform_the_same(std::shared_ptr lhs, std::shared_ptr rhs) { auto lhs_plan = get_slice_plan(lhs); @@ -88,6 +89,8 @@ bool strided_slices_perform_the_same(std::shared_ptr f) { diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/shuffle_channels_fusion.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/shuffle_channels_fusion.cpp index 464761390a2..515a8969e72 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/shuffle_channels_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/shuffle_channels_fusion.cpp @@ -12,6 +12,8 @@ #include #include +namespace { + bool check_shapes(const ngraph::Shape& shape_input, const ngraph::Shape& shape_reshape_before, const ngraph::AxisVector& transpose_constant_values, const ngraph::Shape& shape_reshape_after) { // x: [N, C, H, W] @@ -51,6 +53,8 @@ bool check_shapes(const ngraph::Shape& shape_input, const ngraph::Shape& shape_r return is_transformation_valid; } +} // namespace + NGRAPH_RTTI_DEFINITION(ngraph::pass::ShuffleChannelsFusion, "ShuffleChannelsFusion", 0); ngraph::pass::ShuffleChannelsFusion::ShuffleChannelsFusion(const bool reshape_constants_check) { diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/swish_fusion.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/swish_fusion.cpp index bf6c12584aa..0ff405fd980 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/swish_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/swish_fusion.cpp @@ -12,6 +12,8 @@ #include #include "transformations/utils/utils.hpp" +namespace { + bool check_beta_value(const std::shared_ptr& constant) { // check that the constant for beta contains only one distinct element if (!constant) { @@ -28,6 +30,8 @@ bool check_beta_value(const std::shared_ptr& constant) return true; } +} // namespace + NGRAPH_RTTI_DEFINITION(ngraph::pass::SwishFusion, "SwishFusion", 0); NGRAPH_RTTI_DEFINITION(ngraph::pass::SwishFusionWithSigmoid, "SwishFusionWithSigmoid", 0); diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/transpose_sinking.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/transpose_sinking.cpp index 7ae2c34dfca..f5b62cd7c9c 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/transpose_sinking.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/transpose_sinking.cpp @@ -22,6 +22,8 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::TransposeFuse, "TransposeFuse", 0); using namespace ngraph; +namespace { + std::shared_ptr get_reduced_order_constant(const std::shared_ptr& axes_const, const std::shared_ptr& order_const) { auto order = order_const->cast_vector(); @@ -56,6 +58,8 @@ std::shared_ptr get_reversed_order_constant(const std: ngraph::element::i64, ngraph::Shape{reverse_order.size()}, reverse_order); } +} // namespace + ngraph::pass::TransposeReduction::TransposeReduction() { MATCHER_SCOPE(TransposeReduction); diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/transpose_to_reshape.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/transpose_to_reshape.cpp index fe968bf5484..04086272a44 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/transpose_to_reshape.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/transpose_to_reshape.cpp @@ -18,6 +18,8 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::TransposeToReshape, "TransposeToReshape", 0 using namespace ngraph; +namespace { + bool replace_transpose_with_reshape(const std::shared_ptr& transpose) { auto data = transpose->input_value(0); const auto input_shape = transpose->input(0).get_partial_shape(); @@ -101,6 +103,8 @@ bool replace_transpose_with_reshape(const std::shared_ptr& transpose) { return true; } +} // namespace + ngraph::pass::TransposeToReshape::TransposeToReshape() { MATCHER_SCOPE(TransposeToReshape); diff --git a/inference-engine/src/transformations/src/transformations/op_conversions/convert_broadcast3.cpp b/inference-engine/src/transformations/src/transformations/op_conversions/convert_broadcast3.cpp index 51073ed6237..4bde5e67c8e 100644 --- a/inference-engine/src/transformations/src/transformations/op_conversions/convert_broadcast3.cpp +++ b/inference-engine/src/transformations/src/transformations/op_conversions/convert_broadcast3.cpp @@ -16,6 +16,8 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertBroadcast3, "ConvertBroadcast3", 0); +namespace { + bool make_compatible_shape(const ngraph::PartialShape & input_shape, std::vector & target_shape) { if (input_shape.rank().is_dynamic()) { return false; @@ -55,6 +57,8 @@ bool make_compatible_shape(const ngraph::PartialShape & input_shape, std::vector return true; } +} // namespace + ngraph::pass::ConvertBroadcast3::ConvertBroadcast3() { MATCHER_SCOPE(ConvertBroadcast3); auto broadcast = pattern::wrap_type(); diff --git a/inference-engine/src/transformations/src/transformations/op_conversions/fq_decomposition.cpp b/inference-engine/src/transformations/src/transformations/op_conversions/fq_decomposition.cpp index 3203c82ead6..ac8c3e7681d 100644 --- a/inference-engine/src/transformations/src/transformations/op_conversions/fq_decomposition.cpp +++ b/inference-engine/src/transformations/src/transformations/op_conversions/fq_decomposition.cpp @@ -15,6 +15,8 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::FakeQuantizeDecomposition, "FakeQuantizeDecomposition", 0); +namespace { + bool isValidRangesInputs(const std::shared_ptr &fq) { auto il = fq->input_value(1); auto ih = fq->input_value(2); @@ -31,6 +33,8 @@ bool isValidRangesInputs(const std::shared_ptr &fq return !std::any_of(comp_result.begin(), comp_result.end(), [](const bool value) { return value; }); } +} // namespace + ngraph::pass::FakeQuantizeDecomposition::FakeQuantizeDecomposition() { MATCHER_SCOPE(FakeQuantizeDecomposition); auto data = ngraph::pattern::any_input(); diff --git a/inference-engine/src/vpu/common/src/ngraph/operations/dynamic_shape_resolver.cpp b/inference-engine/src/vpu/common/src/ngraph/operations/dynamic_shape_resolver.cpp index 460407d1762..15ed96c7cf4 100644 --- a/inference-engine/src/vpu/common/src/ngraph/operations/dynamic_shape_resolver.cpp +++ b/inference-engine/src/vpu/common/src/ngraph/operations/dynamic_shape_resolver.cpp @@ -59,6 +59,7 @@ bool DynamicShapeResolver::visit_attributes(ngraph::AttributeVisitor&) { } namespace dyn_shape { +namespace { template bool getShapeFromHostTensorData(const HostTensorPtr& data, Shape& result) { @@ -187,6 +188,7 @@ bool evaluateDynamicShapeResolver(const HostTensorPtr& inputTensor, return rc; } +} // namespace } // namespace dyn_shape bool DynamicShapeResolver::evaluate(const HostTensorVector& outputs, diff --git a/inference-engine/src/vpu/common/src/ngraph/operations/out_shape_of_reshape.cpp b/inference-engine/src/vpu/common/src/ngraph/operations/out_shape_of_reshape.cpp index b5e5198a2b7..cb2d518b887 100644 --- a/inference-engine/src/vpu/common/src/ngraph/operations/out_shape_of_reshape.cpp +++ b/inference-engine/src/vpu/common/src/ngraph/operations/out_shape_of_reshape.cpp @@ -66,6 +66,7 @@ bool OutShapeOfReshape::visit_attributes(ngraph::AttributeVisitor& visitor) { } namespace out_shape { +namespace { template bool getShapeFromHostTensorData(const HostTensorPtr& data, Shape& result) { @@ -248,6 +249,7 @@ bool evaluateOutShapeOfReshape( return true; } +} // namespace } // namespace out_shape bool OutShapeOfReshape::evaluate(const HostTensorVector& outputs, diff --git a/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_gather_nd.cpp b/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_gather_nd.cpp index 7e8986f16e7..da3687b9646 100644 --- a/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_gather_nd.cpp +++ b/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_gather_nd.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "vpu/ngraph/transformations/dynamic_to_static_shape_gather.hpp" +#include "vpu/ngraph/transformations/dynamic_to_static_shape_gather_nd.hpp" #include "vpu/ngraph/operations/dynamic_shape_resolver.hpp" #include "vpu/ngraph/utilities.hpp" diff --git a/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_matmul.cpp b/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_matmul.cpp index 60cbd674872..d6262fb8e69 100644 --- a/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_matmul.cpp +++ b/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_matmul.cpp @@ -16,6 +16,8 @@ namespace vpu { +namespace { + void get_normalized_shape(ngraph::Output& shape, size_t actual_rank_value, size_t max_rank_value, bool transpose, const ngraph::element::Type& elementType) { if (const size_t rank_diff = max_rank_value - actual_rank_value) { @@ -33,6 +35,8 @@ void get_normalized_shape(ngraph::Output& shape, size_t actual_ran } } +} // namespace + void dynamicToStaticShapeMatMul(std::shared_ptr target) { const auto matmul = ngraph::as_type_ptr(target); VPU_THROW_UNLESS(matmul, "dynamicToStaticShapeMatMul transformation is not applicable for {}, it should be {} instead", diff --git a/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_split.cpp b/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_split.cpp index 385cd971b32..1c38e52cd93 100644 --- a/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_split.cpp +++ b/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_split.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "vpu/ngraph/transformations/dynamic_to_static_shape_broadcast.hpp" +#include "vpu/ngraph/transformations/dynamic_to_static_shape_split.hpp" #include "vpu/ngraph/operations/dynamic_shape_resolver.hpp" #include "vpu/ngraph/utilities.hpp" diff --git a/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_strided_slice.cpp b/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_strided_slice.cpp index b12d5a77942..0b209a45027 100644 --- a/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_strided_slice.cpp +++ b/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_strided_slice.cpp @@ -19,6 +19,8 @@ namespace vpu { +namespace { + ngraph::AxisSet convert_mask_to_axis_set(const std::vector& mask) { ngraph::AxisSet axis_set{}; for (size_t i = 0; i < mask.size(); ++i) @@ -121,6 +123,8 @@ std::shared_ptr calculate_output_shape( return output_shape; } +} // namespace + void dynamicToStaticShapeStridedSlice(std::shared_ptr target) { const auto dsr = target->input_value(0).get_node_shared_ptr(); VPU_THROW_UNLESS(ngraph::as_type_ptr(dsr), diff --git a/inference-engine/src/vpu/graph_transformer/src/frontend/custom_kernel.cpp b/inference-engine/src/vpu/graph_transformer/src/frontend/custom_kernel.cpp index cc7cadedc3c..38dba8f0230 100644 --- a/inference-engine/src/vpu/graph_transformer/src/frontend/custom_kernel.cpp +++ b/inference-engine/src/vpu/graph_transformer/src/frontend/custom_kernel.cpp @@ -11,6 +11,8 @@ namespace vpu { +namespace { + VPU_PACKED(Elf32Shdr { uint32_t shName; uint32_t pad0[3]; @@ -78,33 +80,6 @@ VPU_PACKED(KernelArgHdr { uint32_t laneSize; };) -std::pair findSymbolTable( - const char* ELFData) { - const uint32_t SYMTAB = 2; // Link editing symbol table - const uint32_t STRTAB = 3; // A string table - - IE_ASSERT(ELFData != nullptr); - - auto ehdr = reinterpret_cast(ELFData); - auto shdr = reinterpret_cast(ELFData + ehdr->eShoff); - - const Elf32Section* strShdr = nullptr; - const Elf32Section* symShdr = nullptr; - for (size_t i = 0; i < ehdr->eShnum; i++) { - if (shdr[i].shType == STRTAB && strShdr == nullptr) { - strShdr = &shdr[i]; - } else if (shdr[i].shType == SYMTAB && symShdr == nullptr) { - symShdr = &shdr[i]; - } - - if (symShdr != nullptr && strShdr != nullptr) - break; - } - IE_ASSERT(symShdr != nullptr && strShdr != nullptr); - - return std::make_pair(strShdr, symShdr); -} - SmallVector deduceKernelParameters(const md_parser_t& parser, int kernelId) { const auto kernelDesc = parser.get_kernel(kernelId); IE_ASSERT(kernelDesc != nullptr); @@ -129,7 +104,7 @@ SmallVector deduceKernelParameters(const md_parser_t& parser, int k return arguments; } -static const Elf32Shdr *get_elf_section_with_name(const uint8_t *elf_data, const char* section_name) { +const Elf32Shdr *get_elf_section_with_name(const uint8_t *elf_data, const char* section_name) { IE_ASSERT(elf_data); IE_ASSERT(section_name); @@ -167,31 +142,64 @@ static const Elf32Shdr *get_elf_section_with_name(const uint8_t *elf_data, const return nullptr; } -uint32_t getKernelEntry(const char* ELFData, const std::string& kernelName) { - IE_ASSERT(ELFData != nullptr); +std::pair parseDimSource(const std::string& dims) { const auto cmp = ie::details::CaselessEq{}; - - auto ehdr = reinterpret_cast(ELFData); - auto phdr = reinterpret_cast(ELFData + ehdr->ePhoff); - - const Elf32Section* strShdr = nullptr; - const Elf32Section* symShdr = nullptr; - std::tie(strShdr, symShdr) = findSymbolTable(ELFData); - IE_ASSERT(symShdr != nullptr && strShdr != nullptr); - - auto numSymEntries = symShdr->shSize / symShdr->shEntsize; - auto sym = reinterpret_cast(ELFData + symShdr->shOffset); - auto firstStr = ELFData + strShdr->shOffset; - - for (size_t i = 0; i < numSymEntries; i++) { - if (cmp(firstStr + sym[i].stName, kernelName)) { - return sym[i].stValue - phdr->pVaddr; + const auto pos = dims.find_first_of(','); + const auto source = dims.substr(0, pos); + const auto dimSource = [&] { + if (cmp(source, "input")) { + return CustomDimSource::Input; + } else if (cmp(source, "output")) { + return CustomDimSource::Output; + } else { + IE_THROW() << "Invalid dim source argument" << source; } + }(); + + const auto idx = [&] { + if (pos == std::string::npos) { + return -1; + } + const auto idxString = dims.substr(pos + 1, std::string::npos); + return std::stoi(idxString); + }(); + + return std::make_pair(dimSource, idx); +} + +CustomDataFormat formatFromString(const std::string& str) { + static const ie::details::caseless_map FormatNameToType = { + { "BFYX" , CustomDataFormat::BFYX }, + { "BYXF" , CustomDataFormat::BYXF }, + { "FYX" , CustomDataFormat::FYX }, + { "YXF" , CustomDataFormat::YXF }, + { "BF" , CustomDataFormat::BF }, + { "ANY" , CustomDataFormat::Any } + }; + + auto it = FormatNameToType.find(str); + if (it != FormatNameToType.end()) { + return it->second; } - IE_THROW() << "Cannot find kernel entry point for custom kernel " << kernelName; + IE_THROW() << "Tensor node has an invalid format '" << str << "'"; } +SmallVector parseSizeRule(const std::string& size) { + auto result = SmallVector(); + result.reserve(std::count(begin(size), end(size), ',') + 1); + std::stringstream sizeRules{size}; + std::string bufferSize; + + while (std::getline(sizeRules, bufferSize, ',')) { + result.push_back(bufferSize); + } + + return result; +} + +} // namespace + CustomKernel::CustomKernel(const pugi::xml_node& kernel, std::string configDir): _configDir {std::move(configDir)} { _maxShaves = XMLParseUtils::GetIntAttr(kernel, "max-shaves", 0); @@ -246,63 +254,6 @@ CustomKernel::CustomKernel(const pugi::xml_node& kernel, std::string configDir): _inputDataCount = static_cast(std::count_if(begin(_kernelParams), end(_kernelParams), isInputData)); } -std::pair parseDimSource(const std::string& dims) { - const auto cmp = ie::details::CaselessEq{}; - const auto pos = dims.find_first_of(','); - const auto source = dims.substr(0, pos); - const auto dimSource = [&] { - if (cmp(source, "input")) { - return CustomDimSource::Input; - } else if (cmp(source, "output")) { - return CustomDimSource::Output; - } else { - IE_THROW() << "Invalid dim source argument" << source; - } - }(); - - const auto idx = [&] { - if (pos == std::string::npos) { - return -1; - } - const auto idxString = dims.substr(pos + 1, std::string::npos); - return std::stoi(idxString); - }(); - - return std::make_pair(dimSource, idx); -} - - -CustomDataFormat formatFromString(const std::string& str) { - static const ie::details::caseless_map FormatNameToType = { - { "BFYX" , CustomDataFormat::BFYX }, - { "BYXF" , CustomDataFormat::BYXF }, - { "FYX" , CustomDataFormat::FYX }, - { "YXF" , CustomDataFormat::YXF }, - { "BF" , CustomDataFormat::BF }, - { "ANY" , CustomDataFormat::Any } - }; - - auto it = FormatNameToType.find(str); - if (it != FormatNameToType.end()) { - return it->second; - } - - IE_THROW() << "Tensor node has an invalid format '" << str << "'"; -} - -SmallVector parseSizeRule(const std::string& size) { - auto result = SmallVector(); - result.reserve(std::count(begin(size), end(size), ',') + 1); - std::stringstream sizeRules{size}; - std::string bufferSize; - - while (std::getline(sizeRules, bufferSize, ',')) { - result.push_back(bufferSize); - } - - return result; -} - void CustomKernel::processParametersNode(const pugi::xml_node& node) { const auto cmp = ie::details::CaselessEq {}; const auto parameters = node.child("Parameters"); diff --git a/inference-engine/src/vpu/graph_transformer/src/middleend/hw/conv_tiling/hw_convolution_tiler.cpp b/inference-engine/src/vpu/graph_transformer/src/middleend/hw/conv_tiling/hw_convolution_tiler.cpp index d8c570b68c4..6b7f9c4e610 100644 --- a/inference-engine/src/vpu/graph_transformer/src/middleend/hw/conv_tiling/hw_convolution_tiler.cpp +++ b/inference-engine/src/vpu/graph_transformer/src/middleend/hw/conv_tiling/hw_convolution_tiler.cpp @@ -17,6 +17,7 @@ bool operator<(const TilingOption& lhs, const TilingOption& rhs) { return lhs.cost < rhs.cost || (isDoubleEqual(lhs.cost, rhs.cost) && lhs.totalNumTiles < rhs.totalNumTiles); } +static void correctOutputPlaneSizeF(const ConvolutionOptions& convolutionOptions, bool _useCeil, const DimValues& inputTileDims, DimValues& outputTileDims) { auto maxOutputWidth = calcOutputSize( diff --git a/inference-engine/src/vpu/graph_transformer/src/middleend/passes/inject_sw.cpp b/inference-engine/src/vpu/graph_transformer/src/middleend/passes/inject_sw.cpp index 6f739e04080..1874e5249e6 100644 --- a/inference-engine/src/vpu/graph_transformer/src/middleend/passes/inject_sw.cpp +++ b/inference-engine/src/vpu/graph_transformer/src/middleend/passes/inject_sw.cpp @@ -22,9 +22,6 @@ namespace vpu { -void printTo(std::ostream&, const std::list::iterator&) { -} - namespace { class PassImpl final : public Pass { diff --git a/inference-engine/src/vpu/graph_transformer/src/model/data_contents/deconvolution_contents.cpp b/inference-engine/src/vpu/graph_transformer/src/model/data_contents/deconvolution_contents.cpp index da223652d34..437b868d5f3 100644 --- a/inference-engine/src/vpu/graph_transformer/src/model/data_contents/deconvolution_contents.cpp +++ b/inference-engine/src/vpu/graph_transformer/src/model/data_contents/deconvolution_contents.cpp @@ -37,6 +37,8 @@ void DeconvolutionToConvolutionContent::fillTempBuf(void* tempBuf) const { // DepthDeconvolutionCHWWeightsContent // +namespace { + void depthDeconvolutionRelayoutCHW( const fp16_t* src, int src_size, fp16_t* dst, int dst_size, @@ -55,6 +57,8 @@ void depthDeconvolutionRelayoutCHW( }); } +} // namespace + DepthDeconvolutionCHWWeightsContent::DepthDeconvolutionCHWWeightsContent( const DataContent::Ptr& origContent, int KX, int KY, int channels) : @@ -77,6 +81,8 @@ size_t DepthDeconvolutionCHWWeightsContent::byteSize() const { // DepthDeconvolutionHWCWeightsContent // +namespace { + void depthDeconvolutionRelayoutHWC( const fp16_t* src, int src_size, fp16_t* dst, int dst_size, @@ -95,6 +101,8 @@ void depthDeconvolutionRelayoutHWC( }); } +} // namespace + DepthDeconvolutionHWCWeightsContent::DepthDeconvolutionHWCWeightsContent( const DataContent::Ptr& origContent, int KX, int KY, int channels) : @@ -118,6 +126,8 @@ size_t DepthDeconvolutionHWCWeightsContent::byteSize() const { // DeconvolutionWeightsContent // +namespace { + void deconvolutionRelayout( const fp16_t* src, int src_size, fp16_t* dst, int dst_size, @@ -142,6 +152,8 @@ void deconvolutionRelayout( }); } +} // namespace + DeconvolutionWeightsContent::DeconvolutionWeightsContent( const DataContent::Ptr& origContent, DataDesc desc, diff --git a/ngraph/core/CMakeLists.txt b/ngraph/core/CMakeLists.txt index ad93fe75574..f93cdfd83bd 100644 --- a/ngraph/core/CMakeLists.txt +++ b/ngraph/core/CMakeLists.txt @@ -4,6 +4,10 @@ add_definitions(-DIN_NGRAPH_LIBRARY) +if(CMAKE_COMPILER_IS_GNUCXX) + ie_add_compiler_flags(-Wmissing-declarations) +endif() + file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp) file(GLOB_RECURSE PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp) diff --git a/ngraph/core/builder/src/builder/autobroadcast.cpp b/ngraph/core/builder/src/builder/autobroadcast.cpp index de296af2a34..28f11946b58 100644 --- a/ngraph/core/builder/src/builder/autobroadcast.cpp +++ b/ngraph/core/builder/src/builder/autobroadcast.cpp @@ -360,9 +360,9 @@ Output get_axes_mapping_output(const Shape& output_shape, const AxisSet& b return op::Constant::create(element::i64, Shape{axes_mapping.size()}, axes_mapping); } -Output get_axes_mapping_output(const PartialShape& output_shape, - const Output& input_shape, - std::size_t start_match_axis) { +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}); diff --git a/ngraph/core/builder/src/builder/norm.cpp b/ngraph/core/builder/src/builder/norm.cpp index de7a82c27b0..0c947be1f3e 100644 --- a/ngraph/core/builder/src/builder/norm.cpp +++ b/ngraph/core/builder/src/builder/norm.cpp @@ -23,6 +23,7 @@ namespace ngraph { namespace builder { namespace detail { namespace opset1 { +namespace { shared_ptr lp_norm(const Output& value, size_t p_norm, const Output& reduction_axes, @@ -47,6 +48,7 @@ shared_ptr lp_norm(const Output& value, return {make_shared(values, inv_p_node)}; } +} // namespace } // namespace opset1 } // namespace detail diff --git a/ngraph/core/builder/src/builder/reduce_ops.cpp b/ngraph/core/builder/src/builder/reduce_ops.cpp index b18083bc2c6..fe9ae58329d 100644 --- a/ngraph/core/builder/src/builder/reduce_ops.cpp +++ b/ngraph/core/builder/src/builder/reduce_ops.cpp @@ -19,6 +19,7 @@ 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) { @@ -38,6 +39,8 @@ std::shared_ptr get_num_elements(const Output& value, const Output 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(); diff --git a/ngraph/core/include/ngraph/ngraph.hpp b/ngraph/core/include/ngraph/ngraph.hpp index 8cee2eb06a0..63b440f5985 100644 --- a/ngraph/core/include/ngraph/ngraph.hpp +++ b/ngraph/core/include/ngraph/ngraph.hpp @@ -19,28 +19,6 @@ #include -// clang-format off -extern "C" NGRAPH_API -NGRAPH_DEPRECATED("This method is deprecated and will be removed soon") -const char* get_ngraph_version_string(); -// clang-format on - -namespace ngraph { -/// \brief Function to query parsed version information of the version of ngraph which -/// contains this function. Version information strictly follows Semantic Versioning -/// http://semver.org -/// \param major Returns the major part of the version -/// \param minor Returns the minor part of the version -/// \param patch Returns the patch part of the version -/// \param extra Returns the extra part of the version. This includes everything following -/// the patch version number. -/// -/// \note Throws a runtime_error if there is an error during parsing -NGRAPH_API -NGRAPH_DEPRECATED("This method is deprecated and will be removed soon") -void get_version(size_t& major, size_t& minor, size_t& patch, std::string& extra); -} // namespace ngraph - /// \namespace ngraph /// \brief The Intel nGraph C++ API. diff --git a/ngraph/core/include/ngraph/version.hpp b/ngraph/core/include/ngraph/version.hpp index 32b21432df4..9df5f4a1482 100644 --- a/ngraph/core/include/ngraph/version.hpp +++ b/ngraph/core/include/ngraph/version.hpp @@ -2,6 +2,31 @@ // SPDX-License-Identifier: Apache-2.0 // +#include + +#include "ngraph/deprecated.hpp" #include "ngraph/ngraph_visibility.hpp" NGRAPH_EXTERN_C NGRAPH_API const char* NGRAPH_VERSION_NUMBER; + +// clang-format off +extern "C" NGRAPH_API +NGRAPH_DEPRECATED("This method is deprecated and will be removed soon") +const char* get_ngraph_version_string(); +// clang-format on + +namespace ngraph { +/// \brief Function to query parsed version information of the version of ngraph which +/// contains this function. Version information strictly follows Semantic Versioning +/// http://semver.org +/// \param major Returns the major part of the version +/// \param minor Returns the minor part of the version +/// \param patch Returns the patch part of the version +/// \param extra Returns the extra part of the version. This includes everything following +/// the patch version number. +/// +/// \note Throws a runtime_error if there is an error during parsing +NGRAPH_API +NGRAPH_DEPRECATED("This method is deprecated and will be removed soon") +void get_version(size_t& major, size_t& minor, size_t& patch, std::string& extra); +} // namespace ngraph diff --git a/ngraph/core/include/openvino/core/function.hpp b/ngraph/core/include/openvino/core/function.hpp index 59b4ecde18f..7741b3efa14 100644 --- a/ngraph/core/include/openvino/core/function.hpp +++ b/ngraph/core/include/openvino/core/function.hpp @@ -145,7 +145,6 @@ public: std::vector> get_ordered_ops() const; void map_unordered_ops(std::function f) const; - friend std::ostream& operator<<(std::ostream&, const Function&); // updates graph and m_results list void replace_node(std::shared_ptr old, std::shared_ptr repl); @@ -312,6 +311,9 @@ private: RTMap m_rt_info; }; +OPENVINO_API +std::ostream& operator<<(std::ostream&, const Function&); + template <> class OPENVINO_API AttributeAdapter> : public DirectValueAccessor> { diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/scatter_update.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/scatter_update.hpp index 6224726d001..197cb208cff 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/scatter_update.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/scatter_update.hpp @@ -30,15 +30,15 @@ static const CoordinateTransformBasic get_target_shape(const Shape& data_shape, return target_shape; } -void scatter_update(const char* input_data, - const int64_t* indices, - const char* updates, - const int64_t axis, - char* out_buf, - const size_t elem_size, - const Shape& data_shape, - const Shape& indices_shape, - const Shape& updates_shape) { +static void scatter_update(const char* input_data, + const int64_t* indices, + const char* updates, + const int64_t axis, + char* out_buf, + const size_t elem_size, + const Shape& data_shape, + const Shape& indices_shape, + const Shape& updates_shape) { // Copy inputs to out std::memcpy(out_buf, input_data, elem_size * shape_size(data_shape)); diff --git a/ngraph/core/reference/src/runtime/reference/einsum.cpp b/ngraph/core/reference/src/runtime/reference/einsum.cpp index 4783ad2a21d..c9420224eda 100644 --- a/ngraph/core/reference/src/runtime/reference/einsum.cpp +++ b/ngraph/core/reference/src/runtime/reference/einsum.cpp @@ -19,7 +19,7 @@ namespace ngraph { namespace runtime { namespace reference { -namespace einsum_details { +namespace { /// \brief Compute einsum_path for a given Einsum node meaning that the /// (pseudo-)optimal order of operands contraction in terms of performance and /// memory consumption @@ -983,7 +983,7 @@ void einsum_impl(const HostTensorVector& inputs, const HostTensorVector& outputs outputs[0]->write(int_inputs[0]->get_data_ptr(), buf_size); } -} // namespace einsum_details +} // namespace void einsum(const HostTensorVector& outputs, const HostTensorVector& inputs, const std::string& equation) { NGRAPH_CHECK(inputs.size() > 0, "Einsum must accept at least one input."); @@ -992,9 +992,9 @@ void einsum(const HostTensorVector& outputs, const HostTensorVector& inputs, con NGRAPH_CHECK(inputs[input_ind]->get_element_type() == input_type, "Input types must be the same."); } if (input_type == element::Type_t::f32) { - einsum_details::einsum_impl(inputs, outputs, equation); + einsum_impl(inputs, outputs, equation); } else if (input_type == element::Type_t::i32) { - einsum_details::einsum_impl(inputs, outputs, equation); + einsum_impl(inputs, outputs, equation); } else { NGRAPH_CHECK(false, "Unsupported input type for Einsum operation."); } diff --git a/ngraph/core/reference/src/runtime/reference/pad.cpp b/ngraph/core/reference/src/runtime/reference/pad.cpp index c1f66347029..cb42847a8e6 100644 --- a/ngraph/core/reference/src/runtime/reference/pad.cpp +++ b/ngraph/core/reference/src/runtime/reference/pad.cpp @@ -162,7 +162,6 @@ struct SymmetricAndReflectPad : PadBase { int axis_correction{}; }; -} // namespace void pad(const char* data, const char* pad_value, @@ -194,6 +193,7 @@ void pad(const char* data, break; } } +} // namespace } // namespace impl namespace reference { diff --git a/ngraph/core/reference/src/runtime/reference/random_uniform.cpp b/ngraph/core/reference/src/runtime/reference/random_uniform.cpp index e183eba59aa..4205f434d7d 100644 --- a/ngraph/core/reference/src/runtime/reference/random_uniform.cpp +++ b/ngraph/core/reference/src/runtime/reference/random_uniform.cpp @@ -11,6 +11,7 @@ namespace ngraph { namespace runtime { namespace reference { +namespace { // Splits uint64 value into two uint32 values with right and left part of original value. std::pair split_high_low(uint64_t value) { @@ -176,6 +177,8 @@ void convert_to_output_type(const std::vector& res, memcpy(out + k * elem_type.size(), res_out_type.data(), std::min(step, elem_count - k) * elem_type.size()); } +} // namespace + // Implementation of RandomUniform that uses Philox algorithm as inner random unsigned integer generator. std::pair random_uniform(const uint64_t* out_shape, const char* min_val, diff --git a/ngraph/core/src/descriptor/tensor.cpp b/ngraph/core/src/descriptor/tensor.cpp index 291bb4d8ef3..2cf21ef978d 100644 --- a/ngraph/core/src/descriptor/tensor.cpp +++ b/ngraph/core/src/descriptor/tensor.cpp @@ -114,7 +114,7 @@ void ov::descriptor::Tensor::add_names(const std::unordered_set& na } } -ostream& operator<<(ostream& out, const ov::descriptor::Tensor& tensor) { +ostream& ov::descriptor::operator<<(ostream& out, const ov::descriptor::Tensor& tensor) { std::string names; for (const auto& name : tensor.get_names()) { if (!names.empty()) diff --git a/ngraph/core/src/function.cpp b/ngraph/core/src/function.cpp index d838d328d89..396a68f04ed 100644 --- a/ngraph/core/src/function.cpp +++ b/ngraph/core/src/function.cpp @@ -33,6 +33,8 @@ BWDCMP_RTTI_DEFINITION(ov::AttributeAdapter>); atomic ov::Function::m_next_instance_id(0); +namespace { + void check_all_variables_registered(const std::vector>& ordered_ops, const ov::op::util::VariableVector& variables) { OV_ITT_SCOPED_TASK(ov::itt::domains::nGraphPass_LT, "Function::check_all_variables_registered"); @@ -83,6 +85,8 @@ ngraph::ParameterVector auto_detect_parameters(const std::vectorbuildNumber; } -namespace ngraph { -NGRAPH_API void get_version(size_t& major, size_t& minor, size_t& patch, std::string& extra) { - NGRAPH_SUPPRESS_DEPRECATED_START +void ngraph::get_version(size_t& major, size_t& minor, size_t& patch, std::string& extra) { std::string version = get_ngraph_version_string(); ngraph::parse_version_string(version, major, minor, patch, extra); - NGRAPH_SUPPRESS_DEPRECATED_END } -} // namespace ngraph + +NGRAPH_SUPPRESS_DEPRECATED_END diff --git a/ngraph/core/src/op/abs.cpp b/ngraph/core/src/op/abs.cpp index 242efbbcad2..159850b650e 100644 --- a/ngraph/core/src/op/abs.cpp +++ b/ngraph/core/src/op/abs.cpp @@ -23,6 +23,7 @@ std::shared_ptr ov::op::v0::Abs::clone_with_new_inputs(const OutputVec } namespace absop { +namespace { template inline bool evaluate(const ngraph::HostTensorPtr& arg0, const ngraph::HostTensorPtr& out, const size_t count) { using T = typename ov::element_type_traits::value_type; @@ -49,6 +50,7 @@ bool evaluate_abs(const ngraph::HostTensorPtr& arg0, const ngraph::HostTensorPtr } return rc; } +} // namespace } // namespace absop bool ov::op::v0::Abs::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/acos.cpp b/ngraph/core/src/op/acos.cpp index aec704e1d2a..74ea20dc8cf 100644 --- a/ngraph/core/src/op/acos.cpp +++ b/ngraph/core/src/op/acos.cpp @@ -31,6 +31,7 @@ std::shared_ptr ov::op::v0::Acos::clone_with_new_inputs(const OutputVe } namespace acosop { +namespace { template inline bool evaluate(const ngraph::HostTensorPtr& arg0, const ngraph::HostTensorPtr& out, const size_t count) { using T = typename ov::element_type_traits::value_type; @@ -55,6 +56,7 @@ bool evaluate_acos(const ov::HostTensorPtr& arg0, const ov::HostTensorPtr& out, } return rc; } +} // namespace } // namespace acosop bool ov::op::v0::Acos::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/acosh.cpp b/ngraph/core/src/op/acosh.cpp index 85d56b0cd69..a1367565aad 100644 --- a/ngraph/core/src/op/acosh.cpp +++ b/ngraph/core/src/op/acosh.cpp @@ -25,6 +25,7 @@ std::shared_ptr ov::op::v3::Acosh::clone_with_new_inputs(const OutputV } namespace acoshop { +namespace { template bool evaluate(const ngraph::HostTensorPtr& arg0, const ngraph::HostTensorPtr& out) { ngraph::runtime::reference::acosh(arg0->get_data_ptr(), out->get_data_ptr(), shape_size(arg0->get_shape())); @@ -47,6 +48,7 @@ bool evaluate_acosh(const ngraph::HostTensorPtr& arg0, const ngraph::HostTensorP } return rc; } +} // namespace } // namespace acoshop bool ov::op::v3::Acosh::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/add.cpp b/ngraph/core/src/op/add.cpp index 98496ee7ab3..d4aa821b6e9 100644 --- a/ngraph/core/src/op/add.cpp +++ b/ngraph/core/src/op/add.cpp @@ -12,6 +12,7 @@ using namespace std; using namespace ngraph; namespace add { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -50,6 +51,7 @@ bool evaluate_add(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace add // ------------------------------- v1 ------------------------------------------ diff --git a/ngraph/core/src/op/asin.cpp b/ngraph/core/src/op/asin.cpp index c56c422dbe4..9947fbdbd95 100644 --- a/ngraph/core/src/op/asin.cpp +++ b/ngraph/core/src/op/asin.cpp @@ -35,6 +35,7 @@ shared_ptr op::Asin::clone_with_new_inputs(const OutputVector& new_args) c } namespace asinop { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -59,6 +60,7 @@ bool evaluate_asin(const HostTensorPtr& arg0, const HostTensorPtr& out, const si } return rc; } +} // namespace } // namespace asinop bool op::Asin::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/asinh.cpp b/ngraph/core/src/op/asinh.cpp index c70b52dc598..9cecf29ea58 100644 --- a/ngraph/core/src/op/asinh.cpp +++ b/ngraph/core/src/op/asinh.cpp @@ -29,6 +29,7 @@ shared_ptr op::v3::Asinh::clone_with_new_inputs(const OutputVector& new_ar } namespace asinhop { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { runtime::reference::asinh(arg0->get_data_ptr(), out->get_data_ptr(), count); @@ -53,6 +54,7 @@ bool evaluate_asinh(const HostTensorPtr& arg0, const HostTensorPtr& out) { } return rc; } +} // namespace } // namespace asinhop bool op::v3::Asinh::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/atan.cpp b/ngraph/core/src/op/atan.cpp index 2f8097eab26..7315f8fd32c 100644 --- a/ngraph/core/src/op/atan.cpp +++ b/ngraph/core/src/op/atan.cpp @@ -33,6 +33,7 @@ shared_ptr op::Atan::clone_with_new_inputs(const OutputVector& new_args) c } namespace atanop { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -57,6 +58,7 @@ bool evaluate_atan(const HostTensorPtr& arg0, const HostTensorPtr& out, const si } return rc; } +} // namespace } // namespace atanop bool op::Atan::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/atanh.cpp b/ngraph/core/src/op/atanh.cpp index f774e04b632..f82ec984e6f 100644 --- a/ngraph/core/src/op/atanh.cpp +++ b/ngraph/core/src/op/atanh.cpp @@ -28,6 +28,7 @@ shared_ptr op::v3::Atanh::clone_with_new_inputs(const OutputVector& new_ar } namespace atanhop { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out) { runtime::reference::atanh(arg0->get_data_ptr(), out->get_data_ptr(), shape_size(arg0->get_shape())); @@ -50,6 +51,7 @@ bool evaluate_atanh(const HostTensorPtr& arg0, const HostTensorPtr& out) { } return rc; } +} // namespace } // namespace atanhop bool op::v3::Atanh::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/ceiling.cpp b/ngraph/core/src/op/ceiling.cpp index d75b3aa05c2..5a92ea19eae 100644 --- a/ngraph/core/src/op/ceiling.cpp +++ b/ngraph/core/src/op/ceiling.cpp @@ -26,6 +26,7 @@ shared_ptr op::Ceiling::clone_with_new_inputs(const OutputVector& new_args } namespace ceiling { +namespace { // function used by TYPE_CASE template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { @@ -63,6 +64,7 @@ bool evaluate_ceiling(const HostTensorPtr& arg0, const HostTensorPtr& out, const } return rc; } +} // namespace } // namespace ceiling bool op::Ceiling::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/clamp.cpp b/ngraph/core/src/op/clamp.cpp index a2f3aa4e9de..4c459893632 100644 --- a/ngraph/core/src/op/clamp.cpp +++ b/ngraph/core/src/op/clamp.cpp @@ -14,6 +14,7 @@ using namespace std; using namespace ngraph; namespace clamp { +namespace { template bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out, T min, T max, size_t count) { runtime::reference::clamp(arg->get_data_ptr(), out->get_data_ptr(), min, max, count); @@ -68,6 +69,7 @@ bool evaluate_clamp(const HostTensorPtr& arg, const HostTensorPtr& out, double m } return rc; } +} // namespace } // namespace clamp bool op::v0::Clamp::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/convert.cpp b/ngraph/core/src/op/convert.cpp index 752bf4ad54b..47c98f082af 100644 --- a/ngraph/core/src/op/convert.cpp +++ b/ngraph/core/src/op/convert.cpp @@ -42,6 +42,7 @@ shared_ptr op::Convert::clone_with_new_inputs(const OutputVector& new_args } namespace convert { +namespace { template bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out) @@ -156,6 +157,7 @@ bool evaluate_bound(const Node* node, const HostTensorVector& output_values, boo } else return false; } +} // namespace } // namespace convert bool op::v0::Convert::evaluate(const HostTensorVector& output_values, const HostTensorVector& input_values) const { NGRAPH_OP_SCOPE(v0_Convert_evaluate); diff --git a/ngraph/core/src/op/cos.cpp b/ngraph/core/src/op/cos.cpp index 09bc54f4f0a..cbb7b9cce1a 100644 --- a/ngraph/core/src/op/cos.cpp +++ b/ngraph/core/src/op/cos.cpp @@ -30,6 +30,7 @@ shared_ptr op::Cos::clone_with_new_inputs(const OutputVector& new_args) co } namespace cosop { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -54,6 +55,7 @@ bool evaluate_cos(const HostTensorPtr& arg0, const HostTensorPtr& out, const siz } return rc; } +} // namespace } // namespace cosop bool op::Cos::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/cosh.cpp b/ngraph/core/src/op/cosh.cpp index f6b54fd11fb..bc832aa4d65 100644 --- a/ngraph/core/src/op/cosh.cpp +++ b/ngraph/core/src/op/cosh.cpp @@ -30,6 +30,7 @@ shared_ptr op::Cosh::clone_with_new_inputs(const OutputVector& new_args) c } namespace coshop { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -54,6 +55,7 @@ bool evaluate_cosh(const HostTensorPtr& arg0, const HostTensorPtr& out, const si } return rc; } +} // namespace } // namespace coshop bool op::Cosh::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/deformable_convolution.cpp b/ngraph/core/src/op/deformable_convolution.cpp index 6ccc6bbcd37..0bd45223306 100644 --- a/ngraph/core/src/op/deformable_convolution.cpp +++ b/ngraph/core/src/op/deformable_convolution.cpp @@ -177,6 +177,7 @@ std::shared_ptr op::v8::DeformableConvolution::clone_with_new_inputs(const } namespace deformable_convolution { +namespace { template inline bool evaluate(const HostTensorVector& inputs, const HostTensorPtr& out, @@ -294,6 +295,7 @@ bool evaluate_deformable_convolution(const HostTensorVector& inputs, } return rc; } +} // namespace } // namespace deformable_convolution bool op::v8::DeformableConvolution::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/depth_to_space.cpp b/ngraph/core/src/op/depth_to_space.cpp index 532888284c2..cd58c04a5e7 100644 --- a/ngraph/core/src/op/depth_to_space.cpp +++ b/ngraph/core/src/op/depth_to_space.cpp @@ -83,6 +83,7 @@ void op::DepthToSpace::validate_and_infer_types() { } } +namespace { bool evaluate_depth_to_space(const HostTensorVector& outputs, const HostTensorVector& inputs, const std::size_t block_size, @@ -102,6 +103,7 @@ bool evaluate_depth_to_space(const HostTensorVector& outputs, elem_size); return true; } +} // namespace bool op::DepthToSpace::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { NGRAPH_OP_SCOPE(v0_DepthToSpace_evaluate); diff --git a/ngraph/core/src/op/divide.cpp b/ngraph/core/src/op/divide.cpp index eb9af1a13c9..553ed4d3ff7 100644 --- a/ngraph/core/src/op/divide.cpp +++ b/ngraph/core/src/op/divide.cpp @@ -12,6 +12,7 @@ using namespace std; using namespace ngraph; namespace divide { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -49,6 +50,7 @@ bool evaluate_divide(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace divide // ------------------------------ v1 ------------------------------------------- diff --git a/ngraph/core/src/op/einsum.cpp b/ngraph/core/src/op/einsum.cpp index 2d580d836d7..62246d35221 100644 --- a/ngraph/core/src/op/einsum.cpp +++ b/ngraph/core/src/op/einsum.cpp @@ -24,6 +24,8 @@ op::v7::Einsum::Einsum(const OutputVector& inputs, const std::string& equation) constructor_validate_and_infer_types(); } +namespace { + /// \brief Check that a subscript contains only alphabetic letters or /// alphabetic letters with one ellipsis /// @@ -76,6 +78,8 @@ bool is_label_elsewhere(const std::vector& input_subscripts, return false; } +} // namespace + void op::v7::Einsum::parse_equation(const std::string& equation, std::vector& input_subscripts, std::string& output_subscript) { diff --git a/ngraph/core/src/op/equal.cpp b/ngraph/core/src/op/equal.cpp index a7d70bf5cd4..079e5760a26 100644 --- a/ngraph/core/src/op/equal.cpp +++ b/ngraph/core/src/op/equal.cpp @@ -12,6 +12,7 @@ using namespace std; using namespace ngraph; namespace equal { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -48,6 +49,7 @@ bool evaluate_equal(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace equal //------------------------------- v1 ------------------------------------------- diff --git a/ngraph/core/src/op/erf.cpp b/ngraph/core/src/op/erf.cpp index 2d97c9a85cf..ab02ad385fc 100644 --- a/ngraph/core/src/op/erf.cpp +++ b/ngraph/core/src/op/erf.cpp @@ -31,6 +31,7 @@ op::Erf::Erf(const Output& arg) : UnaryElementwiseArithmetic(arg) { } namespace erfop { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -55,6 +56,7 @@ bool evaluate_erf(const HostTensorPtr& arg0, const HostTensorPtr& out, const siz } return rc; } +} // namespace } // namespace erfop bool op::Erf::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/exp.cpp b/ngraph/core/src/op/exp.cpp index a2ed45611c4..23ba03295ab 100644 --- a/ngraph/core/src/op/exp.cpp +++ b/ngraph/core/src/op/exp.cpp @@ -31,6 +31,7 @@ shared_ptr op::Exp::clone_with_new_inputs(const OutputVector& new_args) co } namespace expop { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -56,6 +57,7 @@ bool evaluate_exp(const HostTensorPtr& arg0, const HostTensorPtr& out) { } return rc; } +} // namespace } // namespace expop bool op::Exp::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/fake_quantize.cpp b/ngraph/core/src/op/fake_quantize.cpp index ee42e1b9e83..7835dc579c5 100644 --- a/ngraph/core/src/op/fake_quantize.cpp +++ b/ngraph/core/src/op/fake_quantize.cpp @@ -77,6 +77,7 @@ shared_ptr op::FakeQuantize::clone_with_new_inputs(const OutputVector& new } namespace fakequantizeop { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -124,6 +125,7 @@ bool evaluate_fakequantize(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace fakequantizeop bool ngraph::op::FakeQuantize::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/floor.cpp b/ngraph/core/src/op/floor.cpp index 560306418e0..14c75605558 100644 --- a/ngraph/core/src/op/floor.cpp +++ b/ngraph/core/src/op/floor.cpp @@ -31,6 +31,7 @@ shared_ptr op::Floor::clone_with_new_inputs(const OutputVector& new_args) } namespace floorop { +namespace { // function used by TYPE_CASE template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { @@ -68,6 +69,7 @@ bool evaluate_floor(const HostTensorPtr& arg0, const HostTensorPtr& out, const s } return rc; } +} // namespace } // namespace floorop bool op::Floor::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/floor_mod.cpp b/ngraph/core/src/op/floor_mod.cpp index ae7ba178f5a..fdd41ee572c 100644 --- a/ngraph/core/src/op/floor_mod.cpp +++ b/ngraph/core/src/op/floor_mod.cpp @@ -25,6 +25,7 @@ shared_ptr op::v1::FloorMod::clone_with_new_inputs(const OutputVector& new } namespace floor_mod { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -61,6 +62,7 @@ bool evaluate_floor_mod(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace floor_mod bool op::v1::FloorMod::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/gelu.cpp b/ngraph/core/src/op/gelu.cpp index f39c4dcf777..21f268c9b8e 100644 --- a/ngraph/core/src/op/gelu.cpp +++ b/ngraph/core/src/op/gelu.cpp @@ -108,6 +108,7 @@ op::GeluApproximationMode op::v7::Gelu::get_approximation_mode() const { } namespace gelu { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, @@ -132,6 +133,7 @@ bool evaluate_gelu(const HostTensorPtr& arg0, const HostTensorPtr& out, op::Gelu } return rc; } +} // namespace } // namespace gelu bool op::v7::Gelu::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/greater.cpp b/ngraph/core/src/op/greater.cpp index afcea6e7841..0b37734e9be 100644 --- a/ngraph/core/src/op/greater.cpp +++ b/ngraph/core/src/op/greater.cpp @@ -12,6 +12,7 @@ using namespace std; using namespace ngraph; namespace greaterop { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -46,6 +47,7 @@ bool evaluate_greater(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace greaterop //-------------------------------------- v1 ------------------------------------ diff --git a/ngraph/core/src/op/greater_eq.cpp b/ngraph/core/src/op/greater_eq.cpp index 36a15466aab..660daebb732 100644 --- a/ngraph/core/src/op/greater_eq.cpp +++ b/ngraph/core/src/op/greater_eq.cpp @@ -13,6 +13,7 @@ using namespace std; using namespace ngraph; namespace greater_equalop { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -47,6 +48,7 @@ bool evaluate_greater_equal(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace greater_equalop //---------------------------------- v1 ---------------------------------------- diff --git a/ngraph/core/src/op/hswish.cpp b/ngraph/core/src/op/hswish.cpp index 637d36c564e..46b72b8c2e1 100644 --- a/ngraph/core/src/op/hswish.cpp +++ b/ngraph/core/src/op/hswish.cpp @@ -31,6 +31,7 @@ shared_ptr op::v4::HSwish::clone_with_new_inputs(const OutputVector& new_a } namespace hswish { +namespace { template inline bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -54,6 +55,7 @@ bool evaluate_hswish(const HostTensorPtr& arg, const HostTensorPtr& out) { } return rc; } +} // namespace } // namespace hswish bool op::v4::HSwish::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/less.cpp b/ngraph/core/src/op/less.cpp index 1963750bfe0..48e8eae36cd 100644 --- a/ngraph/core/src/op/less.cpp +++ b/ngraph/core/src/op/less.cpp @@ -12,6 +12,7 @@ using namespace std; using namespace ngraph; namespace lessop { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -46,6 +47,7 @@ bool evaluate_less(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace lessop // ----------------------------- v1 -------------------------------------------- diff --git a/ngraph/core/src/op/less_eq.cpp b/ngraph/core/src/op/less_eq.cpp index 0eaee94a192..338e137b24e 100644 --- a/ngraph/core/src/op/less_eq.cpp +++ b/ngraph/core/src/op/less_eq.cpp @@ -29,6 +29,7 @@ shared_ptr op::v1::LessEqual::clone_with_new_inputs(const OutputVector& ne } namespace less_equalop { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -63,6 +64,7 @@ bool evaluate_less_equal(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace less_equalop bool op::v1::LessEqual::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/log.cpp b/ngraph/core/src/op/log.cpp index faa4d2696b7..c1d7878ab8c 100644 --- a/ngraph/core/src/op/log.cpp +++ b/ngraph/core/src/op/log.cpp @@ -30,6 +30,7 @@ shared_ptr op::Log::clone_with_new_inputs(const OutputVector& new_args) co } namespace logop { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -55,6 +56,7 @@ bool evaluate_log(const HostTensorPtr& arg0, const HostTensorPtr& out, const siz } return rc; } +} // namespace } // namespace logop bool op::Log::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/logical_and.cpp b/ngraph/core/src/op/logical_and.cpp index c6847551a02..03367f9c3a8 100644 --- a/ngraph/core/src/op/logical_and.cpp +++ b/ngraph/core/src/op/logical_and.cpp @@ -33,6 +33,7 @@ shared_ptr op::v1::LogicalAnd::clone_with_new_inputs(const OutputVector& n } namespace logand { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -61,6 +62,7 @@ bool evaluate_logand(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace logand bool op::v1::LogicalAnd::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/logical_not.cpp b/ngraph/core/src/op/logical_not.cpp index b38d5e1262b..abc11584581 100644 --- a/ngraph/core/src/op/logical_not.cpp +++ b/ngraph/core/src/op/logical_not.cpp @@ -40,6 +40,7 @@ shared_ptr op::v1::LogicalNot::clone_with_new_inputs(const OutputVector& n } namespace notop { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -65,6 +66,7 @@ bool evaluate_not(const HostTensorPtr& arg0, const HostTensorPtr& out, const siz } return rc; } +} // namespace } // namespace notop bool op::v1::LogicalNot::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/logical_or.cpp b/ngraph/core/src/op/logical_or.cpp index 39fc88581dd..c4e7955eb98 100644 --- a/ngraph/core/src/op/logical_or.cpp +++ b/ngraph/core/src/op/logical_or.cpp @@ -27,6 +27,7 @@ shared_ptr op::v1::LogicalOr::clone_with_new_inputs(const OutputVector& ne } namespace logor { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -55,6 +56,7 @@ bool evaluate_logor(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace logor bool op::v1::LogicalOr::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/lstm_cell.cpp b/ngraph/core/src/op/lstm_cell.cpp index 0e7b7221d33..b62403adf02 100644 --- a/ngraph/core/src/op/lstm_cell.cpp +++ b/ngraph/core/src/op/lstm_cell.cpp @@ -350,7 +350,7 @@ BWDCMP_RTTI_DEFINITION(AttributeAdapter); } // namespace ov -std::ostream& operator<<(std::ostream& s, const op::LSTMWeightsFormat& type) { +std::ostream& ov::operator<<(std::ostream& s, const op::LSTMWeightsFormat& type) { return s << as_string(type); } diff --git a/ngraph/core/src/op/matmul.cpp b/ngraph/core/src/op/matmul.cpp index 5e3414976f5..f0febdcdea7 100644 --- a/ngraph/core/src/op/matmul.cpp +++ b/ngraph/core/src/op/matmul.cpp @@ -38,6 +38,7 @@ shared_ptr op::MatMul::clone_with_new_inputs(const OutputVector& new_args) } namespace matmul { +namespace { ov::PartialShape validate_matmul_output_shape(const ov::PartialShape& arg0_shape, const ov::PartialShape& arg1_shape, bool transpose_a, @@ -222,6 +223,7 @@ bool evaluate_matmul(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace matmul bool op::MatMul::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/max_pool.cpp b/ngraph/core/src/op/max_pool.cpp index 657fa9376bb..afb78c6fe3b 100644 --- a/ngraph/core/src/op/max_pool.cpp +++ b/ngraph/core/src/op/max_pool.cpp @@ -66,6 +66,7 @@ shared_ptr op::v1::MaxPool::get_default_value() const { } namespace maxpool { +namespace { template inline bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out, @@ -110,6 +111,7 @@ bool evaluate_maxpool(const HostTensorPtr& arg, } return rc; } +} // namespace } // namespace maxpool bool op::v1::MaxPool::evaluate_maxpool(const HostTensorVector& outputs, const HostTensorVector& inputs) const { @@ -161,6 +163,7 @@ bool op::v1::MaxPool::has_evaluate() const { // ------------------------------ V8 ------------------------------ namespace maxpool_v8 { +namespace { template inline bool evaluate(const HostTensorPtr& data, const HostTensorPtr& values, @@ -248,6 +251,7 @@ bool evaluate_maxpool(const HostTensorPtr& data, return rc; } +} // namespace } // namespace maxpool_v8 op::v8::MaxPool::MaxPool(const Output& arg, diff --git a/ngraph/core/src/op/maximum.cpp b/ngraph/core/src/op/maximum.cpp index b488083376a..d70d5b71104 100644 --- a/ngraph/core/src/op/maximum.cpp +++ b/ngraph/core/src/op/maximum.cpp @@ -20,6 +20,7 @@ using namespace ngraph; // ------------------------------------ v0 ------------------------------------- namespace maximumop { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -53,6 +54,7 @@ bool evaluate_maximum(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace maximumop // ------------------------------------ v1 ------------------------------------- diff --git a/ngraph/core/src/op/minimum.cpp b/ngraph/core/src/op/minimum.cpp index 9fd2881eddb..b55d8d6a942 100644 --- a/ngraph/core/src/op/minimum.cpp +++ b/ngraph/core/src/op/minimum.cpp @@ -18,6 +18,7 @@ using namespace std; using namespace ngraph; namespace minimumop { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -53,6 +54,7 @@ bool evaluate_minimum(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace minimumop // ------------------------------ v1 ------------------------------------------- diff --git a/ngraph/core/src/op/mish.cpp b/ngraph/core/src/op/mish.cpp index 5e3e6845789..d8ff4ef1144 100644 --- a/ngraph/core/src/op/mish.cpp +++ b/ngraph/core/src/op/mish.cpp @@ -47,6 +47,7 @@ shared_ptr op::v4::Mish::clone_with_new_inputs(const OutputVector& new_arg } namespace mish { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -68,6 +69,7 @@ bool evaluate_mish(const HostTensorPtr& arg0, const HostTensorPtr& out) { } return rc; } +} // namespace } // namespace mish bool op::v4::Mish::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/multiply.cpp b/ngraph/core/src/op/multiply.cpp index a14222eb434..a72a561e22e 100644 --- a/ngraph/core/src/op/multiply.cpp +++ b/ngraph/core/src/op/multiply.cpp @@ -12,6 +12,7 @@ using namespace std; using namespace ngraph; namespace multiplyop { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -46,6 +47,7 @@ bool evaluate_multiply(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace multiplyop // ------------------------------------ v1 ------------------------------------- diff --git a/ngraph/core/src/op/negative.cpp b/ngraph/core/src/op/negative.cpp index c87ade2fd5d..a58ff5f9641 100644 --- a/ngraph/core/src/op/negative.cpp +++ b/ngraph/core/src/op/negative.cpp @@ -30,6 +30,7 @@ shared_ptr op::Negative::clone_with_new_inputs(const OutputVector& new_arg } namespace negativeop { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -53,6 +54,7 @@ bool evaluate_negative(const HostTensorPtr& arg0, const HostTensorPtr& out, cons } return rc; } +} // namespace } // namespace negativeop bool op::Negative::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/non_zero.cpp b/ngraph/core/src/op/non_zero.cpp index 5cd0baa1f02..37f044c4e5a 100644 --- a/ngraph/core/src/op/non_zero.cpp +++ b/ngraph/core/src/op/non_zero.cpp @@ -77,6 +77,7 @@ shared_ptr op::v3::NonZero::clone_with_new_inputs(const OutputVector& new_ } namespace nonzero { +namespace { template bool evaluate_nonzero_execute(const HostTensorPtr& input, const HostTensorPtr& output) { using IN_T = typename element_type_traits::value_type; @@ -145,6 +146,7 @@ bool evaluate_nonzero(const HostTensorPtr& input, const HostTensorPtr& output) { } return rc; } +} // namespace } // namespace nonzero bool op::v3::NonZero::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/not_equal.cpp b/ngraph/core/src/op/not_equal.cpp index 66e5e7ca45e..484a66cf3c7 100644 --- a/ngraph/core/src/op/not_equal.cpp +++ b/ngraph/core/src/op/not_equal.cpp @@ -13,6 +13,7 @@ using namespace std; using namespace ngraph; namespace not_equalop { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -47,6 +48,7 @@ bool evaluate_not_equal(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace not_equalop // ----------------------------------- v1 -------------------------------------- diff --git a/ngraph/core/src/op/one_hot.cpp b/ngraph/core/src/op/one_hot.cpp index d28dccf7bcc..64f42cfef6f 100644 --- a/ngraph/core/src/op/one_hot.cpp +++ b/ngraph/core/src/op/one_hot.cpp @@ -110,6 +110,7 @@ shared_ptr op::v1::OneHot::clone_with_new_inputs(const OutputVector& new_a } namespace one_hot { +namespace { template bool evaluate(const HostTensorVector& output_values, const HostTensorVector& input_values, const int64_t axis) { using INPUT_TYPE = typename element_type_traits::value_type; @@ -138,6 +139,7 @@ bool evaluate_onehot(const HostTensorVector& output_values, const HostTensorVect } return rc; } +} // namespace } // namespace one_hot bool op::v1::OneHot::evaluate(const HostTensorVector& output_values, const HostTensorVector& input_values) const { diff --git a/ngraph/core/src/op/power.cpp b/ngraph/core/src/op/power.cpp index 62e7a7f003e..456bd80c733 100644 --- a/ngraph/core/src/op/power.cpp +++ b/ngraph/core/src/op/power.cpp @@ -15,6 +15,7 @@ using namespace std; using namespace ngraph; namespace power { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -49,6 +50,7 @@ bool evaluate_power(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace power // ------------------------------ v1 ------------------------------------------- diff --git a/ngraph/core/src/op/prelu.cpp b/ngraph/core/src/op/prelu.cpp index 12a10b31346..7211d5a564b 100644 --- a/ngraph/core/src/op/prelu.cpp +++ b/ngraph/core/src/op/prelu.cpp @@ -37,6 +37,7 @@ shared_ptr ov::op::v0::PRelu::clone_with_new_inputs(const OutputVector } namespace prelu { +namespace { template bool evaluate(const ngraph::HostTensorPtr& arg, const ngraph::HostTensorPtr& slope, const ngraph::HostTensorPtr& out) { ngraph::runtime::reference::prelu(arg->get_data_ptr(), @@ -62,6 +63,7 @@ bool evaluate_prelu(const ngraph::HostTensorPtr& arg, } return rc; } +} // namespace } // namespace prelu bool ov::op::v0::PRelu::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/prior_box.cpp b/ngraph/core/src/op/prior_box.cpp index 4d77785e672..b19b136cd09 100644 --- a/ngraph/core/src/op/prior_box.cpp +++ b/ngraph/core/src/op/prior_box.cpp @@ -131,6 +131,7 @@ bool op::PriorBox::visit_attributes(AttributeVisitor& visitor) { } namespace prior_box { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -164,6 +165,7 @@ bool evaluate_prior_box(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace prior_box bool op::v0::PriorBox::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/prior_box_clustered.cpp b/ngraph/core/src/op/prior_box_clustered.cpp index 25a081f68c6..d9c7fbfdcff 100644 --- a/ngraph/core/src/op/prior_box_clustered.cpp +++ b/ngraph/core/src/op/prior_box_clustered.cpp @@ -106,6 +106,7 @@ bool ov::op::v0::PriorBoxClustered::visit_attributes(AttributeVisitor& visitor) } namespace prior_box_clustered { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -139,6 +140,7 @@ bool evaluate_prior_box(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace prior_box_clustered bool op::v0::PriorBoxClustered::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/range.cpp b/ngraph/core/src/op/range.cpp index a2b11560691..4d850eb7667 100644 --- a/ngraph/core/src/op/range.cpp +++ b/ngraph/core/src/op/range.cpp @@ -190,6 +190,7 @@ bool get_casted_value(const HostTensorPtr& tensor, T* val) { } namespace rangeop { +namespace { template bool evaluate(const HostTensorPtr& out, const HostTensorPtr& start, @@ -253,6 +254,7 @@ bool evaluate_power(const HostTensorPtr& out, } return rc; } +} // namespace } // namespace rangeop bool op::v4::Range::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/reduce_l1.cpp b/ngraph/core/src/op/reduce_l1.cpp index db37be1e7da..384ea11b380 100644 --- a/ngraph/core/src/op/reduce_l1.cpp +++ b/ngraph/core/src/op/reduce_l1.cpp @@ -36,6 +36,7 @@ shared_ptr op::v4::ReduceL1::clone_with_new_inputs(const OutputVector& new } namespace reduce_l1 { +namespace { template bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out, const AxisSet& axes, bool keep_dims) { out->set_shape(reduce(arg->get_shape(), axes, keep_dims)); @@ -57,6 +58,7 @@ bool evaluate_sum(const HostTensorPtr& arg, const HostTensorPtr& out, const Axis } return rc; } +} // namespace } // namespace reduce_l1 bool op::v4::ReduceL1::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/reduce_l2.cpp b/ngraph/core/src/op/reduce_l2.cpp index 79b94078b02..ee681ab3c93 100644 --- a/ngraph/core/src/op/reduce_l2.cpp +++ b/ngraph/core/src/op/reduce_l2.cpp @@ -36,6 +36,7 @@ shared_ptr op::v4::ReduceL2::clone_with_new_inputs(const OutputVector& new } namespace reduce_l2 { +namespace { template bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out, const AxisSet& axes, bool keep_dims) { out->set_shape(reduce(arg->get_shape(), axes, keep_dims)); @@ -55,6 +56,7 @@ bool evaluate_reduce_l2(const HostTensorPtr& arg, const HostTensorPtr& out, cons } return rc; } +} // namespace } // namespace reduce_l2 bool op::v4::ReduceL2::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/reduce_logical_and.cpp b/ngraph/core/src/op/reduce_logical_and.cpp index e6630fe356e..edee6d8dd31 100644 --- a/ngraph/core/src/op/reduce_logical_and.cpp +++ b/ngraph/core/src/op/reduce_logical_and.cpp @@ -31,6 +31,7 @@ shared_ptr op::v1::ReduceLogicalAnd::clone_with_new_inputs(const OutputVec } namespace reduce_and { +namespace { bool evaluate_reduce_logical_and(const HostTensorPtr& data, const HostTensorPtr& out, const AxisSet& reduction_axes, @@ -47,6 +48,7 @@ bool evaluate_reduce_logical_and(const HostTensorPtr& data, return false; } } +} // namespace } // namespace reduce_and bool op::v1::ReduceLogicalAnd::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/reduce_logical_or.cpp b/ngraph/core/src/op/reduce_logical_or.cpp index 8fdb87482b7..82b866b6993 100644 --- a/ngraph/core/src/op/reduce_logical_or.cpp +++ b/ngraph/core/src/op/reduce_logical_or.cpp @@ -31,6 +31,7 @@ shared_ptr op::v1::ReduceLogicalOr::clone_with_new_inputs(const OutputVect } namespace reduce_or { +namespace { bool evaluate_reduce_logical_or(const HostTensorPtr& data, const HostTensorPtr& out, const AxisSet& reduction_axes, @@ -47,6 +48,7 @@ bool evaluate_reduce_logical_or(const HostTensorPtr& data, return false; } } +} // namespace } // namespace reduce_or bool op::v1::ReduceLogicalOr::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/reduce_max.cpp b/ngraph/core/src/op/reduce_max.cpp index 3765be586fe..6dddb7bb60a 100644 --- a/ngraph/core/src/op/reduce_max.cpp +++ b/ngraph/core/src/op/reduce_max.cpp @@ -16,6 +16,7 @@ using namespace std; using namespace ngraph; namespace maxop { +namespace { template bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out, const AxisSet& axes, bool keep_dims) { out->set_shape(reduce(arg->get_shape(), axes, keep_dims)); @@ -38,6 +39,7 @@ bool evaluate_max(const HostTensorPtr& arg, const HostTensorPtr& out, const Axis } return rc; } +} // namespace } // namespace maxop BWDCMP_RTTI_DEFINITION(op::v1::ReduceMax); diff --git a/ngraph/core/src/op/reduce_mean.cpp b/ngraph/core/src/op/reduce_mean.cpp index a60711b4e9e..6b88a895d97 100644 --- a/ngraph/core/src/op/reduce_mean.cpp +++ b/ngraph/core/src/op/reduce_mean.cpp @@ -31,6 +31,7 @@ shared_ptr op::v1::ReduceMean::clone_with_new_inputs(const OutputVector& n } namespace mean { +namespace { template bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out, const AxisSet& axes, bool keep_dims) { out->set_shape(reduce(arg->get_shape(), axes, keep_dims)); @@ -53,6 +54,7 @@ bool evaluate_mean(const HostTensorPtr& arg, const HostTensorPtr& out, const Axi } return rc; } +} // namespace } // namespace mean bool op::v1::ReduceMean::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/reduce_min.cpp b/ngraph/core/src/op/reduce_min.cpp index 0c11afc1642..fb8bb22a9ba 100644 --- a/ngraph/core/src/op/reduce_min.cpp +++ b/ngraph/core/src/op/reduce_min.cpp @@ -15,6 +15,7 @@ using namespace std; using namespace ngraph; namespace minop { +namespace { template bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out, const AxisSet& axes, const bool keep_dims) { out->set_shape(reduce(arg->get_shape(), axes, keep_dims)); @@ -37,6 +38,7 @@ bool evaluate_min(const HostTensorPtr& arg, const HostTensorPtr& out, const Axis } return rc; } +} // namespace } // namespace minop BWDCMP_RTTI_DEFINITION(op::v1::ReduceMin); diff --git a/ngraph/core/src/op/reduce_prod.cpp b/ngraph/core/src/op/reduce_prod.cpp index d5217794b83..2ca70c0dd18 100644 --- a/ngraph/core/src/op/reduce_prod.cpp +++ b/ngraph/core/src/op/reduce_prod.cpp @@ -36,6 +36,7 @@ shared_ptr op::v1::ReduceProd::clone_with_new_inputs(const OutputVector& n } namespace reduce_prod { +namespace { template bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out, const AxisSet& axes, bool keep_dims) { out->set_shape(reduce(arg->get_shape(), axes, keep_dims)); @@ -57,7 +58,8 @@ bool evaluate_product(const HostTensorPtr& arg, const HostTensorPtr& out, const break; } return rc; -} +} // namespace +} // namespace } // namespace reduce_prod bool op::v1::ReduceProd::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/reduce_sum.cpp b/ngraph/core/src/op/reduce_sum.cpp index ddd739548c4..b8f81922833 100644 --- a/ngraph/core/src/op/reduce_sum.cpp +++ b/ngraph/core/src/op/reduce_sum.cpp @@ -38,6 +38,7 @@ shared_ptr op::v1::ReduceSum::clone_with_new_inputs(const OutputVector& ne } namespace reduce_sum { +namespace { template bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out, const AxisSet& axes, bool keep_dims) { out->set_shape(reduce(arg->get_shape(), axes, keep_dims)); @@ -59,7 +60,8 @@ bool evaluate_sum(const HostTensorPtr& arg, const HostTensorPtr& out, const Axis break; } return rc; -} +} // namespace +} // namespace } // namespace reduce_sum bool op::v1::ReduceSum::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/relu.cpp b/ngraph/core/src/op/relu.cpp index b68e9d714d7..097a4713cca 100644 --- a/ngraph/core/src/op/relu.cpp +++ b/ngraph/core/src/op/relu.cpp @@ -27,6 +27,7 @@ shared_ptr op::Relu::clone_with_new_inputs(const OutputVector& new_args) c } namespace relu { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -53,6 +54,7 @@ bool evaluate_relu(const HostTensorPtr& arg0, const HostTensorPtr& out) { } return rc; } +} // namespace } // namespace relu bool op::Relu::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/reshape.cpp b/ngraph/core/src/op/reshape.cpp index bd0f2fa5f5a..e13718a812a 100644 --- a/ngraph/core/src/op/reshape.cpp +++ b/ngraph/core/src/op/reshape.cpp @@ -16,6 +16,7 @@ using namespace std; using namespace ngraph; namespace reshapeop { +namespace { bool evaluate_reshape(const HostTensorPtr& arg0, const HostTensorPtr& out, const AxisVector& order) { runtime::opt_kernel::reshape(arg0->get_data_ptr(), out->get_data_ptr(), @@ -35,6 +36,7 @@ void compute_output_shape(const HostTensorPtr& shape_pattern, std::vector& EnumNames bool evaluate(const HostTensorPtr& feature_maps, const HostTensorPtr& rois, @@ -264,6 +265,7 @@ bool evaluate_roi_align(const HostTensorVector& args, return rc; } +} // namespace } // namespace roi_alinop bool op::v3::ROIAlign::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/round.cpp b/ngraph/core/src/op/round.cpp index 90015a2f107..bc15db2efef 100644 --- a/ngraph/core/src/op/round.cpp +++ b/ngraph/core/src/op/round.cpp @@ -15,6 +15,7 @@ using namespace std; using namespace ngraph; namespace roundop { +namespace { // function used by TYPE_CASE template inline bool evaluate(const HostTensorPtr& arg0, @@ -59,6 +60,7 @@ bool evaluate_round(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace roundop BWDCMP_RTTI_DEFINITION(op::v5::Round); diff --git a/ngraph/core/src/op/scatter_elements_update.cpp b/ngraph/core/src/op/scatter_elements_update.cpp index 10aca33eba5..6f151e11db8 100644 --- a/ngraph/core/src/op/scatter_elements_update.cpp +++ b/ngraph/core/src/op/scatter_elements_update.cpp @@ -116,6 +116,7 @@ shared_ptr op::v3::ScatterElementsUpdate::clone_with_new_inputs(const Outp } namespace scatter_element_update { +namespace { template bool evaluate(const HostTensorPtr& data, const HostTensorPtr& indices, @@ -229,6 +230,7 @@ bool evaluate_scatter_element_update(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace scatter_element_update bool op::v3::ScatterElementsUpdate::evaluate_scatter_element_update(const HostTensorVector& outputs, diff --git a/ngraph/core/src/op/scatter_nd_update.cpp b/ngraph/core/src/op/scatter_nd_update.cpp index 0b002890f66..39dde4e9be0 100644 --- a/ngraph/core/src/op/scatter_nd_update.cpp +++ b/ngraph/core/src/op/scatter_nd_update.cpp @@ -23,6 +23,7 @@ shared_ptr op::v3::ScatterNDUpdate::clone_with_new_inputs(const OutputVect } namespace scatter { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -78,6 +79,7 @@ bool evaluate_scatter(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace scatter bool op::v3::ScatterNDUpdate::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/scatter_update.cpp b/ngraph/core/src/op/scatter_update.cpp index 8e7e255466f..42cf8b3d47b 100644 --- a/ngraph/core/src/op/scatter_update.cpp +++ b/ngraph/core/src/op/scatter_update.cpp @@ -29,11 +29,13 @@ shared_ptr op::v3::ScatterUpdate::clone_with_new_inputs(const OutputVector } namespace scatter_update { +namespace { template std::vector get_indices(const HostTensorPtr& in) { auto data_ptr = in->get_data_ptr(); return std::vector(data_ptr, data_ptr + in->get_element_count()); } +} // namespace } // namespace scatter_update #define GET_INDICES(a, ...) \ diff --git a/ngraph/core/src/op/select.cpp b/ngraph/core/src/op/select.cpp index e1a0dc5f933..15f6af798e8 100644 --- a/ngraph/core/src/op/select.cpp +++ b/ngraph/core/src/op/select.cpp @@ -87,6 +87,7 @@ bool op::v1::Select::visit_attributes(AttributeVisitor& visitor) { } namespace detail { +namespace { template bool evaluate(const HostTensorVector& output_values, const HostTensorVector& input_values, @@ -137,6 +138,7 @@ bool evaluate_select(const HostTensorVector& output_values, return rc; } +} // namespace } // namespace detail bool op::v1::Select::evaluate(const HostTensorVector& output_values, const HostTensorVector& input_values) const { diff --git a/ngraph/core/src/op/shape_of.cpp b/ngraph/core/src/op/shape_of.cpp index 226be6e5c4e..1ed1d31b446 100644 --- a/ngraph/core/src/op/shape_of.cpp +++ b/ngraph/core/src/op/shape_of.cpp @@ -50,6 +50,7 @@ shared_ptr op::v3::ShapeOf::clone_with_new_inputs(const OutputVector& new_ } namespace shape_of { +namespace { template inline bool evaluate(const ov::Shape& shape, const HostTensorPtr& output_value) { runtime::reference::shape_of(shape, output_value->get_data_ptr()); @@ -147,6 +148,7 @@ bool evaluate_bound_shape(const Node* shape_of_node, const HostTensorVector& out } return true; } +} // namespace } // namespace shape_of bool op::v3::ShapeOf::evaluate(const HostTensorVector& output_values, const HostTensorVector& input_values) const { diff --git a/ngraph/core/src/op/sigmoid.cpp b/ngraph/core/src/op/sigmoid.cpp index 785683f7484..adb2562763f 100644 --- a/ngraph/core/src/op/sigmoid.cpp +++ b/ngraph/core/src/op/sigmoid.cpp @@ -28,6 +28,7 @@ ov::op::v0::Sigmoid::Sigmoid(const Output& arg) : UnaryElementwiseArithmet } namespace sigmoid { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -53,6 +54,7 @@ bool evaluate_sigmoid(const HostTensorPtr& arg0, const HostTensorPtr& out) { } return rc; } +} // namespace } // namespace sigmoid bool ov::op::v0::Sigmoid::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/sign.cpp b/ngraph/core/src/op/sign.cpp index 00b5f29d14b..7ac52000eed 100644 --- a/ngraph/core/src/op/sign.cpp +++ b/ngraph/core/src/op/sign.cpp @@ -30,6 +30,7 @@ shared_ptr op::Sign::clone_with_new_inputs(const OutputVector& new_args) c } namespace signop { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -54,6 +55,7 @@ bool evaluate_sign(const HostTensorPtr& arg0, const HostTensorPtr& out, const si } return rc; } +} // namespace } // namespace signop bool op::Sign::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/sin.cpp b/ngraph/core/src/op/sin.cpp index f690965db05..aa474cd5bdf 100644 --- a/ngraph/core/src/op/sin.cpp +++ b/ngraph/core/src/op/sin.cpp @@ -31,6 +31,7 @@ shared_ptr op::Sin::clone_with_new_inputs(const OutputVector& new_args) co } namespace sinop { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -55,6 +56,7 @@ bool evaluate_sin(const HostTensorPtr& arg0, const HostTensorPtr& out, const siz } return rc; } +} // namespace } // namespace sinop bool op::Sin::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/sinh.cpp b/ngraph/core/src/op/sinh.cpp index 41f855e2052..35c2195e650 100644 --- a/ngraph/core/src/op/sinh.cpp +++ b/ngraph/core/src/op/sinh.cpp @@ -30,6 +30,7 @@ shared_ptr op::Sinh::clone_with_new_inputs(const OutputVector& new_args) c } namespace sinhop { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -54,6 +55,7 @@ bool evaluate_sinh(const HostTensorPtr& arg0, const HostTensorPtr& out, const si } return rc; } +} // namespace } // namespace sinhop bool op::Sinh::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/softplus.cpp b/ngraph/core/src/op/softplus.cpp index 986c44d4c49..d3ebccb8f5d 100644 --- a/ngraph/core/src/op/softplus.cpp +++ b/ngraph/core/src/op/softplus.cpp @@ -45,6 +45,7 @@ shared_ptr op::v4::SoftPlus::clone_with_new_inputs(const OutputVector& new } namespace softplus { +namespace { template inline bool evaluate(const HostTensorPtr& arg, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -67,6 +68,7 @@ bool evaluate_softplus(const HostTensorPtr& arg, const HostTensorPtr& out) { } return rc; } +} // namespace } // namespace softplus bool op::v4::SoftPlus::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/space_to_depth.cpp b/ngraph/core/src/op/space_to_depth.cpp index 47e48f0597a..14fff599f81 100644 --- a/ngraph/core/src/op/space_to_depth.cpp +++ b/ngraph/core/src/op/space_to_depth.cpp @@ -85,6 +85,7 @@ void ngraph::op::v0::SpaceToDepth::validate_and_infer_types() { } } +namespace { bool evaluate_space_to_depth(const HostTensorVector& outputs, const HostTensorVector& inputs, const std::size_t block_size, @@ -106,6 +107,8 @@ bool evaluate_space_to_depth(const HostTensorVector& outputs, elem_size); return true; } +} // namespace + bool ngraph::op::v0::SpaceToDepth::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { NGRAPH_OP_SCOPE(v0_SpaceToDepth_evaluate); return evaluate_space_to_depth(outputs, inputs, m_blocksize, m_mode); diff --git a/ngraph/core/src/op/split.cpp b/ngraph/core/src/op/split.cpp index 1259203ac0a..d23971d207a 100644 --- a/ngraph/core/src/op/split.cpp +++ b/ngraph/core/src/op/split.cpp @@ -104,6 +104,7 @@ shared_ptr op::v1::Split::clone_with_new_inputs(const OutputVector& new_ar } namespace split { +namespace { inline bool evaluate(const HostTensorPtr& data_tensor, const HostTensorVector& outputs, const int64_t axis, @@ -137,6 +138,7 @@ bool evaluate_split(const HostTensorPtr& data_tensor, evaluate(data_tensor, outputs, axis, num_splits); return true; } +} // namespace } // namespace split bool op::v1::Split::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/sqrt.cpp b/ngraph/core/src/op/sqrt.cpp index f8357f4ce1b..abbd4488523 100644 --- a/ngraph/core/src/op/sqrt.cpp +++ b/ngraph/core/src/op/sqrt.cpp @@ -31,6 +31,7 @@ shared_ptr op::Sqrt::clone_with_new_inputs(const OutputVector& new_args) c } namespace sqrtop { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -55,6 +56,7 @@ bool evaluate_sqrt(const HostTensorPtr& arg0, const HostTensorPtr& out, const si } return rc; } +} // namespace } // namespace sqrtop bool op::Sqrt::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/squeeze.cpp b/ngraph/core/src/op/squeeze.cpp index 9a73a3a3b0c..f1567482a1a 100644 --- a/ngraph/core/src/op/squeeze.cpp +++ b/ngraph/core/src/op/squeeze.cpp @@ -137,6 +137,7 @@ shared_ptr op::Squeeze::clone_with_new_inputs(const OutputVector& new_args } namespace squeeze { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, const HostTensorPtr& out) { const auto data_rank = arg0->get_partial_shape().rank().get_length(); @@ -203,6 +204,7 @@ bool evaluate_squeeze(const HostTensorPtr& arg0, const HostTensorPtr& arg1, cons bool evaluate_squeeze(const HostTensorPtr& arg0, const HostTensorPtr& out) { return evaluate(arg0, out); } +} // namespace } // namespace squeeze bool op::v0::Squeeze::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/strided_slice.cpp b/ngraph/core/src/op/strided_slice.cpp index 398945904fe..003f909d9e7 100644 --- a/ngraph/core/src/op/strided_slice.cpp +++ b/ngraph/core/src/op/strided_slice.cpp @@ -202,6 +202,7 @@ shared_ptr op::v1::StridedSlice::clone_with_new_inputs(const OutputVector& } namespace strided_slice { +namespace { inline bool evaluate(const HostTensorPtr& in, const SlicePlan& sp, const HostTensorPtr& out) { @@ -239,6 +240,7 @@ bool evaluate_strided_slice(const HostTensorPtr& in, ellipsis_mask); return evaluate(in, slice_plan, out); } +} // namespace } // namespace strided_slice bool op::v1::StridedSlice::evaluate(const HostTensorVector& output_values, const HostTensorVector& input_values) const { diff --git a/ngraph/core/src/op/subtract.cpp b/ngraph/core/src/op/subtract.cpp index 10c968c7acd..312eda55ad5 100644 --- a/ngraph/core/src/op/subtract.cpp +++ b/ngraph/core/src/op/subtract.cpp @@ -13,6 +13,7 @@ using namespace std; using namespace ngraph; namespace subtract { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -47,6 +48,7 @@ bool evaluate_subtract(const HostTensorPtr& arg0, } return rc; } +} // namespace } // namespace subtract // ------------------------------- v1 ------------------------------------------ diff --git a/ngraph/core/src/op/swish.cpp b/ngraph/core/src/op/swish.cpp index d91d1892a96..8cf19ce6c24 100644 --- a/ngraph/core/src/op/swish.cpp +++ b/ngraph/core/src/op/swish.cpp @@ -73,6 +73,7 @@ shared_ptr op::v4::Swish::clone_with_new_inputs(const OutputVector& new_ar } namespace swish { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -107,6 +108,7 @@ bool evaluate_swish(const HostTensorVector& inputs, const HostTensorPtr& out) { } return rc; } +} // namespace } // namespace swish bool op::v4::Swish::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/tan.cpp b/ngraph/core/src/op/tan.cpp index 881789b6f53..660671c197b 100644 --- a/ngraph/core/src/op/tan.cpp +++ b/ngraph/core/src/op/tan.cpp @@ -32,6 +32,7 @@ shared_ptr op::Tan::clone_with_new_inputs(const OutputVector& new_args) co } namespace tanop { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -56,6 +57,7 @@ bool evaluate_tan(const HostTensorPtr& arg0, const HostTensorPtr& out, const siz } return rc; } +} // namespace } // namespace tanop bool op::Tan::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/tanh.cpp b/ngraph/core/src/op/tanh.cpp index 4f128abdf8c..8649e600073 100644 --- a/ngraph/core/src/op/tanh.cpp +++ b/ngraph/core/src/op/tanh.cpp @@ -31,6 +31,7 @@ shared_ptr op::Tanh::clone_with_new_inputs(const OutputVector& new_args) c } namespace tanhop { +namespace { template inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { using T = typename element_type_traits::value_type; @@ -55,6 +56,7 @@ bool evaluate_tanh(const HostTensorPtr& arg0, const HostTensorPtr& out, const si } return rc; } +} // namespace } // namespace tanhop bool op::Tanh::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/topk.cpp b/ngraph/core/src/op/topk.cpp index 3c87aeeb6ba..93bc14a17be 100644 --- a/ngraph/core/src/op/topk.cpp +++ b/ngraph/core/src/op/topk.cpp @@ -20,6 +20,7 @@ using namespace std; using namespace ngraph; namespace topk { +namespace { template inline bool evaluate_execute(const HostTensorPtr& arg0, const HostTensorPtr& out_indices, @@ -133,6 +134,7 @@ size_t read_k_from_host_tensor(const HostTensorPtr& arg_k) { } return k; } +} // namespace } // namespace topk // v1 version starts diff --git a/ngraph/core/src/op/transpose.cpp b/ngraph/core/src/op/transpose.cpp index 1be32dfedd6..4f7d255da2f 100644 --- a/ngraph/core/src/op/transpose.cpp +++ b/ngraph/core/src/op/transpose.cpp @@ -69,6 +69,7 @@ shared_ptr op::v1::Transpose::clone_with_new_inputs(const OutputVector& ne } namespace transpose { +namespace { bool evaluate_transpose(const HostTensorPtr& arg1, const HostTensorPtr& arg2, const HostTensorPtr& out) { NGRAPH_CHECK(arg2->get_element_type().is_integral_number(), "Transpose axis element type has to be integral data type."); @@ -102,6 +103,7 @@ bool evaluate_transpose(const HostTensorPtr& arg1, const HostTensorPtr& arg2, co out_shape); return true; } +} // namespace } // namespace transpose bool op::v1::Transpose::evaluate(const HostTensorVector& output_values, const HostTensorVector& input_values) const { NGRAPH_OP_SCOPE(v1_Transpose_evaluate); diff --git a/ngraph/core/src/op/unsqueeze.cpp b/ngraph/core/src/op/unsqueeze.cpp index ae9c4094c32..ffafec5a2b3 100644 --- a/ngraph/core/src/op/unsqueeze.cpp +++ b/ngraph/core/src/op/unsqueeze.cpp @@ -75,6 +75,7 @@ shared_ptr op::v0::Unsqueeze::clone_with_new_inputs(const OutputVector& ne } namespace unsqueeze { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out) { runtime::reference::copy(arg0->get_data_ptr(), out->get_data_ptr(), shape_size(out->get_shape())); @@ -122,6 +123,7 @@ bool evaluate_unsqueeze(const HostTensorPtr& arg0, const HostTensorPtr& arg1, co } return rc; } +} // namespace } // namespace unsqueeze bool op::v0::Unsqueeze::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/util/convert_color_nv12_base.cpp b/ngraph/core/src/op/util/convert_color_nv12_base.cpp index 0a65116e164..7179e550495 100644 --- a/ngraph/core/src/op/util/convert_color_nv12_base.cpp +++ b/ngraph/core/src/op/util/convert_color_nv12_base.cpp @@ -142,6 +142,7 @@ void ov::op::util::ConvertColorNV12Base::validate_and_infer_types() { } namespace color_convert_nv12_op { +namespace { template inline bool evaluate(const ov::HostTensorVector& input_values, @@ -202,6 +203,7 @@ bool evaluate_nv12_convert(const ov::HostTensorVector& input_values, return rc; } +} // namespace } // namespace color_convert_nv12_op bool ov::op::util::ConvertColorNV12Base::visit_attributes(AttributeVisitor& visitor) { diff --git a/ngraph/core/src/op/util/gather_base.cpp b/ngraph/core/src/op/util/gather_base.cpp index 948996873cb..72541421879 100644 --- a/ngraph/core/src/op/util/gather_base.cpp +++ b/ngraph/core/src/op/util/gather_base.cpp @@ -144,6 +144,7 @@ int64_t ov::op::util::GatherBase::get_axis() const { } namespace gather { +namespace { template bool evaluate(const ngraph::HostTensorPtr& arg0, const ngraph::HostTensorPtr& arg1, @@ -269,6 +270,7 @@ bool cf_gather_with_subgraph(ov::OutputVector& output_values, return true; } +} // namespace } // namespace gather bool ov::op::util::GatherBase::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/op/variadic_split.cpp b/ngraph/core/src/op/variadic_split.cpp index 6f501db7179..ff0ace0096b 100644 --- a/ngraph/core/src/op/variadic_split.cpp +++ b/ngraph/core/src/op/variadic_split.cpp @@ -118,6 +118,7 @@ shared_ptr op::v1::VariadicSplit::clone_with_new_inputs(const OutputVector } namespace variadic_split { +namespace { inline bool evaluate(const HostTensorPtr& in, const HostTensorPtr& out, const Coordinate& lower_bounds, @@ -133,6 +134,7 @@ inline bool evaluate(const HostTensorPtr& in, return true; } +} // namespace } // namespace variadic_split bool op::v1::VariadicSplit::evaluate_variadic_split(const HostTensorVector& inputs, diff --git a/ngraph/core/src/op/xor.cpp b/ngraph/core/src/op/xor.cpp index 9d42a79d626..a5ce2d742ff 100644 --- a/ngraph/core/src/op/xor.cpp +++ b/ngraph/core/src/op/xor.cpp @@ -28,6 +28,7 @@ shared_ptr op::v1::LogicalXor::clone_with_new_inputs(const OutputVector& n } namespace logxor { +namespace { template bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& arg1, @@ -55,7 +56,8 @@ bool evaluate_logxor(const HostTensorPtr& arg0, break; } return rc; -} // namespace logxor +} +} // namespace } // namespace logxor bool op::v1::LogicalXor::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { diff --git a/ngraph/core/src/pass/graph_rewrite.cpp b/ngraph/core/src/pass/graph_rewrite.cpp index c88f010e265..b0ad50032bd 100644 --- a/ngraph/core/src/pass/graph_rewrite.cpp +++ b/ngraph/core/src/pass/graph_rewrite.cpp @@ -52,12 +52,12 @@ namespace ov { namespace pass { -namespace internal { +namespace { PerfCounters& perf_counters_graph_rewrite() { static PerfCounters counters; return counters; } -} // namespace internal +} // namespace } // namespace pass } // namespace ov @@ -372,7 +372,7 @@ void ov::pass::MatcherPass::register_matcher(const std::shared_ptr node) { - OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, pass::internal::perf_counters_graph_rewrite()[get_type_info()]); + OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, pass::perf_counters_graph_rewrite()[get_type_info()]); m_new_nodes.clear(); if (m_handler) return m_handler(node); diff --git a/ngraph/core/src/pass/low_latency.cpp b/ngraph/core/src/pass/low_latency.cpp index 5afa405cdbe..2bbbaab5d09 100644 --- a/ngraph/core/src/pass/low_latency.cpp +++ b/ngraph/core/src/pass/low_latency.cpp @@ -89,6 +89,8 @@ ngraph::pass::LowLatency::LowLatency() { } NGRAPH_SUPPRESS_DEPRECATED_END +namespace { + void UnrollSingleIteration(const shared_ptr& sub_graph_op, const shared_ptr& outer_f) { using namespace ngraph::opset7; @@ -144,6 +146,8 @@ ngraph::Output create_init_subgraph(const shared_ptroutput(0); } +} // namespace + bool ov::pass::LowLatency2::run_on_function(shared_ptr f) { using namespace ngraph::opset7; diff --git a/ngraph/core/src/pass/manager.cpp b/ngraph/core/src/pass/manager.cpp index 8f3e0fd20d5..3048d65b79b 100644 --- a/ngraph/core/src/pass/manager.cpp +++ b/ngraph/core/src/pass/manager.cpp @@ -27,12 +27,12 @@ using namespace std; namespace ov { namespace pass { -namespace internal { +namespace { PerfCounters& perf_counters() { static PerfCounters counters; return counters; } -} // namespace internal +} // namespace } // namespace pass } // namespace ov @@ -61,9 +61,7 @@ void ov::pass::Manager::run_passes(shared_ptr func) { continue; } - OV_ITT_SCOPE(FIRST_INFERENCE, - ov::itt::domains::nGraphPass_LT, - pass::internal::perf_counters()[pass->get_type_info()]); + OV_ITT_SCOPE(FIRST_INFERENCE, ov::itt::domains::nGraphPass_LT, pass::perf_counters()[pass->get_type_info()]); pass_timer.start(); diff --git a/ngraph/core/src/pass/smart_reshape/matmul_sr.cpp b/ngraph/core/src/pass/smart_reshape/matmul_sr.cpp index a4241bd3fba..fea411877f5 100644 --- a/ngraph/core/src/pass/smart_reshape/matmul_sr.cpp +++ b/ngraph/core/src/pass/smart_reshape/matmul_sr.cpp @@ -14,6 +14,8 @@ #include "itt.hpp" +namespace { + bool relax_hc_reshape_followed_by_matmul(const ngraph::pattern::PatternValueMap& pattern_to_output, const std::shared_ptr& matmul_label, const std::shared_ptr& reshape_label, @@ -51,6 +53,8 @@ bool relax_hc_reshape_followed_by_matmul(const ngraph::pattern::PatternValueMap& return true; } +} // namespace + NGRAPH_RTTI_DEFINITION(ngraph::pass::ReshapeAMatMul, "ReshapeAMatMul", 0); ngraph::pass::ReshapeAMatMul::ReshapeAMatMul() { diff --git a/ngraph/core/src/pass/smart_reshape/proposal_scales_stridedslice.cpp b/ngraph/core/src/pass/smart_reshape/proposal_scales_stridedslice.cpp index 3722e06783d..e04d96eaf98 100644 --- a/ngraph/core/src/pass/smart_reshape/proposal_scales_stridedslice.cpp +++ b/ngraph/core/src/pass/smart_reshape/proposal_scales_stridedslice.cpp @@ -12,6 +12,8 @@ #include "itt.hpp" +namespace { + bool crop_scales_for_proposal(const ngraph::pattern::PatternValueMap& pattern_to_output, std::shared_ptr parameter_label, std::shared_ptr proposal_label) { @@ -32,6 +34,8 @@ bool crop_scales_for_proposal(const ngraph::pattern::PatternValueMap& pattern_to return true; } +} // namespace + NGRAPH_RTTI_DEFINITION(ngraph::pass::Proposal1Scales, "Proposal1Scales", 0); ngraph::pass::Proposal1Scales::Proposal1Scales() { diff --git a/ngraph/core/src/pass/smart_reshape/strided_slice_squeeze.cpp b/ngraph/core/src/pass/smart_reshape/strided_slice_squeeze.cpp index f6a30598c58..c75b4b39f7b 100644 --- a/ngraph/core/src/pass/smart_reshape/strided_slice_squeeze.cpp +++ b/ngraph/core/src/pass/smart_reshape/strided_slice_squeeze.cpp @@ -182,6 +182,8 @@ ngraph::pass::SqueezeStridedSlice::SqueezeStridedSlice() { NGRAPH_RTTI_DEFINITION(ngraph::pass::SharedSqueeze, "ngraph::pass::SharedSqueeze", 0); +namespace { + bool squeezes_perform_the_same(std::shared_ptr lhs, std::shared_ptr rhs) { size_t l_input_size = lhs->inputs().size(), r_input_size = rhs->inputs().size(); @@ -200,6 +202,8 @@ bool squeezes_perform_the_same(std::shared_ptr lhs, return false; } +} // namespace + bool ngraph::pass::SharedSqueeze::run_on_function(std::shared_ptr f) { // TODO: enable conditional compile // RUN_ON_FUNCTION_SCOPE(SharedSqueeze); diff --git a/ngraph/core/src/type/bfloat16.cpp b/ngraph/core/src/type/bfloat16.cpp index 2c53f1484d0..af633ddedca 100644 --- a/ngraph/core/src/type/bfloat16.cpp +++ b/ngraph/core/src/type/bfloat16.cpp @@ -30,7 +30,7 @@ using namespace ngraph; static_assert(sizeof(bfloat16) == 2, "class bfloat16 must be exactly 2 bytes"); -bool float_isnan(const float& x) { +inline bool float_isnan(const float& x) { return std::isnan(x); } diff --git a/ngraph/core/src/type/element_type.cpp b/ngraph/core/src/type/element_type.cpp index fb9f2c0bf88..4b6bfa6fa60 100644 --- a/ngraph/core/src/type/element_type.cpp +++ b/ngraph/core/src/type/element_type.cpp @@ -283,7 +283,7 @@ size_t ov::element::Type::bitwidth() const { return get_type_info(m_type).m_bitwidth; } -size_t compiler_byte_size(ov::element::Type_t et) { +inline size_t compiler_byte_size(ov::element::Type_t et) { switch (et) { #define ET_CASE(et) \ case ov::element::Type_t::et: \ diff --git a/ngraph/core/src/validation_util.cpp b/ngraph/core/src/validation_util.cpp index 9e41495c4ec..1d6077f1718 100644 --- a/ngraph/core/src/validation_util.cpp +++ b/ngraph/core/src/validation_util.cpp @@ -1165,6 +1165,8 @@ bool ngraph::could_propagate(const Output& output, std::vector& ord return status; } +namespace { + void propagate_rt_info(Node* node, const Output& final_port) { auto node_outputs = node->outputs(); bool same_outputs = std::all_of(node_outputs.begin(), node_outputs.end(), [](const Output& output) { @@ -1242,6 +1244,8 @@ HostTensorPtr evaluate_bound(const Output& output, bool is_upper) { return output.get_tensor().get_lower_value(); } +} // namespace + HostTensorPtr ngraph::evaluate_lower_bound(const Output& output) { return evaluate_bound(output, false); } @@ -1273,7 +1277,7 @@ bool ov::evaluate_as_partial_shape(const Output& output, PartialShape& psh return shape_defined; } -bool default_bound_evaluator(const Node* node, const HostTensorVector& output_values, bool is_upper) { +inline bool default_bound_evaluator(const Node* node, const HostTensorVector& output_values, bool is_upper) { HostTensorVector input_tensors; for (const auto& input : node->input_values()) { if (auto bound = is_upper ? input.get_tensor().get_upper_value() : input.get_tensor().get_lower_value()) @@ -1350,6 +1354,8 @@ shared_ptr ngraph::get_constant_min_of_type(element::Type_t t) { } } +namespace { + HostTensorPtr equality_mask(const HostTensorPtr& tensor, const shared_ptr& constant) { auto mask = std::make_shared(element::boolean, tensor->get_shape()); const auto& param = std::make_shared(tensor->get_element_type(), tensor->get_shape()); @@ -1367,6 +1373,8 @@ HostTensorPtr or_tensor(const HostTensorPtr& lhs, const HostTensorPtr& rhs) { return result; } +} // namespace + bool ngraph::interval_bound_evaluator(const Node* node, const HostTensorVector& lower_output_values, const HostTensorVector& upper_output_values) { diff --git a/ngraph/frontend/frontend_manager/CMakeLists.txt b/ngraph/frontend/frontend_manager/CMakeLists.txt index 8fe88b3ef5a..0dd4224da6f 100644 --- a/ngraph/frontend/frontend_manager/CMakeLists.txt +++ b/ngraph/frontend/frontend_manager/CMakeLists.txt @@ -4,6 +4,10 @@ set(TARGET_NAME "frontend_manager") +if(CMAKE_COMPILER_IS_GNUCXX) + ie_add_compiler_flags(-Wmissing-declarations) +endif() + file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) file(GLOB_RECURSE LIBRARY_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp) file(GLOB_RECURSE LIBRARY_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp) diff --git a/ngraph/frontend/ir/src/frontend.cpp b/ngraph/frontend/ir/src/frontend.cpp index 78d143f3f67..c82372d0146 100644 --- a/ngraph/frontend/ir/src/frontend.cpp +++ b/ngraph/frontend/ir/src/frontend.cpp @@ -16,6 +16,7 @@ using namespace ngraph; namespace ngraph { namespace frontend { +namespace { inline size_t GetIRVersion(pugi::xml_node& root) { return XMLParseUtils::GetUIntAttr(root, "version", 0); @@ -52,6 +53,8 @@ size_t GetIRVersion(std::istream& model) { return 0; } +} // namespace + bool FrontEndIR::supported_impl(const std::vector>& variants) const { std::ifstream local_model_stream; std::istream* provided_model_stream = nullptr; diff --git a/ngraph/frontend/onnx/frontend/src/core/transform.cpp b/ngraph/frontend/onnx/frontend/src/core/transform.cpp index 20e2a2c3287..5ca8473f535 100644 --- a/ngraph/frontend/onnx/frontend/src/core/transform.cpp +++ b/ngraph/frontend/onnx/frontend/src/core/transform.cpp @@ -18,7 +18,7 @@ namespace ngraph { namespace onnx_import { namespace transform { -namespace detail { +namespace { ONNX_NAMESPACE::TypeProto get_input_type(std::string const& name, ONNX_NAMESPACE::GraphProto& graph) { for (auto& input : graph.input()) { if (input.name() == name) { @@ -33,10 +33,10 @@ ONNX_NAMESPACE::TypeProto get_input_type(std::string const& name, ONNX_NAMESPACE return ONNX_NAMESPACE::TypeProto(); } -inline void function_expand_and_remove_original_node(const ONNX_NAMESPACE::NodeProto& node, - const ONNX_NAMESPACE::FunctionProto& func_proto, - ONNX_NAMESPACE::GraphProto* graph, - int current_node_idx) { +void function_expand_and_remove_original_node(const ONNX_NAMESPACE::NodeProto& node, + const ONNX_NAMESPACE::FunctionProto& func_proto, + ONNX_NAMESPACE::GraphProto* graph, + int current_node_idx) { const auto before_expand_size = graph->node().size(); ONNX_NAMESPACE::FunctionExpandHelper(node, func_proto, *graph); const auto added_nodes = graph->node().size() - before_expand_size; @@ -50,7 +50,7 @@ inline void function_expand_and_remove_original_node(const ONNX_NAMESPACE::NodeP graph->mutable_node()->end()); } -} // namespace detail +} // namespace } // namespace transform } // namespace onnx_import } // namespace ngraph @@ -81,7 +81,7 @@ void ngraph::onnx_import::transform::expand_onnx_functions(ONNX_NAMESPACE::Model if (node_op_schema->HasFunction()) { const auto* func_proto = node_op_schema->GetFunction(); // Move index to the previous position because a first node of expanded function can have also function - detail::function_expand_and_remove_original_node(node, *func_proto, graph_proto, i--); + function_expand_and_remove_original_node(node, *func_proto, graph_proto, i--); } else if (node_op_schema->HasContextDependentFunction()) { @@ -94,14 +94,14 @@ void ngraph::onnx_import::transform::expand_onnx_functions(ONNX_NAMESPACE::Model std::vector input_types; for (const auto& input : node.input()) { - input_types.push_back(ngraph::onnx_import::transform::detail::get_input_type(input, *graph_proto)); + input_types.push_back(get_input_type(input, *graph_proto)); } ONNX_NAMESPACE::FunctionBodyBuildContextImpl ctx(node, input_types); ONNX_NAMESPACE::FunctionProto func_proto; node_op_schema->BuildContextDependentFunction(ctx, func_proto); // Move index to the previous position because a first node of expanded function can have also function - detail::function_expand_and_remove_original_node(node, func_proto, graph_proto, i--); + function_expand_and_remove_original_node(node, func_proto, graph_proto, i--); } } } diff --git a/ngraph/frontend/onnx/frontend/src/onnx.cpp b/ngraph/frontend/onnx/frontend/src/onnx.cpp index 5a7920159bc..67a2b610c70 100644 --- a/ngraph/frontend/onnx/frontend/src/onnx.cpp +++ b/ngraph/frontend/onnx/frontend/src/onnx.cpp @@ -45,10 +45,6 @@ bool is_operator_supported(const std::string& op_name, std::int64_t version, con return OperatorsBridge::is_operator_registered(op_name, version, domain == "ai.onnx" ? "" : domain); } -void convert_decoded_function(std::shared_ptr function) { - detail::convert_decoded_function(function); -} - } // namespace onnx_import } // namespace ngraph diff --git a/ngraph/frontend/onnx/frontend/src/op/affine.cpp b/ngraph/frontend/onnx/frontend/src/op/affine.cpp index 8c8d6bed65b..de33b6d0a09 100644 --- a/ngraph/frontend/onnx/frontend/src/op/affine.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/affine.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "op/affine.hpp" + #include "default_opset.hpp" #include "exceptions.hpp" #include "ngraph/builder/autobroadcast.hpp" diff --git a/ngraph/frontend/onnx/frontend/src/op/argmax.cpp b/ngraph/frontend/onnx/frontend/src/op/argmax.cpp index ba5dd9fe3a1..adddd4ee1fe 100644 --- a/ngraph/frontend/onnx/frontend/src/op/argmax.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/argmax.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "op/argmax.hpp" + #include "exceptions.hpp" #include "onnx_import/core/node.hpp" #include "utils/arg_min_max_factory.hpp" diff --git a/ngraph/frontend/onnx/frontend/src/op/argmin.cpp b/ngraph/frontend/onnx/frontend/src/op/argmin.cpp index ab01049755e..ced9a2f667d 100644 --- a/ngraph/frontend/onnx/frontend/src/op/argmin.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/argmin.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "op/argmin.hpp" + #include "exceptions.hpp" #include "onnx_import/core/node.hpp" #include "utils/arg_min_max_factory.hpp" diff --git a/ngraph/frontend/onnx/frontend/src/op/cast_like.cpp b/ngraph/frontend/onnx/frontend/src/op/cast_like.cpp index 112b55749e4..994e7c9bd3e 100644 --- a/ngraph/frontend/onnx/frontend/src/op/cast_like.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/cast_like.cpp @@ -2,11 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "op/cast_like.hpp" + #include #include "default_opset.hpp" #include "ngraph/type/element_type.hpp" -#include "op/cast.hpp" #include "utils/common.hpp" namespace ngraph { diff --git a/ngraph/frontend/onnx/frontend/src/op/constant_fill.cpp b/ngraph/frontend/onnx/frontend/src/op/constant_fill.cpp index 8dc0d8d46b2..8b7d3641ebe 100644 --- a/ngraph/frontend/onnx/frontend/src/op/constant_fill.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/constant_fill.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "op/constant_fill.hpp" + #include // onnx types #include "default_opset.hpp" diff --git a/ngraph/frontend/onnx/frontend/src/op/constant_of_shape.cpp b/ngraph/frontend/onnx/frontend/src/op/constant_of_shape.cpp index 81daf3e1471..367a04e45d2 100644 --- a/ngraph/frontend/onnx/frontend/src/op/constant_of_shape.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/constant_of_shape.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "op/constant_of_shape.hpp" + #include "core/tensor.hpp" #include "default_opset.hpp" #include "ngraph/op/constant.hpp" diff --git a/ngraph/frontend/onnx/frontend/src/op/crop.cpp b/ngraph/frontend/onnx/frontend/src/op/crop.cpp index 1acfecbdcc0..8dffacc7ff0 100644 --- a/ngraph/frontend/onnx/frontend/src/op/crop.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/crop.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "op/crop.hpp" + #include "default_opset.hpp" #include "exceptions.hpp" #include "ngraph/builder/autobroadcast.hpp" diff --git a/ngraph/frontend/onnx/frontend/src/op/gather_nd.cpp b/ngraph/frontend/onnx/frontend/src/op/gather_nd.cpp index 1f153e1ce83..49b4418cb2e 100644 --- a/ngraph/frontend/onnx/frontend/src/op/gather_nd.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/gather_nd.cpp @@ -5,6 +5,8 @@ // Disabled in CMakeList // Update to higher opset required +#include "op/gather_nd.hpp" + #include "default_opset.hpp" #include "utils/common.hpp" diff --git a/ngraph/frontend/onnx/frontend/src/op/log_softmax.cpp b/ngraph/frontend/onnx/frontend/src/op/log_softmax.cpp index 31a996ca534..c9a5ae680ac 100644 --- a/ngraph/frontend/onnx/frontend/src/op/log_softmax.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/log_softmax.cpp @@ -12,7 +12,7 @@ namespace ngraph { namespace onnx_import { -namespace detail { +namespace { std::shared_ptr onnx_logsoftmax(const Output data, const int64_t axis) { const auto coerced_data = ngraph::builder::opset1::flatten(data, axis); const auto result = std::make_shared(coerced_data, 1); @@ -51,12 +51,12 @@ OutputVector log_softmax(const Node& node, const int64_t DEFAULT_AXIS) { return {result}; } -} // namespace detail +} // namespace namespace op { namespace set_1 { OutputVector log_softmax(const Node& node) { - return detail::log_softmax(node, 1); + return ngraph::onnx_import::log_softmax(node, 1); } } // namespace set_1 diff --git a/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/detection_output.cpp b/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/detection_output.cpp index 4fd988d44c5..82d48b6cc7f 100644 --- a/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/detection_output.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/detection_output.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "op/org.openvinotoolkit/experimental_detectron/detection_output.hpp" + #include "default_opset.hpp" #include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" diff --git a/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/generate_proposals_single_image.cpp b/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/generate_proposals_single_image.cpp index 54bc31df992..a0b46617d41 100644 --- a/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/generate_proposals_single_image.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/generate_proposals_single_image.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "op/org.openvinotoolkit/experimental_detectron/generate_proposals_single_image.hpp" + #include "default_opset.hpp" #include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" diff --git a/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/prior_grid_generator.cpp b/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/prior_grid_generator.cpp index 2d69d4b93b4..0ddba6a56b8 100644 --- a/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/prior_grid_generator.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/prior_grid_generator.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "op/org.openvinotoolkit/experimental_detectron/prior_grid_generator.hpp" + #include "default_opset.hpp" #include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" diff --git a/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/roi_feature_extractor.cpp b/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/roi_feature_extractor.cpp index 5c1a33a4dd0..88201f9109e 100644 --- a/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/roi_feature_extractor.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/roi_feature_extractor.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "op/org.openvinotoolkit/experimental_detectron/roi_feature_extractor.hpp" + #include "default_opset.hpp" #include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" diff --git a/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/topk_rios.cpp b/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/topk_rios.cpp index c8305821934..5e28b9f5cb1 100644 --- a/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/topk_rios.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/experimental_detectron/topk_rios.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "op/org.openvinotoolkit/experimental_detectron/topk_rios.hpp" + #include "default_opset.hpp" #include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" diff --git a/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/swish.cpp b/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/swish.cpp index 6998be52784..db660754bbf 100644 --- a/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/swish.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/org.openvinotoolkit/swish.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "op/org.openvinotoolkit/swish.hpp" + #include "default_opset.hpp" #include "ngraph/op/normalize_l2.hpp" #include "op/org.openvinotoolkit/normalize.hpp" diff --git a/ngraph/frontend/onnx/frontend/src/op/quantize_linear.cpp b/ngraph/frontend/onnx/frontend/src/op/quantize_linear.cpp index a6615e3730f..ffbefe71a03 100644 --- a/ngraph/frontend/onnx/frontend/src/op/quantize_linear.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/quantize_linear.cpp @@ -138,7 +138,7 @@ OutputVector quantize_linear(const Node& node) { } // namespace set_1 namespace set_13 { -namespace detail { +namespace { OutputVector quantize_linear(Output x, Output y_scale, Output y_zero_point, @@ -189,7 +189,7 @@ OutputVector quantize_linear(Output x, return {detail::make_fake_quantize(y_scale, y_zero_point, x)}; } -} // namespace detail +} // namespace OutputVector quantize_linear(const Node& node) { const OutputVector inputs{node.get_ng_inputs()}; @@ -203,7 +203,7 @@ OutputVector quantize_linear(const Node& node) { auto scale = inputs[1]; auto zero_point = op::detail::get_zero_point(inputs); - return detail::quantize_linear(x, scale, zero_point, node.get_attribute_value("axis", 1), node); + return quantize_linear(x, scale, zero_point, node.get_attribute_value("axis", 1), node); } } // namespace set_13 diff --git a/ngraph/frontend/onnx/frontend/src/op/range.cpp b/ngraph/frontend/onnx/frontend/src/op/range.cpp index 752cd20d6a3..5aa12a79f47 100644 --- a/ngraph/frontend/onnx/frontend/src/op/range.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/range.cpp @@ -2,10 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "op/range.hpp" + #include #include "default_opset.hpp" -#include "op/round.hpp" namespace ngraph { namespace onnx_import { diff --git a/ngraph/frontend/onnx/frontend/src/op/reduce.cpp b/ngraph/frontend/onnx/frontend/src/op/reduce.cpp index dab913f7622..da824a6b292 100644 --- a/ngraph/frontend/onnx/frontend/src/op/reduce.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/reduce.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "op/reduce.hpp" + #include #include diff --git a/ngraph/frontend/onnx/frontend/src/op/slice.cpp b/ngraph/frontend/onnx/frontend/src/op/slice.cpp index 13c08449cab..47fce9aa086 100644 --- a/ngraph/frontend/onnx/frontend/src/op/slice.cpp +++ b/ngraph/frontend/onnx/frontend/src/op/slice.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "op/slice.hpp" + #include #include #include diff --git a/ngraph/frontend/onnx/frontend/src/ops_bridge.cpp b/ngraph/frontend/onnx/frontend/src/ops_bridge.cpp index 3c8e0594e32..93badc431fa 100644 --- a/ngraph/frontend/onnx/frontend/src/ops_bridge.cpp +++ b/ngraph/frontend/onnx/frontend/src/ops_bridge.cpp @@ -161,7 +161,7 @@ namespace ngraph { namespace onnx_import { -namespace detail { +namespace { const std::map::const_iterator find(std::int64_t version, const std::map& map) { // Get the latest version. @@ -176,7 +176,7 @@ const std::map::const_iterator find(std::int64_t version } return std::end(map); } -} // namespace detail +} // namespace void OperatorsBridge::_register_operator(const std::string& name, std::int64_t version, @@ -237,7 +237,7 @@ OperatorSet OperatorsBridge::_get_operator_set(const std::string& domain, std::i << " is unsupported. Falling back to: " << OperatorsBridge::LATEST_SUPPORTED_ONNX_OPSET_VERSION; } for (const auto& op : dm->second) { - const auto& it = detail::find(version, op.second); + const auto& it = find(version, op.second); if (it == std::end(op.second)) { throw error::UnsupportedVersion{op.first, version, domain}; } @@ -261,7 +261,7 @@ bool OperatorsBridge::_is_operator_registered(const std::string& name, return false; } - if (detail::find(version, op_map->second) != std::end(op_map->second)) { + if (find(version, op_map->second) != std::end(op_map->second)) { return true; } else { return false; diff --git a/ngraph/frontend/onnx/frontend/src/utils/convpool.cpp b/ngraph/frontend/onnx/frontend/src/utils/convpool.cpp index 89d4b09758b..ea4ed987a47 100644 --- a/ngraph/frontend/onnx/frontend/src/utils/convpool.cpp +++ b/ngraph/frontend/onnx/frontend/src/utils/convpool.cpp @@ -21,7 +21,7 @@ Shape get_kernel_shape(const Node& node) { return node.get_attribute_value>("kernel_shape", std::vector(input_spatial_dims, 1UL)); } -namespace detail { +namespace { /// \brief Gets the attribute default value. /// /// \param[in] node The node we get attribute value from. @@ -59,14 +59,14 @@ std::vector get_attribute_value(const Node& node, return get_attr_default_value(node, attr_name); } } -} // namespace detail +} // namespace Strides get_strides(const Node& node, const std::size_t kernel_rank) { - return detail::get_attribute_value(node, "strides", kernel_rank); + return get_attribute_value(node, "strides", kernel_rank); } Strides get_dilations(const Node& node, const std::size_t kernel_rank) { - return detail::get_attribute_value(node, "dilations", kernel_rank); + return get_attribute_value(node, "dilations", kernel_rank); } ngraph::op::RoundingType get_rounding_type(const Node& node) { diff --git a/ngraph/frontend/onnx/frontend/src/utils/onnx_internal.cpp b/ngraph/frontend/onnx/frontend/src/utils/onnx_internal.cpp index 3a2546889a2..4263806c796 100644 --- a/ngraph/frontend/onnx/frontend/src/utils/onnx_internal.cpp +++ b/ngraph/frontend/onnx/frontend/src/utils/onnx_internal.cpp @@ -15,6 +15,7 @@ namespace ngraph { namespace onnx_import { namespace detail { +namespace { void remove_dangling_parameters(std::shared_ptr& function) { const auto parameters = function->get_parameters(); for (auto parameter : parameters) { @@ -50,6 +51,14 @@ void remove_dangling_results(std::shared_ptr& function) { } } +void apply_transformations(ONNX_NAMESPACE::ModelProto& model_proto, const std::string& model_path) { + transform::expand_onnx_functions(model_proto); + transform::fixup_legacy_operators(model_proto); + transform::update_external_data_paths(model_proto, model_path); +} + +} // namespace + void convert_decoded_function(std::shared_ptr function) { for (const auto& node : function->get_ordered_ops()) { if (auto raw_node = std::dynamic_pointer_cast(node)) { @@ -71,12 +80,6 @@ void convert_decoded_function(std::shared_ptr function) { detail::remove_dangling_results(function); } -void apply_transformations(ONNX_NAMESPACE::ModelProto& model_proto, const std::string& model_path) { - transform::expand_onnx_functions(model_proto); - transform::fixup_legacy_operators(model_proto); - transform::update_external_data_paths(model_proto, model_path); -} - std::shared_ptr import_onnx_model(std::shared_ptr model_proto, const std::string& model_path) { apply_transformations(*model_proto, model_path); diff --git a/ngraph/frontend/onnx/onnx_common/src/onnx_model_validator.cpp b/ngraph/frontend/onnx/onnx_common/src/onnx_model_validator.cpp index 82f2b3540fe..ee75cf47991 100644 --- a/ngraph/frontend/onnx/onnx_common/src/onnx_model_validator.cpp +++ b/ngraph/frontend/onnx/onnx_common/src/onnx_model_validator.cpp @@ -10,7 +10,7 @@ #include #include -namespace detail { +namespace { namespace onnx { enum Field { IR_VERSION = 1, @@ -190,7 +190,7 @@ bool contains_onnx_model_keys(const std::string& model, const size_t expected_ke return keys_found == expected_keys_num; } } // namespace prototxt -} // namespace detail +} // namespace namespace ngraph { namespace onnx_common { @@ -201,12 +201,12 @@ bool is_valid_model(std::istream& model) { unsigned int valid_fields_found = 0u; try { while (!model.eof() && valid_fields_found < EXPECTED_FIELDS_FOUND) { - const auto field = detail::onnx::decode_next_field(model); + const auto field = ::onnx::decode_next_field(model); ++valid_fields_found; if (field.second > 0) { - detail::onnx::skip_payload(model, field.second); + ::onnx::skip_payload(model, field.second); } } diff --git a/ngraph/frontend/paddlepaddle/src/frontend.cpp b/ngraph/frontend/paddlepaddle/src/frontend.cpp index 157908b47f8..ea68793fcc6 100644 --- a/ngraph/frontend/paddlepaddle/src/frontend.cpp +++ b/ngraph/frontend/paddlepaddle/src/frontend.cpp @@ -28,6 +28,7 @@ using namespace ngraph::frontend; namespace ngraph { namespace frontend { namespace pdpd { +namespace { NamedOutputs make_ng_node(const std::map>& nodes, const std::shared_ptr& op_place, const std::map& CREATORS_MAP) { @@ -131,6 +132,7 @@ std::istream* variant_to_stream_ptr(const std::shared_ptr& variant, std FRONT_END_INITIALIZATION_CHECK(ext_stream && ext_stream.is_open(), "Cannot open model file."); return &ext_stream; } +} // namespace } // namespace pdpd std::shared_ptr FrontEndPDPD::convert_each_node( diff --git a/ngraph/frontend/paddlepaddle/src/model.cpp b/ngraph/frontend/paddlepaddle/src/model.cpp index d811681fd6f..171c596f48e 100644 --- a/ngraph/frontend/paddlepaddle/src/model.cpp +++ b/ngraph/frontend/paddlepaddle/src/model.cpp @@ -129,7 +129,7 @@ void InputModelPDPD::InputModelPDPDImpl::loadPlaces() { } } -namespace pdpd { +namespace { bool read_tensor(std::istream& is, char* data, size_t len) { std::vector header(16); is.read(&header[0], 16); @@ -192,7 +192,7 @@ std::basic_string get_model_path(const std::basic_string& path return model_file; } #endif -} // namespace pdpd +} // namespace std::vector> InputModelPDPD::InputModelPDPDImpl::get_op_places() const { if (m_graph_changed) { @@ -260,11 +260,11 @@ void InputModelPDPD::InputModelPDPDImpl::loadConsts(const std::basic_string& bool read_succeed = false; if (weight_stream) { - read_succeed = pdpd::read_tensor(*weight_stream, reinterpret_cast(&tensor_data[0]), data_length); + read_succeed = read_tensor(*weight_stream, reinterpret_cast(&tensor_data[0]), data_length); } else if (!folder_with_weights.empty()) { - std::ifstream is(pdpd::get_const_path(folder_with_weights, name), std::ios::in | std::ifstream::binary); + std::ifstream is(get_const_path(folder_with_weights, name), std::ios::in | std::ifstream::binary); FRONT_END_GENERAL_CHECK(is && is.is_open(), "Cannot open file for constant value."); - read_succeed = pdpd::read_tensor(is, reinterpret_cast(&tensor_data[0]), data_length); + read_succeed = read_tensor(is, reinterpret_cast(&tensor_data[0]), data_length); } else { FRONT_END_GENERAL_CHECK(false, "Either folder with weights or stream must be provided."); } @@ -285,7 +285,7 @@ InputModelPDPD::InputModelPDPDImpl::InputModelPDPDImpl(const std::basic_string(path, &weights_stream), std::ios::in | std::ifstream::binary); + std::ifstream pb_stream(get_model_path(path, &weights_stream), std::ios::in | std::ifstream::binary); FRONT_END_GENERAL_CHECK(pb_stream && pb_stream.is_open(), "Model file doesn't exist"); FRONT_END_GENERAL_CHECK(m_fw_ptr->ParseFromIstream(&pb_stream), "Model can't be parsed"); @@ -337,7 +337,7 @@ Place::Ptr InputModelPDPD::InputModelPDPDImpl::getPlaceByTensorName(const std::s return nullptr; } -namespace pdpd { +namespace { std::shared_ptr castToTensorPlace(const Place::Ptr& place) { if (auto var_place = std::dynamic_pointer_cast(place)) { return var_place; @@ -349,13 +349,13 @@ std::shared_ptr castToTensorPlace(const Place::Ptr& place) { FRONT_END_GENERAL_CHECK(false, "Cannot cast this Place to TensorPlacePDPD."); } -} // namespace pdpd +} // namespace void InputModelPDPD::InputModelPDPDImpl::overrideAllInputs(const std::vector& inputs) { m_graph_changed = true; m_inputs.clear(); for (const auto& inp : inputs) { - m_inputs.push_back(pdpd::castToTensorPlace(inp)); + m_inputs.push_back(castToTensorPlace(inp)); } } @@ -363,7 +363,7 @@ void InputModelPDPD::InputModelPDPDImpl::overrideAllOutputs(const std::vectorset_partial_shape(p_shape); + castToTensorPlace(place)->set_partial_shape(p_shape); } ngraph::PartialShape InputModelPDPD::InputModelPDPDImpl::getPartialShape(Place::Ptr place) const { - return pdpd::castToTensorPlace(place)->get_partial_shape(); + return castToTensorPlace(place)->get_partial_shape(); } void InputModelPDPD::InputModelPDPDImpl::setElementType(Place::Ptr place, const ngraph::element::Type& type) { - pdpd::castToTensorPlace(place)->set_element_type(type); + castToTensorPlace(place)->set_element_type(type); } void InputModelPDPD::InputModelPDPDImpl::setTensorValue(Place::Ptr place, const void* value) { m_graph_changed = true; - auto tensor_place = pdpd::castToTensorPlace(place); + auto tensor_place = castToTensorPlace(place); auto p_shape = tensor_place->get_partial_shape(); auto type = tensor_place->get_element_type(); auto constant = opset7::Constant::create(type, p_shape.to_shape(), value); diff --git a/ngraph/frontend/tensorflow/src/decoder_proto.cpp b/ngraph/frontend/tensorflow/src/decoder_proto.cpp index 9bfb8386fa5..0464314b5af 100644 --- a/ngraph/frontend/tensorflow/src/decoder_proto.cpp +++ b/ngraph/frontend/tensorflow/src/decoder_proto.cpp @@ -10,6 +10,7 @@ namespace ov { namespace frontend { namespace tf { +namespace { const std::map<::tensorflow::DataType, ov::element::Type>& TYPE_MAP() { static const std::map<::tensorflow::DataType, ov::element::Type> type_map{ {::tensorflow::DataType::DT_BOOL, ov::element::boolean}, @@ -24,6 +25,7 @@ const std::map<::tensorflow::DataType, ov::element::Type>& TYPE_MAP() { {::tensorflow::DataType::DT_BFLOAT16, ov::element::bf16}}; return type_map; } +} // namespace std::shared_ptr DecoderTFProto::get_attribute(const std::string& name, const VariantTypeInfo& type_info) const { From 054a2f8d9cbbeca22c64d46fcc2c0187ef541e9b Mon Sep 17 00:00:00 2001 From: Dmitry Pigasin Date: Thu, 28 Oct 2021 00:17:34 +0300 Subject: [PATCH 06/12] [IE Python Speech Sample] Add context windows feature (#7801) * Add `context_window_left` feature * Add a check of positive context window args * Add `context_window_right` feature --- samples/python/speech_sample/arg_parser.py | 39 +++++++++++++++++-- samples/python/speech_sample/speech_sample.py | 31 +++++++++------ 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/samples/python/speech_sample/arg_parser.py b/samples/python/speech_sample/arg_parser.py index d4e2b345ea2..1469a4c731f 100644 --- a/samples/python/speech_sample/arg_parser.py +++ b/samples/python/speech_sample/arg_parser.py @@ -25,8 +25,9 @@ def parse_args() -> argparse.Namespace: 'CPU, GPU, MYRIAD, GNA_AUTO, GNA_HW, GNA_SW_FP32, GNA_SW_EXACT and HETERO with combination of GNA' ' as the primary device and CPU as a secondary (e.g. HETERO:GNA,CPU) are supported. ' 'The sample will look for a suitable plugin for device specified. Default value is CPU.') - args.add_argument('-bs', '--batch_size', default=1, type=int, help='Optional. Batch size 1-8 (default 1).') - args.add_argument('-qb', '--quantization_bits', default=16, type=int, + args.add_argument('-bs', '--batch_size', default=1, type=int, choices=range(1, 9), metavar='[1-8]', + help='Optional. Batch size 1-8 (default 1).') + args.add_argument('-qb', '--quantization_bits', default=16, type=int, choices=(8, 16), metavar='[8, 16]', help='Optional. Weight bits for quantization: 8 or 16 (default 16).') args.add_argument('-sf', '--scale_factor', type=str, help='Optional. The user-specified input scale factor for quantization. ' @@ -37,7 +38,7 @@ def parse_args() -> argparse.Namespace: args.add_argument('-we_gen', '--embedded_gna_configuration', default='GNA1', type=str, help=argparse.SUPPRESS) args.add_argument('-pc', '--performance_counter', action='store_true', help='Optional. Enables performance report (specify -a to ensure arch accurate results).') - args.add_argument('-a', '--arch', default='CORE', type=str.upper, choices=['CORE', 'ATOM'], + args.add_argument('-a', '--arch', default='CORE', type=str.upper, choices=('CORE', 'ATOM'), metavar='[CORE, ATOM]', help='Optional. Specify architecture. CORE, ATOM with the combination of -pc.') args.add_argument('-iname', '--input_layers', type=str, help='Optional. Layer names for input blobs. The names are separated with ",". ' @@ -45,5 +46,37 @@ def parse_args() -> argparse.Namespace: args.add_argument('-oname', '--output_layers', type=str, help='Optional. Layer names for output blobs. The names are separated with ",". ' 'Allows to change the order of output layers for -o flag. Example: Output1:port,Output2:port.') + args.add_argument('-cw_l', '--context_window_left', type=IntRange(0), default=0, + help='Optional. Number of frames for left context windows (default is 0). ' + 'Works only with context window networks. ' + 'If you use the cw_l or cw_r flag, then batch size argument is ignored.') + args.add_argument('-cw_r', '--context_window_right', type=IntRange(0), default=0, + help='Optional. Number of frames for right context windows (default is 0). ' + 'Works only with context window networks. ' + 'If you use the cw_l or cw_r flag, then batch size argument is ignored.') return parser.parse_args() + + +class IntRange: + """Custom argparse type representing a bounded int.""" + + def __init__(self, _min=None, _max=None): + self._min = _min + self._max = _max + + def __call__(self, arg): + try: + value = int(arg) + except ValueError: + raise argparse.ArgumentTypeError('Must be an integer.') + + if (self._min is not None and value < self._min) or (self._max is not None and value > self._max): + if self._min is not None and self._max is not None: + raise argparse.ArgumentTypeError(f'Must be an integer in the range [{self._min}, {self._max}].') + elif self._min is not None: + raise argparse.ArgumentTypeError(f'Must be an integer >= {self._min}.') + elif self._max is not None: + raise argparse.ArgumentTypeError(f'Must be an integer <= {self._max}.') + + return value diff --git a/samples/python/speech_sample/speech_sample.py b/samples/python/speech_sample/speech_sample.py index 4e7a3d52793..4d222af9959 100755 --- a/samples/python/speech_sample/speech_sample.py +++ b/samples/python/speech_sample/speech_sample.py @@ -30,7 +30,9 @@ def get_scale_factor(matrix: np.ndarray) -> float: return target_max / max_val -def infer_data(data: dict, exec_net: ExecutableNetwork, input_blobs: list, output_blobs: list) -> np.ndarray: +def infer_data( + data: dict, exec_net: ExecutableNetwork, input_blobs: list, output_blobs: list, cw_l: int = 0, cw_r: int = 0, +) -> np.ndarray: """Do a synchronous matrix inference""" matrix_shape = next(iter(data.values())).shape result = {} @@ -40,11 +42,16 @@ def infer_data(data: dict, exec_net: ExecutableNetwork, input_blobs: list, outpu batch_size = shape[0] result[blob_name] = np.ndarray((matrix_shape[0], shape[-1])) - slice_begin = 0 - slice_end = batch_size + for i in range(-cw_l, matrix_shape[0] + cw_r, batch_size): + if i < 0: + index = 0 + elif i >= matrix_shape[0]: + index = matrix_shape[0] - 1 + else: + index = i + + vectors = {blob_name: data[blob_name][index:index + batch_size] for blob_name in input_blobs} - while slice_begin < matrix_shape[0]: - vectors = {blob_name: data[blob_name][slice_begin:slice_end] for blob_name in input_blobs} num_of_vectors = next(iter(vectors.values())).shape[0] if num_of_vectors < batch_size: @@ -57,11 +64,11 @@ def infer_data(data: dict, exec_net: ExecutableNetwork, input_blobs: list, outpu vector_results = exec_net.infer(vectors) - for blob_name in output_blobs: - result[blob_name][slice_begin:slice_end] = vector_results[blob_name][:num_of_vectors] + if i - cw_r < 0: + continue - slice_begin += batch_size - slice_end += batch_size + for blob_name in output_blobs: + result[blob_name][i - cw_r:i - cw_r + batch_size] = vector_results[blob_name][:num_of_vectors] return result @@ -161,7 +168,7 @@ def main(): for blob_name in output_blobs: net.outputs[blob_name].precision = 'FP32' - net.batch_size = args.batch_size + net.batch_size = args.batch_size if args.context_window_left + args.context_window_right == 0 else 1 # ---------------------------Step 4. Loading model to the device------------------------------------------------------- devices = args.device.replace('HETERO:', '').split(',') @@ -272,7 +279,9 @@ def main(): for state in request.query_state(): state.reset() - result = infer_data(input_data[key], exec_net, input_blobs, output_blobs) + result = infer_data( + input_data[key], exec_net, input_blobs, output_blobs, args.context_window_left, args.context_window_right, + ) for blob_name in result.keys(): results[blob_name][key] = result[blob_name] From 6f862822e1d51740c01b133603596a54e9b0e82f Mon Sep 17 00:00:00 2001 From: Steve Yoo Date: Thu, 28 Oct 2021 14:42:50 +0900 Subject: [PATCH 07/12] Migrate Movement 1 Operations (ScatterNDUpsate-1) (#8116) * Migrate ScatterNDUpsate-1 * Remove round.in.cpp --- .../op_reference/scatter_nd_update.cpp | 201 ++++++++ ngraph/test/CMakeLists.txt | 1 - ngraph/test/backend/scatter_nd_update.in.cpp | 449 ------------------ 3 files changed, 201 insertions(+), 450 deletions(-) create mode 100644 docs/template_plugin/tests/functional/op_reference/scatter_nd_update.cpp delete mode 100644 ngraph/test/backend/scatter_nd_update.in.cpp diff --git a/docs/template_plugin/tests/functional/op_reference/scatter_nd_update.cpp b/docs/template_plugin/tests/functional/op_reference/scatter_nd_update.cpp new file mode 100644 index 00000000000..bdc236778c1 --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/scatter_nd_update.cpp @@ -0,0 +1,201 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "openvino/op/scatter_nd_update.hpp" +#include "openvino/op/constant.hpp" +#include "base_reference_test.hpp" + +using namespace reference_tests; +using namespace ov; + +namespace { +struct ScatterNDUpdateParams { + ScatterNDUpdateParams(const Tensor& dataTensor, const Tensor& indexTensor, const Tensor& updateTensor, + const Tensor& expectedTensor, const std::string& testcaseName = "") : + dataTensor(dataTensor), indexTensor(indexTensor), updateTensor(updateTensor), + expectedTensor(expectedTensor), testcaseName(testcaseName) {} + + Tensor dataTensor; + Tensor indexTensor; + Tensor updateTensor; + Tensor expectedTensor; + std::string testcaseName; +}; + +class ReferenceScatterNDUpdateLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params); + inputData = {params.dataTensor.data}; + refOutData = {params.expectedTensor.data}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "dType=" << param.dataTensor.type; + result << "_dShape=" << param.dataTensor.shape; + result << "_iType=" << param.indexTensor.type; + result << "_iShape=" << param.indexTensor.shape; + result << "_uType=" << param.updateTensor.type; + result << "_uShape=" << param.updateTensor.shape; + result << "_eType=" << param.expectedTensor.type; + if (param.testcaseName != "") { + result << "_eShape=" << param.expectedTensor.shape; + result << "_" << param.testcaseName; + } else { + result << "_eShape=" << param.expectedTensor.shape; + } + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const ScatterNDUpdateParams& params) { + const auto data = std::make_shared(params.dataTensor.type, params.dataTensor.shape); + const auto indices = std::make_shared(params.indexTensor.type, + params.indexTensor.shape, + params.indexTensor.data.data()); + const auto updates = std::make_shared(params.updateTensor.type, + params.updateTensor.shape, + params.updateTensor.data.data()); + const auto scatter = std::make_shared(data, indices, updates); + return std::make_shared(NodeVector{scatter}, ParameterVector{data}); + } +}; + +TEST_P(ReferenceScatterNDUpdateLayerTest, CompareWithRefs) { + Exec(); +} + +template +std::vector generateScatterNDUpdateParams() { + using T = typename element_type_traits::value_type; + using U = typename element_type_traits::value_type; + std::vector scatterParams { + // scatter_nd_update_1x1 + ScatterNDUpdateParams(Tensor({1}, IN_ET, std::vector{1}), + Tensor({1}, IU_ET, std::vector{0}), + Tensor({1}, IN_ET, std::vector{20}), + Tensor({1}, IN_ET, std::vector{20}), + "scatter_nd_update_1x1"), + // scatter_nd_update_2x2_by_1 + ScatterNDUpdateParams(Tensor({2, 2}, IN_ET, std::vector{1, 2, 3, 4}), + Tensor({2, 1}, IU_ET, std::vector{1, 0}), + Tensor({2, 2}, IN_ET, std::vector{10, 20, 30, 40}), + Tensor({2, 2}, IN_ET, std::vector{30, 40, 10, 20}), + "scatter_nd_update_2x2_by_1"), + // scatter_nd_update_2x2_by_2 + ScatterNDUpdateParams(Tensor({2, 2}, IN_ET, std::vector{1, 2, 3, 4}), + Tensor({2, 2}, IU_ET, std::vector{0, 0, 1, 1}), + Tensor({2}, IN_ET, std::vector{10, 40}), + Tensor({2, 2}, IN_ET, std::vector{10, 2, 3, 40}), + "scatter_nd_update_2x2_by_2"), + // scatter_nd_update_3x3_by_1 + ScatterNDUpdateParams(Tensor({3, 3, 3}, IN_ET, std::vector{11, 12, 13, 14, 15, 16, 17, 18, 19, + 21, 22, 23, 24, 25, 26, 27, 28, 29, + 31, 32, 33, 34, 35, 36, 37, 38, 39}), + Tensor({2, 1}, IU_ET, std::vector{0, 2}), + Tensor({2, 3, 3}, IN_ET, std::vector{91, 92, 93, 94, 95, 96, 97, 98, 99, + 81, 82, 83, 84, 85, 86, 87, 88, 89}), + Tensor({3, 3, 3}, IN_ET, std::vector{91, 92, 93, 94, 95, 96, 97, 98, 99, + 21, 22, 23, 24, 25, 26, 27, 28, 29, + 81, 82, 83, 84, 85, 86, 87, 88, 89}), + "scatter_nd_update_3x3_by_1"), + // scatter_nd_update_3x3_by_2v2 + ScatterNDUpdateParams(Tensor({3, 3, 3}, IN_ET, std::vector{11, 12, 13, 14, 15, 16, 17, 18, 19, + 21, 22, 23, 24, 25, 26, 27, 28, 29, + 31, 32, 33, 34, 35, 36, 37, 38, 39}), + Tensor({2, 2, 3}, IU_ET, std::vector{0, 0, 0, 2, 2, 2, 1, 0, 0, 1, 2, 2}), + Tensor({2, 2}, IN_ET, std::vector{91, 92, 81, 82}), + Tensor({3, 3, 3}, IN_ET, std::vector{91, 12, 13, 14, 15, 16, 17, 18, 19, + 81, 22, 23, 24, 25, 26, 27, 28, 82, + 31, 32, 33, 34, 35, 36, 37, 38, 92}), + "scatter_nd_update_3x3_by_2v2"), + // scatter_nd_update_3x3_by_2 + ScatterNDUpdateParams(Tensor({3, 3, 3}, IN_ET, std::vector{11, 12, 13, 14, 15, 16, 17, 18, 19, + 21, 22, 23, 24, 25, 26, 27, 28, 29, + 31, 32, 33, 34, 35, 36, 37, 38, 39}), + Tensor({2, 2}, IU_ET, std::vector{0, 0, 2, 2}), + Tensor({2, 3}, IN_ET, std::vector{91, 92, 93, 87, 88, 89}), + Tensor({3, 3, 3}, IN_ET, std::vector{91, 92, 93, 14, 15, 16, 17, 18, 19, + 21, 22, 23, 24, 25, 26, 27, 28, 29, + 31, 32, 33, 34, 35, 36, 87, 88, 89}), + "scatter_nd_update_3x3_by_2"), + // scatter_nd_update_3x3_by_3 + ScatterNDUpdateParams(Tensor({3, 3, 3}, IN_ET, std::vector{11, 12, 13, 14, 15, 16, 17, 18, 19, + 21, 22, 23, 24, 25, 26, 27, 28, 29, + 31, 32, 33, 34, 35, 36, 37, 38, 39}), + Tensor({2, 3}, IU_ET, std::vector{0, 0, 0, 2, 2, 2}), + Tensor({2}, IN_ET, std::vector{91, 99}), + Tensor({3, 3, 3}, IN_ET, std::vector{91, 12, 13, 14, 15, 16, 17, 18, 19, + 21, 22, 23, 24, 25, 26, 27, 28, 29, + 31, 32, 33, 34, 35, 36, 37, 38, 99}), + "scatter_nd_update_3x3_by_3"), + // scatter_nd_update_1d_from_examples + ScatterNDUpdateParams(Tensor({8}, IN_ET, std::vector{1, 2, 3, 4, 5, 6, 7, 8}), + Tensor({4, 1}, IU_ET, std::vector{4, 3, 1, 7}), + Tensor({4}, IN_ET, std::vector{9, 10, 11, 12}), + Tensor({8}, IN_ET, std::vector{1, 11, 3, 10, 9, 6, 7, 12}), + "scatter_nd_update_1d_from_examples"), + // scatter_nd_update_4x4_shape_from_examples + ScatterNDUpdateParams(Tensor({4, 4, 4}, IN_ET, std::vector{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, + 1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, + 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, + 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8}), + Tensor({2, 1}, IU_ET, std::vector{0, 2}), + Tensor({2, 4, 4}, IN_ET, std::vector{5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, + 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4}), + Tensor({4, 4, 4}, IN_ET, std::vector{5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, + 1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, + 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, + 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8}), + "scatter_nd_update_4x4_shape_from_examples"), + // scatter_nd_update_4x4_v2 + ScatterNDUpdateParams(Tensor({4, 4, 4}, IN_ET, std::vector{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, + 1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, + 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, + 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8}), + Tensor({2, 2, 2}, IU_ET, std::vector{0, 0, 2, 2, 1, 1, 3, 3}), + Tensor({2, 2, 4}, IN_ET, std::vector{15, 16, 17, 18, 25, 26, 27, 28, + 35, 36, 37, 38, 45, 46, 47, 58}), + Tensor({4, 4, 4}, IN_ET, std::vector{15, 16, 17, 18, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, + 1, 2, 3, 4, 35, 36, 37, 38, 8, 7, 6, 5, 4, 3, 2, 1, + 8, 7, 6, 5, 4, 3, 2, 1, 25, 26, 27, 28, 5, 6, 7, 8, + 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 45, 46, 47, 58}), + "scatter_nd_update_4x4_v2"), + }; + return scatterParams; +} + +std::vector generateScatterNDUpdateCombinedParams() { + const std::vector> scatterTypeParams { + generateScatterNDUpdateParams(), + generateScatterNDUpdateParams(), + generateScatterNDUpdateParams(), + generateScatterNDUpdateParams(), + generateScatterNDUpdateParams(), + generateScatterNDUpdateParams(), + generateScatterNDUpdateParams(), + generateScatterNDUpdateParams(), + generateScatterNDUpdateParams(), + generateScatterNDUpdateParams(), + generateScatterNDUpdateParams(), + generateScatterNDUpdateParams(), + generateScatterNDUpdateParams(), + generateScatterNDUpdateParams(), + }; + std::vector combinedParams; + + for (const auto& params : scatterTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P(smoke_ScatterNDUpdate_With_Hardcoded_Refs, ReferenceScatterNDUpdateLayerTest, + testing::ValuesIn(generateScatterNDUpdateCombinedParams()), ReferenceScatterNDUpdateLayerTest::getTestCaseName); +} // namespace \ No newline at end of file diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index 58eaff5f03d..a0e4f959622 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -507,7 +507,6 @@ set(MULTI_TEST_SRC backend/result.in.cpp backend/reverse.in.cpp backend/roll.in.cpp - backend/scatter_nd_update.in.cpp backend/space_to_depth.in.cpp backend/shuffle_channels.in.cpp backend/space_to_batch.in.cpp diff --git a/ngraph/test/backend/scatter_nd_update.in.cpp b/ngraph/test/backend/scatter_nd_update.in.cpp deleted file mode 100644 index a7e875a48d4..00000000000 --- a/ngraph/test/backend/scatter_nd_update.in.cpp +++ /dev/null @@ -1,449 +0,0 @@ -//***************************************************************************** -// Copyright 2021 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -//***************************************************************************** - -#include -#include - -#include "engines_util/execute_tools.hpp" -#include "gtest/gtest.h" -#include "ngraph/opsets/opset7.hpp" -#include "ngraph/type/element_type.hpp" -#include "runtime/backend.hpp" -#include "util/all_close_f.hpp" -#include "util/ndarray.hpp" -#include "util/test_control.hpp" - -static std::string s_manifest = "${MANIFEST}"; - -namespace { -template -struct Array { - using StorageType = ngraph::test::NDArrayBase; - static ngraph::element::Type element_type() { - return ngraph::element::from(); - } - StorageType data; -}; -struct Params { - Array input; - Array indices; - Array updates; - Array expected_output; -}; - -void execute_test(const Params& p) { - using namespace ngraph; - using namespace opset7; - - auto inputs = std::make_shared(p.input.element_type(), p.input.data.get_shape()); - auto indices = Constant::create(p.indices.element_type(), p.indices.data.get_shape(), p.indices.data.get_vector()); - auto updates = Constant::create(p.updates.element_type(), p.updates.data.get_shape(), p.updates.data.get_vector()); - - auto scatter = std::make_shared(inputs, indices, updates); - - auto function = std::make_shared(scatter, ParameterVector{inputs}, "ScatterNDUpdate"); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto inputs_tensor = backend->create_tensor(p.input.element_type(), p.input.data.get_shape()); - copy_data(inputs_tensor, p.input.data.get_vector()); - - auto result = backend->create_tensor(p.input.element_type(), p.expected_output.data.get_shape()); - - auto handle = backend->compile(function); - handle->call_with_validate({result}, {inputs_tensor}); - - EXPECT_TRUE( - test::all_close_f(p.expected_output.data.get_vector(), read_vector(result), MIN_FLOAT_TOLERANCE_BITS)); -} -} // namespace - -NGRAPH_TEST(${BACKEND_NAME}, scatter_nd_update_1x1) { - using namespace ngraph::test; - execute_test(Params{NDArray{1}, NDArray{{0}}, NDArray{20}, NDArray{20}}); -} - -NGRAPH_TEST(${BACKEND_NAME}, scatter_nd_update_2x2_by_1) { - using namespace ngraph::test; - execute_test(Params{NDArray{ - {1, 2}, - {3, 4}, - }, - NDArray{{1}, {0}}, - NDArray{{10, 20}, {30, 40}}, - NDArray{ - {30, 40}, - {10, 20}, - }}); -} - -NGRAPH_TEST(${BACKEND_NAME}, scatter_nd_update_2x2_by_2) { - using namespace ngraph::test; - execute_test(Params{NDArray{ - {1, 2}, - {3, 4}, - }, - NDArray{ - {0, 0}, - {1, 1}, - }, - NDArray{10, 40}, - NDArray{ - {10, 2}, - {3, 40}, - }}); -} - -NGRAPH_TEST(${BACKEND_NAME}, scatter_nd_update_3x3_by_1) { - using namespace ngraph::test; - execute_test(Params{NDArray{ - { - {11, 12, 13}, - {14, 15, 16}, - {17, 18, 19}, - }, - { - {21, 22, 23}, - {24, 25, 26}, - {27, 28, 29}, - }, - { - {31, 32, 33}, - {34, 35, 36}, - {37, 38, 39}, - }, - }, - NDArray{{0}, {2}}, - NDArray{ - { - {91, 92, 93}, - {94, 95, 96}, - {97, 98, 99}, - }, - { - {81, 82, 83}, - {84, 85, 86}, - {87, 88, 89}, - }, - }, - NDArray{ - { - {91, 92, 93}, - {94, 95, 96}, - {97, 98, 99}, - }, - { - {21, 22, 23}, - {24, 25, 26}, - {27, 28, 29}, - }, - { - {81, 82, 83}, - {84, 85, 86}, - {87, 88, 89}, - }, - }}); -} - -NGRAPH_TEST(${BACKEND_NAME}, scatter_nd_update_3x3_by_2v2) { - using namespace ngraph::test; - execute_test(Params{NDArray{ - { - {11, 12, 13}, - {14, 15, 16}, - {17, 18, 19}, - }, - { - {21, 22, 23}, - {24, 25, 26}, - {27, 28, 29}, - }, - { - {31, 32, 33}, - {34, 35, 36}, - {37, 38, 39}, - }, - }, - NDArray{ - { - {0, 0, 0}, - {2, 2, 2}, - }, - { - {1, 0, 0}, - {1, 2, 2}, - }, - }, - NDArray{ - {91, 92}, - {81, 82}, - }, - NDArray{ - { - {91, 12, 13}, - {14, 15, 16}, - {17, 18, 19}, - }, - { - {81, 22, 23}, - {24, 25, 26}, - {27, 28, 82}, - }, - { - {31, 32, 33}, - {34, 35, 36}, - {37, 38, 92}, - }, - }}); -} - -NGRAPH_TEST(${BACKEND_NAME}, scatter_nd_update_3x3_by_2) { - using namespace ngraph::test; - execute_test(Params{NDArray{ - { - {11, 12, 13}, - {14, 15, 16}, - {17, 18, 19}, - }, - { - {21, 22, 23}, - {24, 25, 26}, - {27, 28, 29}, - }, - { - {31, 32, 33}, - {34, 35, 36}, - {37, 38, 39}, - }, - }, - NDArray{{0, 0}, {2, 2}}, - NDArray{ - {91, 92, 93}, - {87, 88, 89}, - }, - NDArray{ - { - {91, 92, 93}, - {14, 15, 16}, - {17, 18, 19}, - }, - { - {21, 22, 23}, - {24, 25, 26}, - {27, 28, 29}, - }, - { - {31, 32, 33}, - {34, 35, 36}, - {87, 88, 89}, - }, - }}); -} - -NGRAPH_TEST(${BACKEND_NAME}, scatter_nd_update_3x3_by_3) { - using namespace ngraph::test; - execute_test(Params{NDArray{ - { - {11, 12, 13}, - {14, 15, 16}, - {17, 18, 19}, - }, - { - {21, 22, 23}, - {24, 25, 26}, - {27, 28, 29}, - }, - { - {31, 32, 33}, - {34, 35, 36}, - {37, 38, 39}, - }, - }, - NDArray{{0, 0, 0}, {2, 2, 2}}, - NDArray{91, 99}, - NDArray{ - { - {91, 12, 13}, - {14, 15, 16}, - {17, 18, 19}, - }, - { - {21, 22, 23}, - {24, 25, 26}, - {27, 28, 29}, - }, - { - {31, 32, 33}, - {34, 35, 36}, - {37, 38, 99}, - }, - }}); -} - -NGRAPH_TEST(${BACKEND_NAME}, scatter_nd_update_1d_from_examples) { - using namespace ngraph::test; - execute_test(Params{NDArray{1, 2, 3, 4, 5, 6, 7, 8}, - NDArray{{4}, {3}, {1}, {7}}, - NDArray{9, 10, 11, 12}, - NDArray{1, 11, 3, 10, 9, 6, 7, 12}}); -} - -NGRAPH_TEST(${BACKEND_NAME}, scatter_nd_update_4x4_shape_from_examples) { - using namespace ngraph::test; - execute_test(Params{NDArray{{ - {1, 2, 3, 4}, - {5, 6, 7, 8}, - {8, 7, 6, 5}, - {4, 3, 2, 1}, - }, - { - {1, 2, 3, 4}, - {5, 6, 7, 8}, - {8, 7, 6, 5}, - {4, 3, 2, 1}, - }, - { - {8, 7, 6, 5}, - {4, 3, 2, 1}, - {1, 2, 3, 4}, - {5, 6, 7, 8}, - }, - { - {8, 7, 6, 5}, - {4, 3, 2, 1}, - {1, 2, 3, 4}, - {5, 6, 7, 8}, - }}, - NDArray{{0}, {2}}, - NDArray{ - { - {5, 5, 5, 5}, - {6, 6, 6, 6}, - {7, 7, 7, 7}, - {8, 8, 8, 8}, - }, - { - {1, 1, 1, 1}, - {2, 2, 2, 2}, - {3, 3, 3, 3}, - {4, 4, 4, 4}, - }, - }, - NDArray{ - { - {5, 5, 5, 5}, - {6, 6, 6, 6}, - {7, 7, 7, 7}, - {8, 8, 8, 8}, - }, - { - {1, 2, 3, 4}, - {5, 6, 7, 8}, - {8, 7, 6, 5}, - {4, 3, 2, 1}, - }, - { - {1, 1, 1, 1}, - {2, 2, 2, 2}, - {3, 3, 3, 3}, - {4, 4, 4, 4}, - }, - { - {8, 7, 6, 5}, - {4, 3, 2, 1}, - {1, 2, 3, 4}, - {5, 6, 7, 8}, - }, - }}); -} - -NGRAPH_TEST(${BACKEND_NAME}, scatter_nd_update_4x4_v2) { - using namespace ngraph::test; - execute_test(Params{NDArray{ - { - {1, 2, 3, 4}, - {5, 6, 7, 8}, - {8, 7, 6, 5}, - {4, 3, 2, 1}, - }, - { - {1, 2, 3, 4}, - {5, 6, 7, 8}, - {8, 7, 6, 5}, - {4, 3, 2, 1}, - }, - { - {8, 7, 6, 5}, - {4, 3, 2, 1}, - {1, 2, 3, 4}, - {5, 6, 7, 8}, - }, - { - {8, 7, 6, 5}, - {4, 3, 2, 1}, - {1, 2, 3, 4}, - {5, 6, 7, 8}, - }, - }, - NDArray{ - { - {0, 0}, - {2, 2}, - }, - { - {1, 1}, - {3, 3}, - }, - }, - NDArray{ - { - {15, 16, 17, 18}, - {25, 26, 27, 28}, - }, - { - {35, 36, 37, 38}, - {45, 46, 47, 58}, - }, - }, - NDArray{ - { - {15, 16, 17, 18}, - {5, 6, 7, 8}, - {8, 7, 6, 5}, - {4, 3, 2, 1}, - - }, - { - {1, 2, 3, 4}, - {35, 36, 37, 38}, - {8, 7, 6, 5}, - {4, 3, 2, 1}, - }, - { - {8, 7, 6, 5}, - {4, 3, 2, 1}, - {25, 26, 27, 28}, - {5, 6, 7, 8}, - }, - { - {8, 7, 6, 5}, - {4, 3, 2, 1}, - {1, 2, 3, 4}, - {45, 46, 47, 58}, - }, - }}); -} From 262c87c6e1bd829396af22ca1a229558f92df810 Mon Sep 17 00:00:00 2001 From: Ilya Znamenskiy Date: Thu, 28 Oct 2021 09:30:08 +0300 Subject: [PATCH 08/12] [GPU] New OneDNN post-ops optimizations and fusing tests (#8056) * [GPU] New OneDNN post-ops optimizations and fusing tests * [GPU] Code refactoring by github comments Failing test disabled in #8109 --- .../src/impls/onednn/primitive_onednn_base.h | 195 ++++++---- .../tests/test_cases/fusings_gpu_test.cpp | 358 ++++++++++++++++++ 2 files changed, 475 insertions(+), 78 deletions(-) diff --git a/inference-engine/thirdparty/clDNN/src/impls/onednn/primitive_onednn_base.h b/inference-engine/thirdparty/clDNN/src/impls/onednn/primitive_onednn_base.h index bce27bc2cfd..10748a4c68b 100644 --- a/inference-engine/thirdparty/clDNN/src/impls/onednn/primitive_onednn_base.h +++ b/inference-engine/thirdparty/clDNN/src/impls/onednn/primitive_onednn_base.h @@ -161,6 +161,33 @@ protected: } }; + // Check that post-op type is any optimized + auto type_is_any_optimized = [](onednn_post_op_type type) -> bool { + return type == onednn_post_op_type::optimized || type == onednn_post_op_type::optimized_sum || + type == onednn_post_op_type::optimized_eltwise; + }; + + // Check that post-op type is eltwise + auto type_is_eltwise = [](onednn_post_op_type type) -> bool { + return type == onednn_post_op_type::eltwise_round || type == onednn_post_op_type::eltwise_linear || + type == onednn_post_op_type::eltwise_clip || type == onednn_post_op_type::eltwise_act; + }; + + // Check that post-op type is binary_add or binary_mul + auto type_is_binary_add_or_mul = [](onednn_post_op_type type) -> bool { + return type == onednn_post_op_type::binary_add || type == onednn_post_op_type::binary_mul; + }; + + // Simple post-op type checks + auto type_is_optimized = [](onednn_post_op_type type) -> bool { return type == onednn_post_op_type::optimized; }; + auto type_is_eltwise_linear = [](onednn_post_op_type type) -> bool { return type == onednn_post_op_type::eltwise_linear; }; + auto type_is_optimized_eltwise = [](onednn_post_op_type type) -> bool { return type == onednn_post_op_type::optimized_eltwise; }; + auto type_is_binary_add = [](onednn_post_op_type type) -> bool { return type == onednn_post_op_type::binary_add; }; + auto type_is_binary_mul = [](onednn_post_op_type type) -> bool { return type == onednn_post_op_type::binary_mul; }; + auto type_is_sum = [](onednn_post_op_type type) -> bool { return type == onednn_post_op_type::sum; }; + auto type_is_optimized_sum = [](onednn_post_op_type type) -> bool { return type == onednn_post_op_type::optimized_sum; }; + auto type_is_scale = [](onednn_post_op_type type) -> bool { return type == onednn_post_op_type::scale; }; + auto& cur_post_ops = onednn_fusing_map[node_id]; size_t cur_post_op_idx = 1; @@ -169,11 +196,11 @@ protected: // Check and update post-op map if we already optimized something for (size_t post_op_idx = 0; post_op_idx < cur_post_ops.size(); post_op_idx++) { - if (cur_post_ops[post_op_idx].op_type == onednn_post_op_type::optimized_sum) + if (type_is_optimized_sum(cur_post_ops[post_op_idx].op_type)) cur_post_ops[post_op_idx].op_type = onednn_post_op_type::sum; - else if (cur_post_ops[post_op_idx].op_type == onednn_post_op_type::optimized_eltwise) + else if (type_is_optimized_eltwise(cur_post_ops[post_op_idx].op_type)) cur_post_ops[post_op_idx].op_type = onednn_post_op_type::eltwise_linear; - else if (cur_post_ops[post_op_idx].op_type == onednn_post_op_type::optimized) + else if (type_is_optimized(cur_post_ops[post_op_idx].op_type)) cur_post_ops.erase(cur_post_ops.begin() + post_op_idx); } @@ -186,8 +213,7 @@ protected: auto prev_type = cur_post_ops[prev_post_op_idx].op_type; // Ignore optimized operations for "previous" operation in our operation pair - while ((prev_type == onednn_post_op_type::optimized || prev_type == onednn_post_op_type::optimized_sum || - prev_type == onednn_post_op_type::optimized_eltwise) && cur_post_op_idx < post_ops_size - 1) { + while (type_is_any_optimized(prev_type) && cur_post_op_idx < post_ops_size - 1) { prev_post_op_idx++; cur_post_op_idx++; prev_type = cur_post_ops[prev_post_op_idx].op_type; @@ -195,80 +221,83 @@ protected: } // Ignore optimized operations for "current" operation in our operation pair - while ((cur_type == onednn_post_op_type::optimized || cur_type == onednn_post_op_type::optimized_sum || - cur_type == onednn_post_op_type::optimized_eltwise) && cur_post_op_idx < post_ops_size - 1) { + while (type_is_any_optimized(cur_type) && cur_post_op_idx < post_ops_size - 1) { cur_post_op_idx++; cur_type = cur_post_ops[cur_post_op_idx].op_type; } auto cur_idx = static_cast(has_out_scales(attr) ? (cur_post_op_idx >= 1 ? cur_post_op_idx - 1 : 0) : cur_post_op_idx); auto prev_idx = static_cast(has_out_scales(attr) ? (prev_post_op_idx >= 1 ? prev_post_op_idx - 1 : 0) : prev_post_op_idx); - auto cur_type_is_optimized = cur_type == onednn_post_op_type::optimized || - cur_type == onednn_post_op_type::optimized_sum || - cur_type == onednn_post_op_type::optimized_eltwise; - auto prev_type_is_optimized = prev_type == onednn_post_op_type::optimized || - prev_type == onednn_post_op_type::optimized_sum || - prev_type == onednn_post_op_type::optimized_eltwise; // If this is the last pair and it's optimized - add the last post-op and go out from the cycle - if (cur_post_op_idx == post_ops_size - 1 && (cur_type_is_optimized || prev_type_is_optimized)) { - if (!prev_type_is_optimized) { + if (cur_post_op_idx == post_ops_size - 1 && (type_is_any_optimized(cur_type) || type_is_any_optimized(prev_type))) { + if (!type_is_any_optimized(prev_type)) { add_post_op(prev_type, p_ops, optimized_p_ops, prev_idx); } - if (!cur_type_is_optimized) { + if (!type_is_any_optimized(cur_type)) { add_post_op(cur_type, p_ops, optimized_p_ops, cur_idx); } break; } - auto equal_ops = cur_type == prev_type; - auto cur_type_is_binary_add_or_mul = cur_type == onednn_post_op_type::binary_add || cur_type == onednn_post_op_type::binary_mul; - auto prev_type_is_binary_add_or_mul = prev_type == onednn_post_op_type::binary_add || prev_type == onednn_post_op_type::binary_mul; - // Post-ops combinations which can be simplified - auto eltw_and_eltw = equal_ops && cur_type == onednn_post_op_type::eltwise_linear; - auto bin_and_eltw = cur_type_is_binary_add_or_mul && prev_type == onednn_post_op_type::eltwise_linear; - auto eltw_and_bin = cur_type == onednn_post_op_type::eltwise_linear && prev_type_is_binary_add_or_mul; - auto eltw_and_sum = cur_type == onednn_post_op_type::eltwise_linear && prev_type == onednn_post_op_type::sum; - auto eltw_and_scale = cur_type == onednn_post_op_type::eltwise_linear && prev_type == onednn_post_op_type::scale; + auto eltw_and_eltw = type_is_eltwise(cur_type) && type_is_eltwise(prev_type); + auto bin_and_eltw = type_is_binary_add_or_mul(cur_type) && type_is_eltwise_linear(prev_type); + auto eltw_and_bin = type_is_eltwise_linear(cur_type) && type_is_binary_add_or_mul(prev_type); + auto sum_and_eltw = type_is_sum(cur_type) && type_is_eltwise(prev_type); + auto eltw_and_scale = type_is_eltwise_linear(cur_type) && type_is_scale(prev_type); auto can_try_optimize = eltw_and_eltw || bin_and_eltw || eltw_and_bin || - eltw_and_sum || + sum_and_eltw || eltw_and_scale; bool cur_ops_pair_is_optimized = false; if (can_try_optimize) { if (eltw_and_eltw) { - dnnl::algorithm alg; + dnnl::algorithm cur_alg, prev_alg; float cur_scale, prev_scale, cur_alpha, prev_alpha, cur_beta, prev_beta; - p_ops.get_params_eltwise(prev_idx, prev_scale, alg, prev_alpha, prev_beta); - p_ops.get_params_eltwise(cur_idx, cur_scale, alg, cur_alpha, cur_beta); + p_ops.get_params_eltwise(prev_idx, prev_scale, prev_alg, prev_alpha, prev_beta); + p_ops.get_params_eltwise(cur_idx, cur_scale, cur_alg, cur_alpha, cur_beta); - // Eltwise + eltwise pair can be optimized only if cur_alpha is equal to 1.0f - if (cur_alpha == 1.0f && prev_scale == cur_scale) { + auto eltw_linear_and_eltw_linear = type_is_eltwise_linear(cur_type) && type_is_eltwise_linear(prev_type); + auto eltw_linear_and_eltw_non_linear = type_is_eltwise_linear(cur_type) && !type_is_eltwise_linear(prev_type) && cur_beta == 0; + + // eltwise_linear + eltwise_linear combination can be optimized always + if (eltw_linear_and_eltw_linear) { dnnl::post_ops eltw_p_op; - eltw_p_op.append_eltwise(cur_scale, alg, prev_alpha, cur_beta + prev_beta); + float optimized_alpha = cur_alpha * prev_alpha * prev_scale; + float optimized_beta = cur_alpha * prev_beta * prev_scale + cur_beta; + float optimized_scale = cur_scale; + eltw_p_op.append_eltwise(optimized_scale, cur_alg, optimized_alpha, optimized_beta); // Combine 2 eltwises into one add_post_op(cur_type, eltw_p_op, optimized_p_ops, 0); + } else if (eltw_linear_and_eltw_non_linear) { + dnnl::post_ops eltw_p_op; + eltw_p_op.append_eltwise(cur_scale * prev_scale * cur_alpha, prev_alg, prev_alpha, prev_beta); + // Combine 2 eltwises into one + add_post_op(prev_type, eltw_p_op, optimized_p_ops, 0); + } + + if (eltw_linear_and_eltw_linear || eltw_linear_and_eltw_non_linear) { // Marked current and previous eltwise operations as 'optimized' (they will be ignored on the next iteration of cycle) cur_post_ops[cur_post_op_idx].op_type = onednn_post_op_type::optimized; cur_post_ops[prev_post_op_idx].op_type = onednn_post_op_type::optimized_eltwise; // Set the flag if extra optimizations checking is needed if (cur_post_op_idx < post_ops_size - 1) { - if (cur_post_ops[cur_post_op_idx + 1].op_type == onednn_post_op_type::eltwise_linear || - cur_post_ops[cur_post_op_idx + 1].op_type == onednn_post_op_type::binary_add || - cur_post_ops[cur_post_op_idx + 1].op_type == onednn_post_op_type::binary_mul || - cur_post_ops[cur_post_op_idx + 1].op_type == onednn_post_op_type::optimized_eltwise) { + if (type_is_eltwise_linear(cur_post_ops[cur_post_op_idx + 1].op_type) || + type_is_binary_add_or_mul(cur_post_ops[cur_post_op_idx + 1].op_type) || + type_is_optimized_eltwise(cur_post_ops[cur_post_op_idx + 1].op_type)) { optimization_is_completed = true; } } + cur_ops_pair_is_optimized = true; } } else if (bin_and_eltw) { @@ -285,11 +314,13 @@ protected: auto bin_ops_can_be_optimized = cur_node.is_type() && cur_node.is_constant() && cur_node.get_users().size() == 1 && desc.data_type() == dnnl_f32; - auto bin_add_and_eltw = alpha == 1.0f && scale == 1.0f && cur_type == onednn_post_op_type::binary_add && bin_ops_can_be_optimized; - auto bin_mul_and_eltw = beta == 0.f && scale == 1.0f && cur_type == onednn_post_op_type::binary_mul && bin_ops_can_be_optimized; + auto bin_add_and_eltw = alpha == 1.0f && scale == 1.0f && type_is_binary_add(cur_type) && bin_ops_can_be_optimized; + auto bin_mul_and_eltw = beta == 0.f && type_is_binary_mul(cur_type) && bin_ops_can_be_optimized; if (bin_add_and_eltw || bin_mul_and_eltw) { memory::ptr cur_bin_mem_ptr = cur_node.as().get_attached_memory_ptr(); + if (cur_bin_mem_ptr == nullptr) + throw std::runtime_error("OneDNN post-ops optimization error: nonexistent node for bin + eltw"); auto& stream = cur_bin_mem_ptr->get_engine()->get_program_stream(); mem_lock bin_and_eltw_lock(cur_bin_mem_ptr, stream); @@ -302,7 +333,7 @@ protected: } } else { for (size_t data_idx = 0; data_idx < cur_bin_mem_size; data_idx++) { - bin_and_eltw_lock[data_idx] *= alpha; + bin_and_eltw_lock[data_idx] *= alpha * scale; } } @@ -325,11 +356,13 @@ protected: auto bin_ops_can_be_optimized = prev_node.is_type() && prev_node.is_constant() && prev_node.get_users().size() == 1 && desc.data_type() == dnnl_f32; - auto eltw_and_bin_add = alpha == 1.0f && scale == 1.0f && prev_type == onednn_post_op_type::binary_add && bin_ops_can_be_optimized; - auto eltw_and_bin_mul = beta == 0.f && scale == 1.0f && prev_type == onednn_post_op_type::binary_mul && bin_ops_can_be_optimized; + auto eltw_and_bin_add = alpha == 1.0f && scale == 1.0f && type_is_binary_add(prev_type) && bin_ops_can_be_optimized; + auto eltw_and_bin_mul = beta == 0.f && type_is_binary_mul(prev_type) && bin_ops_can_be_optimized; if (eltw_and_bin_add || eltw_and_bin_mul) { memory::ptr prev_bin_mem_ptr = prev_node.as().get_attached_memory_ptr(); + if (prev_bin_mem_ptr == nullptr) + throw std::runtime_error("OneDNN post-ops optimization error: nonexistent node for eltw + bin"); auto& stream = prev_bin_mem_ptr->get_engine()->get_program_stream(); mem_lock eltw_and_bin_lock(prev_bin_mem_ptr, stream); @@ -342,7 +375,7 @@ protected: } } else { for (size_t data_idx = 0; data_idx < prev_bin_mem_size; data_idx++) { - eltw_and_bin_lock[data_idx] *= alpha; + eltw_and_bin_lock[data_idx] *= alpha * scale; } } @@ -351,63 +384,69 @@ protected: cur_ops_pair_is_optimized = true; } - } else if (eltw_and_sum) { + } else if (sum_and_eltw) { dnnl::algorithm alg; - float cur_scale, prev_scale, alpha, beta; + float sum_scale, eltw_scale, alpha, beta; dnnl::memory::data_type data_type; - cldnn::program_node& prev_node = arg.get_dependency(cur_post_ops[prev_post_op_idx].mem_dep); + dnnl::algorithm next_alg; + float next_scale, next_alpha, next_beta; + size_t next_idx = cur_idx + 1; + size_t next_post_op_idx = cur_post_op_idx + 1; - p_ops.get_params_eltwise(cur_idx, cur_scale, alg, alpha, beta); - p_ops.get_params_sum(prev_idx, prev_scale, data_type); + bool can_optimize_eltw_and_sum = false; - // Eltwise operations can use runtime non-constant data buffers, so check that memory buffers consist of constant data only - auto eltw_ops_can_be_optimized = prev_node.is_type() && prev_node.is_constant() && - prev_node.get_users().size() == 1; + if (cur_post_op_idx < post_ops_size - 1) { + auto next_type = cur_post_ops[next_post_op_idx].op_type; + if (type_is_eltwise_linear(next_type)) { + p_ops.get_params_eltwise(next_idx, next_scale, next_alg, next_alpha, next_beta); - // Eltwise can be inserted into the scale field of previous sum if cur_beta is equal to 0.f - if (beta == 0.f && cur_scale == 1.0f && eltw_ops_can_be_optimized) { - dnnl::post_ops sum_p_op; - sum_p_op.append_sum(alpha * prev_scale, data_type); - - // Insert cur eltwise into sum - add_post_op(prev_type, sum_p_op, optimized_p_ops, 0); - - memory::ptr prev_eltw_mem_ptr = prev_node.as().get_attached_memory_ptr(); - auto& stream = prev_eltw_mem_ptr->get_engine()->get_program_stream(); - mem_lock eltw_and_sum_lock(prev_eltw_mem_ptr, stream); - - size_t prev_eltw_mem_size = prev_node.get_output_layout().count(); - - // Also multiply sum on alpha for getting valid results - for (size_t data_idx = 0; data_idx < prev_eltw_mem_size; data_idx++) { - eltw_and_sum_lock[data_idx] *= alpha; + if (next_beta == 0) + can_optimize_eltw_and_sum = true; } + } - // Marked current and previous operations as 'optimized' (they will be ignored on the next iteration of cycle) - cur_post_ops[cur_post_op_idx].op_type = onednn_post_op_type::optimized; - cur_post_ops[prev_post_op_idx].op_type = onednn_post_op_type::optimized_sum; + // Try to optimize eltwise (any) + sum + eltwise_linear (with beta = 0) chain of operations + if (can_optimize_eltw_and_sum) { + p_ops.get_params_sum(cur_idx, sum_scale, data_type); + p_ops.get_params_eltwise(prev_idx, eltw_scale, alg, alpha, beta); + + dnnl::post_ops eltw_p_op_prev, sum_p_op; + + eltw_p_op_prev.append_eltwise(eltw_scale * next_alpha * next_scale, alg, alpha, beta); + sum_p_op.append_sum(sum_scale * next_alpha, data_type); + + add_post_op(prev_type, eltw_p_op_prev, optimized_p_ops, 0); + add_post_op(cur_type, sum_p_op, optimized_p_ops, 0); + + // Marked current, previous and next operations as 'optimized' (they will be ignored on the next iteration of cycle) + cur_post_ops[prev_post_op_idx].op_type = onednn_post_op_type::optimized_eltwise; + cur_post_ops[cur_post_op_idx].op_type = onednn_post_op_type::optimized_sum; + cur_post_ops[next_post_op_idx].op_type = onednn_post_op_type::optimized; // Set the flag if extra optimizations checking is needed - if (cur_post_op_idx < post_ops_size - 1) { - if (cur_post_ops[cur_post_op_idx + 1].op_type == onednn_post_op_type::eltwise_linear || - cur_post_ops[cur_post_op_idx + 1].op_type == onednn_post_op_type::optimized_eltwise) { + if (next_post_op_idx < post_ops_size - 1) { + if (type_is_eltwise_linear(cur_post_ops[next_post_op_idx + 1].op_type) || + type_is_optimized_eltwise(cur_post_ops[next_post_op_idx + 1].op_type)) { optimization_is_completed = true; } } + cur_ops_pair_is_optimized = true; } } else if (eltw_and_scale) { dnnl::algorithm alg; - float cur_scale, alpha, beta; + float eltw_scale, alpha, beta; cldnn::program_node& prev_node = arg.get_dependency(cur_post_ops[prev_post_op_idx].mem_dep); - p_ops.get_params_eltwise(cur_idx, cur_scale, alg, alpha, beta); + p_ops.get_params_eltwise(cur_idx, eltw_scale, alg, alpha, beta); - // Eltwise can be inserted into output_scale if cur_beta is equal to 0.f and cur_scale is equal to 1.0f - if (beta == 0.f && cur_scale == 1.0f && prev_node.get_output_layout().data_type == data_types::f32) { + // Eltwise can be inserted into the output_scale if cur_beta is equal to 0.f + if (beta == 0.f && prev_node.get_output_layout().data_type == data_types::f32) { memory::ptr prev_scale_mem_ptr = prev_node.as().get_attached_memory_ptr(); + if (prev_scale_mem_ptr == nullptr) + throw std::runtime_error("OneDNN post-ops optimization error: nonexistent node for eltw + scale"); auto& stream = prev_scale_mem_ptr->get_engine()->get_program_stream(); mem_lock eltw_and_scale_lock(prev_scale_mem_ptr, stream); @@ -415,7 +454,7 @@ protected: // Update all scale coefficients for (size_t data_idx = 0; data_idx < prev_scale_mem_size; data_idx++) { - eltw_and_scale_lock[data_idx] *= alpha; + eltw_and_scale_lock[data_idx] *= alpha * eltw_scale; } // Marked current eltwise operation as 'optimized' (it will be ignored on the next iteration of cycle) diff --git a/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp b/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp index 0089df16947..888c1cfe161 100644 --- a/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp +++ b/inference-engine/thirdparty/clDNN/tests/test_cases/fusings_gpu_test.cpp @@ -9433,6 +9433,364 @@ INSTANTIATE_TEST_SUITE_P(fusings_gpu, conv_int8_scale_shift_swish_onednn, bc_test_params{CASE_CONV_S8S8_13, 2, 7}, bc_test_params{CASE_CONV_S8S8_15, 2, 7}, })); + +/* ----------------------------------------------------------------------------------------------------- */ +/* ------------------------------ OneDNN post-ops cases with optimizations ----------------------------- */ +/* ----------------------------------------------------------------------------------------------------- */ + +// Before optimization: eltw_linear + eltw_linear +// After optimization: eltw_linear +// Limitations: no +// DNNL_VERBOSE log without optimization: attr-post-ops:eltwise_linear:12.75:127.5+eltwise_linear:1:-128 +// DNNL_VERBOSE log with optimization: attr-post-ops:eltwise_linear:12.75:-0.5 +class post_ops_optimizations_onednn_eltw_linear_eltw_linear : public ConvFusingTestOneDNN {}; +TEST_P(post_ops_optimizations_onednn_eltw_linear_eltw_linear, basic) { + auto p = GetParam(); + create_topologies(input_layout("input", get_input_layout(p)), + data("weights", get_mem(get_weights_layout(p))), + data("bias", get_mem(get_bias_layout(p))), + data("in_lo", get_mem(get_single_element_layout(p), -10)), + data("in_hi", get_mem(get_single_element_layout(p), 10)), + data("out_lo", get_mem(get_single_element_layout(p), -128)), + data("out_hi", get_mem(get_single_element_layout(p), 127)), + convolution("conv_prim", "input", { "weights" }, { "bias" }, p.groups, p.stride, p.pad, p.dilation), + quantize("quantize", "conv_prim", "in_lo", "in_hi", "out_lo", "out_hi", 256, data_types::i8), + reorder("reorder_bfyx", "quantize", p.default_format, data_types::f32) + ); + + tolerance = 1.f; + execute(p); +} + +INSTANTIATE_TEST_SUITE_P(fusings_gpu, post_ops_optimizations_onednn_eltw_linear_eltw_linear, + ::testing::ValuesIn(std::vector{ + // cases with batch = 1 + bc_test_params{CASE_CONV_U8S8_1, 2, 3}, + bc_test_params{CASE_CONV_U8S8_2, 2, 3}, + bc_test_params{CASE_CONV_U8S8_3, 2, 3}, + bc_test_params{CASE_CONV_S8S8_1, 2, 3}, + bc_test_params{CASE_CONV_S8S8_2, 2, 3}, + bc_test_params{CASE_CONV_S8S8_3, 2, 3}, + + // cases with batch = 16 + bc_test_params{CASE_CONV_U8S8_9, 2, 3}, + bc_test_params{CASE_CONV_U8S8_10, 2, 3}, + bc_test_params{CASE_CONV_S8S8_9, 2, 3}, + bc_test_params{CASE_CONV_S8S8_10, 2, 3}, + + // cases with batch = 32 + bc_test_params{CASE_CONV_U8S8_11, 2, 3}, + bc_test_params{CASE_CONV_U8S8_12, 2, 3}, + bc_test_params{CASE_CONV_U8S8_13, 2, 3}, + bc_test_params{CASE_CONV_U8S8_14, 2, 3}, + bc_test_params{CASE_CONV_S8S8_12, 2, 3}, + bc_test_params{CASE_CONV_S8S8_13, 2, 3}, + bc_test_params{CASE_CONV_S8S8_14, 2, 3}, + bc_test_params{CASE_CONV_S8S8_15, 2, 3}, + })); + +// Before optimization: eltw_non_linear + eltw_linear +// After optimization: eltw_non_linear +// Limitations: beta = 0 in eltw_linear +// DNNL_VERBOSE log without optimization: attr-post-ops:eltwise_linear:12.75:127.5+eltwise_round+eltwise_linear:2.00784+eltwise_clip:0:512 +// DNNL_VERBOSE log with optimization: attr-post-ops:eltwise_linear:12.75:127.5+eltwise_round:0:0:2.00784+eltwise_clip:0:512 +class post_ops_optimizations_onednn_eltw_non_linear_eltw_linear : public ConvFusingTestOneDNN {}; +TEST_P(post_ops_optimizations_onednn_eltw_non_linear_eltw_linear, basic) { + auto p = GetParam(); + create_topologies(input_layout("input", get_input_layout(p)), + data("weights", get_mem(get_weights_layout(p))), + data("bias", get_mem(get_bias_layout(p))), + data("in_lo", get_mem(get_single_element_layout(p), -10)), + data("in_hi", get_mem(get_single_element_layout(p), 10)), + data("out_lo", get_mem(get_single_element_layout(p), 0)), + data("out_hi", get_mem(get_single_element_layout(p), 512)), + convolution("conv_prim", "input", { "weights" }, { "bias" }, p.groups, p.stride, p.pad, p.dilation), + quantize("quantize", "conv_prim", "in_lo", "in_hi", "out_lo", "out_hi", 256, data_types::f32), + reorder("reorder_bfyx", "quantize", p.default_format, data_types::f32) + ); + + tolerance = 1.f; + execute(p); +} + +INSTANTIATE_TEST_SUITE_P(fusings_gpu, post_ops_optimizations_onednn_eltw_non_linear_eltw_linear, + ::testing::ValuesIn(std::vector{ + // cases with batch = 1 + bc_test_params{CASE_CONV_U8S8_1, 2, 3}, + bc_test_params{CASE_CONV_U8S8_2, 2, 3}, + bc_test_params{CASE_CONV_U8S8_3, 2, 3}, + bc_test_params{CASE_CONV_S8S8_1, 2, 3}, + bc_test_params{CASE_CONV_S8S8_2, 2, 3}, + bc_test_params{CASE_CONV_S8S8_3, 2, 3}, + + // cases with batch = 16 + bc_test_params{CASE_CONV_U8S8_9, 2, 3}, + bc_test_params{CASE_CONV_U8S8_10, 2, 3}, + bc_test_params{CASE_CONV_S8S8_9, 2, 3}, + bc_test_params{CASE_CONV_S8S8_10, 2, 3}, + + // cases with batch = 32 + bc_test_params{CASE_CONV_U8S8_11, 2, 3}, + bc_test_params{CASE_CONV_U8S8_12, 2, 3}, + bc_test_params{CASE_CONV_U8S8_13, 2, 3}, + bc_test_params{CASE_CONV_U8S8_14, 2, 3}, + bc_test_params{CASE_CONV_S8S8_12, 2, 3}, + bc_test_params{CASE_CONV_S8S8_13, 2, 3}, + bc_test_params{CASE_CONV_S8S8_14, 2, 3}, + bc_test_params{CASE_CONV_S8S8_15, 2, 3}, + })); + +// Before optimization: binary_add + eltw_linear +// After optimization: binary_add +// Limitations: alpha = 1 and scale = 1 in eltw_linear; binary_add is a constant compile-time buffer +// DNNL_VERBOSE log without optimization: attr-oscale:2 attr-post-ops:binary_add:f32:2+eltwise_linear:1:-127+eltwise_clip:-127:127 +// DNNL_VERBOSE log with optimization: attr-oscale:2 attr-post-ops:binary_add:f32:2+eltwise_clip:-127:127 +class post_ops_optimizations_onednn_binary_add_eltw_linear : public ConvFusingTestOneDNN {}; +TEST_P(post_ops_optimizations_onednn_binary_add_eltw_linear, basic) { + auto p = GetParam(); + create_topologies(input_layout("input", get_input_layout(p)), + data("weights", get_mem(get_weights_layout(p))), + data("bias", get_mem(get_bias_layout(p))), + data("in_lo", get_mem(get_per_channel_layout(p), min_random, 0)), + data("in_hi", get_mem(get_per_channel_layout(p), 1, max_random)), + data("out_lo", get_mem(get_single_element_layout(p), -127)), + data("out_hi", get_mem(get_single_element_layout(p), 127)), + convolution("conv_prim", "input", { "weights" }, { "bias" }, p.groups, p.stride, p.pad, p.dilation), + quantize("quantize", "conv_prim", "in_lo", "in_hi", "out_lo", "out_hi", 255, data_types::i8), + reorder("reorder_bfyx", "quantize", p.default_format, data_types::f32) + ); + + tolerance = 1.f; + execute(p); +} + +INSTANTIATE_TEST_SUITE_P(fusings_gpu, post_ops_optimizations_onednn_binary_add_eltw_linear, + ::testing::ValuesIn(std::vector{ + // cases with batch = 1 + bc_test_params{CASE_CONV_U8S8_1, 2, 3}, + bc_test_params{CASE_CONV_U8S8_2, 2, 3}, + bc_test_params{CASE_CONV_U8S8_3, 2, 3}, + bc_test_params{CASE_CONV_S8S8_1, 2, 3}, + bc_test_params{CASE_CONV_S8S8_2, 2, 3}, + bc_test_params{CASE_CONV_S8S8_3, 2, 3}, + + // cases with batch = 16 + bc_test_params{CASE_CONV_U8S8_9, 2, 3}, + bc_test_params{CASE_CONV_U8S8_10, 2, 3}, + bc_test_params{CASE_CONV_S8S8_9, 2, 3}, + bc_test_params{CASE_CONV_S8S8_10, 2, 3}, + + // cases with batch = 32 + bc_test_params{CASE_CONV_U8S8_11, 2, 3}, + bc_test_params{CASE_CONV_U8S8_12, 2, 3}, + bc_test_params{CASE_CONV_U8S8_13, 2, 3}, + bc_test_params{CASE_CONV_U8S8_14, 2, 3}, + bc_test_params{CASE_CONV_S8S8_12, 2, 3}, + bc_test_params{CASE_CONV_S8S8_13, 2, 3}, + bc_test_params{CASE_CONV_S8S8_14, 2, 3}, + bc_test_params{CASE_CONV_S8S8_15, 2, 3}, + })); + +// Before optimization: binary_mul + eltw_linear +// After optimization: binary_mul +// Limitations: beta = 0 in eltw_linear; binary_mul is a constant compile-time buffer +// DNNL_VERBOSE log without optimization: attr-oscale:2 attr-post-ops:binary_mul:f32:2+eltwise_linear:2.01575+eltwise_clip:0:512 +// DNNL_VERBOSE log with optimization: attr-oscale:2 attr-post-ops:binary_mul:f32:2+eltwise_clip:0:512 +class post_ops_optimizations_onednn_binary_mul_eltw_linear : public ConvFusingTestOneDNN {}; +TEST_P(post_ops_optimizations_onednn_binary_mul_eltw_linear, basic) { + auto p = GetParam(); + create_topologies(input_layout("input", get_input_layout(p)), + data("weights", get_mem(get_weights_layout(p))), + data("bias", get_mem(get_bias_layout(p))), + data("eltwise_data", get_mem(get_per_channel_layout(p), -1, 1)), + data("in_lo", get_mem(get_per_channel_layout(p), 0)), + data("in_hi", get_mem(get_per_channel_layout(p), 1, max_random)), + data("out_lo", get_mem(get_single_element_layout(p), 0)), + data("out_hi", get_mem(get_single_element_layout(p), 512)), + convolution("conv_prim", "input", { "weights" }, { "bias" }, p.groups, p.stride, p.pad, p.dilation), + eltwise("eltwise", { "conv_prim", "eltwise_data" }, eltwise_mode::prod), + quantize("quantize", "eltwise", "in_lo", "in_hi", "out_lo", "out_hi", 255, data_types::i8), + reorder("reorder_bfyx", "quantize", p.default_format, data_types::f32) + ); + + tolerance = 1.f; + execute(p); +} + +INSTANTIATE_TEST_SUITE_P(fusings_gpu, post_ops_optimizations_onednn_binary_mul_eltw_linear, + ::testing::ValuesIn(std::vector{ + // cases with batch = 1 + bc_test_params{CASE_CONV_U8S8_1, 2, 4}, + bc_test_params{CASE_CONV_U8S8_2, 2, 4}, + bc_test_params{CASE_CONV_U8S8_3, 2, 4}, + bc_test_params{CASE_CONV_S8S8_1, 2, 4}, + bc_test_params{CASE_CONV_S8S8_2, 2, 4}, + bc_test_params{CASE_CONV_S8S8_3, 2, 4}, + + // cases with batch = 16 + bc_test_params{CASE_CONV_U8S8_9, 2, 4}, + bc_test_params{CASE_CONV_U8S8_10, 2, 4}, + bc_test_params{CASE_CONV_S8S8_9, 2, 4}, + bc_test_params{CASE_CONV_S8S8_10, 2, 4}, + + // cases with batch = 32 + bc_test_params{CASE_CONV_U8S8_11, 2, 4}, + bc_test_params{CASE_CONV_U8S8_12, 2, 4}, + bc_test_params{CASE_CONV_U8S8_13, 2, 4}, + bc_test_params{CASE_CONV_S8S8_12, 2, 4}, + bc_test_params{CASE_CONV_S8S8_13, 2, 4}, + bc_test_params{CASE_CONV_S8S8_14, 2, 4}, + })); + +// Before optimization: o_scale + eltw_linear +// After optimization: o_scale +// Limitations: beta = 0 in eltw_linear +// DNNL_VERBOSE log without optimization: attr-oscale:2 attr-post-ops:eltwise_linear:2.01575+eltwise_clip:0:512 +// DNNL_VERBOSE log with optimization: attr-oscale:2 attr-post-ops:eltwise_clip:0:512 +class post_ops_optimizations_onednn_oscale_eltw_linear : public ConvFusingTestOneDNN {}; +TEST_P(post_ops_optimizations_onednn_oscale_eltw_linear, basic) { + auto p = GetParam(); + create_topologies(input_layout("input", get_input_layout(p)), + data("weights", get_mem(get_weights_layout(p))), + data("bias", get_mem(get_bias_layout(p))), + data("in_lo", get_mem(get_per_channel_layout(p), 0)), + data("in_hi", get_mem(get_per_channel_layout(p), 1, max_random)), + data("out_lo", get_mem(get_single_element_layout(p), 0)), + data("out_hi", get_mem(get_single_element_layout(p), 512)), + convolution("conv_prim", "input", { "weights" }, { "bias" }, p.groups, p.stride, p.pad, p.dilation), + quantize("quantize", "conv_prim", "in_lo", "in_hi", "out_lo", "out_hi", 255, data_types::i8), + reorder("reorder_bfyx", "quantize", p.default_format, data_types::f32) + ); + + tolerance = 1.f; + execute(p); +} + +INSTANTIATE_TEST_SUITE_P(fusings_gpu, post_ops_optimizations_onednn_oscale_eltw_linear, + ::testing::ValuesIn(std::vector{ + // cases with batch = 1 + bc_test_params{CASE_CONV_U8S8_1, 2, 3}, + bc_test_params{CASE_CONV_U8S8_2, 2, 3}, + bc_test_params{CASE_CONV_U8S8_3, 2, 3}, + bc_test_params{CASE_CONV_S8S8_1, 2, 3}, + bc_test_params{CASE_CONV_S8S8_2, 2, 3}, + bc_test_params{CASE_CONV_S8S8_3, 2, 3}, + + // cases with batch = 16 + bc_test_params{CASE_CONV_U8S8_9, 2, 3}, + bc_test_params{CASE_CONV_U8S8_10, 2, 3}, + bc_test_params{CASE_CONV_S8S8_9, 2, 3}, + bc_test_params{CASE_CONV_S8S8_10, 2, 3}, + + // cases with batch = 32 + bc_test_params{CASE_CONV_U8S8_11, 2, 3}, + bc_test_params{CASE_CONV_U8S8_12, 2, 3}, + bc_test_params{CASE_CONV_U8S8_13, 2, 3}, + bc_test_params{CASE_CONV_S8S8_12, 2, 3}, + bc_test_params{CASE_CONV_S8S8_13, 2, 3}, + bc_test_params{CASE_CONV_S8S8_14, 2, 3}, + })); + +// Before optimization: eltw_any + sum + eltw_linear +// After optimization: eltw_any + sum +// Limitations: beta = 0 in eltw_linear +// DNNL_VERBOSE log without optimization: attr-post-ops:eltwise_relu+sum:1:0:u8+eltwise_linear:12.7+eltwise_clip:0:127 +// DNNL_VERBOSE log with optimization: attr-post-ops:eltwise_relu:0:0:12.7+sum:12.7:0:u8+eltwise_clip:0:127 +class post_ops_optimizations_onednn_eltw_any_sum_eltw_linear : public ConvFusingTestOneDNN {}; +TEST_P(post_ops_optimizations_onednn_eltw_any_sum_eltw_linear, basic) { + auto p = GetParam(); + create_topologies(input_layout("input", get_input_layout(p)), + data("weights", get_mem(get_weights_layout(p))), + data("bias", get_mem(get_bias_layout(p))), + data("in_lo", get_mem(get_single_element_layout(p), 0)), + data("in_hi", get_mem(get_single_element_layout(p), 10)), + data("out_lo", get_mem(get_single_element_layout(p), 0)), + data("out_hi", get_mem(get_single_element_layout(p), 127)), + data("eltwise_data", get_mem(get_output_layout(p))), + convolution("conv_prim", "input", { "weights" }, { "bias" }, p.groups, p.stride, p.pad, p.dilation), + activation("activation", "conv_prim", activation_func::relu_negative_slope), + eltwise("sum", { "activation", "eltwise_data" }, eltwise_mode::sum), + quantize("quantize", "sum", "in_lo", "in_hi", "out_lo", "out_hi", 128, data_types::u8), + reorder("reorder_bfyx", "quantize", p.default_format, data_types::f32) + ); + + tolerance = 1.f; + execute(p); +} + +INSTANTIATE_TEST_SUITE_P(fusings_gpu, post_ops_optimizations_onednn_eltw_any_sum_eltw_linear, + ::testing::ValuesIn(std::vector{ + // cases with batch = 1 + bc_test_params{CASE_CONV_U8S8_1, 2, 5}, + bc_test_params{CASE_CONV_U8S8_2, 2, 5}, + bc_test_params{CASE_CONV_U8S8_3, 2, 5}, + bc_test_params{CASE_CONV_S8S8_1, 2, 5}, + bc_test_params{CASE_CONV_S8S8_2, 2, 5}, + bc_test_params{CASE_CONV_S8S8_3, 2, 5}, + + // cases with batch = 16 + bc_test_params{CASE_CONV_U8S8_10, 2, 5}, + bc_test_params{CASE_CONV_S8S8_10, 2, 5}, + + // cases with batch = 32 + bc_test_params{CASE_CONV_U8S8_11, 2, 5}, + bc_test_params{CASE_CONV_U8S8_12, 2, 5}, + bc_test_params{CASE_CONV_U8S8_13, 2, 5}, + bc_test_params{CASE_CONV_U8S8_14, 2, 5}, + bc_test_params{CASE_CONV_S8S8_12, 2, 5}, + bc_test_params{CASE_CONV_S8S8_13, 2, 5}, + bc_test_params{CASE_CONV_S8S8_14, 2, 5}, + bc_test_params{CASE_CONV_S8S8_15, 2, 5}, + })); + +// Input range uses in 2 cases: not per-tensor output range or out_lo > out_hi +// Here's out_lo > out_hi and no optimizations +// DNNL_VERBOSE log: attr-post-ops:eltwise_linear:12.75:127.5+eltwise_round+eltwise_linear:-1:127 +class post_ops_optimizations_input_range : public ConvFusingTestOneDNN {}; +TEST_P(post_ops_optimizations_input_range, basic) { + auto p = GetParam(); + create_topologies(input_layout("input", get_input_layout(p)), + data("weights", get_mem(get_weights_layout(p))), + data("bias", get_mem(get_bias_layout(p))), + data("in_lo", get_mem(get_single_element_layout(p), -10)), + data("in_hi", get_mem(get_single_element_layout(p), 10)), + data("out_lo", get_mem(get_single_element_layout(p), 127)), + data("out_hi", get_mem(get_single_element_layout(p), -128)), + convolution("conv_prim", "input", { "weights" }, { "bias" }, p.groups, p.stride, p.pad, p.dilation), + quantize("quantize", "conv_prim", "in_lo", "in_hi", "out_lo", "out_hi", 256, data_types::i8), + reorder("reorder_bfyx", "quantize", p.default_format, data_types::f32) + ); + + tolerance = 1.f; + execute(p); +} + +INSTANTIATE_TEST_SUITE_P(fusings_gpu, post_ops_optimizations_input_range, + ::testing::ValuesIn(std::vector{ + // cases with batch = 1 + bc_test_params{CASE_CONV_U8S8_1, 2, 3}, + bc_test_params{CASE_CONV_U8S8_2, 2, 3}, + bc_test_params{CASE_CONV_U8S8_3, 2, 3}, + bc_test_params{CASE_CONV_S8S8_1, 2, 3}, + bc_test_params{CASE_CONV_S8S8_2, 2, 3}, + bc_test_params{CASE_CONV_S8S8_3, 2, 3}, + + // cases with batch = 16 + bc_test_params{CASE_CONV_U8S8_9, 2, 3}, + bc_test_params{CASE_CONV_U8S8_10, 2, 3}, + bc_test_params{CASE_CONV_S8S8_9, 2, 3}, + bc_test_params{CASE_CONV_S8S8_10, 2, 3}, + + // cases with batch = 32 + bc_test_params{CASE_CONV_U8S8_11, 2, 3}, + bc_test_params{CASE_CONV_U8S8_12, 2, 3}, + bc_test_params{CASE_CONV_U8S8_13, 2, 3}, + bc_test_params{CASE_CONV_U8S8_14, 2, 3}, + bc_test_params{CASE_CONV_S8S8_12, 2, 3}, + bc_test_params{CASE_CONV_S8S8_13, 2, 3}, + bc_test_params{CASE_CONV_S8S8_14, 2, 3}, + bc_test_params{CASE_CONV_S8S8_15, 2, 3}, + })); #endif From db9fbcbec28c9d832fced8c51824b1f3d130f75c Mon Sep 17 00:00:00 2001 From: Sergey Shlyapnikov Date: Thu, 28 Oct 2021 09:37:25 +0300 Subject: [PATCH 09/12] [GPU] Fix output format for FP16/FP32 Convolution output (#8223) --- .../thirdparty/clDNN/src/layout_optimizer.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/inference-engine/thirdparty/clDNN/src/layout_optimizer.cpp b/inference-engine/thirdparty/clDNN/src/layout_optimizer.cpp index 3e80a995713..c9be94318ad 100644 --- a/inference-engine/thirdparty/clDNN/src/layout_optimizer.cpp +++ b/inference-engine/thirdparty/clDNN/src/layout_optimizer.cpp @@ -281,6 +281,12 @@ bool layout_optimizer::can_fuse_reorder(program_node& prev, program_node& next, (fmt_next == format::bs_fs_yx_bsv32_fsv16 && (prev_output_layout.size.feature[0] == 3 || prev_output_layout.size.feature[0] == 4)))) return true; + // Remove Reorder for Convolution: b_fs_yx_fsv32 (i8/u8) -> b_fs_yx_fsv16 (fp32/fp16) + if (next.is_type() && fmt_prev == format::b_fs_yx_fsv32 && fmt_next == format::b_fs_yx_fsv16 && + !data_type_traits::is_floating_point(prev_dt) && data_type_traits::is_floating_point(next_dt)) { + return true; + } + if (next.is_type()) return true; @@ -826,10 +832,14 @@ layout layout_optimizer::get_expected_layout(layout const& current_layout, /* ***************************** OneDNN impls format selection part ****************************** */ if (i8_u8_input) { if ((non_grouped || valid_grouped || valid_int8_dw) && onednn_valid_post_ops && is_2d) { - if (input_layout.size.batch[0] % 16 == 0) + if (input_layout.size.batch[0] % 16 == 0) { expected_format = cldnn::format::bs_fs_yx_bsv32_fsv32; - else - expected_format = cldnn::format::b_fs_yx_fsv32; + } else { + if (data_type_traits::is_floating_point(output_layout.data_type)) + expected_format = cldnn::format::b_fs_yx_fsv16; + else + expected_format = cldnn::format::b_fs_yx_fsv32; + } } else if ((_optimization_attributes.b_fs_yx_fsv16_network && convolution_b_fs_yx_fsv16_opt(input_layout, output_layout, weights_layout, prim)) && is_2d) { if (is_dw) From d198d57fe18d2b2479e6b4f63965a0c117731cba Mon Sep 17 00:00:00 2001 From: David Nam Date: Thu, 28 Oct 2021 15:45:12 +0900 Subject: [PATCH 10/12] Migrate pooling to template plugin test (#8136) * Migrate pooling to template plugin test * Fix clang format * Fix clang style error * Fix clang style error * Remove unused variable * Fix cpplint error * Fix CI build error * Remove max_pool.in.cpp --- .../op_reference/adaptive_avg_pool.cpp | 181 ++++++++++++ .../op_reference/adaptive_max_pool.cpp | 217 ++++++++++++++ .../functional/op_reference/avg_pool.cpp | 271 ++++++++++++++++++ ngraph/test/CMakeLists.txt | 5 +- ngraph/test/backend/adaptive_avg_pool.in.cpp | 111 ------- ngraph/test/backend/adaptive_max_pool.in.cpp | 140 --------- ngraph/test/backend/avg_pool.in.cpp | 251 ---------------- ngraph/test/backend/max_pool.in.cpp | 186 ------------ ngraph/test/visitors/op/avg_pool.cpp | 66 +++++ 9 files changed, 736 insertions(+), 692 deletions(-) create mode 100644 docs/template_plugin/tests/functional/op_reference/adaptive_avg_pool.cpp create mode 100644 docs/template_plugin/tests/functional/op_reference/adaptive_max_pool.cpp create mode 100644 docs/template_plugin/tests/functional/op_reference/avg_pool.cpp delete mode 100644 ngraph/test/backend/adaptive_avg_pool.in.cpp delete mode 100644 ngraph/test/backend/adaptive_max_pool.in.cpp delete mode 100644 ngraph/test/backend/avg_pool.in.cpp delete mode 100644 ngraph/test/backend/max_pool.in.cpp create mode 100644 ngraph/test/visitors/op/avg_pool.cpp diff --git a/docs/template_plugin/tests/functional/op_reference/adaptive_avg_pool.cpp b/docs/template_plugin/tests/functional/op_reference/adaptive_avg_pool.cpp new file mode 100644 index 00000000000..ccfd2474a1e --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/adaptive_avg_pool.cpp @@ -0,0 +1,181 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "base_reference_test.hpp" +#include "openvino/op/adaptive_avg_pool.hpp" +#include "openvino/op/constant.hpp" + +using namespace ov; +using namespace reference_tests; + +namespace { + +struct AdaptiveAvgPoolParams { + template + AdaptiveAvgPoolParams(const Shape& input_shape, + const Shape& output_shape, + const element::Type& input_type, + const element::Type& ouput_type, + const std::vector& input_values, + const std::vector& output_values, + const Shape& adaptive_shape, + const std::vector& adaptive_values) + : m_input_shape(input_shape), + m_output_shape(output_shape), + m_input_type(input_type), + m_output_type(ouput_type), + m_input_data(CreateTensor(input_type, input_values)), + m_expected_data(CreateTensor(ouput_type, output_values)), + m_adaptive_shape(adaptive_shape), + m_adaptive_values(adaptive_values) {} + Shape m_input_shape; + Shape m_output_shape; + element::Type m_input_type; + element::Type m_output_type; + runtime::Tensor m_input_data; + runtime::Tensor m_expected_data; + Shape m_adaptive_shape; + std::vector m_adaptive_values; +}; + +class ReferenceAdaptiveAvgPoolLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.m_input_shape, + params.m_input_type, + params.m_adaptive_shape, + params.m_adaptive_values); + inputData = {params.m_input_data}; + refOutData = {params.m_expected_data}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto params = obj.param; + std::ostringstream result; + result << "shape=" << params.m_input_shape << "_"; + result << "iType=" << params.m_input_type << "_"; + result << "shape=" << params.m_output_shape << "_"; + result << "oType=" << params.m_output_type; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const Shape& input_shape, + const element::Type& input_type, + const Shape& adaptive_shape, + const std::vector adaptive_values) { + const auto in = std::make_shared(input_type, input_shape); + const auto out = op::v0::Constant::create(element::Type_t::i64, adaptive_shape, adaptive_values); + const auto adaptive_avg_pool = std::make_shared(in, out); + return std::make_shared(NodeVector{adaptive_avg_pool}, ParameterVector{in}); + } +}; + +TEST_P(ReferenceAdaptiveAvgPoolLayerTest, AdaptiveAvgPoolWithHardcodedRefs) { + Exec(); +} + +template +std::vector generateParamsForAdaptiveAvgPool() { + using T = typename element_type_traits::value_type; + + std::vector params{ + AdaptiveAvgPoolParams(ov::Shape{2, 3, 7}, + ov::Shape{2, 3, 3}, + IN_ET, + IN_ET, + std::vector{0, 4, 1, 3, -2, -5, -2, -2, 1, -3, 1, -3, -4, 0, -2, 1, -1, -2, 3, -1, -3, + -1, -2, 3, 4, -3, -4, 1, 2, 0, -4, -5, -2, -2, -3, 2, 3, 1, -5, 2, -4, -2}, + std::vector{1.66666663, + 0.66666669, + -3., + -1.33333337, + -1.66666663, + -2.33333325, + -0.66666669, + 0., + -0.33333334, + + 0., + 1.33333337, + -2., + -0.66666669, + -3.66666675, + -2.33333325, + 2., + -0.66666669, + -1.33333337}, + ov::Shape{1}, + {3}), + AdaptiveAvgPoolParams( + ov::Shape{1, 3, 7, 10}, + ov::Shape{1, 3, 3, 3}, + IN_ET, + IN_ET, + std::vector{-2, -3, -4, 3, -5, 4, 0, -4, -2, -4, -5, 0, -3, 0, -2, 0, 0, -5, -4, -1, 3, -1, 0, -1, + 0, -2, 0, 4, 1, 4, 0, -1, -4, 2, -2, -5, -1, -1, -2, 1, 2, -2, -1, 2, 0, -1, 0, -5, + 4, 4, 3, 0, -4, -4, -4, -2, 0, 1, -2, -1, 4, -2, -4, 1, -1, -3, -4, -1, 1, -4, + + -2, -4, -5, 0, -4, 3, 4, -5, -4, -2, 0, 2, -4, -3, 3, -1, 1, -4, -5, 4, 2, -5, 2, -3, + 0, 4, 3, 3, 1, 2, -1, -4, 1, -3, -3, -2, 3, 4, -2, -5, 1, 4, 4, -2, 2, 1, -5, -2, + -5, 1, 1, -2, -3, -3, -1, -5, 1, -3, -5, -3, -4, -1, 4, -3, 4, -1, 4, 3, 1, 4, + + -2, -4, -4, 4, -3, 4, 2, -3, -2, 4, -3, 0, 1, -4, 4, 4, 0, 3, -1, 3, 3, -5, 0, 3, + -3, 1, -2, 4, -5, -5, 1, 0, -1, 0, -3, -2, 0, -3, 3, -2, -2, 0, -3, 4, -1, 2, -2, 2, + -3, -1, -4, -2, 0, 2, 0, 2, 0, -3, 4, 3, -5, -3, -5, 1, -5, -3, -5, 4, -3, 3}, + std::vector{-1.08333337, -0.25000000, -0.91666669, -0.08333334, -0.66666669, + 0.75000000, -0.41666666, -1.33333337, -0.58333331, + + -1.66666663, 0.58333331, -0.16666667, -0.33333334, -0.41666666, + -0.16666667, -0.33333334, -0.66666669, -0.75000000, + + -0.91666669, 0.83333331, -0.16666667, 0., -0.25000000, + -1.16666663, -1.41666663, -0.41666666, -0.08333334}, + ov::Shape{2}, + {3, 3}), + AdaptiveAvgPoolParams( + ov::Shape{2, 2, 3, 3, 3}, + ov::Shape{2, 2, 2, 2, 2}, + IN_ET, + IN_ET, + std::vector{-5, 1, -3, -4, 4, -4, 3, -3, -1, 0, 0, -2, -4, 2, 0, -4, -5, -2, -4, -4, 0, -2, 3, -3, 4, -1, -4, + -1, -1, -5, 4, -1, -2, -3, 0, 4, -1, -5, -4, 1, 1, 4, -5, -5, -5, 4, -3, -3, -3, 4, 0, -3, -5, 1, + 4, 2, 1, -5, -5, 1, 0, -4, -1, 2, -4, -2, 4, 3, 1, -3, -3, -2, -4, -3, -3, 3, -1, 1, 2, 2, -4, + -5, -4, 1, 3, -4, -1, 2, 4, -5, 0, 1, -2, 0, 0, -2, 3, -2, -5, -3, -5, -2, -1, 3, -2, 4, 3, -3}, + std::vector{-0.750, -0.250, -1.375, -1.125, -1.125, -0.500, -0.875, -1.250, + -0.375, -1.625, -1., -0.500, -0.250, -0.750, -1.875, -0.625, + 0.125, -0.375, -1.625, -1.250, 0., -1., 0.875, -0.375, + -1.125, -1.375, 0.750, -1.875, -0.625, -1.125, 1.250, -1.}, + ov::Shape{3}, + {2, 2, 2}), + }; + return params; +} + +std::vector generateCombinedParamsForAdaptiveAvgPool() { + const std::vector> allTypeParams{ + generateParamsForAdaptiveAvgPool(), + generateParamsForAdaptiveAvgPool(), + generateParamsForAdaptiveAvgPool() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P( + smoke_AdaptiveAvgPool_With_Hardcoded_Refs, + ReferenceAdaptiveAvgPoolLayerTest, + ::testing::ValuesIn(generateCombinedParamsForAdaptiveAvgPool()), + ReferenceAdaptiveAvgPoolLayerTest::getTestCaseName); + +} // namespace \ No newline at end of file diff --git a/docs/template_plugin/tests/functional/op_reference/adaptive_max_pool.cpp b/docs/template_plugin/tests/functional/op_reference/adaptive_max_pool.cpp new file mode 100644 index 00000000000..975aa4ccb2a --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/adaptive_max_pool.cpp @@ -0,0 +1,217 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "base_reference_test.hpp" +#include "openvino/op/adaptive_max_pool.hpp" +#include "openvino/op/constant.hpp" + +using namespace ov; +using namespace reference_tests; + +namespace { + +struct AdaptiveMaxPoolParams { + template + AdaptiveMaxPoolParams(const Shape& input_shape, + const Shape& output_shape, + const element::Type& input_type, + const element::Type& output_type, + const std::vector& input_values, + const std::vector& output_values, + const std::vector& output_indices, + const Shape& adaptive_shape, + const std::vector& adaptive_values) + : m_input_shape(input_shape), + m_output_shape(output_shape), + m_input_type(input_type), + m_output_type(output_type), + m_input_data(CreateTensor(input_type, input_values)), + m_expected_data(CreateTensor(output_type, output_values)), + m_expected_indices(CreateTensor(element::Type_t::i64, output_indices)), + m_adaptive_shape(adaptive_shape), + m_adaptive_values(adaptive_values) {} + Shape m_input_shape; + Shape m_output_shape; + element::Type m_input_type; + element::Type m_output_type; + runtime::Tensor m_input_data; + runtime::Tensor m_expected_data; + runtime::Tensor m_expected_indices; + Shape m_adaptive_shape; + std::vector m_adaptive_values; +}; + +class ReferenceAdaptiveMaxPoolLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.m_input_shape, + params.m_input_type, + params.m_adaptive_shape, + params.m_adaptive_values); + inputData = {params.m_input_data}; + refOutData = {params.m_expected_data, params.m_expected_indices}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto params = obj.param; + std::ostringstream result; + result << "shape=" << params.m_input_shape << "_"; + result << "iType=" << params.m_input_type << "_"; + result << "shape=" << params.m_output_shape << "_"; + result << "oType=" << params.m_output_type; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const Shape& input_shape, + const element::Type& input_type, + const Shape& adaptive_shape, + const std::vector adaptive_values) { + const auto in = std::make_shared(input_type, input_shape); + const auto out = op::v0::Constant::create(element::Type_t::i64, adaptive_shape, adaptive_values); + const auto adaptive_max_pool = std::make_shared(in, out); + return std::make_shared(adaptive_max_pool->outputs(), ParameterVector{in}); + } +}; + +TEST_P(ReferenceAdaptiveMaxPoolLayerTest, AdaptiveMaxPoolWithHardcodedRefs) { + Exec(); +} + +template +std::vector generateParamsForAdaptiveMaxPoolWithExpectedResult() { + using T = typename element_type_traits::value_type; + + std::vector params{ + AdaptiveMaxPoolParams( + ov::Shape{2, 3, 7}, + ov::Shape{2, 3, 3}, + IN_ET, + IN_ET, + std::vector{0, 4, 1, 3, -2, -5, -2, -2, 1, -3, 1, -3, -4, 0, -2, 1, -1, -2, 3, -1, -3, + -1, -2, 3, 4, -3, -4, 1, 2, 0, -4, -5, -2, -2, -3, 2, 3, 1, -5, 2, -4, -2}, + std::vector{4, + 3, + -2, + 1, + 1, + 0, + 1, + 3, + 3, + + 3, + 4, + 1, + 2, + -2, + -2, + 3, + 2, + 2}, + std::vector{1, + 3, + 4, + 1, + 3, + 6, + 1, + 4, + 4, + + 2, + 3, + 6, + 0, + 4, + 4, + 1, + 4, + 4}, + ov::Shape{1}, + std::vector{3}), + AdaptiveMaxPoolParams( + ov::Shape{1, 3, 7, 10}, + ov::Shape{1, 3, 3, 3}, + IN_ET, + IN_ET, + std::vector{0, -2, -5, -5, 2, 3, 2, -3, 1, -2, -4, -1, -1, -1, 2, -4, 3, -5, -1, -1, 1, 2, 4, -2, + -3, -2, 0, -5, 2, -4, -1, -4, 4, 2, 1, -2, 2, -3, 0, 1, -3, 3, -1, 4, 0, 2, 0, 3, + 4, -4, 1, 4, -1, -5, -2, 4, -3, 3, 2, 1, 0, 4, 2, -5, 2, -5, -2, -1, 4, 2, + + 0, 4, -2, 0, -5, -3, 4, -4, -2, -2, 2, 1, 4, 3, 2, -5, -4, -4, 0, 1, 4, -4, -3, 3, + 3, 4, -2, -3, -4, -2, 0, 1, -1, 3, -2, 2, 0, -3, -1, -1, 0, 0, 2, 2, -2, 1, -3, 1, + 2, 4, 3, -5, -4, 1, -4, 2, 0, -2, -5, 2, -3, -2, -3, -4, 2, -2, -4, 2, -4, -3, + + 1, -5, -1, -5, 2, 1, 3, 4, 3, 0, -5, 4, -3, -4, -1, 2, -4, 2, 0, -5, -3, 0, 2, -3, + -5, 3, -2, -1, -5, -4, -5, 0, -5, -1, -3, 3, 3, -4, -3, -4, -5, 4, -1, 1, -1, -4, 1, -3, + -4, -1, -2, -3, -5, 2, 2, -5, 1, 1, -5, -4, 0, 2, 4, 2, 0, 2, 4, 0, -5, 2}, + std::vector{4, 3, 3, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 3, 2, 4, + 4, 3, 4, 4, 3, 3, 4, 4, 4}, + std::vector{22, 5, 16, 22, 43, 48, 43, 43, 48, + 1, 6, 6, 20, 25, 49, 50, 43, 49, + 11, 6, 7, 41, 25, 36, 41, 66, 66}, + ov::Shape{2}, + std::vector{3, 3}), + AdaptiveMaxPoolParams( + ov::Shape{2, 2, 3, 3, 3}, + ov::Shape{2, 2, 2, 2, 2}, + IN_ET, + IN_ET, + std::vector{-5, 1, -3, -4, 4, -4, 3, -3, -1, 0, 0, -2, -4, 2, + 0, -4, -5, -2, -4, -4, 0, -2, 3, -3, 4, -1, -4, + + -1, -1, -5, 4, -1, -2, -3, 0, 4, -1, -5, -4, 1, 1, + 4, -5, -5, -5, 4, -3, -3, -3, 4, 0, -3, -5, 1, + + 4, 2, 1, -5, -5, 1, 0, -4, -1, 2, -4, -2, 4, 3, + 1, -3, -3, -2, -4, -3, -3, 3, -1, 1, 2, 2, -4, + + -5, -4, 1, 3, -4, -1, 2, 4, -5, 0, 1, -2, 0, 0, + -2, 3, -2, -5, -3, -5, -2, -1, 3, -2, 4, 3, -3}, + std::vector{4, 4, 4, 4, 3, 3, 4, 3, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 3, 4, 3, 4, 3, 4, 3, + 3, 1, 4, 4, 3, 3, 4, 3}, + std::vector{4, 4, 4, 4, 22, 22, 24, 22, + 3, 14, 3, 8, 18, 14, 22, 14, + 0, 13, 12, 13, 12, 13, 12, 13, + 3, 2, 7, 7, 22, 22, 24, 22}, + ov::Shape{3}, + std::vector{2, 2, 2}) + }; + return params; +} + +std::vector generateCombinedParamsForAdaptiveMaxPool() { + const std::vector> allTypeParams{ + generateParamsForAdaptiveMaxPoolWithExpectedResult(), + generateParamsForAdaptiveMaxPoolWithExpectedResult(), + generateParamsForAdaptiveMaxPoolWithExpectedResult(), + generateParamsForAdaptiveMaxPoolWithExpectedResult(), + generateParamsForAdaptiveMaxPoolWithExpectedResult(), + generateParamsForAdaptiveMaxPoolWithExpectedResult(), + generateParamsForAdaptiveMaxPoolWithExpectedResult(), + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P( + smoke_AdaptiveMaxPool_With_Hardcoded_Refs, + ReferenceAdaptiveMaxPoolLayerTest, + ::testing::ValuesIn(generateCombinedParamsForAdaptiveMaxPool()), + ReferenceAdaptiveMaxPoolLayerTest::getTestCaseName); + +} // namespace \ No newline at end of file diff --git a/docs/template_plugin/tests/functional/op_reference/avg_pool.cpp b/docs/template_plugin/tests/functional/op_reference/avg_pool.cpp new file mode 100644 index 00000000000..9cbf2932080 --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/avg_pool.cpp @@ -0,0 +1,271 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "base_reference_test.hpp" +#include "openvino/op/avg_pool.hpp" + +using namespace ov; +using namespace reference_tests; + +namespace { + +struct AvgPoolParams { + template + AvgPoolParams(const Shape& input_shape, + const Shape& output_shape, + const element::Type& input_type, + const element::Type& ouput_type, + const std::vector& input_values, + const std::vector& output_values, + const Strides& strides, + const Shape& pads_begin, + const Shape& pads_end, + const Shape& kernel, + const bool exclude_pad, + const op::RoundingType& rounding_type, + const op::PadType& pad_type) + : m_input_shape(input_shape), + m_output_shape(output_shape), + m_input_type(input_type), + m_output_type(ouput_type), + m_input_data(CreateTensor(input_type, input_values)), + m_expected_data(CreateTensor(ouput_type, output_values)), + m_strides(strides), + m_pads_begin(pads_begin), + m_pads_end(pads_end), + m_kernel(kernel), + m_exclude_pad(exclude_pad), + m_rounding_type(rounding_type), + m_pad_type(pad_type) {} + + Shape m_input_shape; + Shape m_output_shape; + element::Type m_input_type; + element::Type m_output_type; + runtime::Tensor m_input_data; + runtime::Tensor m_expected_data; + Strides m_strides; + Shape m_pads_begin; + Shape m_pads_end; + Shape m_kernel; + bool m_exclude_pad; + op::RoundingType m_rounding_type; + op::PadType m_pad_type; +}; + +class ReferenceAvgPoolLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.m_input_shape, + params.m_input_type, + params.m_strides, + params.m_pads_begin, + params.m_pads_end, + params.m_kernel, + params.m_exclude_pad, + params.m_rounding_type, + params.m_pad_type); + inputData = {params.m_input_data}; + refOutData = {params.m_expected_data}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto params = obj.param; + std::ostringstream result; + result << "iShape=" << params.m_input_shape << "_"; + result << "iType=" << params.m_input_type << "_"; + result << "iShape=" << params.m_output_shape << "_"; + result << "oType=" << params.m_output_type << "_"; + result << "excludePad=" << params.m_exclude_pad << "_"; + result << "roundingType=" << params.m_rounding_type << "_"; + result << "padType=" << params.m_pad_type; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const Shape& input_shape, + const element::Type& input_type, + const Strides& strides, + const Shape& pads_begin, + const Shape& pads_end, + const Shape& kernel, + const bool exclude_pad, + const op::RoundingType rounding_type, + const op::PadType pad_type) { + const auto in = std::make_shared(input_type, input_shape); + const auto avgPool = std::make_shared(in, + strides, + pads_begin, + pads_end, + kernel, + exclude_pad, + rounding_type, + pad_type); + return std::make_shared(NodeVector{avgPool}, ParameterVector{in}); + } +}; + +TEST_P(ReferenceAvgPoolLayerTest, AvgPoolWithHardcodedRefs) { + Exec(); +} + +template +std::vector getContinuousIncreasingValue(size_t elementSize, float step) { + std::vector a(elementSize); + std::iota(std::begin(a), std::end(a), step); + return a; +} + +template +std::vector generateParamsForAvgPool() { + using T = typename element_type_traits::value_type; + + std::vector params{ + AvgPoolParams(ov::Shape{1, 1, 3, 3}, + ov::Shape{1, 1, 2, 2}, + IN_ET, + IN_ET, + std::vector{1, 2, 3, 4, 5, 6, 7, 8, 9}, + std::vector{3, 4, 6, 7}, + Strides{1, 1}, + Shape{0, 0}, + Shape{0, 0}, + Shape{2, 2}, + true, + op::RoundingType::FLOOR, + op::PadType::NOTSET), + AvgPoolParams(ov::Shape{1, 1, 4, 4}, + ov::Shape{1, 1, 2, 2}, + IN_ET, + IN_ET, + std::vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, + std::vector{6, 7, 10, 11}, + Strides{1, 1}, + Shape{0, 0}, + Shape{0, 0}, + Shape{3, 3}, + true, + op::RoundingType::CEIL, + op::PadType::NOTSET), + AvgPoolParams(ov::Shape{1, 1, 2, 2}, + ov::Shape{1, 1, 3, 3}, + IN_ET, + IN_ET, + std::vector{1, 2, 3, 4}, + std::vector{1, 1.5, 2, 2, 2.5, 3, 3, 3.5, 4}, + Strides{1, 1}, + Shape{1, 1}, + Shape{1, 1}, + Shape{2, 2}, + true, + op::RoundingType::CEIL, + op::PadType::NOTSET), + AvgPoolParams(ov::Shape{1, 1, 1, 5}, + ov::Shape{1, 1, 1, 3}, + IN_ET, + IN_ET, + std::vector{1, 2, 3, 4, 5}, + std::vector{1.5, 3, 4.5}, + Strides{1, 2}, + Shape{1, 1}, + Shape{1, 1}, + Shape{3, 3}, + true, + op::RoundingType::CEIL, + op::PadType::EXPLICIT), + AvgPoolParams(ov::Shape{1, 1, 1, 5}, + ov::Shape{1, 1, 1, 3}, + IN_ET, + IN_ET, + std::vector{2.5, 2, 12, 4, 5}, + std::vector{0.5, 2, 1}, + Strides{1, 2}, + Shape{1, 1}, + Shape{1, 1}, + Shape{3, 3}, + false, + op::RoundingType::CEIL, + op::PadType::EXPLICIT), + AvgPoolParams(ov::Shape{1, 1, 3, 3}, + ov::Shape{1, 1, 3, 3}, + IN_ET, + IN_ET, + std::vector{1, 2, 3, 4, 5, 6, 7, 8, 9}, + std::vector{3, 4, 2.25, 6, 7, 3.75, 3.75, 4.25, 2.25}, + Strides{1, 1}, + Shape{0, 0}, + Shape{0, 0}, + Shape{2, 2}, + false, + op::RoundingType::CEIL, + op::PadType::SAME_UPPER), + AvgPoolParams(ov::Shape{1, 1, 3, 3}, + ov::Shape{1, 1, 3, 3}, + IN_ET, + IN_ET, + std::vector{1, 2, 3, 4, 5, 6, 7, 8, 9}, + std::vector{0.25, 0.75, 1.25, 1.25, 3, 4, 2.75, 6, 7}, + Strides{1, 1}, + Shape{0, 0}, + Shape{0, 0}, + Shape{2, 2}, + false, + op::RoundingType::CEIL, + op::PadType::SAME_LOWER), + AvgPoolParams(ov::Shape{1, 1, 2, 2, 2}, + ov::Shape{1, 1, 2, 2, 1}, + IN_ET, + IN_ET, + std::vector{1, 2, 3, 4, 5, 6, 7, 8}, + std::vector{1.5, 3.5, 5.5, 7.5}, + Strides{1, 1, 1}, + Shape{0, 0, 0}, + Shape{0, 0, 0}, + Shape{1, 1, 2}, + true, + op::RoundingType::CEIL, + op::PadType::VALID), + AvgPoolParams(ov::Shape{1, 1, 3, 3}, + ov::Shape{1, 1, 3, 3}, + IN_ET, + IN_ET, + getContinuousIncreasingValue(1 * 1 * 3 * 3, 1), + std::vector{1.0f, 2.5f, 0, 5.5f, 7.0f, 0, 0, 0, 0}, + Strides{2, 2}, + Shape{1, 1}, + Shape{1, 1}, + Shape{2, 2}, + true, + op::RoundingType::CEIL, + op::PadType::NOTSET), + }; + return params; +} + +std::vector generateCombinedParamsForAvgPool() { + const std::vector> allTypeParams{ + generateParamsForAvgPool(), + generateParamsForAvgPool(), + generateParamsForAvgPool() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P( + smoke_AvgPool_With_Hardcoded_Refs, + ReferenceAvgPoolLayerTest, + ::testing::ValuesIn(generateCombinedParamsForAvgPool()), + ReferenceAvgPoolLayerTest::getTestCaseName); + +} // namespace \ No newline at end of file diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index a0e4f959622..9e91740e061 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -266,6 +266,7 @@ set(SRC visitors/op/asinh.cpp visitors/op/atan.cpp visitors/op/atanh.cpp + visitors/op/avg_pool.cpp visitors/op/batch_norm.cpp visitors/op/batch_to_space.cpp visitors/op/binary_convolution.cpp @@ -453,12 +454,9 @@ endif() set(MULTI_TEST_SRC backend/abc.in.cpp - backend/adaptive_avg_pool.in.cpp - backend/adaptive_max_pool.in.cpp backend/aliased_output.in.cpp backend/api.in.cpp backend/auto_broadcast.in.cpp - backend/avg_pool.in.cpp backend/batch_norm.in.cpp backend/batch_to_space.in.cpp backend/broadcast.in.cpp @@ -487,7 +485,6 @@ set(MULTI_TEST_SRC backend/lrn.in.cpp backend/matmul.in.cpp backend/matrix_nms.in.cpp - backend/max_pool.in.cpp backend/multiclass_nms.in.cpp backend/multiple_backends.in.cpp backend/multiple_result.in.cpp diff --git a/ngraph/test/backend/adaptive_avg_pool.in.cpp b/ngraph/test/backend/adaptive_avg_pool.in.cpp deleted file mode 100644 index ae6377e76b6..00000000000 --- a/ngraph/test/backend/adaptive_avg_pool.in.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "engines_util/test_case.hpp" -#include "engines_util/test_engines.hpp" -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "util/test_control.hpp" - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; -using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); - -NGRAPH_TEST(${BACKEND_NAME}, adaptive_avg_pool_1d) { - auto data = make_shared(element::f32, Shape{2, 3, 7}); - auto output_shape = op::Constant::create(element::i64, Shape{1}, {3}); - auto adaptive_pool = make_shared(data, output_shape); - auto fun = make_shared(OutputVector{adaptive_pool}, ParameterVector{data}); - - std::vector inputs{0, 4, 1, 3, -2, -5, -2, -2, 1, -3, 1, -3, -4, 0, -2, 1, -1, -2, 3, -1, -3, - - -1, -2, 3, 4, -3, -4, 1, 2, 0, -4, -5, -2, -2, -3, 2, 3, 1, -5, 2, -4, -2}; - std::vector expected_result{1.66666663, - 0.66666669, - -3., - -1.33333337, - -1.66666663, - -2.33333325, - -0.66666669, - 0., - -0.33333334, - - 0., - 1.33333337, - -2., - -0.66666669, - -3.66666675, - -2.33333325, - 2., - -0.66666669, - -1.33333337}; - - auto test_case = test::TestCase(fun); - test_case.add_input(Shape{2, 3, 7}, inputs); - test_case.add_expected_output(Shape{2, 3, 3}, expected_result); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, adaptive_avg_pool_2d) { - auto data = make_shared(element::f32, Shape{1, 3, 7, 10}); - auto output_shape = op::Constant::create(element::i64, Shape{2}, {3, 3}); - auto adaptive_pool = make_shared(data, output_shape); - auto fun = make_shared(OutputVector{adaptive_pool}, ParameterVector{data}); - - std::vector inputs{ - -2, -3, -4, 3, -5, 4, 0, -4, -2, -4, -5, 0, -3, 0, -2, 0, 0, -5, -4, -1, 3, -1, 0, -1, - 0, -2, 0, 4, 1, 4, 0, -1, -4, 2, -2, -5, -1, -1, -2, 1, 2, -2, -1, 2, 0, -1, 0, -5, - 4, 4, 3, 0, -4, -4, -4, -2, 0, 1, -2, -1, 4, -2, -4, 1, -1, -3, -4, -1, 1, -4, - - -2, -4, -5, 0, -4, 3, 4, -5, -4, -2, 0, 2, -4, -3, 3, -1, 1, -4, -5, 4, 2, -5, 2, -3, - 0, 4, 3, 3, 1, 2, -1, -4, 1, -3, -3, -2, 3, 4, -2, -5, 1, 4, 4, -2, 2, 1, -5, -2, - -5, 1, 1, -2, -3, -3, -1, -5, 1, -3, -5, -3, -4, -1, 4, -3, 4, -1, 4, 3, 1, 4, - - -2, -4, -4, 4, -3, 4, 2, -3, -2, 4, -3, 0, 1, -4, 4, 4, 0, 3, -1, 3, 3, -5, 0, 3, - -3, 1, -2, 4, -5, -5, 1, 0, -1, 0, -3, -2, 0, -3, 3, -2, -2, 0, -3, 4, -1, 2, -2, 2, - -3, -1, -4, -2, 0, 2, 0, 2, 0, -3, 4, 3, -5, -3, -5, 1, -5, -3, -5, 4, -3, 3}; - std::vector expected_result{-1.08333337, -0.25000000, -0.91666669, -0.08333334, -0.66666669, - 0.75000000, -0.41666666, -1.33333337, -0.58333331, - - -1.66666663, 0.58333331, -0.16666667, -0.33333334, -0.41666666, - -0.16666667, -0.33333334, -0.66666669, -0.75000000, - - -0.91666669, 0.83333331, -0.16666667, 0., -0.25000000, - -1.16666663, -1.41666663, -0.41666666, -0.08333334}; - - auto test_case = test::TestCase(fun); - test_case.add_input(Shape{1, 3, 7, 10}, inputs); - test_case.add_expected_output(Shape{1, 3, 3, 3}, expected_result); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, adaptive_avg_pool_3d) { - auto data = make_shared(element::f32, Shape{2, 2, 3, 3, 3}); - auto output_shape = op::Constant::create(element::i64, Shape{3}, {2, 2, 2}); - auto adaptive_pool = make_shared(data, output_shape); - auto fun = make_shared(OutputVector{adaptive_pool}, ParameterVector{data}); - - std::vector inputs{ - -5, 1, -3, -4, 4, -4, 3, -3, -1, 0, 0, -2, -4, 2, 0, -4, -5, -2, -4, -4, 0, -2, 3, -3, 4, -1, -4, - - -1, -1, -5, 4, -1, -2, -3, 0, 4, -1, -5, -4, 1, 1, 4, -5, -5, -5, 4, -3, -3, -3, 4, 0, -3, -5, 1, - - 4, 2, 1, -5, -5, 1, 0, -4, -1, 2, -4, -2, 4, 3, 1, -3, -3, -2, -4, -3, -3, 3, -1, 1, 2, 2, -4, - - -5, -4, 1, 3, -4, -1, 2, 4, -5, 0, 1, -2, 0, 0, -2, 3, -2, -5, -3, -5, -2, -1, 3, -2, 4, 3, -3}; - std::vector expected_result{-0.750, -0.250, -1.375, -1.125, -1.125, -0.500, -0.875, -1.250, - - -0.375, -1.625, -1., -0.500, -0.250, -0.750, -1.875, -0.625, - - 0.125, -0.375, -1.625, -1.250, 0., -1., 0.875, -0.375, - - -1.125, -1.375, 0.750, -1.875, -0.625, -1.125, 1.250, -1.}; - - auto test_case = test::TestCase(fun); - test_case.add_input(Shape{2, 2, 3, 3, 3}, inputs); - test_case.add_expected_output(Shape{2, 2, 2, 2, 2}, expected_result); - test_case.run(); -} diff --git a/ngraph/test/backend/adaptive_max_pool.in.cpp b/ngraph/test/backend/adaptive_max_pool.in.cpp deleted file mode 100644 index 3ce25626b1c..00000000000 --- a/ngraph/test/backend/adaptive_max_pool.in.cpp +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include "engines_util/test_case.hpp" -#include "engines_util/test_engines.hpp" -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "util/test_control.hpp" - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; -using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); - -NGRAPH_TEST(${BACKEND_NAME}, adaptive_max_pool_1d) { - auto data = make_shared(element::f32, Shape{2, 3, 7}); - auto output_shape = op::Constant::create(element::i64, Shape{1}, {3}); - auto adaptive_pool = make_shared(data, output_shape); - auto fun = make_shared(adaptive_pool->outputs(), ParameterVector{data}); - - std::vector inputs{0, 4, 1, 3, -2, -5, -2, -2, 1, -3, 1, -3, -4, 0, -2, 1, -1, -2, 3, -1, -3, - - -1, -2, 3, 4, -3, -4, 1, 2, 0, -4, -5, -2, -2, -3, 2, 3, 1, -5, 2, -4, -2}; - std::vector expected_result{4, - 3, - -2, - 1, - 1, - 0, - 1, - 3, - 3, - - 3, - 4, - 1, - 2, - -2, - -2, - 3, - 2, - 2}; - std::vector expected_indices{1, - 3, - 4, - 1, - 3, - 6, - 1, - 4, - 4, - - 2, - 3, - 6, - 0, - 4, - 4, - 1, - 4, - 4}; - auto test_case = test::TestCase(fun); - test_case.add_input(Shape{2, 3, 7}, inputs); - test_case.add_expected_output(Shape{2, 3, 3}, expected_result); - test_case.add_expected_output(Shape{2, 3, 3}, expected_indices); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, adaptive_max_pool_2d) { - auto data = make_shared(element::f32, Shape{1, 3, 7, 10}); - auto output_shape = op::Constant::create(element::i64, Shape{2}, {3, 3}); - auto adaptive_pool = make_shared(data, output_shape); - auto fun = make_shared(adaptive_pool->outputs(), ParameterVector{data}); - - std::vector inputs{ - 0, -2, -5, -5, 2, 3, 2, -3, 1, -2, -4, -1, -1, -1, 2, -4, 3, -5, -1, -1, 1, 2, 4, -2, - -3, -2, 0, -5, 2, -4, -1, -4, 4, 2, 1, -2, 2, -3, 0, 1, -3, 3, -1, 4, 0, 2, 0, 3, - 4, -4, 1, 4, -1, -5, -2, 4, -3, 3, 2, 1, 0, 4, 2, -5, 2, -5, -2, -1, 4, 2, - - 0, 4, -2, 0, -5, -3, 4, -4, -2, -2, 2, 1, 4, 3, 2, -5, -4, -4, 0, 1, 4, -4, -3, 3, - 3, 4, -2, -3, -4, -2, 0, 1, -1, 3, -2, 2, 0, -3, -1, -1, 0, 0, 2, 2, -2, 1, -3, 1, - 2, 4, 3, -5, -4, 1, -4, 2, 0, -2, -5, 2, -3, -2, -3, -4, 2, -2, -4, 2, -4, -3, - - 1, -5, -1, -5, 2, 1, 3, 4, 3, 0, -5, 4, -3, -4, -1, 2, -4, 2, 0, -5, -3, 0, 2, -3, - -5, 3, -2, -1, -5, -4, -5, 0, -5, -1, -3, 3, 3, -4, -3, -4, -5, 4, -1, 1, -1, -4, 1, -3, - -4, -1, -2, -3, -5, 2, 2, -5, 1, 1, -5, -4, 0, 2, 4, 2, 0, 2, 4, 0, -5, 2}; - std::vector expected_result{4, 3, 3, 4, 4, 4, 4, 4, 4, - - 4, 4, 4, 4, 4, 4, 3, 2, 4, - - 4, 3, 4, 4, 3, 3, 4, 4, 4}; - std::vector expected_indices{22, 5, 16, 22, 43, 48, 43, 43, 48, - - 1, 6, 6, 20, 25, 49, 50, 43, 49, - - 11, 6, 7, 41, 25, 36, 41, 66, 66}; - - auto test_case = test::TestCase(fun); - test_case.add_input(Shape{1, 3, 7, 10}, inputs); - test_case.add_expected_output(Shape{1, 3, 3, 3}, expected_result); - test_case.add_expected_output(Shape{1, 3, 3, 3}, expected_indices); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, adaptive_max_pool_3d) { - auto data = make_shared(element::f32, Shape{2, 2, 3, 3, 3}); - auto output_shape = op::Constant::create(element::i64, Shape{3}, {2, 2, 2}); - auto adaptive_pool = make_shared(data, output_shape); - auto fun = make_shared(adaptive_pool->outputs(), ParameterVector{data}); - - std::vector inputs{ - -5, 1, -3, -4, 4, -4, 3, -3, -1, 0, 0, -2, -4, 2, 0, -4, -5, -2, -4, -4, 0, -2, 3, -3, 4, -1, -4, - - -1, -1, -5, 4, -1, -2, -3, 0, 4, -1, -5, -4, 1, 1, 4, -5, -5, -5, 4, -3, -3, -3, 4, 0, -3, -5, 1, - - 4, 2, 1, -5, -5, 1, 0, -4, -1, 2, -4, -2, 4, 3, 1, -3, -3, -2, -4, -3, -3, 3, -1, 1, 2, 2, -4, - - -5, -4, 1, 3, -4, -1, 2, 4, -5, 0, 1, -2, 0, 0, -2, 3, -2, -5, -3, -5, -2, -1, 3, -2, 4, 3, -3}; - std::vector expected_result{4, 4, 4, 4, 3, 3, 4, 3, - - 4, 4, 4, 4, 4, 4, 4, 4, - - 4, 3, 4, 3, 4, 3, 4, 3, - - 3, 1, 4, 4, 3, 3, 4, 3}; - std::vector expected_indices{4, 4, 4, 4, 22, 22, 24, 22, - - 3, 14, 3, 8, 18, 14, 22, 14, - - 0, 13, 12, 13, 12, 13, 12, 13, - - 3, 2, 7, 7, 22, 22, 24, 22}; - - auto test_case = test::TestCase(fun); - test_case.add_input(Shape{2, 2, 3, 3, 3}, inputs); - test_case.add_expected_output(Shape{2, 2, 2, 2, 2}, expected_result); - test_case.add_expected_output(Shape{2, 2, 2, 2, 2}, expected_indices); - test_case.run(); -} diff --git a/ngraph/test/backend/avg_pool.in.cpp b/ngraph/test/backend/avg_pool.in.cpp deleted file mode 100644 index 075da10cd20..00000000000 --- a/ngraph/test/backend/avg_pool.in.cpp +++ /dev/null @@ -1,251 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -// clang-format off -#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#endif - -#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#endif -// clang-format on - -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "engines_util/test_engines.hpp" -#include "engines_util/test_case.hpp" -#include "util/test_control.hpp" - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; -using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); - -NGRAPH_TEST(${BACKEND_NAME}, avg_pool_2d_floor) { - Shape in_shape{1, 1, 3, 3}; - Shape out_shape{1, 1, 2, 2}; - const Strides& strides{1, 1}; - const Shape& pads_begin{0, 0}; - const Shape& pads_end{0, 0}; - const Shape& kernel{2, 2}; - const bool exclude_pad = true; - const op::RoundingType rounding_type = op::RoundingType::FLOOR; - const op::PadType pad_type = op::PadType::NOTSET; - - auto A = make_shared(element::f32, in_shape); - auto avgPool = - make_shared(A, strides, pads_begin, pads_end, kernel, exclude_pad, rounding_type, pad_type); - auto f = make_shared(avgPool, ParameterVector{A}); - - std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9}; - std::vector result{3, 4, 6, 7}; - - auto test_case = test::TestCase(f); - test_case.add_input({a}); - test_case.add_expected_output(out_shape, result); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, avg_pool_2d_ceil) { - Shape in_shape{1, 1, 4, 4}; - Shape out_shape{1, 1, 2, 2}; - const Strides& strides{1, 1}; - const Shape& pads_begin{0, 0}; - const Shape& pads_end{0, 0}; - const Shape& kernel{3, 3}; - const bool exclude_pad = true; - const op::RoundingType rounding_type = op::RoundingType::CEIL; - const op::PadType pad_type = op::PadType::NOTSET; - - auto A = make_shared(element::f32, in_shape); - auto avgPool = - make_shared(A, strides, pads_begin, pads_end, kernel, exclude_pad, rounding_type, pad_type); - auto f = make_shared(avgPool, ParameterVector{A}); - - std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - std::vector result{6, 7, 10, 11}; - - auto test_case = test::TestCase(f); - test_case.add_input({a}); - test_case.add_expected_output(out_shape, result); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, avg_pool_2d_pad) { - Shape in_shape{1, 1, 2, 2}; - Shape out_shape{1, 1, 3, 3}; - const Strides& strides{1, 1}; - const Shape& pads_begin{1, 1}; - const Shape& pads_end{1, 1}; - const Shape& kernel{2, 2}; - const bool exclude_pad = true; - const op::RoundingType rounding_type = op::RoundingType::CEIL; - const op::PadType pad_type = op::PadType::NOTSET; - - auto A = make_shared(element::f32, in_shape); - auto avgPool = - make_shared(A, strides, pads_begin, pads_end, kernel, exclude_pad, rounding_type, pad_type); - auto f = make_shared(avgPool, ParameterVector{A}); - - std::vector a{1, 2, 3, 4}; - std::vector result{1, 1.5, 2, 2, 2.5, 3, 3, 3.5, 4}; - - auto test_case = test::TestCase(f); - test_case.add_input({a}); - test_case.add_expected_output(out_shape, result); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, avg_pool_2d_ceil_stride_pad) { - Shape in_shape{1, 1, 1, 5}; - Shape out_shape{1, 1, 1, 3}; - const Strides& strides{1, 2}; - const Shape& pads_begin{1, 1}; - const Shape& pads_end{1, 1}; - const Shape& kernel{3, 3}; - const bool exclude_pad = true; - const op::RoundingType rounding_type = op::RoundingType::CEIL; - const op::PadType pad_type = op::PadType::EXPLICIT; - - auto A = make_shared(element::f32, in_shape); - auto avgPool = - make_shared(A, strides, pads_begin, pads_end, kernel, exclude_pad, rounding_type, pad_type); - auto f = make_shared(avgPool, ParameterVector{A}); - - std::vector a{1, 2, 3, 4, 5}; - std::vector result{1.5, 3, 4.5}; - - auto test_case = test::TestCase(f); - test_case.add_input({a}); - test_case.add_expected_output(out_shape, result); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, avg_pool_2d_ceil_stride_pad_include_padding) { - Shape in_shape{1, 1, 1, 5}; - Shape out_shape{1, 1, 1, 3}; - const Strides& strides{1, 2}; - const Shape& pads_begin{1, 1}; - const Shape& pads_end{1, 1}; - const Shape& kernel{3, 3}; - const bool exclude_pad = false; - const op::RoundingType rounding_type = op::RoundingType::CEIL; - const op::PadType pad_type = op::PadType::EXPLICIT; - - auto A = make_shared(element::f32, in_shape); - auto avgPool = - make_shared(A, strides, pads_begin, pads_end, kernel, exclude_pad, rounding_type, pad_type); - auto f = make_shared(avgPool, ParameterVector{A}); - - std::vector a{2.5, 2, 12, 4, 5}; - std::vector result{0.5, 2, 1}; - - auto test_case = test::TestCase(f); - test_case.add_input({a}); - test_case.add_expected_output(out_shape, result); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, avg_pool_2d_same_upper) { - Shape in_shape{1, 1, 3, 3}; - Shape out_shape{1, 1, 3, 3}; - const Strides& strides{1, 1}; - const Shape& pads_begin{0, 0}; - const Shape& pads_end{0, 0}; - const Shape& kernel{2, 2}; - const bool exclude_pad = false; - const op::RoundingType rounding_type = op::RoundingType::CEIL; - const op::PadType pad_type = op::PadType::SAME_UPPER; - - auto A = make_shared(element::f32, in_shape); - auto avgPool = - make_shared(A, strides, pads_begin, pads_end, kernel, exclude_pad, rounding_type, pad_type); - auto f = make_shared(avgPool, ParameterVector{A}); - - std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9}; - std::vector result{3, 4, 2.25, 6, 7, 3.75, 3.75, 4.25, 2.25}; - - auto test_case = test::TestCase(f); - test_case.add_input({a}); - test_case.add_expected_output(out_shape, result); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, avg_pool_3d) { - Shape in_shape{1, 1, 2, 2, 2}; - Shape out_shape{1, 1, 2, 2, 1}; - const Strides& strides{1, 1, 1}; - const Shape& pads_begin{0, 0, 0}; - const Shape& pads_end{0, 0, 0}; - const Shape& kernel{1, 1, 2}; - const bool exclude_pad = true; - const op::RoundingType rounding_type = op::RoundingType::CEIL; - const op::PadType pad_type = op::PadType::VALID; - - auto A = make_shared(element::f32, in_shape); - auto avgPool = - make_shared(A, strides, pads_begin, pads_end, kernel, exclude_pad, rounding_type, pad_type); - auto f = make_shared(avgPool, ParameterVector{A}); - - std::vector a{1, 2, 3, 4, 5, 6, 7, 8}; - std::vector result{1.5, 3.5, 5.5, 7.5}; - - auto test_case = test::TestCase(f); - test_case.add_input({a}); - test_case.add_expected_output(out_shape, result); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, avg_pool_2d_same_lower) { - Shape in_shape{1, 1, 3, 3}; - Shape out_shape{1, 1, 3, 3}; - const Strides& strides{1, 1}; - const Shape& pads_begin{0, 0}; - const Shape& pads_end{0, 0}; - const Shape& kernel{2, 2}; - const bool exclude_pad = false; - const op::RoundingType rounding_type = op::RoundingType::CEIL; - const op::PadType pad_type = op::PadType::SAME_LOWER; - - auto A = make_shared(element::f32, in_shape); - auto avgPool = - make_shared(A, strides, pads_begin, pads_end, kernel, exclude_pad, rounding_type, pad_type); - auto f = make_shared(avgPool, ParameterVector{A}); - - std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9}; - std::vector result{0.25, 0.75, 1.25, 1.25, 3, 4, 2.75, 6, 7}; - - auto test_case = test::TestCase(f); - test_case.add_input({a}); - test_case.add_expected_output(out_shape, result); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, avg_pool_2d_padding) { - Shape in_shape{1, 1, 3, 3}; - Shape out_shape{1, 1, 3, 3}; - const Strides& strides{2, 2}; - const Shape& pads_begin{1, 1}; - const Shape& pads_end{1, 1}; - const Shape& kernel{2, 2}; - const bool exclude_pad = true; - const op::RoundingType rounding_type = op::RoundingType::CEIL; - const op::PadType pad_type = op::PadType::NOTSET; - - auto A = make_shared(element::f32, in_shape); - auto avgPool = - make_shared(A, strides, pads_begin, pads_end, kernel, exclude_pad, rounding_type, pad_type); - auto f = make_shared(avgPool, ParameterVector{A}); - - std::vector a(1 * 1 * 3 * 3); - std::iota(std::begin(a), std::end(a), 1); - std::vector result{1.0f, 2.5f, 0, 5.5f, 7.0f, 0, 0, 0, 0}; - - auto test_case = test::TestCase(f); - test_case.add_input({a}); - test_case.add_expected_output(out_shape, result); - test_case.run(); -} diff --git a/ngraph/test/backend/max_pool.in.cpp b/ngraph/test/backend/max_pool.in.cpp deleted file mode 100644 index 76639917d6c..00000000000 --- a/ngraph/test/backend/max_pool.in.cpp +++ /dev/null @@ -1,186 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -// clang-format off -#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#endif - -#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#endif -// clang-format on - -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "engines_util/test_engines.hpp" -#include "engines_util/test_case.hpp" -#include "util/test_control.hpp" - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; -using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); - -NGRAPH_TEST(${BACKEND_NAME}, max_pool_2d_floor) { - Shape in_shape{1, 1, 3, 3}; - Shape out_shape{1, 1, 2, 2}; - const Strides& strides{1, 1}; - const Shape& pads_begin{0, 0}; - const Shape& pads_end{0, 0}; - const Shape& kernel{2, 2}; - const op::RoundingType rounding_type = op::RoundingType::FLOOR; - const op::PadType pad_type = op::PadType::NOTSET; - - auto A = make_shared(element::f32, in_shape); - auto maxPool = make_shared(A, strides, pads_begin, pads_end, kernel, rounding_type, pad_type); - auto f = make_shared(maxPool, ParameterVector{A}); - - std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9}; - std::vector result{5, 6, 8, 9}; - - auto test_case = test::TestCase(f); - test_case.add_input({a}); - test_case.add_expected_output(out_shape, result); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, max_pool_2d_ceil) { - Shape in_shape{1, 1, 4, 4}; - Shape out_shape{1, 1, 2, 2}; - const Strides& strides{1, 1}; - const Shape& pads_begin{0, 0}; - const Shape& pads_end{0, 0}; - const Shape& kernel{3, 3}; - const op::RoundingType rounding_type = op::RoundingType::CEIL; - const op::PadType pad_type = op::PadType::NOTSET; - - auto A = make_shared(element::f32, in_shape); - auto maxPool = make_shared(A, strides, pads_begin, pads_end, kernel, rounding_type, pad_type); - auto f = make_shared(maxPool, ParameterVector{A}); - - std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - std::vector result{11, 12, 15, 16}; - - auto test_case = test::TestCase(f); - test_case.add_input({a}); - test_case.add_expected_output(out_shape, result); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, max_pool_2d_pad) { - Shape in_shape{1, 1, 2, 2}; - Shape out_shape{1, 1, 3, 3}; - const Strides& strides{1, 1}; - const Shape& pads_begin{1, 1}; - const Shape& pads_end{1, 1}; - const Shape& kernel{2, 2}; - const op::RoundingType rounding_type = op::RoundingType::CEIL; - const op::PadType pad_type = op::PadType::NOTSET; - - auto A = make_shared(element::f32, in_shape); - auto maxPool = make_shared(A, strides, pads_begin, pads_end, kernel, rounding_type, pad_type); - auto f = make_shared(maxPool, ParameterVector{A}); - - std::vector a{1, 2, 3, 4}; - std::vector result{1, 2, 2, 3, 4, 4, 3, 4, 4}; - - auto test_case = test::TestCase(f); - test_case.add_input({a}); - test_case.add_expected_output(out_shape, result); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, max_pool_2d_ceil_stride_pad) { - Shape in_shape{1, 1, 1, 5}; - Shape out_shape{1, 1, 1, 3}; - const Strides& strides{1, 2}; - const Shape& pads_begin{1, 1}; - const Shape& pads_end{1, 1}; - const Shape& kernel{3, 3}; - const op::RoundingType rounding_type = op::RoundingType::CEIL; - const op::PadType pad_type = op::PadType::EXPLICIT; - - auto A = make_shared(element::f32, in_shape); - auto maxPool = make_shared(A, strides, pads_begin, pads_end, kernel, rounding_type, pad_type); - auto f = make_shared(maxPool, ParameterVector{A}); - - std::vector a{1, 2, 3, 4, 5}; - std::vector result{2, 4, 5}; - - auto test_case = test::TestCase(f); - test_case.add_input({a}); - test_case.add_expected_output(out_shape, result); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, max_pool_2d_same_upper) { - Shape in_shape{1, 1, 3, 3}; - Shape out_shape{1, 1, 3, 3}; - const Strides& strides{1, 1}; - const Shape& pads_begin{0, 0}; - const Shape& pads_end{0, 0}; - const Shape& kernel{2, 2}; - const op::RoundingType rounding_type = op::RoundingType::CEIL; - const op::PadType pad_type = op::PadType::SAME_UPPER; - - auto A = make_shared(element::f32, in_shape); - auto maxPool = make_shared(A, strides, pads_begin, pads_end, kernel, rounding_type, pad_type); - auto f = make_shared(maxPool, ParameterVector{A}); - - std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9}; - std::vector result{5, 6, 6, 8, 9, 9, 8, 9, 9}; - - auto test_case = test::TestCase(f); - test_case.add_input({a}); - test_case.add_expected_output(out_shape, result); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, max_pool_3d) { - Shape in_shape{1, 1, 2, 2, 2}; - Shape out_shape{1, 1, 2, 2, 1}; - const Strides& strides{1, 1, 1}; - const Shape& pads_begin{0, 0, 0}; - const Shape& pads_end{0, 0, 0}; - const Shape& kernel{1, 1, 2}; - const op::RoundingType rounding_type = op::RoundingType::CEIL; - const op::PadType pad_type = op::PadType::VALID; - - auto A = make_shared(element::f32, in_shape); - auto maxPool = make_shared(A, strides, pads_begin, pads_end, kernel, rounding_type, pad_type); - auto f = make_shared(maxPool, ParameterVector{A}); - - std::vector a{1, 2, 3, 4, 5, 6, 7, 8}; - std::vector result{2, 4, 6, 8}; - - auto test_case = test::TestCase(f); - test_case.add_input({a}); - test_case.add_expected_output(out_shape, result); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, max_pool_2d_same_lower) { - Shape in_shape{1, 1, 3, 3}; - Shape out_shape{1, 1, 3, 3}; - const Strides& strides{1, 1}; - const Shape& pads_begin{0, 0}; - const Shape& pads_end{0, 0}; - const Shape& kernel{2, 2}; - const op::RoundingType rounding_type = op::RoundingType::CEIL; - const op::PadType pad_type = op::PadType::SAME_LOWER; - - auto A = make_shared(element::f32, in_shape); - auto maxPool = make_shared(A, strides, pads_begin, pads_end, kernel, rounding_type, pad_type); - auto f = make_shared(maxPool, ParameterVector{A}); - - std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9}; - std::vector result{1, 2, 3, 4, 5, 6, 7, 8, 9}; - - auto test_case = test::TestCase(f); - test_case.add_input({a}); - test_case.add_expected_output(out_shape, result); - test_case.run(); -} diff --git a/ngraph/test/visitors/op/avg_pool.cpp b/ngraph/test/visitors/op/avg_pool.cpp new file mode 100644 index 00000000000..4975b2a20d5 --- /dev/null +++ b/ngraph/test/visitors/op/avg_pool.cpp @@ -0,0 +1,66 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "gtest/gtest.h" +#include "ngraph/ngraph.hpp" +#include "ngraph/op/util/attr_types.hpp" +#include "ngraph/opsets/opset1.hpp" +#include "ngraph/opsets/opset8.hpp" +#include "util/visitor.hpp" + +using namespace std; +using namespace ngraph; +using ngraph::test::NodeBuilder; +using ngraph::test::ValueMap; + +TEST(attributes, avg_pool_op) { + NodeBuilder::get_ops().register_factory(); + auto data = make_shared(element::f32, Shape{64, 3, 5}); + + auto strides = Strides{2}; + auto pads_begin = Shape{1}; + auto pads_end = Shape{1}; + auto kernel = Shape{1}; + bool exclude_pad = false; + auto rounding_mode = op::RoundingType::FLOOR; + auto auto_pad = op::PadType::EXPLICIT; + + auto avg_pool = + make_shared(data, strides, pads_begin, pads_end, kernel, exclude_pad, rounding_mode, auto_pad); + + NodeBuilder builder(avg_pool); + auto g_avg_pool = ov::as_type_ptr(builder.create()); + + EXPECT_EQ(g_avg_pool->get_strides(), avg_pool->get_strides()); + EXPECT_EQ(g_avg_pool->get_pads_begin(), avg_pool->get_pads_begin()); + EXPECT_EQ(g_avg_pool->get_pads_end(), avg_pool->get_pads_end()); + EXPECT_EQ(g_avg_pool->get_kernel(), avg_pool->get_kernel()); + EXPECT_EQ(g_avg_pool->get_rounding_type(), avg_pool->get_rounding_type()); + EXPECT_EQ(g_avg_pool->get_auto_pad(), avg_pool->get_auto_pad()); +} + +TEST(attributes, avg_pool_v8_op) { + NodeBuilder::get_ops().register_factory(); + const auto data = make_shared(element::i32, Shape{1, 3, 37, 37}); + + const auto strides = Strides{1, 1}; + const auto pads_begin = Shape{1, 1}; + const auto pads_end = Shape{1, 1}; + const auto kernel = Shape{2, 2}; + bool exclude_pad = false; + const auto rounding_mode = op::RoundingType::CEIL; + const auto auto_pad = op::PadType::EXPLICIT; + + const auto avg_pool = + make_shared(data, strides, pads_begin, pads_end, kernel, exclude_pad, rounding_mode, auto_pad); + NodeBuilder builder(avg_pool); + auto g_avg_pool = ov::as_type_ptr(builder.create()); + + EXPECT_EQ(g_avg_pool->get_strides(), avg_pool->get_strides()); + EXPECT_EQ(g_avg_pool->get_pads_begin(), avg_pool->get_pads_begin()); + EXPECT_EQ(g_avg_pool->get_pads_end(), avg_pool->get_pads_end()); + EXPECT_EQ(g_avg_pool->get_kernel(), avg_pool->get_kernel()); + EXPECT_EQ(g_avg_pool->get_rounding_type(), avg_pool->get_rounding_type()); + EXPECT_EQ(g_avg_pool->get_auto_pad(), avg_pool->get_auto_pad()); +} From 6908023a42e0a4faf5a023aa0fe194b58e76582f Mon Sep 17 00:00:00 2001 From: Artyom Anokhov Date: Thu, 28 Oct 2021 10:50:09 +0300 Subject: [PATCH 11/12] config.py: Updated routing due to new place of DM tool. (#8230) config/*.json: Updated list of files due to current layout --- tools/deployment_manager/configs/darwin.json | 9 ++++----- tools/deployment_manager/configs/linux.json | 11 +++++------ tools/deployment_manager/configs/windows.json | 9 ++++----- tools/deployment_manager/deployman/config.py | 3 +-- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/tools/deployment_manager/configs/darwin.json b/tools/deployment_manager/configs/darwin.json index bedec06697a..492bf6692a8 100644 --- a/tools/deployment_manager/configs/darwin.json +++ b/tools/deployment_manager/configs/darwin.json @@ -26,7 +26,6 @@ "runtime/lib/intel64/libfrontend_manager.dylib", "runtime/lib/intel64/libir_ngraph_frontend.dylib", "runtime/lib/intel64/libonnx_ngraph_frontend.dylib", - "runtime/lib/intel64/libpaddlepaddle_ngraph_frontend.dylib", "runtime/lib/intel64/plugins.xml", "runtime/3rdparty/tbb" ] @@ -56,10 +55,10 @@ "group": ["opencv"], "dependencies" : [], "files": [ - "opencv/version.txt", - "opencv/setupvars.sh", - "opencv/lib", - "opencv/bin" + "extras/opencv/version.txt", + "extras/opencv/setupvars.sh", + "extras/opencv/lib", + "extras/opencv/bin" ] }, "python_common": { diff --git a/tools/deployment_manager/configs/linux.json b/tools/deployment_manager/configs/linux.json index 181e5116554..0108677c007 100644 --- a/tools/deployment_manager/configs/linux.json +++ b/tools/deployment_manager/configs/linux.json @@ -32,7 +32,6 @@ "runtime/lib/intel64/libfrontend_manager.so", "runtime/lib/intel64/libir_ngraph_frontend.so", "runtime/lib/intel64/libonnx_ngraph_frontend.so", - "runtime/lib/intel64/libpaddlepaddle_ngraph_frontend.so", "runtime/lib/intel64/plugins.xml", "runtime/3rdparty/tbb" ] @@ -78,7 +77,7 @@ "files": [ "runtime/lib/intel64/libgna.so", "runtime/lib/intel64/libgna.so.2", - "runtime/lib/intel64/libgna.so.2.0.0.1226", + "runtime/lib/intel64/libgna.so.3.0.0.1377", "runtime/lib/intel64/libinference_engine_legacy.so", "runtime/lib/intel64/libGNAPlugin.so" ] @@ -98,10 +97,10 @@ "group": ["opencv"], "dependencies" : [], "files": [ - "opencv/version.txt", - "opencv/setupvars.sh", - "opencv/lib", - "opencv/bin" + "extras/opencv/version.txt", + "extras/opencv/setupvars.sh", + "extras/opencv/lib", + "extras/opencv/bin" ] }, "python_common": { diff --git a/tools/deployment_manager/configs/windows.json b/tools/deployment_manager/configs/windows.json index 71eedada1de..7c0f5c3078f 100644 --- a/tools/deployment_manager/configs/windows.json +++ b/tools/deployment_manager/configs/windows.json @@ -26,7 +26,6 @@ "runtime/bin/intel64/Release/frontend_manager.dll", "runtime/bin/intel64/Release/ir_ngraph_frontend.dll", "runtime/bin/intel64/Release/onnx_ngraph_frontend.dll", - "runtime/bin/intel64/Release/paddlepaddle_ngraph_frontend.dll", "runtime/bin/intel64/Release/plugins.xml", "runtime/3rdparty/tbb" ] @@ -88,10 +87,10 @@ "group": ["opencv"], "dependencies" : [], "files": [ - "opencv/version.txt", - "opencv/setupvars.bat", - "opencv/lib", - "opencv/bin" + "extras/opencv/version.txt", + "extras/opencv/setupvars.bat", + "extras/opencv/lib", + "extras/opencv/bin" ] }, "python_common": { diff --git a/tools/deployment_manager/deployman/config.py b/tools/deployment_manager/deployman/config.py index 91fff2870a0..d129df32f65 100644 --- a/tools/deployment_manager/deployman/config.py +++ b/tools/deployment_manager/deployman/config.py @@ -32,8 +32,7 @@ class Component: self.logger = logger self.root_dir = os.getenv('INTEL_OPENVINO_DIR', os.path.abspath(os.path.join(os.path.dirname(__file__), - os.pardir, os.pardir, - os.pardir, os.pardir))) + os.pardir, os.pardir, os.pardir))) def is_exist(self): self.logger.debug("Checking {} component...".format(self.name)) From 6416b73855053581dec347f15d2ceba658ced8c9 Mon Sep 17 00:00:00 2001 From: Maxim Andronov Date: Thu, 28 Oct 2021 10:52:14 +0300 Subject: [PATCH 12/12] [CPU] MVN, FQ, Convert dynamic nodes (#7817) --- .../src/mkldnn_plugin/mkldnn_graph.cpp | 2 +- .../mkldnn_plugin/mkldnn_graph_optimizer.cpp | 25 +- .../src/mkldnn_plugin/mkldnn_node.cpp | 147 ++++---- .../src/mkldnn_plugin/mkldnn_node.h | 14 +- .../nodes/mkldnn_bin_conv_node.cpp | 12 +- .../nodes/mkldnn_concat_node.cpp | 2 +- .../mkldnn_plugin/nodes/mkldnn_conv_node.cpp | 8 +- .../nodes/mkldnn_convert_node.cpp | 17 +- .../mkldnn_plugin/nodes/mkldnn_convert_node.h | 6 +- .../nodes/mkldnn_deconv_node.cpp | 5 +- .../nodes/mkldnn_eltwise_node.cpp | 61 ++- .../mkldnn_plugin/nodes/mkldnn_eltwise_node.h | 11 +- .../nodes/mkldnn_fake_quantize_node.cpp | 348 ++++++++++++------ .../nodes/mkldnn_fake_quantize_node.h | 29 +- .../nodes/mkldnn_fullyconnected_node.cpp | 8 +- .../nodes/mkldnn_interpolate_node.cpp | 5 +- .../nodes/mkldnn_matmul_node.cpp | 4 +- .../mkldnn_plugin/nodes/mkldnn_mvn_node.cpp | 163 ++++---- .../src/mkldnn_plugin/nodes/mkldnn_mvn_node.h | 16 +- .../nodes/mkldnn_normalize_node.cpp | 5 +- .../nodes/mkldnn_reorder_node.cpp | 4 - .../nodes/mkldnn_select_node.cpp | 4 - .../src/mkldnn_plugin/utils/cpu_utils.hpp | 38 +- .../skip_tests_config.cpp | 9 + .../cpu/single_layer_tests/conversion.cpp | 134 +++++-- .../cpu/single_layer_tests/fake_quantize.cpp | 315 +++++++++++----- .../plugin/cpu/single_layer_tests/mvn.cpp | 225 ++++++++--- .../plugin/cpu/single_layer_tests/select.cpp | 4 +- 28 files changed, 1085 insertions(+), 536 deletions(-) diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_graph.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_graph.cpp index 61928e183f5..c8c9966b0c5 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_graph.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_graph.cpp @@ -486,7 +486,7 @@ void MKLDNNGraph::InitEdges() { std::string convertName = edge->getParent()->getName() + "_" + inDesc.getPrecision().name() + "_" + outDesc.getPrecision().name(); - auto convertNode = std::make_shared(inDesc.getShape().getStaticDims(), inDesc.getPrecision(), outDesc.getPrecision(), + auto convertNode = std::make_shared(inDesc.getShape(), inDesc.getPrecision(), outDesc.getPrecision(), convertName, this->getEngine(), this->weightsCache); convertNode->setDescs(inDesc, outDesc); InsertNode(edge, convertNode, true); diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp index 07a4314ff3b..639932348f0 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp @@ -1609,7 +1609,30 @@ void MKLDNNGraphOptimizer::FusePerformedAsScaleShiftAndFakeQuantize(MKLDNNGraph std::vector scalesBuffer; std::vector shiftsBuffer; - parent->fillScalesAndShifts(parent->getParentEdgesAtPort(1 - getConstPort(parent))[0]->getParent().get(), scalesBuffer, shiftsBuffer, 1); + auto parentEltwise = std::dynamic_pointer_cast(parent); + if (!parentEltwise) { + IE_THROW() << "Cannot cast " << parent->getName() << " to Eltwise node"; + } + + std::tie(scalesBuffer, shiftsBuffer) = parentEltwise->getScalesAndShifts(parent->getParentEdgesAtPort(1 - getConstPort(parent))[0]->getParent().get()); + + const auto &outputShape = child->getOutputShapeAtPort(0); + VectorDims outputDims = outputShape.getDims(); + const size_t channelPos = outputDims.size() > 1 ? 1 : 0; + if (outputShape.isDynamic()) { + if (outputDims[channelPos] == Shape::UNDEFINED_DIM) { + if (scalesBuffer.size() > 1) { + outputDims[channelPos] = scalesBuffer.size(); + } else if (shiftsBuffer.size() > 1) { + outputDims[channelPos] = shiftsBuffer.size(); + } else { + return false; + } + } + } + + scalesBuffer = makeAlignedBuffer(outputDims[channelPos], scalesBuffer, 1); + shiftsBuffer = makeAlignedBuffer(outputDims[channelPos], shiftsBuffer, 1); for (int i = 0; i < scalesBuffer.size(); i++) if (scalesBuffer[i] == 0.f) diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_node.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_node.cpp index 31d36aece4a..e6cf1a01704 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_node.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_node.cpp @@ -503,8 +503,9 @@ void MKLDNNNode::execute(mkldnn::stream strm) { } void MKLDNNNode::executeDynamic(mkldnn::stream strm) { - if (needShapeInfer()) + if (needShapeInfer()) { redefineOutputMemory(shapeInfer()); + } if (needPrepareParams()) { IE_ASSERT(inputShapesDefined()) << "Can't prepare params for " << getTypeStr() << " node with name: " << getName() << " since the input shapes are not defined."; @@ -1045,7 +1046,7 @@ Layout MKLDNNNode::getWeightsLayoutByDims(SizeVector dims, bool isGrouped) { } } -void MKLDNNNode::appendPostOps(mkldnn::post_ops& ops, bool initAsBinary, bool initBinaryMemory) { +void MKLDNNNode::appendPostOps(mkldnn::post_ops& ops, const VectorDims &postOpDims, int align, bool initAsBinary, bool initBinaryMemory) { IE_THROW() << "Fusing of " << this->getType() << " operation is not implemented"; } @@ -1192,7 +1193,7 @@ bool MKLDNNNode::canBePerformedAsScaleShift(const MKLDNNNode *parentNode) const if (i == fusingPort) continue; auto& weightShape = getInputShapeAtPort(i).getDims(); - if (getParentEdgesAtPort(i)[0]->getParent()->getChildEdges().size() != 1 || !isPerTensorOrPerChannelBroadcastable(dataShape, weightShape)) + if (getParentEdgesAtPort(i)[0]->getParent()->getChildEdges().size() != 1 || !isPerTensorOrPerChannelBroadcastable(dataShape, weightShape, true)) return false; } return true; @@ -1213,6 +1214,66 @@ bool MKLDNNNode::canBePerformedAsScaleShift(const MKLDNNNode *parentNode) const || isConvertablePowerStatic(); } +std::pair, std::vector> MKLDNNNode::getScalesAndShifts(const MKLDNNNode *parentNode) const { + std::vector scales, shifts; + + const auto fillValuesFrom = [&](const MKLDNNNodePtr& constInput, std::vector& buffer) { + auto *constInputNode = dynamic_cast(constInput.get()); + auto constBlob = constInputNode->getMemoryPtr(); + const auto elementsCount = constBlob->GetDescWithType()->getPaddedElementsCount(); + buffer.resize(elementsCount); + cpu_convert(constBlob->GetPtr(), + &buffer[0], + MKLDNNExtensionUtils::DataTypeToIEPrecision(constBlob->GetDataType()), + Precision::FP32, + elementsCount); + }; + + const auto constPort = getParentEdgesAtPort(0)[0]->getParent().get() == parentNode ? 1 : 0; + + if (one_of(getAlgorithm(), EltwiseMultiply, EltwiseDivide, EltwisePrelu)) { + fillValuesFrom(getParentEdgesAtPort(constPort)[0]->getParent(), scales); + } else if (one_of(getAlgorithm(), EltwiseAdd, EltwiseSubtract)) { + fillValuesFrom(getParentEdgesAtPort(constPort)[0]->getParent(), shifts); + } else if (one_of(getAlgorithm(), EltwiseMulAdd)) { + fillValuesFrom(getParentEdgesAtPort(1)[0]->getParent(), scales); + fillValuesFrom(getParentEdgesAtPort(2)[0]->getParent(), shifts); + } else if (one_of(getAlgorithm(), EltwisePowerStatic)) { + const auto power = dynamic_cast(this); + if (!power) { + IE_THROW() << "Cannot cast " << getName() << " to MKLDNNEltwiseNode"; + } + scales.push_back(power->getBeta()); + shifts.push_back(power->getGamma()); + } else { + IE_THROW() << "Can't fill scale and shifts for node: " << getName() << " with type: " << NameFromType(getType()); + } + + switch (getAlgorithm()) { + case EltwiseAdd: { + scales.resize(shifts.size(), 1.0f); + break; + } + case EltwiseSubtract: { + scales.resize(shifts.size(), 1.0f); + std::transform(shifts.begin(), shifts.end(), shifts.begin(), [](float shift){ return -1.0f * shift; }); + break; + } + case EltwiseMultiply: { + shifts.resize(scales.size(), 0.0f); + break; + } + case EltwiseDivide: { + shifts.resize(scales.size(), 0.0f); + std::transform(scales.begin(), scales.end(), scales.begin(), [](float scale){ return 1.0f / scale; }); + break; + } + default: break; + } + + return {scales, shifts}; +} + bool MKLDNNNode::inputShapesDefined() const { for (size_t i = 0; i < getParentEdges().size(); i++) { if (!getParentEdgesAtPort(i)[0]->getMemory().getDesc().isDefined()) @@ -1307,86 +1368,6 @@ bool MKLDNNNode::canFuseSimpleOperation(const MKLDNNNodePtr& node) const { return false; } -void MKLDNNNode::fillScalesAndShifts(const MKLDNNNode *parentNode, std::vector &scales, std::vector &shifts, int align) { - scales.clear(); - shifts.clear(); - const auto fillValuesFrom = [&](const MKLDNNNodePtr& constInput, std::vector& buffer) { - auto *constInputNode = dynamic_cast(constInput.get()); - auto constBlob = constInputNode->getMemoryPtr(); - const auto elementsCount = constBlob->GetDescWithType()->getPaddedElementsCount(); - buffer.resize(elementsCount); - cpu_convert(constBlob->GetPtr(), - &buffer[0], - MKLDNNExtensionUtils::DataTypeToIEPrecision(constBlob->GetDataType()), - Precision::FP32, - elementsCount); - }; - - const size_t constPort = getParentEdgesAtPort(0)[0]->getParent().get() == parentNode ? 1 : 0; - - if (one_of(getAlgorithm(), EltwiseMultiply, EltwiseDivide, EltwisePrelu)) { - fillValuesFrom(getParentEdgesAtPort(constPort)[0]->getParent(), scales); - } else if (one_of(getAlgorithm(), EltwiseAdd, EltwiseSubtract)) { - fillValuesFrom(getParentEdgesAtPort(constPort)[0]->getParent(), shifts); - } else if (one_of(getAlgorithm(), EltwiseMulAdd)) { - fillValuesFrom(getParentEdgesAtPort(1)[0]->getParent(), scales); - fillValuesFrom(getParentEdgesAtPort(2)[0]->getParent(), shifts); - } else if (one_of(getAlgorithm(), EltwisePowerStatic)) { - const auto power = dynamic_cast(this); - if (!power) { - IE_THROW() << "Cannot cast " << getName() << " to MKLDNNEltwiseNode"; - } - scales.push_back(power->getBeta()); - shifts.push_back(power->getGamma()); - } else { - IE_THROW() << "Can't fill scale and shifts for node: " << getName() << " with type: " << NameFromType(getType()); - } - - const size_t bufferSize = static_cast(outputShapes[0].getStaticDims()[outputShapes[0].getRank() > 1 ? 1 : 0]); - if (align == -1) { - align = bufferSize; - } - const size_t bufferSizeAligned = rnd_up(bufferSize, static_cast(align)); - - size_t initSize = scales.size(); - if (initSize > 0) { - scales.resize(bufferSizeAligned, 0); - if (initSize == 1) { - std::fill(scales.begin() + 1, scales.begin() + bufferSize, scales[0]); - } - } - - initSize = shifts.size(); - if (initSize > 0) { - shifts.resize(bufferSizeAligned, 0); - if (initSize == 1) { - std::fill(shifts.begin() + 1, shifts.begin() + bufferSize, shifts[0]); - } - } - - switch (getAlgorithm()) { - case EltwiseAdd: { - scales.resize(bufferSizeAligned, 1.0f); - break; - } - case EltwiseSubtract: { - scales.resize(bufferSizeAligned, 1.0f); - std::transform(shifts.begin(), shifts.end(), shifts.begin(), [](float shift){ return -1.0f * shift; }); - break; - } - case EltwiseMultiply: { - shifts.resize(bufferSizeAligned, 0.0f); - break; - } - case EltwiseDivide: { - shifts.resize(bufferSizeAligned, 0.0f); - std::transform(scales.begin(), scales.end(), scales.begin(), [](float scale){ return 1.0f / scale; }); - break; - } - default: break; - } -} - void MKLDNNNode::createShapeInferSubgraph(const std::shared_ptr& op) { ngraph::OutputVector inputsForShapeInfer; for (size_t i = 0; i < inputShapes.size(); i++) { diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_node.h b/inference-engine/src/mkldnn_plugin/mkldnn_node.h index 7e089789720..d488aa100a1 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_node.h +++ b/inference-engine/src/mkldnn_plugin/mkldnn_node.h @@ -556,10 +556,18 @@ public: return outputShapes[port]; } + /** + * @brief Return scales and shift if nodes can be executed as ScaleShift, else raise exception + * If node has only scale or shift value, fill missing value with default values + * i.e. EltwiseAdd: fill shifts from constant, fill scales with default values = 1.0f + * @param parentNode + * node from which data comes + * @return pair of scales and shifts + */ + std::pair, std::vector> getScalesAndShifts(const MKLDNNNode *parentNode) const; + protected: bool canFuseSimpleOperation(const MKLDNNNodePtr& node) const; - // TODO [mandrono]: place outside of the node API - void fillScalesAndShifts(const MKLDNNNode *parentNode, std::vector &scales, std::vector &shifts, const int align = -1); void setType(Type type) { this->type = type; @@ -578,7 +586,7 @@ protected: * Seed node should call this routine and pass its post operations list as parameter. * @param ops List of fused post operations */ - virtual void appendPostOps(mkldnn::post_ops& ops, bool initAsBinary = false, bool initBinaryMemory = false); + virtual void appendPostOps(mkldnn::post_ops& ops, const VectorDims &postOpDims, int align = -1, bool initAsBinary = false, bool initBinaryMemory = false); virtual std::shared_ptr initPrimitiveAttr() const { return nullptr; } typedef std::function diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_bin_conv_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_bin_conv_node.cpp index 77e256a4204..b44b830495f 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_bin_conv_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_bin_conv_node.cpp @@ -19,6 +19,7 @@ #include "cpu/x64/cpu_isa_traits.hpp" #include "utils/general_utils.h" #include +#include "utils/cpu_utils.hpp" // WA for xbyak.h #ifdef _WIN32 @@ -1127,16 +1128,19 @@ void MKLDNNBinaryConvolutionNode::setPostOps(mkldnn::primitive_attr &attr) { for (auto &node : fusedWith) { auto* eltwiseNode = dynamic_cast(node.get()); if (eltwiseNode) { - if (eltwiseNode->isSpecialConvolutionAddFusing()) + if (eltwiseNode->isSpecialConvolutionAddFusing()) { ops.append_sum(1.0); - else - eltwiseNode->appendPostOps(ops); + } else { + // TODO [DS]: change to shape from memory + constexpr int align = 16; + eltwiseNode->appendPostOps(ops, getOutputShapeAtPort(0).getStaticDims(), align); + } continue; } auto* fakeQuantizeNode = dynamic_cast(node.get()); if (fakeQuantizeNode) { - fakeQuantizeNode->appendPostOps(ops); + fakeQuantizeNode->appendPostOps(ops, getOutputShapeAtPort(0).getStaticDims()); continue; } diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_concat_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_concat_node.cpp index 6ea8d482827..e03c006fe63 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_concat_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_concat_node.cpp @@ -355,7 +355,7 @@ void MKLDNNConcatNode::createPrimitive() { IE_THROW() << "Source memory from " << parent->getName() << " didn't allocate for node " << getName() << "."; } -// DnnlBlockedMemoryDesc + auto desc = srcMemPtr->GetDescWithType()->getDnnlDesc(); auto& dims = getInputShapeAtPort(i).getStaticDims(); for (size_t j = 0; j < dims.size(); j++) { diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_conv_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_conv_node.cpp index 121d7c63c5b..fb9a0ceacb4 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_conv_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_conv_node.cpp @@ -20,6 +20,7 @@ #include "common/cpu_convert.h" #include #include "memory_desc/dnnl_blocked_memory_desc.h" +#include "utils/cpu_utils.hpp" using namespace mkldnn; using namespace MKLDNNPlugin; @@ -338,7 +339,8 @@ void MKLDNNConvolutionNode::setPostOps(mkldnn::primitive_attr &attr, bool initWe if (eltwiseNode->isSpecialConvolutionAddFusing()) { ops.append_sum(1.0, MKLDNNExtensionUtils::IEPrecisionToDataType(eltwisePrecision)); } else { - eltwiseNode->appendPostOps(ops, initAsBinary, initBinaryMemory); + constexpr int align = 16; + eltwiseNode->appendPostOps(ops, getOutputShapeAtPort(0).getStaticDims(), align, initAsBinary, initBinaryMemory); if (initBinaryMemory) { if (eltwiseNode->scalesMemory) binaryPostOpsArgs.push_back(eltwiseNode->scalesMemory->GetPrimitive()); @@ -351,7 +353,9 @@ void MKLDNNConvolutionNode::setPostOps(mkldnn::primitive_attr &attr, bool initWe auto* fakeQuantizeNode = dynamic_cast(node.get()); if (fakeQuantizeNode) { - fakeQuantizeNode->appendPostOps(ops, initAsBinary, initBinaryMemory); + constexpr int align = -1; + // no need to fill post ops dims for fq, make sense only for bin fq + fakeQuantizeNode->appendPostOps(ops, VectorDims{}, align, initAsBinary, initBinaryMemory); if (initBinaryMemory) { if (fakeQuantizeNode->cropHighMemory) binaryPostOpsArgs.push_back(fakeQuantizeNode->cropHighMemory->GetPrimitive()); diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_convert_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_convert_node.cpp index 548f2a9efc7..2faf969c1ea 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_convert_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_convert_node.cpp @@ -15,11 +15,6 @@ using namespace InferenceEngine; bool MKLDNNConvertNode::isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept { try { - if (isDynamicNgraphNode(op)) { - errorMessage = "Doesn't support op with dynamic shapes"; - return false; - } - const auto convert = std::dynamic_pointer_cast(op); if (!convert) { errorMessage = "Only opset1 Convert operation is supported"; @@ -41,14 +36,20 @@ MKLDNNConvertNode::MKLDNNConvertNode(const std::shared_ptr& op, co } } -MKLDNNConvertNode::MKLDNNConvertNode(const InferenceEngine::SizeVector &dims, const InferenceEngine::Precision &inPrc, const InferenceEngine::Precision &outPrc, +std::vector MKLDNNConvertNode::shapeInfer() const { + return std::vector{getParentEdgesAtPort(0)[0]->getMemory().getStaticDims()}; +} + +MKLDNNConvertNode::MKLDNNConvertNode(const Shape &shape, const InferenceEngine::Precision &inPrc, const InferenceEngine::Precision &outPrc, const std::string &nodeName, const mkldnn::engine& eng, MKLDNNWeightsSharing::Ptr &cache) : MKLDNNNode("Convert", nodeName, eng, cache) { - inputShapes.emplace_back(dims); + inputShapes.push_back(shape); addOriginalInputPrecision(inPrc); - outputShapes.emplace_back(dims); + outputShapes.push_back(shape); addOriginalOutputPrecision(outPrc); + isDynamic = shape.isDynamic(); + errorPrefix = "Convert node with name '" + getName() + "'"; } diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_convert_node.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_convert_node.h index 9ed32a4d17e..bffb2447280 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_convert_node.h +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_convert_node.h @@ -14,13 +14,14 @@ namespace MKLDNNPlugin { class MKLDNNConvertNode : public MKLDNNNode { public: MKLDNNConvertNode(const std::shared_ptr& op, const mkldnn::engine& eng, MKLDNNWeightsSharing::Ptr &cache); - MKLDNNConvertNode(const InferenceEngine::SizeVector &dims, const InferenceEngine::Precision &inPrc, const InferenceEngine::Precision &outPrc, + MKLDNNConvertNode(const Shape &shape, const InferenceEngine::Precision &inPrc, const InferenceEngine::Precision &outPrc, const std::string &nodeName, const mkldnn::engine& eng, MKLDNNWeightsSharing::Ptr &cache); void getSupportedDescriptors() override; void initSupportedPrimitiveDescriptors() override; void createPrimitive() override; void execute(mkldnn::stream strm) override; + void executeDynamicImpl(mkldnn::stream strm) override { execute(strm); } bool created() const override; bool canBeInPlace() const override { return false; @@ -38,6 +39,9 @@ public: const MemoryDesc& getInput() const { return *input; } const MemoryDesc& getOutput() const { return *output; } + std::vector shapeInfer() const override; + bool needPrepareParams() const override { return false; } + static bool isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept; static bool isSupportedDesc(const MemoryDesc &desc); diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_deconv_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_deconv_node.cpp index 3bf3a41f8e8..1cb58a478ec 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_deconv_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_deconv_node.cpp @@ -18,6 +18,7 @@ #include #include #include "memory_desc/dnnl_blocked_memory_desc.h" +#include "utils/cpu_utils.hpp" using namespace mkldnn; using namespace MKLDNNPlugin; @@ -273,7 +274,9 @@ void MKLDNNDeconvolutionNode::setPostOps(mkldnn::primitive_attr &attr) { for (auto &node : fusedWith) { auto* eltwiseNode = dynamic_cast(node.get()); if (eltwiseNode) { - eltwiseNode->appendPostOps(ops); + // TODO [DS]: change to shape from memory + constexpr int align = 16; + eltwiseNode->appendPostOps(ops, getOutputShapeAtPort(0).getStaticDims(), align); continue; } auto* fakeQuantizeNode = dynamic_cast(node.get()); diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.cpp index 2809b7c5606..2fa7c19b873 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.cpp @@ -23,6 +23,7 @@ #include "emitters/jit_bf16_emitters.hpp" #include #include "utils/general_utils.h" +#include "utils/cpu_utils.hpp" #include "ngraph/ngraph.hpp" #include @@ -1007,9 +1008,9 @@ size_t MKLDNNEltwiseNode::getOpInputsNum() const { // TODO [DS]: used only in FuseConvolutionSumAndConvolutionSumActivation // fix when reimplement this transformation for dynamic shapes bool MKLDNNEltwiseNode::isWithBroadcast() { - auto oDims = outputShapes[0].getStaticDims(); + auto oDims = getOutputShapeAtPort(0).getStaticDims(); for (size_t i = 0; i < inputShapes.size(); i++) { - auto iDims = inputShapes[i].getStaticDims(); + auto iDims = getInputShapeAtPort(i).getStaticDims(); if (iDims != oDims) return true; } @@ -1039,7 +1040,7 @@ void MKLDNNEltwiseNode::initSupportedPrimitiveDescriptors() { return; // if dim rank is greater than the maximum possible, we should use the reference execution - canUseOptimizedImpl = mayiuse(x64::sse41) && inputShapes[0].getRank() <= MAX_ELTWISE_DIM_RANK; + canUseOptimizedImpl = mayiuse(x64::sse41) && getInputShapeAtPort(0).getRank() <= MAX_ELTWISE_DIM_RANK; size_t expectedInputsNum = getOpInputsNum(); for (auto& postOp : fusedWith) { @@ -1246,10 +1247,6 @@ std::vector MKLDNNEltwiseNode::shapeInfer() const { } void MKLDNNEltwiseNode::prepareParams() { - if (!inputShapesDefined()) { - IE_THROW() << "Can't prepare params for eltwise node with name: " << getName(); - } - if (memPtrs.empty()) { for (auto i = 0; i < inputNum; i++) memPtrs.push_back(getParentEdgeAt(i)->getMemoryPtr()); @@ -1520,7 +1517,7 @@ void MKLDNNEltwiseNode::offset_in_calc(VectorDims& offset, VectorDims& dims_in, } } -void MKLDNNEltwiseNode::executeOptimized6D(const std::shared_ptr &pKernel, const jit_eltwise_call_args_ptrs &args_ptrs, +void MKLDNNEltwiseNode::executeOptimized6D(const std::unique_ptr &pKernel, const jit_eltwise_call_args_ptrs &args_ptrs, const VectorDims &dims_out) const { parallel_for5d(dims_out[0], dims_out[1], dims_out[2], dims_out[3], dims_out[4], [&](size_t i0, size_t i1, size_t i2, size_t i3, size_t i4) { @@ -1535,7 +1532,7 @@ void MKLDNNEltwiseNode::executeOptimized6D(const std::shared_ptr &pKernel, const jit_eltwise_call_args_ptrs &args_ptrs, +void MKLDNNEltwiseNode::executeOptimizedGeneric(const std::unique_ptr &pKernel, const jit_eltwise_call_args_ptrs &args_ptrs, const VectorDims &dims_out, const size_t schedulerWorkAmount) const { parallel_nt(0, [&](const int ithr, const int nthr) { size_t start = 0, end = 0; @@ -1690,19 +1687,14 @@ void MKLDNNEltwiseNode::fuseInto(MKLDNNNodePtr& parentNode) { specialConvolutionAddFusing = (parentNode->getType() == Convolution || parentNode->getType() == BinaryConvolution) && getAlgorithm() == EltwiseAdd && getInputShapeAtPort(0) == getInputShapeAtPort(1); if (!specialConvolutionAddFusing && canBePerformedAsScaleShift(parentNode.get())) { - if ((parentNode->getType() == FullyConnected) && one_of(getAlgorithm(), EltwiseAdd, EltwiseSubtract, - EltwiseMultiply, EltwiseDivide, EltwiseMulAdd, EltwisePowerStatic, EltwisePrelu)) { - fillScalesAndShifts(parentNode.get(), scales, shifts); - } else { - fillScalesAndShifts(parentNode.get(), scales, shifts, 16); - } - scalesSize = static_cast(outputShapes[0].getStaticDims()[outputShapes[0].getRank() > 1 ? 1 : 0]); + std::tie(scales, shifts) = getScalesAndShifts(parentNode.get()); } MKLDNNNode::fuseInto(parentNode); } -void MKLDNNEltwiseNode::appendPostOps(mkldnn::post_ops& ops, bool initAsBinary, bool initBinaryMemory) { +void MKLDNNEltwiseNode::appendPostOps(mkldnn::post_ops& ops, const VectorDims &postOpDims, int align, bool initAsBinary, bool initBinaryMemory) { const std::string errorPrefix = "Appending Eltwise node with name '" + getName() + "' "; + if (getMKLDNNAlgorithm() != mkldnn::algorithm::undef) { switch (getMKLDNNAlgorithm()) { case mkldnn::algorithm::eltwise_relu: @@ -1730,18 +1722,21 @@ void MKLDNNEltwiseNode::appendPostOps(mkldnn::post_ops& ops, bool initAsBinary, default: IE_THROW() << errorPrefix << "as post operation is not supported"; } } else { + const size_t chIdx = postOpDims.size() > 1 ? 1 : 0; + scalesBuffer = makeAlignedBuffer(postOpDims[chIdx], scales, align); + if (getAlgorithm() != EltwisePrelu) { + shiftsBuffer = makeAlignedBuffer(postOpDims[chIdx], shifts, align); + } + if (initAsBinary) { auto appendBinary = [&](const mkldnn::algorithm alg, MKLDNNMemoryPtr &memPtr, const std::vector &data) { if (data.empty()) IE_THROW() << errorPrefix << "cannot be performed since buffers are not allocated"; - auto outShape = outputShapes[0].getStaticDims(); - auto chIdx = outputShapes[0].getRank() > 1 ? 1 : 0; + std::vector binaryDims(postOpDims.size(), 1); + binaryDims[chIdx] = postOpDims[chIdx]; - std::vector binaryShape(outShape.size(), 1); - binaryShape[chIdx] = outShape[chIdx]; - - DnnlBlockedMemoryDesc memoryDesc(Precision::FP32, Shape(binaryShape)); + DnnlBlockedMemoryDesc memoryDesc(Precision::FP32, Shape(binaryDims)); ops.append_binary(alg, memoryDesc.getDnnlDesc()); if (initBinaryMemory) { @@ -1752,19 +1747,19 @@ void MKLDNNEltwiseNode::appendPostOps(mkldnn::post_ops& ops, bool initAsBinary, switch (getAlgorithm()) { case EltwiseAdd: case EltwiseSubtract: - appendBinary(mkldnn::algorithm::binary_add, shiftsMemory, shifts); + appendBinary(mkldnn::algorithm::binary_add, shiftsMemory, shiftsBuffer); break; case EltwiseMultiply: case EltwiseDivide: - appendBinary(mkldnn::algorithm::binary_mul, scalesMemory, scales); + appendBinary(mkldnn::algorithm::binary_mul, scalesMemory, scalesBuffer); break; case EltwiseMulAdd: case EltwisePowerStatic: - appendBinary(mkldnn::algorithm::binary_mul, scalesMemory, scales); - appendBinary(mkldnn::algorithm::binary_add, shiftsMemory, shifts); + appendBinary(mkldnn::algorithm::binary_mul, scalesMemory, scalesBuffer); + appendBinary(mkldnn::algorithm::binary_add, shiftsMemory, shiftsBuffer); break; case EltwisePrelu: - appendBinary(mkldnn::algorithm::binary_prelu, scalesMemory, scales); + appendBinary(mkldnn::algorithm::binary_prelu, scalesMemory, scalesBuffer); break; default: IE_THROW() << errorPrefix << "as post operation is not supported"; @@ -1777,14 +1772,14 @@ void MKLDNNEltwiseNode::appendPostOps(mkldnn::post_ops& ops, bool initAsBinary, case EltwiseDivide: case EltwiseMulAdd: case EltwisePowerStatic: - if (scales.empty() || shifts.empty()) + if (scalesBuffer.empty() || shiftsBuffer.empty()) IE_THROW() << errorPrefix << "cannot be performed since buffers are not allocated"; - ops.append_depthwise(mkldnn::algorithm::depthwise_scale_shift, &scales[0], &shifts[0]); + ops.append_depthwise(mkldnn::algorithm::depthwise_scale_shift, &scalesBuffer[0], &shiftsBuffer[0]); break; case EltwisePrelu: - if (scales.empty()) + if (scalesBuffer.empty()) IE_THROW() << errorPrefix << "cannot be performed since buffers are not allocated"; - ops.append_depthwise(mkldnn::algorithm::depthwise_prelu, &scales[0], nullptr); + ops.append_depthwise(mkldnn::algorithm::depthwise_prelu, &scalesBuffer[0], nullptr); break; default: IE_THROW() << errorPrefix << "as post operation is not supported"; @@ -1810,7 +1805,7 @@ bool MKLDNNEltwiseNode::canFuse(const MKLDNNNodePtr& node) const { return true; }; - if (!mayiuse(x64::sse41) || inputShapes[0].getRank() > MAX_ELTWISE_DIM_RANK) + if (!mayiuse(x64::sse41) || getInputShapeAtPort(0).getRank() > MAX_ELTWISE_DIM_RANK) return false; if (!isSuitableNode(this)) { diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.h index b5a8404cd47..f2d0f16e389 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.h +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.h @@ -75,7 +75,7 @@ public: bool created() const override; bool canBeInPlace() const override; bool canFuse(const MKLDNNNodePtr& node) const override; - void appendPostOps(mkldnn::post_ops& ops, bool initAsBinary = false, bool initBinaryMemory = false) override; + void appendPostOps(mkldnn::post_ops& ops, const VectorDims &postOpDims, int align = -1, bool initAsBinary = false, bool initBinaryMemory = false) override; void fuseInto(MKLDNNNodePtr& parentNode) override; InferenceEngine::Precision getRuntimePrecision() const override; @@ -116,7 +116,7 @@ private: void exec(const MKLDNNEltwiseNode& node, const jit_eltwise_call_args_ptrs &args_ptrs, const VectorDims &dims_out) override; const jit_eltwise_params& getJep() const override; - std::shared_ptr pKernel; + std::unique_ptr pKernel; size_t schedulerWorkAmount = 0; }; @@ -149,15 +149,16 @@ private: std::vector scales = {}; std::vector shifts = {}; - size_t scalesSize = 0; + std::vector scalesBuffer = {}; + std::vector shiftsBuffer = {}; std::vector memPtrs = {}; static std::map&, MKLDNNEltwiseNode& node)>> initializers; - void executeOptimized6D(const std::shared_ptr &pKernel, const jit_eltwise_call_args_ptrs &args_ptrs, + void executeOptimized6D(const std::unique_ptr &pKernel, const jit_eltwise_call_args_ptrs &args_ptrs, const VectorDims &dims_out) const; - void executeOptimizedGeneric(const std::shared_ptr &pKernel, const jit_eltwise_call_args_ptrs &args_ptrs, + void executeOptimizedGeneric(const std::unique_ptr &pKernel, const jit_eltwise_call_args_ptrs &args_ptrs, const VectorDims &dims_out, const size_t schedulerWorkAmount) const; void executeReference(const jit_eltwise_params &jep, const jit_eltwise_call_args_ptrs &args_ptrs, const VectorDims &dims_out, const size_t fullWorkAmount) const; diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_fake_quantize_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_fake_quantize_node.cpp index a4ddf5fbb66..481a6d5eb92 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_fake_quantize_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_fake_quantize_node.cpp @@ -22,6 +22,7 @@ #include #include "memory_desc/dnnl_blocked_memory_desc.h" #include "utils/ngraph_utils.hpp" +#include "common/cpu_memcpy.h" // Quantization ranges validation is switched off by default in order to avoid regressions on user side // #define VALIDATE_QUANTIZATION_RANGES @@ -825,23 +826,19 @@ private: bool MKLDNNFakeQuantizeNode::isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept { try { - if (isDynamicNgraphNode(op)) { - errorMessage = "Doesn't support op with dynamic shapes"; - return false; - } - const auto fq = std::dynamic_pointer_cast(op); if (!fq) { errorMessage = "Only opset1 FakeQuantize operation is supported"; return false; } - if (fq->get_input_shape(0).size() < 2 || fq->get_input_shape(0).size() > 5) { - errorMessage = "Doesn't support 'data' input with rank: " + std::to_string(fq->get_input_shape(0).size()); + const auto dataRank = fq->get_input_partial_shape(0).rank().get_length(); + if (dataRank < 2 || dataRank > 5) { + errorMessage = "Doesn't support 'data' input with rank: " + std::to_string(dataRank); return false; } for (size_t i = 1; i < fq->get_input_size(); i++) { - if (fq->get_input_shape(i).size() > 5) { - errorMessage = "Doesn't support 'range' input with rank: " + std::to_string(fq->get_input_shape(i).size()); + if (fq->get_input_partial_shape(i).rank().get_length() > 5) { + errorMessage = "Doesn't support 'range' input with rank: " + std::to_string(fq->get_input_partial_shape(i).rank().get_length()); return false; } } @@ -853,7 +850,7 @@ bool MKLDNNFakeQuantizeNode::isSupportedOperation(const std::shared_ptrget_input_size(); i++) { size_t count_not_unit_axis = 0; - auto shape = getNormalizedDimsBySize(fq->get_input_shape(i), fq->get_input_shape(0).size()); + auto shape = getNormalizedDimsBySize(fq->get_input_shape(i), dataRank); if (ngraph::shape_size(shape) != 1) { size_t not_unit_axis = 0; @@ -892,12 +889,12 @@ MKLDNNFakeQuantizeNode::MKLDNNFakeQuantizeNode(const std::shared_ptrget_input_size() != 5) - IE_THROW() << errorPrefix << "has incorrect number of input edges: " << fq->get_input_size(); - if (fq->get_output_size() != 1) - IE_THROW() << errorPrefix << "has incorrect number of output edges: " << fq->get_output_size(); + if (inputShapes.size() != 5) + IE_THROW() << errorPrefix << "has incorrect number of input edges: " << inputShapes.size(); + if (outputShapes.size() != 1) + IE_THROW() << errorPrefix << "has incorrect number of output edges: " << outputShapes.size(); - auto initAxisIdx = [&](const ngraph::Shape& inputDims) { + auto initAxisIdx = [&](const VectorDims& inputDims) { size_t axisIdx = 0; for (int i = 1; i < inputDims.size(); i++) { if (inputDims[i] > 1) { @@ -908,11 +905,11 @@ MKLDNNFakeQuantizeNode::MKLDNNFakeQuantizeNode(const std::shared_ptrget_input_shape(0).size(); - axis = dataNDims == 1 ? 0 : 1; + const size_t dataRank = getInputShapeAtPort(0).getRank(); + axis = dataRank == 1 ? 0 : 1; int axisSize = -1; - const auto ilShape = getNormalizedDimsBySize(fq->get_input_shape(1), dataNDims); + const auto ilShape = getNormalizedDimsBySize(fq->get_input_shape(1), dataRank); auto inputLowAxis = initAxisIdx(ilShape); isInputLowBroadcasted = (ngraph::is_scalar(ilShape) || ilShape[inputLowAxis] == 1); if (!isInputLowBroadcasted) { @@ -920,7 +917,7 @@ MKLDNNFakeQuantizeNode::MKLDNNFakeQuantizeNode(const std::shared_ptrget_input_shape(2), dataNDims); + const auto ihShape = getNormalizedDimsBySize(fq->get_input_shape(2), dataRank); auto inputHighAxis = initAxisIdx(ihShape); isInputHighBroadcasted = (ngraph::is_scalar(ihShape) || ihShape[inputHighAxis] == 1); if (!isInputHighBroadcasted) { @@ -928,7 +925,7 @@ MKLDNNFakeQuantizeNode::MKLDNNFakeQuantizeNode(const std::shared_ptrget_input_shape(3), dataNDims); + const auto olShape = getNormalizedDimsBySize(fq->get_input_shape(3), dataRank); auto outputLowAxis = initAxisIdx(olShape); isOutputLowBroadcasted = (ngraph::is_scalar(olShape) || olShape[outputLowAxis] == 1); if (!isOutputLowBroadcasted) { @@ -936,7 +933,7 @@ MKLDNNFakeQuantizeNode::MKLDNNFakeQuantizeNode(const std::shared_ptrget_input_shape(4), dataNDims); + const auto ohShape = getNormalizedDimsBySize(fq->get_input_shape(4), dataRank); auto outputHighAxis = initAxisIdx(ohShape); isOutputHighBroadcasted = (ngraph::is_scalar(ohShape) || ohShape[outputHighAxis] == 1); if (!isOutputHighBroadcasted) { @@ -949,11 +946,9 @@ MKLDNNFakeQuantizeNode::MKLDNNFakeQuantizeNode(const std::shared_ptr(fq->get_input_shape(0)[axis]); - size_t axisPaddedSize = static_cast(rnd_up(fq->get_input_shape(0)[axis], 16)); - - if (axisSize != -1 && axisSize != axisRealSize) + if (axisSize != -1 && !dimsEqualWeak(axisSize, getInputShapeAtPort(0).getDims()[axis])) { IE_THROW() << errorPrefix << "has different quantization axis size on 'data' and 'range' inputs"; + } const auto inputLowNode = std::dynamic_pointer_cast(fq->get_input_node_shared_ptr(1)); auto inputLowData = inputLowNode->cast_vector(); @@ -995,12 +990,24 @@ MKLDNNFakeQuantizeNode::MKLDNNFakeQuantizeNode(const std::shared_ptr &data, size_t size) { @@ -1117,13 +1124,14 @@ MKLDNNFakeQuantizeNode::MKLDNNFakeQuantizeNode(const std::shared_ptr MKLDNNFakeQuantizeNode::getDataFormats() const { // Special case for first FQ in the network - if (getInputShapeAtPort(0).getStaticDims()[getAxis()] == 3) { + const auto &dims = getInputShapeAtPort(0).getDims(); + if (dims[getAxis()] == 3) { return { LayoutType::ncsp }; } else { if (isBinarization()) { return { LayoutType::nspc }; } else { - if (one_of(getInputShapeAtPort(0).getRank(), 4, 5)) { + if (one_of(dims.size(), 4, 5)) { if (getAxis() == 1) { auto blkFormat = mayiuse(cpu::x64::avx512_common) ? LayoutType::nCsp16c : LayoutType::nCsp8c; return { blkFormat, LayoutType::nspc, LayoutType::ncsp }; @@ -1235,81 +1243,139 @@ void MKLDNNFakeQuantizeNode::initSupportedPrimitiveDescriptors() { } } -void MKLDNNFakeQuantizeNode::createPrimitive() { - auto config = getSelectedPrimitiveDescriptor()->getConfig(); - - auto inDims = config.inConfs[0].desc->getShape().getStaticDims(); - jqp.c = inDims.size() > 1 ? inDims[1] : 1; - - jqp.src_prc = config.inConfs[0].desc->getPrecision(); - jqp.wei_prc = Precision::FP32; - jqp.dst_prc = config.outConfs[0].desc->getPrecision(); - - auto srcDesc = getParentEdgeAt(0)->getMemory().GetDescWithType(); - jqp.s_str = srcDesc->getStrides(); - - auto dstDesc = getChildEdgeAt(0)->getMemory().GetDescWithType(); - jqp.d_str = dstDesc->getStrides(); - - jqp.is_planar = srcDesc->hasLayoutType(LayoutType::ncsp) && one_of(srcDesc->getShape().getRank(), 3, 4, 5); - - jqp.op_type = getAlgorithm(); - +bool MKLDNNFakeQuantizeNode::needPrepareParams() const { auto selectedPrimitiveDescriptor = getSelectedPrimitiveDescriptor(); if (!selectedPrimitiveDescriptor) IE_THROW() << "CPU quantize node with name '" << getName() << "' doesn't have primitive descriptors."; - if (selectedPrimitiveDescriptor->getImplementationType() != impl_desc_type::ref) { - if (mayiuse(cpu::x64::avx512_common)) { - if (isBinarization()) - quantize_kernel.reset(new jit_uni_binarization_kernel(jqp)); - else - quantize_kernel.reset(new jit_uni_quantization_kernel(jqp)); - } else if (mayiuse(cpu::x64::avx2)) { - if (isBinarization()) - quantize_kernel.reset(new jit_uni_binarization_kernel(jqp)); - else - quantize_kernel.reset(new jit_uni_quantization_kernel(jqp)); - } else if (mayiuse(cpu::x64::sse41)) { - if (isBinarization()) - quantize_kernel.reset(new jit_uni_binarization_kernel(jqp)); - else - quantize_kernel.reset(new jit_uni_quantization_kernel(jqp)); + if (internalBlobMemory.empty() || (selectedPrimitiveDescriptor->getImplementationType() != impl_desc_type::ref && inputShapesModified())) { + return true; + } + + const auto axisSize = getParentEdgesAtPort(0)[0]->getMemory().getStaticDims()[getAxis()]; + const auto newPaddedSize = rnd_up(axisSize, 16); + const auto currPaddedSize = rnd_up(currentAxisSize, 16); + + return newPaddedSize != currPaddedSize || (isBinarization() && (isInputLowBroadcasted || isOutputHighBroadcasted) && + axisSize != currentAxisSize); +} + +void MKLDNNFakeQuantizeNode::prepareParams() { + const size_t axisSize = getParentEdgesAtPort(0)[0]->getMemory().GetShape().getStaticDims()[getAxis()]; + const size_t newPaddedSize = rnd_up(axisSize, 16); + IE_ASSERT(newPaddedSize != 0); + + if (internalBlobMemory.empty() || newPaddedSize != rnd_up(currentAxisSize, 16) || + (isBinarization() && (isInputLowBroadcasted || isOutputHighBroadcasted) && axisSize != currentAxisSize)) { + DnnlBlockedMemoryDesc weightsDataDesc(Shape(VectorDims{newPaddedSize}), memory::data_type::f32, memory::format_tag::x); + + if (isBinarization()) { + constexpr size_t numBinFqIntBlob = 2; + bool needUpdThr = false, needUpdMask = false; + if (isInputLowBroadcasted && axisSize != currentAxisSize) { + binarizationThresholds.resize(newPaddedSize); + std::fill(binarizationThresholds.begin() + 1, binarizationThresholds.begin() + axisSize, binarizationThresholds[0]); + std::fill(binarizationThresholds.begin() + axisSize, binarizationThresholds.end(), 0); + needUpdThr = true; + } + + if (isOutputHighBroadcasted && axisSize != currentAxisSize) { + binarizationOutputMask.resize(newPaddedSize); + std::fill(binarizationOutputMask.begin() + 1, binarizationOutputMask.begin() + axisSize, binarizationOutputMask[0]); + std::fill(binarizationOutputMask.begin() + axisSize, binarizationOutputMask.end(), 0); + needUpdMask = true; + } + + if (internalBlobMemory.empty() || needUpdThr) { + auto binarizationThresholdsDataMem = std::make_shared(getEngine()); + binarizationThresholdsDataMem->Create(weightsDataDesc, getBinarizationTresholdsPtr()); + if (internalBlobMemory.empty()) { + internalBlobMemory.push_back(binarizationThresholdsDataMem); + } else { + internalBlobMemory[0] = binarizationThresholdsDataMem; + } + } + + if (internalBlobMemory.size() == (numBinFqIntBlob - 1) || needUpdMask) { + auto binarizationMaskDataMem = std::make_shared(getEngine()); + binarizationMaskDataMem->Create(weightsDataDesc, getBinarizationOutputMaskPtr()); + if (internalBlobMemory.size() == (numBinFqIntBlob - 1)) { + internalBlobMemory.push_back(binarizationMaskDataMem); + } else { + internalBlobMemory[1] = binarizationMaskDataMem; + } + } + } else if (levels != 2) { + constexpr size_t numFqIntBlob = 6; + + auto pushInternalBlob = [&](std::vector& data, size_t idx) { + auto memory = std::make_shared(getEngine()); + bool needOverwrite = getInputShapeAtPort(0).getDims()[getAxis()] == Shape::UNDEFINED_DIM && data.size() == 1; + if (needOverwrite) { + memory->Create(weightsDataDesc); + float *ptr = reinterpret_cast(memory->GetPtr()); + std::fill(ptr, ptr + newPaddedSize, data[0]); + } else { + if (data.size() == 1) { + data.resize(newPaddedSize, data[0]); + } else { + data.resize(newPaddedSize); + } + memory->Create(weightsDataDesc, &data[0]); + } + + if (internalBlobMemory.size() != numFqIntBlob) { + internalBlobMemory.push_back(memory); + } else if (needOverwrite) { + internalBlobMemory[idx] = memory; + } + }; + + pushInternalBlob(cropLow, 0); + pushInternalBlob(cropHigh, 1); + pushInternalBlob(inputScale, 2); + pushInternalBlob(inputShift, 3); + pushInternalBlob(outputScale, 4); + pushInternalBlob(outputShift, 5); + } else { + IE_THROW() << "Can't fill internal blob for FakeQuantize node with name: " << getName(); } } - if (quantize_kernel) - quantize_kernel->create_ker(); + currentAxisSize = axisSize; - size_t axisSize = getParentEdgesAtPort(0)[0]->getMemory().GetShape().getStaticDims()[getAxis()]; - size_t axisPaddedSize = rnd_up(axisSize, 16); + auto selectedPrimitiveDescriptor = getSelectedPrimitiveDescriptor(); + if (!selectedPrimitiveDescriptor) + IE_THROW() << "CPU quantize node with name '" << getName() << "' doesn't have primitive descriptors."; + if (selectedPrimitiveDescriptor->getImplementationType() != impl_desc_type::ref) { + const auto& config = getSelectedPrimitiveDescriptor()->getConfig(); - DnnlBlockedMemoryDesc weightsDataDesc(Shape(InferenceEngine::SizeVector{axisPaddedSize}), memory::data_type::f32, memory::format_tag::x); + const auto& inDims = getParentEdgesAtPort(0)[0]->getMemory().getStaticDims(); - if (isBinarization()) { - auto binarizationThresholdsDataMem = std::make_shared(getEngine()); - binarizationThresholdsDataMem->Create(weightsDataDesc, getBinarizationTresholdsPtr()); - internalBlobMemory.push_back(binarizationThresholdsDataMem); + jit_quantize_params jqp = {}; + jqp.c = inDims.size() > 1 ? inDims[1] : 1; - auto binarizationMaskDataMem = std::make_shared(getEngine()); - binarizationMaskDataMem->Create(weightsDataDesc, getBinarizationOutputMaskPtr()); - internalBlobMemory.push_back(binarizationMaskDataMem); - } else if (levels != 2) { - auto pushInternalBlob = [&](std::vector& data) { - if (data.size() == 1) - data.resize(axisPaddedSize, data[0]); - else - data.resize(axisPaddedSize); - auto memory = std::make_shared(getEngine()); - memory->Create(weightsDataDesc, &data[0]); - internalBlobMemory.push_back(memory); - }; + jqp.src_prc = config.inConfs[0].desc->getPrecision(); + jqp.wei_prc = Precision::FP32; + jqp.dst_prc = config.outConfs[0].desc->getPrecision(); - pushInternalBlob(cropLow); - pushInternalBlob(cropHigh); - pushInternalBlob(inputScale); - pushInternalBlob(inputShift); - pushInternalBlob(outputScale); - pushInternalBlob(outputShift); + auto srcDesc = getParentEdgeAt(0)->getMemory().GetDescWithType(); + jqp.s_str = srcDesc->getStrides(); + + auto dstDesc = getChildEdgeAt(0)->getMemory().GetDescWithType(); + jqp.d_str = dstDesc->getStrides(); + + jqp.is_planar = srcDesc->hasLayoutType(LayoutType::ncsp) && one_of(srcDesc->getShape().getRank(), 3, 4, 5); + + jqp.op_type = getAlgorithm(); + + execPtr = std::make_shared(jqp); + } +} + +void MKLDNNFakeQuantizeNode::createPrimitive() { + if (inputShapesDefined()) { + prepareParams(); + updateLastInputDims(); } } @@ -1322,8 +1388,8 @@ void MKLDNNFakeQuantizeNode::executeReference() { auto srcDims = srcMemory->getStaticDims(); auto dstDims = dstMemory->getStaticDims(); - auto s_str = jqp.s_str; - auto d_str = jqp.d_str; + auto s_str = srcMemory->GetDescWithType()->getStrides(); + auto d_str = dstMemory->GetDescWithType()->getStrides(); const int N = srcDims[0]; const int C = srcDims.size() > 1 ? srcDims[1] : 1; @@ -1331,7 +1397,7 @@ void MKLDNNFakeQuantizeNode::executeReference() { const int H = srcDims.size() == 3 ? srcDims[2] : srcDims.size() > 3 ? srcDims[srcDims.size() - 2] : 1; const int W = srcDims.size() > 3 ? srcDims[srcDims.size() - 1] : 1; - if (jqp.op_type == FQBinarization) { + if (isBinarization()) { size_t tmp = s_str[s_str.size() - 1]; for (int i = s_str.size() - 1; i > 1; i--) { s_str[i] = s_str[i - 1]; @@ -1430,7 +1496,7 @@ void MKLDNNFakeQuantizeNode::executeReference() { } } -void MKLDNNFakeQuantizeNode::executeBinarization() { +void MKLDNNFakeQuantizeNode::executeBinarization(const std::unique_ptr &pKernel) const { auto &srcMemory = getParentEdgeAt(0)->getMemoryPtr(); auto &dstMemory = getChildEdgeAt(0)->getMemoryPtr(); @@ -1442,6 +1508,7 @@ void MKLDNNFakeQuantizeNode::executeBinarization() { auto src_dims = srcMemory->getStaticDims(); + const auto &jqp = pKernel->jqp_; std::vector s_str = jqp.s_str; size_t tmp = s_str[s_str.size() - 1]; for (int i = s_str.size() - 1; i > 1; i--) { @@ -1465,11 +1532,11 @@ void MKLDNNFakeQuantizeNode::executeBinarization() { arg.output_mask = &output_mask[0]; arg.work_amount = (size_t)C; - (*quantize_kernel)(&arg); + (*pKernel)(&arg); }); } -void MKLDNNFakeQuantizeNode::executeQuantization() { +void MKLDNNFakeQuantizeNode::executeQuantization(const std::unique_ptr &pKernel) const { auto &srcMemory = getParentEdgeAt(0)->getMemoryPtr(); auto &dstMemory = getChildEdgeAt(0)->getMemoryPtr(); @@ -1490,6 +1557,7 @@ void MKLDNNFakeQuantizeNode::executeQuantization() { int blk_size = (srcDesc.hasLayoutType(LayoutType::ncsp) && one_of(srcDesc.getShape().getRank(), 3, 4, 5)) ? 1 : mayiuse(cpu::x64::avx512_common) ? 16 : 8; + const auto &jqp = pKernel->jqp_; auto src_type_size = jqp.src_prc.size(); auto dst_type_size = jqp.dst_prc.size(); @@ -1536,7 +1604,7 @@ void MKLDNNFakeQuantizeNode::executeQuantization() { arg.block_size = (size_t) blk_size; arg.work_amount = (size_t)H; - (*quantize_kernel)(&arg); + (*pKernel)(&arg); }); } else { parallel_nd(N, CB, D, H, [&](int n, int cb, int d, int h) { @@ -1564,7 +1632,7 @@ void MKLDNNFakeQuantizeNode::executeQuantization() { arg.block_size = (is_blk_format && srcDims.size() != 2) ? (size_t) blk_size : nstl::min(blk_size, C - c); arg.work_amount = (size_t) W; - (*quantize_kernel)(&arg); + (*pKernel)(&arg); }); } } @@ -1575,29 +1643,40 @@ void MKLDNNFakeQuantizeNode::execute(mkldnn::stream strm) { IE_THROW() << "CPU quantize node with name '" << getName() << "' doesn't have primitive descriptors."; if (selectedPrimitiveDescriptor->getImplementationType() != impl_desc_type::ref) { - if (jqp.op_type == FQBinarization) - executeBinarization(); - else - executeQuantization(); + execPtr->exec(*this); } else { executeReference(); } } -void MKLDNNFakeQuantizeNode::appendPostOps(mkldnn::post_ops& ops, bool initAsBinary, bool initBinaryMemory) { +void MKLDNNFakeQuantizeNode::appendPostOps(mkldnn::post_ops& ops, const VectorDims &postOpDims, int align, bool initAsBinary, bool initBinaryMemory) { // MKLDNN quantization_injectors assumes that quantization data memory is always aligned on 16 // by length of AVX512 vector register which is also enough for AVX2 and SSE42 implementations. // Otherwise it can lead to buffer over-read and performance penalties due to denormals. const size_t bufferAlignment = 16; if (getAlgorithm() == FQBinarization) { + const auto realAxisSize = postOpDims[postOpDims.size() > 1 ? 1 : 0]; + const auto axisPaddedSize = rnd_up(realAxisSize, bufferAlignment); if (!isPostOpDataInitialized) { - size_t paddedSize = rnd_up(binarizationThresholds.size(), bufferAlignment); - binarizationThresholds.resize(paddedSize, 0); - binarizationOutputMask.resize(paddedSize, 0); + binarizationThresholds.resize(axisPaddedSize, 0); + binarizationOutputMask.resize(axisPaddedSize, 0); + + if (isInputLowBroadcasted) { + std::fill(binarizationThresholds.begin() + 1, binarizationThresholds.begin() + realAxisSize, binarizationThresholds[0]); + std::fill(binarizationThresholds.begin() + realAxisSize, binarizationThresholds.end(), 0); + } + if (isOutputHighBroadcasted) { + std::fill(binarizationOutputMask.begin() + 1, binarizationOutputMask.begin() + realAxisSize, binarizationOutputMask[0]); + std::fill(binarizationThresholds.begin() + realAxisSize, binarizationThresholds.end(), 0); + } } ops.append_binarization(mkldnn::algorithm::binarization_depthwise, (const float*)&binarizationThresholds[0], (const float*)&binarizationOutputMask[0]); + + if (!isInputLowBroadcasted && !isOutputHighBroadcasted) { + isPostOpDataInitialized = true; + } } else { if (!isPostOpDataInitialized) { if (cropLow.size() > 1) @@ -1626,10 +1705,10 @@ void MKLDNNFakeQuantizeNode::appendPostOps(mkldnn::post_ops& ops, bool initAsBin if (initAsBinary) { auto appendBinary = [&](const mkldnn::algorithm alg, const size_t dataSize, MKLDNNMemoryPtr &memPtr, const void *data) { - auto outShape = outputShapes[0].getStaticDims(); - auto chIdx = outputShapes[0].getRank() > 1 ? 1 : 0; + const auto rank = getOutputShapeAtPort(0).getRank(); + auto chIdx = rank > 1 ? 1 : 0; - std::vector binaryShape(outShape.size(), 1); + std::vector binaryShape(rank, 1); binaryShape[chIdx] = dataSize; DnnlBlockedMemoryDesc memoryDesc(Precision::FP32, Shape(binaryShape)); @@ -1654,10 +1733,45 @@ void MKLDNNFakeQuantizeNode::appendPostOps(mkldnn::post_ops& ops, bool initAsBin } else { ops.append_quantization(alg, &cropLowData, &cropHighData, &inputScaleData, &inputShiftData, &outputScaleData, &outputShiftData); } - } - if (!isPostOpDataInitialized) isPostOpDataInitialized = true; + } +} + +MKLDNNFakeQuantizeNode::FakeQuantizeJitExecutor::FakeQuantizeJitExecutor(const jit_quantize_params &_jqp) { + bool isBinarization = _jqp.op_type == FQBinarization; + if (mayiuse(cpu::x64::avx512_common)) { + if (isBinarization) + pKernel.reset(new jit_uni_binarization_kernel(_jqp)); + else + pKernel.reset(new jit_uni_quantization_kernel(_jqp)); + } else if (mayiuse(cpu::x64::avx2)) { + if (isBinarization) + pKernel.reset(new jit_uni_binarization_kernel(_jqp)); + else + pKernel.reset(new jit_uni_quantization_kernel(_jqp)); + } else if (mayiuse(cpu::x64::sse41)) { + if (isBinarization) + pKernel.reset(new jit_uni_binarization_kernel(_jqp)); + else + pKernel.reset(new jit_uni_quantization_kernel(_jqp)); + } else { + IE_THROW() << "Can't create jit fake quantize kernel"; + } + if (pKernel) { + pKernel->create_ker(); + } +} + +void MKLDNNFakeQuantizeNode::FakeQuantizeJitExecutor::exec(const MKLDNNFakeQuantizeNode& node) { + if (!pKernel) + IE_THROW() << "Can't execute, kernel for fake quantize node is not compiled"; + + if (pKernel->jqp_.op_type == FQBinarization) { + node.executeBinarization(pKernel); + } else { + node.executeQuantization(pKernel); + } } bool MKLDNNFakeQuantizeNode::created() const { diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_fake_quantize_node.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_fake_quantize_node.h index 3316e11d41a..b97a1c1fc4f 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_fake_quantize_node.h +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_fake_quantize_node.h @@ -73,11 +73,15 @@ public: void createPrimitive() override; bool created() const override; void execute(mkldnn::stream strm) override; + void executeDynamicImpl(mkldnn::stream strm) override { execute(strm); } size_t getAxis() const { return axis; } bool isBinarization() const { return getAlgorithm() == Algorithm::FQBinarization; } + bool needPrepareParams() const override; + void prepareParams() override; + const float* getBinarizationTresholdsPtr() const { return &binarizationThresholds[0]; } const float* getBinarizationOutputMaskPtr() const { return reinterpret_cast(&binarizationOutputMask[0]); } size_t getBinarizationTresholdsSize() const { return binarizationThresholds.size(); } @@ -117,7 +121,8 @@ public: InferenceEngine::Precision getInputPrecision() const { return inputPrecision; } InferenceEngine::Precision getOutputPrecision() const { return outputPrecision; } - void appendPostOps(mkldnn::post_ops& ops, bool initAsBinary = false, bool initBinaryMemory = false) override; + void appendPostOps(mkldnn::post_ops& ops, const VectorDims &postOpDims = {}, int align = -1, bool initAsBinary = false, + bool initBinaryMemory = false) override; static bool isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept; @@ -129,11 +134,24 @@ public: MKLDNNMemoryPtr outputShiftMemory; private: + struct FakeQuantizeExecutor { + virtual void exec(const MKLDNNFakeQuantizeNode& node) = 0; + virtual ~FakeQuantizeExecutor() = default; + }; + using executorPtr = std::shared_ptr; + executorPtr execPtr = nullptr; + + struct FakeQuantizeJitExecutor : public FakeQuantizeExecutor { + FakeQuantizeJitExecutor(const jit_quantize_params &_jqp); + void exec(const MKLDNNFakeQuantizeNode& node) override; + std::unique_ptr pKernel; + }; + void init() override; std::vector getDataFormats() const; void executeReference(); - void executeBinarization(); - void executeQuantization(); + void executeBinarization(const std::unique_ptr &pKernel) const; + void executeQuantization(const std::unique_ptr &pKernel) const; size_t levels = 0; @@ -170,15 +188,12 @@ private: bool isOutputLowBroadcasted = false; bool isOutputHighBroadcasted = false; + size_t currentAxisSize = 0; size_t axis = 0; InferenceEngine::Precision inputPrecision = InferenceEngine::Precision::FP32; InferenceEngine::Precision outputPrecision = InferenceEngine::Precision::FP32; - jit_quantize_params jqp = {}; - - std::shared_ptr quantize_kernel = nullptr; - std::string errorPrefix; }; diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_fullyconnected_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_fullyconnected_node.cpp index bb46f7f8678..f188978c9b0 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_fullyconnected_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_fullyconnected_node.cpp @@ -14,6 +14,7 @@ #include "utils/general_utils.h" #include #include "memory_desc/dnnl_blocked_memory_desc.h" +#include "utils/cpu_utils.hpp" using namespace mkldnn; using namespace MKLDNNPlugin; @@ -189,7 +190,8 @@ void MKLDNNFullyConnectedNode::setPostOps(mkldnn::primitive_attr &attr, bool ini for (auto &node : fusedWith) { auto* fakeQuantizeNode = dynamic_cast(node.get()); if (fakeQuantizeNode) { - fakeQuantizeNode->appendPostOps(ops, initAsBinary, initBinaryMemory); + // no need to fill post ops dims for fq, make sense only for bin fq + fakeQuantizeNode->appendPostOps(ops, VectorDims{}, -1, initAsBinary, initBinaryMemory); if (initBinaryMemory) { if (fakeQuantizeNode->cropHighMemory) binaryPostOpsArgs.push_back(fakeQuantizeNode->cropHighMemory->GetPrimitive()); @@ -209,7 +211,9 @@ void MKLDNNFullyConnectedNode::setPostOps(mkldnn::primitive_attr &attr, bool ini auto* eltwiseNode = dynamic_cast(node.get()); if (eltwiseNode) { - eltwiseNode->appendPostOps(ops, initAsBinary, initBinaryMemory); + // TODO [DS]: change to shape from memory + constexpr int align = -1; + eltwiseNode->appendPostOps(ops, getOutputShapeAtPort(0).getStaticDims(), align, initAsBinary, initBinaryMemory); if (initBinaryMemory) { if (eltwiseNode->scalesMemory) binaryPostOpsArgs.push_back(eltwiseNode->scalesMemory->GetPrimitive()); diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_interpolate_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_interpolate_node.cpp index 4f90a6461d5..8949bf025d4 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_interpolate_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_interpolate_node.cpp @@ -25,6 +25,7 @@ #include #include +#include "utils/cpu_utils.hpp" using namespace mkldnn; using namespace MKLDNNPlugin; @@ -2394,7 +2395,9 @@ void MKLDNNInterpolateNode::setPostOps(mkldnn::primitive_attr &attr, bool initWe auto* eltwiseNode = dynamic_cast(node.get()); if (eltwiseNode) { - eltwiseNode->appendPostOps(ops); + constexpr int align = 16; + // TODO [DS]: change to shape from memory + eltwiseNode->appendPostOps(ops, getOutputShapeAtPort(0).getStaticDims(), align); continue; } diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_matmul_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_matmul_node.cpp index 4cc3e0d7021..08cd2e585d3 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_matmul_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_matmul_node.cpp @@ -24,6 +24,7 @@ #include "utils/general_utils.h" #include "memory_desc/cpu_memory_desc_utils.h" #include "mkldnn_extension_utils.h" +#include "utils/cpu_utils.hpp" using namespace mkldnn; using namespace MKLDNNPlugin; @@ -89,7 +90,8 @@ void MKLDNNMatMulNode::setPostOps(mkldnn::primitive_attr &attr, bool initWeights for (auto &node : fusedWith) { if (auto* eltwiseNode = dynamic_cast(node.get())) { - eltwiseNode->appendPostOps(ops); + // TODO [DS]: change to shape from memory + eltwiseNode->appendPostOps(ops, getOutputShapeAtPort(0).getStaticDims()); continue; } diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_mvn_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_mvn_node.cpp index f5c83167e30..eef13ed432f 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_mvn_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_mvn_node.cpp @@ -24,6 +24,7 @@ #include #include "memory_desc/dnnl_blocked_memory_desc.h" +#include "utils/cpu_utils.hpp" using namespace mkldnn; using namespace MKLDNNPlugin; @@ -604,11 +605,6 @@ private: bool MKLDNNMVNNode::isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept { try { - if (isDynamicNgraphNode(op)) { - errorMessage = "Doesn't support op with dynamic shapes"; - return false; - } - if (op->get_output_partial_shape(0).rank().is_dynamic()) { errorMessage = "Unsupported dynamic input rank."; return false; @@ -680,7 +676,6 @@ MKLDNNMVNNode::MKLDNNMVNNode(const std::shared_ptr& op, const mkld IE_THROW(NotImplemented) << errorMessage; } - const ngraph::Shape& inDataShape = op->input_value(0).get_shape(); if (auto mvnOp = ngraph::as_type_ptr(op)) { normalizeVariance_ = mvnOp->get_normalize_variance(); epsValue_ = mvnOp->get_eps(); @@ -689,27 +684,25 @@ MKLDNNMVNNode::MKLDNNMVNNode(const std::shared_ptr& op, const mkld epsMode_ = OUTSIDE_SQRT; } - acrossChannels_ = false; - const auto& inDataShapeSize = inDataShape.size(); + initAcrossChannels_ = false; + const auto& inDataShapeSize = getInputShapeAtPort(0).getRank(); if (inDataShapeSize == mvnOp->input_value(1).get_shape()[0] + 1 || inDataShapeSize == 1) - acrossChannels_ = true; + initAcrossChannels_ = true; } else if (auto mvnOp = ngraph::as_type_ptr(op)) { normalizeVariance_ = mvnOp->get_normalize_variance(); epsValue_ = mvnOp->get_eps(); epsMode_ = INSIDE_SQRT; - acrossChannels_ = mvnOp->get_across_channels(); + initAcrossChannels_ = mvnOp->get_across_channels(); } + execAcrossChannels_ = initAcrossChannels_; } -void MKLDNNMVNNode::getSupportedDescriptors() { -} +void MKLDNNMVNNode::getSupportedDescriptors() {} void MKLDNNMVNNode::initSupportedPrimitiveDescriptors() { if (!supportedPrimitiveDescriptors.empty()) return; - setPostOps(attr, true); - Precision inputPrecision = getOriginalInputPrecisionAtPort(0); Precision outputPrecision = getOriginalOutputPrecisionAtPort(0); if (!mayiuse(avx512_core)) { @@ -729,7 +722,8 @@ void MKLDNNMVNNode::initSupportedPrimitiveDescriptors() { src_data_size = inputPrecision.size(); dst_data_size = outputPrecision.size(); - bool canBeInplace = (src_data_size == dst_data_size) && + // TODO [DS]: inplace + bool canBeInplace = !isDynamicNode() && (src_data_size == dst_data_size) && (getParentEdgeAt(0)->getParent()->getChildEdges().size() == 1) && !getParentEdgeAt(0)->getParent()->isConstant(); @@ -788,7 +782,7 @@ void MKLDNNMVNNode::initSupportedPrimitiveDescriptors() { pushDesc(LayoutType::ncsp, impl_type); } -void MKLDNNMVNNode::createPrimitive() { +void MKLDNNMVNNode::prepareParams() { auto& dstMemPtr = getChildEdgeAt(0)->getMemoryPtr(); auto& srcMemPtr = getParentEdgeAt(0)->getMemoryPtr(); if (!dstMemPtr || !dstMemPtr->GetPrimitivePtr()) @@ -800,74 +794,87 @@ void MKLDNNMVNNode::createPrimitive() { const SizeVector in_dims = srcMemPtr->getStaticDims(); transformTo5DCase(in_dims); - auto selectedPD = getSelectedPrimitiveDescriptor(); - auto jcp = jit_mvn_config_params(); - jcp.src_prc = selectedPD->getConfig().inConfs[0].desc->getPrecision(); - jcp.dst_prc = selectedPD->getConfig().outConfs[0].desc->getPrecision(); - jcp.src_data_size = MKLDNNExtensionUtils::sizeOfDataType(MKLDNNExtensionUtils::IEPrecisionToDataType(jcp.src_prc)); - jcp.dst_data_size = MKLDNNExtensionUtils::sizeOfDataType(MKLDNNExtensionUtils::IEPrecisionToDataType(jcp.dst_prc)); - jcp.planar_layout = selectedPD->getConfig().inConfs[0].desc->hasLayoutType(LayoutType::ncsp); - jcp.normalize_variance = normalizeVariance_; - jcp.across_channels = acrossChannels_; - int N = 0; - std::tie(N, jcp.C, jcp.D, jcp.H, jcp.W) = shape5D; - if (mayiuse(cpu::x64::avx512_common)) { - mvn_kernel.reset(new jit_uni_mvn_kernel_f32(jcp, *attr.get())); + setPostOps(attr, true); - jcp.normalize_variance = false; - mvn_mean_kernel.reset(new jit_uni_mvn_mean_variance_kernel_f32(jcp)); - if (normalizeVariance_) { - jcp.normalize_variance = true; - mvn_variance_kernel.reset(new jit_uni_mvn_mean_variance_kernel_f32(jcp)); + if (mayiuse(cpu::x64::sse41)) { + auto selectedPD = getSelectedPrimitiveDescriptor(); + auto jcp = jit_mvn_config_params(); + jcp.src_prc = selectedPD->getConfig().inConfs[0].desc->getPrecision(); + jcp.dst_prc = selectedPD->getConfig().outConfs[0].desc->getPrecision(); + jcp.src_data_size = MKLDNNExtensionUtils::sizeOfDataType(MKLDNNExtensionUtils::IEPrecisionToDataType(jcp.src_prc)); + jcp.dst_data_size = MKLDNNExtensionUtils::sizeOfDataType(MKLDNNExtensionUtils::IEPrecisionToDataType(jcp.dst_prc)); + jcp.planar_layout = selectedPD->getConfig().inConfs[0].desc->hasLayoutType(LayoutType::ncsp); + jcp.normalize_variance = normalizeVariance_; + jcp.across_channels = execAcrossChannels_; + int N = 0; + std::tie(N, jcp.C, jcp.D, jcp.H, jcp.W) = shape5D; + + if (mayiuse(cpu::x64::avx512_common)) { + mvn_kernel.reset(new jit_uni_mvn_kernel_f32(jcp, *attr.get())); + + jcp.normalize_variance = false; + mvn_mean_kernel.reset(new jit_uni_mvn_mean_variance_kernel_f32(jcp)); + if (normalizeVariance_) { + jcp.normalize_variance = true; + mvn_variance_kernel.reset(new jit_uni_mvn_mean_variance_kernel_f32(jcp)); + } + } else if (mayiuse(cpu::x64::avx2)) { + mvn_kernel.reset(new jit_uni_mvn_kernel_f32(jcp, *attr.get())); + + jcp.normalize_variance = false; + mvn_mean_kernel.reset(new jit_uni_mvn_mean_variance_kernel_f32(jcp)); + if (normalizeVariance_) { + jcp.normalize_variance = true; + mvn_variance_kernel.reset(new jit_uni_mvn_mean_variance_kernel_f32(jcp)); + } + } else if (mayiuse(cpu::x64::sse41)) { + mvn_kernel.reset(new jit_uni_mvn_kernel_f32(jcp, *attr.get())); + + jcp.normalize_variance = false; + mvn_mean_kernel.reset(new jit_uni_mvn_mean_variance_kernel_f32(jcp)); + if (normalizeVariance_) { + jcp.normalize_variance = true; + mvn_variance_kernel.reset(new jit_uni_mvn_mean_variance_kernel_f32(jcp)); + } } - } else if (mayiuse(cpu::x64::avx2)) { - mvn_kernel.reset(new jit_uni_mvn_kernel_f32(jcp, *attr.get())); - jcp.normalize_variance = false; - mvn_mean_kernel.reset(new jit_uni_mvn_mean_variance_kernel_f32(jcp)); - if (normalizeVariance_) { - jcp.normalize_variance = true; - mvn_variance_kernel.reset(new jit_uni_mvn_mean_variance_kernel_f32(jcp)); - } - } else if (mayiuse(cpu::x64::sse41)) { - mvn_kernel.reset(new jit_uni_mvn_kernel_f32(jcp, *attr.get())); + if (mvn_kernel) + mvn_kernel->create_ker(); - jcp.normalize_variance = false; - mvn_mean_kernel.reset(new jit_uni_mvn_mean_variance_kernel_f32(jcp)); - if (normalizeVariance_) { - jcp.normalize_variance = true; - mvn_variance_kernel.reset(new jit_uni_mvn_mean_variance_kernel_f32(jcp)); + if (mvn_mean_kernel) + mvn_mean_kernel->create_ker(); + + if (mvn_variance_kernel) + mvn_variance_kernel->create_ker(); } +} + +void MKLDNNMVNNode::createPrimitive() { + if (inputShapesDefined()) { + if (needPrepareParams()) + prepareParams(); + updateLastInputDims(); } - - if (mvn_kernel) - mvn_kernel->create_ker(); - - if (mvn_mean_kernel) - mvn_mean_kernel->create_ker(); - - if (mvn_variance_kernel) - mvn_variance_kernel->create_ker(); } void MKLDNNMVNNode::transformTo5DCase(const SizeVector& shape) { switch (shape.size()) { - // for 1 and 2 rank, if acrossChannels_ is true, adjust shape to fully vectorize under unified 5d procedure. + // for 1 and 2 rank, if initAcrossChannels_ is true, adjust shape to fully vectorize under unified 5d procedure. // otherwise there are not enough data in spatial dimension to process in one kernel. case 1 : // C - if (acrossChannels_) { + if (initAcrossChannels_) { shape5D = std::make_tuple(1, 1, 1, 1, shape[0]); - acrossChannels_ = false; + execAcrossChannels_ = false; break; } else { shape5D = std::make_tuple(1, shape[0], 1, 1, 1); break; } case 2 : // NC - if (acrossChannels_) { + if (initAcrossChannels_) { shape5D = std::make_tuple(1, shape[0], 1, shape[1], 1); - acrossChannels_ = false; + execAcrossChannels_ = false; break; } else { shape5D = std::make_tuple(shape[0], shape[1], 1, 1, 1); @@ -882,6 +889,8 @@ void MKLDNNMVNNode::transformTo5DCase(const SizeVector& shape) { void MKLDNNMVNNode::setPostOps(mkldnn::primitive_attr &attr, bool initWeights) { mkldnn::post_ops ops; + VectorDims postOpDims(5); + std::tie(postOpDims[0], postOpDims[1], postOpDims[2], postOpDims[3], postOpDims[4]) = shape5D; for (auto &node : fusedWith) { auto* fakeQuantizeNode = dynamic_cast(node.get()); if (fakeQuantizeNode) { @@ -891,7 +900,8 @@ void MKLDNNMVNNode::setPostOps(mkldnn::primitive_attr &attr, bool initWeights) { auto* eltwiseNode = dynamic_cast(node.get()); if (eltwiseNode) { - eltwiseNode->appendPostOps(ops); + constexpr int align = 16; + eltwiseNode->appendPostOps(ops, postOpDims, align); continue; } IE_THROW() << "Fusing of " << NameFromType(node->getType()) << " operation to " << NameFromType(this->getType()) << " node is not implemented"; @@ -906,22 +916,21 @@ void MKLDNNMVNNode::execute(mkldnn::stream strm) { uint8_t *dst_data = reinterpret_cast(dstMemPtr->GetPtr()); uint8_t *src_data = reinterpret_cast(srcMemPtr->GetPtr()); - auto dim = srcMemPtr->getStaticDims(); if (mayiuse(cpu::x64::sse41)) { if (!mvn_mean_kernel || (normalizeVariance_ && !mvn_variance_kernel) || !mvn_kernel) { IE_THROW() << "MVN layer with name '" << getName() << "' doesn't create kernel to execute on sse41 above platform."; } if (getParentEdgeAt(0)->getMemory().getDesc().hasLayoutType(LayoutType::ncsp)) { - mvn_pln(src_data, dst_data, dim); + mvn_pln(src_data, dst_data); } else { - mvn_blk(src_data, dst_data, dim); + mvn_blk(src_data, dst_data); } } else { - mvn_ref(src_data, dst_data, dim); + mvn_ref(src_data, dst_data); } } -void MKLDNNMVNNode::mvn_pln(const uint8_t* src_data, uint8_t* dst_data, const SizeVector& dims) { +void MKLDNNMVNNode::mvn_pln(const uint8_t* src_data, uint8_t* dst_data) { size_t blk_size = 1; // blk size in vmm if (mayiuse(cpu::x64::avx512_common)) { blk_size = 16; @@ -943,7 +952,7 @@ void MKLDNNMVNNode::mvn_pln(const uint8_t* src_data, uint8_t* dst_data, const Si for (size_t b = 0lu; b < N; b++) { size_t cb = b * C3; - if (acrossChannels_) { + if (execAcrossChannels_) { // Calculate mean value for one instance in batch // Parallel sum for each channel float C3inv = 1.f / static_cast(C3); @@ -1056,7 +1065,7 @@ void MKLDNNMVNNode::mvn_pln(const uint8_t* src_data, uint8_t* dst_data, const Si } } -void MKLDNNMVNNode::mvn_ref(const uint8_t* src_data, uint8_t* dst_data, const SizeVector& dims) { +void MKLDNNMVNNode::mvn_ref(const uint8_t* src_data, uint8_t* dst_data) { const float *src_data_ptr = reinterpret_cast(src_data); float *dst_data_ptr = reinterpret_cast(dst_data); size_t N = 0; size_t C = 0; size_t D = 0; size_t H = 0; size_t W = 0; @@ -1068,7 +1077,7 @@ void MKLDNNMVNNode::mvn_ref(const uint8_t* src_data, uint8_t* dst_data, const Si for (size_t b = 0lu; b < N; b++) { size_t cb = b * C3; - if (acrossChannels_) { + if (execAcrossChannels_) { // Parallel sum for each channel for mean float C3inv = 1.f / static_cast(C3); float mean_temp = 0.0f; @@ -1154,7 +1163,7 @@ void MKLDNNMVNNode::mvn_ref(const uint8_t* src_data, uint8_t* dst_data, const Si } } -void MKLDNNMVNNode::mvn_blk(const uint8_t* src_data, uint8_t* dst_data, const SizeVector& dims) { +void MKLDNNMVNNode::mvn_blk(const uint8_t* src_data, uint8_t* dst_data) { size_t blk_size = 1; // channel blk for memory layout if (mayiuse(cpu::x64::avx512_common)) { blk_size = 16; @@ -1176,7 +1185,7 @@ void MKLDNNMVNNode::mvn_blk(const uint8_t* src_data, uint8_t* dst_data, const Si size_t C5 = C * D * H * W; size_t threads_num = parallel_get_num_threads(); - size_t aux_buffer_size = acrossChannels_ ? blk_size : rnd_up(C, blk_size); + size_t aux_buffer_size = execAcrossChannels_ ? blk_size : rnd_up(C, blk_size); std::vector mean_buffer(aux_buffer_size * threads_num); std::vector variance_buffer(aux_buffer_size * threads_num); @@ -1185,7 +1194,7 @@ void MKLDNNMVNNode::mvn_blk(const uint8_t* src_data, uint8_t* dst_data, const Si for (size_t b = 0lu; b < N; b++) { size_t b_offset = is_nhwc ? b * C5 : b * C3; - if (acrossChannels_) { + if (execAcrossChannels_) { // mean for this instance in batch float C5inv = 1.f / static_cast(C5); float mean_temp = 0.0f; @@ -1213,7 +1222,7 @@ void MKLDNNMVNNode::mvn_blk(const uint8_t* src_data, uint8_t* dst_data, const Si arg.src_stride = src_stride_size; arg.work_amount = static_cast(W); arg.oc_off = static_cast(cb * blk_size * sizeof(float)); // for tail process - (*mvn_mean_kernel)(&arg); // for W * blk + (*mvn_mean_kernel)(&arg); // for W * blk size_t min_cb = (std::min)(blk_size, C - cb * blk_size); for (int i = 0; i < min_cb; i++) @@ -1401,7 +1410,7 @@ bool MKLDNNMVNNode::canFuse(const MKLDNNNodePtr& node) const { EltwiseSwish, EltwiseHswish, EltwiseMish, EltwiseHsigmoid, EltwiseRoundHalfToEven, EltwiseRoundHalfAwayFromZero, EltwiseAbs, EltwiseSqrt, EltwiseSoftRelu); if ((inputRank == 1 && !unaryEltwise) || - (inputRank == 2 && !unaryEltwise && acrossChannels_)) { + (inputRank == 2 && !unaryEltwise && initAcrossChannels_)) { return false; } diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_mvn_node.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_mvn_node.h index dd0090c3d72..f40486a7a4f 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_mvn_node.h +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_mvn_node.h @@ -80,12 +80,13 @@ public: void createPrimitive() override; bool created() const override; void execute(mkldnn::stream strm) override; + void executeDynamicImpl(mkldnn::stream strm) override { execute(strm); } bool canBeInPlace() const override { return false; } inline bool getAcrossChannels() const { - return acrossChannels_; + return initAcrossChannels_; } inline bool getNormalizeVariance() const { @@ -94,12 +95,14 @@ public: bool canFuse(const MKLDNNNodePtr& node) const override; + void prepareParams() override; + private: - void mvn_pln(const uint8_t *src_data, uint8_t *dst_data, const InferenceEngine::SizeVector &dims); + void mvn_pln(const uint8_t *src_data, uint8_t *dst_data); - void mvn_blk(const uint8_t *src_data, uint8_t *dst_data, const InferenceEngine::SizeVector &dims); + void mvn_blk(const uint8_t *src_data, uint8_t *dst_data); - void mvn_ref(const uint8_t *src_data, uint8_t *dst_data, const InferenceEngine::SizeVector &dims); + void mvn_ref(const uint8_t *src_data, uint8_t *dst_data); void setPostOps(mkldnn::primitive_attr &attr, bool initWeights = false); @@ -107,7 +110,8 @@ private: std::tuple shape5D; - bool acrossChannels_ = false; + bool initAcrossChannels_ = false; + bool execAcrossChannels_ = false; bool normalizeVariance_ = true; float epsValue_ = 1e-9f; // Defines way to add epsilon: inside sqrt or outside. @@ -122,8 +126,6 @@ private: mkldnn::primitive_attr attr; - std::vector PostOpsIntBlobMemory; - std::shared_ptr mvn_mean_kernel; std::shared_ptr mvn_variance_kernel; std::shared_ptr mvn_kernel; diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_normalize_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_normalize_node.cpp index 0f65c38f4f4..a14a22d5243 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_normalize_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_normalize_node.cpp @@ -22,6 +22,7 @@ #include #include "memory_desc/dnnl_blocked_memory_desc.h" +#include "utils/cpu_utils.hpp" using namespace mkldnn; using namespace MKLDNNPlugin; @@ -811,7 +812,9 @@ void MKLDNNNormalizeL2Node::setPostOps(mkldnn::primitive_attr &attr, bool initWe auto* eltwiseNode = dynamic_cast(node.get()); if (eltwiseNode) { - eltwiseNode->appendPostOps(ops); + // TODO [DS]: change to shape from memory + constexpr int align = 16; + eltwiseNode->appendPostOps(ops, getOutputShapeAtPort(0).getStaticDims(), align); continue; } diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_reorder_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_reorder_node.cpp index 546f0afef67..02ccf1b546b 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_reorder_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_reorder_node.cpp @@ -102,10 +102,6 @@ void MKLDNNReorderNode::createPrimitive() { void MKLDNNReorderNode::prepareParams() { if (!isOptimized) { - if (!inputShapesDefined()) { - IE_THROW() << "Can't prepare params for eltwise node with name: " << getName(); - } - auto &srcMemPtr = getParentEdgeAt(0)->getMemoryPtr(); auto &dstMemPtr = getChildEdgeAt(0)->getMemoryPtr(); if (!dstMemPtr || !dstMemPtr->GetPrimitivePtr()) diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_select_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_select_node.cpp index 97925f3c39f..f8d9675aff4 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_select_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_select_node.cpp @@ -124,10 +124,6 @@ void MKLDNNSelectNode::initSupportedPrimitiveDescriptors() { } void MKLDNNSelectNode::prepareParams() { - if (!inputShapesDefined()) { - IE_THROW() << "Can't prepare params for eltwise node with name: " << getName(); - } - const auto &_conditionDims = getParentEdgesAtPort(CONDITION)[0]->getMemory().getStaticDims(); const auto &_thenDims = getParentEdgesAtPort(THEN)[0]->getMemory().getStaticDims(); const auto &_elseDims = getParentEdgesAtPort(ELSE)[0]->getMemory().getStaticDims(); diff --git a/inference-engine/src/mkldnn_plugin/utils/cpu_utils.hpp b/inference-engine/src/mkldnn_plugin/utils/cpu_utils.hpp index 38a4f7ac0d7..14fd043dce0 100644 --- a/inference-engine/src/mkldnn_plugin/utils/cpu_utils.hpp +++ b/inference-engine/src/mkldnn_plugin/utils/cpu_utils.hpp @@ -32,9 +32,13 @@ inline std::vector getNormalizedDimsBySize(const InferenceEngine::SizeVe * shape on which should be broadcastable * @param secondInputDims * shape which should be broadcastable +* @param weakComparison +* flag which specify how we compare C dims if value is undefined (weak or strong) * @return true if broadcastable, false otherwise. */ -inline bool isPerTensorOrPerChannelBroadcastable(const InferenceEngine::SizeVector &firstInputDims, const InferenceEngine::SizeVector& secondInputDims) { +inline bool isPerTensorOrPerChannelBroadcastable(const InferenceEngine::SizeVector &firstInputDims, const InferenceEngine::SizeVector& secondInputDims, + bool weakComparison = false) { + bool (*dimsEqual)(size_t, size_t) = weakComparison ? static_cast(dimsEqualWeak) : dimsEqualStrong; if (secondInputDims.size() > firstInputDims.size()) return false; if (std::accumulate(secondInputDims.begin(), secondInputDims.end(), 1, std::multiplies()) == 1) @@ -42,7 +46,7 @@ inline bool isPerTensorOrPerChannelBroadcastable(const InferenceEngine::SizeVect std::vector normalizedSecondInputDims = getNormalizedDimsBySize(secondInputDims, firstInputDims.size()); for (size_t i = 0; i < normalizedSecondInputDims.size(); i++) { - if ((i == 1 && normalizedSecondInputDims[i] != firstInputDims[1]) || (i != 1 && normalizedSecondInputDims[i] != 1)) + if ((i == 1 && !dimsEqual(normalizedSecondInputDims[i], firstInputDims[1])) || (i != 1 && normalizedSecondInputDims[i] != 1)) return false; } return true; @@ -90,4 +94,34 @@ inline InferenceEngine::Precision normalizeToSupportedPrecision(InferenceEngine: return precision; } +/** +* @brief Return aligned buffer by targetSize. +* If buffer has size 1, values are broadcasted with targetSize size. +* If aligned buffer size > targetSize, other values filled by zero. +* @param targetSize +* target size buffer +* @param buffer +* buffer to be aligned +* @param align +* alignment for targetSize +* @return aligned buffer +*/ +inline std::vector makeAlignedBuffer(size_t targetSize, const std::vector &buffer, int align = -1) { + if (buffer.empty()) { + IE_THROW() << "Can't align buffer, becuase buffer is empty"; + } + + auto alignedBuffer = buffer; + if (align == -1) { + align = targetSize; + } + const size_t bufferSizeAligned = rnd_up(targetSize, align); + + alignedBuffer.resize(bufferSizeAligned, 0); + if (buffer.size() == 1) { + std::fill(alignedBuffer.begin() + 1, alignedBuffer.begin() + targetSize, buffer[0]); + } + return alignedBuffer; +} + } // namespace MKLDNNPlugin diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp index bff7bb9a1e9..07f70676076 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp @@ -143,6 +143,15 @@ std::vector disabledTestPatterns() { R"(.*CanSetInBlobWithDifferentPrecision/netPRC=BIN.*)", R"(.*CanSetOutBlobWithDifferentPrecision/netPRC=(I4|U4).*)", R"(.*CanSetOutBlobWithDifferentPrecision/netPRC=BIN.*)", + + // Issue: 69086 + // need to add support convert BIN -> FP32 + // if we set output precision as BIN, when we create output blob precision looks like UNSPECIFIED + R"(.*smoke_FakeQuantizeLayerCPUTest.*bin.*)", + // Issue: 69088 + // bad accuracy + R"(.*smoke_FakeQuantizeLayerCPUTest_Decompos. + *IS=_TS=\(\(4\.5\.6\.7\)\)_RS=\(\(1\.1\.6\.1\)\)_\(\(1\.5\.6\.1\)\)_\(\(1\.1\.1\.1\)\)_\(\(1\.1\.6\.1\)\).*)", }; #define FIX_62820 0 diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/conversion.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/conversion.cpp index b41ea5a889c..8f757f34a04 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/conversion.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/conversion.cpp @@ -2,33 +2,106 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include "shared_test_classes/base/layer_test_utils.hpp" +#include "test_utils/cpu_test_utils.hpp" +#include "ngraph_functions/builders.hpp" -using namespace LayerTestsDefinitions; using namespace InferenceEngine; +using namespace ngraph; +using namespace CPUTestUtils; -namespace CPULayerTestsDefinitions { +namespace CPULayerTestsDefinitions { -class ConvertCPULayerTest : public ConversionLayerTest {}; +using convertLayerShapeDefinition = std::pair, std::vector>; + +using convertLayerTestParamsSet = std::tuple; + +class ConvertCPULayerTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon, public CPUTestsBase { +public: + static std::string getTestCaseName(testing::TestParamInfo obj) { + convertLayerShapeDefinition shapes; + InferenceEngine::Precision inPrc, outPrc; + CPUSpecificParams cpuParams; + std::tie(shapes, inPrc, outPrc, cpuParams) = obj.param; + + std::ostringstream result; + if (!shapes.first.empty()) { + result << "IS=" << CommonTestUtils::partialShape2str(shapes.first) << "_"; + } + result << "TS="; + for (const auto& shape : shapes.second) { + result << CommonTestUtils::vec2str(shape) << "_"; + } + result << "inputPRC=" << inPrc.name() << "_"; + result << "targetPRC=" << outPrc.name() << "_"; + result << CPUTestsBase::getTestCaseName(cpuParams); + + return result.str(); + } + +protected: + void SetUp() override { + targetDevice = CommonTestUtils::DEVICE_CPU; + + convertLayerShapeDefinition shapes; + InferenceEngine::Precision inPrc, outPrc; + CPUSpecificParams cpuParams; + std::tie(shapes, inPrc, outPrc, cpuParams) = GetParam(); + + std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; + + selectedType = std::string("unknown_") + (inPrc == InferenceEngine::Precision::U8 ? "I8" : inPrc.name()); + + for (size_t i = 0; i < shapes.second.size(); i++) { + targetStaticShapes.push_back(std::vector{shapes.second[i]}); + } + inputDynamicShapes = shapes.first; + + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inPrc); + auto targetPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(outPrc); + auto params = ngraph::builder::makeParams(ngPrc, {targetStaticShapes[0][0]}); + auto conversion = ngraph::builder::makeConversion(params.front(), targetPrc, helpers::ConversionTypes::CONVERT); + + function = makeNgraphFunction(ngPrc, params, conversion, "ConversionCPU"); + } +}; TEST_P(ConvertCPULayerTest, CompareWithRefs) { SKIP_IF_CURRENT_TEST_IS_DISABLED() - ConversionParamsTuple params = GetParam(); - inPrc = std::get<2>(params); - outPrc = std::get<3>(params); - Run(); + + CheckPluginRelatedResults(executableNetwork, "Convert"); } -namespace { -const std::vector conversionOpTypes = { - ngraph::helpers::ConversionTypes::CONVERT, - ngraph::helpers::ConversionTypes::CONVERT_LIKE, +std::vector inShapes_4D = { + {{}, {{1, 2, 3, 4}}}, + { + // dynamic + {{-1, -1, -1, -1}}, + // target + { + {2, 4, 4, 1}, + {2, 17, 5, 4}, + {1, 2, 3, 4} + } + }, + { + // dynamic + {{{1, 5}, {2, 22}, {2, 9}, {1, 4}}}, + // target + { + {2, 17, 5, 4}, + {5, 2, 3, 2}, + {1, 10, 4, 1}, + } + } }; -const std::vector> inShape = {{1, 2, 3, 4}}; - // List of precisions natively supported by mkldnn. const std::vector precisions = { Precision::U8, @@ -38,26 +111,19 @@ const std::vector precisions = { Precision::BF16 }; -INSTANTIATE_TEST_SUITE_P(smoke_ConversionLayerTest_From_BF16, ConvertCPULayerTest, - ::testing::Combine( - ::testing::ValuesIn(conversionOpTypes), - ::testing::Values(inShape), - ::testing::Values(Precision::BF16), - ::testing::ValuesIn(precisions), - ::testing::Values(Layout::ANY), - ::testing::Values(Layout::ANY), - ::testing::Values(CommonTestUtils::DEVICE_CPU)), - ConversionLayerTest::getTestCaseName); +std::vector memForm4D = { + CPUSpecificParams({nchw}, {nchw}, {}, {}), + CPUSpecificParams({nhwc}, {nhwc}, {}, {}), + CPUSpecificParams({nChw8c}, {nChw8c}, {}, {}), + CPUSpecificParams({nChw16c}, {nChw16c}, {}, {}) +}; -INSTANTIATE_TEST_SUITE_P(smoke_ConversionLayerTest_To_BF16, ConvertCPULayerTest, +INSTANTIATE_TEST_SUITE_P(smoke_ConvertCPULayerTest, ConvertCPULayerTest, ::testing::Combine( - ::testing::ValuesIn(conversionOpTypes), - ::testing::Values(inShape), + ::testing::ValuesIn(inShapes_4D), ::testing::ValuesIn(precisions), - ::testing::Values(Precision::BF16), - ::testing::Values(Layout::ANY), - ::testing::Values(Layout::ANY), - ::testing::Values(CommonTestUtils::DEVICE_CPU)), - ConversionLayerTest::getTestCaseName); -} // namespace -} // namespace CPULayerTestsDefinitions + ::testing::ValuesIn(precisions), + ::testing::ValuesIn(memForm4D)), + ConvertCPULayerTest::getTestCaseName); + +} // namespace CPULayerTestsDefinitions \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/fake_quantize.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/fake_quantize.cpp index 09bc5f27a62..78aa4c938b8 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/fake_quantize.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/fake_quantize.cpp @@ -12,15 +12,18 @@ using namespace CPUTestUtils; namespace CPULayerTestsDefinitions { +using inputShapes = std::tuple, // dynamic input shapes + std::vector, // target input shapes + std::vector>; // range input shapes + using fqSpecificParams = std::tuple, // output low std::vector, // output high - std::vector, // 'range' inputs shapes size_t>; // levels using fqLayerTestParamsSet = std::tuple, std::vector>, // il and ih values bool, // should be decomposed @@ -31,30 +34,39 @@ class FakeQuantizeLayerCPUTest : public testing::WithParamInterface obj) { fqSpecificParams fqParams; - SizeVector inDataShape; + inputShapes testShapes; Precision inPrec; std::pair, std::vector> inputRangesValues; bool shouldBeDecomposed; CPUSpecificParams cpuParams; - std::tie(fqParams, inDataShape, inPrec, inputRangesValues, shouldBeDecomposed, cpuParams) = obj.param; + std::tie(fqParams, testShapes, inPrec, inputRangesValues, shouldBeDecomposed, cpuParams) = obj.param; + + std::vector dynamicShapes; + std::vector targetShapes; + std::vector ranges; + std::tie(dynamicShapes, targetShapes, ranges) = testShapes; int64_t inDataLowBounds, inDataHighBounds; std::vector inputLow, inputHigh, outputLow, outputHigh; - std::vector inRangesShapes; size_t levels; inputLow = inputRangesValues.first; inputHigh = inputRangesValues.second; - std::tie(inDataLowBounds, inDataHighBounds, outputLow, outputHigh, inRangesShapes, levels) = fqParams; + std::tie(inDataLowBounds, inDataHighBounds, outputLow, outputHigh, levels) = fqParams; std::ostringstream result; - result << "IS=" << CommonTestUtils::vec2str(inDataShape) << "_"; + if (!dynamicShapes.empty()) { + result << "IS=" << CommonTestUtils::partialShape2str(dynamicShapes) << "_"; + } + result << "TS="; + for (const auto& shape : targetShapes) { + result << "(" << CommonTestUtils::vec2str(shape) << ")_"; + } + result << "RS="; + for (const auto& data : ranges) { + result << "(" << CommonTestUtils::vec2str(data) << ")_"; + } result << "inPrec=" << inPrec.name() << "_"; - std::string rs = ""; - for (size_t i = 0; i < inRangesShapes.size(); i++) { - rs += CommonTestUtils::vec2str(inRangesShapes[i]) + "_"; - } - result << "RS=" << rs; result << "LOW_BOUNDS=" << inDataLowBounds << "_"; result << "HIGH_BOUNDS=" << inDataHighBounds << "_"; result << "IL=" << CommonTestUtils::vec2str(inputLow) << "_"; @@ -75,7 +87,9 @@ public: const InputsDataMap &inDataMap = cnnNetwork.getInputsInfo(); auto input = inDataMap.begin(); - Blob::Ptr blob = FuncTestUtils::createAndFillBlob(input->second->getTensorDesc(), inDataHighBounds - inDataLowBounds, inDataLowBounds); + const auto td = input->second->getTensorDesc(); + Blob::Ptr blob = FuncTestUtils::createAndFillBlob(InferenceEngine::TensorDesc(td.getPrecision(), targetStaticShapes[index][0], td.getLayout()), + inDataHighBounds - inDataLowBounds, inDataLowBounds); inferRequest.SetBlob(input->second->name(), blob); inputs.push_back(blob); @@ -88,30 +102,37 @@ protected: void SetUp() override { targetDevice = CommonTestUtils::DEVICE_CPU; fqSpecificParams fqParams; - SizeVector inDataShape; + inputShapes testShapes; Precision inPrec; std::pair, std::vector> inputRangesValues; bool shouldBeDecomposed; CPUSpecificParams cpuParams; - std::tie(fqParams, inDataShape, inPrec, inputRangesValues, shouldBeDecomposed, cpuParams) = this->GetParam(); + std::tie(fqParams, testShapes, inPrec, inputRangesValues, shouldBeDecomposed, cpuParams) = this->GetParam(); std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; - std::vector inRangesShapes; + std::vector targetShapes; + std::vector ranges; + std::tie(inputDynamicShapes, targetShapes, ranges) = testShapes; + + for (size_t i = 0; i < targetShapes.size(); i++) { + targetStaticShapes.push_back(std::vector{targetShapes}); + } + size_t levels; std::vector> rangesBounds(RANGES_INPUT_NUMBER); rangesBounds[0] = inputRangesValues.first; rangesBounds[1] = inputRangesValues.second; - std::tie(inDataLowBounds, inDataHighBounds, rangesBounds[2], rangesBounds[3], inRangesShapes, levels) = fqParams; + std::tie(inDataLowBounds, inDataHighBounds, rangesBounds[2], rangesBounds[3], levels) = fqParams; auto ngInPrec = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inPrec); - ParameterVector params = builder::makeParams(ngInPrec, {inDataShape}); + ParameterVector params = builder::makeParams(ngInPrec, {targetStaticShapes[0][0]}); auto paramOuts = helpers::convert2OutputVector(helpers::castOps2Nodes(params)); - auto il = builder::makeConstant(ngInPrec, inRangesShapes[0], rangesBounds[0], rangesBounds[0].empty()); - auto ih = builder::makeConstant(ngInPrec, inRangesShapes[1], rangesBounds[1], rangesBounds[1].empty()); - auto ol = builder::makeConstant(ngInPrec, inRangesShapes[2], rangesBounds[2], rangesBounds[2].empty()); - auto oh = builder::makeConstant(ngInPrec, inRangesShapes[3], rangesBounds[3], rangesBounds[3].empty()); + auto il = builder::makeConstant(ngInPrec, ranges[0], rangesBounds[0], rangesBounds[0].empty()); + auto ih = builder::makeConstant(ngInPrec, ranges[1], rangesBounds[1], rangesBounds[1].empty()); + auto ol = builder::makeConstant(ngInPrec, ranges[2], rangesBounds[2], rangesBounds[2].empty()); + auto oh = builder::makeConstant(ngInPrec, ranges[3], rangesBounds[3], rangesBounds[3].empty()); auto fq = std::make_shared(paramOuts[0], il, ih, ol, oh, levels); layerName = shouldBeDecomposed ? "" : "FakeQuantize"; @@ -120,9 +141,7 @@ protected: selectedType = getPrimitiveType() + "_" + inPrec.name(); } - fq->get_rt_info() = getCPUInfo(); - - function = std::make_shared(fq, params, "FakeQuantizeCPU"); + function = makeNgraphFunction(ngInPrec, params, fq, "FakeQuantizeCPU"); } private: @@ -132,6 +151,7 @@ private: }; TEST_P(FakeQuantizeLayerCPUTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() Run(); CheckPluginRelatedResults(executableNetwork, layerName); @@ -149,6 +169,12 @@ const std::vector, std::vector>> input_range const std::vector outputLow{5.0f}, outputHigh{25.0f}; +const auto specificParams = ::testing::Combine(::testing::Values(dataLowBounds), + ::testing::Values(dataHighBounds), + ::testing::Values(outputLow), + ::testing::Values(outputHigh), + ::testing::ValuesIn(levels)); + namespace fqImpl { std::vector memForm4D_jit = { @@ -157,19 +183,31 @@ std::vector memForm4D_jit = { CPUSpecificParams({nChw16c}, {nChw16c}, {}, {}) }; -const std::vector> rangesShapes4D_jit = { - {{1, 5, 1, 1}, {1, 5, 1, 1}, {1, 5, 1, 1}, {1, 5, 1, 1}}, - {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}} +std::vector rangesShapes4D_jit = { + inputShapes{ + {}, + {{4, 5, 6, 7}}, + {{1, 5, 1, 1}, {1, 5, 1, 1}, {1, 5, 1, 1}, {1, 5, 1, 1}} + }, + inputShapes{ + {}, + {{4, 5, 6, 7}}, + {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}} + }, + inputShapes{ + {{-1, -1, -1, -1}}, + {{4, 5, 6, 7}, {1, 12, 1, 1}, {4, 1, 8, 2}, {1, 16, 6, 1}}, + {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}} + }, + inputShapes{ + {{-1, -1, -1, -1}}, + {{4, 16, 6, 7}, {1, 16, 1, 1}, {7, 16, 1, 2}, {1, 16, 6, 1}}, + {{1, 16, 1, 1}, {1, 16, 1, 1}, {1, 16, 1, 1}, {1, 16, 1, 1}} + }, }; -const auto specificParams4D_jit = ::testing::Combine(::testing::Values(dataLowBounds), - ::testing::Values(dataHighBounds), - ::testing::Values(outputLow), - ::testing::Values(outputHigh), - ::testing::ValuesIn(rangesShapes4D_jit), - ::testing::ValuesIn(levels)); -const auto testParams4D_jit = ::testing::Combine(specificParams4D_jit, - ::testing::Values(SizeVector{4, 5, 6, 7}), +const auto testParams4D_jit = ::testing::Combine(specificParams, + ::testing::ValuesIn(rangesShapes4D_jit), ::testing::Values(Precision::FP32), ::testing::ValuesIn(input_ranges), ::testing::Values(false), @@ -181,18 +219,21 @@ std::vector memForm4D_ref = { CPUSpecificParams({nchw}, {nchw}, {"ref_FP32"}, {"ref_FP32"}) }; -const std::vector> rangesShapes4D_ref = { - {{4, 1, 1, 1}, {4, 1, 1, 1}, {4, 1, 1, 1}, {4, 1, 1, 1}} +std::vector rangesShapes4D_ref = { + inputShapes{ + {}, + {{4, 5, 6, 7}}, + {{4, 1, 1, 1}, {4, 1, 1, 1}, {4, 1, 1, 1}, {4, 1, 1, 1}} + }, + inputShapes{ + {{-1, -1, -1, -1}}, + {{4, 16, 6, 7}, {4, 1, 1, 1}, {4, 16, 1, 2}, {4, 16, 6, 1}}, + {{4, 1, 1, 1}, {4, 1, 1, 1}, {4, 1, 1, 1}, {4, 1, 1, 1}} + }, }; -const auto specificParams4D_ref = ::testing::Combine(::testing::Values(dataLowBounds), - ::testing::Values(dataHighBounds), - ::testing::Values(outputLow), - ::testing::Values(outputHigh), - ::testing::ValuesIn(rangesShapes4D_ref), - ::testing::ValuesIn(levels)); -const auto testParams4D_ref = ::testing::Combine(specificParams4D_ref, - ::testing::Values(SizeVector{4, 5, 6, 7}), +const auto testParams4D_ref = ::testing::Combine(specificParams, + ::testing::ValuesIn(rangesShapes4D_ref), ::testing::Values(Precision::FP32), ::testing::ValuesIn(input_ranges), ::testing::Values(false), @@ -206,19 +247,31 @@ std::vector memForm5D_jit = { CPUSpecificParams({nCdhw16c}, {nCdhw16c}, {}, {}) }; -const std::vector> rangesShapes5D_jit = { - {{1, 4, 1, 1, 1}, {1, 4, 1, 1, 1}, {1, 4, 1, 1, 1}, {1, 4, 1, 1, 1}}, - {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}} +std::vector rangesShapes5D_jit = { + inputShapes{ + {}, + {{3, 4, 5, 6, 7}}, + {{1, 4, 1, 1, 1}, {1, 4, 1, 1, 1}, {1, 4, 1, 1, 1}, {1, 4, 1, 1, 1}} + }, + inputShapes{ + {}, + {{3, 4, 5, 6, 7}}, + {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}} + }, + inputShapes{ + {{-1, -1, -1, -1, -1}}, + {{3, 4, 5, 6, 7}, {1, 12, 1, 1, 1}, {4, 1, 8, 2, 7}, {1, 16, 6, 5, 1}}, + {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}} + }, + inputShapes{ + {{-1, -1, -1, -1, -1}}, + {{4, 16, 6, 7, 8}, {1, 16, 1, 1, 1}, {7, 16, 1, 2, 5}, {1, 16, 6, 1, 7}}, + {{1, 16, 1, 1, 1}, {1, 16, 1, 1, 1}, {1, 16, 1, 1, 1}, {1, 16, 1, 1, 1}} + }, }; -const auto specificParams5D_jit = ::testing::Combine(::testing::Values(dataLowBounds), - ::testing::Values(dataHighBounds), - ::testing::Values(outputLow), - ::testing::Values(outputHigh), - ::testing::ValuesIn(rangesShapes5D_jit), - ::testing::ValuesIn(levels)); -const auto testParams5D_jit = ::testing::Combine(specificParams5D_jit, - ::testing::Values(SizeVector{3, 4, 5, 6, 7}), +const auto testParams5D_jit = ::testing::Combine(specificParams, + ::testing::ValuesIn(rangesShapes5D_jit), ::testing::Values(Precision::FP32), ::testing::ValuesIn(input_ranges), ::testing::Values(false), @@ -231,18 +284,21 @@ std::vector memForm5D_ref = { CPUSpecificParams({ncdhw}, {ncdhw}, {"ref_FP32"}, {"ref_FP32"}) }; -const std::vector> rangesShapes5D_ref = { - {{3, 1, 1, 1, 1}, {3, 1, 1, 1, 1}, {3, 1, 1, 1, 1}, {3, 1, 1, 1, 1}} +std::vector rangesShapes5D_ref = { + inputShapes{ + {}, + {{3, 4, 5, 6, 7}}, + {{3, 1, 1, 1, 1}, {3, 1, 1, 1, 1}, {3, 1, 1, 1, 1}, {3, 1, 1, 1, 1}} + }, + inputShapes{ + {{-1, -1, -1, -1, -1}}, + {{3, 16, 6, 7, 8}, {3, 16, 1, 1, 1}, {3, 16, 1, 2, 5}, {3, 16, 6, 1, 7}}, + {{3, 1, 1, 1, 1}, {3, 1, 1, 1, 1}, {3, 1, 1, 1, 1}, {3, 1, 1, 1, 1}} + }, }; -const auto specificParams5D_ref = ::testing::Combine(::testing::Values(dataLowBounds), - ::testing::Values(dataHighBounds), - ::testing::Values(outputLow), - ::testing::Values(outputHigh), - ::testing::ValuesIn(rangesShapes5D_ref), - ::testing::ValuesIn(levels)); -const auto testParams5D_ref = ::testing::Combine(specificParams5D_ref, - ::testing::Values(SizeVector{3, 4, 5, 6, 7}), +const auto testParams5D_ref = ::testing::Combine(specificParams, + ::testing::ValuesIn(rangesShapes5D_ref), ::testing::Values(Precision::FP32), ::testing::ValuesIn(input_ranges), ::testing::Values(false), @@ -250,32 +306,115 @@ const auto testParams5D_ref = ::testing::Combine(specificParams5D_ref, INSTANTIATE_TEST_SUITE_P(smoke_FakeQuantizeLayerCPUTest_5D_ref, FakeQuantizeLayerCPUTest, testParams5D_ref, FakeQuantizeLayerCPUTest::getTestCaseName); +const auto specificParamsBin = ::testing::Combine(::testing::Values(dataLowBounds), + ::testing::Values(dataHighBounds), + ::testing::Values(std::vector{0.0f}), + ::testing::Values(std::vector{1.0f}), + ::testing::Values(2)); + +const auto testParamsBin4D = ::testing::Combine(specificParamsBin, + ::testing::ValuesIn(rangesShapes4D_jit), + ::testing::Values(Precision::FP32), + ::testing::Values(std::pair, std::vector>{{3.0f}, {3.f}}), + ::testing::Values(false), + ::testing::Values(CPUSpecificParams())); + +INSTANTIATE_TEST_SUITE_P(smoke_FakeQuantizeLayerCPUTest_4D_bin, FakeQuantizeLayerCPUTest, testParamsBin4D, FakeQuantizeLayerCPUTest::getTestCaseName); + } // namespace fqImpl -const std::vector dataShapes = { - {4, 5, 6, 7}, - {3, 4, 5, 6, 7}, - {2, 3, 4, 5, 6, 7}, -}; - -const std::vector> rangesShapes = { - {{4, 5, 6, 7}, {4, 5, 6, 7}, {4, 5, 6, 7}, {4, 5, 6, 7}}, - {{1, 5, 1, 1}, {1, 1, 6, 7}, {1, 1, 6, 7}, {1, 1, 6, 7}}, - {{1, 1, 6, 7}, {1, 1, 6, 7}, {1, 1, 6, 7}, {1, 1, 6, 7}}, - {{1, 1, 6, 7}, {1, 1, 6, 7}, {1, 1, 1, 1}, {1, 1, 1, 1}}, - {{1, 1, 6, 1}, {1, 5, 6, 7}, {1, 1, 6, 1}, {1, 1, 6, 1}} -}; - namespace fqDecompos { -const auto specificParams = ::testing::Combine(::testing::Values(dataLowBounds), - ::testing::Values(dataHighBounds), - ::testing::Values(outputLow), - ::testing::Values(outputHigh), - ::testing::ValuesIn(rangesShapes), - ::testing::ValuesIn(levels)); +std::vector decomposeShapes = { + inputShapes{ + {}, + {{4, 5, 6, 7}}, + {{4, 5, 6, 7}, {4, 5, 6, 7}, {4, 5, 6, 7}, {4, 5, 6, 7}} + }, + inputShapes{ + {}, + {{4, 5, 6, 7}}, + {{1, 5, 1, 1}, {1, 1, 6, 7}, {1, 1, 6, 7}, {1, 1, 6, 7}} + }, + inputShapes{ + {}, + {{4, 5, 6, 7}}, + {{1, 1, 6, 7}, {1, 1, 6, 7}, {1, 1, 6, 7}, {1, 1, 6, 7}} + }, + inputShapes{ + {}, + {{4, 5, 6, 7}}, + {{1, 1, 6, 7}, {1, 1, 6, 7}, {1, 1, 1, 1}, {1, 1, 1, 1}} + }, + inputShapes{ + {}, + {{4, 5, 6, 7}}, + {{1, 1, 6, 1}, {1, 5, 6, 7}, {1, 1, 6, 1}, {1, 1, 6, 1}} + }, + inputShapes{ + {}, + {{3, 4, 5, 6, 7}}, + {{4, 5, 6, 7}, {4, 5, 6, 7}, {4, 5, 6, 7}, {4, 5, 6, 7}} + }, + inputShapes{ + {}, + {{3, 4, 5, 6, 7}}, + {{1, 5, 1, 1}, {1, 1, 6, 7}, {1, 1, 6, 7}, {1, 1, 6, 7}} + }, + inputShapes{ + {}, + {{3, 4, 5, 6, 7}}, + {{1, 1, 6, 7}, {1, 1, 6, 7}, {1, 1, 6, 7}, {1, 1, 6, 7}} + }, + inputShapes{ + {}, + {{3, 4, 5, 6, 7}}, + {{1, 1, 6, 7}, {1, 1, 6, 7}, {1, 1, 1, 1}, {1, 1, 1, 1}} + }, + inputShapes{ + {}, + {{3, 4, 5, 6, 7}}, + {{1, 1, 6, 1}, {1, 5, 6, 7}, {1, 1, 6, 1}, {1, 1, 6, 1}} + }, + inputShapes{ + {}, + {{2, 3, 4, 5, 6, 7}}, + {{4, 5, 6, 7}, {4, 5, 6, 7}, {4, 5, 6, 7}, {4, 5, 6, 7}} + }, + inputShapes{ + {}, + {{2, 3, 4, 5, 6, 7}}, + {{1, 5, 1, 1}, {1, 1, 6, 7}, {1, 1, 6, 7}, {1, 1, 6, 7}} + }, + inputShapes{ + {}, + {{2, 3, 4, 5, 6, 7}}, + {{1, 1, 6, 7}, {1, 1, 6, 7}, {1, 1, 6, 7}, {1, 1, 6, 7}} + }, + inputShapes{ + {}, + {{2, 3, 4, 5, 6, 7}}, + {{1, 1, 6, 7}, {1, 1, 6, 7}, {1, 1, 1, 1}, {1, 1, 1, 1}} + }, + inputShapes{ + {}, + {{2, 3, 4, 5, 6, 7}}, + {{1, 1, 6, 1}, {1, 5, 6, 7}, {1, 1, 6, 1}, {1, 1, 6, 1}} + }, + inputShapes{ + {{-1, -1, -1, -1}}, + {{4, 5, 6, 7}, {1, 5, 6, 7}, {7, 5, 6, 7}}, + {{1, 1, 6, 1}, {1, 5, 6, 7}, {1, 1, 6, 1}, {1, 1, 6, 1}} + }, + inputShapes{ + {{-1, -1, -1, -1, -1}}, + {{8, 4, 5, 6, 7}, {1, 1, 5, 6, 7}, {1, 1, 1, 6, 7}}, + {{1, 1, 6, 7}, {1, 1, 6, 7}, {1, 1, 1, 1}, {1, 1, 1, 1}} + }, +}; + const auto testParams = ::testing::Combine(specificParams, - ::testing::ValuesIn(dataShapes), + ::testing::ValuesIn(decomposeShapes), ::testing::Values(Precision::FP32), ::testing::ValuesIn(input_ranges), ::testing::Values(true), diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/mvn.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/mvn.cpp index 9a69164baaa..10fb8ef7826 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/mvn.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/mvn.cpp @@ -12,8 +12,16 @@ using namespace CPUTestUtils; namespace CPULayerTestsDefinitions { +using basicCpuMvnParams = std::tuple< + std::pair, std::vector>, // Input shapes + InferenceEngine::Precision, // Input precision + ngraph::AxisSet, // Reduction axes + bool, // Across channels + bool, // Normalize variance + double>; // Epsilon + typedef std::tuple< - LayerTestsDefinitions::mvn1Params, + basicCpuMvnParams, CPUSpecificParams, fusingSpecificParams, Precision, // CNNNetwork input precision @@ -24,16 +32,35 @@ class MvnLayerCPUTest : public testing::WithParamInterface obj) { - LayerTestsDefinitions::mvn1Params basicParamsSet; + basicCpuMvnParams basicParamsSet; CPUSpecificParams cpuParams; fusingSpecificParams fusingParams; Precision inputPrecision, outputPrecision; std::tie(basicParamsSet, cpuParams, fusingParams, inputPrecision, outputPrecision) = obj.param; - std::ostringstream result; - result << LayerTestsDefinitions::Mvn1LayerTest::getTestCaseName(testing::TestParamInfo( - basicParamsSet, 0)); + std::pair, std::vector> inputShapes; + InferenceEngine::Precision netPrecision; + ngraph::AxisSet axes; + bool acrossChanels, normalizeVariance; + double eps; + std::tie(inputShapes, netPrecision, axes, acrossChanels, normalizeVariance, eps) = basicParamsSet; + std::ostringstream result; + if (!inputShapes.first.empty()) { + result << "IS=" << CommonTestUtils::partialShape2str(inputShapes.first) << "_"; + } + result << "TS="; + for (const auto& shape : inputShapes.second) { + result << "(" << CommonTestUtils::vec2str(shape) << ")_"; + } + result << "Precision=" << netPrecision.name() << "_"; + if (!axes.empty()) { + result << "ReductionAccess=" << CommonTestUtils::vec2str(axes.to_vector()) << "_"; + } else { + result << "AcrossChannels=" << (acrossChanels ? "TRUE" : "FALSE") << "_"; + } + result << "NormalizeVariance=" << (normalizeVariance ? "TRUE" : "FALSE") << "_"; + result << "Epsilon=" << eps; result << "_" << "CNNInpPrc=" << inputPrecision.name(); result << "_" << "CNNOutPrc=" << outputPrecision.name(); @@ -45,7 +72,9 @@ public: } protected: void SetUp() override { - LayerTestsDefinitions::mvn1Params basicParamsSet; + targetDevice = CommonTestUtils::DEVICE_CPU; + + basicCpuMvnParams basicParamsSet; CPUSpecificParams cpuParams; fusingSpecificParams fusingParams; std::tie(basicParamsSet, cpuParams, fusingParams, inPrc, outPrc) = this->GetParam(); @@ -53,14 +82,20 @@ protected: std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; std::tie(postOpMgrPtr, fusedOps) = fusingParams; - InferenceEngine::SizeVector inputShapes; + std::pair, std::vector> inputShapes; InferenceEngine::Precision netPrecision; ngraph::AxisSet axes; bool acrossChanels, normalizeVariance; double eps; - std::tie(inputShapes, netPrecision, axes, acrossChanels, normalizeVariance, eps, targetDevice) = basicParamsSet; + std::tie(inputShapes, netPrecision, axes, acrossChanels, normalizeVariance, eps) = basicParamsSet; + + for (size_t i = 0; i < inputShapes.second.size(); i++) { + targetStaticShapes.push_back({inputShapes.second[i]}); + } + inputDynamicShapes = inputShapes.first; + auto netPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - auto param = ngraph::builder::makeParams(netPrc, {inputShapes}); + auto param = ngraph::builder::makeParams(netPrc, {targetStaticShapes[0].front()}); auto paramOuts = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(param)); auto mvn = ngraph::builder::makeMVN(paramOuts[0], acrossChanels, normalizeVariance, eps); if (!axes.empty()) { @@ -82,40 +117,141 @@ TEST_P(MvnLayerCPUTest, CompareWithRefs) { } namespace { -const std::vector> inputShapes_1D = { - {5}, - {16}, + +const std::vector, std::vector>> inputShapes_1D = { + { {}, {{5}}}, + { {}, {{16}}}, + { + // dynamic + {{-1}}, + // target + { + {2}, + {16}, + {1} + } + }, + { + // dynamic + {{{1, 20}}}, + // target + { + {1}, + {16}, + {4} + } + } }; -const std::vector> inputShapes_2D = { - {1, 32}, - {16, 64}, +const std::vector, std::vector>> inputShapes_2D = { + { {}, {{1, 32}}}, + { {}, {{16, 64}}}, + { + // dynamic + {{-1, -1}}, + // target + { + {2, 16}, + {4, 16}, + {1, 16} + } + }, + { + // dynamic + {{{1, 5}, {1, 20}}}, + // target + { + {1, 1}, + {2, 16}, + {4, 16} + } + } }; -const std::vector> inputShapes_3D = { - {1, 32, 17}, - {1, 37, 9}, - {1, 16, 4}, +const std::vector, std::vector>> inputShapes_3D = { + { {}, {{1, 32, 17}}}, + { {}, {{1, 37, 9}}}, + { {}, {{1, 16, 4}}}, + { + // dynamic + {{-1, -1, -1}}, + // target + { + {2, 16, 6}, + {4, 16, 2}, + {1, 16, 4} + } + }, + { + // dynamic + {{{1, 5}, {1, 20}, {1, 7}}}, + // target + { + {1, 1, 1}, + {2, 16, 6}, + {4, 16, 2} + } + } }; -const std::vector> inputShapes_4D = { - {1, 16, 5, 8}, - {2, 19, 5, 10}, - {7, 32, 2, 8}, - {5, 8, 3, 5}, - {1, 2, 7, 5}, - {1, 4, 5, 5}, - {1, 7, 3, 5}, - {1, 15, 9, 5}, - {4, 41, 6, 9} +const std::vector, std::vector>> inputShapes_4D = { + { {}, {{1, 16, 5, 8}}}, + { {}, {{2, 19, 5, 10}}}, + { {}, {{7, 32, 2, 8}}}, + { {}, {{5, 8, 3, 5}}}, + { {}, {{1, 2, 7, 5}}}, + { {}, {{1, 4, 5, 5}}}, + { {}, {{1, 7, 3, 5}}}, + { {}, {{1, 15, 9, 5}}}, + { {}, {{4, 41, 6, 9}}}, + { + // dynamic + {{-1, -1, -1, -1}}, + // target + { + {2, 16, 10, 6}, + {4, 16, 2, 2}, + {1, 16, 8, 4} + } + }, + { + // dynamic + {{{1, 5}, {1, 20}, {1, 10}, {1, 7}}}, + // target + { + {1, 1, 1, 1}, + {2, 16, 10, 6}, + {4, 16, 2, 2} + } + } }; -const std::vector> inputShapes_5D = { - {1, 32, 8, 1, 6}, - {1, 9, 1, 15, 9}, - {6, 64, 6, 1, 18}, - {2, 31, 2, 9, 1}, - {10, 16, 5, 10, 6} +const std::vector, std::vector>> inputShapes_5D = { + { {}, {{1, 32, 8, 1, 6}}}, + { {}, {{1, 9, 1, 15, 9}}}, + { {}, {{6, 64, 6, 1, 18}}}, + { {}, {{2, 31, 2, 9, 1}}}, + { {}, {{10, 16, 5, 10, 6}}}, + { + // dynamic + {{-1, -1, -1, -1, -1}}, + // target + { + {2, 16, 5, 10, 6}, + {4, 16, 7, 2, 2}, + {1, 16, 11, 8, 4} + } + }, + { + // dynamic + {{{1, 5}, {1, 20}, {1, 7}, {1, 10}, {1, 7}}}, + // target + { + {1, 1, 1, 1, 1}, + {2, 16, 5, 10, 6}, + {4, 16, 7, 2, 2} + } + } }; const std::vector acrossChannels = { @@ -162,6 +298,7 @@ std::vector fusingParamsSet { fusingFakeQuantizePerTensorRelu, /* another patterns */ fusingScaleShift, + fusingAddPerTensor }; const auto Mvn3D = ::testing::Combine( @@ -171,8 +308,7 @@ const auto Mvn3D = ::testing::Combine( ::testing::ValuesIn(emptyReductionAxes), ::testing::ValuesIn(acrossChannels), ::testing::ValuesIn(normalizeVariance), - ::testing::ValuesIn(epsilon), - ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(epsilon)), ::testing::Values(emptyCPUSpec), ::testing::ValuesIn(fusingParamsSet), ::testing::ValuesIn(inpPrc), @@ -187,8 +323,7 @@ const auto Mvn4D = ::testing::Combine( ::testing::ValuesIn(emptyReductionAxes), ::testing::ValuesIn(acrossChannels), ::testing::ValuesIn(normalizeVariance), - ::testing::ValuesIn(epsilon), - ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(epsilon)), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D)), ::testing::ValuesIn(fusingParamsSet), ::testing::ValuesIn(inpPrc), @@ -203,8 +338,7 @@ const auto Mvn5D = ::testing::Combine( ::testing::ValuesIn(emptyReductionAxes), ::testing::ValuesIn(acrossChannels), ::testing::ValuesIn(normalizeVariance), - ::testing::ValuesIn(epsilon), - ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(epsilon)), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D)), ::testing::ValuesIn(fusingParamsSet), ::testing::ValuesIn(inpPrc), @@ -228,8 +362,7 @@ const auto Mvn1D = ::testing::Combine( ::testing::ValuesIn(emptyReductionAxes), ::testing::ValuesIn(acrossChannels), ::testing::ValuesIn(normalizeVariance), - ::testing::ValuesIn(epsilon), - ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(epsilon)), ::testing::Values(emptyCPUSpec), ::testing::ValuesIn(fusingUnaryEltwiseParamsSet), ::testing::ValuesIn(inpPrc), @@ -245,8 +378,7 @@ const auto Mvn2D = ::testing::Combine( ::testing::ValuesIn(emptyReductionAxes), ::testing::Values(false), ::testing::ValuesIn(normalizeVariance), - ::testing::ValuesIn(epsilon), - ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(epsilon)), ::testing::Values(emptyCPUSpec), ::testing::ValuesIn(fusingParamsSet), ::testing::ValuesIn(inpPrc), @@ -262,8 +394,7 @@ const auto Mvn2DTrans = ::testing::Combine( ::testing::ValuesIn(emptyReductionAxes), ::testing::Values(true), ::testing::ValuesIn(normalizeVariance), - ::testing::ValuesIn(epsilon), - ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(epsilon)), ::testing::Values(emptyCPUSpec), ::testing::ValuesIn(fusingUnaryEltwiseParamsSet), ::testing::ValuesIn(inpPrc), diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/select.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/select.cpp index 7a9a9458a08..0f552a6a974 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/select.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/select.cpp @@ -23,7 +23,9 @@ public: std::tie(shapes, broadcast) = obj.param; std::ostringstream result; - result << "IS=" << CommonTestUtils::partialShape2str(shapes.first) << "_"; + if (!shapes.first.empty()) { + result << "IS=" << CommonTestUtils::partialShape2str(shapes.first) << "_"; + } result << "TS="; for (const auto& shape : shapes.second) { result << "(";