OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[Snippets][TESTS] Refactor movebroadcast and codegen_gelu tests (#31222)
Arseniy Obolenskiy3a8954359bd5
diff --git a/src/common/snippets/tests/include/pass/movebroadcast.hpp b/src/common/snippets/tests/include/pass/movebroadcast.hppnew file mode 100644index 00000000000..4a02639d39d--- /dev/null+++ b/src/common/snippets/tests/include/pass/movebroadcast.hpp@@ -0,0 +1,20 @@+// Copyright (C) 2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include <common_test_utils/ov_test_utils.hpp>++namespace ov {+namespace test {+namespace snippets {++class MoveBroadcastTests : public TransformationTestsF {+protected:+ void SetUp() override;+};++} // namespace snippets+} // namespace test+} // namespace ovdiff --git a/src/common/snippets/tests/src/pass/movebroadcast.cpp b/src/common/snippets/tests/src/pass/movebroadcast.cppindex 9cffede7cc7..83583852f00 100644--- a/src/common/snippets/tests/src/pass/movebroadcast.cpp+++ b/src/common/snippets/tests/src/pass/movebroadcast.cpp@@ -5,32 +5,31 @@#include <gtest/gtest.h>#include "openvino/op/add.hpp"-#include "snippets/pass/insert_movebroadcast.hpp"#include "snippets/op/broadcastmove.hpp"+#include "snippets/pass/insert_movebroadcast.hpp"+#include "subgraph_movebroadcast.hpp"-#include "transformations/init_node_info.hpp"--#include "common_test_utils/ov_test_utils.hpp"+#include "pass/movebroadcast.hpp"using namespace testing;using namespace ov;-// todo: Rewrite this test using Snippets test infrastructure. See ./include/canonicalization.hpp for example--TEST_F(TransformationTestsF, InsertBroadcastMove) {- {- auto data0 = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 3});- auto data1 = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 2, 1});- auto add = std::make_shared<ov::op::v1::Add>(data0, data1);- model = std::make_shared<Model>(OutputVector{add}, ParameterVector{data0, data1});-- manager.register_pass<snippets::pass::InsertMoveBroadcast>();- }- {- auto data0 = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 3});- auto data1 = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 2, 1});- auto move1 = std::make_shared<snippets::op::BroadcastMove>(data1, ov::Dimension{3});- auto add = std::make_shared<ov::op::v1::Add>(data0, move1);- model_ref = std::make_shared<Model>(OutputVector{add}, ParameterVector{data0, data1});- }+namespace ov {+namespace test {+namespace snippets {++void MoveBroadcastTests::SetUp() {+ TransformationTestsF::SetUp();+ manager.register_pass<::snippets::pass::InsertMoveBroadcast>();}++TEST_F(MoveBroadcastTests, InsertBroadcastMove) {+ std::vector<PartialShape> input_shapes = {Shape{2, 3}, Shape{1, 2, 1}};+ MoveBroadcastFunction function(input_shapes);+ model = function.getOriginal();+ model_ref = function.getReference();+}++} // namespace snippets+} // namespace test+} // namespace ovdiff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/codegen_gelu.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/codegen_gelu.cppindex a2245fca600..f4fadd8dec3 100644--- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/codegen_gelu.cpp+++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/codegen_gelu.cpp@@ -1,4 +1,3 @@-// Copyright (C) 2018-2025 Intel Corporation// SPDX-License-Identifier: Apache-2.0//@@ -7,7 +6,6 @@#include "snippets/codegen_gelu.hpp"#include "common_test_utils/test_constants.hpp"-// todo: Rewrite this test using Snippets test infrastructure. See add_convert or conv_eltwise for examplenamespace ov {namespace test {diff --git a/src/tests/functional/plugin/shared/src/snippets/codegen_gelu.cpp b/src/tests/functional/plugin/shared/src/snippets/codegen_gelu.cppindex bb789c0b460..a1d0179d603 100644--- a/src/tests/functional/plugin/shared/src/snippets/codegen_gelu.cpp+++ b/src/tests/functional/plugin/shared/src/snippets/codegen_gelu.cpp@@ -3,14 +3,12 @@// SPDX-License-Identifier: Apache-2.0//+#include "snippets/codegen_gelu.hpp"+#include "common_test_utils/common_utils.hpp"-#include "openvino/op/gelu.hpp"-#include "openvino/op/parameter.hpp"#include "openvino/pass/constant_folding.hpp"-#include "snippets/codegen_gelu.hpp"-#include "subgraph_simple.hpp"#include "functional_test_utils/skip_tests_config.hpp"-#include "openvino/op/add.hpp"+#include "subgraph_gelu.hpp"namespace ov {namespace test {@@ -42,24 +40,15 @@ namespace snippets {// Gelu from bert-large-uncased-whole-word-masking-squad-fp32-onnx-0001void CodegenGelu::SetUp() {- InputShape inputShape0, inputShapes1;- ov::element::Type_t netPrecision;- bool useSubgraph;- std::tie(netPrecision, inputShape0, inputShapes1, useSubgraph, targetDevice) = this->GetParam();-- init_input_shapes({inputShape0, inputShapes1});+ auto [netPrecision, inputShape0, inputShape1, useSubgraph, targetDeviceValue] = this->GetParam();+ targetDevice = targetDeviceValue;- auto input0 = std::make_shared<ov::op::v0::Parameter>(netPrecision, inputDynamicShapes[0]);- auto input1 = std::make_shared<ov::op::v0::Parameter>(netPrecision, inputDynamicShapes[1]);- auto add = std::make_shared<ov::op::v1::Add>(input0, input1);+ init_input_shapes({inputShape0, inputShape1});- auto gelu = std::make_shared<ov::op::v0::Gelu>(add);- auto result = std::make_shared<ov::op::v0::Result>(gelu);+ auto f = ov::test::snippets::CodegenGeluFunction(inputDynamicShapes, netPrecision);+ function = f.getOriginal();- function = std::make_shared<ov::Model>(- ov::ResultVector{result},- ov::ParameterVector{input0, input1},- "CodegenGelu");+ setInferenceType(netPrecision);if (useSubgraph) {ov::pass::InitNodeInfo().run_on_model(function);diff --git a/src/tests/ov_helpers/ov_snippets_models/include/subgraph_gelu.hpp b/src/tests/ov_helpers/ov_snippets_models/include/subgraph_gelu.hppnew file mode 100644index 00000000000..29399d52f80--- /dev/null+++ b/src/tests/ov_helpers/ov_snippets_models/include/subgraph_gelu.hpp@@ -0,0 +1,24 @@+// Copyright (C) 2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//+#pragma once++#include "snippets_helpers.hpp"++namespace ov {+namespace test {+namespace snippets {++class CodegenGeluFunction : public SnippetsFunctionBase {+public:+ CodegenGeluFunction(const std::vector<ov::PartialShape>& inputShapes,+ ov::element::Type_t precision = ov::element::f32);++protected:+ std::shared_ptr<ov::Model> initOriginal() const override;+};++} // namespace snippets+} // namespace test+} // namespace ov+diff --git a/src/tests/ov_helpers/ov_snippets_models/include/subgraph_movebroadcast.hpp b/src/tests/ov_helpers/ov_snippets_models/include/subgraph_movebroadcast.hppnew file mode 100644index 00000000000..ecbf475b973--- /dev/null+++ b/src/tests/ov_helpers/ov_snippets_models/include/subgraph_movebroadcast.hpp@@ -0,0 +1,24 @@+// Copyright (C) 2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//+#pragma once++#include "snippets_helpers.hpp"++namespace ov {+namespace test {+namespace snippets {++class MoveBroadcastFunction : public SnippetsFunctionBase {+public:+ MoveBroadcastFunction(const std::vector<ov::PartialShape>& inputShapes,+ ov::element::Type_t precision = ov::element::f32);++protected:+ std::shared_ptr<ov::Model> initOriginal() const override;+ std::shared_ptr<ov::Model> initReference() const override;+};++} // namespace snippets+} // namespace test+} // namespace ov\ No newline at end of filediff --git a/src/tests/ov_helpers/ov_snippets_models/src/subgraph_gelu.cpp b/src/tests/ov_helpers/ov_snippets_models/src/subgraph_gelu.cppnew file mode 100644index 00000000000..cbc31b724ce--- /dev/null+++ b/src/tests/ov_helpers/ov_snippets_models/src/subgraph_gelu.cpp@@ -0,0 +1,37 @@+// Copyright (C) 2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//+#include "subgraph_gelu.hpp"++#include "openvino/op/add.hpp"+#include "openvino/op/gelu.hpp"+#include "openvino/op/parameter.hpp"+#include "openvino/op/result.hpp"+#include "openvino/pass/constant_folding.hpp"+#include "transformations/init_node_info.hpp"++namespace ov {+namespace test {+namespace snippets {++CodegenGeluFunction::CodegenGeluFunction(const std::vector<ov::PartialShape>& inputShapes,+ ov::element::Type_t precision)+ : SnippetsFunctionBase(inputShapes, precision) {+ OPENVINO_ASSERT(input_shapes.size() == 2, "Got invalid number of input shapes");+}++std::shared_ptr<ov::Model> CodegenGeluFunction::initOriginal() const {+ auto input0 = std::make_shared<ov::op::v0::Parameter>(precision, input_shapes[0]);+ auto input1 = std::make_shared<ov::op::v0::Parameter>(precision, input_shapes[1]);+ auto add = std::make_shared<ov::op::v1::Add>(input0, input1);+ auto gelu = std::make_shared<ov::op::v0::Gelu>(add);+ auto result = std::make_shared<ov::op::v0::Result>(gelu);+ auto model = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input0, input1});++ return model;+}++} // namespace snippets+} // namespace test+} // namespace ov+diff --git a/src/tests/ov_helpers/ov_snippets_models/src/subgraph_movebroadcast.cpp b/src/tests/ov_helpers/ov_snippets_models/src/subgraph_movebroadcast.cppnew file mode 100644index 00000000000..6d4dda2c9df--- /dev/null+++ b/src/tests/ov_helpers/ov_snippets_models/src/subgraph_movebroadcast.cpp@@ -0,0 +1,45 @@+// Copyright (C) 2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//+#include "subgraph_movebroadcast.hpp"++#include "openvino/op/add.hpp"+#include "openvino/op/parameter.hpp"+#include "openvino/op/result.hpp"+#include "openvino/pass/constant_folding.hpp"+#include "snippets/op/broadcastmove.hpp"+#include "transformations/init_node_info.hpp"++namespace ov {+namespace test {+namespace snippets {++MoveBroadcastFunction::MoveBroadcastFunction(const std::vector<ov::PartialShape>& inputShapes,+ ov::element::Type_t precision)+ : SnippetsFunctionBase(inputShapes, precision) {+ OPENVINO_ASSERT(input_shapes.size() == 2, "Got invalid number of input shapes");+}++std::shared_ptr<ov::Model> MoveBroadcastFunction::initOriginal() const {+ auto input0 = std::make_shared<ov::op::v0::Parameter>(precision, input_shapes[0]);+ auto input1 = std::make_shared<ov::op::v0::Parameter>(precision, input_shapes[1]);+ auto add = std::make_shared<ov::op::v1::Add>(input0, input1);+ auto result = std::make_shared<ov::op::v0::Result>(add);+ auto model = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input0, input1});++ return model;+}++std::shared_ptr<ov::Model> MoveBroadcastFunction::initReference() const {+ auto ref_data0 = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 3});+ auto ref_data1 = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 2, 1});+ auto move1 = std::make_shared<ov::snippets::op::BroadcastMove>(ref_data1, ov::Dimension{3});+ auto add_ref = std::make_shared<ov::op::v1::Add>(ref_data0, move1);+ auto model = std::make_shared<Model>(OutputVector{add_ref}, ParameterVector{ref_data0, ref_data1});++ return model;+}++} // namespace snippets+} // namespace test+} // namespace ov\ No newline at end of file