An open API service indexing awesome lists of open source software.

https://github.com/modular/mojo-gpu-puzzles

Learn GPU Programming in Mojo🔥 by Solving Puzzles
https://github.com/modular/mojo-gpu-puzzles

gpu learn-by-doing mojo programming

Last synced: 6 months ago
JSON representation

Learn GPU Programming in Mojo🔥 by Solving Puzzles

Awesome Lists containing this project

README

          


Mojo GPU Puzzles Logo


Mojo🔥 GPU Puzzles


Learn GPU Programming in Mojo🔥 Through Interactive Puzzles🧩


Overview
Why Mojo
Getting Started
Development
Community



CI


Powered by Mojo


Subscribe for Updates


Modular Forum


Discord

## Overview

> _"For the things we have to learn before we can do them, we learn by doing them."_
> — Aristotle, (Nicomachean Ethics)

Welcome to **Mojo🔥 GPU Puzzles** — an interactive approach to learning GPU programming through hands-on puzzle solving. Instead of traditional textbook learning, you'll immediately dive into writing real GPU code and seeing the results.

Start Learning Now 👉 [https://builds.modular.com/puzzles](https://builds.modular.com/puzzles)

> 📬 [Subscribe to updates](https://www.modular.com/company/talk-to-us) to get notified when new puzzles are released!

## Why Mojo🔥

[Mojo](https://docs.modular.com/mojo/manual/) represents a revolutionary approach to GPU programming, making massive parallelism accessible while maintaining systems-level performance:

- 🐍 **Python-like Syntax** with systems programming capabilities
- ⚡ **Zero-cost Abstractions** that compile to efficient machine code
- 🛡️ **Strong Type System** catching errors at compile time
- 📊 **Built-in Tensor Support** with hardware-aware optimizations
- 🔧 **Direct Hardware Access** to CPU and GPU intrinsics
- 🔄 **Cross-Hardware Portability** for CPUs and GPUs
- 🎯 **Ergonomic Improvements** over traditional C/C++

## Getting Started

### Prerequisits

You'll need a [compatible GPU](https://docs.modular.com/max/faq#gpu-requirements) to run the examples.

1. Visit [https://builds.modular.com/puzzles](https://builds.modular.com/puzzles)
2. Clone this repository
```bash
git clone https://github.com/modular/mojo-gpu-puzzles
cd mojo-gpu-puzzles
```
3. Install a package manager to run the Mojo🔥 programs:

### Option 1: [`uv`](https://docs.astral.sh/uv/getting-started/installation/) (recommended for users)

**Install:**
```bash
curl -fsSL https://astral.sh/uv/install.sh | sh
```

**Update:**
```bash
uv self update
```

**Create a virtual environment:**
```bash
uv venv && source .venv/bin/activate
```

### Option 2: [pixi](https://pixi.sh/latest/#installation) (recommended for contributors)

**Install:**
```bash
curl -fsSL https://pixi.sh/install.sh | sh
```

**Update:**
```bash
pixi self-update
```

4. Start solving puzzles!

## Development

We use `pixi` for development as it includes `uv` and also supports conda packages (like `mdbook` from the `conda-forge` channel) needed for development workflows.

```bash
# Build and serve the book
pixi run book

# Test solutions on GPU
pixi run tests
# Or a specific puzzle
pixi run tests pXX
# Or manually
pixi run mojo/python solutions/pXX/pXX.{mojo,py}

# Run GPU sanitizers for debugging on NVIDIA GPUs using `compute-sanitizer`
pixi run memcheck # Detect memory errors
pixi run racecheck # Detect race conditions
pixi run synccheck # Detect synchronization errors
pixi run initcheck # Detect uninitialized memory access
# Or manually
# Note: ignore the mojo runtime error collision with the sanitizer. Look for `Error SUMMARY`
pixi run compute-sanitizer --tool {memcheck,racecheck,synccheck,initcheck} mojo solutions/pXX/pXX.mojo

# Format code
pixi run format
```

## Contributing

We welcome contributions! Whether it's:
- 📝 Improving explanations
- 🐛 Fixing bugs ([report bug](https://github.com/modular/mojo-gpu-puzzles/issues/new?template=bug_report.yml))
- 💡 Suggesting improvements ([request feature](https://github.com/modular/mojo-gpu-puzzles/issues/new?template=feature_request.yml))

Please feel free to:
1. Fork the repository
2. Create your feature branch
3. Submit a pull request

## Community



Subscribe for Updates


Modular Forum


Discord

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

## Acknowledgments

- Thanks to all our [contributors](https://github.com/modular/mojo-gpu-puzzles/graphs/contributors)
- Initial puzzles are heavily inspired by [GPU Puzzles](https://github.com/srush/GPU-Puzzles)
- Built with [mdBook](https://rust-lang.github.io/mdBook/)

## License

This project is licensed under the LLVM License - see the [LICENSE](LICENSE) file for details.


Built with ❤️ by the Modular team