Vector add and fused softmax with bandwidth measurement
Colab T4 · freenotebook150 minrequiredGoal · Write two Triton kernels from scratch, verify them against PyTorch, and report achieved GB/s versus the T4's peak of about 320 GB/s.
- 1Open a Colab notebook with a T4 runtime; pip install triton if the preinstalled torch does not ship it.
- 2Write add_kernel with program_id, tl.arange, masks and tl.load/tl.store; verify with torch.allclose on a non-multiple-of-BLOCK size.
- 3Write softmax_kernel with one program per row and the whole row in registers; handle rows longer than BLOCK with masking.
- 4Verify against torch.softmax for shapes (1823, 781) and (4096, 4096) in fp16 and fp32.
- 5Benchmark both kernels with triton.testing.do_bench for sizes from 2^12 to 2^26 elements; compute GB/s as bytes moved divided by time.
- 6Plot GB/s versus size for your kernel and torch; annotate the peak bandwidth line.
- 7Run the add kernel once with TRITON_INTERPRET=1 on a CPU runtime to see the interpreter path work.
- Deliverable
- A notebook with both kernels, correctness asserts and the bandwidth plot.
- Check
- Softmax reaches at least 60 percent of T4 peak bandwidth for 4096x4096 fp16 and matches torch within atol 1e-2 for fp16.
- Fallback
- Use a Kaggle T4 notebook, or run with TRITON_INTERPRET=1 on CPU for correctness only and skip the bandwidth numbers.