Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[sns]Matmul via blockwised with kleidiai (#30534)

Chenhu Wang813b3ac907d3
diff --git a/src/common/snippets/include/snippets/utils/utils.hpp b/src/common/snippets/include/snippets/utils/utils.hpp
index d6520a89fc3..09ef1d1ba51 100644
--- a/src/common/snippets/include/snippets/utils/utils.hpp
+++ b/src/common/snippets/include/snippets/utils/utils.hpp
@@ -12,6 +12,7 @@
#include "snippets/shape_types.hpp"
#include "snippets/lowered/expression.hpp"
#include "snippets/lowered/expression_port.hpp"
+#include "snippets/lowered/port_descriptor.hpp"
#include "openvino/op/fake_quantize.hpp"
#include "openvino/op/constant.hpp"
@@ -40,6 +41,15 @@ constexpr inline bool is_full_dim_value(size_t value) {
return value == get_full_dim_value();
}
/* ---------------------- */
+template <typename T,
+ typename = typename std::enable_if<(std::is_same<T, ov::Output<Node>>::value ||
+ std::is_same<T, ov::Input<Node>>::value),
+ void>::type>
+void set_full_port_desc(const T& port, size_t rank = 2) {
+ const auto& shape_rank = port.get_partial_shape().size();
+ const std::vector<size_t> full_dim_subtensor(std::min(shape_rank, rank), ov::snippets::utils::get_full_dim_value());
+ ov::snippets::lowered::PortDescriptorUtils::set_port_descriptor(port, full_dim_subtensor);
+}
// Get non-scalar Constant count that will be created after FakeQuantize decomposition.
// This count is needed to know exact count of non-scalar Constants during tokenization.
diff --git a/src/plugins/intel_cpu/src/emitters/snippets/aarch64/cpu_generator.cpp b/src/plugins/intel_cpu/src/emitters/snippets/aarch64/cpu_generator.cpp
index b4776923814..2e76259afbf 100644
--- a/src/plugins/intel_cpu/src/emitters/snippets/aarch64/cpu_generator.cpp
+++ b/src/plugins/intel_cpu/src/emitters/snippets/aarch64/cpu_generator.cpp
@@ -9,6 +9,8 @@
#include "emitters/plugin/aarch64/jit_conversion_emitters.hpp"
#include "emitters/plugin/aarch64/jit_eltwise_emitters.hpp"
#include "emitters/snippets/aarch64/jit_fill_emitter.hpp"
+#include "emitters/snippets/aarch64/jit_gemm_copy_b_emitter.hpp"
+#include "emitters/snippets/aarch64/jit_gemm_emitter.hpp"
#include "emitters/snippets/aarch64/jit_kernel_emitter.hpp"
#include "emitters/snippets/aarch64/jit_loop_emitters.hpp"
#include "emitters/snippets/aarch64/jit_memory_emitters.hpp"
@@ -24,6 +26,8 @@
#include "snippets/lowered/expression.hpp"
#include "snippets/snippets_isa.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"
#ifdef SNIPPETS_LIBXSMM_TPP
@@ -155,6 +159,7 @@ CPUTargetMachine::CPUTargetMachine(dnnl::impl::cpu::aarch64::cpu_isa_t host_isa,
// data movement
jitters[op::v0::Parameter::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(jit_nop_emitter);
jitters[op::v0::Result::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(jit_nop_emitter);
+ jitters[snippets::op::Buffer::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(jit_nop_emitter);
jitters[snippets::op::VectorBuffer::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(jit_nop_emitter);
jitters[snippets::op::RankNormalization::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(jit_nop_emitter);
jitters[snippets::op::BroadcastMove::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(jit_broadcast_move_emitter);
@@ -217,7 +222,10 @@ CPUTargetMachine::CPUTargetMachine(dnnl::impl::cpu::aarch64::cpu_isa_t host_isa,
jitters[ov::op::v0::Sqrt::get_type_info_static()] = CREATE_CPU_EMITTER(jit_sqrt_emitter);
jitters[ov::intel_cpu::SwishNode::get_type_info_static()] = CREATE_CPU_EMITTER(jit_swish_emitter);
jitters[ov::op::v0::Tanh::get_type_info_static()] = CREATE_CPU_EMITTER(jit_tanh_emitter);
-
+ jitters[ov::intel_cpu::aarch64::GemmCPU::get_type_info_static()] =
+ CREATE_SNIPPETS_EMITTER(jit_gemm_emitter, configurator->get_kernel_executor_table());
+ jitters[ov::intel_cpu::aarch64::GemmCopyB::get_type_info_static()] =
+ CREATE_SNIPPETS_EMITTER(jit_gemm_copy_b_emitter, configurator->get_kernel_executor_table());
#ifdef SNIPPETS_LIBXSMM_TPP
// brgemm
jitters[ov::intel_cpu::tpp::op::BrgemmTPP::get_type_info_static()] =
@@ -321,7 +329,10 @@ std::shared_ptr<snippets::Generator> CPUGenerator::clone() const {
ov::snippets::RegType CPUGenerator::get_specific_op_out_reg_type(const ov::Output<ov::Node>& out) const {
const auto op = out.get_node_shared_ptr();
- if (ov::as_type_ptr<intel_cpu::FusedMulAdd>(op) || ov::as_type_ptr<intel_cpu::SwishNode>(op)) {
+ if (is_type_any_of<intel_cpu::aarch64::GemmCPU, intel_cpu::aarch64::GemmCopyB>(op)) {
+ return ov::snippets::RegType::gpr;
+ }
+ if (ov::is_type_any_of<intel_cpu::FusedMulAdd, intel_cpu::SwishNode>(op)) {
return ov::snippets::RegType::vec;
}
return ov::snippets::RegType::undefined;
diff --git a/src/plugins/intel_cpu/src/emitters/snippets/aarch64/jit_gemm_copy_b_emitter.cpp b/src/plugins/intel_cpu/src/emitters/snippets/aarch64/jit_gemm_copy_b_emitter.cpp
new file mode 100644
index 00000000000..357146cb1f1
--- /dev/null
+++ b/src/plugins/intel_cpu/src/emitters/snippets/aarch64/jit_gemm_copy_b_emitter.cpp
@@ -0,0 +1,81 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "jit_gemm_copy_b_emitter.hpp"
+
+#include "snippets/utils/utils.hpp"
+#include "transformations/snippets/aarch64/op/gemm_copy_b.hpp"
+#include "transformations/snippets/aarch64/op/gemm_utils.hpp"
+
+namespace ov::intel_cpu::aarch64 {
+
+using jit_generator = dnnl::impl::cpu::aarch64::jit_generator;
+using cpu_isa_t = dnnl::impl::cpu::aarch64::cpu_isa_t;
+using ExpressionPtr = ov::snippets::lowered::ExpressionPtr;
+
+jit_gemm_copy_b_emitter::jit_gemm_copy_b_emitter(jit_generator* h,
+ cpu_isa_t isa,
+ const ExpressionPtr& expr,
+ const snippets::KernelExecutorTablePtr& kernel_table)
+ : jit_emitter(h, isa) {
+ in_out_type_ = emitter_in_out_map::gpr_to_gpr;
+ const auto gemm_repack = ov::as_type_ptr<GemmCopyB>(expr->get_node());
+ OV_CPU_JIT_EMITTER_ASSERT(gemm_repack, "expects GemmCopyB node");
+ const auto& child_gemms = ov::intel_cpu::aarch64::gemm_utils::repacking::get_gemm_exprs(expr);
+ size_t n_blk_size = 0;
+ for (size_t i = 0; i < child_gemms.size(); i++) {
+ const auto& gemm_in1_subtensor =
+ ov::snippets::utils::get_projected_subtensor(child_gemms[i]->get_input_port(1));
+ const auto& current_block = *gemm_in1_subtensor.rbegin();
+ if (current_block != snippets::utils::get_dynamic_value<size_t>() && current_block > n_blk_size) {
+ n_blk_size = current_block;
+ }
+ }
+ OV_CPU_JIT_EMITTER_ASSERT(n_blk_size > 0, "n_blk_size of gemm_repack is expected to be greater than 0.");
+ GemmCopyBKernelKaiConfig kernel_config(n_blk_size);
+ m_kernel_executor = kernel_table->register_kernel<GemmCopyBKaiKernelExecutor>(expr, kernel_config);
+}
+
+std::set<std::vector<element::Type>> jit_gemm_copy_b_emitter::get_supported_precisions(
+ const std::shared_ptr<ov::Node>& node) {
+ // Note: Brgemm currently supports only fp32 on arm
+ return {{element::f32}};
+}
+
+void jit_gemm_copy_b_emitter::validate_arguments(const std::vector<size_t>& in, const std::vector<size_t>& out) const {
+ OV_CPU_JIT_EMITTER_ASSERT(in.size() == 1, "Expects 1 input reg, got", in.size());
+ OV_CPU_JIT_EMITTER_ASSERT(out.size() == 1, "Expects 1 output reg, got", out.size());
+}
+
+void jit_gemm_copy_b_emitter::emit_impl(const std::vector<size_t>& in, const std::vector<size_t>& out) const {
+ validate_arguments(in, out);
+ // todo: use optimized reg spill after CVS-162498
+ std::unordered_set<size_t> exclude = {};
+ store_context(exclude);
+
+ Xbyak_aarch64::XReg x0(0);
+ Xbyak_aarch64::XReg x1(1);
+ Xbyak_aarch64::XReg x2(2);
+ h->str(Xbyak_aarch64::XReg(in[0]), pre_ptr(h->sp, -get_vec_length()));
+ h->str(Xbyak_aarch64::XReg(out[0]), pre_ptr(h->sp, -get_vec_length()));
+ h->ldr(x2, post_ptr(h->sp, get_vec_length()));
+ h->ldr(x1, post_ptr(h->sp, get_vec_length()));
+ const auto& compiled_kernel = get_compiled_kernel_ptr();
+ h->mov(x0, compiled_kernel);
+
+ Xbyak_aarch64::XReg func_reg(9);
+ h->mov(func_reg, get_execute_function_ptr());
+ h->blr(func_reg);
+
+ restore_context(exclude);
+}
+
+const uintptr_t jit_gemm_copy_b_emitter::get_compiled_kernel_ptr() const {
+ return reinterpret_cast<const uintptr_t>(m_kernel_executor.get());
+}
+
+const uintptr_t jit_gemm_copy_b_emitter::get_execute_function_ptr() const {
+ return reinterpret_cast<const uintptr_t>(GemmCopyBKaiKernelExecutor::execute);
+}
+} // namespace ov::intel_cpu::aarch64
\ No newline at end of file
diff --git a/src/plugins/intel_cpu/src/emitters/snippets/aarch64/jit_gemm_copy_b_emitter.hpp b/src/plugins/intel_cpu/src/emitters/snippets/aarch64/jit_gemm_copy_b_emitter.hpp
new file mode 100644
index 00000000000..cb069fb9291
--- /dev/null
+++ b/src/plugins/intel_cpu/src/emitters/snippets/aarch64/jit_gemm_copy_b_emitter.hpp
@@ -0,0 +1,35 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "emitters/plugin/aarch64/jit_emitter.hpp"
+#include "emitters/snippets/aarch64/kernel_executors/gemm_copy_b.hpp"
+
+namespace ov::intel_cpu::aarch64 {
+class jit_gemm_copy_b_emitter : public jit_emitter {
+public:
+ jit_gemm_copy_b_emitter(dnnl::impl::cpu::aarch64::jit_generator* h,
+ dnnl::impl::cpu::aarch64::cpu_isa_t isa,
+ const ov::snippets::lowered::ExpressionPtr& expr,
+ const snippets::KernelExecutorTablePtr& kernel_table);
+
+ size_t get_inputs_count() const override {
+ return 1;
+ }
+
+ static std::set<std::vector<element::Type>> get_supported_precisions(
+ const std::shared_ptr<ov::Node>& node = nullptr);
+
+protected:
+ void validate_arguments(const std::vector<size_t>& in, const std::vector<size_t>& out) const override;
+ void emit_impl(const std::vector<size_t>& in, const std::vector<size_t>& out) const override;
+
+ const uintptr_t get_execute_function_ptr() const;
+ const uintptr_t get_compiled_kernel_ptr() const;
+
+ std::shared_ptr<GemmCopyBKaiKernelExecutor> m_kernel_executor = nullptr;
+};
+
+} // namespace ov::intel_cpu::aarch64
\ No newline at end of file
diff --git a/src/plugins/intel_cpu/src/emitters/snippets/aarch64/jit_gemm_emitter.cpp b/src/plugins/intel_cpu/src/emitters/snippets/aarch64/jit_gemm_emitter.cpp
new file mode 100644
index 00000000000..0956daf21a5
--- /dev/null
+++ b/src/plugins/intel_cpu/src/emitters/snippets/aarch64/jit_gemm_emitter.cpp
@@ -0,0 +1,71 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "jit_gemm_emitter.hpp"
+
+#include "snippets/utils/utils.hpp"
+
+using namespace Xbyak_aarch64;
+
+namespace ov::intel_cpu::aarch64 {
+
+using jit_generator = dnnl::impl::cpu::aarch64::jit_generator;
+using cpu_isa_t = dnnl::impl::cpu::aarch64::cpu_isa_t;
+using ExpressionPtr = ov::snippets::lowered::ExpressionPtr;
+
+jit_gemm_emitter::jit_gemm_emitter(jit_generator* h,
+ cpu_isa_t isa,
+ const ExpressionPtr& expr,
+ const snippets::KernelExecutorTablePtr& kernel_table)
+ : jit_emitter(h, isa) {
+ in_out_type_ = emitter_in_out_map::gpr_to_gpr;
+ GemmKernelKaiConfig kernel_config;
+ m_kernel_executor_kai = kernel_table->register_kernel<GemmKaiKernelExecutor>(expr, kernel_config);
+}
+
+std::set<std::vector<element::Type>> jit_gemm_emitter::get_supported_precisions(const std::shared_ptr<ov::Node>& node) {
+ // Note: currently supports only fp32 on arm
+ return {{element::f32, element::f32}};
+}
+
+void jit_gemm_emitter::validate_arguments(const std::vector<size_t>& in, const std::vector<size_t>& out) const {
+ OV_CPU_JIT_EMITTER_ASSERT(in.size() == 2, "Expects 2 input regs, got", in.size());
+ OV_CPU_JIT_EMITTER_ASSERT(out.size() == 1, "Expects 1 output reg, got", out.size());
+}
+
+void jit_gemm_emitter::emit_impl(const std::vector<size_t>& in, const std::vector<size_t>& out) const {
+ validate_arguments(in, out);
+ // todo: use optimized reg spill after CVS-162498
+ std::unordered_set<size_t> exclude = {};
+ store_context(exclude);
+
+ Xbyak_aarch64::XReg x0(0);
+ Xbyak_aarch64::XReg x1(1);
+ Xbyak_aarch64::XReg x2(2);
+ Xbyak_aarch64::XReg x3(3);
+ h->str(Xbyak_aarch64::XReg(in[0]), pre_ptr(h->sp, -get_vec_length()));
+ h->str(Xbyak_aarch64::XReg(in[1]), pre_ptr(h->sp, -get_vec_length()));
+ h->str(Xbyak_aarch64::XReg(out[0]), pre_ptr(h->sp, -get_vec_length()));
+ h->ldr(x3, post_ptr(h->sp, get_vec_length()));
+ h->ldr(x2, post_ptr(h->sp, get_vec_length()));
+ h->ldr(x1, post_ptr(h->sp, get_vec_length()));
+ const auto& compiled_kernel = get_compiled_kernel_ptr();
+ h->mov(x0, compiled_kernel);
+
+ Xbyak_aarch64::XReg func_reg(9);
+ h->mov(func_reg, get_execute_function_ptr());
+ h->blr(func_reg);
+
+ restore_context(exclude);
+}
+
+const uintptr_t jit_gemm_emitter::get_compiled_kernel_ptr() const {
+ return reinterpret_cast<const uintptr_t>(m_kernel_executor_kai.get());
+}
+
+const uintptr_t jit_gemm_emitter::get_execute_function_ptr() const {
+ return reinterpret_cast<const uintptr_t>(GemmKaiKernelExecutor::execute);
+}
+
+} // namespace ov::intel_cpu::aarch64
diff --git a/src/plugins/intel_cpu/src/emitters/snippets/aarch64/jit_gemm_emitter.hpp b/src/plugins/intel_cpu/src/emitters/snippets/aarch64/jit_gemm_emitter.hpp
new file mode 100644
index 00000000000..9a157c2085d
--- /dev/null
+++ b/src/plugins/intel_cpu/src/emitters/snippets/aarch64/jit_gemm_emitter.hpp
@@ -0,0 +1,37 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "emitters/plugin/aarch64/jit_emitter.hpp"
+#include "emitters/snippets/aarch64/kernel_executors/gemm.hpp"
+#include "emitters/snippets/brgemm_generic.hpp"
+
+namespace ov::intel_cpu::aarch64 {
+
+class jit_gemm_emitter : public jit_emitter {
+public:
+ jit_gemm_emitter(dnnl::impl::cpu::aarch64::jit_generator* h,
+ dnnl::impl::cpu::aarch64::cpu_isa_t isa,
+ const ov::snippets::lowered::ExpressionPtr& expr,
+ const snippets::KernelExecutorTablePtr& kernel_table);
+
+ size_t get_inputs_count() const override {
+ return 2;
+ }
+
+ static std::set<std::vector<element::Type>> get_supported_precisions(
+ const std::shared_ptr<ov::Node>& node = nullptr);
+
+protected:
+ void validate_arguments(const std::vector<size_t>& in, const std::vector<size_t>& out) const override;
+ void emit_impl(const std::vector<size_t>& in, const std::vector<size_t>& out) const override;
+
+ const uintptr_t get_execute_function_ptr() const;
+ const uintptr_t get_compiled_kernel_ptr() const;
+
+ std::shared_ptr<GemmKaiKernelExecutor> m_kernel_executor_kai = nullptr;
+};
+
+} // namespace ov::intel_cpu::aarch64
diff --git a/src/plugins/intel_cpu/src/emitters/snippets/aarch64/kernel_executors/gemm.cpp b/src/plugins/intel_cpu/src/emitters/snippets/aarch64/kernel_executors/gemm.cpp
new file mode 100644
index 00000000000..637109403f1
--- /dev/null
+++ b/src/plugins/intel_cpu/src/emitters/snippets/aarch64/kernel_executors/gemm.cpp
@@ -0,0 +1,87 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "gemm.hpp"
+
+#include "openvino/core/parallel.hpp"
+#include "transformations/snippets/aarch64/op/gemm_utils.hpp"
+#include "transformations/tpp/common/op/brgemm.hpp"
+
+namespace ov::intel_cpu::aarch64 {
+
+void GemmKernelKaiConfig::update(int64_t M, int64_t N, int64_t K, int64_t LDA, int64_t LDB, int64_t LDC, float beta) {
+ BrgemmGenericKernelConfig::update(M, N, K, LDA, LDB, LDC, beta);
+ m_hash = BrgemmGenericKernelConfig::compute_hash();
+}
+
+bool GemmKernelKaiConfig::operator==(const GemmKernelKaiConfig& rhs) const {
+ return BrgemmGenericKernelConfig::operator==(rhs) && m_hash == rhs.m_hash;
+}
+
+GemmKaiKernelExecutor::GemmKaiKernelExecutor(GemmKernelKaiConfig config)
+ : snippets::KernelExecutor<GemmKernelKaiConfig, GemmCompiledKernel>(std::move(config)) {}
+
+void GemmKaiKernelExecutor::update_kernel(const GemmKernelKaiConfig& config,
+ std::shared_ptr<GemmCompiledKernel>& kernel) const {
+ if (kernel == nullptr) {
+ // universal kernel could be used in any config and shape, as excuted peice by peice as binary call.
+ // config is passed as binary call parameters.
+ kernel = std::make_shared<GemmCompiledKernel>();
+ }
+}
+
+void GemmKaiKernelExecutor::update_config(const ov::snippets::lowered::ExpressionPtr& expr,
+ const ov::snippets::lowered::LinearIRCPtr& linear_ir,
+ GemmKernelKaiConfig& config) const {
+ const auto [M, N, K, beta] = BrgemmKernelExecutorHelper::get_runtime_brgemm_params(expr, linear_ir);
+
+ const auto LDA = snippets::utils::get_dim_stride(expr->get_input_port(0));
+ const auto LDC = snippets::utils::get_dim_stride(expr->get_output_port(0));
+ const auto LDB = snippets::utils::get_dim_stride(expr->get_input_port(1));
+ config.update(M, N, K, LDA, LDB, LDC, beta);
+}
+
+void GemmKaiKernelExecutor::execute(const GemmKaiKernelExecutor* executor, void* in0, void* in1, void* out0) {
+ OV_CPU_JIT_EMITTER_ASSERT(executor, "has nullptr executor");
+ // matmul for input1 and slices of repacked input2
+ const auto& config = static_cast<const GemmKernelKaiConfig&>(executor->get_config());
+ const auto& kernel = executor->get_kernel();
+ const auto& ukernel = *kernel->gemm_ukernel;
+ const auto& M = config.get_M();
+ const auto& N = config.get_N();
+ const auto& K = config.get_K();
+ const auto& lda = config.get_LDA();
+ const auto& ldc = config.get_LDC();
+ const size_t& BLOCK_SIZE = ov::intel_cpu::aarch64::gemm_utils::repacking::get_inner_n_block(element::f32);
+ size_t n_blocks = ov::snippets::utils::div_up(N, BLOCK_SIZE);
+ const size_t lhs_stride = lda * sizeof(float); // K not split, it's also K * sizeof(float)
+ const size_t dst_stride_row = ldc * sizeof(float);
+ const size_t dst_stride_col = sizeof(float);
+ for (size_t n_block = 0; n_block < n_blocks; n_block++) {
+ size_t n_start = n_block * BLOCK_SIZE;
+ size_t n_end = std::min(n_start + BLOCK_SIZE, static_cast<size_t>(N));
+ size_t n_block_size = n_end - n_start;
+ // rhs_packed_offset is n_start*(k+1), as packed mem as 8*(K+1) blocks. If k blocked, then lda.
+ const size_t rhs_packed_offset = ukernel.get_rhs_packed_offset(n_start, K);
+ // m_idx is 0 as dst already point current block.
+ const size_t dst_offset = ukernel.get_dst_offset(0, n_start, dst_stride_row);
+ // in0, in1, out is point to current block memory, based on block loop info, and shift done in loop begin and
+ // end emitters(adjusted copyb loop info as repack outside block loops).
+ float* rhs_ptr = static_cast<float*>(in1) + rhs_packed_offset / sizeof(float);
+ float* dst_ptr = (static_cast<float*>(out0) + dst_offset / (sizeof(float)));
+ ukernel.run_matmul(M,
+ n_block_size,
+ K,
+ in0,
+ lhs_stride,
+ rhs_ptr,
+ dst_ptr,
+ dst_stride_row,
+ dst_stride_col,
+ std::numeric_limits<float>::min(),
+ std::numeric_limits<float>::max());
+ }
+}
+
+} // namespace ov::intel_cpu::aarch64
diff --git a/src/plugins/intel_cpu/src/emitters/snippets/aarch64/kernel_executors/gemm.hpp b/src/plugins/intel_cpu/src/emitters/snippets/aarch64/kernel_executors/gemm.hpp
new file mode 100644
index 00000000000..6c053ce2629
--- /dev/null
+++ b/src/plugins/intel_cpu/src/emitters/snippets/aarch64/kernel_executors/gemm.hpp
@@ -0,0 +1,72 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "emitters/snippets/brgemm_generic.hpp"
+#include "emitters/utils.hpp"
+#include "kai/ukernels/matmul/matmul_clamp_f32_f32_f32p/kai_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla.h"
+#include "kai/ukernels/matmul/matmul_clamp_f32_f32_f32p/kai_matmul_clamp_f32_f32_f32p_interface.h"
+#include "kai/ukernels/matmul/pack/kai_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon.h"
+
+namespace ov::intel_cpu::aarch64 {
+
+struct GemmKernelKaiConfig : public BrgemmGenericKernelConfig {
+public:
+ GemmKernelKaiConfig() = default;
+
+ bool operator==(const GemmKernelKaiConfig& rhs) const;
+ bool operator!=(const GemmKernelKaiConfig& rhs) const {
+ return !(*this == rhs);
+ }
+
+ void update(int64_t M, int64_t N, int64_t K, int64_t LDA, int64_t LDB, int64_t LDC, float beta) override;
+
+ std::unique_ptr<snippets::KernelExecutorBase::GenericConfig> get_clone_ptr() const override {
+ return std::make_unique<GemmKernelKaiConfig>(*this);
+ }
+
+ size_t hash() const override {
+ return m_hash;
+ }
+
+private:
+ size_t m_hash{SIZE_MAX};
+};
+
+struct GemmCompiledKernel {
+ std::shared_ptr<kai_matmul_clamp_f32_f32_f32p_ukernel> gemm_ukernel =
+ std::make_shared<kai_matmul_clamp_f32_f32_f32p_ukernel>(ukernel);
+
+ static constexpr kai_matmul_clamp_f32_f32_f32p_ukernel ukernel{
+ kai_get_m_step_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla,
+ kai_get_n_step_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla,
+ kai_get_nr_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla,
+ kai_get_kr_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla,
+ kai_get_sr_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla,
+ kai_get_lhs_offset_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla,
+ kai_get_rhs_packed_offset_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla,
+ kai_get_dst_offset_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla,
+ kai_get_dst_size_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla,
+ kai_run_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla};
+};
+
+class GemmKaiKernelExecutor : public snippets::KernelExecutor<GemmKernelKaiConfig, GemmCompiledKernel> {
+public:
+ GemmKaiKernelExecutor(GemmKernelKaiConfig config);
+
+ // No need kernel update, just update config is enough for update. The universal ukernel is reused with any config.
+ void update_kernel(const GemmKernelKaiConfig& config,
+ std::shared_ptr<GemmCompiledKernel>& kernel) const override final;
+
+ // Function that will be called in runtime to execute the kernel
+ static void execute(const GemmKaiKernelExecutor* executor, void* in0, void* in1, void* out0);
+
+private:
+ void update_config(const ov::snippets::lowered::ExpressionPtr& expr,
+ const ov::snippets::lowered::LinearIRCPtr& linear_ir,
+ GemmKernelKaiConfig& config) const override;
+};
+
+} // namespace ov::intel_cpu::aarch64
\ No newline at end of file
diff --git a/src/plugins/intel_cpu/src/emitters/snippets/aarch64/kernel_executors/gemm_copy_b.cpp b/src/plugins/intel_cpu/src/emitters/snippets/aarch64/kernel_executors/gemm_copy_b.cpp
new file mode 100644
index 00000000000..df25091491b
--- /dev/null
+++ b/src/plugins/intel_cpu/src/emitters/snippets/aarch64/kernel_executors/gemm_copy_b.cpp
@@ -0,0 +1,155 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "gemm_copy_b.hpp"
+
+#include "openvino/core/parallel.hpp"
+#include "snippets/utils/utils.hpp"
+#include "transformations/snippets/aarch64/op/gemm_utils.hpp"
+#include "transformations/tpp/common/op/brgemm.hpp"
+
+namespace ov::intel_cpu::aarch64 {
+
+GemmCopyBKernelKaiConfig::GemmCopyBKernelKaiConfig(const size_t n_blk_size)
+ : m_static_params(std::make_shared<StaticParams>(n_blk_size)) {
+ OPENVINO_ASSERT(n_blk_size != 0, "n_blk_size can not be zero in GemmCopyBKernelKaiConfig.");
+ m_hash = compute_hash();
+}
+
+bool GemmCopyBKernelKaiConfig::operator==(const GemmCopyBKernelKaiConfig& rhs) const {
+ return m_N == rhs.m_N && m_K == rhs.m_K && m_hash == rhs.m_hash &&
+ (m_static_params == rhs.m_static_params || *m_static_params == *(rhs.m_static_params));
+}
+
+bool GemmCopyBKernelKaiConfig::is_completed() const {
+ return !ov::snippets::utils::one_of(0ul, m_N, m_K) || is_empty();
+}
+
+bool GemmCopyBKernelKaiConfig::is_empty() const {
+ return everyone_is(0ul, m_N, m_K);
+}
+
+#ifdef SNIPPETS_DEBUG_CAPS
+# define PRINT(X) ss << #X << " = " << (X) << "\n"
+std::string GemmCopyBKernelKaiConfig::to_string() const {
+ std::stringstream ss;
+ ss << m_static_params->to_string() << "\n";
+ PRINT(m_N);
+ PRINT(m_K);
+ return ss.str();
+}
+# undef PRINT
+#endif
+
+void GemmCopyBKernelKaiConfig::update(size_t N, size_t K) {
+ // If one of the dims is zero, it means that GemmCopyB won't be executed (in Loop with work_amount = 0, for
+ // example) To process this case, we have to make this Config as empty (nullify runtime parameters)
+ if (ov::snippets::utils::one_of(0ul, N, K)) {
+ m_N = 0;
+ m_K = 0;
+ } else {
+ m_N = N;
+ m_K = K;
+ }
+ m_hash = compute_hash();
+}
+
+size_t GemmCopyBKernelKaiConfig::compute_hash() const {
+ size_t seed = m_static_params->hash;
+ seed = dnnl::impl::hash_combine(seed, m_N);
+ seed = dnnl::impl::hash_combine(seed, m_K);
+ return seed;
+}
+
+GemmCopyBKernelKaiConfig::StaticParams::StaticParams(size_t wei_n_blk)
+ : wei_N_blk(wei_n_blk),
+ hash(init_hash(wei_N_blk)) {}
+
+bool GemmCopyBKernelKaiConfig::StaticParams::operator==(const StaticParams& rhs) const {
+ return wei_N_blk == rhs.wei_N_blk && hash == rhs.hash;
+}
+
+size_t GemmCopyBKernelKaiConfig::StaticParams::init_hash(size_t wei_n_blk) {
+ size_t seed = 0;
+ seed = dnnl::impl::hash_combine(seed, wei_n_blk);
+ return seed;
+}
+
+#ifdef SNIPPETS_DEBUG_CAPS
+# define PRINT(X) ss << #X << " = " << (X) << "\n"
+std::string GemmCopyBKernelKaiConfig::StaticParams::to_string() const {
+ std::stringstream ss;
+ PRINT(wei_N_blk);
+ return ss.str();
+}
+# undef PRINT
+#endif
+
+GemmCopyBKaiKernelExecutor::GemmCopyBKaiKernelExecutor(GemmCopyBKernelKaiConfig config)
+ : snippets::KernelExecutor<GemmCopyBKernelKaiConfig, GemmCopyBCompiledKernel>(std::move(config)) {}
+
+void GemmCopyBKaiKernelExecutor::update_kernel(const GemmCopyBKernelKaiConfig& config,
+ std::shared_ptr<GemmCopyBCompiledKernel>& kernel) const {
+ if (kernel == nullptr) {
+ // GemmCopyBCompiledKernel is an universal kernel, which could be used in any config and shape.
+ // 1. It's executed block by block with binary call and config passed as parameters.
+ // 2. In each block, at most n_blk_size bias is needed. n_blk_size is a fixed value in gemm blocking pass.
+ // if N block size changed in gemm blocking in future and based on shape, bias_buffer should be updated
+ kernel = std::make_shared<GemmCopyBCompiledKernel>();
+ const auto& n_blk_size = config.get_n_blk_size();
+ kernel->bias_buffer->resize(n_blk_size * sizeof(float), 0);
+ }
+}
+
+void GemmCopyBKaiKernelExecutor::update_config(const ov::snippets::lowered::ExpressionPtr& expr,
+ const ov::snippets::lowered::LinearIRCPtr& linear_ir,
+ GemmCopyBKernelKaiConfig& config) const {
+ const auto& in0_shape = snippets::utils::get_planar_vdims(expr->get_input_port(0));
+ int64_t N = *in0_shape.rbegin();
+ int64_t K = *++in0_shape.rbegin();
+ config.update(N, K);
+}
+
+// regarding K*N(32*516),
+// for K*N(32*512) part and nb(n_block-64), repack each nb block(32*64) to nb(K+1)8nb.
+// for K*N(32*4) part, roundup to (32+1)*8.
+void GemmCopyBKaiKernelExecutor::execute(const GemmCopyBKaiKernelExecutor* executor, void* in0, void* out0) {
+ OV_CPU_JIT_EMITTER_ASSERT(executor, "has nullptr executor");
+ // rhs is input, rhs_packed is output
+ const auto& config = static_cast<const GemmCopyBKernelKaiConfig&>(executor->get_config());
+ const auto& kernel = executor->get_kernel();
+ const auto& ukernel = kernel->copy_b_ukernel;
+ const auto K = config.get_K(); // K
+ const auto N = config.get_N(); // N-rhs_stride
+ const auto& n_blk_size = config.get_n_blk_size(); // n_blk
+ const size_t nr = ukernel->get_nr();
+ const size_t kr = ukernel->get_kr();
+ const size_t sr = ukernel->get_sr();
+ size_t n_blocks = ov::snippets::utils::div_up(N, n_blk_size);
+ size_t dst_offset = 0;
+ const size_t rhsPackedSize = kai_get_rhs_packed_size_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon(n_blk_size, K);
+ for (size_t n_block = 0; n_block < n_blocks; n_block++) {
+ size_t n_start = n_block * n_blk_size;
+ size_t n_end = std::min(n_start + n_blk_size, N);
+ size_t n_step = n_end - n_start;
+ int8_t* src_ptr = static_cast<int8_t*>(in0) + n_start * sizeof(int32_t);
+ int8_t* dst_ptr = static_cast<int8_t*>(out0) + dst_offset;
+ dst_offset += rhsPackedSize;
+ kai_run_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon(1,
+ n_step,
+ K,
+ nr,
+ kr,
+ sr, // Packing arguments
+ N * sizeof(float), // RHS stride
+ src_ptr, // RHS
+ kernel->bias_buffer->data(), // bias
+ nullptr, // Scale
+ dst_ptr, // RHS packed
+ 0,
+ nullptr);
+ }
+}
+
+} // namespace ov::intel_cpu::aarch64
diff --git a/src/plugins/intel_cpu/src/emitters/snippets/aarch64/kernel_executors/gemm_copy_b.hpp b/src/plugins/intel_cpu/src/emitters/snippets/aarch64/kernel_executors/gemm_copy_b.hpp
new file mode 100644
index 00000000000..b309aaef7e7
--- /dev/null
+++ b/src/plugins/intel_cpu/src/emitters/snippets/aarch64/kernel_executors/gemm_copy_b.hpp
@@ -0,0 +1,116 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "common/utils.hpp"
+#include "cpu_memory.h"
+#include "emitters/snippets/brgemm_generic.hpp"
+#include "emitters/utils.hpp"
+#include "kai/ukernels/matmul/matmul_clamp_f32_f32_f32p/kai_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla.h"
+#include "kai/ukernels/matmul/matmul_clamp_f32_f32_f32p/kai_matmul_clamp_f32_f32_f32p_interface.h"
+#include "kai/ukernels/matmul/pack/kai_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon.h"
+
+namespace ov::intel_cpu::aarch64 {
+
+struct GemmCopyBKernelKaiConfig : public snippets::KernelExecutorBase::GenericConfig {
+public:
+ GemmCopyBKernelKaiConfig() = default;
+ GemmCopyBKernelKaiConfig(const size_t n_blk_size);
+
+ bool operator==(const GemmCopyBKernelKaiConfig& rhs) const;
+ bool operator!=(const GemmCopyBKernelKaiConfig& rhs) const {
+ return !(*this == rhs);
+ }
+
+ [[nodiscard]] std::unique_ptr<GenericConfig> get_clone_ptr() const override {
+ return std::make_unique<GemmCopyBKernelKaiConfig>(*this);
+ }
+
+ [[nodiscard]] bool is_completed() const override;
+ [[nodiscard]] bool is_empty() const;
+
+#ifdef SNIPPETS_DEBUG_CAPS
+ virtual std::string to_string() const override;
+#endif
+
+ void update(size_t N, size_t K);
+
+ size_t hash() const override {
+ return m_hash;
+ }
+
+ [[nodiscard]] size_t get_N() const {
+ return m_N;
+ }
+ [[nodiscard]] size_t get_K() const {
+ return m_K;
+ }
+ [[nodiscard]] size_t get_n_blk_size() const {
+ return m_static_params->wei_N_blk;
+ }
+
+private:
+ struct StaticParams {
+ StaticParams(size_t wei_n_blk);
+
+ const size_t wei_N_blk{0};
+ const size_t hash{0};
+
+ bool operator==(const StaticParams& rhs) const;
+ bool operator!=(const StaticParams& rhs) const {
+ return !(*this == rhs);
+ }
+
+#ifdef SNIPPETS_DEBUG_CAPS
+ [[nodiscard]] std::string to_string() const;
+#endif
+
+ private:
+ static size_t init_hash(size_t wei_n_blk);
+ };
+
+ [[nodiscard]] size_t compute_hash() const;
+
+ std::shared_ptr<StaticParams> m_static_params;
+ size_t m_N = 0;
+ size_t m_K = 0;
+ size_t m_hash{SIZE_MAX};
+};
+
+struct GemmCopyBCompiledKernel {
+ std::shared_ptr<kai_matmul_clamp_f32_f32_f32p_ukernel> copy_b_ukernel =
+ std::make_shared<kai_matmul_clamp_f32_f32_f32p_ukernel>(ukernel);
+ std::shared_ptr<std::vector<uint8_t>> bias_buffer = std::make_shared<std::vector<uint8_t>>();
+
+ static constexpr kai_matmul_clamp_f32_f32_f32p_ukernel ukernel{
+ kai_get_m_step_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla,
+ kai_get_n_step_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla,
+ kai_get_nr_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla,
+ kai_get_kr_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla,
+ kai_get_sr_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla,
+ kai_get_lhs_offset_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla,
+ kai_get_rhs_packed_offset_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla,
+ kai_get_dst_offset_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla,
+ kai_get_dst_size_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla,
+ kai_run_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla};
+};
+
+class GemmCopyBKaiKernelExecutor : public snippets::KernelExecutor<GemmCopyBKernelKaiConfig, GemmCopyBCompiledKernel> {
+public:
+ GemmCopyBKaiKernelExecutor(GemmCopyBKernelKaiConfig config);
+
+ void update_kernel(const GemmCopyBKernelKaiConfig& config,
+ std::shared_ptr<GemmCopyBCompiledKernel>& kernel) const override final;
+
+ // Function that will be called in runtime to execute the kernel
+ static void execute(const GemmCopyBKaiKernelExecutor* executor, void* in0, void* out0);
+
+private:
+ void update_config(const ov::snippets::lowered::ExpressionPtr& expr,
+ const ov::snippets::lowered::LinearIRCPtr& linear_ir,
+ GemmCopyBKernelKaiConfig& config) const override;
+};
+
+} // namespace ov::intel_cpu::aarch64
diff --git a/src/plugins/intel_cpu/src/emitters/snippets/cpu_runtime_configurator.cpp b/src/plugins/intel_cpu/src/emitters/snippets/cpu_runtime_configurator.cpp
index 781f3fe564d..c15a95ed760 100644
--- a/src/plugins/intel_cpu/src/emitters/snippets/cpu_runtime_configurator.cpp
+++ b/src/plugins/intel_cpu/src/emitters/snippets/cpu_runtime_configurator.cpp
@@ -27,6 +27,9 @@
# include "transformations/snippets/x64/pass/lowered/brgemm_copy_b_loop_ports_adjuster.hpp"
# include "transformations/snippets/x64/pass/lowered/external_repacking_adjuster.hpp"
#endif
+#ifdef OPENVINO_ARCH_ARM64
+# include "transformations/snippets/aarch64/pass/lowered/gemm_copy_b_loop_ports_adjuster.hpp"
+#endif
namespace ov::intel_cpu {
using namespace ov::snippets::lowered::pass;
@@ -68,6 +71,11 @@ void CPURuntimeConfigurator::initialization(const ov::snippets::lowered::LinearI
RuntimeOptimizer::register_if_applicable<BrgemmCopyBLoopPortsAdjuster>(m_intermediate_optimizers, linear_ir, this);
RuntimeOptimizer::register_if_applicable<BrgemmExternalRepackingAdjuster>(m_final_optimizers, linear_ir, this);
#endif
+#ifdef OPENVINO_ARCH_ARM64
+ RuntimeOptimizer::register_if_applicable<pass::aarch64::GemmCopyBLoopPortsAdjuster>(m_intermediate_optimizers,
+ linear_ir,
+ this);
+#endif
}
void CPURuntimeConfigurator::update(const ov::snippets::lowered::LinearIRCPtr& linear_ir) {
diff --git a/src/plugins/intel_cpu/src/extension.cpp b/src/plugins/intel_cpu/src/extension.cpp
index c181abda6ca..4e6fde3fac2 100644
--- a/src/plugins/intel_cpu/src/extension.cpp
+++ b/src/plugins/intel_cpu/src/extension.cpp
@@ -96,6 +96,10 @@
#include "transformations/cpu_opset/x64/op/interaction.hpp"
#include "transformations/cpu_opset/x64/op/llm_mlp.hpp"
#include "transformations/cpu_opset/x64/op/qkv_proj.hpp"
+#if defined(OPENVINO_ARCH_ARM64)
+# include "transformations/snippets/aarch64/op/gemm_copy_b.hpp"
+# include "transformations/snippets/aarch64/op/gemm_cpu.hpp"
+#endif
#include "transformations/snippets/x64/op/brgemm_copy_b.hpp"
#include "transformations/snippets/x64/op/brgemm_cpu.hpp"
#include "transformations/snippets/x64/op/load_convert.hpp"
@@ -141,6 +145,12 @@ private:
# define OP_EXTENSION_X64(x)
#endif
+#if defined(OPENVINO_ARCH_ARM64)
+# define OP_EXTENSION_ARM64(x) x,
+#else
+# define OP_EXTENSION_ARM64(x)
+#endif
+
#if defined(SNIPPETS_DEBUG_CAPS)
# define OP_EXTENSION_SNIPPETS_DEBUG_CAPS(x) x,
#else
@@ -185,6 +195,8 @@ OPENVINO_CREATE_EXTENSIONS(std::vector<ov::Extension::Ptr>({
OP_EXTENSION_X64(std::make_shared<ov::OpExtension<ov::intel_cpu::StoreConvertTruncation>>())
OP_EXTENSION_X64(std::make_shared<ov::OpExtension<ov::intel_cpu::BrgemmCPU>>())
OP_EXTENSION_X64(std::make_shared<ov::OpExtension<ov::intel_cpu::BrgemmCopyB>>())
+ OP_EXTENSION_ARM64(std::make_shared<ov::OpExtension<ov::intel_cpu::aarch64::GemmCPU>>())
+ OP_EXTENSION_ARM64(std::make_shared<ov::OpExtension<ov::intel_cpu::aarch64::GemmCopyB>>())
// clang-format on
std::make_shared<TypeRelaxedExtension<ov::op::v1::Add>>(),
std::make_shared<TypeRelaxedExtension<ov::op::v1::AvgPool>>(),
diff --git a/src/plugins/intel_cpu/src/nodes/subgraph.cpp b/src/plugins/intel_cpu/src/nodes/subgraph.cpp
index dec7f283f39..d1820bb8668 100644
--- a/src/plugins/intel_cpu/src/nodes/subgraph.cpp
+++ b/src/plugins/intel_cpu/src/nodes/subgraph.cpp
@@ -54,6 +54,11 @@
#if defined(OPENVINO_ARCH_ARM64)
# include "emitters/snippets/aarch64/cpu_generator.hpp"
# include "executors/aarch64/subgraph.hpp"
+# include "snippets/lowered/pass/insert_reg_spills.hpp"
+# include "transformations/snippets/aarch64/pass/brgemm_to_gemm_cpu.hpp"
+# include "transformations/snippets/aarch64/pass/lowered/adjust_gemm_copy_b_loop_ports.hpp"
+# include "transformations/snippets/aarch64/pass/lowered/gemm_cpu_blocking.hpp"
+# include "transformations/snippets/aarch64/pass/lowered/insert_gemm_copy_buffers.hpp"
# include "transformations/snippets/aarch64/shape_inference.hpp"
#else
# include "emitters/snippets/x64/cpu_generator.hpp"
@@ -558,6 +563,9 @@ Subgraph::DataFlowPasses Subgraph::getDataFlowPasses() {
repacked_constant_input_config);
}
SNIPPETS_REGISTER_PASS_ABSOLUTE_X86_64(Place::PipelineEnd, ov::intel_cpu::pass::RemoveConverts);
+ SNIPPETS_REGISTER_PASS_RELATIVE_ARM64(Place::Before,
+ ov::snippets::pass::PropagatePrecision,
+ ov::intel_cpu::pass::BrgemmToGemmCPU);
SNIPPETS_REGISTER_PASS_ABSOLUTE_COMMON(Place::PipelineEnd, ov::intel_cpu::pass::MulAddToFMA);
#ifdef SNIPPETS_LIBXSMM_TPP
@@ -588,11 +596,10 @@ Subgraph::DataFlowPasses Subgraph::getDataFlowPasses() {
Subgraph::ControlFlowPasses Subgraph::getControlFlowPasses() {
ControlFlowPasses backend_passes;
-#if defined(OPENVINO_ARCH_X86_64) || (defined(OPENVINO_ARCH_ARM64) && defined(SNIPPETS_LIBXSMM_TPP))
+#if defined(OPENVINO_ARCH_X86_64) || defined(OPENVINO_ARCH_ARM64)
using PassPosition = ov::snippets::pass::PassPosition;
using Place = PassPosition::Place;
#endif
-
#if defined(OPENVINO_ARCH_X86_64)
# define SNIPPETS_REGISTER_PASS_RELATIVE_X86_64(PASS_PLACE, TARGET_PASS, PASS, ...) \
backend_passes.emplace_back(PassPosition(PASS_PLACE, TARGET_PASS::get_type_info_static()), \
@@ -639,6 +646,15 @@ Subgraph::ControlFlowPasses Subgraph::getControlFlowPasses() {
ov::intel_cpu::pass::InitRepackedConstantInputs,
context->getParamsCache(),
repacked_constant_input_config);
+ SNIPPETS_REGISTER_PASS_RELATIVE_ARM64(Place::After,
+ ov::snippets::lowered::pass::MarkLoops,
+ ov::intel_cpu::pass::GemmCPUBlocking);
+ SNIPPETS_REGISTER_PASS_RELATIVE_ARM64(Place::After,
+ ov::snippets::lowered::pass::InitLoops,
+ ov::intel_cpu::pass::aarch64::AdjustGemmCopyBLoopPorts);
+ SNIPPETS_REGISTER_PASS_RELATIVE_ARM64(Place::Before,
+ ov::snippets::lowered::pass::InsertBuffers,
+ ov::intel_cpu::pass::aarch64::InsertGemmCopyBuffers);
#ifdef SNIPPETS_LIBXSMM_TPP
SNIPPETS_REGISTER_PASS_RELATIVE_X86_64(Place::Before,
@@ -715,6 +731,10 @@ void Subgraph::optimizeIR() {
const auto control_flow_config = std::make_shared<ov::snippets::lowered::pass::PassConfig>();
const auto control_flow_passes = getControlFlowPasses();
+#if defined(OPENVINO_ARCH_ARM64)
+ // enable it after emitters for RegSpillBegin and RegSpillEnd are implemented on ARM in CVS-162498
+ control_flow_config->disable<ov::snippets::lowered::pass::InsertRegSpills>();
+#endif
#ifdef SNIPPETS_LIBXSMM_TPP
// Note: temporary disabled. Re-enable after ticket 132833 is resolved
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/op/gemm_copy_b.cpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/op/gemm_copy_b.cpp
new file mode 100644
index 00000000000..e7321f75586
--- /dev/null
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/op/gemm_copy_b.cpp
@@ -0,0 +1,76 @@
+// Copyright (C) 2018-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "gemm_copy_b.hpp"
+
+#include "kai/ukernels/matmul/pack/kai_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon.h"
+#include "snippets/itt.hpp"
+#include "snippets/utils/utils.hpp"
+#include "utils/general_utils.h"
+
+namespace ov::intel_cpu::aarch64 {
+
+GemmCopyB::GemmCopyB(const Output<Node>& x,
+ const PortDescriptor& desc_in0,
+ const PortDescriptor& desc_out0,
+ const std::vector<size_t>& layout_input)
+ : snippets::modifier::MemoryAccess(1, 1),
+ op::Op({x}) {
+ set_output_size(1);
+ set_input_port_descriptor(desc_in0, 0);
+ set_output_port_descriptor(desc_out0, 0);
+ custom_constructor_validate_and_infer_types(layout_input);
+}
+
+void GemmCopyB::custom_constructor_validate_and_infer_types(const std::vector<size_t>& layout_input) {
+ INTERNAL_OP_SCOPE(GemmRepack_ctor_validate_and_infer_types);
+ // During ctor call, GemmCopyB doesn't know his port descriptors.
+ // So we use port descs from source inputs
+ const auto& element_type = get_input_element_type(0);
+ validate_element_type(element_type);
+ // The data always store in planar shape after repacking
+ const auto planar_pshape = snippets::utils::get_planar_pshape(get_input_partial_shape(0), layout_input);
+ // data repacking output
+ set_output_type(0, element_type, planar_pshape);
+}
+
+void GemmCopyB::validate_and_infer_types() {
+ INTERNAL_OP_SCOPE(GemmRepack_validate_and_infer_types);
+ const auto& element_type = get_input_element_type(0);
+ validate_element_type(element_type);
+ const auto port = snippets::lowered::PortDescriptorUtils::get_port_descriptor_ptr(input(0));
+ const auto shape = ov::Shape(port->get_shape());
+ const auto& planar_pshape = snippets::utils::get_planar_pshape(shape, port->get_layout());
+ set_output_type(0, element_type, planar_pshape);
+}
+
+void GemmCopyB::validate_element_type(const ov::element::Type& element_type) {
+ OPENVINO_ASSERT(one_of(element_type, element::f32),
+ "GemmCopyB doesn't support element type" + element_type.get_type_name());
+}
+
+std::shared_ptr<ov::Node> GemmCopyB::clone_with_new_inputs(const OutputVector& new_args) const {
+ INTERNAL_OP_SCOPE(GemmRepack_clone_with_new_inputs);
+ check_new_args_count(this, new_args);
+ return std::make_shared<GemmCopyB>(
+ new_args.at(0),
+ get_input_port_descriptor(0),
+ get_output_port_descriptor(0),
+ snippets::lowered::PortDescriptorUtils::get_port_descriptor_ptr(input(0))->get_layout());
+}
+
+GemmCopyB::ShapeInfer::ShapeInfer(const std::shared_ptr<ov::Node>& n) {
+ const auto& copyb = ov::as_type_ptr<GemmCopyB>(n);
+ OPENVINO_ASSERT(copyb, "Got invalid node in GemmCopyB::ShapeInfer");
+ m_layout = snippets::lowered::PortDescriptorUtils::get_port_descriptor_ptr(n->input(0))->get_layout();
+}
+
+ov::snippets::IShapeInferSnippets::Result GemmCopyB::ShapeInfer::infer(
+ const std::vector<ov::snippets::VectorDimsRef>& input_shapes) {
+ OPENVINO_ASSERT(input_shapes.size() == 1, "Got unexpected number of input shapes");
+ auto planar_shape = ov::snippets::utils::get_planar_vdims(input_shapes[0].get(), m_layout);
+ std::vector<ov::snippets::VectorDims> new_shapes(1, planar_shape);
+ return {new_shapes, ov::snippets::ShapeInferStatus::success};
+}
+} // namespace ov::intel_cpu::aarch64
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/op/gemm_copy_b.hpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/op/gemm_copy_b.hpp
new file mode 100644
index 00000000000..1c496719913
--- /dev/null
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/op/gemm_copy_b.hpp
@@ -0,0 +1,53 @@
+// Copyright (C) 2018-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "openvino/core/attribute_visitor.hpp"
+#include "snippets/op/memory_access.hpp"
+#include "snippets/shape_inference/shape_inference.hpp"
+#include "snippets/shape_types.hpp"
+
+namespace ov::intel_cpu::aarch64 {
+
+/**
+* @interface GemmCopyB
+* @brief The operation for data repacking of GemmCPU.
+ The CPU Generator uses kleidiAI primitives for generation code of Gemm.
+ kleidiAI requiers data repacking for second input of Gemm.
+* @ingroup snippets
+*/
+class GemmCopyB : public snippets::modifier::MemoryAccess, public ov::op::Op {
+public:
+ OPENVINO_OP("GemmCopyB", "SnippetsOpset");
+
+ GemmCopyB(const Output<Node>& x,
+ const PortDescriptor& desc_in0,
+ const PortDescriptor& desc_out0,
+ const std::vector<size_t>& layout_input = {});
+ GemmCopyB() = default;
+
+ size_t get_offset_in() const {
+ return get_input_offset(0);
+ }
+ size_t get_offset_out() const {
+ return get_output_offset(0);
+ }
+
+ void validate_and_infer_types() override;
+ std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;
+
+ class ShapeInfer : public snippets::IShapeInferSnippets {
+ std::vector<size_t> m_layout{};
+
+ public:
+ explicit ShapeInfer(const std::shared_ptr<ov::Node>& n);
+ Result infer(const std::vector<snippets::VectorDimsRef>& input_shapes) override;
+ };
+
+private:
+ void custom_constructor_validate_and_infer_types(const std::vector<size_t>& layout_input = {});
+ void validate_element_type(const ov::element::Type& element_type);
+};
+} // namespace ov::intel_cpu::aarch64
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/op/gemm_cpu.cpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/op/gemm_cpu.cpp
new file mode 100644
index 00000000000..c5adf86f28a
--- /dev/null
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/op/gemm_cpu.cpp
@@ -0,0 +1,75 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "gemm_cpu.hpp"
+
+#include "snippets/itt.hpp"
+#include "snippets/lowered/port_descriptor.hpp"
+#include "snippets/snippets_isa.hpp"
+#include "snippets/utils/utils.hpp"
+#include "utils/general_utils.h"
+
+namespace ov::intel_cpu::aarch64 {
+
+GemmCPU::GemmCPU(const Output<Node>& A,
+ const Output<Node>& B,
+ const PortDescriptor& desc_a,
+ const PortDescriptor& desc_b,
+ const PortDescriptor& desc_c,
+ const std::vector<size_t>& layout_a,
+ const std::vector<size_t>& layout_b,
+ const std::vector<size_t>& layout_c)
+ : Brgemm() {
+ set_arguments({A, B});
+ set_output_size(1);
+ m_input_ports = {{0, desc_a}, {1, desc_b}};
+ m_output_ports = {{0, desc_c}};
+ custom_constructor_validate_and_infer_types(layout_a, layout_b, layout_c);
+}
+
+void GemmCPU::custom_constructor_validate_and_infer_types(const std::vector<size_t>& layout_a,
+ const std::vector<size_t>& layout_b,
+ const std::vector<size_t>& layout_c) {
+ INTERNAL_OP_SCOPE(GemmCPU_constructor_validate_and_infer_types);
+ const auto& element_type_0 = get_input_element_type(0);
+ const auto& element_type_1 = get_input_element_type(1);
+ validate_element_type(element_type_0, element_type_1);
+ const std::vector<ov::PartialShape> planar_input_shapes{
+ snippets::utils::get_planar_pshape(get_input_partial_shape(0), layout_a),
+ snippets::utils::get_planar_pshape(get_input_partial_shape(1), layout_b)};
+ auto output_shape = infer_output_partial_shape(planar_input_shapes);
+ set_output_type(0, get_output_type(), snippets::utils::get_planar_pshape(output_shape, layout_c));
+}
+
+void GemmCPU::validate_and_infer_types() {
+ INTERNAL_OP_SCOPE(GemmCPU_validate_and_infer_types);
+ const auto& element_type_0 = get_input_element_type(0);
+ const auto& element_type_1 = get_input_element_type(1);
+ validate_element_type(element_type_0, element_type_1);
+ const auto planar_input_shapes = get_planar_input_shapes({input(0), input(1)});
+ auto output_shape = infer_output_partial_shape(planar_input_shapes);
+ set_output_type(0, get_output_type(), get_planar_output_shape(output_shape));
+}
+
+void GemmCPU::validate_element_type(const ov::element::Type& type_0, const ov::element::Type& type_1) {
+ OPENVINO_ASSERT(
+ everyone_is(type_0, type_1, element::f32),
+ "GemmCPU doesn't support element type in0:" + type_0.get_type_name() + " in1:" + type_1.get_type_name());
+}
+
+std::shared_ptr<Node> GemmCPU::clone_with_new_inputs(const OutputVector& new_args) const {
+ INTERNAL_OP_SCOPE(BrgemmCPU_clone_with_new_inputs);
+ check_new_args_count(this, new_args);
+ return std::make_shared<GemmCPU>(
+ new_args.at(0),
+ new_args.at(1),
+ get_input_port_descriptor(0),
+ get_input_port_descriptor(1),
+ get_output_port_descriptor(0),
+ snippets::lowered::PortDescriptorUtils::get_port_descriptor_ptr(input(0))->get_layout(),
+ snippets::lowered::PortDescriptorUtils::get_port_descriptor_ptr(input(1))->get_layout(),
+ snippets::lowered::PortDescriptorUtils::get_port_descriptor_ptr(output(0))->get_layout());
+}
+
+} // namespace ov::intel_cpu::aarch64
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/op/gemm_cpu.hpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/op/gemm_cpu.hpp
new file mode 100644
index 00000000000..6c84071dea6
--- /dev/null
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/op/gemm_cpu.hpp
@@ -0,0 +1,41 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "snippets/lowered/port_descriptor.hpp"
+#include "snippets/op/brgemm.hpp"
+
+namespace ov::intel_cpu::aarch64 {
+
+/**
+ * @interface GemmCPU
+ * @brief GemmCPU is a matrix multiplication with the support of arbitrary strides between matrices rows
+ * with support of several precisions on plugin level
+ * @ingroup snippets
+ */
+class GemmCPU : public snippets::op::Brgemm {
+public:
+ OPENVINO_OP("GemmCPU", "SnippetsOpset", snippets::op::Brgemm);
+
+ GemmCPU(const Output<Node>& A,
+ const Output<Node>& B,
+ const PortDescriptor& desc_a,
+ const PortDescriptor& desc_b,
+ const PortDescriptor& desc_c,
+ const std::vector<size_t>& layout_a = {},
+ const std::vector<size_t>& layout_b = {},
+ const std::vector<size_t>& layout_c = {});
+ GemmCPU() = default;
+
+ void validate_and_infer_types() override;
+ std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;
+
+private:
+ void custom_constructor_validate_and_infer_types(const std::vector<size_t>& layout_a,
+ const std::vector<size_t>& layout_b,
+ const std::vector<size_t>& layout_c);
+ void validate_element_type(const ov::element::Type& type_0, const ov::element::Type& type_1);
+};
+} // namespace ov::intel_cpu::aarch64
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/op/gemm_utils.cpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/op/gemm_utils.cpp
new file mode 100644
index 00000000000..a87b28543da
--- /dev/null
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/op/gemm_utils.cpp
@@ -0,0 +1,72 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "gemm_utils.hpp"
+
+#include "snippets/lowered/expressions/buffer_expression.hpp"
+#include "snippets/op/buffer.hpp"
+#include "transformations/snippets/aarch64/op/gemm_copy_b.hpp"
+#include "transformations/snippets/aarch64/op/gemm_cpu.hpp"
+#include "transformations/snippets/aarch64/pass/lowered/expressions/gemm_copy_b_buffer_expressions.hpp"
+#include "utils/general_utils.h"
+
+using namespace ov::snippets::utils;
+
+namespace ov {
+namespace intel_cpu::aarch64::gemm_utils {
+namespace repacking {
+ov::snippets::lowered::ExpressionPtr get_copy_b_expr(const ov::snippets::lowered::ExpressionPtr& gemm_expr) {
+ OPENVINO_ASSERT(ov::is_type<GemmCPU>(gemm_expr->get_node()),
+ "get_copy_b_expr must be called only for GemmCPU node");
+ auto b_input_expr = gemm_expr->get_input_port_connector(1)->get_source().get_expr();
+ if (ov::is_type<GemmCopyB>(b_input_expr->get_node())) {
+ return b_input_expr;
+ }
+ if (ov::is_type<RepackedWeightsBufferExpression>(b_input_expr)) {
+ OPENVINO_ASSERT(b_input_expr->get_input_count() == 1,
+ "RepackedWeightsBufferExpression on gemm's B input must has one input");
+ auto input_buffer_expr = b_input_expr->get_input_port_connector(0)->get_source().get_expr();
+ if (ov::is_type<GemmCopyB>(input_buffer_expr->get_node())) {
+ return input_buffer_expr;
+ }
+ }
+ return nullptr;
+}
+
+std::vector<snippets::lowered::ExpressionPtr> get_gemm_exprs(
+ const ov::snippets::lowered::ExpressionPtr& gemm_copyb_expr) {
+ OPENVINO_ASSERT(ov::is_type<GemmCopyB>(gemm_copyb_expr->get_node()),
+ "get_gemm_exprs must be called only for GemmCopyB node");
+ OPENVINO_ASSERT(gemm_copyb_expr->get_output_count() == 1, "gemm copyb expr must has one output");
+ std::vector<snippets::lowered::ExpressionPtr> result;
+ auto copyb_output_expr = gemm_copyb_expr->get_output_port_connector(0)->get_consumers().begin()->get_expr();
+ if (ov::is_type<GemmCPU>(copyb_output_expr->get_node())) {
+ result.push_back(copyb_output_expr);
+ }
+ if (ov::is_type<RepackedWeightsBufferExpression>(copyb_output_expr)) {
+ OPENVINO_ASSERT(copyb_output_expr->get_output_count() == 1, "gemm copyb buffer expr must has one output");
+ // repacked buffer could connect gemm expr in main loop and tail loop.
+ const auto& consumers = copyb_output_expr->get_output_port_connector(0)->get_consumers();
+ for (const auto& consumer : consumers) {
+ if (ov::is_type<GemmCPU>(consumer.get_expr()->get_node())) {
+ result.push_back(consumer.get_expr());
+ }
+ }
+ }
+ return result;
+}
+
+size_t get_inner_n_block(const ov::element::Type& precision) {
+ OPENVINO_ASSERT(precision == element::f32, "Only f32 is supported for snippets Matmul");
+ return 8;
+}
+
+size_t get_k_pad_size(const ov::element::Type& precision) {
+ OPENVINO_ASSERT(precision == element::f32, "Only f32 is supported for snippets Matmul");
+ return 1;
+}
+
+} // namespace repacking
+} // namespace intel_cpu::aarch64::gemm_utils
+} // namespace ov
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/op/gemm_utils.hpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/op/gemm_utils.hpp
new file mode 100644
index 00000000000..c05060d5502
--- /dev/null
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/op/gemm_utils.hpp
@@ -0,0 +1,47 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <type_traits>
+
+#include "openvino/core/dimension.hpp"
+#include "openvino/core/type/element_type.hpp"
+#include "snippets/lowered/expression.hpp"
+#include "snippets/utils/utils.hpp"
+
+namespace ov {
+namespace intel_cpu::aarch64::gemm_utils {
+namespace repacking {
+/**
+ * @brief Retrieves the expression pointer for the gemm_copy_b expression corresponding to the given GemmCPU
+ * expression.
+ * @param gemm_expr The expression pointer for the GemmCPU operation.
+ * @return The expression pointer for the GemmCopyB operation.
+ */
+snippets::lowered::ExpressionPtr get_copy_b_expr(const snippets::lowered::ExpressionPtr& gemm_expr);
+
+/**
+ * @brief Retrieves the expression pointers for the gemm expressions corresponding to the given gemm_copy_b
+ * expression.
+ * @param gemm_expr The expression pointer for the gemm_copy_b operation.
+ * @return The expression pointers for the gemm operation.
+ */
+std::vector<snippets::lowered::ExpressionPtr> get_gemm_exprs(const snippets::lowered::ExpressionPtr& gemm_copyb_expr);
+
+/**
+ * @brief Get inner n block that is required by KleidiAI
+ * @return Inner n block size
+ */
+size_t get_inner_n_block(const ov::element::Type& precision);
+
+/**
+ * @brief Get k padding size that is required by KleidiAI
+ * @return k padding size
+ */
+size_t get_k_pad_size(const ov::element::Type& precision);
+
+} // namespace repacking
+} // namespace intel_cpu::aarch64::gemm_utils
+} // namespace ov
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/brgemm_to_gemm_cpu.cpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/brgemm_to_gemm_cpu.cpp
new file mode 100644
index 00000000000..b6cafcea2c9
--- /dev/null
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/brgemm_to_gemm_cpu.cpp
@@ -0,0 +1,98 @@
+// Copyright (C) 2018-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "brgemm_to_gemm_cpu.hpp"
+
+#include "cpu_shape.h"
+#include "openvino/core/graph_util.hpp"
+#include "openvino/core/rt_info.hpp"
+#include "openvino/pass/pattern/matcher.hpp"
+#include "openvino/pass/pattern/op/wrap_type.hpp"
+#include "snippets/itt.hpp"
+#include "snippets/op/brgemm.hpp"
+#include "snippets/op/buffer.hpp"
+#include "snippets/op/memory_access.hpp"
+#include "snippets/utils/utils.hpp"
+#include "transformations/snippets/aarch64/op/gemm_copy_b.hpp"
+#include "transformations/snippets/aarch64/op/gemm_cpu.hpp"
+#include "transformations/tpp/common/op/modifiers.hpp"
+#include "utils/general_utils.h"
+
+namespace ov::intel_cpu {
+
+using namespace snippets::lowered;
+
+pass::BrgemmToGemmCPU::BrgemmToGemmCPU() {
+ MATCHER_SCOPE(BrgemmToGemmCPU);
+ auto is_not_tpp = [](const Output<Node>& out) {
+ return !std::dynamic_pointer_cast<const intel_cpu::tpp::modifier::TensorProcessingPrimitive>(
+ out.get_node_shared_ptr());
+ };
+ auto m_brgemm = ov::pass::pattern::wrap_type<snippets::op::Brgemm>(is_not_tpp);
+
+ auto callback = [=](ov::pass::pattern::Matcher& m) {
+ OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "ov::intel_cpu::pass::BrgemmToGemmCPU")
+ const auto node = m.get_match_root();
+ const auto brgemm = ov::as_type_ptr<snippets::op::Brgemm>(node);
+ const auto gemm_plugin = ov::as_type_ptr<aarch64::GemmCPU>(node);
+ if (!brgemm || gemm_plugin) {
+ OPENVINO_ASSERT("GemmCPU cannot be in body before BrgemmToGemmCPU pass");
+ }
+
+ const auto& brgemm_in0_desc = PortDescriptorUtils::get_port_descriptor_ptr(brgemm->input(0));
+ const auto& brgemm_in1_desc = PortDescriptorUtils::get_port_descriptor_ptr(brgemm->input(1));
+ const auto& brgemm_out_desc = PortDescriptorUtils::get_port_descriptor_ptr(brgemm->output(0));
+
+ const auto& layout_a = brgemm_in0_desc->get_layout();
+ const auto& layout_b = brgemm_in1_desc->get_layout();
+ const auto& layout_c = brgemm_out_desc->get_layout();
+
+ const auto element_type_b = brgemm->get_input_element_type(1);
+ OPENVINO_ASSERT(element_type_b == element::f32, "GemmCPU only support f32 precision.");
+ const auto offset_a = brgemm->get_offset_a();
+ const auto offset_b = brgemm->get_offset_b();
+ const auto offset_c = brgemm->get_offset_c();
+
+ snippets::modifier::MemoryAccess::PortDescriptor copyb_in_port_desc(0, offset_b);
+ snippets::modifier::MemoryAccess::PortDescriptor copyb_out_port_desc(0, 0);
+ auto gemm_repacking = std::make_shared<aarch64::GemmCopyB>(brgemm->input_value(1),
+ copyb_in_port_desc,
+ copyb_out_port_desc,
+ layout_b);
+ PortDescriptorUtils::set_port_descriptor(gemm_repacking->input(0), brgemm_in1_desc->get_subtensor(), layout_b);
+ snippets::utils::set_full_port_desc(gemm_repacking->output(0));
+
+ snippets::modifier::MemoryAccess::PortDescriptor gemm_in_port_desc_0(0, offset_a);
+ snippets::modifier::MemoryAccess::PortDescriptor gemm_in_port_desc_1(0, 0);
+ snippets::modifier::MemoryAccess::PortDescriptor gemm_out_port_desc(0, offset_c);
+ std::shared_ptr<aarch64::GemmCPU> gemm_cpu = std::make_shared<aarch64::GemmCPU>(brgemm->input_value(0),
+ gemm_repacking->output(0),
+ gemm_in_port_desc_0,
+ gemm_in_port_desc_1,
+ gemm_out_port_desc,
+ layout_a,
+ std::vector<size_t>{},
+ layout_c);
+
+ gemm_cpu->set_friendly_name(brgemm->get_friendly_name());
+ ov::replace_node(brgemm, gemm_cpu);
+ ov::copy_runtime_info(brgemm, gemm_cpu);
+
+ // Transfer ports
+ PortDescriptorUtils::set_port_descriptor(gemm_cpu->input(0), brgemm_in0_desc->get_subtensor(), layout_a);
+ snippets::utils::set_full_port_desc(gemm_cpu->input(1));
+ PortDescriptorUtils::set_port_descriptor(gemm_cpu->output(0), brgemm_out_desc->get_subtensor(), layout_c);
+
+ // need to run validate_and_infer_types manually: either input shapes were updated or
+ // output Layout was updated (out shape will be updated in validate_and_infer_types())
+ gemm_repacking->validate_and_infer_types();
+ gemm_cpu->validate_and_infer_types();
+
+ return true;
+ };
+
+ auto m = std::make_shared<ov::pass::pattern::Matcher>(m_brgemm, matcher_name);
+ register_matcher(m, callback);
+}
+} // namespace ov::intel_cpu
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/brgemm_to_gemm_cpu.hpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/brgemm_to_gemm_cpu.hpp
new file mode 100644
index 00000000000..0fc2321d406
--- /dev/null
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/brgemm_to_gemm_cpu.hpp
@@ -0,0 +1,23 @@
+// Copyright (C) 2018-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "openvino/pass/graph_rewrite.hpp"
+
+namespace ov::intel_cpu::pass {
+
+/**
+ * @interface BrgemmToGemmCPU
+ * @brief The pass decompose Snippets Brgemm to specific ops
+ * Brgemm -> copyB + GemmCPU
+ * @ingroup snippets
+ */
+class BrgemmToGemmCPU : public ov::pass::MatcherPass {
+public:
+ OPENVINO_MATCHER_PASS_RTTI("BrgemmToGemmCPU");
+ BrgemmToGemmCPU();
+};
+
+} // namespace ov::intel_cpu::pass
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/adjust_gemm_copy_b_loop_ports.cpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/adjust_gemm_copy_b_loop_ports.cpp
new file mode 100644
index 00000000000..858f9c02aa8
--- /dev/null
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/adjust_gemm_copy_b_loop_ports.cpp
@@ -0,0 +1,79 @@
+// Copyright (C) 2018-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "adjust_gemm_copy_b_loop_ports.hpp"
+
+#include "snippets/itt.hpp"
+#include "snippets/lowered/loop_manager.hpp"
+#include "snippets/utils/utils.hpp"
+#include "transformations/snippets/aarch64/op/gemm_copy_b.hpp"
+#include "transformations/snippets/aarch64/op/gemm_cpu.hpp"
+#include "transformations/snippets/aarch64/op/gemm_utils.hpp"
+
+namespace ov::intel_cpu {
+
+bool pass::aarch64::AdjustGemmCopyBLoopPorts::update_loop_info(
+ const std::shared_ptr<snippets::lowered::UnifiedLoopInfo>& loop_info) {
+ OPENVINO_ASSERT(loop_info, "Invalid loop info pointer");
+ bool modified = false;
+ auto caller = [&](snippets::lowered::LoopPort& loop_port,
+ snippets::lowered::UnifiedLoopInfo::LoopPortDesc& loop_desc) {
+ const auto& p = *loop_port.get_expr_port();
+ if (p.get_type() == snippets::lowered::ExpressionPort::Input && p.get_index() == 1) {
+ const auto& expr = p.get_expr();
+ if (as_type_ptr<ov::intel_cpu::aarch64::GemmCPU>(expr->get_node())) {
+ // from format KN to NK64n(64 is n block), and for each K64n, repack to nK8n
+ if (loop_port.is_incremented()) {
+ if (loop_port.get_dim_idx() == 0) {
+ // N blocking loop
+ const auto& in_0_shape = ov::snippets::utils::get_planar_vdims(expr->get_input_port(0));
+ int64_t K = in_0_shape.back(); // K dimension(K is not blocked)
+ // NK repacked and padded to to N(K+1)
+ // ptr_increment is 1, inc is 64. inc*ptr_increment adjusted from 64*1 to 64*(K+1)
+ const auto k_pad = snippets::utils::dynamic_safe_add(K, static_cast<int64_t>(1));
+ loop_desc.ptr_increment = snippets::utils::dynamic_safe_mul(loop_desc.ptr_increment, k_pad);
+ loop_desc.finalization_offset =
+ snippets::utils::dynamic_safe_mul(loop_desc.finalization_offset, k_pad);
+ } else {
+ OPENVINO_THROW("Unexpected loop port dimension index in AdjustGemmCopyBLoopPorts");
+ }
+ modified = true;
+ }
+ }
+ }
+ };
+ loop_info->iterate_through_infos(caller);
+ return modified;
+}
+
+bool pass::aarch64::AdjustGemmCopyBLoopPorts::run(const snippets::lowered::LinearIR& linear_ir) {
+ OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::AdjustGemmCopyBLoopPorts")
+
+ bool modified = false;
+
+ for (const auto& expr : linear_ir) {
+ const auto gemm = ov::as_type_ptr<ov::intel_cpu::aarch64::GemmCPU>(expr->get_node());
+ if (!gemm) {
+ continue;
+ }
+ const auto& gemm_loop_ids = expr->get_loop_ids();
+ if (gemm_loop_ids.empty()) {
+ continue;
+ }
+ const auto& loop_manager = linear_ir.get_loop_manager();
+ // only adjust inner most loop(N loop)
+ const auto& loop = loop_manager->get_loop_info(gemm_loop_ids.back());
+ auto uni_loop = ov::as_type_ptr<snippets::lowered::UnifiedLoopInfo>(loop);
+ if (!uni_loop) {
+ uni_loop = ov::as_type_ptr<snippets::lowered::ExpandedLoopInfo>(loop)->get_unified_loop_info();
+ }
+ if (!m_affected_loops.count(uni_loop) && update_loop_info(uni_loop)) {
+ m_affected_loops.insert(uni_loop);
+ modified = true;
+ }
+ }
+
+ return modified;
+}
+} // namespace ov::intel_cpu
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/adjust_gemm_copy_b_loop_ports.hpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/adjust_gemm_copy_b_loop_ports.hpp
new file mode 100644
index 00000000000..48cefe3719c
--- /dev/null
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/adjust_gemm_copy_b_loop_ports.hpp
@@ -0,0 +1,33 @@
+// Copyright (C) 2018-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "snippets/lowered/loop_info.hpp"
+#include "snippets/lowered/pass/pass.hpp"
+
+namespace ov::intel_cpu::pass::aarch64 {
+
+/**
+ * @interface AdjustGemmCopyBLoopPorts
+ * @brief GemmCopyB is located outside of blocking loops and repacks input data into a blocked layout.
+ * This layout should be accounted for when we increment GemmCopyB data pointers. This pass
+ * Finds loop ports connected to GemmCopyB and sets appropriate pointer increments.
+ * @ingroup snippets
+ */
+class AdjustGemmCopyBLoopPorts : public snippets::lowered::pass::ConstPass {
+public:
+ OPENVINO_RTTI("AdjustGemmCopyBLoopPorts", "", ConstPass)
+ AdjustGemmCopyBLoopPorts() = default;
+ bool run(const snippets::lowered::LinearIR& linear_ir) override;
+ static bool update_loop_info(const snippets::lowered::UnifiedLoopInfoPtr& uni_loop_info);
+ const std::unordered_set<snippets::lowered::UnifiedLoopInfoPtr>& get_affected_loops() {
+ return m_affected_loops;
+ }
+
+private:
+ std::unordered_set<snippets::lowered::UnifiedLoopInfoPtr> m_affected_loops;
+};
+
+} // namespace ov::intel_cpu::pass::aarch64
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/expressions/gemm_copy_b_buffer_expressions.cpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/expressions/gemm_copy_b_buffer_expressions.cpp
new file mode 100644
index 00000000000..5bcffc8d7ab
--- /dev/null
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/expressions/gemm_copy_b_buffer_expressions.cpp
@@ -0,0 +1,77 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "gemm_copy_b_buffer_expressions.hpp"
+
+#include <memory>
+
+#include "kai/ukernels/matmul/pack/kai_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon.h"
+#include "snippets/lowered/loop_manager.hpp"
+#include "snippets/utils/utils.hpp"
+#include "transformations/snippets/aarch64/op/gemm_copy_b.hpp"
+#include "transformations/snippets/aarch64/op/gemm_cpu.hpp"
+#include "utils/general_utils.h"
+
+using namespace ov::snippets::lowered;
+
+namespace ov::intel_cpu::aarch64 {
+
+RepackedWeightsBufferExpression::RepackedWeightsBufferExpression(
+ const std::shared_ptr<ov::Node>& n,
+ const std::shared_ptr<snippets::IShapeInferSnippetsFactory>& factory)
+ : BufferExpression(n, factory) {}
+
+snippets::lowered::ExpressionPtr RepackedWeightsBufferExpression::clone() const {
+ return std::make_shared<RepackedWeightsBufferExpression>(*this);
+}
+
+void RepackedWeightsBufferExpression::validate() const {
+ BufferExpression::validate();
+ OPENVINO_ASSERT(get_input_count() == 1, "RepackedWeightsBufferExpression must have only one input");
+ const auto& parent_out = get_input_port_connector(0)->get_source();
+ OPENVINO_ASSERT(ov::is_type<ov::intel_cpu::aarch64::GemmCopyB>(parent_out.get_expr()->get_node()) &&
+ parent_out.get_index() == 0,
+ "RepackedWeightsBufferExpression expects GemmCopyB as parent expression");
+ OPENVINO_ASSERT(one_of(get_node()->get_input_element_type(0), ov::element::f32),
+ "RepackedWeightsBufferExpression after GemmCopyB currently only support f32 data type on arm");
+}
+
+void RepackedWeightsBufferExpression::init_allocation_size(
+ [[maybe_unused]] const std::shared_ptr<snippets::lowered::LoopManager>& loop_manager,
+ [[maybe_unused]] size_t allocation_rank) {
+ const auto& parent_expr = get_input_port_connector(0)->get_source().get_expr();
+ const auto& in_shape = ov::snippets::utils::get_planar_vdims(parent_expr->get_input_port(0));
+ OPENVINO_ASSERT(in_shape.size() >= 2 && allocation_rank >= 2, "GemmCopyB should has at least 2 rank tensor");
+ const auto& element_type = get_node()->get_input_element_type(0);
+ const size_t N = *in_shape.rbegin();
+ const size_t K = *++in_shape.rbegin();
+
+ const auto& consumers = get_output_port_connector(0)->get_consumers();
+ ExpressionPtr child_gemm_expr = nullptr;
+ // maybe connected to loopEnd besides gemm
+ for (const auto& consumer : consumers) {
+ if (ov::is_type<ov::intel_cpu::aarch64::GemmCPU>(consumer.get_expr()->get_node())) {
+ child_gemm_expr = consumer.get_expr();
+ break;
+ }
+ }
+ OPENVINO_ASSERT(child_gemm_expr, "RepackedWeightsBufferExpression must connect to gemm");
+ const auto& gemm_in_subtensor = ov::snippets::utils::get_projected_subtensor(child_gemm_expr->get_input_port(1));
+ const size_t n_block_size = *gemm_in_subtensor.rbegin();
+ if (snippets::utils::is_dynamic_value(N) || snippets::utils::is_dynamic_value(K) ||
+ snippets::utils::is_dynamic_value(n_block_size)) {
+ m_allocation_size = snippets::utils::get_dynamic_value<size_t>();
+ return;
+ }
+ size_t n_block_num = N / n_block_size;
+ size_t n_tail_size = N % n_block_size;
+ m_allocation_size = n_block_num * kai_get_rhs_packed_size_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon(n_block_size, K);
+ if (n_tail_size > 0) {
+ m_allocation_size += kai_get_rhs_packed_size_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon(n_tail_size, K);
+ }
+ // convert byte size to element type size
+ m_allocation_size = m_allocation_size / element_type.size();
+}
+
+} // namespace ov::intel_cpu::aarch64
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/expressions/gemm_copy_b_buffer_expressions.hpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/expressions/gemm_copy_b_buffer_expressions.hpp
new file mode 100644
index 00000000000..8ae0edd35b9
--- /dev/null
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/expressions/gemm_copy_b_buffer_expressions.hpp
@@ -0,0 +1,29 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "snippets/lowered/expressions/buffer_expression.hpp"
+
+namespace ov::intel_cpu::aarch64 {
+
+class RepackedWeightsBufferExpression : public snippets::lowered::BufferExpression {
+ friend class snippets::lowered::ExpressionFactory;
+
+public:
+ OPENVINO_RTTI("RepackedWeightsBufferExpression", "0", BufferExpression)
+ RepackedWeightsBufferExpression() = default;
+
+ void validate() const override;
+ void init_allocation_size(const std::shared_ptr<snippets::lowered::LoopManager>& loop_manager,
+ size_t allocation_rank) override;
+
+private:
+ RepackedWeightsBufferExpression(const std::shared_ptr<ov::Node>& n,
+ const std::shared_ptr<snippets::IShapeInferSnippetsFactory>& factory);
+
+ snippets::lowered::ExpressionPtr clone() const override;
+};
+
+} // namespace ov::intel_cpu::aarch64
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/gemm_copy_b_loop_ports_adjuster.cpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/gemm_copy_b_loop_ports_adjuster.cpp
new file mode 100644
index 00000000000..9c898f7a766
--- /dev/null
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/gemm_copy_b_loop_ports_adjuster.cpp
@@ -0,0 +1,60 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "gemm_copy_b_loop_ports_adjuster.hpp"
+
+#include <memory>
+
+#include "emitters/snippets/cpu_runtime_configurator.hpp"
+#include "openvino/core/type.hpp"
+#include "openvino/itt.hpp"
+#include "snippets/itt.hpp"
+#include "snippets/lowered/linear_ir.hpp"
+#include "snippets/lowered/loop_info.hpp"
+#include "snippets/lowered/loop_manager.hpp"
+#include "snippets/lowered/pass/runtime_optimizer.hpp"
+#include "snippets/runtime_configurator.hpp"
+#include "transformations/snippets/aarch64/pass/lowered/adjust_gemm_copy_b_loop_ports.hpp"
+
+namespace ov::intel_cpu::pass::aarch64 {
+
+GemmCopyBLoopPortsAdjuster::GemmCopyBLoopPortsAdjuster(const ov::snippets::lowered::LinearIRCPtr& linear_ir,
+ const CPURuntimeConfigurator* configurator)
+ : ov::snippets::lowered::pass::RuntimeOptimizer(configurator) {
+ if (!linear_ir->is_dynamic()) {
+ return;
+ }
+
+ const auto& pass = std::make_shared<intel_cpu::pass::aarch64::AdjustGemmCopyBLoopPorts>();
+ pass->run(*linear_ir);
+ const auto& affected_uni_loops = pass->get_affected_loops();
+ const snippets::lowered::LoopManagerPtr& loop_manager = linear_ir->get_loop_manager();
+ const auto& loop_map = loop_manager->get_map();
+ for (const auto& p : loop_map) {
+ if (const auto& exp_loop = ov::as_type_ptr<snippets::lowered::ExpandedLoopInfo>(p.second)) {
+ const auto& uni_loop = exp_loop->get_unified_loop_info();
+ if (affected_uni_loops.count(uni_loop)) {
+ m_affected_uni2exp_map[uni_loop].push_back(exp_loop);
+ }
+ }
+ }
+}
+
+bool GemmCopyBLoopPortsAdjuster::run([[maybe_unused]] const snippets::lowered::LinearIR& linear_ir) {
+ OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::GemmCopyBLoopPortsAdjuster")
+ for (const auto& p : m_affected_uni2exp_map) {
+ const auto& uni_loop = p.first;
+ const auto& exp_loops = p.second;
+ snippets::RuntimeConfigurator::LoopInfoRuntimeParamsMap initialized_info;
+ if (intel_cpu::pass::aarch64::AdjustGemmCopyBLoopPorts::update_loop_info(uni_loop)) {
+ initialized_info[uni_loop] = snippets::RuntimeConfigurator::get_loop_runtime_params(uni_loop);
+ for (const auto& exp_loop : exp_loops) {
+ snippets::RuntimeConfigurator::update_expanded_loop_info(exp_loop, initialized_info);
+ }
+ }
+ }
+ return true;
+}
+
+} // namespace ov::intel_cpu::pass::aarch64
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/gemm_copy_b_loop_ports_adjuster.hpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/gemm_copy_b_loop_ports_adjuster.hpp
new file mode 100644
index 00000000000..a8c7efcb181
--- /dev/null
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/gemm_copy_b_loop_ports_adjuster.hpp
@@ -0,0 +1,39 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <unordered_map>
+#include <vector>
+
+#include "emitters/snippets/cpu_runtime_configurator.hpp"
+#include "openvino/core/rtti.hpp"
+#include "snippets/lowered/linear_ir.hpp"
+#include "snippets/lowered/loop_info.hpp"
+#include "snippets/lowered/pass/runtime_optimizer.hpp"
+
+namespace ov::intel_cpu::pass::aarch64 {
+
+/**
+ * @class GemmCopyBLoopPortsAdjuster
+ * @brief A runtime optimizer that adjusts blocked loops parameters for gemm operations which require repacking.
+ */
+class GemmCopyBLoopPortsAdjuster : public ov::snippets::lowered::pass::RuntimeOptimizer {
+public:
+ OPENVINO_RTTI("GemmCopyBLoopPortsAdjuster", "", RuntimeOptimizer)
+ GemmCopyBLoopPortsAdjuster() = default;
+ GemmCopyBLoopPortsAdjuster(const ov::snippets::lowered::LinearIRCPtr& linear_ir,
+ const CPURuntimeConfigurator* configurator);
+
+ bool run(const snippets::lowered::LinearIR& linear_ir) override;
+ bool applicable() const override {
+ return !m_affected_uni2exp_map.empty();
+ }
+
+private:
+ std::unordered_map<snippets::lowered::UnifiedLoopInfoPtr, std::vector<snippets::lowered::ExpandedLoopInfoPtr>>
+ m_affected_uni2exp_map;
+};
+
+} // namespace ov::intel_cpu::pass::aarch64
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/gemm_cpu_blocking.cpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/gemm_cpu_blocking.cpp
new file mode 100644
index 00000000000..ce5473a1e7c
--- /dev/null
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/gemm_cpu_blocking.cpp
@@ -0,0 +1,28 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "gemm_cpu_blocking.hpp"
+
+#include "snippets/utils/utils.hpp"
+
+namespace ov::intel_cpu::pass {
+
+std::tuple<size_t, size_t, size_t> GemmCPUBlocking::get_blocking_params(
+ const ov::snippets::lowered::ExpressionPtr& gemm_expr) const {
+ const auto gemm = ov::as_type_ptr<ov::intel_cpu::aarch64::GemmCPU>(gemm_expr->get_node());
+ assert(gemm && "GemmCPU is expected!");
+
+ const auto [m, n, k] = get_brgemm_dimensions(gemm_expr);
+
+ const size_t& default_m_blk = 32;
+ const size_t& default_n_blk = 64;
+
+ const size_t& m_blk = get_corrected_blk_size_by_dim(m, default_m_blk);
+ const size_t& n_blk = get_corrected_blk_size_by_dim(n, default_n_blk);
+ const size_t& k_blk = ov::snippets::utils::get_full_dim_value();
+
+ return std::make_tuple(m_blk, n_blk, k_blk);
+}
+
+} // namespace ov::intel_cpu::pass
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/gemm_cpu_blocking.hpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/gemm_cpu_blocking.hpp
new file mode 100644
index 00000000000..634a5323757
--- /dev/null
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/gemm_cpu_blocking.hpp
@@ -0,0 +1,26 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "snippets/lowered/pass/brgemm_blocking.hpp"
+#include "transformations/snippets/aarch64/op/gemm_cpu.hpp"
+
+namespace ov::intel_cpu::pass {
+
+/**
+ * @interface GemmCPUBlocking
+ * @brief Covers GemmCPU with blocking loops
+ * @ingroup snippets
+ */
+class GemmCPUBlocking : public ov::snippets::lowered::pass::BrgemmBlocking<ov::intel_cpu::aarch64::GemmCPU> {
+public:
+ OPENVINO_RTTI("GemmCPUBlocking", "", BrgemmBlocking)
+
+private:
+ std::tuple<size_t, size_t, size_t> get_blocking_params(
+ const ov::snippets::lowered::ExpressionPtr& gemm_expr) const override;
+};
+
+} // namespace ov::intel_cpu::pass
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/insert_gemm_copy_buffers.cpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/insert_gemm_copy_buffers.cpp
new file mode 100644
index 00000000000..78170e1f774
--- /dev/null
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/insert_gemm_copy_buffers.cpp
@@ -0,0 +1,57 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "insert_gemm_copy_buffers.hpp"
+
+#include "expressions/gemm_copy_b_buffer_expressions.hpp"
+#include "snippets/itt.hpp"
+#include "snippets/lowered/loop_manager.hpp"
+#include "transformations/snippets/aarch64/op/gemm_copy_b.hpp"
+#include "transformations/snippets/aarch64/op/gemm_cpu.hpp"
+#include "transformations/snippets/aarch64/op/gemm_utils.hpp"
+
+using namespace ov::intel_cpu::aarch64::gemm_utils::repacking;
+using namespace ov::snippets::lowered;
+
+namespace ov::intel_cpu::pass::aarch64 {
+
+bool InsertGemmCopyBuffers::run(LinearIR& linear_ir, LinearIR::constExprIt begin, LinearIR::constExprIt end) {
+ OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::InsertBrgemmCopyBuffers")
+
+ const auto& factory = linear_ir.get_expr_factory();
+
+ auto insert_copy_b_buffer = [&](const ExpressionPtr& copy_b_expr, LinearIR::constExprIt insertion_pos) {
+ const auto& copy_b = ov::as_type_ptr<ov::intel_cpu::aarch64::GemmCopyB>(copy_b_expr->get_node());
+ const auto& copy_b_out = copy_b_expr->get_output_port_connector(0);
+ const auto copy_b_consumers = copy_b_out->get_consumers();
+ OPENVINO_ASSERT(copy_b_consumers.size() == 1,
+ "BufferCopyB must have only one consumer on each out port - Gemm");
+ const auto& buffer_op = std::make_shared<ov::snippets::op::Buffer>(copy_b->output(0));
+ BufferExpressionPtr buffer_expr =
+ factory->build<ov::intel_cpu::aarch64::RepackedWeightsBufferExpression>(buffer_op, {copy_b_out});
+ linear_ir.insert_expr(buffer_expr,
+ LoopManager::get_common_outer_loops(copy_b_expr, copy_b_consumers.begin()->get_expr()),
+ true,
+ insertion_pos,
+ {copy_b_consumers});
+ };
+
+ bool modified = false;
+ for (auto expr_it = begin; expr_it != end; ++expr_it) {
+ const auto& gemm_expr = *expr_it;
+ if (const auto gemm_cpu = ov::as_type_ptr<ov::intel_cpu::aarch64::GemmCPU>(gemm_expr->get_node())) {
+ if (const auto copy_b_expr = get_copy_b_expr(gemm_expr)) {
+ auto insertion_it = std::next(linear_ir.find_before(expr_it, copy_b_expr));
+ OPENVINO_ASSERT(copy_b_expr->get_output_count() == 1, "gemm copyb must have only one output");
+ insert_copy_b_buffer(copy_b_expr, insertion_it);
+ modified = true;
+ } else {
+ OPENVINO_THROW("GemmCopyB must connect to gemmCPU in subgraph, and not be extracted from the body");
+ }
+ }
+ }
+ return modified;
+}
+
+} // namespace ov::intel_cpu::pass::aarch64
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/insert_gemm_copy_buffers.hpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/insert_gemm_copy_buffers.hpp
new file mode 100644
index 00000000000..f6a125bef74
--- /dev/null
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/lowered/insert_gemm_copy_buffers.hpp
@@ -0,0 +1,26 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "snippets/lowered/pass/pass.hpp"
+
+namespace ov::intel_cpu::pass::aarch64 {
+
+/**
+ * @interface InsertGemmCopyBuffers
+ * @brief Insert Gemm-specific buffers after GemmCopyB with algorithm of allocation size calculation which distinguishes
+ * with common algorithm
+ * @ingroup snippets
+ */
+class InsertGemmCopyBuffers : public snippets::lowered::pass::RangedPass {
+public:
+ InsertGemmCopyBuffers() = default;
+ OPENVINO_RTTI("InsertGemmCopyBuffers", "", RangedPass)
+ bool run(snippets::lowered::LinearIR& linear_ir,
+ snippets::lowered::LinearIR::constExprIt begin,
+ snippets::lowered::LinearIR::constExprIt end) override;
+};
+
+} // namespace ov::intel_cpu::pass::aarch64
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.cpp
index 4547090f4c4..37de45c05d3 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
@@ -11,6 +11,8 @@
#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"
@@ -49,6 +51,8 @@ const CPUShapeInferSnippetsFactory::TRegistry CPUShapeInferSnippetsFactory::spec
SHAPE_INFER_PREDEFINED(ov::intel_cpu::FusedMulAdd, NumpyBroadcastShapeInfer),
SHAPE_INFER_PREDEFINED(ov::intel_cpu::SwishNode, PassThroughShapeInfer),
SHAPE_INFER_OP_SPECIFIC_EXTERNAL(ov::intel_cpu::tpp::op::BrgemmTPP, BrgemmShapeInfer),
+ SHAPE_INFER_OP_SPECIFIC_EXTERNAL(ov::intel_cpu::aarch64::GemmCPU, BrgemmShapeInfer),
+ SHAPE_INFER_OP_SPECIFIC(ov::intel_cpu::aarch64::GemmCopyB),
};
#undef SHAPE_INFER_OP_SPECIFIC
#undef SHAPE_INFER_PREDEFINED
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_utils.cpp b/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_utils.cpp
index d50dc4c9625..b0d11143ad6 100644
--- a/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_utils.cpp
+++ b/src/plugins/intel_cpu/src/transformations/snippets/x64/op/brgemm_utils.cpp
@@ -17,12 +17,12 @@
#include "openvino/core/type.hpp"
#include "openvino/core/type/element_type.hpp"
#include "snippets/lowered/expression.hpp"
-#include "snippets/lowered/expressions/buffer_expression.hpp"
#include "snippets/shape_types.hpp"
#include "snippets/utils/utils.hpp"
#include "transformations/snippets/x64/op/brgemm_copy_b.hpp"
#include "transformations/snippets/x64/op/brgemm_cpu.hpp"
#include "transformations/snippets/x64/pass/lowered/brgemm_cpu_blocking.hpp"
+#include "transformations/snippets/x64/pass/lowered/expressions/brgemm_copy_b_buffer_expressions.hpp"
#include "utils/general_utils.h"
using namespace Xbyak;
@@ -166,9 +166,9 @@ ov::snippets::lowered::ExpressionPtr get_copy_b_expr(const ov::snippets::lowered
if (ov::is_type<BrgemmCopyB>(b_input_expr->get_node())) {
return b_input_expr;
}
- if (ov::is_type<snippets::lowered::BufferExpression>(b_input_expr)) {
+ if (ov::is_type<RepackedWeightsBufferExpression>(b_input_expr)) {
OPENVINO_ASSERT(b_input_expr->get_input_count() >= 1,
- "BufferExpression on brgemm's B input must have at least one input");
+ "RepackedWeightsBufferExpression on brgemm's B input must have at least one input");
auto input_buffer_expr = b_input_expr->get_input_port_connector(0)->get_source().get_expr();
if (ov::is_type<BrgemmCopyB>(input_buffer_expr->get_node())) {
return input_buffer_expr;
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/brgemm_to_brgemm_cpu.cpp b/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/brgemm_to_brgemm_cpu.cpp
index a40078726f9..46ed7f5d4cc 100644
--- a/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/brgemm_to_brgemm_cpu.cpp
+++ b/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/brgemm_to_brgemm_cpu.cpp
@@ -35,20 +35,9 @@ namespace ov::intel_cpu {
using namespace snippets::lowered;
using PortDescriptor = ov::snippets::modifier::MemoryAccess::PortDescriptor;
-namespace {
-template <typename T>
-void set_full_port_desc(const T& port) {
- const auto& shape_rank = port.get_partial_shape().size();
- const std::vector<size_t> full_dim_subtensor(std::min(shape_rank, static_cast<size_t>(2)),
- ov::snippets::utils::get_full_dim_value());
- PortDescriptorUtils::set_port_descriptor(port, full_dim_subtensor);
-}
-} // namespace
-
bool pass::BrgemmToBrgemmCPU::run_on_model(const std::shared_ptr<ov::Model>& model) {
RUN_ON_MODEL_SCOPE(BrgemmToBrgemmCPU);
OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "ov::intel_cpu::pass::BrgemmToBrgemmCPU")
-
auto is_not_tpp = [](const Output<Node>& out) {
return !std::dynamic_pointer_cast<const intel_cpu::tpp::modifier::TensorProcessingPrimitive>(
out.get_node_shared_ptr());
@@ -113,7 +102,7 @@ bool pass::BrgemmToBrgemmCPU::run_on_model(const std::shared_ptr<ov::Model>& mod
brgemm_in1_desc->get_subtensor(),
layout_b);
for (const auto& out : brgemm_copy_b->outputs()) {
- set_full_port_desc(out);
+ snippets::utils::set_full_port_desc(out);
}
brgemm_in1 = brgemm_copy_b->output(0);
@@ -131,8 +120,8 @@ bool pass::BrgemmToBrgemmCPU::run_on_model(const std::shared_ptr<ov::Model>& mod
layout_b,
layout_c);
- set_full_port_desc(scratch->output(0));
- set_full_port_desc(brgemm_cpu->input(2));
+ snippets::utils::set_full_port_desc(scratch->output(0));
+ snippets::utils::set_full_port_desc(brgemm_cpu->input(2));
} else if (brgemm_config.with_compensations()) {
OPENVINO_ASSERT(brgemm_copy_b, "BrgemmCopyB is required");
brgemm_cpu = std::make_shared<BrgemmCPU>(ov::OutputVector{brgemm_in0, brgemm_in1, brgemm_copy_b->output(1)},
@@ -151,11 +140,10 @@ bool pass::BrgemmToBrgemmCPU::run_on_model(const std::shared_ptr<ov::Model>& mod
layout_b,
layout_c);
}
-
// need to run validate_and_infer_types manually: either input shapes were updated or
// output Layout was updated (out shape will be updated in validate_and_infer_types())
if (brgemm_copy_b) {
- set_full_port_desc(brgemm_cpu->input(1));
+ snippets::utils::set_full_port_desc(brgemm_cpu->input(1));
brgemm_copy_b->validate_and_infer_types();
} else {
PortDescriptorUtils::set_port_descriptor(brgemm_cpu->input(1), brgemm_in1_desc->get_subtensor(), layout_b);
diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp
index 306ac70dd03..ea317acb13c 100644
--- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp
+++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp
@@ -500,8 +500,10 @@ std::vector<std::string> disabledTestPatterns() {
#if !defined(OPENVINO_ARCH_ARM64)
retVector.emplace_back(R"(smoke_Snippets.*)");
#endif
- // smoke_Snippets test cases are not supported on arm64 platforms, except for smoke_Snippets_Eltwise
- retVector.emplace_back(R"(smoke_Snippets(?!_Eltwise|_Convert|_FQDecomposition_).*)");
+ // smoke_Snippets test cases are not supported on arm64 platforms, except for smoke_Snippets_Eltwise,
+ // smoke_Snippets_Convert, smoke_Snippets_FQDecomposition and static smoke_Snippets_MatMul
+ retVector.emplace_back(R"(smoke_Snippets(?!_Eltwise|_Convert|_FQDecomposition_|_MatMul/).*)");
+ retVector.emplace_back(R"(smoke_Snippets_MatMul.*\[.*\?.*\].*)");
#endif
#if defined(_WIN32)
retVector.emplace_back(R"(.*smoke_QuantizedConvolutionBatchNormTransposeOnWeights/QuantizedConvolutionBatchNorm.CompareWithRefs/conv_type=convolution_quantize_type=fake_quantize_intervals_type=per_(tensor|channel)_transpose_on_weights=true_device=CPU.*)");