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][CPU] Reuse common shape inference registry across architectures (#34062)
Arseniy Obolenskiy154c2cc88d2f
diff --git a/src/plugins/intel_cpu/CMakeLists.txt b/src/plugins/intel_cpu/CMakeLists.txtindex 3fe7fa2c284..33648da88a8 100644--- a/src/plugins/intel_cpu/CMakeLists.txt+++ b/src/plugins/intel_cpu/CMakeLists.txt@@ -182,17 +182,11 @@ if(NOT X86_64)${CMAKE_CURRENT_SOURCE_DIR}/src/emitters/plugin/x64/*${CMAKE_CURRENT_SOURCE_DIR}/src/emitters/snippets/x64/*${CMAKE_CURRENT_SOURCE_DIR}/src/emitters/tpp/x64/*+ ${CMAKE_CURRENT_SOURCE_DIR}/src/transformations/snippets/x64/*${CMAKE_CURRENT_SOURCE_DIR}/src/transformations/cpu_opset/x64/*${CMAKE_CURRENT_SOURCE_DIR}/src/transformations/tpp/x64/*)endif()-if (AARCH64)- # this directory is reused on RISCV64- list(APPEND EXCLUDE_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/src/transformations/snippets/x64/*)-else()- list(APPEND EXCLUDE_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/src/nodes/executors/kleidiai/*)-endif()-if(NOT (AARCH64 OR ARM))list(APPEND EXCLUDE_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/src/transformations/cpu_opset/arm/*${CMAKE_CURRENT_SOURCE_DIR}/src/transformations/tpp/aarch64/*@@ -207,7 +201,8 @@ endif()if(NOT AARCH64)list(APPEND EXCLUDE_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/src/transformations/snippets/aarch64/*- ${CMAKE_CURRENT_SOURCE_DIR}/src/emitters/snippets/aarch64/*)+ ${CMAKE_CURRENT_SOURCE_DIR}/src/emitters/snippets/aarch64/*+ ${CMAKE_CURRENT_SOURCE_DIR}/src/nodes/executors/kleidiai/*)endif()if (NOT RISCV64)diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/shape_inference.cpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/shape_inference.cppindex 0e6b8ba24ce..ec3e84600a1 100644--- a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/shape_inference.cpp+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/shape_inference.cpp@@ -4,36 +4,17 @@#include "transformations/snippets/common/shape_inference.hpp"-#include <memory>--#include "openvino/core/node.hpp"-#include "openvino/core/type.hpp"#include "snippets/shape_inference/shape_infer_instances.hpp"#include "snippets/shape_inference/shape_inference.hpp"-#include "transformations/cpu_opset/common/op/swish_cpu.hpp"#include "transformations/snippets/aarch64/op/gemm_copy_b.hpp"#include "transformations/snippets/aarch64/op/gemm_cpu.hpp"-#include "transformations/snippets/common/op/fused_mul_add.hpp"-#include "transformations/tpp/common/op/brgemm.hpp"namespace ov::snippets {-using ShapeInferPtr = IShapeInferSnippetsFactory::ShapeInferPtr;--ShapeInferPtr CPUShapeInferSnippetsFactory::get_specific_op_shape_infer(const ov::DiscreteTypeInfo& key,- const std::shared_ptr<ov::Node>& op) const {- const auto& maker_iter = specific_ops_registry.find(key);- if (maker_iter != specific_ops_registry.end()) {- return maker_iter->second(op);- }- return {};-}--const CPUShapeInferSnippetsFactory::TRegistry CPUShapeInferSnippetsFactory::specific_ops_registry{- make_predefined<ov::intel_cpu::FusedMulAdd, NumpyBroadcastShapeInfer>(),- make_predefined<ov::intel_cpu::SwishNode, PassThroughShapeInfer>(),- make_specific_external<ov::intel_cpu::tpp::op::BrgemmTPP, BrgemmShapeInfer>(),- make_specific_external<ov::intel_cpu::aarch64::GemmCPU, BrgemmShapeInfer>(),- make_specific<ov::intel_cpu::aarch64::GemmCopyB>(),-};+const CPUShapeInferSnippetsFactory::TRegistry CPUShapeInferSnippetsFactory::specific_ops_registry = []() {+ auto registry = detail::make_common_cpu_shape_infer_registry();+ registry.insert(make_specific_external<ov::intel_cpu::aarch64::GemmCPU, BrgemmShapeInfer>());+ registry.insert(make_specific<ov::intel_cpu::aarch64::GemmCopyB>());+ return registry;+}();} // namespace ov::snippetsdiff --git a/src/plugins/intel_cpu/src/transformations/snippets/common/shape_inference.cpp b/src/plugins/intel_cpu/src/transformations/snippets/common/shape_inference.cppnew file mode 100644index 00000000000..c28c07f0d7f--- /dev/null+++ b/src/plugins/intel_cpu/src/transformations/snippets/common/shape_inference.cpp@@ -0,0 +1,62 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "transformations/snippets/common/shape_inference.hpp"++#include <memory>++#include "openvino/core/node.hpp"+#include "openvino/core/type.hpp"+#include "openvino/core/visibility.hpp"+#include "snippets/shape_inference/shape_infer_instances.hpp"+#include "snippets/shape_inference/shape_inference.hpp"+#include "transformations/cpu_opset/common/op/swish_cpu.hpp"+#include "transformations/snippets/common/op/fused_mul_add.hpp"++#ifdef SNIPPETS_LIBXSMM_TPP+# include "transformations/tpp/common/op/brgemm.hpp"+#endif++namespace ov::snippets {+using ShapeInferPtr = IShapeInferSnippetsFactory::ShapeInferPtr;++namespace detail {++IShapeInferSnippetsFactory::TRegistry make_common_cpu_shape_infer_registry() {+ const static IShapeInferSnippetsFactory::TRegistry registry{+ {ov::intel_cpu::FusedMulAdd::get_type_info_static(),+ [](const std::shared_ptr<ov::Node>&) {+ return std::make_shared<NumpyBroadcastShapeInfer>();+ }},+ {ov::intel_cpu::SwishNode::get_type_info_static(),+ [](const std::shared_ptr<ov::Node>&) {+ return std::make_shared<PassThroughShapeInfer>();+ }},+#ifdef SNIPPETS_LIBXSMM_TPP+ {ov::intel_cpu::tpp::op::BrgemmTPP::get_type_info_static(),+ [](const std::shared_ptr<ov::Node>& n) {+ return std::make_shared<BrgemmShapeInfer>(n);+ }},+#endif+ };+ return registry;+}++} // namespace detail++ShapeInferPtr CPUShapeInferSnippetsFactory::get_specific_op_shape_infer(const ov::DiscreteTypeInfo& key,+ const std::shared_ptr<ov::Node>& op) const {+ const auto& maker_iter = specific_ops_registry.find(key);+ if (maker_iter != specific_ops_registry.end()) {+ return maker_iter->second(op);+ }+ return {};+}++#if !defined(OPENVINO_ARCH_X86_64) && !defined(OPENVINO_ARCH_ARM64)+const CPUShapeInferSnippetsFactory::TRegistry CPUShapeInferSnippetsFactory::specific_ops_registry =+ detail::make_common_cpu_shape_infer_registry();+#endif++} // namespace ov::snippetsdiff --git a/src/plugins/intel_cpu/src/transformations/snippets/common/shape_inference.hpp b/src/plugins/intel_cpu/src/transformations/snippets/common/shape_inference.hppindex 64db9610b8a..8b005e8cd41 100644--- a/src/plugins/intel_cpu/src/transformations/snippets/common/shape_inference.hpp+++ b/src/plugins/intel_cpu/src/transformations/snippets/common/shape_inference.hpp@@ -12,6 +12,10 @@namespace ov::snippets {+namespace detail {+IShapeInferSnippetsFactory::TRegistry make_common_cpu_shape_infer_registry();+} // namespace detail+/*** \brief Shape infer factory that can create shape-infer instances for cpu-specific operations*/diff --git a/src/plugins/intel_cpu/src/transformations/snippets/x64/shape_inference.cpp b/src/plugins/intel_cpu/src/transformations/snippets/x64/shape_inference.cppindex 33081c2f5a0..36ccf0dc144 100644--- a/src/plugins/intel_cpu/src/transformations/snippets/x64/shape_inference.cpp+++ b/src/plugins/intel_cpu/src/transformations/snippets/x64/shape_inference.cpp@@ -4,7 +4,6 @@#include "transformations/snippets/common/shape_inference.hpp"-#include <memory>#include <snippets/shape_inference/shape_infer_instances.hpp>#include "op/brgemm_copy_b.hpp"@@ -12,43 +11,24 @@#include "op/load_convert.hpp"#include "op/perf_count_rdtsc.hpp"#include "op/store_convert.hpp"-#include "openvino/core/node.hpp"-#include "openvino/core/type.hpp"#include "snippets/shape_inference/shape_inference.hpp"-#include "transformations/cpu_opset/common/op/swish_cpu.hpp"-#include "transformations/snippets/common/op/fused_mul_add.hpp"-#ifdef SNIPPETS_LIBXSMM_TPP-# include "transformations/tpp/common/op/brgemm.hpp"-#endifnamespace ov::snippets {-using ShapeInferPtr = IShapeInferSnippetsFactory::ShapeInferPtr;--ShapeInferPtr CPUShapeInferSnippetsFactory::get_specific_op_shape_infer(const ov::DiscreteTypeInfo& key,- const std::shared_ptr<ov::Node>& op) const {- const auto& maker_iter = specific_ops_registry.find(key);- if (maker_iter != specific_ops_registry.end()) {- return maker_iter->second(op);- }- return {};-}+const CPUShapeInferSnippetsFactory::TRegistry CPUShapeInferSnippetsFactory::specific_ops_registry = []() {+ auto registry = detail::make_common_cpu_shape_infer_registry();-const CPUShapeInferSnippetsFactory::TRegistry CPUShapeInferSnippetsFactory::specific_ops_registry{- make_predefined<ov::intel_cpu::FusedMulAdd, NumpyBroadcastShapeInfer>(),- make_predefined<ov::intel_cpu::SwishNode, PassThroughShapeInfer>(),- make_predefined<ov::intel_cpu::LoadConvertSaturation, PassThroughShapeInfer>(),- make_predefined<ov::intel_cpu::LoadConvertTruncation, PassThroughShapeInfer>(),- make_predefined<ov::intel_cpu::StoreConvertSaturation, PassThroughShapeInfer>(),- make_predefined<ov::intel_cpu::StoreConvertTruncation, PassThroughShapeInfer>(),+ registry.insert(make_predefined<ov::intel_cpu::LoadConvertSaturation, PassThroughShapeInfer>());+ registry.insert(make_predefined<ov::intel_cpu::LoadConvertTruncation, PassThroughShapeInfer>());+ registry.insert(make_predefined<ov::intel_cpu::StoreConvertSaturation, PassThroughShapeInfer>());+ registry.insert(make_predefined<ov::intel_cpu::StoreConvertTruncation, PassThroughShapeInfer>());#ifdef SNIPPETS_DEBUG_CAPS- make_predefined<ov::intel_cpu::PerfCountRdtscBegin, EmptyShapeInfer>(),- make_predefined<ov::intel_cpu::PerfCountRdtscEnd, EmptyShapeInfer>(),+ registry.insert(make_predefined<ov::intel_cpu::PerfCountRdtscBegin, EmptyShapeInfer>());+ registry.insert(make_predefined<ov::intel_cpu::PerfCountRdtscEnd, EmptyShapeInfer>());#endif-#ifdef SNIPPETS_LIBXSMM_TPP- make_specific_external<ov::intel_cpu::tpp::op::BrgemmTPP, BrgemmShapeInfer>(),-#endif- make_specific_external<ov::intel_cpu::BrgemmCPU, BrgemmShapeInfer>(),- make_specific<ov::intel_cpu::BrgemmCopyB>(),-};+ registry.insert(make_specific_external<ov::intel_cpu::BrgemmCPU, BrgemmShapeInfer>());+ registry.insert(make_specific<ov::intel_cpu::BrgemmCopyB>());++ return registry;+}();} // namespace ov::snippets