fix x86_64 arch detection when cross-compiling on macos arm64#6730
Open
LudovicoYIN wants to merge 2 commits into
Open
fix x86_64 arch detection when cross-compiling on macos arm64#6730LudovicoYIN wants to merge 2 commits into
LudovicoYIN wants to merge 2 commits into
Conversation
Member
Author
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6730 +/- ##
==========================================
- Coverage 95.96% 95.93% -0.03%
==========================================
Files 970 970
Lines 403093 403668 +575
==========================================
+ Hits 386820 387273 +453
- Misses 16273 16395 +122 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes incorrect target architecture detection when cross-compiling ncnn for x86_64 on Apple Silicon (macOS arm64) with -DCMAKE_OSX_ARCHITECTURES=x86_64, which previously caused the build to be treated as ARM and skipped all x86 SIMD feature detection.
Changes:
- Adjust ARM-architecture detection on Apple platforms to avoid using
CMAKE_SYSTEM_PROCESSOR(host CPU) whenCMAKE_OSX_ARCHITECTURESis explicitly set to a non-ARM architecture. - Ensures x86_64 cross-compiles on macOS arm64 properly follow the x86 feature-probing path (SSE/AVX/etc.).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix #6505 — when cross-compiling ncnn for x86_64 on macOS arm64 with
-DCMAKE_OSX_ARCHITECTURES=x86_64, the target architecture is incorrectlydetected as ARM, causing all x86 SIMD optimizations (SSE/AVX/AVX2/AVX512)
to be skipped.
Root cause
In
CMakeLists.txt:164,CMAKE_SYSTEM_PROCESSORalways reports the hostCPU (
arm64), even whenCMAKE_OSX_ARCHITECTURESis explicitly set tox86_64. This causes the ARM arch branch to match, settingNCNN_TARGET_ARCHtoarminstead ofx86.Fix
On Apple platforms, skip the
CMAKE_SYSTEM_PROCESSORarm match whenCMAKE_OSX_ARCHITECTURESis explicitly set to a non-arm architecture.Before / After