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

  1. 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
    
  2. Install a package manager to run the Mojo🔥 programs:

    Install:

    curl -fsSL https://astral.sh/uv/install.sh | sh
    

    Update:

    uv self update
    

    Create a virtual environment:

    uv venv && source .venv/bin/activate
    

    Install:

    curl -fsSL https://pixi.sh/install.sh | sh
    

    Update:

    pixi self-update
    
  3. Run the puzzles via uv or pixi 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 or
  • pixi 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

Subscribe for Updates Modular Forum Discord

Join our vibrant community to discuss GPU programming, share solutions, and get help!