Version: 1.1.0

GPU puzzles

GPU puzzles are graded kernels. You fill in a Mojo function, launch it, and check the result against a reference.

The pattern

1. Read the shape of the input tensors. 2. Compute the thread index. 3. Guard the index so extra threads do nothing. 4. Write one output element.

A first kernel

def vector_add(a: UnsafePointer[Float32], b: UnsafePointer[Float32], out: UnsafePointer[Float32], n: Int):
    var i = global_idx.x
    if i < n:
        out[i] = a[i] + b[i]

The same pattern scales to tiles, shared memory, and reductions. Read GPU programming for the surrounding model.