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
-
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 cloneit on Bender. -
Edit
tilemm.pyand fill in theINSERT CODE HEREsections. 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 withct.load, multiply-accumulate them withct.mma), and thect.storeof the result.main.pyis provided; do not modify it.ct.loadandct.storeindex whole tiles, not elements: index(i, j)with shape(BLOCK_M, BLOCK_K)is the tile starting at rowi*BLOCK_M, columnj*BLOCK_K.- Use the block sizes passed to
tiled_matmul, not hard-coded numbers. - Your code must work for any matrix shape.
ct.storedrops the parts of a tile that hang over the edge of C, but forct.loadyou must ask for zero padding withpadding_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.pymay not use CuPy's matrix multiplication.
-
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 250The 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 undercompute-sanitizer:TILEMM_NO_GUARD=1 compute-sanitizer python main.py 33 17 65If
compute-sanitizerorcuobjdumpis not found, addexport PATH=/usr/local/cuda/bin:$PATHto~/.bashrc. To debug,ct.printfprints from inside a kernel. -
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 pushtilemm.py,REPORT.mdandplots/.
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.pyhas a@ct.kernelthat usesct.loadwith zero padding,ct.mmaandct.store, launched withct.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.pysurrounds the matrices with guard values, andcompute-sanitizerchecks a few sizes.
If a test fails, click on it: the summary explains the cause, and the log shows the full output.