Skip to content

Enables Windows ARM64 build with MSVC cl.exe - #28362

Merged
aendk merged 18 commits into
ggml-org:masterfrom
sarahwu185:sarwu/windows_arm64_fix
Sep 28, 2026
Merged

aendk merged 18 commits into
ggml-org:masterfrom
sarahwu185:sarwu/windows_arm64_fix

Conversation

@sarahwu185

@sarahwu185 sarahwu185 commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Overview

In the current flow on WoA systems the default is to build with the arm64-windows-llvm-release preset, which requires developers to install clang when building MSVC. This PR allows developers to directly use cmake -B build -S . -DGGML_NATIVE=ON to build the project on WoA systems.

In addition to build with ARM64EC, users can simply do cmake -S . -B build_arm64ec -A ARM64EC

Additional information

For context, several MSVC gaps for NEON intrinsics were identified.

  1. FP16 vector intrinsics not implemented in MSVC
  2. dotprod probing volatile issue
  3. i8mm probing volatile issue
  4. SME/SVE not implemented in MSVC
  5. Other Feature detection error with MSVC (such as FMA)

For item 2 and 3, we dropped the volatile keyword in cmake, and for 5 some corresponding cmake changes were added either during flag checking or when probing happens. Additional change is in quant.c to make the syntax conform to MSVC.

However, since item 1, 4 are still pending MSVC support, native MSVC build cannot turn on all of the arm intrinsics support as compared to clang build. So there is performance gap on the CPU backend.

Profiling results

For other systems (linux, x86_64 windows), we locally tested and saw no performance degradation between PR and master.

Local profiling MSVC build vs clang.exe build performance is also on par.

Another thing to note is that MSVC does not define __NEON_ARM by default even though there is the arm neon header in MSVC. This means in quant.c, MSVC compiler will go through generic path when compiling. However, when I forcefully turn on this flag, I see an around 37% performance drop on CPU workloads. This is because MSVC already auto-vectorizes the generic C kernels when that header is not defined, defining the macros forces the compiler down the hand written intrinsics which is less performant.

Future Works

While working on this, I found that arm64-windows-llvm-release is still just defaulting to cross compile for WoA. This actually automatically turn off -DGGML_NATIVE and does not actually enable some of the arm intrinsics that clang allows.

I think we will need more profiling work into whether we should switch on __NEON_ARM for MSVC or we should just let MSVC to auto-vectorize the instructions. Especially when more missing NEON intrinsics are support in MSVC in the future.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: yes, AI is used for testing on systems, for syntax and cmake changes.

@github-actions github-actions Bot added the ggml changes relating to the ggml tensor library for machine learning label Sep 4, 2026
@sarahwu185
sarahwu185 marked this pull request as ready for review September 4, 2026 05:42
@ggml-gh-bot

ggml-gh-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

Hi @sarahwu185, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • Multiple open PRs from a new contributor: We limit new contributors (those without a previously merged PR) to 1 open PR at a time. You currently have 2 open PRs.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@sarahwu185
sarahwu185 force-pushed the sarwu/windows_arm64_fix branch from 18eaa3a to bce6a32 Compare September 8, 2026 22:59
@github-actions github-actions Bot added mtmd Related to multimodal functionality (video/image/audio) CUDA Related to the CUDA backend labels Sep 8, 2026
@sarahwu185
sarahwu185 marked this pull request as ready for review September 8, 2026 23:03
@sarahwu185
sarahwu185 requested review from a team as code owners September 8, 2026 23:03
@ggerganov ggerganov self-assigned this Sep 9, 2026
@aendk

aendk commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

@ggerganov @sarahwu185 just for reference, I evaluated this PR with the PR-skill; as cmake is not my specialty.
It reports the following possible gaps:

Code review(review · 6 findings)
ggml/cmake/common.cmake
  ●   30 [correctness] GGML_SYSTEM_ARCH detection never matches "arm64ec", so this whole PR's arm64ec code path is unreachable dead code on its own target platform.
ggml/src/ggml-cpu/llamafile/sgemm.cpp
  ●  231 [correctness] The MSVC/arm64 guard around hsum(float32x4_t) was widened, but the arm_neon.h include and sibling load<float32x4_t>/dispatch call sites weren't updated to match.
ggml/src/ggml-cpu/CMakeLists.txt
  ●  146 [correctness] check_arm_feature still emits GCC-style "-mcpu=native+tag" flags even on the new real-MSVC (cl.exe) detection path, which cl.exe rejects.
  ●  150 [style]       New comments in this PR violate AGENTS.md's formatting rule (concise, no hard-wrap, no mid-sentence line split).
ggml/src/ggml-cpu/arch/arm/quants.c
  ●  858 [correctness] The NVFP4 dot-product kernel (ggml_vec_dot_iq1_m_q8_K's sibling) still uses raw NEON brace-init syntax that this PR exists to eliminate for MSVC.
  ● 2722 [correctness] uint32x2_t mins8 = {0} brace-initializers (also at line 2809) were missed by the same brace-init-to-intrinsic conversion this PR applied to the sibling q4_K site.

Are the correctness-remarks valid? If so, these should be fixed before merge.

address CI comments

fix cross compile issue

remove warning

fix style and fix fma probing

fix style
@sarahwu185

Copy link
Copy Markdown
Contributor Author

Hello @aendk Thank you so much for the comments!

GGML_SYSTEM_ARCH detection never matches "arm64ec", so this whole PR's arm64ec code path is unreachable dead code on its own target platform.

arm64ec is in fact reachable when user specify -A ARM64EC regardless of GGML_SYSTEM_ARCH. But it is true that GGML_SYSTEM_ARCH is set to UNKNOWN if we are compiling for arm64ec. I have patched this.

The MSVC/arm64 guard around hsum(float32x4_t) was widened, but the arm_neon.h include and sibling load<float32x4_t>/dispatch call sites weren't updated to match.

We only need to widen hsum guard to get pass the compile errors. The load dispatch is currently unreachable as MSVC lacks support for SVE.

check_arm_feature still emits GCC-style "-mcpu=native+tag" flags even on the new real-MSVC (cl.exe) detection path, which cl.exe rejects.

Yes, I have fixed this, now the warnings are gone.

New comments in this PR violate AGENTS.md's formatting rule (concise, no hard-wrap, no mid-sentence line split).

Fixed.

The NVFP4 dot-product kernel (ggml_vec_dot_iq1_m_q8_K's sibling) still uses raw NEON brace-init syntax that this PR exists to eliminate for MSVC.

This is correct. I have fixed this.

uint32x2_t mins8 = {0} brace-initializers (also at line 2809) were missed by the same brace-init-to-intrinsic conversion this PR applied to the sibling q4_K site.

This one does not need to be changed. MSVC has syntax support for this.

I iterated locally with Claude to PR review a few times and now there are still generated issues but they seem minor/inaccurate. I also tested the new changes locally and there is no functional/performance impact.

Let me know if other changes are needed.

@aendk
aendk self-requested a review September 11, 2026 11:58
@aendk

aendk commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Thanks for the fixes!
Following up internally to ensure compatibility with unreleased arm64 platforms 👍

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Sep 21, 2026

@aendk aendk 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.

Looks good to me after conducting some internal testing.

@aendk

aendk commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

claude tells me via gh that the CI failures are unrelated to this PR, as they were also present in the master.

So please rebase again and then we can merge it. Thanks!

@aendk
aendk merged commit 0c6a6a7 into ggml-org:master Sep 28, 2026
38 of 42 checks passed
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 7, 2026
* can reproduce the issue vlad sees

* fix fma issue

* drop volatile

* fix volatile runtime task

* add arm flag if needed

* fix hsum compile error

* fix syntax in quants

* strengthen sve probing

* make the syntax fixes one liners

* remove debug code

* formatting

* remove macro for float

* drive down gcc instruction count

* support armec

* fix CI comments

address CI comments

fix cross compile issue

remove warning

fix style and fix fma probing

fix style

* add documentation

* update documentation

(cherry picked from commit 0c6a6a7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA Related to the CUDA backend documentation Improvements or additions to documentation ggml changes relating to the ggml tensor library for machine learning mtmd Related to multimodal functionality (video/image/audio)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants