Triton Matmul with ReLU Epilogue
Problem Statement
Fuse a ReLU into the matmul epilogue: C = relu(A @ B).
Background
Apply tl.maximum(acc, 0.0) to the accumulator before storing. Fusing the activation avoids a second kernel reading and writing all of C.
Your Task
Implement matmul_relu_kernel and run(M=128, N=128, K=128) comparing to torch.relu(A @ B).
How it is tested
Your solution must define a top-level function run(...) that allocates inputs on the GPU, launches your Triton kernel, and returns a boolean from torch.allclose(triton_out, torch_reference, ...). The grader prints run(...); the expected output is True.
Example
M = 128, N = 128, K = 128
True
- The
runfunction allocates two input matricesAandBof size and respectively on the GPU, where , , and . - It then launches the
matmul_relu_kernelfunction, which performs the matrix multiplicationA @ Band applies the ReLU activation function to the result, effectively computing . - The result from the
matmul_relu_kernelfunction is stored intriton_outand compared to the result fromtorch.relu(A @ B)usingtorch.allclose. - The comparison returns
Trueif the two results are close within a certain tolerance, indicating that the custom implementation matches the PyTorch reference implementation.
Constraints
- Tiled matmul accumulator
- Epilogue: acc = tl.maximum(acc, 0.0) before store