mojo-gpu-fundamentals

Translate CUDA kernel definitions and launches into Mojo GPU programming constructs.

6|Updated Sep 26, 2024
One-click install
npx skills add https://github.com/better-mojo/uuid --skill mojo-gpu-fundamentals-better-mojo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mojo-gpu-fundamentals
Source: https://github.com/better-mojo/uuid/tree/main/.pi/skills/mojo-gpu-fundamentals
Command: npx skills add https://github.com/better-mojo/uuid --skill mojo-gpu-fundamentals-better-mojo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It prevents common, CUDA-based misconceptions when writing GPU-targeted Mojo programs by mapping CUDA concepts to Mojo’s actual GPU programming model.

Core Features & Use Cases

  • Not-CUDA concept mapping: replaces CUDA syntax and launch idioms with Mojo equivalents like ctx.enqueue_function[...], barrier(), and Atomic.fetch_add.
  • Correct kernel structure for GPUs: explains plain-function kernels, TensorLayout-parameterized TileTensor usage, and mandatory comptime assert input.flat_rank == N when subscripting TileTensor.
  • End-to-end GPU fundamentals: covers indexing (global_idx, thread_idx, block_idx), shared memory allocation (stack_allocation with AddressSpace.SHARED), warp primitives, memory management via DeviceContext/DeviceBuffer, and host vs target GPU checks (has_* vs is_*).

Quick Start

Use the mojo-gpu-fundamentals skill while writing your Mojo GPU kernels so you replace CUDA-style syntax with the Mojo ctx.enqueue_function launch pattern and std.gpu/layout primitives.

Frequently Asked Questions about mojo-gpu-fundamentals

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write GPU kernels in Mojo without using CUDA syntax?

To write GPU kernels in Mojo, define plain functions and launch them using `ctx.enqueue_function[...]` instead of CUDA syntax, leveraging `std.gpu` primitives for indexing and synchronization across NVIDIA, AMD, and Apple Silicon accelerators.

What is the correct way to allocate shared memory when programming GPUs in Mojo?

Shared memory allocation in Mojo GPU programming uses `stack_allocation` with `AddressSpace.SHARED`, replacing CUDA shared memory syntax while providing similar on-chip memory performance for thread block communication.

How do I launch a GPU kernel function in Mojo?

GPU kernel launches in Mojo use the `DeviceContext` method `ctx.enqueue_function[...]` to queue plain-function kernels for execution on the target accelerator, replacing CUDA's `<<<>>>` launch configuration syntax.

Why does my Mojo GPU code fail when subscripting TileTensor types?

Subscripting `TileTensor` types in Mojo requires mandatory `comptime assert input.flat_rank == N` to validate the `TensorLayout` parameters, preventing compilation failures from rank mismatches.

Does Mojo GPU programming support warp primitives and thread synchronization?

Mojo GPU programming supports warp primitives and thread synchronization through `barrier()` and `Atomic.fetch_add` operations within `std.gpu`, providing correct synchronization mechanisms across different accelerator architectures.

When should I use `has_*` versus `is_*` architecture checks in Mojo GPU code?

Use `has_*` checks to verify target GPU capabilities during host code execution and `is_*` checks within device kernels to confirm the active architecture, ensuring correct cross-platform compilation.