TensorTonic
Problems
Autotuned Matrix Multiplication in Triton
Linear AlgebraGPU Programming
Medium

Same operation as tiled matmul: given AAA of shape (M,K)(M, K)(M,K) and BBB of shape (K,N)(K, N)(K,N), compute C=A⋅BC = A \cdot BC=A⋅B.

C[i,j]=∑k=0K−1A[i,k]⋅B[k,j]C[i, j] = \sum_{k=0}^{K-1} A[i, k] \cdot B[k, j]C[i,j]=k=0∑K−1​A[i,k]⋅B[k,j]

The difference is that the kernel is decorated with @triton.autotune\texttt{@triton.autotune}@triton.autotune over a small space of configs, and Triton picks the fastest config per shape at runtime. Autotune compiles every config on the first call for a given key signature, benchmarks each one, caches the winner, and reuses it for matching subsequent calls. The search space must stay small to fit inside the harness subprocess timeout.

Loading visualization...

Examples

Input: A = [[1, 2], [3, 4]], B = [[5, 6], [7, 8]]

Output: [[19, 22], [43, 50]]

Input: A = [[2, 0], [0, 2]], B = [[1, 2], [3, 4]]

Output: [[2, 4], [6, 8]]

Hint 1

Build each config with triton.Config\texttt{triton.Config}triton.Config specifying the meta-parameter dictionary, num_stages\texttt{num\_stages}num_stages, and num_warps\texttt{num\_warps}num_warps. Keep the list short; first-call compile time scales with the size of the space.

Hint 2

The key\texttt{key}key argument names the runtime values that uniquely determine the best config. For matmul those are MMM, NNN, and KKK; the kernel must accept them as regular int arguments so autotune can hash them.

Hint 3

Inside the kernel body, the autotuner injects the winning config's block sizes via the constexpr meta-parameters. The body is identical to the non-autotuned matmul.

Requirements

  • Decorate the matmul kernel with @triton.autotune\texttt{@triton.autotune}@triton.autotune keyed on (M,N,K)(M, N, K)(M,N,K)
  • Pass a small set of configs (three to five) varying the block sizes and pipeline depth
  • Mask the loads and stores on the MMM, NNN, and KKK tails as in the plain tiled matmul
  • The solve\texttt{solve}solve signature must not change
  • use ieee precision for consistent float32 accuracy across gpus.

Constraints

  • 1≤M,N,K≤5121 \le M, N, K \le 5121≤M,N,K≤512.
  • All tensors are torch.float32 on cuda.
  • Tolerance: atol=1e-2 + rtol=1e-2 * abs(expected) for K≥128K \ge 128K≥128.
  • Keep the autotune space at most 4 configs to avoid compile-time timeouts.
Try Similar Problems
Tiled Transpose in TritonMediumGEMV: Matrix Vector Product in TritonMediumFused Matmul + Bias + ReLU in TritonMediumTiled Matrix Multiplication in TritonMediumScaled Dot-Product Attention in TritonMediumBlock-Pointer Matmul in TritonMediumSplit-K Matmul in TritonHardVector Addition in TritonEasyFused Multiply-Add in TritonEasyGrouped Program-ID Matmul in TritonHardL2 Vector Norm in TritonEasyRMS Normalization as a CUDA KernelMedium

Accepts: array

Accepts: array

You must run your code first.

Kernel performance

Submit a correct solution to see your kernel performance.

Autotuned Matrix Multiplication in Triton

Autotuned Matrix Multiplication in Triton

Linear AlgebraGPU Programming
Medium

Same operation as tiled matmul: given AAA of shape (M,K)(M, K)(M,K) and BBB of shape (K,N)(K, N)(K,N), compute C=A⋅BC = A \cdot BC=A⋅B.

C[i,j]=∑k=0K−1A[i,k]⋅B[k,j]C[i, j] = \sum_{k=0}^{K-1} A[i, k] \cdot B[k, j]C[i,j]=k=0∑K−1​A[i,k]⋅B[k,j]

The difference is that the kernel is decorated with @triton.autotune\texttt{@triton.autotune}@triton.autotune over a small space of configs, and Triton picks the fastest config per shape at runtime. Autotune compiles every config on the first call for a given key signature, benchmarks each one, caches the winner, and reuses it for matching subsequent calls. The search space must stay small to fit inside the harness subprocess timeout.

Loading visualization...

Examples

Input: A = [[1, 2], [3, 4]], B = [[5, 6], [7, 8]]

Output: [[19, 22], [43, 50]]

Input: A = [[2, 0], [0, 2]], B = [[1, 2], [3, 4]]

Output: [[2, 4], [6, 8]]

Hint 1

Build each config with triton.Config\texttt{triton.Config}triton.Config specifying the meta-parameter dictionary, num_stages\texttt{num\_stages}num_stages, and num_warps\texttt{num\_warps}num_warps. Keep the list short; first-call compile time scales with the size of the space.

Hint 2

The key\texttt{key}key argument names the runtime values that uniquely determine the best config. For matmul those are MMM, NNN, and KKK; the kernel must accept them as regular int arguments so autotune can hash them.

Hint 3

Inside the kernel body, the autotuner injects the winning config's block sizes via the constexpr meta-parameters. The body is identical to the non-autotuned matmul.

Requirements

  • Decorate the matmul kernel with @triton.autotune\texttt{@triton.autotune}@triton.autotune keyed on (M,N,K)(M, N, K)(M,N,K)
  • Pass a small set of configs (three to five) varying the block sizes and pipeline depth
  • Mask the loads and stores on the MMM, NNN, and KKK tails as in the plain tiled matmul
  • The solve\texttt{solve}solve signature must not change
  • use ieee precision for consistent float32 accuracy across gpus.

Constraints

  • 1≤M,N,K≤5121 \le M, N, K \le 5121≤M,N,K≤512.
  • All tensors are torch.float32 on cuda.
  • Tolerance: atol=1e-2 + rtol=1e-2 * abs(expected) for K≥128K \ge 128K≥128.
  • Keep the autotune space at most 4 configs to avoid compile-time timeouts.
Try Similar Problems
Tiled Transpose in TritonMediumGEMV: Matrix Vector Product in TritonMediumFused Matmul + Bias + ReLU in TritonMediumTiled Matrix Multiplication in TritonMediumScaled Dot-Product Attention in TritonMediumBlock-Pointer Matmul in TritonMediumSplit-K Matmul in TritonHardVector Addition in TritonEasyFused Multiply-Add in TritonEasyGrouped Program-ID Matmul in TritonHardL2 Vector Norm in TritonEasyRMS Normalization as a CUDA KernelMedium

Accepts: array

Accepts: array

You must run your code first.

Kernel performance

Submit a correct solution to see your kernel performance.

Problems
Loading...
1 / 1