Skip to content

Add JIT compiler support for Windows - #3556

Merged
zcbenz merged 3 commits into
ml-explore:mainfrom
dhiltgen:pr/jit-windows
May 20, 2026
Merged

zcbenz merged 3 commits into
ml-explore:mainfrom
dhiltgen:pr/jit-windows

Conversation

@dhiltgen

Copy link
Copy Markdown
Contributor

Proposed changes

Split out from #3019

Enable CPU mx.compile() on Windows by detecting and using clang-cl bundled with Visual Studio, or MSVC cl.exe, for JIT compilation.

Keep GPU compile availability independent from the CPU compiler probe so CPU+GPU builds do not disable GPU mx.compile() when a host C++ compiler is unavailable.

Changes:

  • Add clang-cl detection via vswhere and prefer a compiler matching the build toolchain
  • Add JitCompiler::available() to probe CPU JIT availability
  • Emit and load .dll JIT libraries on Windows
  • Support both MSVC and GCC/Clang preamble generation scripts, including optional SIMD flags
  • Use WIN32 shell detection and pass preamble SIMD flags through CMake
  • Define NOMINMAX/WIN32_LEAN_AND_MEAN on all WIN32 compilers

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

Comment thread mlx/backend/cpu/jit_compiler.cpp Resolved
Comment thread mlx/backend/cpu/jit_compiler.cpp Resolved
Comment thread mlx/backend/cpu/jit_compiler.cpp Resolved
Comment thread mlx/backend/cpu/jit_compiler.cpp Resolved
Comment thread mlx/backend/cpu/jit_compiler.cpp Resolved
@dhiltgen
dhiltgen force-pushed the pr/jit-windows branch 2 times, most recently from b74e03c to c5fc3d3 Compare May 17, 2026 16:01

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

dhiltgen and others added 3 commits May 18, 2026 09:26
Enable CPU mx.compile() on Windows by detecting and using clang-cl bundled with Visual Studio, or MSVC cl.exe, for JIT compilation.

Keep GPU compile availability independent from the CPU compiler probe so CPU+GPU builds do not disable GPU mx.compile() when a host C++ compiler is unavailable.

Changes:
- Add clang-cl detection via vswhere and prefer a compiler matching the build toolchain
- Add JitCompiler::available() to probe CPU JIT availability
- Emit and load .dll JIT libraries on Windows
- Support both MSVC and GCC/Clang preamble generation scripts, including optional SIMD flags
- Use WIN32 shell detection and pass preamble SIMD flags through CMake
- Define NOMINMAX/WIN32_LEAN_AND_MEAN on all WIN32 compilers
Also fixed Visual Studio compiler selection conservative for the embedded prebuilt preamble fallback while preferring cl.exe when installed headers are available.

Pass Visual Studio INCLUDE paths from vcvarsall into runtime JIT compilations so normal Python processes can find VC and Windows SDK headers.
@zcbenz
zcbenz merged commit 5d1c0e4 into ml-explore:main May 20, 2026
16 checks passed
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