Skip to content

About

CUDA compiler and runtime for Apple Silicon

Topics

Resources

Contributing

Security policy

Stars

221 stars

Watchers

2 watching

Forks

Repository files navigation

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.

The LAMMPS/Kokkos GPU demo compiles unmodified LAMMPS and passes the stock 32,000-atom, 100-step full/half-neighbour numerical gate. See demos for more workloads.

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

If cumetal doctor reports a missing or placeholder Metal toolchain, see checking the toolchain.

Compile and run your CUDA source:

cumetalc kernel.cu -o kernel
./kernel

Build from source

FP64 arithmetic comes from the third_party/VF64-metal submodule; initialize it with git submodule update --init --recursive.

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 testing for validation commands.

How it works

CUDA C++ / PTX → CuMetal compiler → Metal Shading Language → Apple tools → metallib
  • Direct CUDA C++, compiled ahead of time. cumetalc compiles CUDA C++ through typed CuMetal IR and embeds the Metal library in the executable, so there is no first-launch PTX JIT. CuMetal uses no private Apple APIs.
  • PTX import with SSA and pointer-provenance recovery. PTX registers become typed SSA values, and addresses stay real pointers in their Metal address space. Bounded proofs recover pointer arithmetic; a Metal pointer is never turned into an integer, and what cannot be proved is rejected, not guessed.
  • FP64 emulation with VF64-metal. Apple GPUs have no native FP64. double runs in a selectable emulation mode: fast48 by default, ieee64 for correctly rounded results (FP64 policy).
  • 64-bit atomics and scoped memory (Metal 3.2+). Typed lock-backed 64-bit atomics use device-coherent payload pointers and device fences, covering binary64 atomicAdd and cross-block scan descriptors.

The proof rules behind the PTX path are in the "PTX memory proof rules" section of compiler architecture; known gaps lists memory-provenance and legacy-backend limits.

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.
  • Device pointers the host writes directly into managed or mapped memory, or passes as plain integers, need CUMETAL_USE_METAL_DEVICE_ADDRESSES=1, which serializes work across streams. Pointers stored by kernels or copied in with cudaMemcpy* need nothing (details).

Documentation

License

Apache 2.0 · Legal notice

About

CUDA compiler and runtime for Apple Silicon

Topics

Resources

Contributing

Security policy

Stars

221 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages