Hi,
I’m learning Mojo using a MacBook pro with M1 and working my way through the examples. I’ve just started this one; Get started with GPU programming | Modular
(pretty basic I know!)
The first step works fine:
mojo vector_addition.mojo
Found GPU: Apple M1 Max
However, creating a kernel fails to compile. I’ve reduced the code to this:
from gpu.host import DeviceContext
from gpu.id import block_idx, thread_idx
from sys import has_accelerator
fn print_threads():
“”“Print thread IDs.”“”
print(“Block index: [”,
block_idx.x,
“]\tThread index: [”,
thread_idx.x,
“]”
)
def main():
ctx = DeviceContext()
ctx.enqueue_function[print_threads](grid_dim=2, block_dim=64)
adding the cix.enqueue_function call and compiling gives the following errors:
% mojo vector_addition.mojo
gpu-intro/vector_addition.mojo:1:1: error: failed to run the pass manager for offload functions
from gpu.host import DeviceContext
^
gpu-intro/vector_addition.mojo:8:10: error: call expansion failed
print(“Block index: [”,
^
open-source/max/mojo/stdlib/stdlib/io/io.mojo:366:4: note: function instantiation failed
open-source/max/mojo/stdlib/stdlib/io/io.mojo:432:18: note: call expansion failed
open-source/max/mojo/stdlib/stdlib/sys/info.mojo:78:14: note: call expansion failed
open-source/max/mojo/stdlib/stdlib/builtin/constrained.mojo:58:6: note: constraint failed: Current compilation target does not support operation: print. Note:
mojo: error: failed to run the pass manager
No idea where to start with this…
All help appreciated!
Thanks
Pip