I am an iOS developer looking to switch fields and interested in, but new to the GPU programming world, and only have access to an Apple silicon MacBook.
According to the system requirements for Macs at FAQ | Modular , an Apple silicon Mac is required, however its GPU is not supported and Apple silicon macs do not support eGPUs.
Is it possible to learn GPU programming with Mojo/Max on Macs?
If you’re willing to do the “hardmode” version, I believe that you should be able to run code on Apple Silicon Mac GPUs now, but that much of the standard library and MAX are missing support. Helping with bring-up there is going to be diving into the deep end, but you will learn a lot.
@owenhilyard Can you elaborate on what is already done, what needs doing and also give some pointers on how to get started?
Does Mojo already support the Mac GPU as a compilation target, so the “only” thing that needs adding is a way to manage the GPU (a new DeviceContext backend maybe?).
Let’s say I want to run the GPU puzzles, for starters. Currently, I get the following, which suggests that even the target is not supported but maybe that’s a just a symptom of something else.
(mojo-gpu-puzzles) chill@Mareks-Laptop mojo-gpu-puzzles % uv run poe p01
Poe => mojo problems/p01/p01.mojo
open-source/max/mojo/stdlib/stdlib/builtin/_startup.mojo:103:4: error: call expansion failed
open-source/max/mojo/stdlib/stdlib/builtin/_startup.mojo:72:4: note: function instantiation failed
/Users/chill/Documents/GitHub/mojo-gpu-puzzles/problems/p01/p01.mojo:23:5: note: call expansion failed
def main():
^
open-source/max/mojo/stdlib/stdlib/gpu/host/info.mojo:1691:8: note: function instantiation failed
open-source/max/mojo/stdlib/stdlib/gpu/host/info.mojo:1701:43: note: call expansion failed
open-source/max/mojo/stdlib/stdlib/gpu/host/info.mojo:2224:4: note: function instantiation failed
open-source/max/mojo/stdlib/stdlib/gpu/host/info.mojo:2280:6: note: call expansion failed
open-source/max/mojo/stdlib/stdlib/builtin/constrained.mojo:58:6: note: constraint failed: the target architecture '' is not valid
/Users/chill/Documents/GitHub/mojo-gpu-puzzles/.venv/bin/mojo: error: failed to run the pass manager
We’re in the early stages of landing the basic components for Apple Silicon GPU support in the nightlies, including a new backend for DeviceContext. You can’t actually do much with what has been integrated so far, which is why we’ve held off from posting about it. We’ll be sure to let people know when enough is functional that you can run our Mojo GPU function examples.
As Owen says, support will be pretty basic at first, with only minimal GPU functions working initially. When ready, we’ll post with details about how you can get started and specific areas that you can help with adding intrinsics, new kernel paths, etc. With the ready access to this hardware that many people have, we figure that some of this bringup can be parallelized.
We’ve previously done these posts about new functionality in the nightly builds here in the forum, and I’ll try to remember to follow up in this thread with a link when it’s up. I can’t promise any timelines, but we are actively working on this with the hope of at least minimal functionality landing sooner rather than later.
We announced this in tonight’s community livestream: tonight’s Mojo nightly has enough functionality to run a very basic Mojo GPU function on Apple Silicon GPUs. This is currently gated behind the environment flag MOJO_ENABLE_HAS_GPU_FOR_APPLE, but if you set that flag you’ll be able to build the example examples/mojo/gpu-functions/vector_addition_metal.mojo on your Apple Silicon GPU.
We have a bunch more functionality to land to enable the other Mojo GPU function examples on Apple Silicon GPUs. We’ll let you know as more of this becomes viable.
Are there any prerequisites for running the vector_addition_metal example besides using nightly build? When I tested the example I got a create Metal library error.
Make sure you’re on macOS 15 (Sequoia) or newer, and have Xcode installed. We’re currently generating bitcode for Metal Shading Language version 3.2, which is available in macOS 15+. Xcode is needed to compile the final .metallib before execution.
Will it work on M1 MacBook Air? I will appreciate if you could give more detail on how to set this flag. Will it be export MOJO_ENABLE_HAS_GPU_FOR_APPLE = “true”
I’ve posted an introduction to Apple Silicon GPU support in Mojo: Apple Silicon GPU support in Mojo . This is now enabled by default in the latest nightlies, so you no longer need an environment variable to be set. I’ve also described current limitations and what we plan to work on next as we add more support.