Felt a little left out playing with GPUs due to me going the cheap route with Intel Arc but finally got Level Zero working from Mojo (no C wrapper nor SYCL dependency). Took a couple weekends but my B580 finally runs Mojo code.
It’s now available on the modular-community channel and on GitHub at andomeder/mojo-intel-gpu.
You can install it with: pixi add mojo-intel-gpu
It requires libze_loader.so (intel-compute-runtime + level-zero-loader on Arch, level-zero + level-zero-dev on Debian/Ubuntu) to run it and what you get is a DeviceContext-style API: IntelGPUContext, DeviceBuffer[T], HostBuffer[T], Kernel, plus IntelGPUDetector for auto-discovery.
Kernels compile from OpenCL C to SPIR-V with clang -target spirv64, loaded at runtime through zeModuleCreate.
It does have a lot missing and some rough spots like async pipeline work is synchronous through immediate command lists, subgroup and SLM intrinsics have low-level L0 bindings but no high-level wrapper, zeInitDrivers iterates all drivers and devices & the API takes the first GPU it finds so currently, you only have single device selection.
Empty kernel launch lands at 2.03 µs on my hardware. clpeak reports 1.39 µs for raw Level Zero, so I’m about 1.5x slower through the Mojo FFI + set_args overhead. H2D memcpy at 1 MB hits 12.78 GB/s, Intel’s published number is 14.5 GB/s. Sustained matches published; the first transfer is slower because of command list setup overhead. Memory fill clocks 172 GB/s.
I don’t have a clpeak FP32 number yet. Working on it.
I’ll keep working on it to add more support(a native backend) once the Mojo compiler is open-sourced so you can be able to write def kernel and have it target Intel directly but as for now, I’m just happy to play with it instead of having it be a paperweight when I want to use Mojo.
Trying it:
pixi add mojo-intel-gpu
git clone https://github.com/andomeder/mojo-intel-gpu
cd mojo-intel-gpu
./tools/compile_kernels.sh
mojo run -I . examples/vector_add.mojo
Repo: GitHub - andomeder/mojo-intel-gpu: Mojo GPU compute on Intel GPUs via Level Zero FFI · GitHub