Skip to content

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

[CPU][ARM] KleidiAI integration and KleidiAI MM executor (#28830)

Aleksandr Voronff06fa3e7e48
diff --git a/.gitmodules b/.gitmodules
index 884ba551c9b..2afacd5ef77 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -87,3 +87,6 @@
[submodule "src/plugins/intel_cpu/thirdparty/shl"]
path = src/plugins/intel_cpu/thirdparty/shl
url = https://github.com/openvinotoolkit/shl.git
+[submodule "src/plugins/intel_cpu/thirdparty/kleidiai"]
+ path = src/plugins/intel_cpu/thirdparty/kleidiai
+ url = https://git.gitlab.arm.com/kleidi/kleidiai.git
diff --git a/licensing/third-party-programs.txt b/licensing/third-party-programs.txt
index d2ed0d5a3f4..2469577dad0 100644
--- a/licensing/third-party-programs.txt
+++ b/licensing/third-party-programs.txt
@@ -1872,3 +1872,87 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+-------------------------------------------------------------
+
+32. KleidiAI (https://git.gitlab.arm.com/kleidi/kleidiai)
+Copyright 2024-2025 Arm Limited and/or its affiliates <[email protected]>
+
+Apache License
+Version 2.0, January 2004
+http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
+
+"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
+
+"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity.
+For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
+
+"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
+
+"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
+
+"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
+
+"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
+
+"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship.
+For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
+
+"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner.
+For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
+
+"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted.
+If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
+
+ (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear.
+ The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
+
+Copyright [yyyy] [name of copyright owner]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-------------------------------------------------------------
\ No newline at end of file
diff --git a/src/plugins/intel_cpu/CMakeLists.txt b/src/plugins/intel_cpu/CMakeLists.txt
index 2b53a54686f..34b0db32158 100644
--- a/src/plugins/intel_cpu/CMakeLists.txt
+++ b/src/plugins/intel_cpu/CMakeLists.txt
@@ -146,6 +146,13 @@ else()
endif()
ov_dependent_option(ENABLE_SHL_FOR_CPU "Enable SHL for OpenVINO CPU Plugin" ${ENABLE_SHL_FOR_CPU_DEFAULT} "RISCV64" OFF)
+if(AARCH64)
+ set(ENABLE_KLEIDIAI_FOR_CPU_DEFAULT ON)
+else()
+ set(ENABLE_KLEIDIAI_FOR_CPU_DEFAULT OFF)
+endif()
+ov_dependent_option(ENABLE_KLEIDIAI_FOR_CPU "Enable KleidiAI for OpenVINO CPU Plugin" ${ENABLE_KLEIDIAI_FOR_CPU_DEFAULT} "AARCH64" OFF)
+
add_subdirectory(thirdparty)
if(WIN32)
@@ -171,6 +178,11 @@ if(DNNL_USE_ACL)
set(OV_CPU_WITH_ACL ON)
endif()
+if(ENABLE_KLEIDIAI_FOR_CPU)
+ add_definitions(-DOV_CPU_WITH_KLEIDIAI)
+ set(OV_CPU_WITH_KLEIDIAI ON)
+endif()
+
if (ENABLE_SHL_FOR_CPU)
add_definitions(-DOV_CPU_WITH_SHL)
set(OV_CPU_WITH_SHL ON)
@@ -200,6 +212,8 @@ 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))
@@ -265,6 +279,10 @@ endif ()
if(ENABLE_SHL_FOR_CPU)
target_link_libraries(${TARGET_NAME} PRIVATE shl)
endif()
+if(ENABLE_KLEIDIAI_FOR_CPU)
+ target_link_libraries(${TARGET_NAME} PRIVATE kleidiai)
+endif()
+
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE $<TARGET_PROPERTY:dnnl,INCLUDE_DIRECTORIES>)
# Temporal solution to use template reference implementations in cases where optimizied implementation
@@ -368,6 +386,10 @@ if(BUILD_SHARED_LIBS)
target_include_directories(${TARGET_NAME}_obj SYSTEM PUBLIC $<TARGET_PROPERTY:shl,INTERFACE_INCLUDE_DIRECTORIES>)
endif()
+ if(ENABLE_KLEIDIAI_FOR_CPU)
+ target_include_directories(${TARGET_NAME}_obj SYSTEM PUBLIC $<TARGET_PROPERTY:kleidiai,INTERFACE_INCLUDE_DIRECTORIES>)
+ endif()
+
ov_set_threading_interface_for(${TARGET_NAME}_obj)
target_compile_definitions(${TARGET_NAME}_obj PRIVATE USE_STATIC_IE)
diff --git a/src/plugins/intel_cpu/src/node.cpp b/src/plugins/intel_cpu/src/node.cpp
index 500dc352bd2..b409c85832c 100644
--- a/src/plugins/intel_cpu/src/node.cpp
+++ b/src/plugins/intel_cpu/src/node.cpp
@@ -637,6 +637,7 @@ std::string Node::getPrimitiveDescriptorType() const {
SEARCH_TYPE(sparse);
SEARCH_TYPE(acl);
SEARCH_TYPE(shl);
+ SEARCH_TYPE(kleidiai);
SEARCH_TYPE(_dw);
SEARCH_TYPE(_1x1);
@@ -1330,7 +1331,8 @@ const std::vector<impl_desc_type>& Node::getDefaultImplPriority() {
#endif
impl_desc_type::gemm_any, impl_desc_type::gemm_blas, impl_desc_type::gemm_avx512, impl_desc_type::gemm_avx2,
impl_desc_type::gemm_avx, impl_desc_type::gemm_sse42, impl_desc_type::gemm_acl, impl_desc_type::acl,
- impl_desc_type::jit_gemm, impl_desc_type::ref_any, impl_desc_type::ref,
+ impl_desc_type::gemm_kleidiai, impl_desc_type::kleidiai, impl_desc_type::jit_gemm, impl_desc_type::ref_any,
+ impl_desc_type::ref,
};
return priorities;
diff --git a/src/plugins/intel_cpu/src/nodes/executors/executor.cpp b/src/plugins/intel_cpu/src/nodes/executors/executor.cpp
index 342fcf19575..38f14605940 100644
--- a/src/plugins/intel_cpu/src/nodes/executors/executor.cpp
+++ b/src/plugins/intel_cpu/src/nodes/executors/executor.cpp
@@ -22,6 +22,7 @@ std::string ExecutorTypeToString(const ExecutorType type) {
CASE(Mlas);
CASE(jit_aarch64);
CASE(Shl);
+ CASE(Kleidiai);
}
#undef CASE
return "Undefined";
@@ -41,6 +42,7 @@ ExecutorType ExecutorTypeFromString(const std::string& typeStr) {
CASE(Mlas);
CASE(jit_aarch64);
CASE(Shl);
+ CASE(Kleidiai);
#undef CASE
return ExecutorType::Undefined;
}
diff --git a/src/plugins/intel_cpu/src/nodes/executors/executor.hpp b/src/plugins/intel_cpu/src/nodes/executors/executor.hpp
index 84dd52ea075..15cbfc1d11f 100644
--- a/src/plugins/intel_cpu/src/nodes/executors/executor.hpp
+++ b/src/plugins/intel_cpu/src/nodes/executors/executor.hpp
@@ -51,6 +51,12 @@ namespace ov::intel_cpu {
# define OV_CPU_INSTANCE_DNNL(...)
#endif
+#if defined(OV_CPU_WITH_KLEIDIAI)
+# define OV_CPU_INSTANCE_KLEIDIAI(...) {__VA_ARGS__},
+#else
+# define OV_CPU_INSTANCE_KLEIDIAI(...)
+#endif
+
#if defined(OPENVINO_ARCH_X86_64)
# define OV_CPU_INSTANCE_X64(...) {__VA_ARGS__},
#else
@@ -74,7 +80,7 @@ namespace ov::intel_cpu {
// @todo another option is to determine shape relation by executor type
enum class ShapeTolerance { Agnostic, Dependant };
-enum class ExecutorType { Undefined, Graph, Common, jit_x64, Dnnl, Acl, Mlas, jit_aarch64, Shl };
+enum class ExecutorType { Undefined, Graph, Common, jit_x64, Dnnl, Acl, Mlas, jit_aarch64, Shl, Kleidiai };
enum class OperationType { FullyConnected, MatMul, Convolution };
diff --git a/src/plugins/intel_cpu/src/nodes/executors/fullyconnected_implementations.cpp b/src/plugins/intel_cpu/src/nodes/executors/fullyconnected_implementations.cpp
index ba7b417c044..54a2fe9d4d4 100644
--- a/src/plugins/intel_cpu/src/nodes/executors/fullyconnected_implementations.cpp
+++ b/src/plugins/intel_cpu/src/nodes/executors/fullyconnected_implementations.cpp
@@ -30,6 +30,10 @@
#include "utils/cpp/maybe_unused.hpp"
#include "utils/debug_capabilities.h"
+#if defined(OV_CPU_WITH_KLEIDIAI)
+# include "nodes/executors/kleidiai/kleidiai_mm.hpp"
+#endif
+
#if defined(OV_CPU_WITH_ACL)
# include "nodes/executors/acl/acl_fullyconnected.hpp"
# include "nodes/executors/acl/acl_lowp_fullyconnected.hpp"
@@ -418,6 +422,36 @@ const std::vector<ExecutorImplementation<FCAttrs>>& getImplementations() {
const ExecutorContext::CPtr& context) {
return std::make_shared<ACLLowpFullyConnectedExecutor>(attrs, postOps, memory, context);
})
+ OV_CPU_INSTANCE_KLEIDIAI(
+ "fullyconnected_kleidiai",
+ ExecutorType::Kleidiai,
+ OperationType::MatMul,
+ ShapeTolerance::Agnostic,
+ // supports
+ [](const FCConfig& config) -> bool {
+ VERIFY(noPostOps(config), UNSUPPORTED_POST_OPS);
+ VERIFY(noSparseDecompression(config), UNSUPPORTED_SPARSE_WEIGHTS);
+ VERIFY(noWeightsDecompression(config), UNSUPPORTED_WEIGHTS_DECOMPRESSION);
+ VERIFY(everyone_is(f32, srcType(config), weiType(config), dstType(config)), UNSUPPORTED_SRC_PRECISIONS);
+ if (config.attrs.withBias) {
+ VERIFY(biaType(config) == f32, UNSUPPORTED_SRC_PRECISIONS);
+ }
+ VERIFY(srcRank(config) == 2U, UNSUPPORTED_SRC_RANK);
+ VERIFY(weiRank(config) == 2U, UNSUPPORTED_WEI_RANK);
+ return MatMulKleidiAIExecutor::supports(config);
+ },
+ // requiresFallback
+ [](const FCConfig& config) -> ov::optional<executor::Config<FCAttrs>> {
+ return {};
+ },
+ // acceptsShapes
+ [](const MemoryArgs& memory) -> bool {
+ return true;
+ },
+ // create
+ [](const FCAttrs& attrs, const PostOps& postOps, const MemoryArgs& memory, ExecutorContext::CPtr context) {
+ return std::make_shared<MatMulKleidiAIExecutor>(attrs, postOps, memory, context);
+ })
OV_CPU_INSTANCE_SHL(
"fullyconnected_shl",
ExecutorType::Shl,
diff --git a/src/plugins/intel_cpu/src/nodes/executors/kleidiai/kleidiai_mm.cpp b/src/plugins/intel_cpu/src/nodes/executors/kleidiai/kleidiai_mm.cpp
new file mode 100644
index 00000000000..6af143451e3
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/executors/kleidiai/kleidiai_mm.cpp
@@ -0,0 +1,172 @@
+// Copyright (C) 2023 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "kleidiai_mm.hpp"
+
+#include <cstdint>
+#include <memory>
+
+#include "cpu_memory.h"
+#include "memory_desc/cpu_blocked_memory_desc.h"
+#include "memory_desc/cpu_memory_desc_utils.h"
+#include "nodes/executors/executor.hpp"
+#include "nodes/executors/fullyconnected_config.hpp"
+#include "nodes/executors/memory_arguments.hpp"
+#include "openvino/core/parallel.hpp"
+#include "utils/cpu_utils.hpp"
+#include "utils/debug_capabilities.h"
+
+#define FLOAT_MAX 3.4028235e38f
+#define FLOAT_MIN -3.4028235e38f
+
+namespace ov {
+namespace intel_cpu {
+
+using namespace executor;
+using namespace ov::element;
+
+template <typename T>
+static std::vector<T> normalizeDimsTo2D(const std::vector<T>& dims) {
+ return {std::accumulate(dims.begin(), dims.end() - 1, (T)1, std::multiplies<T>()), dims[dims.size() - 1]};
+}
+
+bool MatMulKleidiAIExecutor::supports(const FCConfig& config) {
+ return true;
+}
+
+MatMulKleidiAIExecutor::MatMulKleidiAIExecutor(const FCAttrs& attrs,
+ const PostOps& postOps,
+ const MemoryArgs& memory,
+ const ExecutorContext::CPtr& context)
+ : m_attrs(attrs),
+ m_memoryArgs(memory) {
+ auto srcMem = memory.at(ARG_SRC);
+ auto weiMem = memory.at(ARG_WEI);
+ auto weiDims = weiMem->getDesc().getShape().getDims();
+ auto N = weiDims[0];
+ auto K = weiDims[1];
+
+ if (memory.at(ARG_BIAS)->getDataAs<float>() == nullptr) {
+ auto biasDesc = std::make_shared<CpuBlockedMemoryDesc>(f32, Shape({N}));
+ biasMem = std::make_shared<Memory>(context->getEngine(), biasDesc);
+ biasMem->nullify();
+ } else {
+ biasMem = memory.at(ARG_BIAS);
+ }
+ if (memory.at(ARG_SRC)->getPrecision() != memory.at(ARG_WEI)->getPrecision()) {
+ aclfcAttrs.isConvertedWeights = true;
+ }
+ auto originalWeightsDesc = memory.at(ARG_WEI)->getDescPtr();
+ const auto& wgtDims = originalWeightsDesc->getShape().getStaticDims();
+ const VectorDims wgtDims2D = reshapeDownToRank<2>(wgtDims);
+ originalWeightsDesc = std::make_shared<CpuBlockedMemoryDesc>(originalWeightsDesc->getPrecision(), Shape{wgtDims2D});
+ auto dnnlSrcDesc = MemoryDescUtils::convertToDnnlMemoryDesc(originalWeightsDesc);
+ auto dstDesc = originalWeightsDesc->cloneWithNewPrecision(memory.at(ARG_SRC)->getDescPtr()->getPrecision());
+ auto dnnlDstDesc = MemoryDescUtils::convertToDnnlMemoryDesc(dstDesc);
+ if (!attrs.weightsNonTransposed) {
+ dnnlDstDesc = acl_fc_executor::makeTransposedWeightDescriptor(dnnlDstDesc, dnnlSrcDesc);
+ aclfcAttrs.isWeightsRepacked = true;
+ }
+ packedWeights = acl_fc_executor::reorderWeights(memory, context, aclfcAttrs, dnnlSrcDesc, dnnlDstDesc);
+ const size_t rhsPackedSize = kai_get_rhs_packed_size_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon(N, K);
+ auto rhsPackedDesc = std::make_shared<CpuBlockedMemoryDesc>(f32, Shape({rhsPackedSize}));
+ rhsPackedMem = std::make_shared<Memory>(context->getEngine(), rhsPackedDesc);
+
+ float* bias = biasMem->getDataAs<float>();
+ float* rhs_packed = static_cast<float*>(rhsPackedMem->getData());
+ float* rhs = static_cast<float*>(packedWeights->getData());
+ const size_t rhs_stride = N * sizeof(float);
+
+ const size_t nr = ukernel.get_nr();
+ const size_t kr = ukernel.get_kr();
+ const size_t sr = ukernel.get_sr();
+
+ kai_run_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon(1,
+ N,
+ K,
+ nr,
+ kr,
+ sr, // Packing arguments
+ rhs_stride, // RHS stride
+ rhs, // RHS
+ bias, // Bias
+ nullptr, // Scale
+ rhs_packed, // RHS packed
+ 0,
+ nullptr);
+}
+
+bool MatMulKleidiAIExecutor::update(const MemoryArgs& memory) {
+ const auto& weiDesc = memory.at(ARG_WEI)->getDescPtr();
+ const auto& dstDesc = memory.at(ARG_DST)->getDescPtr();
+ const auto& wgtDims = weiDesc->getShape().getStaticDims();
+ // Weights are transposed by MatMulConstTransposesExtraction
+ // K is the IC of weight
+ // the weight is reshaped to [-1, K] in ConvertMatMulToFC
+ K = wgtDims[1];
+ N = wgtDims[0];
+
+ const auto& outDims = dstDesc->getShape().getStaticDims();
+ if (outDims.size() > 2) {
+ M = std::accumulate(outDims.begin(), outDims.end() - 1, 1, std::multiplies<size_t>());
+ } else {
+ M = outDims[0];
+ }
+ return true;
+}
+
+void MatMulKleidiAIExecutor::execute(const MemoryArgs& memory) {
+ size_t BLOCK_SIZE = 8;
+ auto srcMem = memory.at(ARG_SRC);
+ auto weiMem = memory.at(ARG_WEI);
+ auto dstMem = memory.at(ARG_DST);
+ auto srcDims = normalizeDimsTo2D(srcMem->getDesc().getShape().getDims());
+ auto weiDims = weiMem->getDesc().getShape().getDims();
+ auto M = srcDims[0];
+ auto K = srcDims[1];
+ auto N = weiDims[0];
+
+ const size_t lhs_stride = K * sizeof(float);
+ const size_t dst_stride_row = N * sizeof(float);
+ const size_t dst_stride_col = sizeof(float);
+
+ float* lhs = srcMem->getDataAs<float>();
+ float* rhs_packed = static_cast<float*>(rhsPackedMem->getData());
+ float* dst = dstMem->getDataAs<float>();
+
+ size_t n_blocks = (N + BLOCK_SIZE - 1) / BLOCK_SIZE;
+ parallel_for(n_blocks, [&](size_t n_block) {
+ size_t n_start = (n_block * BLOCK_SIZE);
+ size_t n_end = std::min(n_start + BLOCK_SIZE, N);
+ size_t n_block_size = n_end - n_start;
+ const size_t rhs_packed_offset = ukernel.get_rhs_packed_offset(n_start, K);
+ const size_t dst_offset = ukernel.get_dst_offset(0, n_start, dst_stride_row);
+ const float* rhs_ptr = (rhs_packed + rhs_packed_offset / sizeof(float));
+ float* dst_ptr = (dst + dst_offset / (sizeof(float)));
+ ukernel.run_matmul(M,
+ n_block_size,
+ K,
+ lhs,
+ lhs_stride,
+ rhs_ptr,
+ dst_ptr,
+ dst_stride_row,
+ dst_stride_col,
+ FLOAT_MIN,
+ FLOAT_MAX);
+ });
+}
+
+void MatMulKleidiAIExecutor::moveMemToNumaNode(int numaNodeID) {
+ if (curNumaNode == numaNodeID)
+ return;
+ curNumaNode = numaNodeID;
+ mbind_move(packedWeights, numaNodeID);
+ if (m_attrs.withBias) {
+ mbind_move(m_memoryArgs.at(ARG_BIAS), numaNodeID);
+ }
+}
+
+} // namespace intel_cpu
+} // namespace ov
\ No newline at end of file
diff --git a/src/plugins/intel_cpu/src/nodes/executors/kleidiai/kleidiai_mm.hpp b/src/plugins/intel_cpu/src/nodes/executors/kleidiai/kleidiai_mm.hpp
new file mode 100644
index 00000000000..707637bc6f5
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/executors/kleidiai/kleidiai_mm.hpp
@@ -0,0 +1,66 @@
+// Copyright (C) 2018-2022 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+#pragma once
+
+#include <memory>
+#include <oneapi/dnnl/dnnl.hpp>
+
+#include "arm_neon.h"
+#include "cpu_memory.h"
+#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"
+#include "nodes/executors/acl/acl_fullyconnected_utils.hpp"
+#include "nodes/executors/fullyconnected_config.hpp"
+
+namespace ov {
+namespace intel_cpu {
+
+class MatMulKleidiAIExecutor : public Executor {
+public:
+ MatMulKleidiAIExecutor(const FCAttrs& attrs,
+ const PostOps& postOps,
+ const MemoryArgs& memory,
+ const ExecutorContext::CPtr& context);
+
+ void execute(const MemoryArgs& memory) override;
+
+ impl_desc_type implType() const override {
+ return impl_desc_type::kleidiai;
+ }
+
+ // offloads execution data preparation from the exec call
+ bool update(const MemoryArgs& memory) override;
+
+ static bool supports(const FCConfig& config);
+
+ void moveMemToNumaNode(int numaNodeID) override;
+
+private:
+ 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};
+
+ const FCAttrs& m_attrs;
+ ACLFCAttrs aclfcAttrs;
+ const MemoryArgs& m_memoryArgs;
+ MemoryPtr biasMem;
+ MemoryPtr rhsPackedMem;
+ MemoryCPtr packedWeights;
+ int64_t M, N, K;
+ int curNumaNode = -1;
+};
+
+using MatMulKleidiAIExecutorPtr = std::shared_ptr<MatMulKleidiAIExecutor>;
+
+} // namespace intel_cpu
+} // namespace ov
\ No newline at end of file
diff --git a/src/plugins/intel_cpu/src/onednn/iml_type_mapper.cpp b/src/plugins/intel_cpu/src/onednn/iml_type_mapper.cpp
index c2f4fb80db8..b59d89678c6 100644
--- a/src/plugins/intel_cpu/src/onednn/iml_type_mapper.cpp
+++ b/src/plugins/intel_cpu/src/onednn/iml_type_mapper.cpp
@@ -57,6 +57,7 @@ impl_desc_type parse_impl_name(std::string impl_desc_name) {
SEARCH_WORD(reorder);
SEARCH_WORD(sparse);
SEARCH_WORD(acl);
+ SEARCH_WORD(kleidiai);
SEARCH_WORD(shl);
SEARCH_WORD(asimd);
if ((res & impl_desc_type::avx2) != impl_desc_type::avx2 &&
@@ -152,6 +153,8 @@ const char* impl_type_to_string(impl_desc_type type) {
CASE(jit_sve512);
CASE(shl);
CASE(gemm_shl);
+ CASE(kleidiai);
+ CASE(gemm_kleidiai);
#undef CASE
return "unknown";
diff --git a/src/plugins/intel_cpu/src/onednn/iml_type_mapper.h b/src/plugins/intel_cpu/src/onednn/iml_type_mapper.h
index 6079e8febb8..f9766fafea4 100644
--- a/src/plugins/intel_cpu/src/onednn/iml_type_mapper.h
+++ b/src/plugins/intel_cpu/src/onednn/iml_type_mapper.h
@@ -51,6 +51,8 @@ enum impl_desc_type : int64_t {
// shl backend
shl = 1ll << 32,
+ kleidiai = 1ll << 33,
+
// real types
ref_any = ref | any,
@@ -120,7 +122,8 @@ enum impl_desc_type : int64_t {
jit_sve384 = jit | sve384,
jit_sve512 = jit | sve512,
- gemm_shl = gemm | shl
+ gemm_shl = gemm | shl,
+ gemm_kleidiai = gemm | kleidiai
};
std::vector<std::string> extractTypeAndImplName(const std::string& priority);
diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/arm/matmul.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/arm/matmul.cpp
index 4afdd90427b..809e0442b9a 100644
--- a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/arm/matmul.cpp
+++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/arm/matmul.cpp
@@ -141,4 +141,4 @@ INSTANTIATE_TEST_SUITE_P(smoke_FC_4D_f16, MatMulLayerCPUTest, testParams4D_smoke
} // namespace matmul
} // namespace MatMul
} // namespace test
-} // namespace ov
+} // namespace ov
\ No newline at end of file
diff --git a/src/plugins/intel_cpu/tests/functional/utils/arm/filter_cpu_info.cpp b/src/plugins/intel_cpu/tests/functional/utils/arm/filter_cpu_info.cpp
index a6d19d962fe..b0dea849035 100644
--- a/src/plugins/intel_cpu/tests/functional/utils/arm/filter_cpu_info.cpp
+++ b/src/plugins/intel_cpu/tests/functional/utils/arm/filter_cpu_info.cpp
@@ -22,7 +22,8 @@ std::vector<CPUSpecificParams> filterCPUInfoForArch(const std::vector<CPUSpecifi
auto selectedTypeStr = std::get<selectedTypeIndex>(param);
if (selectedTypeStr.find("acl") == std::string::npos &&
- selectedTypeStr.find("ref") == std::string::npos)
+ selectedTypeStr.find("ref") == std::string::npos &&
+ selectedTypeStr.find("kleidiai") == std::string::npos)
continue;
#if defined(OPENVINO_ARCH_ARM)
// disable gemm_acl on 32-bit arm platforms because oneDNN\ACL does not support it
diff --git a/src/plugins/intel_cpu/tests/unit/CMakeLists.txt b/src/plugins/intel_cpu/tests/unit/CMakeLists.txt
index 0a628bc8bb0..7cfcaa3196f 100644
--- a/src/plugins/intel_cpu/tests/unit/CMakeLists.txt
+++ b/src/plugins/intel_cpu/tests/unit/CMakeLists.txt
@@ -40,6 +40,10 @@ if (ENABLE_SHL_FOR_CPU)
set(SHL_LIBRARY "shl")
endif()
+if (ENABLE_KLEIDIAI_FOR_CPU)
+ set(KLEIDIAI_LIBRARY "kleidiai")
+endif()
+
ov_add_test_target(
NAME ${TARGET_NAME}
ROOT ${CMAKE_CURRENT_SOURCE_DIR}
@@ -70,6 +74,7 @@ ov_add_test_target(
snippets_test_utils
${MLAS_LIBRARY}
${SHL_LIBRARY}
+ ${KLEIDIAI_LIBRARY}
ADD_CPPLINT
LABELS
OV UNIT CPU
diff --git a/src/plugins/intel_cpu/thirdparty/CMakeLists.txt b/src/plugins/intel_cpu/thirdparty/CMakeLists.txt
index f25b5205784..d172e457986 100644
--- a/src/plugins/intel_cpu/thirdparty/CMakeLists.txt
+++ b/src/plugins/intel_cpu/thirdparty/CMakeLists.txt
@@ -26,6 +26,12 @@ function(ov_create_acl_version_file)
file(WRITE ${ACL_VERSION_FILE_PATH} "\"arm_compute_version=v${ACL_VERSION}\"")
endfunction()
+function(ov_build_kleidiai_static)
+ set(BUILD_SHARED_LIBS OFF)
+ set(KLEIDIAI_BUILD_TESTS OFF CACHE BOOL "" FORCE)
+ add_subdirectory(kleidiai EXCLUDE_FROM_ALL)
+endfunction()
+
function(ov_add_onednn)
set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)
set(CMAKE_DISABLE_FIND_PACKAGE_PythonInterp ON)
@@ -169,4 +175,9 @@ if(ENABLE_SHL_FOR_CPU)
ov_install_static_lib(shl ${OV_CPACK_COMP_CORE})
endif()
+if(ENABLE_KLEIDIAI_FOR_CPU)
+ ov_build_kleidiai_static()
+ ov_install_static_lib(kleidiai ${OV_CPACK_COMP_CORE})
+endif()
+
ov_add_onednn()
diff --git a/src/plugins/intel_cpu/thirdparty/kleidiai b/src/plugins/intel_cpu/thirdparty/kleidiai
new file mode 160000
index 00000000000..eaf63a6ae9a
--- /dev/null
+++ b/src/plugins/intel_cpu/thirdparty/kleidiai
@@ -0,0 +1 @@
+Subproject commit eaf63a6ae9a903fb4fa8a4d004a974995011f444