Metal.jl
Metal.jl lets you program the GPU of an Apple silicon Mac from Julia, using GPU arrays or kernels written in Julia. It compiles Julia code to Apple's intermediate representation (AIR) and hands it to the GPU driver through the Metal framework, so you don't need Xcode or a Metal toolchain.
Requirements:
- a Mac with Apple silicon (M1 or newer);
- macOS 15 or newer;
- Julia 1.10 or newer, the native Apple silicon (
aarch64) build rather than the Intel one running under Rosetta.
Install the package and check that it finds your GPU:
using PkgPkg.add("Metal")using MetalMetal.versioninfo()Metal.versioninfo() reports your system, package versions and available GPUs. If it finds no devices, see Troubleshooting.
A first array operation:
julia> a = MtlArray(Float32[1, 2, 3]);julia> a .+ 1f03-element MtlVector{Float32, Metal.SharedStorage}: 2.0 3.0 4.0For direct access to Apple's frameworks, Metal.MTL and Metal.MPS wrap Metal and Metal Performance Shaders. They follow Apple's API closely; consult Apple's documentation for their concepts.
Where to go next
- Introduction: a tutorial from broadcasting to a parallel kernel.
- Arrays: constructing
MtlArrays, supported element types and array operations. - Memory and Tasks and synchronization: how GPU memory and asynchronous execution work, and when you need to wait for the GPU.
- Kernel programming: writing your own kernels with
@metal. - Profiling and Performance: measuring and improving performance.
- Troubleshooting: common error messages and what they mean.
Getting help and contributing
Ask questions in the GPU domain of the Julia Discourse or the #gpu channel of the Julia Slack. Report bugs and missing functionality on the issue tracker, including the output of Metal.versioninfo(). To work on Metal.jl itself, see Contributing.
If you use Metal.jl in research, please cite it using the CITATION.cff file in the repository. Metal.jl is maintained by Tim Besard (@maleadt) and Christian Guinard (@christiangnrd).