mojo-gpu-fundamentals
The basics of how to program GPUs using Mojo. Use this skill in addition to mojo-syntax when writing Mojo code that targets GPUs or other accelerators. Use targeting code to NVIDIA, AMD, Apple silicon GPUs, or others. Use this skill to overcome misconceptions about how Mojo GPU code is written.
Security Assessment
About mojo-gpu-fundamentals
This skill is a correction layer for GPU programming in Mojo, designed to override the CUDA-style assumptions a pretrained model would otherwise apply. Its central point is that Mojo GPU code has no CUDA syntax: there is no `__global__`, `__device__`, `__shared__`, or `<<<>>>` launch syntax, and the skill instructs the agent to follow it over pretrained knowledge. It solves the problem of models generating plausible-but-wrong Mojo GPU code by documenting only the things that differ from what a model would guess.
The core content is a concept-mapping table translating CUDA constructs to their Mojo equivalents (kernel definitions as plain functions, `ctx.enqueue_function` launches, buffer creation and copies via DeviceContext, `barrier()` for synchronization, `thread_idx`/`global_idx` for indexing, warp primitives, and Atomic operations), followed by the correct import paths. It then covers kernel definition rules (plain functions, no decorators, the mandatory `comptime assert tensor.flat_rank == N` before subscripting a TileTensor), and the TileTensor data abstraction including layout creation with `row_major`, constructing tensors from buffers, N-dimensional indexing, and tiling. The file is deliberately terse, using tables and WRONG/CORRECT pairs to keep context cost low.
It is aimed at developers writing Mojo code that targets NVIDIA, AMD, or Apple silicon GPUs and other accelerators, and is meant to be used alongside a companion mojo-syntax skill. It is a documentation-only reference with no scripts or side effects, useful for anyone porting GPU kernels to Mojo or learning the framework's idioms.
FAQ
Do I write CUDA-style kernels in Mojo?
No. The skill stresses that Mojo GPU programming has no CUDA syntax; kernels are plain functions with no decorators, and launches use ctx.enqueue_function instead of triple-angle-bracket syntax.
What GPUs does it target?
It is written for code targeting NVIDIA, AMD, Apple silicon GPUs, and other accelerators.
What is the flat_rank assert about?
A `comptime assert tensor.flat_rank == N` is mandatory in any function that subscripts a TileTensor; without it, indexing fails to compile. Derived tensors from tile/vectorize/distribute must be re-asserted before indexing.
Is it meant to be used alone?
It is intended to be used in addition to a mojo-syntax skill when writing Mojo GPU code, acting as a targeted correction layer rather than a full language tutorial.
Does the skill execute anything?
No. It is a terse documentation reference of tables and code examples with no scripts or runtime side effects.
Install mojo-gpu-fundamentals
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
modular/skills