diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/inplace_edge.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/inplace_edge.cpp index 1385313ce88..7d5c1ebb8a9 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/inplace_edge.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/inplace_edge.cpp @@ -2,16 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include "common_test_utils/node_builders/eltwise.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" #include "test_utils/cpu_test_utils.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "ov_models/builders.hpp" using namespace CPUTestUtils; -using namespace InferenceEngine; - -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { // If a node (CumSum) with constant parents has several non-constant nodes (Eltwises) than the edge is broken. // The fix is to check node type - is should be Input. // Subgraph: @@ -24,16 +21,13 @@ namespace SubgraphTestsDefinitions { * \ / \ / * \ / \ / * Eltwise Eltwise - * \ / + * \ / * Eltwise * | * Result */ -using namespace ov::test; - -class NonInputInPlaceTest : public testing::WithParamInterface, - virtual public SubgraphBaseTest { +class NonInputInPlaceTest : public testing::WithParamInterface, virtual public SubgraphBaseTest { public: static std::string getTestCaseName(testing::TestParamInfo obj) { std::ostringstream result; @@ -44,34 +38,36 @@ public: void SetUp() override { targetDevice = utils::DEVICE_CPU; configuration.insert({ov::hint::inference_precision.name(), ov::element::f16.to_string()}); - const std::vector inputShape = {1, 11, 3, 3}; + const ov::Shape inputShape = {1, 11, 3, 3}; targetStaticShapes = {{inputShape, inputShape}}; ElementType prc = this->GetParam(); - ov::ParameterVector inputParams {std::make_shared(prc, ov::Shape(inputShape)), - std::make_shared(prc, ov::Shape(inputShape))}; + ov::ParameterVector inputParams{std::make_shared(prc, ov::Shape(inputShape)), + std::make_shared(prc, ov::Shape(inputShape))}; - auto cumsum_tensor = ngraph::opset8::Constant::create(prc, inputShape, {10.0f}); - auto axis_node = ngraph::opset8::Constant::create(ngraph::element::i32, {}, {0}); + auto cumsum_tensor = ov::op::v0::Constant::create(prc, inputShape, {10.0f}); + auto axis_node = ov::op::v0::Constant::create(ov::element::i32, {}, {0}); const auto cumsum = std::make_shared(cumsum_tensor, axis_node); - auto eltwiseMul = ngraph::builder::makeEltwise(inputParams[0], cumsum, ngraph::helpers::EltwiseTypes::MULTIPLY); - auto eltwiseAdd1 = ngraph::builder::makeEltwise(inputParams[1], cumsum, ngraph::helpers::EltwiseTypes::ADD); - auto eltwiseAdd2 = ngraph::builder::makeEltwise(eltwiseAdd1, eltwiseMul, ngraph::helpers::EltwiseTypes::ADD); + auto eltwiseMul = ov::test::utils::makeEltwise(inputParams[0], cumsum, ov::test::utils::EltwiseTypes::MULTIPLY); + auto eltwiseAdd1 = ov::test::utils::makeEltwise(inputParams[1], cumsum, ov::test::utils::EltwiseTypes::ADD); + auto eltwiseAdd2 = ov::test::utils::makeEltwise(eltwiseAdd1, eltwiseMul, ov::test::utils::EltwiseTypes::ADD); - ngraph::ResultVector results{std::make_shared(eltwiseAdd2)}; - function = std::make_shared(results, inputParams, "NonInputInPlaceT"); + ov::ResultVector results{std::make_shared(eltwiseAdd2)}; + function = std::make_shared(results, inputParams, "NonInputInPlaceT"); } }; namespace { - TEST_P(NonInputInPlaceTest, CompareWithRefs) { - run(); - } +TEST_P(NonInputInPlaceTest, CompareWithRefs) { + run(); +} -INSTANTIATE_TEST_SUITE_P(smoke_NonInputInPlaceTest_CPU, NonInputInPlaceTest, - testing::Values(ngraph::element::f32, ngraph::element::f16), - NonInputInPlaceTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_NonInputInPlaceTest_CPU, + NonInputInPlaceTest, + testing::Values(ov::element::f32, ov::element::f16), + NonInputInPlaceTest::getTestCaseName); -} // namespace -} // namespace SubgraphTestsDefinitions +} // namespace +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_output_tensor_reuse.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_output_tensor_reuse.cpp index ee09a571dbd..1173eb7df3f 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_output_tensor_reuse.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_output_tensor_reuse.cpp @@ -3,11 +3,9 @@ // #include "shared_test_classes/base/ov_subgraph.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "ov_models/builders.hpp" -using namespace InferenceEngine; -using namespace ov::test; +namespace ov { +namespace test { /*This test runs the following subgraph: @@ -22,14 +20,13 @@ using namespace ov::test; Softmax | Output_1 - + Output_1 -> Param_1 The main purpose of this test is checking the code path when the output tensor is reused as an input tensor of the next infer request. */ -namespace SubgraphTestsDefinitions { class InputOutputTensorReuse : public SubgraphBaseTest { public: void SetUp() override { @@ -45,16 +42,17 @@ public: input_params[1]->set_friendly_name("Param_1"); auto first_soft_max = std::make_shared(input_params[1], softmax_axis); - auto concat = std::make_shared(ov::NodeVector{input_params[0], first_soft_max}, concat_axis); + auto concat = + std::make_shared(ov::NodeVector{input_params[0], first_soft_max}, concat_axis); auto last_soft_max = std::make_shared(concat, softmax_axis); - ngraph::ResultVector results; + ov::ResultVector results; for (size_t i = 0; i < last_soft_max->get_output_size(); i++) - results.push_back(std::make_shared(last_soft_max->output(i))); + results.push_back(std::make_shared(last_soft_max->output(i))); results.front()->set_friendly_name("Output_1"); - function = std::make_shared(results, input_params, "InputOutputTensorReuseTest"); + function = std::make_shared(results, input_params, "InputOutputTensorReuseTest"); } }; @@ -68,9 +66,11 @@ TEST_F(InputOutputTensorReuse, smoke_Input_Output_Binding) { for (size_t i = 0; i < num_iter; i++) { auto outputTensor = inferRequest.get_output_tensor(0); inputShapes.back() = outputTensor.get_shape(); - auto itr = std::find_if(inputs.begin(), inputs.end(), [](const std::pair, ov::Tensor>& item) { - return item.first->get_friendly_name() == "Param_1"; - }); + auto itr = std::find_if(inputs.begin(), + inputs.end(), + [](const std::pair, ov::Tensor>& item) { + return item.first->get_friendly_name() == "Param_1"; + }); ASSERT_NE(itr, inputs.end()); itr->second = outputTensor; const auto& expectedOutputs = calculate_refs(); @@ -91,9 +91,10 @@ TEST_F(InputOutputTensorReuse, smoke_Input_Output_Bind_Once) { auto outputTensor = inferRequest.get_output_tensor(0); inputShapes.back() = outputTensor.get_shape(); - auto itr = std::find_if(inputs.begin(), inputs.end(), [](const std::pair, ov::Tensor>& item) { - return item.first->get_friendly_name() == "Param_1"; - }); + auto itr = + std::find_if(inputs.begin(), inputs.end(), [](const std::pair, ov::Tensor>& item) { + return item.first->get_friendly_name() == "Param_1"; + }); ASSERT_NE(itr, inputs.end()); itr->second = outputTensor; @@ -107,9 +108,11 @@ TEST_F(InputOutputTensorReuse, smoke_Input_Output_Bind_Once) { inferRequest.infer(); compare(expectedOutputs, {outputTensor}); - auto itr = std::find_if(inputs.begin(), inputs.end(), [](const std::pair, ov::Tensor>& item) { - return item.first->get_friendly_name() == "Param_1"; - }); + auto itr = std::find_if(inputs.begin(), + inputs.end(), + [](const std::pair, ov::Tensor>& item) { + return item.first->get_friendly_name() == "Param_1"; + }); ASSERT_NE(itr, inputs.end()); itr->second = expectedOutputs.front(); } @@ -123,9 +126,10 @@ TEST_F(InputOutputTensorReuse, smoke_Input_Output_Bind_Once_Empty_Tensor) { auto outputTensor = inferRequest.get_output_tensor(0); inputShapes.back() = outputTensor.get_shape(); - auto itr = std::find_if(inputs.begin(), inputs.end(), [](const std::pair, ov::Tensor>& item) { - return item.first->get_friendly_name() == "Param_1"; - }); + auto itr = + std::find_if(inputs.begin(), inputs.end(), [](const std::pair, ov::Tensor>& item) { + return item.first->get_friendly_name() == "Param_1"; + }); ASSERT_NE(itr, inputs.end()); itr->second = outputTensor; @@ -139,12 +143,15 @@ TEST_F(InputOutputTensorReuse, smoke_Input_Output_Bind_Once_Empty_Tensor) { inferRequest.infer(); compare(expectedOutputs, {outputTensor}); - auto itr = std::find_if(inputs.begin(), inputs.end(), [](const std::pair, ov::Tensor>& item) { - return item.first->get_friendly_name() == "Param_1"; - }); + auto itr = std::find_if(inputs.begin(), + inputs.end(), + [](const std::pair, ov::Tensor>& item) { + return item.first->get_friendly_name() == "Param_1"; + }); ASSERT_NE(itr, inputs.end()); itr->second = expectedOutputs.front(); } } -} // namespace SubgraphTestsDefinitions \ No newline at end of file +} // namespace test +} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_tensor_roi.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_tensor_roi.cpp index 02f5c3e9b0e..32095fbbc7d 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_tensor_roi.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_tensor_roi.cpp @@ -2,16 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ov_models/builders.hpp" -#include "test_utils/cpu_test_utils.hpp" #include "functional_test_utils/ov_plugin_cache.hpp" +#include "test_utils/cpu_test_utils.hpp" -using namespace ngraph; -using namespace ngraph::op; -using namespace InferenceEngine; using namespace CPUTestUtils; -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { struct InputTensorROIParamType { ov::PartialShape shape; @@ -30,24 +27,23 @@ public: } protected: - std::shared_ptr - create_test_function(element::Type type, - const ov::PartialShape & shape, - const ov::Layout & layout) { + std::shared_ptr create_test_function(element::Type type, + const ov::PartialShape& shape, + const ov::Layout& layout) { ResultVector res; ParameterVector params; - auto param = std::make_shared(type, shape); + auto param = std::make_shared(type, shape); param->set_friendly_name("input_0"); param->get_output_tensor(0).set_names({"tensor_input_0"}); param->set_layout(layout); - auto constant = opset8::Constant::create(type, {1}, {1}); + auto constant = ov::op::v0::Constant::create(type, {1}, {1}); - auto add = std::make_shared(param, constant); + auto add = std::make_shared(param, constant); add->set_friendly_name("Add"); - auto result = std::make_shared(add); + auto result = std::make_shared(add); result->set_friendly_name("result_0"); result->get_output_tensor(0).set_names({"tensor_output_0"}); @@ -57,7 +53,7 @@ protected: return std::make_shared(res, params); } - template + template void Run() { std::shared_ptr ie = ov::test::utils::PluginCache::get().core(); @@ -70,14 +66,14 @@ protected: ov::InferRequest req = compiled_model.create_infer_request(); // Create input tensor - auto input_shape = Shape{ 1, 4, 4, 4 }; + auto input_shape = Shape{1, 4, 4, 4}; auto input_shape_size = ov::shape_size(input_shape); std::vector data(input_shape_size); std::iota(data.begin(), data.end(), 0); auto input_tensor = ov::Tensor(GetParam().type, input_shape, &data[0]); // Set ROI - auto roi = ov::Tensor(input_tensor, { 0, 1, 1, 1 }, { 1, 3, 3, 3 }); + auto roi = ov::Tensor(input_tensor, {0, 1, 1, 1}, {1, 3, 3, 3}); req.set_tensor("tensor_input_0", roi); // Infer @@ -99,24 +95,24 @@ protected: TEST_P(InputTensorROI, SetInputTensorROI) { switch (GetParam().type) { - case ov::element::Type_t::f32: { - Run(); - break; - } - case ov::element::Type_t::u8: { - Run(); - break; - } - default: - break; + case ov::element::Type_t::f32: { + Run(); + break; + } + case ov::element::Type_t::u8: { + Run(); + break; + } + default: + break; } } static InputTensorROI::ParamType InputTensorROIParams[] = { - { ov::PartialShape{ 1, 2, 2, 2 }, element::f32, "NCHW" }, - { ov::PartialShape{ 1, 2, ov::Dimension::dynamic(), ov::Dimension::dynamic() }, element::f32, "NCHW" }, - { ov::PartialShape{ 1, 2, 2, 2 }, element::u8, "NCHW" }, - { ov::PartialShape{ 1, 2, ov::Dimension::dynamic(), ov::Dimension::dynamic() }, element::u8, "NCHW" }, + {ov::PartialShape{1, 2, 2, 2}, element::f32, "NCHW"}, + {ov::PartialShape{1, 2, ov::Dimension::dynamic(), ov::Dimension::dynamic()}, element::f32, "NCHW"}, + {ov::PartialShape{1, 2, 2, 2}, element::u8, "NCHW"}, + {ov::PartialShape{1, 2, ov::Dimension::dynamic(), ov::Dimension::dynamic()}, element::u8, "NCHW"}, }; INSTANTIATE_TEST_SUITE_P(smoke_InputTensorROI, @@ -124,4 +120,5 @@ INSTANTIATE_TEST_SUITE_P(smoke_InputTensorROI, ::testing::ValuesIn(InputTensorROIParams), InputTensorROI::getTestCaseName); -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/interaction.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/interaction.cpp index 1a387437853..572c4e80706 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/interaction.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/interaction.cpp @@ -2,49 +2,37 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "shared_test_classes/base/ov_subgraph.hpp" -#include "ie_precision.hpp" -#include "test_utils/fusing_test_utils.hpp" -#include -#include -#include -#include -#include -#include -#include -#include #include "common_test_utils/common_utils.hpp" -#include -#include "functional_test_utils/skip_tests_config.hpp" +#include "common_test_utils/ov_tensor_utils.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" #include "test_utils/cpu_test_utils.hpp" using namespace CPUTestUtils; using namespace ov::test; -using namespace ov; -static std::shared_ptr createFQ(const std::shared_ptr& input) { - auto input_low = std::make_shared(element::f32, ov::Shape{1}, std::vector{0}); - auto input_high = std::make_shared(element::f32, ov::Shape{1}, std::vector{49.4914f}); - auto output_low = std::make_shared(element::f32, ov::Shape{1}, std::vector{0}); - auto output_high = std::make_shared(element::f32, ov::Shape{1}, std::vector{49.4914f}); - return std::make_shared(input, input_low, input_high, output_low, output_high, 256); +static std::shared_ptr createFQ(const std::shared_ptr& input) { + auto input_low = std::make_shared(ov::element::f32, ov::Shape{1}, std::vector{0}); + auto input_high = std::make_shared(ov::element::f32, ov::Shape{1}, std::vector{49.4914f}); + auto output_low = std::make_shared(ov::element::f32, ov::Shape{1}, std::vector{0}); + auto output_high = std::make_shared(ov::element::f32, ov::Shape{1}, std::vector{49.4914f}); + return std::make_shared(input, input_low, input_high, output_low, output_high, 256); } static std::shared_ptr makeInteraction(const ElementType inType, const ov::PartialShape& inputShape) { bool intraFQ = inType == ElementType::i8; auto paramType = intraFQ ? ElementType::f32 : inType; - std::shared_ptr input = std::make_shared(paramType, inputShape); + std::shared_ptr input = std::make_shared(paramType, inputShape); std::shared_ptr dense_feature = nullptr; if (intraFQ) { dense_feature = createFQ(input); } else { dense_feature = input; } - NodeVector features{dense_feature}; - ParameterVector inputsParams{input}; + ov::NodeVector features{dense_feature}; + ov::ParameterVector inputsParams{input}; const size_t sparse_feature_num = 26; for (size_t i = 0; i < sparse_feature_num; i++) { - auto sparse_input = std::make_shared(paramType, inputShape); + auto sparse_input = std::make_shared(paramType, inputShape); std::shared_ptr sparse_feat = nullptr; if (intraFQ) { sparse_feat = createFQ(sparse_input); @@ -55,23 +43,24 @@ static std::shared_ptr makeInteraction(const ElementType inType, cons inputsParams.push_back(sparse_input); } auto shapeof = std::make_shared(dense_feature); - auto gather_batch_indices = std::make_shared(element::i32, ov::Shape{1}, std::vector{0}); - auto gather_batch_axis = std::make_shared(element::i32, ov::Shape{}, 0); - auto gather_batch = std::make_shared(shapeof, gather_batch_indices, gather_batch_axis); + auto gather_batch_indices = std::make_shared(ov::element::i32, ov::Shape{1}, std::vector{0}); + auto gather_batch_axis = std::make_shared(ov::element::i32, ov::Shape{}, 0); + auto gather_batch = std::make_shared(shapeof, gather_batch_indices, gather_batch_axis); - auto gather_feature_indices = std::make_shared(element::i32, ov::Shape{1}, std::vector{1}); - auto gather_feature_axis = std::make_shared(element::i32, ov::Shape{1}, 0); - auto gather_feature = std::make_shared(shapeof, gather_feature_indices, gather_feature_axis); + auto gather_feature_indices = + std::make_shared(ov::element::i32, ov::Shape{1}, std::vector{1}); + auto gather_feature_axis = std::make_shared(ov::element::i32, ov::Shape{1}, 0); + auto gather_feature = std::make_shared(shapeof, gather_feature_indices, gather_feature_axis); - auto reshape_dim2 = std::make_shared(element::i64, ov::Shape{1}, std::vector{-1}); - auto reshape_shape = std::make_shared(NodeVector{gather_batch, reshape_dim2, gather_feature}, 0); + auto reshape_dim2 = std::make_shared(ov::element::i64, ov::Shape{1}, std::vector{-1}); + auto reshape_shape = std::make_shared(ov::NodeVector{gather_batch, reshape_dim2, gather_feature}, 0); - auto concat1 = std::make_shared(features, 1); - auto reshape = std::make_shared(concat1, reshape_shape, true); + auto concat1 = std::make_shared(features, 1); + auto reshape = std::make_shared(concat1, reshape_shape, true); std::vector transpose1_value = {0, 2, 1}; - auto transpose1_shape = std::make_shared(element::i32, ov::Shape{3}, transpose1_value); - auto transpose1 = std::make_shared(reshape, transpose1_shape); - auto matmul = std::make_shared(reshape, transpose1); + auto transpose1_shape = std::make_shared(ov::element::i32, ov::Shape{3}, transpose1_value); + auto transpose1 = std::make_shared(reshape, transpose1_shape); + auto matmul = std::make_shared(reshape, transpose1); std::shared_ptr inter = nullptr; if (intraFQ) { inter = createFQ(matmul); @@ -79,42 +68,42 @@ static std::shared_ptr makeInteraction(const ElementType inType, cons inter = matmul; } std::vector transpose2_value = {1, 2, 0}; - auto transpose2_shape = std::make_shared(element::i32, ov::Shape{3}, transpose2_value); - auto transpose2 = std::make_shared(inter, transpose2_shape); + auto transpose2_shape = std::make_shared(ov::element::i32, ov::Shape{3}, transpose2_value); + auto transpose2 = std::make_shared(inter, transpose2_shape); std::vector reshape2_value = {729, -1}; - auto reshape2_shape = std::make_shared(element::i32, ov::Shape{2}, reshape2_value); - auto reshape2 = std::make_shared(transpose2, reshape2_shape, true); + auto reshape2_shape = std::make_shared(ov::element::i32, ov::Shape{2}, reshape2_value); + auto reshape2 = std::make_shared(transpose2, reshape2_shape, true); std::vector gather_indices_value; for (int i = 1; i < 27; i++) { - for (int j = 0; j < i; j ++) { + for (int j = 0; j < i; j++) { gather_indices_value.push_back(i * 27 + j); } } - auto gather_indices = std::make_shared(element::i32, ov::Shape{351}, gather_indices_value); - auto gather_axis = std::make_shared(element::i32, ov::Shape{}, 0); - auto gather = std::make_shared(reshape2, gather_indices, gather_axis); - auto reshape3_dim1 = std::make_shared(element::i64, ov::Shape{1}, std::vector{-1}); - auto reshape3_shape = std::make_shared(NodeVector{reshape3_dim1, gather_batch}, 0); - auto reshape3 = std::make_shared(gather, reshape3_shape, true); + auto gather_indices = std::make_shared(ov::element::i32, ov::Shape{351}, gather_indices_value); + auto gather_axis = std::make_shared(ov::element::i32, ov::Shape{}, 0); + auto gather = std::make_shared(reshape2, gather_indices, gather_axis); + auto reshape3_dim1 = std::make_shared(ov::element::i64, ov::Shape{1}, std::vector{-1}); + auto reshape3_shape = std::make_shared(ov::NodeVector{reshape3_dim1, gather_batch}, 0); + auto reshape3 = std::make_shared(gather, reshape3_shape, true); std::vector transpose3_value = {1, 0}; - auto transpose3_shape = std::make_shared(element::i32, ov::Shape{2}, transpose3_value); - auto transpose3 = std::make_shared(reshape3, transpose3_shape); + auto transpose3_shape = std::make_shared(ov::element::i32, ov::Shape{2}, transpose3_value); + auto transpose3 = std::make_shared(reshape3, transpose3_shape); std::vector reshape4_value = {-1, 351}; - auto reshape4_shape = std::make_shared(element::i32, ov::Shape{2}, reshape4_value); - auto reshape4 = std::make_shared(transpose3, reshape4_shape, true); - auto concat2 = std::make_shared(NodeVector{dense_feature, reshape4}, 1); + auto reshape4_shape = std::make_shared(ov::element::i32, ov::Shape{2}, reshape4_value); + auto reshape4 = std::make_shared(transpose3, reshape4_shape, true); + auto concat2 = std::make_shared(ov::NodeVector{dense_feature, reshape4}, 1); std::shared_ptr model; if (intraFQ) { - auto add_const = std::make_shared(element::i8, ov::Shape{355, 1}, 3); - auto convert = std::make_shared(add_const, element::f32); - auto zp_const = std::make_shared(element::f32, ov::Shape{1}, 0); - auto scale_const = std::make_shared(element::f32, ov::Shape{1}, 1); - auto sub = std::make_shared(convert, zp_const); - auto multipy = std::make_shared(sub, scale_const); - const auto matmul = std::make_shared(concat2, multipy); + auto add_const = std::make_shared(ov::element::i8, ov::Shape{355, 1}, 3); + auto convert = std::make_shared(add_const, ov::element::f32); + auto zp_const = std::make_shared(ov::element::f32, ov::Shape{1}, 0); + auto scale_const = std::make_shared(ov::element::f32, ov::Shape{1}, 1); + auto sub = std::make_shared(convert, zp_const); + auto multipy = std::make_shared(sub, scale_const); + const auto matmul = std::make_shared(concat2, multipy); model = std::make_shared(matmul, inputsParams, "interaction"); } else { model = std::make_shared(concat2, inputsParams, "interaction"); @@ -122,7 +111,6 @@ static std::shared_ptr makeInteraction(const ElementType inType, cons return model; } -namespace CPULayerTestsDefinitions { using InteractionLayerCPUTestParams = std::tuple; class IntertactionCPUTest : public testing::WithParamInterface, @@ -146,7 +134,11 @@ public: const auto& funcInput = funcInputs[i]; ov::Tensor tensor; - tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], 15, 0, 32768); + tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), + targetInputStaticShapes[i], + 15, + 0, + 32768); inputs.insert({funcInput.get_node_shared_ptr(), tensor}); } @@ -157,7 +149,7 @@ protected: ElementType inType; InputShape inputShape; std::tie(inType, inputShape) = this->GetParam(); - bool with_bf16 = InferenceEngine::with_cpu_x86_bfloat16(); + bool with_bf16 = ov::with_cpu_x86_bfloat16(); if (with_bf16 && (inType == ov::element::bf16 || inType == ov::element::i32)) { selectedType = makeSelectedTypeStr("ref_any", ov::element::bf16); } else { @@ -166,7 +158,7 @@ protected: targetDevice = ov::test::utils::DEVICE_CPU; inputDynamicShapes.push_back(inputShape.first); const auto& targetInput = inputShape.second; - for (size_t i = 0; i < targetInput.size(); i++) { + for (size_t i = 0; i < targetInput.size(); i++) { targetStaticShapes.push_back(std::vector(27, targetInput[i])); } @@ -180,15 +172,10 @@ TEST_P(IntertactionCPUTest, CompareWithRefs) { } namespace { -const std::vector inPrecisions = { - ElementType::f32, - ElementType::bf16, - ElementType::i32, - ElementType::i8 -}; +const std::vector inPrecisions = {ElementType::f32, ElementType::bf16, ElementType::i32, ElementType::i8}; // the model has 27 inputs with same shape const std::vector input_shapes = { -// temporarily disable dynamic shape for performance issue + // temporarily disable dynamic shape for performance issue // // dynamic batch // { // {-1, 4}, @@ -200,22 +187,11 @@ const std::vector input_shapes = { // {{3, 4}, {5, 6}, {7, 8}} // }, // static shape - { - {6, 4}, - {{6, 4}} - }, - { - {3, 4}, - {{3, 4}} - } -}; + {{6, 4}, {{6, 4}}}, + {{3, 4}, {{3, 4}}}}; -INSTANTIATE_TEST_SUITE_P(smoke_Interaction, IntertactionCPUTest, - ::testing::Combine( - ::testing::ValuesIn(inPrecisions), - ::testing::ValuesIn(input_shapes)), - IntertactionCPUTest::getTestCaseName); -} // namespace - - -} // namespace CPULayerTestsDefinitions +INSTANTIATE_TEST_SUITE_P(smoke_Interaction, + IntertactionCPUTest, + ::testing::Combine(::testing::ValuesIn(inPrecisions), ::testing::ValuesIn(input_shapes)), + IntertactionCPUTest::getTestCaseName); +} // namespace diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/memory_sharing_test.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/memory_sharing_test.cpp index ccd09e50da2..e693270a807 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/memory_sharing_test.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/memory_sharing_test.cpp @@ -2,14 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "common_test_utils/node_builders/convolution.hpp" #include "openvino/openvino.hpp" -#include "test_utils/cpu_test_utils.hpp" -#include "ov_models/builders.hpp" #include "test_utils/convolution_params.hpp" +#include "test_utils/cpu_test_utils.hpp" using namespace CPUTestUtils; -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { class EdgeWithSameNameInTwoModels : public ::testing::Test, public CPUTestsBase {}; @@ -24,36 +25,52 @@ TEST_F(EdgeWithSameNameInTwoModels, smoke_CompareWithRef) { const std::vector padsBegin{0, 0}; const std::vector padsEnd{0, 0}; const std::vector dilations{1, 1}; - const ngraph::op::PadType autoPad(ngraph::op::PadType::EXPLICIT); + const ov::op::PadType autoPad(ov::op::PadType::EXPLICIT); - if (InferenceEngine::with_cpu_x86_avx512f()) { + if (ov::with_cpu_x86_avx512f()) { std::tie(inFmts, outFmts, priority, selectedType) = conv_avx512_2D; - } else if (InferenceEngine::with_cpu_x86_avx2()) { + } else if (ov::with_cpu_x86_avx2()) { std::tie(inFmts, outFmts, priority, selectedType) = conv_avx2_2D; - } else if (InferenceEngine::with_cpu_x86_sse42()) { + } else if (ov::with_cpu_x86_sse42()) { std::tie(inFmts, outFmts, priority, selectedType) = conv_sse42_2D; } // first model - const std::vector> shapes1{{1, 16, 720, 1280}}; + const std::vector shapes1{{1, 16, 720, 1280}}; ov::ParameterVector params1; for (auto&& shape : shapes1) { - params1.push_back(std::make_shared(type, ov::Shape(shape))); + params1.push_back(std::make_shared(type, shape)); } const size_t convOutCh1 = 32; - auto conv1 = ngraph::builder::makeConvolution(params1.front(), type, kernel, strides, padsBegin, padsEnd, dilations, autoPad, convOutCh1); + auto conv1 = ov::test::utils::make_convolution(params1.front(), + type, + kernel, + strides, + padsBegin, + padsEnd, + dilations, + autoPad, + convOutCh1); conv1->set_friendly_name(convName); conv1->get_input_node_shared_ptr(1)->set_friendly_name(weightName); auto model1 = makeNgraphFunction(type, params1, conv1, "Model1"); // second model - const std::vector> shapes2{{1, 32, 24, 24}}; + const std::vector shapes2{{1, 32, 24, 24}}; ov::ParameterVector params2; for (auto&& shape : shapes2) { - params2.push_back(std::make_shared(type, ov::Shape(shape))); + params2.push_back(std::make_shared(type, shape)); } const size_t convOutCh2 = 16; - auto conv2 = ngraph::builder::makeConvolution(params2.front(), type, kernel, strides, padsBegin, padsEnd, dilations, autoPad, convOutCh2); + auto conv2 = ov::test::utils::make_convolution(params2.front(), + type, + kernel, + strides, + padsBegin, + padsEnd, + dilations, + autoPad, + convOutCh2); conv2->set_friendly_name(convName); conv2->get_input_node_shared_ptr(1)->set_friendly_name(weightName); auto model2 = makeNgraphFunction(type, params2, conv2, "Model2"); @@ -78,4 +95,5 @@ TEST_F(EdgeWithSameNameInTwoModels, smoke_CompareWithRef) { inferReq2.infer(); } -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/mha.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/mha.cpp index 068585b2ca9..66bcb7baf5b 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/mha.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/mha.cpp @@ -2,49 +2,41 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include -#include -#include -#include -#include #include "common_test_utils/common_utils.hpp" -#include +#include "common_test_utils/ov_tensor_utils.hpp" #include "functional_test_utils/skip_tests_config.hpp" +#include "ov_models/builders.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" #include "test_utils/cpu_test_utils.hpp" -#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" using namespace CPUTestUtils; using namespace ov::test; -using namespace ngraph::helpers; - -namespace CPUSubgraphTestsDefinitions { using ExpectedNodes = std::vector>; -typedef std::tuple< - std::vector, // Input shapes - std::vector, // Input precisions - std::vector, // MatMul input #0 precisions - size_t, // pattern type # - ExpectedNodes, // Expected node -> count - std::string // Device name -> MHATuple; +typedef std::tuple, // Input shapes + std::vector, // Input precisions + std::vector, // MatMul input #0 precisions + size_t, // pattern type # + ExpectedNodes, // Expected node -> count + std::string // Device name + > + MHATuple; -static std::shared_ptr initMHASubgraph0(std::vector& inputDynamicShapes, std::vector& inputPrecisions) { - ngraph::ParameterVector ngraphParam; +static std::shared_ptr initMHASubgraph0(std::vector& inputDynamicShapes, + std::vector& inputPrecisions) { + ov::ParameterVector ngraphParam; - auto transpose0Param = std::make_shared(inputPrecisions[0], inputDynamicShapes[0]); + auto transpose0Param = std::make_shared(inputPrecisions[0], inputDynamicShapes[0]); ngraphParam.push_back(transpose0Param); - auto transpose1Param = std::make_shared(inputPrecisions[1], inputDynamicShapes[1]); + auto transpose1Param = std::make_shared(inputPrecisions[1], inputDynamicShapes[1]); ngraphParam.push_back(transpose1Param); - auto addParam = std::make_shared(inputPrecisions[2], inputDynamicShapes[2]); + auto addParam = std::make_shared(inputPrecisions[2], inputDynamicShapes[2]); ngraphParam.push_back(addParam); - auto transpose2Param = std::make_shared(inputPrecisions[3], inputDynamicShapes[3]); + auto transpose2Param = std::make_shared(inputPrecisions[3], inputDynamicShapes[3]); ngraphParam.push_back(transpose2Param); std::vector constantShapes; @@ -62,12 +54,13 @@ static std::shared_ptr initMHASubgraph0(std::vector std::vector transpose1ConstData = {0, 2, 3, 1}; auto transpose1Const = ngraph::builder::makeConstant(ElementType::i64, constantShapes[1], transpose1ConstData); - std::vector mulConstData(ngraph::shape_size(constantShapes[2])); + std::vector mulConstData(ov::shape_size(constantShapes[2])); auto mulConst = ngraph::builder::makeConstant(inputPrecisions[0], constantShapes[2], mulConstData, true); - std::vector reshape0ConstData = {static_cast(inputDynamicShapes[0].get_shape()[0] * - inputDynamicShapes[0].get_shape()[1] * inputDynamicShapes[0].get_shape()[2]), - -1}; + std::vector reshape0ConstData = { + static_cast(inputDynamicShapes[0].get_shape()[0] * inputDynamicShapes[0].get_shape()[1] * + inputDynamicShapes[0].get_shape()[2]), + -1}; auto reshape0Const = ngraph::builder::makeConstant(ElementType::i64, constantShapes[3], reshape0ConstData); std::vector reshape1ConstData = {static_cast(inputDynamicShapes[0].get_shape()[0]), @@ -86,33 +79,34 @@ static std::shared_ptr initMHASubgraph0(std::vector float transB = false; const auto transpose0 = std::make_shared(transpose0Param, transpose0Const); const auto transpose1 = std::make_shared(transpose1Param, transpose1Const); - const auto mul = std::make_shared(transpose1, mulConst); - const auto matMul0 = std::make_shared(transpose0, mul, transA, transB); - const auto add = std::make_shared(matMul0, addParam); - const auto reshape0 = std::make_shared(add, reshape0Const, true); - const auto softMax = std::make_shared(reshape0, 1); - const auto reshape1 = std::make_shared(softMax, reshape1Const, true); + const auto mul = std::make_shared(transpose1, mulConst); + const auto matMul0 = std::make_shared(transpose0, mul, transA, transB); + const auto add = std::make_shared(matMul0, addParam); + const auto reshape0 = std::make_shared(add, reshape0Const, true); + const auto softMax = std::make_shared(reshape0, 1); + const auto reshape1 = std::make_shared(softMax, reshape1Const, true); const auto transpose2 = std::make_shared(transpose2Param, transpose2Const); - const auto matMul1 = std::make_shared(reshape1, transpose2, transA, transB); + const auto matMul1 = std::make_shared(reshape1, transpose2, transA, transB); const auto transpose3 = std::make_shared(matMul1, transpose3Const); - ngraph::ResultVector results{std::make_shared(transpose3)}; - return std::make_shared(results, ngraphParam, "mha"); + ov::ResultVector results{std::make_shared(transpose3)}; + return std::make_shared(results, ngraphParam, "mha"); } -static std::shared_ptr initMHASubgraph1(std::vector& inputDynamicShapes, std::vector& inputPrecisions) { - ngraph::ParameterVector ngraphParam; +static std::shared_ptr initMHASubgraph1(std::vector& inputDynamicShapes, + std::vector& inputPrecisions) { + ov::ParameterVector ngraphParam; - auto transpose0Param = std::make_shared(inputPrecisions[0], inputDynamicShapes[0]); + auto transpose0Param = std::make_shared(inputPrecisions[0], inputDynamicShapes[0]); ngraphParam.push_back(transpose0Param); - auto transpose1Param = std::make_shared(inputPrecisions[1], inputDynamicShapes[1]); + auto transpose1Param = std::make_shared(inputPrecisions[1], inputDynamicShapes[1]); ngraphParam.push_back(transpose1Param); - auto addParam = std::make_shared(inputPrecisions[2], inputDynamicShapes[2]); + auto addParam = std::make_shared(inputPrecisions[2], inputDynamicShapes[2]); ngraphParam.push_back(addParam); - auto transpose2Param = std::make_shared(inputPrecisions[3], inputDynamicShapes[3]); + auto transpose2Param = std::make_shared(inputPrecisions[3], inputDynamicShapes[3]); ngraphParam.push_back(transpose2Param); std::vector constantShapes; @@ -140,21 +134,20 @@ static std::shared_ptr initMHASubgraph1(std::vector float transB = false; const auto transpose0 = std::make_shared(transpose0Param, transpose0Const); const auto transpose1 = std::make_shared(transpose1Param, transpose1Const); - const auto matMul0 = std::make_shared(transpose0, transpose1, transA, transB); - const auto add = std::make_shared(matMul0, addParam); - const auto softMax = std::make_shared(add, 3); + const auto matMul0 = std::make_shared(transpose0, transpose1, transA, transB); + const auto add = std::make_shared(matMul0, addParam); + const auto softMax = std::make_shared(add, 3); const auto transpose2 = std::make_shared(transpose2Param, transpose2Const); - const auto matMul1 = std::make_shared(softMax, transpose2, transA, transB); + const auto matMul1 = std::make_shared(softMax, transpose2, transA, transB); const auto transpose3 = std::make_shared(matMul1, transpose3Const); - ngraph::ResultVector results{std::make_shared(transpose3)}; - return std::make_shared(results, ngraphParam, "mha"); + ov::ResultVector results{std::make_shared(transpose3)}; + return std::make_shared(results, ngraphParam, "mha"); } -class MHATest : public testing::WithParamInterface, - virtual public SubgraphBaseTest, public CPUTestsBase { +class MHATest : public testing::WithParamInterface, virtual public SubgraphBaseTest, public CPUTestsBase { public: - static std::string getTestCaseName(const testing::TestParamInfo &obj) { + static std::string getTestCaseName(const testing::TestParamInfo& obj) { std::vector inputShapes; std::vector inputPrecisions; std::vector matMulIn0Precisions; @@ -180,23 +173,31 @@ public: results << "patternType=" << patternType; results << "expect="; for (const auto& node : expectedNodes) { - results << node.first << "[" << node.second << "]" << "_"; + results << node.first << "[" << node.second << "]" + << "_"; } results << "targetDevice=" << targetName; return results.str(); } - void generate_inputs(const std::vector& targetInputStaticShapes) override { + void generate_inputs(const std::vector& targetInputStaticShapes) override { inputs.clear(); const auto& funcInputs = function->inputs(); for (size_t i = 0; i < funcInputs.size(); ++i) { const auto& funcInput = funcInputs[i]; ov::Tensor tensor; if (funcInput.get_element_type() == ov::element::bf16) - tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], 2, -1, 256); + tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), + targetInputStaticShapes[i], + 2, + -1, + 256); else - tensor = ov::test::utils::create_and_fill_tensor_unique_sequence(funcInput.get_element_type(), targetInputStaticShapes[i], -1, 5); + tensor = ov::test::utils::create_and_fill_tensor_unique_sequence(funcInput.get_element_type(), + targetInputStaticShapes[i], + -1, + 5); inputs.insert({funcInput.get_node_shared_ptr(), tensor}); inputs.insert({funcInput.get_node_shared_ptr(), tensor}); } @@ -209,7 +210,8 @@ protected: std::vector inputShapes; std::vector inputPrecisions; std::vector matMulIn0Precisions; - std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = this->GetParam(); + std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = + this->GetParam(); init_input_shapes(inputShapes); @@ -227,14 +229,14 @@ protected: abs_threshold = 0.1f; rel_threshold = 10.f; - configuration.insert({{ InferenceEngine::PluginConfigParams::KEY_ENFORCE_BF16, InferenceEngine::PluginConfigParams::YES }}); + configuration.insert({ov::hint::inference_precision(ov::element::bf16)}); } - // Snippets MHA tokenization has limitations to avoid performance degradations. These limitations depend on target machine. - // Just for testing, we disable these limitations to allow Snippets to tokenize pattern on all machines for validation. - if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { - configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, - InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + // Snippets MHA tokenization has limitations to avoid performance degradations. These limitations depend on + // target machine. Just for testing, we disable these limitations to allow Snippets to tokenize pattern on all + // machines for validation. + if (!configuration.count("SNIPPETS_MODE")) { + configuration.insert({"SNIPPETS_MODE", "IGNORE_CALLBACK"}); } } }; @@ -245,12 +247,13 @@ TEST_P(MHATest, CompareWithRefs) { std::vector matMulIn0Precisions; size_t patternType; ExpectedNodes expectedNodes; - std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = this->GetParam(); + std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = + this->GetParam(); - if (inputPrecisions[0] == ElementType::bf16 && !InferenceEngine::with_cpu_x86_bfloat16()) + if (inputPrecisions[0] == ElementType::bf16 && !ov::with_cpu_x86_bfloat16()) GTEST_SKIP(); - if (!InferenceEngine::with_cpu_x86_avx512_core()) + if (!ov::with_cpu_x86_avx512_core()) GTEST_SKIP(); run(); @@ -262,61 +265,66 @@ TEST_P(MHATest, CompareWithRefs) { namespace { -std::vector> inputShapes = { +std::vector> inputShapes = { {{2, 8, 16, 64}, {2, 8, 16, 64}, {2, 1, 1, 8}, {2, 8, 16, 64}}, {{1, 384, 16, 64}, {1, 384, 16, 64}, {1, 1, 1, 384}, {1, 384, 16, 64}}, {{2, 64, 16, 80}, {2, 64, 16, 80}, {2, 1, 1, 64}, {2, 64, 16, 80}}, {{3, 96, 16, 64}, {3, 96, 16, 64}, {3, 1, 1, 96}, {3, 96, 16, 64}}, {{2, 192, 16, 160}, {2, 192, 16, 160}, {2, 1, 1, 192}, {2, 192, 16, 160}}, {{2, 4, 16, 8}, {2, 4, 16, 8}, {2, 1, 1, 4}, {2, 4, 16, 8}}, - {{1, 204, 13, 212}, {1, 204, 13, 212}, {1, 1, 1, 204}, {1, 204, 13, 212}}, + {{1, 204, 13, 212}, {1, 204, 13, 212}, {1, 1, 1, 204}, {1, 204, 13, 212}}, }; std::vector> matMulIn0Precisions = { {}, }; -std::vector patternTypes = { - 0, 1 -}; +std::vector patternTypes = {0, 1}; -INSTANTIATE_TEST_SUITE_P(smoke_MHA, MHATest, - ::testing::Combine( - ::testing::ValuesIn(static_shapes_to_test_representation(inputShapes)), - ::testing::Values(std::vector{ ElementType::f32, ElementType::f32, ElementType::f32, ElementType::f32 }), - ::testing::ValuesIn(matMulIn0Precisions), - ::testing::ValuesIn(patternTypes), - ::testing::Values(ExpectedNodes{{"Subgraph", 1}}), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MHATest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_MHA_BF16, MHATest, - ::testing::Combine( - ::testing::ValuesIn(static_shapes_to_test_representation(inputShapes)), - ::testing::Values(std::vector{ ElementType::bf16, ElementType::bf16, ElementType::bf16, ElementType::bf16 }), - ::testing::ValuesIn(matMulIn0Precisions), - ::testing::ValuesIn(patternTypes), - ::testing::Values(ExpectedNodes{{"Subgraph", 1}, - {"Transpose", 1}}), // Plugin disables tokenization of Transpose on output - ::testing::Values(ov::test::utils::DEVICE_CPU)), +INSTANTIATE_TEST_SUITE_P(smoke_MHA, + MHATest, + ::testing::Combine(::testing::ValuesIn(static_shapes_to_test_representation(inputShapes)), + ::testing::Values(std::vector{ElementType::f32, + ElementType::f32, + ElementType::f32, + ElementType::f32}), + ::testing::ValuesIn(matMulIn0Precisions), + ::testing::ValuesIn(patternTypes), + ::testing::Values(ExpectedNodes{{"Subgraph", 1}}), + ::testing::Values(ov::test::utils::DEVICE_CPU)), MHATest::getTestCaseName); -} // namespace +INSTANTIATE_TEST_SUITE_P( + smoke_MHA_BF16, + MHATest, + ::testing::Combine( + ::testing::ValuesIn(static_shapes_to_test_representation(inputShapes)), + ::testing::Values( + std::vector{ElementType::bf16, ElementType::bf16, ElementType::bf16, ElementType::bf16}), + ::testing::ValuesIn(matMulIn0Precisions), + ::testing::ValuesIn(patternTypes), + ::testing::Values(ExpectedNodes{{"Subgraph", 1}, + {"Transpose", 1}}), // Plugin disables tokenization of Transpose on output + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MHATest::getTestCaseName); -static std::shared_ptr initMHAQuantSubgraph0(std::vector& inputDynamicShapes, std::vector& inputPrecisions, +} // namespace + +static std::shared_ptr initMHAQuantSubgraph0(std::vector& inputDynamicShapes, + std::vector& inputPrecisions, std::vector& matMulIn0Precisions) { - ngraph::ParameterVector ngraphParam; + ov::ParameterVector ngraphParam; - auto transpose0Param = std::make_shared(inputPrecisions[0], inputDynamicShapes[0]); + auto transpose0Param = std::make_shared(inputPrecisions[0], inputDynamicShapes[0]); ngraphParam.push_back(transpose0Param); - auto transpose1Param = std::make_shared(inputPrecisions[1], inputDynamicShapes[1]); + auto transpose1Param = std::make_shared(inputPrecisions[1], inputDynamicShapes[1]); ngraphParam.push_back(transpose1Param); - auto addParam = std::make_shared(inputPrecisions[2], inputDynamicShapes[2]); + auto addParam = std::make_shared(inputPrecisions[2], inputDynamicShapes[2]); ngraphParam.push_back(addParam); - auto transpose2Param = std::make_shared(inputPrecisions[3], inputDynamicShapes[3]); + auto transpose2Param = std::make_shared(inputPrecisions[3], inputDynamicShapes[3]); ngraphParam.push_back(transpose2Param); std::vector constantShapes; @@ -333,9 +341,10 @@ static std::shared_ptr initMHAQuantSubgraph0(std::vector transpose1ConstData = {0, 2, 3, 1}; auto transpose1Const = ngraph::builder::makeConstant(ElementType::i64, constantShapes[1], transpose1ConstData); - std::vector reshape0ConstData = {static_cast(inputDynamicShapes[0].get_shape()[0] * - inputDynamicShapes[0].get_shape()[1] * inputDynamicShapes[0].get_shape()[2]), - -1}; + std::vector reshape0ConstData = { + static_cast(inputDynamicShapes[0].get_shape()[0] * inputDynamicShapes[0].get_shape()[1] * + inputDynamicShapes[0].get_shape()[2]), + -1}; auto reshape0Const = ngraph::builder::makeConstant(ElementType::i64, constantShapes[2], reshape0ConstData); std::vector reshape1ConstData = {static_cast(inputDynamicShapes[0].get_shape()[0]), @@ -355,52 +364,96 @@ static std::shared_ptr initMHAQuantSubgraph0(std::vector fakeQuantize0; if (matMulIn0Precisions[0] == ElementType::u8) - fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, inputPrecisions[0], 256, {}, {0.0f}, {2.55f}, {0.0f}, {2.55f}); + fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, + inputPrecisions[0], + 256, + {}, + {0.0f}, + {2.55f}, + {0.0f}, + {2.55f}); else - fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, inputPrecisions[0], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); + fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, + inputPrecisions[0], + 256, + {}, + {-1.28f}, + {1.27f}, + {-1.28f}, + {1.27f}); - const auto fakeQuantize1 = ngraph::builder::makeFakeQuantize(transpose1Param, inputPrecisions[1], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); - const auto fakeQuantize2 = ngraph::builder::makeFakeQuantize(transpose2Param, inputPrecisions[3], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); + const auto fakeQuantize1 = ngraph::builder::makeFakeQuantize(transpose1Param, + inputPrecisions[1], + 256, + {}, + {-1.28f}, + {1.27f}, + {-1.28f}, + {1.27f}); + const auto fakeQuantize2 = ngraph::builder::makeFakeQuantize(transpose2Param, + inputPrecisions[3], + 256, + {}, + {-1.28f}, + {1.27f}, + {-1.28f}, + {1.27f}); std::shared_ptr fakeQuantize4; const auto transpose0 = std::make_shared(fakeQuantize0, transpose0Const); const auto transpose1 = std::make_shared(fakeQuantize1, transpose1Const); - const auto matMul0 = std::make_shared(transpose0, transpose1, transA, transB); - const auto fakeQuantize3 = ngraph::builder::makeFakeQuantize(matMul0, inputPrecisions[0], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); - const auto add = std::make_shared(fakeQuantize3, addParam); - const auto reshape0 = std::make_shared(add, reshape0Const, true); - const auto softMax = std::make_shared(reshape0, 1); - const auto reshape1 = std::make_shared(softMax, reshape1Const, true); + const auto matMul0 = std::make_shared(transpose0, transpose1, transA, transB); + const auto fakeQuantize3 = + ngraph::builder::makeFakeQuantize(matMul0, inputPrecisions[0], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); + const auto add = std::make_shared(fakeQuantize3, addParam); + const auto reshape0 = std::make_shared(add, reshape0Const, true); + const auto softMax = std::make_shared(reshape0, 1); + const auto reshape1 = std::make_shared(softMax, reshape1Const, true); if (matMulIn0Precisions[1] == ElementType::u8) - fakeQuantize4 = ngraph::builder::makeFakeQuantize(reshape1, inputPrecisions[0], 256, {}, {0.0f}, {0.255f}, {0.0f}, {0.255f}); + fakeQuantize4 = ngraph::builder::makeFakeQuantize(reshape1, + inputPrecisions[0], + 256, + {}, + {0.0f}, + {0.255f}, + {0.0f}, + {0.255f}); else - fakeQuantize4 = ngraph::builder::makeFakeQuantize(reshape1, inputPrecisions[0], 256, {}, {-0.128f}, {0.127f}, {-0.128f}, {0.127f}); + fakeQuantize4 = ngraph::builder::makeFakeQuantize(reshape1, + inputPrecisions[0], + 256, + {}, + {-0.128f}, + {0.127f}, + {-0.128f}, + {0.127f}); const auto transpose2 = std::make_shared(fakeQuantize2, transpose2Const); - const auto matMul1 = std::make_shared(fakeQuantize4, transpose2, transA, transB); - const auto fakeQuantize5 = ngraph::builder::makeFakeQuantize(matMul1, inputPrecisions[0], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); + const auto matMul1 = std::make_shared(fakeQuantize4, transpose2, transA, transB); + const auto fakeQuantize5 = + ngraph::builder::makeFakeQuantize(matMul1, inputPrecisions[0], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); const auto transpose3 = std::make_shared(fakeQuantize5, transpose3Const); - ngraph::ResultVector results{std::make_shared(transpose3)}; - return std::make_shared(results, ngraphParam, "mha"); + ov::ResultVector results{std::make_shared(transpose3)}; + return std::make_shared(results, ngraphParam, "mha"); } static std::shared_ptr initMHAQuantSubgraph1(const std::vector& inputDynamicShapes, const std::vector& inputPrecisions, const std::vector& matMulIn0Precisions, const bool fakeQuantize3Exists) { - ngraph::ParameterVector ngraphParam; + ov::ParameterVector ngraphParam; - auto transpose0Param = std::make_shared(inputPrecisions[0], inputDynamicShapes[0]); + auto transpose0Param = std::make_shared(inputPrecisions[0], inputDynamicShapes[0]); ngraphParam.push_back(transpose0Param); - auto transpose1Param = std::make_shared(inputPrecisions[1], inputDynamicShapes[1]); + auto transpose1Param = std::make_shared(inputPrecisions[1], inputDynamicShapes[1]); ngraphParam.push_back(transpose1Param); - auto addParam = std::make_shared(inputPrecisions[2], inputDynamicShapes[2]); + auto addParam = std::make_shared(inputPrecisions[2], inputDynamicShapes[2]); ngraphParam.push_back(addParam); - auto transpose2Param = std::make_shared(inputPrecisions[3], inputDynamicShapes[3]); + auto transpose2Param = std::make_shared(inputPrecisions[3], inputDynamicShapes[3]); ngraphParam.push_back(transpose2Param); std::vector constantShapes; @@ -422,7 +475,7 @@ static std::shared_ptr initMHAQuantSubgraph1(const std::vector transpose3ConstData = {0, 2, 1, 3}; auto transpose3Const = ngraph::builder::makeConstant(ElementType::i64, constantShapes[3], transpose3ConstData); - std::vector mulConstData(ngraph::shape_size(constantShapes[4])); + std::vector mulConstData(ov::shape_size(constantShapes[4])); auto mulConst = ngraph::builder::makeConstant(inputPrecisions[0], constantShapes[4], mulConstData, true); float transA = false; @@ -430,33 +483,55 @@ static std::shared_ptr initMHAQuantSubgraph1(const std::vector fakeQuantize0; if (matMulIn0Precisions[0] == ElementType::u8) - fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, inputPrecisions[0], 256, {}, {0.0f}, {2.55f}, {0.0f}, {2.55f}); + fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, + inputPrecisions[0], + 256, + {}, + {0.0f}, + {2.55f}, + {0.0f}, + {2.55f}); else - fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, inputPrecisions[0], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); + fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, + inputPrecisions[0], + 256, + {}, + {-1.28f}, + {1.27f}, + {-1.28f}, + {1.27f}); const auto transpose0 = std::make_shared(fakeQuantize0, transpose0Const); const auto transpose1 = std::make_shared(transpose1Param, transpose1Const); - const auto fakeQuantize1 = ngraph::builder::makeFakeQuantize(transpose1, inputPrecisions[1], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); - const auto matMul0 = std::make_shared(transpose0, fakeQuantize1, transA, transB); - const auto mul = std::make_shared(addParam, mulConst); - const auto add = std::make_shared(matMul0, mul); - const auto softMax = std::make_shared(add, 3); + const auto fakeQuantize1 = ngraph::builder::makeFakeQuantize(transpose1, + inputPrecisions[1], + 256, + {}, + {-1.28f}, + {1.27f}, + {-1.28f}, + {1.27f}); + const auto matMul0 = std::make_shared(transpose0, fakeQuantize1, transA, transB); + const auto mul = std::make_shared(addParam, mulConst); + const auto add = std::make_shared(matMul0, mul); + const auto softMax = std::make_shared(add, 3); const auto transpose2 = std::make_shared(transpose2Param, transpose2Const); - const auto matMul1 = std::make_shared(softMax, transpose2, transA, transB); + const auto matMul1 = std::make_shared(softMax, transpose2, transA, transB); const auto transpose3 = std::make_shared( - fakeQuantize3Exists ? - ngraph::builder::makeFakeQuantize(matMul1, inputPrecisions[0], 256, {}, { 0.0f }, { 2.55f }, { 0.0f }, { 2.55f }) : - matMul1, + fakeQuantize3Exists + ? ngraph::builder::makeFakeQuantize(matMul1, inputPrecisions[0], 256, {}, {0.0f}, {2.55f}, {0.0f}, {2.55f}) + : matMul1, transpose3Const); - ngraph::ResultVector results{std::make_shared(transpose3)}; - return std::make_shared(results, ngraphParam, "mha"); + ov::ResultVector results{std::make_shared(transpose3)}; + return std::make_shared(results, ngraphParam, "mha"); } class MHAQuantTest : public testing::WithParamInterface, - virtual public SubgraphBaseTest, public CPUTestsBase { + virtual public SubgraphBaseTest, + public CPUTestsBase { public: - static std::string getTestCaseName(const testing::TestParamInfo &obj) { + static std::string getTestCaseName(const testing::TestParamInfo& obj) { std::vector inputShapes; std::vector inputPrecisions; std::vector matMulIn0Precisions; @@ -485,24 +560,31 @@ public: results << "patternType=" << patternType; results << "expect="; for (const auto& node : expectedNodes) { - results << node.first << "[" << node.second << "]" << "_"; + results << node.first << "[" << node.second << "]" + << "_"; } results << "targetDevice=" << targetName; return results.str(); } - void generate_inputs(const std::vector& targetInputStaticShapes) override { + void generate_inputs(const std::vector& targetInputStaticShapes) override { inputs.clear(); const auto& funcInputs = function->inputs(); for (size_t i = 0; i < funcInputs.size(); ++i) { const auto& funcInput = funcInputs[i]; ov::Tensor tensor; if (funcInput.get_element_type().is_real()) - tensor = ov::test::utils::create_and_fill_tensor_normal_distribution(funcInput.get_element_type(), targetInputStaticShapes[i], 0.0f, 1.5f); + tensor = ov::test::utils::create_and_fill_tensor_normal_distribution(funcInput.get_element_type(), + targetInputStaticShapes[i], + 0.0f, + 1.5f); else - tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], 255, 0, 1); - + tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), + targetInputStaticShapes[i], + 255, + 0, + 1); inputs.insert({funcInput.get_node_shared_ptr(), tensor}); } @@ -517,7 +599,8 @@ protected: std::vector matMulIn0Precisions; size_t patternType; ExpectedNodes expectedNodes; - std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = this->GetParam(); + std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = + this->GetParam(); init_input_shapes(inputShapes); @@ -531,11 +614,11 @@ protected: FAIL() << "Unsupported MHA pattern type"; } - // Snippets MHA tokenization has limitations to avoid performance degradations. These limitations depend on target machine. - // Just for testing, we disable these limitations to allow Snippets to tokenize pattern on all machines for validation. - if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { - configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, - InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + // Snippets MHA tokenization has limitations to avoid performance degradations. These limitations depend on + // target machine. Just for testing, we disable these limitations to allow Snippets to tokenize pattern on all + // machines for validation. + if (!configuration.count("SNIPPETS_MODE")) { + configuration.insert({"SNIPPETS_MODE", "IGNORE_CALLBACK"}); } } }; @@ -546,12 +629,13 @@ TEST_P(MHAQuantTest, CompareWithRefs) { std::vector matMulIn0Precisions; size_t patternType; ExpectedNodes expectedNodes; - std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = this->GetParam(); + std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = + this->GetParam(); - if (inputPrecisions[0] == ElementType::bf16 && !InferenceEngine::with_cpu_x86_bfloat16()) + if (inputPrecisions[0] == ElementType::bf16 && !ov::with_cpu_x86_bfloat16()) GTEST_SKIP(); - if (!InferenceEngine::with_cpu_x86_avx512_core_vnni()) + if (!ov::with_cpu_x86_avx512_core_vnni()) GTEST_SKIP(); run(); @@ -563,7 +647,7 @@ TEST_P(MHAQuantTest, CompareWithRefs) { namespace { -std::vector> inputShapesQuant = { +std::vector> inputShapesQuant = { {{2, 7, 16, 9}, {2, 7, 16, 9}, {2, 1, 1, 7}, {2, 7, 16, 9}}, {{2, 8, 16, 64}, {2, 8, 16, 64}, {2, 1, 1, 8}, {2, 8, 16, 64}}, {{1, 384, 16, 64}, {1, 384, 16, 64}, {1, 1, 1, 384}, {1, 384, 16, 64}}, @@ -571,52 +655,52 @@ std::vector> inputShapesQuant = { {{3, 96, 16, 64}, {3, 96, 16, 64}, {3, 1, 1, 96}, {3, 96, 16, 64}}, {{2, 192, 16, 160}, {2, 192, 16, 160}, {2, 1, 1, 192}, {2, 192, 16, 160}}, {{2, 4, 16, 8}, {2, 4, 16, 8}, {2, 1, 1, 4}, {2, 4, 16, 8}}, - {{1, 204, 13, 212}, {1, 204, 13, 212}, {1, 1, 1, 204}, {1, 204, 13, 212}}, - {{1, 207, 13, 211}, {1, 207, 13, 211}, {1, 1, 1, 207}, {1, 207, 13, 211}}, + {{1, 204, 13, 212}, {1, 204, 13, 212}, {1, 1, 1, 204}, {1, 204, 13, 212}}, + {{1, 207, 13, 211}, {1, 207, 13, 211}, {1, 1, 1, 207}, {1, 207, 13, 211}}, }; std::vector> inputPrecisionsQuant = { - { ElementType::f32, ElementType::f32, ElementType::f32, ElementType::f32 }, + {ElementType::f32, ElementType::f32, ElementType::f32, ElementType::f32}, }; std::vector> matMulIn0PrecisionsQuant = { - { ElementType::i8, ElementType::i8 }, - { ElementType::i8, ElementType::u8 }, + {ElementType::i8, ElementType::i8}, + {ElementType::i8, ElementType::u8}, }; -INSTANTIATE_TEST_SUITE_P(smoke_MHAQuant_Pattern0, MHAQuantTest, - ::testing::Combine( - ::testing::ValuesIn(static_shapes_to_test_representation(inputShapesQuant)), - ::testing::ValuesIn(inputPrecisionsQuant), - ::testing::ValuesIn(matMulIn0PrecisionsQuant), - ::testing::Values(0), - ::testing::Values(ExpectedNodes{{"Subgraph", 5}, // FQs on inputs x 3 + MHA + Deq Mul - {"Transpose", 1}}), // Transpose between MHA and Deq Mul - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MHAQuantTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_MHAQuant_Pattern0, + MHAQuantTest, + ::testing::Combine(::testing::ValuesIn(static_shapes_to_test_representation(inputShapesQuant)), + ::testing::ValuesIn(inputPrecisionsQuant), + ::testing::ValuesIn(matMulIn0PrecisionsQuant), + ::testing::Values(0), + ::testing::Values(ExpectedNodes{ + {"Subgraph", 5}, // FQs on inputs x 3 + MHA + Deq Mul + {"Transpose", 1}}), // Transpose between MHA and Deq Mul + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MHAQuantTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_MHAQuant_Pattern1, + MHAQuantTest, + ::testing::Combine(::testing::ValuesIn(static_shapes_to_test_representation(inputShapesQuant)), + ::testing::ValuesIn(inputPrecisionsQuant), + ::testing::ValuesIn(matMulIn0PrecisionsQuant), + ::testing::Values(1), + ::testing::Values(ExpectedNodes{ + {"Subgraph", 3}, // FQ on input + MHA + Deq Mul + {"Transpose", 1}}), // Transpose between MHA and Deq Mul + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MHAQuantTest::getTestCaseName); -INSTANTIATE_TEST_SUITE_P(smoke_MHAQuant_Pattern1, MHAQuantTest, - ::testing::Combine( - ::testing::ValuesIn(static_shapes_to_test_representation(inputShapesQuant)), - ::testing::ValuesIn(inputPrecisionsQuant), - ::testing::ValuesIn(matMulIn0PrecisionsQuant), - ::testing::Values(1), - ::testing::Values(ExpectedNodes{{"Subgraph", 3}, // FQ on input + MHA + Deq Mul - {"Transpose", 1}}), // Transpose between MHA and Deq Mul - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MHAQuantTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_MHAQuant_Pattern2, + MHAQuantTest, + ::testing::Combine(::testing::ValuesIn(static_shapes_to_test_representation(inputShapesQuant)), + ::testing::ValuesIn(inputPrecisionsQuant), + ::testing::ValuesIn(matMulIn0PrecisionsQuant), + ::testing::Values(2), + ::testing::Values(ExpectedNodes{{"Subgraph", 2}, // MHA + Deq Mul + {"Transpose", 0}}), // Transpose is fused + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MHAQuantTest::getTestCaseName); -INSTANTIATE_TEST_SUITE_P(smoke_MHAQuant_Pattern2, MHAQuantTest, - ::testing::Combine( - ::testing::ValuesIn(static_shapes_to_test_representation(inputShapesQuant)), - ::testing::ValuesIn(inputPrecisionsQuant), - ::testing::ValuesIn(matMulIn0PrecisionsQuant), - ::testing::Values(2), - ::testing::Values(ExpectedNodes{{"Subgraph", 2}, // MHA + Deq Mul - {"Transpose", 0}}), // Transpose is fused - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MHAQuantTest::getTestCaseName); - -} // namespace -} // namespace CPUSubgraphTestsDefinitions +} // namespace diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/ngram.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/ngram.cpp index 58edce33fcd..865268c500a 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/ngram.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/ngram.cpp @@ -2,46 +2,37 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include -#include -#include -#include -#include #include "common_test_utils/common_utils.hpp" -#include +#include "common_test_utils/ov_tensor_utils.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" #include "test_utils/cpu_test_utils.hpp" -#include -#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" using namespace CPUTestUtils; -using namespace ov::test; -using namespace ngraph::helpers; -namespace CPUSubgraphTestsDefinitions { +namespace ov { +namespace test { -typedef std::tuple< - std::vector, - ElementType, - ElementType, - size_t -> NgramTestParams; +typedef std::tuple, ElementType, ElementType, size_t> NgramTestParams; static std::shared_ptr getStridedSlice(const std::shared_ptr& data, const std::shared_ptr& begin, const std::shared_ptr& end, const std::vector& shrink_axis_mask = {}) { std::vector default_mask(begin->get_shape()[0], 0); - return std::make_shared(data, begin, end, default_mask, default_mask, - std::vector{}, shrink_axis_mask); + return std::make_shared(data, + begin, + end, + default_mask, + default_mask, + std::vector{}, + shrink_axis_mask); } static std::shared_ptr getReshape(const std::shared_ptr& data, const std::vector& requested_shape, const ov::element::Type& prc) { - auto requested_shape_node = ov::opset1::Constant::create(prc, {requested_shape.size()}, requested_shape); - return std::make_shared(data, requested_shape_node, true); + auto requested_shape_node = ov::op::v0::Constant::create(prc, {requested_shape.size()}, requested_shape); + return std::make_shared(data, requested_shape_node, true); } static std::shared_ptr initNgram(std::vector& input_shapes, @@ -58,78 +49,80 @@ static std::shared_ptr initNgram(std::vector& input auto param_node = std::make_shared(input_precisions[i], input_shapes[i]); params.push_back(param_node); } - auto shape_of = std::make_shared(params[0], idces_et); - auto shape_ss_begin = ov::opset1::Constant::create(idces_et, {1}, {0}); - auto shape_ss_end = ov::opset1::Constant::create(idces_et, {1}, {1}); + auto shape_of = std::make_shared(params[0], idces_et); + auto shape_ss_begin = ov::op::v0::Constant::create(idces_et, {1}, {0}); + auto shape_ss_end = ov::op::v0::Constant::create(idces_et, {1}, {1}); auto shape_ss = getStridedSlice(shape_of, shape_ss_begin, shape_ss_end, {1}); auto getInputsToPad = [&](const ov::Output data, const int pad_value) { const size_t length = data.get_partial_shape()[1].get_length(); ov::OutputVector inputs; if (left_pad > 0) { - inputs.push_back(ov::opset1::Constant::create(data.get_element_type(), {left_pad, length}, {pad_value})); + inputs.push_back(ov::op::v0::Constant::create(data.get_element_type(), {left_pad, length}, {pad_value})); } inputs.push_back(data); if (right_pad > 0) { - inputs.push_back(ov::opset1::Constant::create(data.get_element_type(), {right_pad, length}, {pad_value})); + inputs.push_back(ov::op::v0::Constant::create(data.get_element_type(), {right_pad, length}, {pad_value})); } return inputs; }; - auto data_padded = std::make_shared(getInputsToPad(params[0], 0), 0); - auto idces_padded = std::make_shared(getInputsToPad(params[1], -1), 0); + auto data_padded = std::make_shared(getInputsToPad(params[0], 0), 0); + auto idces_padded = std::make_shared(getInputsToPad(params[1], -1), 0); std::shared_ptr as_is_bias = shape_ss; if (mid_idx != 0) { - auto bias_const = ov::opset1::Constant::create(idces_et, {}, {mid_idx}); - as_is_bias = std::make_shared(shape_ss, bias_const); + auto bias_const = ov::op::v0::Constant::create(idces_et, {}, {mid_idx}); + as_is_bias = std::make_shared(shape_ss, bias_const); } - auto as_is_ss_begin = ov::opset1::Constant::create(idces_et, {1}, {mid_idx}); + auto as_is_ss_begin = ov::op::v0::Constant::create(idces_et, {1}, {mid_idx}); auto as_is_ss_end = getReshape(as_is_bias, {1}, idces_et); auto as_is_ss = getStridedSlice(data_padded, as_is_ss_begin, as_is_ss_end); auto getSelectBranch = [&](const size_t cur_idx, const size_t mid_idx) { std::shared_ptr eq_left_bias = shape_ss; if (cur_idx != 0) { - auto bias_const = ov::opset1::Constant::create(idces_et, {}, {cur_idx}); - eq_left_bias = std::make_shared(shape_ss, bias_const); + auto bias_const = ov::op::v0::Constant::create(idces_et, {}, {cur_idx}); + eq_left_bias = std::make_shared(shape_ss, bias_const); } auto eq_left_reshape = getReshape(eq_left_bias, {1}, idces_et); - auto eq_left_concat_const = ov::opset1::Constant::create(idces_et, {1}, {1}); - auto eq_left_concat = std::make_shared(ov::OutputVector{eq_left_reshape, eq_left_concat_const}, 0); - auto eq_left_ss_begin = ov::opset1::Constant::create(idces_et, {2}, std::vector{cur_idx, 0ul}); + auto eq_left_concat_const = ov::op::v0::Constant::create(idces_et, {1}, {1}); + auto eq_left_concat = + std::make_shared(ov::OutputVector{eq_left_reshape, eq_left_concat_const}, 0); + auto eq_left_ss_begin = ov::op::v0::Constant::create(idces_et, {2}, std::vector{cur_idx, 0ul}); auto eq_left_ss = getStridedSlice(idces_padded, eq_left_ss_begin, eq_left_concat, {0, 1}); std::shared_ptr eq_right_bias = shape_ss; if (mid_idx != 0) { - auto bias_const = ov::opset1::Constant::create(idces_et, {}, {mid_idx}); - eq_right_bias = std::make_shared(shape_ss, bias_const); + auto bias_const = ov::op::v0::Constant::create(idces_et, {}, {mid_idx}); + eq_right_bias = std::make_shared(shape_ss, bias_const); } auto eq_right_reshape = getReshape(eq_right_bias, {1}, idces_et); - auto eq_right_concat_const = ov::opset1::Constant::create(idces_et, {1}, {1}); - auto eq_right_concat = std::make_shared(ov::OutputVector{eq_right_reshape, eq_right_concat_const}, 0); - auto eq_right_ss_begin = ov::opset1::Constant::create(idces_et, {2}, std::vector{mid_idx, 0ul}); + auto eq_right_concat_const = ov::op::v0::Constant::create(idces_et, {1}, {1}); + auto eq_right_concat = + std::make_shared(ov::OutputVector{eq_right_reshape, eq_right_concat_const}, 0); + auto eq_right_ss_begin = ov::op::v0::Constant::create(idces_et, {2}, std::vector{mid_idx, 0ul}); auto eq_right_ss = getStridedSlice(idces_padded, eq_right_ss_begin, eq_right_concat, {0, 1}); - auto equal = std::make_shared(eq_left_ss, eq_right_ss); + auto equal = std::make_shared(eq_left_ss, eq_right_ss); auto cond = getReshape(equal, {-1, 1}, idces_et); std::shared_ptr then_bias = shape_ss; if (cur_idx != 0) { - auto bias_const = ov::opset1::Constant::create(idces_et, {}, {cur_idx}); - then_bias = std::make_shared(shape_ss, bias_const); + auto bias_const = ov::op::v0::Constant::create(idces_et, {}, {cur_idx}); + then_bias = std::make_shared(shape_ss, bias_const); } auto then_reshape = getReshape(then_bias, {1}, idces_et); - auto then_ss_begin = ov::opset1::Constant::create(idces_et, {1}, {cur_idx}); + auto then_ss_begin = ov::op::v0::Constant::create(idces_et, {1}, {cur_idx}); auto then = getStridedSlice(data_padded, then_ss_begin, then_reshape); auto else_reshape = getReshape(shape_ss, {1}, idces_et); - auto else_concat_const = ov::opset1::Constant::create(idces_et, {1}, {input_shapes[0][1].get_length()}); - auto else_concat = std::make_shared(ov::OutputVector{else_reshape, else_concat_const}, 0); - auto else_bcast_const = ov::opset1::Constant::create(data_et, {}, {0}); - auto else_bcast = std::make_shared(else_bcast_const, else_concat); + auto else_concat_const = ov::op::v0::Constant::create(idces_et, {1}, {input_shapes[0][1].get_length()}); + auto else_concat = std::make_shared(ov::OutputVector{else_reshape, else_concat_const}, 0); + auto else_bcast_const = ov::op::v0::Constant::create(data_et, {}, {0}); + auto else_bcast = std::make_shared(else_bcast_const, else_concat); - auto select = std::make_shared(cond, then, else_bcast); + auto select = std::make_shared(cond, then, else_bcast); return select; }; @@ -141,13 +134,15 @@ static std::shared_ptr initNgram(std::vector& input concat_inputs[i] = getSelectBranch(i, mid_idx); } - auto final_concat = std::make_shared(concat_inputs, 1); + auto final_concat = std::make_shared(concat_inputs, 1); return std::make_shared(final_concat, params, "ngram"); } -class NgramCPUTest : public testing::WithParamInterface, virtual public SubgraphBaseTest, public CPUTestsBase { +class NgramCPUTest : public testing::WithParamInterface, + virtual public SubgraphBaseTest, + public CPUTestsBase { public: - static std::string getTestCaseName(const testing::TestParamInfo &obj) { + static std::string getTestCaseName(const testing::TestParamInfo& obj) { std::vector input_shapes; size_t k; ElementType data_et; @@ -178,7 +173,6 @@ public: auto embeddings_tensor = ov::test::utils::create_and_fill_tensor_consistently(data_et, data_shape, 100, 1, 1); inputs.insert({model_inputs[0].get_node_shared_ptr(), embeddings_tensor}); - const auto& indices_et = model_inputs[1].get_element_type(); const auto& indices_shape = targetInputStaticShapes[1]; const size_t batch_size = data_shape[0]; @@ -207,9 +201,8 @@ protected: init_input_shapes(inputShapes); function = initNgram(inputDynamicShapes, data_et, idces_et, k); - if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { - configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, - InferenceEngine::PluginConfigInternalParams::DISABLE}); + if (!configuration.count("SNIPPETS_MODE")) { + configuration.insert({"SNIPPETS_MODE", "DISABLE"}); } } }; @@ -222,28 +215,21 @@ TEST_P(NgramCPUTest, CompareWithRefs) { namespace { std::vector> inputShapes = { - { - InputShape{{-1, 2}, {{3, 2}, {5, 2}, {7, 2}}}, - InputShape{{-1, 2}, {{3, 2}, {5, 2}, {7, 2}}} - }, - { - InputShape{{-1, 256}, {{12, 256}, {25, 256}}}, - InputShape{{-1, 2}, {{12, 2}, {25, 2}}} - }, - { - InputShape{{-1, 1}, {{12, 1}}}, - InputShape{{-1, 2}, {{12, 2}}} - }, + {InputShape{{-1, 2}, {{3, 2}, {5, 2}, {7, 2}}}, InputShape{{-1, 2}, {{3, 2}, {5, 2}, {7, 2}}}}, + {InputShape{{-1, 256}, {{12, 256}, {25, 256}}}, InputShape{{-1, 2}, {{12, 2}, {25, 2}}}}, + {InputShape{{-1, 1}, {{12, 1}}}, InputShape{{-1, 2}, {{12, 2}}}}, }; std::vector k_values = {2, 3, 5, 7}; std::vector idces_precisions = {ElementType::i32, ElementType::i64}; -INSTANTIATE_TEST_SUITE_P(smoke_Ngram, NgramCPUTest, - ::testing::Combine(::testing::ValuesIn(inputShapes), - ::testing::Values(ElementType::f32), - ::testing::ValuesIn(idces_precisions), - ::testing::ValuesIn(k_values)), - NgramCPUTest::getTestCaseName); -} // namespace -} // namespace CPUSubgraphTestsDefinitions +INSTANTIATE_TEST_SUITE_P(smoke_Ngram, + NgramCPUTest, + ::testing::Combine(::testing::ValuesIn(inputShapes), + ::testing::Values(ElementType::f32), + ::testing::ValuesIn(idces_precisions), + ::testing::ValuesIn(k_values)), + NgramCPUTest::getTestCaseName); +} // namespace +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/param_result_custom_blob.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/param_result_custom_blob.cpp index b762671a66d..8b086d0833e 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/param_result_custom_blob.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/param_result_custom_blob.cpp @@ -6,10 +6,9 @@ #include "shared_test_classes/subgraph/parameter_result.hpp" using namespace SubgraphTestsDefinitions; -using namespace ov::test; -using namespace InferenceEngine; -namespace CPULayerTestsDefinitions { +namespace ov { +namespace test { class ParameterResultCustomBlobTest : public ParameterResultSubgraphTestLegacyApi { protected: @@ -21,7 +20,7 @@ protected: auto inputBlob = inputs.front(); const size_t elementsCount = inputBlob->size(); for (size_t i = 0; i < inferIterations; ++i) { - ov::test::utils::fill_data_random(inputBlob, 10, 0, 1, i); + ov::test::utils::fill_data_random(inputBlob, 10, 0, 1, i); auto inputsInfo = cnnNetwork.getInputsInfo().begin()->second; std::string inputName = cnnNetwork.getInputsInfo().begin()->first; @@ -30,7 +29,7 @@ protected: std::copy(inpBlobData, inpBlobData + elementsCount, customInpData.begin()); auto& tensorDesc = inputsInfo->getTensorDesc(); - auto customBlob = make_shared_blob(tensorDesc, customInpData.data(), elementsCount); + auto customBlob = InferenceEngine::make_shared_blob(tensorDesc, customInpData.data(), elementsCount); inferRequest.SetBlob(inputName, customBlob); inferRequest.Infer(); @@ -46,8 +45,8 @@ protected: TEST_P(ParameterResultCustomBlobTest, CompareWithRefs) { // Just to show that it is not possible to set different precisions for inputs and outputs with the same name. // If it was possible, the input would have I8 precision and couldn't store data from the custom blob. - inPrc = Precision::I8; - outPrc = Precision::FP32; + inPrc = InferenceEngine::Precision::I8; + outPrc = InferenceEngine::Precision::FP32; Run(); } @@ -84,4 +83,5 @@ INSTANTIATE_TEST_SUITE_P(smoke_Check_Same_Blob, ::testing::Values(ov::test::utils::DEVICE_CPU)), ParameterResultSubgraphTestBase::getTestCaseName); } // namespace -} // namespace CPULayerTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/remove_convert.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/remove_convert.cpp index 5a214177867..8ba11aedcb6 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/remove_convert.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/remove_convert.cpp @@ -2,24 +2,20 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ov_models/builders.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" +#include "common_test_utils/node_builders/activation.hpp" #include "shared_test_classes/base/ov_subgraph.hpp" #include "test_utils/cpu_test_utils.hpp" #include "test_utils/fusing_test_utils.hpp" -using namespace ov::test; -using namespace ngraph; using namespace CPUTestUtils; -using namespace InferenceEngine; -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { using RemoveConvertCPUTestParams = std::tuple; class RemoveUselessBF16ConvertCPUTest : public testing::WithParamInterface, - virtual public SubgraphBaseTest, - public CPUTestsBase { + virtual public SubgraphBaseTest, + public CPUTestsBase { public: static std::string getTestCaseName(const testing::TestParamInfo& obj) { ElementType inType; @@ -44,9 +40,9 @@ public: init_input_shapes({inputShape}); auto input_params = std::make_shared(inType, inputShape.first); auto convert = std::make_shared(input_params, element::f32); - auto begin = builder::makeConstant(element::i64, ov::Shape{4}, std::vector{0, 0, 0, 0}); - auto end = builder::makeConstant(element::i64, ov::Shape{4}, std::vector{0, 0, 16, 0}); - auto stride = builder::makeConstant(element::i64, ov::Shape{4}, std::vector{1, 1, 1, 1}); + auto begin = ngraph::builder::makeConstant(element::i64, ov::Shape{4}, std::vector{0, 0, 0, 0}); + auto end = ngraph::builder::makeConstant(element::i64, ov::Shape{4}, std::vector{0, 0, 16, 0}); + auto stride = ngraph::builder::makeConstant(element::i64, ov::Shape{4}, std::vector{1, 1, 1, 1}); auto slice = std::make_shared(convert, begin, end, @@ -84,17 +80,19 @@ public: init_input_shapes({inputShape}); auto input_params = std::make_shared(inType, inputShape.first); - // Such complicated graph is necessary to cover the case when Convert has several children and connected to non zero output - const auto split_axis = builder::makeConstant(element::i64, ov::Shape{}, std::vector{1}); - const auto split_lengths = builder::makeConstant(element::i64, ov::Shape{2}, std::vector{-1, 1}); - const auto split = std::make_shared(input_params, split_axis, split_lengths); + // Such complicated graph is necessary to cover the case when Convert has several children and connected to non + // zero output + const auto split_axis = ngraph::builder::makeConstant(element::i64, ov::Shape{}, std::vector{1}); + const auto split_lengths = + ngraph::builder::makeConstant(element::i64, ov::Shape{2}, std::vector{-1, 1}); + const auto split = std::make_shared(input_params, split_axis, split_lengths); auto convert = std::make_shared(split->output(1), inType); - auto relu = builder::makeActivation(convert, inType, ::helpers::ActivationTypes::Relu); + auto relu = ov::test::utils::make_activation(convert, inType, ov::test::utils::ActivationTypes::Relu); ov::ResultVector results{ - std::make_shared(split->output(0)), - std::make_shared(convert), - std::make_shared(relu), + std::make_shared(split->output(0)), + std::make_shared(convert), + std::make_shared(relu), }; function = std::make_shared(results, ov::ParameterVector{input_params}, "remove_convert"); @@ -131,4 +129,5 @@ INSTANTIATE_TEST_SUITE_P(smoke_RemoveConvert, ::testing::Combine(::testing::Values(ElementType::f32), ::testing::Values(inputShapes[0])), RemoveUselessConvertCPUTest::getTestCaseName); } // namespace -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov