Assignment - Tile-Based Matrix Multiplication with cuTile

DUE Monday, November 30 @ 11:59:59PM Pacific Time

Overview

In the Matrix Multiply assignment you wrote a tiled kernel in CUDA, thread by thread: you computed indices from threadIdx and blockIdx, staged tiles in shared memory, placed __syncthreads() barriers and zero-padded partial tiles. In this assignment you will write the same computation in cuTile, NVIDIA's tile-based Python language. A cuTile kernel describes what one block does to whole tiles (blocks of a matrix), and the compiler handles threads, shared memory and synchronization. You will then compare your cuTile kernel against your CUDA kernel.

Useful reading: the cuTile Python documentation, in particular ct.kernel, ct.launch, ct.bid, ct.load, ct.store, ct.mma, ct.num_tiles, ct.cdiv and ct.astype.

Setting up Python on Bender

cuTile needs Python 3.11 or newer; use Bender's Python 3.12. Create a virtual environment once (about 300 MB):

python3.12 -m venv ~/cutile-venv
~/cutile-venv/bin/pip install --no-cache-dir -r requirements.txt

Then activate it in every new terminal before working on the assignment:

source ~/cutile-venv/bin/activate

cuTile and CuPy save compiled kernels under your home directory (~/.cache/cutile-python and ~/.cupy). If your home directory is full, compiling fails with Disk quota exceeded; free some space.

Tiled Matrix Multiplication in cuTile

  1. Accept the assignment: https://classroom50.org/UCR-CSEE217/cs-ee217-fall-2026/assignments/cutile-matrix-multiply/accept. A private GitHub repository is created with the starter code; git clone it on Bender.

  2. Edit tilemm.py and fill in the INSERT CODE HERE sections. The code that is the same in every tiled kernel is already there: the block indices, the accumulator tile, the loop over the tiles along K, and the kernel launch; a table at the top of the file maps CUDA concepts to cuTile. You write the launch grid, the body of the K loop (load a tile of A and a tile of B with ct.load, multiply-accumulate them with ct.mma), and the ct.store of the result. main.py is provided; do not modify it.

    • ct.load and ct.store index whole tiles, not elements: index (i, j) with shape (BLOCK_M, BLOCK_K) is the tile starting at row i*BLOCK_M, column j*BLOCK_K.
    • Use the block sizes passed to tiled_matmul, not hard-coded numbers.
    • Your code must work for any matrix shape. ct.store drops the parts of a tile that hang over the edge of C, but for ct.load you must ask for zero padding with padding_mode=ct.PaddingMode.ZERO: this is the zero padding you wrote by hand in CUDA. Without it, the padding is undefined, even if it happens to work on Bender.
    • Compute C with your kernel: tilemm.py may not use CuPy's matrix multiplication.
  3. Run on Bender:

    python main.py                  # 1000 x 1000 matrices
    python main.py 128              # 128 x 128
    python main.py 120 201 250      # A: 120 x 201, B: 201 x 250

    The program checks every element against a double-precision result and prints TEST PASSED, or lists the first wrong elements with a hint. Then it prints the kernel time and throughput. The first call compiles your kernel, so it takes a few seconds. To check for invalid memory accesses, run under compute-sanitizer:

    TILEMM_NO_GUARD=1 compute-sanitizer python main.py 33 17 65

    If compute-sanitizer or cuobjdump is not found, add export PATH=/usr/local/cuda/bin:$PATH to ~/.bashrc. To debug, ct.printf prints from inside a kernel.

  4. Answer the questions in REPORT.md. Some compare your cuTile kernel with your CUDA kernel from the Matrix Multiply assignment: time that one in your Matrix Multiply repository. Commit and push tilemm.py, REPORT.md and plots/.

Options of main.py

Command Effect
python main.py 512 512 x 512 matrices
python main.py 2048 --block-m 128 --block-n 64 --block-k 32 other block sizes (powers of 2, at least 16; default 64 x 64 x 32)

Automated tests

Every time you push to main, GitHub runs a series of tests on a GPU; open the Actions tab to see them. The tests cover:

  • A source check that tilemm.py has a @ct.kernel that uses ct.load with zero padding, ct.mma and ct.store, launched with ct.launch, and no matrix multiplication outside the kernel.
  • Many matrix sizes: tiny and single-row or single-column matrices, sizes just below, at and above the block size, odd rectangular shapes, and larger matrices.
  • Other block sizes, square and non-square, so do not hard-code 64.
  • Invalid memory accesses: main.py surrounds the matrices with guard values, and compute-sanitizer checks a few sizes.

If a test fails, click on it: the summary explains the cause, and the log shows the full output.