How to Use This Book
Each puzzle follows a consistent format designed to progressively build your skills:
- Overview: Clear problem statement and key concepts introduced in each puzzle
- Configuration: Setup parameters and memory organization specific to each challenge
- Code to Complete: Skeleton code with specific sections for you to implement
- Tips: Optional hints if you get stuck, without giving away complete solutions
- Solution: Detailed explanations of the implementation, performance considerations, and underlying concepts
The puzzles gradually increase in complexity, introducing new concepts while reinforcing fundamentals. We recommend solving them in order, as later puzzles build on skills developed in earlier ones.
Running the code
All puzzles are designed to be run with the provided testing framework that verifies your implementation against expected results. Each puzzle includes instructions for running the code and validating your solution.
Prerequisites
Compatible GPU
You’ll need a compatible GPU to run the puzzles.
Setting up your environment
-
Clone the GitHub repository and navigate to the repository:
# Clone the repository git clone https://github.com/modular/mojo-gpu-puzzles cd mojo-gpu-puzzles
-
Install a package manager to run the Mojo🔥 programs:
Option 1:
uv
(recommended for users)Install:
curl -fsSL https://astral.sh/uv/install.sh | sh
Update:
uv self update
Create a virtual environment:
uv venv && source .venv/bin/activate
Option 2: pixi (recommended for contributors)
Install:
curl -fsSL https://pixi.sh/install.sh | sh
Update:
pixi self-update
-
Run the puzzles via
uv
orpixi
as follows:uv run poe pXX # Replace XX with the puzzle number
pixi run pXX # Replace XX with the puzzle number
For example, to run puzzle 01:
uv run poe p01
orpixi run p01
Knowledge prerequisites
Basic knowledge of:
- Programming fundamentals (variables, loops, conditionals, functions)
- Parallel computing concepts (threads, synchronization, race conditions)
- Basic familiarity with Mojo (language basics parts and intro to pointers section)
- A tour of GPU basics in Mojo is helpful
No prior GPU programming experience is necessary! We’ll build that knowledge through the puzzles.
Let’s begin our journey into the exciting world of GPU computing with Mojo 🔥!
Join the community
Join our vibrant community to discuss GPU programming, share solutions, and get help!