Skip to content

Commit ff06fa3

Browse files
authored
[CPU][ARM] KleidiAI integration and KleidiAI MM executor (openvinotoolkit#28830)
### Details: - `kleidiai` is added as git submodule - `kleidiai` is built statically and linked into cpu plugin library - MatMul kleidiai executor is added - weights transpose is supported in MatMul kleidiai executor - Initial implementation is inherited from openvinotoolkit#27331 ### Tickets: - *ticket-id*
1 parent e4d042e commit ff06fa3

File tree

16 files changed

+420
-5
lines changed

16 files changed

+420
-5
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,6 @@
8787
[submodule "src/plugins/intel_cpu/thirdparty/shl"]
8888
path = src/plugins/intel_cpu/thirdparty/shl
8989
url = https://github.com/openvinotoolkit/shl.git
90+
[submodule "src/plugins/intel_cpu/thirdparty/kleidiai"]
91+
path = src/plugins/intel_cpu/thirdparty/kleidiai
92+
url = https://git.gitlab.arm.com/kleidi/kleidiai.git

licensing/third-party-programs.txt

+84
Original file line numberDiff line numberDiff line change
@@ -1872,3 +1872,87 @@ distributed under the License is distributed on an "AS IS" BASIS,
18721872
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18731873
See the License for the specific language governing permissions and
18741874
limitations under the License.
1875+
-------------------------------------------------------------
1876+
1877+
32. KleidiAI (https://git.gitlab.arm.com/kleidi/kleidiai)
1878+
Copyright 2024-2025 Arm Limited and/or its affiliates <open-source-office@arm.com>
1879+
1880+
Apache License
1881+
Version 2.0, January 2004
1882+
http://www.apache.org/licenses/
1883+
1884+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1885+
1886+
1. Definitions.
1887+
1888+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
1889+
1890+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
1891+
1892+
"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.
1893+
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.
1894+
1895+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
1896+
1897+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
1898+
1899+
"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.
1900+
1901+
"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).
1902+
1903+
"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.
1904+
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.
1905+
1906+
"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.
1907+
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."
1908+
1909+
"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.
1910+
1911+
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.
1912+
1913+
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.
1914+
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.
1915+
1916+
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:
1917+
1918+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
1919+
1920+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
1921+
1922+
(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
1923+
1924+
(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.
1925+
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.
1926+
1927+
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.
1928+
1929+
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.
1930+
1931+
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.
1932+
1933+
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.
1934+
1935+
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.
1936+
1937+
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.
1938+
1939+
END OF TERMS AND CONDITIONS
1940+
1941+
APPENDIX: How to apply the Apache License to your work.
1942+
1943+
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.
1944+
1945+
Copyright [yyyy] [name of copyright owner]
1946+
1947+
Licensed under the Apache License, Version 2.0 (the "License");
1948+
you may not use this file except in compliance with the License.
1949+
You may obtain a copy of the License at
1950+
1951+
http://www.apache.org/licenses/LICENSE-2.0
1952+
1953+
Unless required by applicable law or agreed to in writing, software
1954+
distributed under the License is distributed on an "AS IS" BASIS,
1955+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1956+
See the License for the specific language governing permissions and
1957+
limitations under the License.
1958+
-------------------------------------------------------------

src/plugins/intel_cpu/CMakeLists.txt

+22
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ else()
146146
endif()
147147
ov_dependent_option(ENABLE_SHL_FOR_CPU "Enable SHL for OpenVINO CPU Plugin" ${ENABLE_SHL_FOR_CPU_DEFAULT} "RISCV64" OFF)
148148

149+
if(AARCH64)
150+
set(ENABLE_KLEIDIAI_FOR_CPU_DEFAULT ON)
151+
else()
152+
set(ENABLE_KLEIDIAI_FOR_CPU_DEFAULT OFF)
153+
endif()
154+
ov_dependent_option(ENABLE_KLEIDIAI_FOR_CPU "Enable KleidiAI for OpenVINO CPU Plugin" ${ENABLE_KLEIDIAI_FOR_CPU_DEFAULT} "AARCH64" OFF)
155+
149156
add_subdirectory(thirdparty)
150157

151158
if(WIN32)
@@ -171,6 +178,11 @@ if(DNNL_USE_ACL)
171178
set(OV_CPU_WITH_ACL ON)
172179
endif()
173180

181+
if(ENABLE_KLEIDIAI_FOR_CPU)
182+
add_definitions(-DOV_CPU_WITH_KLEIDIAI)
183+
set(OV_CPU_WITH_KLEIDIAI ON)
184+
endif()
185+
174186
if (ENABLE_SHL_FOR_CPU)
175187
add_definitions(-DOV_CPU_WITH_SHL)
176188
set(OV_CPU_WITH_SHL ON)
@@ -200,6 +212,8 @@ endif()
200212
if (AARCH64)
201213
# this directory is reused on RISCV64
202214
list(APPEND EXCLUDE_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/src/transformations/snippets/x64/*)
215+
else()
216+
list(APPEND EXCLUDE_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/src/nodes/executors/kleidiai/*)
203217
endif()
204218

205219
if(NOT (AARCH64 OR ARM))
@@ -265,6 +279,10 @@ endif ()
265279
if(ENABLE_SHL_FOR_CPU)
266280
target_link_libraries(${TARGET_NAME} PRIVATE shl)
267281
endif()
282+
if(ENABLE_KLEIDIAI_FOR_CPU)
283+
target_link_libraries(${TARGET_NAME} PRIVATE kleidiai)
284+
endif()
285+
268286
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE $<TARGET_PROPERTY:dnnl,INCLUDE_DIRECTORIES>)
269287

270288
# Temporal solution to use template reference implementations in cases where optimizied implementation
@@ -368,6 +386,10 @@ if(BUILD_SHARED_LIBS)
368386
target_include_directories(${TARGET_NAME}_obj SYSTEM PUBLIC $<TARGET_PROPERTY:shl,INTERFACE_INCLUDE_DIRECTORIES>)
369387
endif()
370388

389+
if(ENABLE_KLEIDIAI_FOR_CPU)
390+
target_include_directories(${TARGET_NAME}_obj SYSTEM PUBLIC $<TARGET_PROPERTY:kleidiai,INTERFACE_INCLUDE_DIRECTORIES>)
391+
endif()
392+
371393
ov_set_threading_interface_for(${TARGET_NAME}_obj)
372394

373395
target_compile_definitions(${TARGET_NAME}_obj PRIVATE USE_STATIC_IE)

src/plugins/intel_cpu/src/node.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ std::string Node::getPrimitiveDescriptorType() const {
637637
SEARCH_TYPE(sparse);
638638
SEARCH_TYPE(acl);
639639
SEARCH_TYPE(shl);
640+
SEARCH_TYPE(kleidiai);
640641
SEARCH_TYPE(_dw);
641642
SEARCH_TYPE(_1x1);
642643

@@ -1330,7 +1331,8 @@ const std::vector<impl_desc_type>& Node::getDefaultImplPriority() {
13301331
#endif
13311332
impl_desc_type::gemm_any, impl_desc_type::gemm_blas, impl_desc_type::gemm_avx512, impl_desc_type::gemm_avx2,
13321333
impl_desc_type::gemm_avx, impl_desc_type::gemm_sse42, impl_desc_type::gemm_acl, impl_desc_type::acl,
1333-
impl_desc_type::jit_gemm, impl_desc_type::ref_any, impl_desc_type::ref,
1334+
impl_desc_type::gemm_kleidiai, impl_desc_type::kleidiai, impl_desc_type::jit_gemm, impl_desc_type::ref_any,
1335+
impl_desc_type::ref,
13341336
};
13351337

13361338
return priorities;

src/plugins/intel_cpu/src/nodes/executors/executor.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ std::string ExecutorTypeToString(const ExecutorType type) {
2222
CASE(Mlas);
2323
CASE(jit_aarch64);
2424
CASE(Shl);
25+
CASE(Kleidiai);
2526
}
2627
#undef CASE
2728
return "Undefined";
@@ -41,6 +42,7 @@ ExecutorType ExecutorTypeFromString(const std::string& typeStr) {
4142
CASE(Mlas);
4243
CASE(jit_aarch64);
4344
CASE(Shl);
45+
CASE(Kleidiai);
4446
#undef CASE
4547
return ExecutorType::Undefined;
4648
}

src/plugins/intel_cpu/src/nodes/executors/executor.hpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ namespace ov::intel_cpu {
5151
# define OV_CPU_INSTANCE_DNNL(...)
5252
#endif
5353

54+
#if defined(OV_CPU_WITH_KLEIDIAI)
55+
# define OV_CPU_INSTANCE_KLEIDIAI(...) {__VA_ARGS__},
56+
#else
57+
# define OV_CPU_INSTANCE_KLEIDIAI(...)
58+
#endif
59+
5460
#if defined(OPENVINO_ARCH_X86_64)
5561
# define OV_CPU_INSTANCE_X64(...) {__VA_ARGS__},
5662
#else
@@ -74,7 +80,7 @@ namespace ov::intel_cpu {
7480
// @todo another option is to determine shape relation by executor type
7581
enum class ShapeTolerance { Agnostic, Dependant };
7682

77-
enum class ExecutorType { Undefined, Graph, Common, jit_x64, Dnnl, Acl, Mlas, jit_aarch64, Shl };
83+
enum class ExecutorType { Undefined, Graph, Common, jit_x64, Dnnl, Acl, Mlas, jit_aarch64, Shl, Kleidiai };
7884

7985
enum class OperationType { FullyConnected, MatMul, Convolution };
8086

src/plugins/intel_cpu/src/nodes/executors/fullyconnected_implementations.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
#include "utils/cpp/maybe_unused.hpp"
3131
#include "utils/debug_capabilities.h"
3232

33+
#if defined(OV_CPU_WITH_KLEIDIAI)
34+
# include "nodes/executors/kleidiai/kleidiai_mm.hpp"
35+
#endif
36+
3337
#if defined(OV_CPU_WITH_ACL)
3438
# include "nodes/executors/acl/acl_fullyconnected.hpp"
3539
# include "nodes/executors/acl/acl_lowp_fullyconnected.hpp"
@@ -418,6 +422,36 @@ const std::vector<ExecutorImplementation<FCAttrs>>& getImplementations() {
418422
const ExecutorContext::CPtr& context) {
419423
return std::make_shared<ACLLowpFullyConnectedExecutor>(attrs, postOps, memory, context);
420424
})
425+
OV_CPU_INSTANCE_KLEIDIAI(
426+
"fullyconnected_kleidiai",
427+
ExecutorType::Kleidiai,
428+
OperationType::MatMul,
429+
ShapeTolerance::Agnostic,
430+
// supports
431+
[](const FCConfig& config) -> bool {
432+
VERIFY(noPostOps(config), UNSUPPORTED_POST_OPS);
433+
VERIFY(noSparseDecompression(config), UNSUPPORTED_SPARSE_WEIGHTS);
434+
VERIFY(noWeightsDecompression(config), UNSUPPORTED_WEIGHTS_DECOMPRESSION);
435+
VERIFY(everyone_is(f32, srcType(config), weiType(config), dstType(config)), UNSUPPORTED_SRC_PRECISIONS);
436+
if (config.attrs.withBias) {
437+
VERIFY(biaType(config) == f32, UNSUPPORTED_SRC_PRECISIONS);
438+
}
439+
VERIFY(srcRank(config) == 2U, UNSUPPORTED_SRC_RANK);
440+
VERIFY(weiRank(config) == 2U, UNSUPPORTED_WEI_RANK);
441+
return MatMulKleidiAIExecutor::supports(config);
442+
},
443+
// requiresFallback
444+
[](const FCConfig& config) -> ov::optional<executor::Config<FCAttrs>> {
445+
return {};
446+
},
447+
// acceptsShapes
448+
[](const MemoryArgs& memory) -> bool {
449+
return true;
450+
},
451+
// create
452+
[](const FCAttrs& attrs, const PostOps& postOps, const MemoryArgs& memory, ExecutorContext::CPtr context) {
453+
return std::make_shared<MatMulKleidiAIExecutor>(attrs, postOps, memory, context);
454+
})
421455
OV_CPU_INSTANCE_SHL(
422456
"fullyconnected_shl",
423457
ExecutorType::Shl,

0 commit comments

Comments
 (0)