Triton Scaled Matmul
Problem Statement
Compute a scaled matmul C = alpha * (A @ B) with alpha a runtime scalar.
Background
Multiply the accumulator by alpha in the epilogue. This mirrors BLAS GEMM's alpha parameter.
Your Task
Implement scaled_matmul_kernel and run(M=128, N=128, K=128, alpha=0.5) comparing to alpha * (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, alpha = 0.5
True
- We start with the given input values: M = 128, N = 128, K = 128, and alpha = 0.5.
- The
scaled_matmul_kernelfunction computes the matrix product of A and B, resulting in a temporary matrix product . - The kernel then scales this temporary result by the given alpha value, , to produce the final output matrix C.
- The output of the
runfunction isTrueif the resulting matrix C is close to the reference solution computed byalpha * (A @ B), which is verified usingtorch.allclose.
Constraints
- Tiled matmul accumulator
- Epilogue: acc = acc * alpha
- alpha is a runtime scalar