Skip to content

Move KleidiAI support detection to CMake logic.#26178

Merged
edgchen1 merged 6 commits into
mainfrom
edgchen1/kleidiai_support_detection
Sep 30, 2025
Merged

Move KleidiAI support detection to CMake logic.#26178
edgchen1 merged 6 commits into
mainfrom
edgchen1/kleidiai_support_detection

Conversation

@edgchen1

@edgchen1 edgchen1 commented Sep 26, 2025

Copy link
Copy Markdown
Contributor

Description

Use of the KleidiAI library is not supported on all platforms. Previously, this support detection was done in both tools/ci_build/build.py and cmake/CMakeLists.txt. This change consolidates and simplifies the checks. They are now done in one place in the CMake logic.

Motivation and Context

Clean up and simplify.

Comment thread cmake/detect_onnxruntime_target_platform.cmake

@snnn snnn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! I've reviewed the changes, and this is a great refactoring that simplifies the build logic. I have a few technical suggestions for improvement.


1. Potential bug in KleidiAI platform detection for Apple

In cmake/CMakeLists.txt, the platform check for Apple is:

if(NOT (... OR (APPLE AND CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")))

This check depends on CMAKE_OSX_ARCHITECTURES being defined. According to the logic in the new cmake/detect_onnxruntime_target_platform.cmake file, if CMAKE_OSX_ARCHITECTURES is not defined during a build on an Apple machine, onnxruntime_target_platform is set from CMAKE_SYSTEM_PROCESSOR. For a native build on Apple Silicon, this means onnxruntime_target_platform would be arm64, but CMAKE_OSX_ARCHITECTURES would be undefined.

In this case, the check above would evaluate to false, and KleidiAI would be incorrectly disabled.

A more robust condition would be to check onnxruntime_target_platform directly:

if(NOT (... OR (APPLE AND onnxruntime_target_platform STREQUAL "arm64")))

This would correctly enable KleidiAI for native Apple Silicon builds, regardless of whether CMAKE_OSX_ARCHITECTURES is explicitly set.

2. Potential issues in cmake/adjust_global_compile_flags.cmake

I noticed two small things in this file:

  • The if/elseif chain appears to have a syntax error based on the indentation in the diff. It looks like an if statement was added after an elseif, but before the final else, which is not valid CMake syntax. The logic for enabling SAFESEH for x86 builds should likely be nested inside the elseif block that checks for x64 or x86, or placed after the entire if-elseif-else block.

  • The FATAL_ERROR message at the end of that block seems to have a copy-paste error:

    message(FATAL_ERROR "Unknown CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")

    Since the variable being checked throughout this block is onnxruntime_target_platform, the error message should probably refer to that variable for clearer debugging:

    message(FATAL_ERROR "Unknown onnxruntime_target_platform: ${onnxruntime_target_platform}")

This review comment was generated by an AI assistant.

@edgchen1 edgchen1 changed the title [WIP] Move KleidiAI support detection to CMake logic. Move KleidiAI support detection to CMake logic. Sep 29, 2025
@edgchen1 edgchen1 marked this pull request as ready for review September 29, 2025 16:41
@edgchen1 edgchen1 requested a review from snnn September 29, 2025 16:46
snnn
snnn previously approved these changes Sep 29, 2025
@edgchen1 edgchen1 merged commit 2e8a45a into main Sep 30, 2025
92 checks passed
@edgchen1 edgchen1 deleted the edgchen1/kleidiai_support_detection branch September 30, 2025 13:55
fs-eire pushed a commit that referenced this pull request Oct 24, 2025
### Description
<!-- Describe your changes. -->

Use of the KleidiAI library is not supported on all platforms. Previously, this support detection was done in both
`tools/ci_build/build.py` and `cmake/CMakeLists.txt`. This change consolidates and simplifies the checks. They are now done in one place in the CMake logic.

Move setting of onnxruntime_target_platform into a separate file.

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->

Clean up and simplify.
naomiOvad pushed a commit to naomiOvad/onnxruntime that referenced this pull request Nov 2, 2025
### Description
<!-- Describe your changes. -->

Use of the KleidiAI library is not supported on all platforms. Previously, this support detection was done in both
`tools/ci_build/build.py` and `cmake/CMakeLists.txt`. This change consolidates and simplifies the checks. They are now done in one place in the CMake logic.

Move setting of onnxruntime_target_platform into a separate file.

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->

Clean up and simplify.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants