GitHub - Lulzx/cuda-metal: CUDA compiler and runtime for Apple Silicon

GitHub

2 min read Original article ↗

CuMetal

CuMetal is a CUDA compiler and runtime for Apple Silicon. It compiles supported CUDA C++ and PTX into Metal kernels, so you can run existing CUDA code on your Mac’s GPU without rewriting it in Metal.

The project is experimental and supports a tested subset of CUDA and its libraries. See verified results for what runs today and known gaps for the remaining limits.

Install

Requires Apple Silicon and macOS 14 or newer. See the installation guide for compiler and Apple toolchain requirements.

brew install lulzx/tap/cumetal
cumetal doctor

Compile and run your CUDA source:

cumetalc kernel.cu -o kernel
./kernel

Build from source

From a checkout with the build prerequisites installed:

cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j"$(sysctl -n hw.ncpu)"

build/cumetalc samples/vectorAdd/vectorAdd.cu -o vectorAdd
./vectorAdd

See demos for larger workloads and testing for validation commands.

How it works

CUDA C++ / PTX → CuMetal compiler → Metal Shading Language → Apple tools → metallib

Source recompilation is the primary path. Direct CUDA C++ compilation uses typed CuMetal IR and embeds the compiled Metal library in the executable, with no first-launch PTX JIT. CuMetal uses no private Apple APIs. See compiler architecture for backend details.

Limits

  • CUDA and library APIs are tested subsets, not drop-in replacements.
  • SASS execution is unsupported. The optional binary shim is disabled in Release builds unless explicitly enabled.
  • SIMD/warp width is fixed at 32. Multi-GPU, peer access, and graphics-API interop are unsupported.
  • FP64 uses emulation with mode-dependent precision; it is not native Metal FP64.
  • Cooperative grids, dynamic launch, graphs, and textures have bounded or incomplete support. See known gaps for exact limits.

Documentation

License

Apache 2.0 · Legal notice