submission 779904
D. Guo · python · License unknown
Use it
Vendorable · source mirrored · license unknownView source →
No package. Vendor the mirrored source: 122 lines, June 9 Researcher Reciprocity License v1.0.
tritonb200submission.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-matmul-v2-779904?include=source"interfacepython
Compatibility
measured onNVIDIA B200
declared hardwareNVIDIA B200
architecturessm_100
dtypesfp16
Benchmark evidence
1 measurement across 1 GPU, fastest first.
Operation / workload
Hardware
Latency
Rank
Observed
Reported · How evidence levels are derived →
Source and license
sourceavailable
revision digestsha256:66379aa94aacafa043242d8fe779fb2fd02de717e83897fe38d2c1c853a952f5
license declaredunknown
license concludedunknown
authorsD. Guo
imported2026-08-15
Techniques
Extracted from the mirrored source by pattern, never inferred. Each row cites its line.
autotune
@triton.autotune(mma
accumulator = tl.dot(a, b, accumulator, allow_tf32=False)num-warps = 4
triton.Config({'BLOCK_M': 64, 'BLOCK_N': 64, 'BLOCK_K': 64, 'GROUP_SIZE_M': 8}, num_stages=3, num_warps=4),stages = 3
triton.Config({'BLOCK_M': 64, 'BLOCK_N': 64, 'BLOCK_K': 64, 'GROUP_SIZE_M': 8}, num_stages=3, num_warps=4),Kernel source
tritonb200submission.py122 lines
import torch
import triton
import triton.language as tl
from task import input_t, output_t
from utils import make_match_reference, DeterministicContext
def generate_input(m: int, n: int, k: int, seed: int) -> input_t:
gen = torch.Generator(device='cuda')
gen.manual_seed(seed)
a = torch.empty(m, k, device='cuda', dtype=torch.float16)
a.uniform_(0, 1, generator=gen)
b = torch.empty(k, n, device='cuda', dtype=torch.float16)
b.uniform_(0, 1, generator=gen)
c = torch.empty(m, n, device='cuda', dtype=torch.float16)
return a, b, c
@triton.autotune(
configs=[
# Small problem sizes: finer tile granularity for better SM occupancy
triton.Config({'BLOCK_M': 64, 'BLOCK_N': 64, 'BLOCK_K': 64, 'GROUP_SIZE_M': 8}, num_stages=3, num_warps=4),
triton.Config({'BLOCK_M': 64, 'BLOCK_N': 128, 'BLOCK_K': 64, 'GROUP_SIZE_M': 8}, num_stages=3, num_warps=4),
triton.Config({'BLOCK_M': 128, 'BLOCK_N': 64, 'BLOCK_K': 64, 'GROUP_SIZE_M': 8}, num_stages=3, num_warps=4),
# Medium problem sizes: balanced tiles with moderate K
triton.Config({'BLOCK_M': 128, 'BLOCK_N': 128, 'BLOCK_K': 64, 'GROUP_SIZE_M': 8}, num_stages=3, num_warps=8),
triton.Config({'BLOCK_M': 128, 'BLOCK_N': 128, 'BLOCK_K': 128, 'GROUP_SIZE_M': 8}, num_stages=2, num_warps=8),
triton.Config({'BLOCK_M': 256, 'BLOCK_N': 128, 'BLOCK_K': 64, 'GROUP_SIZE_M': 8}, num_stages=3, num_warps=8),
triton.Config({'BLOCK_M': 128, 'BLOCK_N': 256, 'BLOCK_K': 64, 'GROUP_SIZE_M': 8}, num_stages=3, num_warps=8),
# Large problem sizes: wide tiles to maximize compute per block
triton.Config({'BLOCK_M': 256, 'BLOCK_N': 256, 'BLOCK_K': 64, 'GROUP_SIZE_M': 8}, num_stages=3, num_warps=8),
triton.Config({'BLOCK_M': 128, 'BLOCK_N': 256, 'BLOCK_K': 128, 'GROUP_SIZE_M': 8}, num_stages=2, num_warps=8),
# Deep K dimension: large K blocks to reduce loop iterations
triton.Config({'BLOCK_M': 128, 'BLOCK_N': 128, 'BLOCK_K': 256, 'GROUP_SIZE_M': 8}, num_stages=1, num_warps=8),
triton.Config({'BLOCK_M': 256, 'BLOCK_N': 128, 'BLOCK_K': 128, 'GROUP_SIZE_M': 8}, num_stages=2, num_warps=8),
],
key=['M', 'N', 'K'],
)
@triton.jit
def b200_matmul_kernel(
a_ptr, b_ptr, out_ptr,
M, N, K,
stride_am, stride_ak,
stride_bk, stride_bn,
stride_om, stride_on,
BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, BLOCK_K: tl.constexpr,
GROUP_SIZE_M: tl.constexpr,
):
"""
High-performance FP16 matmul kernel tuned for NVIDIA B200 (Blackwell).
Uses group-ordered launch for L2 cache optimization, tensor-core-backed
tl.dot with FP32 accumulation, and configurable tile sizes selected via
autotuning across the benchmark shape spectrum.
"""
pid = tl.program_id(0)
# --- Grouped launch ordering ---
# Programs that share A-tile rows are grouped together to improve L2 hit rate.
num_pid_m = tl.cdiv(M, BLOCK_M)
num_pid_n = tl.cdiv(N, BLOCK_N)
num_pid_in_group = GROUP_SIZE_M * num_pid_n
group_id = pid // num_pid_in_group
first_pid_m = group_id * GROUP_SIZE_M
group_size_m = tl.minimum(num_pid_m - first_pid_m, GROUP_SIZE_M)
pid_m = first_pid_m + ((pid % num_pid_in_group) % group_size_m)
pid_n = (pid % num_pid_in_group) // group_size_m
# --- Tile coordinate ranges ---
offs_am = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)
offs_bn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)
offs_k = tl.arange(0, BLOCK_K)
# --- Pointer base addresses ---
a_ptrs = a_ptr + offs_am[:, None] * stride_am + offs_k[None, :] * stride_ak
b_ptrs = b_ptr + offs_k[:, None] * stride_bk + offs_bn[None, :] * stride_bn
accumulator = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)
# --- Main K-loop ---
num_k_blocks = tl.cdiv(K, BLOCK_K)
for k in range(0, num_k_blocks):
k_rem = K - k * BLOCK_K
a = tl.load(a_ptrs, mask=offs_k[None, :] < k_rem, other=0.0)
b = tl.load(b_ptrs, mask=offs_k[:, None] < k_rem, other=0.0)
accumulator = tl.dot(a, b, accumulator, allow_tf32=False)
a_ptrs += BLOCK_K * stride_ak
b_ptrs += BLOCK_K * stride_bk
# --- Store result ---
out = accumulator.to(tl.float16)
offs_om = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)
offs_on = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)
out_ptrs = out_ptr + offs_om[:, None] * stride_om + offs_on[None, :] * stride_on
out_mask = (offs_om[:, None] < M) & (offs_on[None, :] < N)
tl.store(out_ptrs, out, mask=out_mask)
def custom_kernel(data: input_t) -> output_t:
a, b, _c = data
M, K = a.shape
K2, N = b.shape
assert K == K2, f"Inner dimension mismatch: {K} != {K2}"
output = torch.empty(M, N, device='cuda', dtype=torch.float16)
grid = lambda meta: (
triton.cdiv(M, meta['BLOCK_M']) * triton.cdiv(N, meta['BLOCK_N']),
)
b200_matmul_kernel[grid](
a, b, output,
M, N, K,
a.stride(0), a.stride(1),
b.stride(0), b.stride(1),
output.stride(0), output.stride(1),
)
return output
check_implementation = make_match_reference(custom_kernel)
scrolls · 122 lines total
Source code from GPU Mode and the KernelBot dataset · June 9 Researcher Reciprocity License v1.0
Changes from previous submission
Against this author's previous submission submission 779733.
- import torch- import triton- import triton.language as tl- from task import input_t, output_t-- # ---------------------------------------------------------------------------- # Triton Matmul Kernel with Autotuning for NVIDIA A100- # ---------------------------------------------------------------------------- def get_autotune_configs():- """- Provide various block size, warp, and pipeline stage configurations.- Triton will benchmark these and cache the best configuration for a given (M, N, K).- """- return [- triton.Config({'BLOCK_SIZE_M': 128, 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 64, 'GROUP_SIZE_M': 8}, num_stages=3, num_warps=8),- triton.Config({'BLOCK_SIZE_M': 256, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 64, 'GROUP_SIZE_M': 8}, num_stages=3, num_warps=8),- triton.Config({'BLOCK_SIZE_M': 256, 'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 8}, num_stages=4, num_warps=4),- triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 8}, num_stages=4, num_warps=4),- triton.Config({'BLOCK_SIZE_M': 128, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 8}, num_stages=4, num_warps=4),- triton.Config({'BLOCK_SIZE_M': 128, 'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 8}, num_stages=4, num_warps=4),- triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 8}, num_stages=4, num_warps=4),- triton.Config({'BLOCK_SIZE_M': 128, 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 8}, num_stages=4, num_warps=4),- triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 8}, num_stages=5, num_warps=2),- triton.Config({'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 8}, num_stages=5, num_warps=2),- ]-- @triton.autotune(- configs=get_autotune_configs(),- key=['M', 'N', 'K'],- )- @triton.jit- def _matmul_kernel(- # Pointers to matrices- a_ptr, b_ptr, c_ptr,- # Matrix dimensions- M, N, K,- # Stride variables (how much memory to jump to reach the next row/column)- stride_am, stride_ak,- stride_bk, stride_bn,- stride_cm, stride_cn,- # Meta-parameters (provided by autotuner)- BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr,- GROUP_SIZE_M: tl.constexpr,- ):- # Map program ID to block of C matrix.- # We group by M to increase L2 data reuse.- pid = tl.program_id(axis=0)- num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)- num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)- num_pid_in_group = GROUP_SIZE_M * num_pid_n- group_id = pid // num_pid_in_group- first_pid_m = group_id * GROUP_SIZE_M- group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)-- pid_m = first_pid_m + ((pid % num_pid_in_group) % group_size_m)- pid_n = (pid % num_pid_in_group) // group_size_m-- # Create pointer offsets for A and B.- offs_am = (pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)) % M- offs_bn = (pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)) % N- offs_k = tl.arange(0, BLOCK_SIZE_K)-- # 2D memory layouts- a_ptrs = a_ptr + (offs_am[:, None] * stride_am + offs_k[None, :] * stride_ak)- b_ptrs = b_ptr + (offs_k[:, None] * stride_bk + offs_bn[None, :] * stride_bn)-- # Accumulator initialized to FP32 for precision upcasting inside the loop- accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)-- for k in range(0, tl.cdiv(K, BLOCK_SIZE_K)):- # Load blocks of A and B matrices with boundary masking along the K dimension- a = tl.load(a_ptrs, mask=offs_k[None, :] < K - k * BLOCK_SIZE_K, other=0.0)- b = tl.load(b_ptrs, mask=offs_k[:, None] < K - k * BLOCK_SIZE_K, other=0.0)-- # Accumulate the block matrix multiplication utilizing Tensor Cores- accumulator = tl.dot(a, b, accumulator)-- # Advance pointers- a_ptrs += BLOCK_SIZE_K * stride_ak- b_ptrs += BLOCK_SIZE_K * stride_bk-- # Cast accumulator to FP16 output- c = accumulator.to(tl.float16)-- # Write output to the C matrix, safely masked- offs_cm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)- offs_cn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)- c_ptrs = c_ptr + stride_cm * offs_cm[:, None] + stride_cn * offs_cn[None, :]- c_mask = (offs_cm[:, None] < M) & (offs_cn[None, :] < N)- tl.store(c_ptrs, c, mask=c_mask)--- # ---------------------------------------------------------------------------- # Main Wrapper Implementation- # ---------------------------------------------------------------------------- def custom_kernel(data: input_t) -> output_t:- """- Custom kernel entrypoint that maps exactly to the leaderboard format.- Unpacks `a, b, c` and leverages `c` as the pre-allocated contiguous buffer.- """- a, b, c = data-- M, K = a.shape- _, N = b.shape-- # 1D grid launch calculated dynamically over M and N dimensions- grid = lambda META: (triton.cdiv(M, META['BLOCK_SIZE_M']) * triton.cdiv(N, META['BLOCK_SIZE_N']), )-- _matmul_kernel[grid](- a, b, c,- M, N, K,- a.stride(0), a.stride(1),- b.stride(0), b.stride(1),- c.stride(0), c.stride(1)- )-- return cNo newline at end of file+ import torch+ import triton+ import triton.language as tl+ from task import input_t, output_t+ from utils import make_match_reference, DeterministicContext+++ def generate_input(m: int, n: int, k: int, seed: int) -> input_t:+ gen = torch.Generator(device='cuda')+ gen.manual_seed(seed)+ a = torch.empty(m, k, device='cuda', dtype=torch.float16)+ a.uniform_(0, 1, generator=gen)+ b = torch.empty(k, n, device='cuda', dtype=torch.float16)+ b.uniform_(0, 1, generator=gen)+ c = torch.empty(m, n, device='cuda', dtype=torch.float16)+ return a, b, c+++ @triton.autotune(+ configs=[+ # Small problem sizes: finer tile granularity for better SM occupancy+ triton.Config({'BLOCK_M': 64, 'BLOCK_N': 64, 'BLOCK_K': 64, 'GROUP_SIZE_M': 8}, num_stages=3, num_warps=4),+ triton.Config({'BLOCK_M': 64, 'BLOCK_N': 128, 'BLOCK_K': 64, 'GROUP_SIZE_M': 8}, num_stages=3, num_warps=4),+ triton.Config({'BLOCK_M': 128, 'BLOCK_N': 64, 'BLOCK_K': 64, 'GROUP_SIZE_M': 8}, num_stages=3, num_warps=4),+ # Medium problem sizes: balanced tiles with moderate K+ triton.Config({'BLOCK_M': 128, 'BLOCK_N': 128, 'BLOCK_K': 64, 'GROUP_SIZE_M': 8}, num_stages=3, num_warps=8),+ triton.Config({'BLOCK_M': 128, 'BLOCK_N': 128, 'BLOCK_K': 128, 'GROUP_SIZE_M': 8}, num_stages=2, num_warps=8),+ triton.Config({'BLOCK_M': 256, 'BLOCK_N': 128, 'BLOCK_K': 64, 'GROUP_SIZE_M': 8}, num_stages=3, num_warps=8),+ triton.Config({'BLOCK_M': 128, 'BLOCK_N': 256, 'BLOCK_K': 64, 'GROUP_SIZE_M': 8}, num_stages=3, num_warps=8),+ # Large problem sizes: wide tiles to maximize compute per block+ triton.Config({'BLOCK_M': 256, 'BLOCK_N': 256, 'BLOCK_K': 64, 'GROUP_SIZE_M': 8}, num_stages=3, num_warps=8),+ triton.Config({'BLOCK_M': 128, 'BLOCK_N': 256, 'BLOCK_K': 128, 'GROUP_SIZE_M': 8}, num_stages=2, num_warps=8),+ # Deep K dimension: large K blocks to reduce loop iterations+ triton.Config({'BLOCK_M': 128, 'BLOCK_N': 128, 'BLOCK_K': 256, 'GROUP_SIZE_M': 8}, num_stages=1, num_warps=8),+ triton.Config({'BLOCK_M': 256, 'BLOCK_N': 128, 'BLOCK_K': 128, 'GROUP_SIZE_M': 8}, num_stages=2, num_warps=8),+ ],+ key=['M', 'N', 'K'],+ )+ @triton.jit+ def b200_matmul_kernel(+ a_ptr, b_ptr, out_ptr,+ M, N, K,+ stride_am, stride_ak,+ stride_bk, stride_bn,+ stride_om, stride_on,+ BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, BLOCK_K: tl.constexpr,+ GROUP_SIZE_M: tl.constexpr,+ ):+ """+ High-performance FP16 matmul kernel tuned for NVIDIA B200 (Blackwell).++ Uses group-ordered launch for L2 cache optimization, tensor-core-backed+ tl.dot with FP32 accumulation, and configurable tile sizes selected via+ autotuning across the benchmark shape spectrum.+ """+ pid = tl.program_id(0)++ # --- Grouped launch ordering ---+ # Programs that share A-tile rows are grouped together to improve L2 hit rate.+ num_pid_m = tl.cdiv(M, BLOCK_M)+ num_pid_n = tl.cdiv(N, BLOCK_N)+ num_pid_in_group = GROUP_SIZE_M * num_pid_n+ group_id = pid // num_pid_in_group+ first_pid_m = group_id * GROUP_SIZE_M+ group_size_m = tl.minimum(num_pid_m - first_pid_m, GROUP_SIZE_M)+ pid_m = first_pid_m + ((pid % num_pid_in_group) % group_size_m)+ pid_n = (pid % num_pid_in_group) // group_size_m++ # --- Tile coordinate ranges ---+ offs_am = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)+ offs_bn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)+ offs_k = tl.arange(0, BLOCK_K)++ # --- Pointer base addresses ---+ a_ptrs = a_ptr + offs_am[:, None] * stride_am + offs_k[None, :] * stride_ak+ b_ptrs = b_ptr + offs_k[:, None] * stride_bk + offs_bn[None, :] * stride_bn++ accumulator = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)++ # --- Main K-loop ---+ num_k_blocks = tl.cdiv(K, BLOCK_K)+ for k in range(0, num_k_blocks):+ k_rem = K - k * BLOCK_K+ a = tl.load(a_ptrs, mask=offs_k[None, :] < k_rem, other=0.0)+ b = tl.load(b_ptrs, mask=offs_k[:, None] < k_rem, other=0.0)+ accumulator = tl.dot(a, b, accumulator, allow_tf32=False)+ a_ptrs += BLOCK_K * stride_ak+ b_ptrs += BLOCK_K * stride_bk++ # --- Store result ---+ out = accumulator.to(tl.float16)+ offs_om = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)+ offs_on = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)+ out_ptrs = out_ptr + offs_om[:, None] * stride_om + offs_on[None, :] * stride_on+ out_mask = (offs_om[:, None] < M) & (offs_on[None, :] < N)+ tl.store(out_ptrs, out, mask=out_mask)+++ def custom_kernel(data: input_t) -> output_t:+ a, b, _c = data+ M, K = a.shape+ K2, N = b.shape+ assert K == K2, f"Inner dimension mismatch: {K} != {K2}"++ output = torch.empty(M, N, device='cuda', dtype=torch.float16)++ grid = lambda meta: (+ triton.cdiv(M, meta['BLOCK_M']) * triton.cdiv(N, meta['BLOCK_N']),+ )++ b200_matmul_kernel[grid](+ a, b, output,+ M, N, K,+ a.stride(0), a.stride(1),+ b.stride(0), b.stride(1),+ output.stride(0), output.stride(1),+ )+ return output+++ check_implementation = make_match_reference(custom_kernel)
scrolls · 239 diff lines total
Best evidence level for this revision: reported
JSON