claude-opus-4-1 / tritonde54a2
claude-opus-4-1_triton_de54a2 · claude-opus-4-1-20250805 · triton · Apache-2.0
Use it
Vendorable · source mirrored · Apache-2.0View source →
No package. Vendor the mirrored source: 202 lines, Apache-2.0, pinned at da91508.
main.py
curl "https://kernelindex.com/api/v1/implementations/flashinfer-claude-opus-4-1-triton-de54a2?include=source"interfacetriton
revisionda915083d4c7
symbolrun
pathmain.py
Compatibility
measured onNVIDIA B200
declared hardwareNVIDIA B200
architecturessm_100
dtypesbf16, fp32, int32
Benchmark evidence
66 measurements across 1 GPU, fastest first.
Operation / workload
Hardware
Latency
Rank
Observed
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=17 · num_kv_indices=2
NVIDIA B200
17.5µs
#2 of 5
2026-03-28
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=8 · num_kv_indices=7
NVIDIA B200
22.7µs
#3 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=8 · num_kv_indices=7
NVIDIA B200
23.5µs
#3 of 6
2026-03-28
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=10 · num_kv_indices=9
NVIDIA B200
24.9µs
#2 of 5
2026-03-28
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=17 · num_kv_indices=2
NVIDIA B200
25.1µs
#3 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=10 · num_kv_indices=9
NVIDIA B200
25.1µs
#3 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=12 · num_kv_indices=11
NVIDIA B200
27.6µs
#3 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=15 · num_kv_indices=14
NVIDIA B200
28.6µs
#3 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=15 · num_kv_indices=14
NVIDIA B200
30.0µs
#3 of 6
2026-03-28
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=57 · num_kv_indices=40
NVIDIA B200
58.3µs
#3 of 7
2025-10-16
Show all 66 measurements ›Showing all 66 measurements ⌄
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=57 · num_kv_indices=40
NVIDIA B200
58.3µs
#4 of 6
2026-03-28
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=67 · num_kv_indices=50
NVIDIA B200
68.6µs
#3 of 4
2026-03-28
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=67 · num_kv_indices=50
NVIDIA B200
68.6µs
#5 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=81 · num_kv_indices=64
NVIDIA B200
83.0µs
#3 of 5
2026-03-28
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=81 · num_kv_indices=64
NVIDIA B200
84.0µs
#5 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=9317 · num_kv_indices=72
NVIDIA B200
96.4µs
#4 of 5
2026-03-28
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=9317 · num_kv_indices=72
NVIDIA B200
96.7µs
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=9332 · num_kv_indices=87
NVIDIA B200
111.9µs
#4 of 5
2026-03-28
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=9332 · num_kv_indices=87
NVIDIA B200
113.4µs
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=9347 · num_kv_indices=102
NVIDIA B200
128.6µs
#3 of 4
2026-03-28
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=9347 · num_kv_indices=102
NVIDIA B200
129.3µs
#7 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=191 · num_kv_indices=141
NVIDIA B200
174.4µs
#5 of 6
2026-03-28
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=191 · num_kv_indices=141
NVIDIA B200
175.7µs
#7 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=302 · num_kv_indices=252
NVIDIA B200
263.3µs
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=302 · num_kv_indices=252
NVIDIA B200
297.3µs
#4 of 4
2026-03-28
GQA paged decode h32 kv4 d128 ps1bf16 · [16, 32, 128] · num_pages=1070 · num_kv_indices=1020
NVIDIA B200
350.1µs
#5 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [16, 32, 128] · num_pages=2158 · num_kv_indices=2108
NVIDIA B200
419.3µs
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=412 · num_kv_indices=362
NVIDIA B200
422.2µs
#5 of 5
2026-03-28
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=412 · num_kv_indices=362
NVIDIA B200
423.2µs
#7 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [16, 32, 128] · num_pages=3246 · num_kv_indices=3196
NVIDIA B200
492.7µs
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=486 · num_kv_indices=436
NVIDIA B200
506.0µs
#4 of 4
2026-03-28
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=486 · num_kv_indices=436
NVIDIA B200
507.9µs
#7 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [16, 32, 128] · num_pages=4334 · num_kv_indices=4284
NVIDIA B200
563.3µs
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=596 · num_kv_indices=546
NVIDIA B200
629.7µs
#6 of 6
2026-03-28
GQA paged decode h32 kv4 d128 ps1bf16 · [16, 32, 128] · num_pages=5422 · num_kv_indices=5372
NVIDIA B200
636.0µs
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [1, 32, 128] · num_pages=596 · num_kv_indices=546
NVIDIA B200
636.4µs
#7 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [16, 32, 128] · num_pages=6510 · num_kv_indices=6460
NVIDIA B200
705.7µs
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [16, 32, 128] · num_pages=7598 · num_kv_indices=7548
NVIDIA B200
780.0µs
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [16, 32, 128] · num_pages=8686 · num_kv_indices=8636
NVIDIA B200
849.5µs
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=28831 · num_kv_indices=28815
NVIDIA B200
3.10ms
#4 of 5
2026-03-28
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=31007 · num_kv_indices=30991
NVIDIA B200
3.13ms
#3 of 5
2026-03-28
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=28831 · num_kv_indices=28815
NVIDIA B200
3.13ms
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [16, 32, 128] · num_pages=24732 · num_kv_indices=15463
NVIDIA B200
3.13ms
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=31007 · num_kv_indices=30991
NVIDIA B200
3.15ms
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=33183 · num_kv_indices=33167
NVIDIA B200
3.17ms
#3 of 5
2026-03-28
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=33183 · num_kv_indices=33167
NVIDIA B200
3.18ms
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [16, 32, 128] · num_pages=25820 · num_kv_indices=16551
NVIDIA B200
3.21ms
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=35359 · num_kv_indices=35343
NVIDIA B200
3.22ms
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=37535 · num_kv_indices=37519
NVIDIA B200
3.26ms
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [16, 32, 128] · num_pages=26908 · num_kv_indices=17639
NVIDIA B200
3.27ms
#7 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=39711 · num_kv_indices=39695
NVIDIA B200
3.30ms
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=41887 · num_kv_indices=41871
NVIDIA B200
3.33ms
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [16, 32, 128] · num_pages=27996 · num_kv_indices=18727
NVIDIA B200
3.34ms
#7 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=44063 · num_kv_indices=44047
NVIDIA B200
3.37ms
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=46303 · num_kv_indices=46287
NVIDIA B200
3.40ms
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [16, 32, 128] · num_pages=29084 · num_kv_indices=19815
NVIDIA B200
3.42ms
#7 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=48479 · num_kv_indices=48463
NVIDIA B200
3.44ms
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=50655 · num_kv_indices=50639
NVIDIA B200
3.48ms
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [16, 32, 128] · num_pages=30172 · num_kv_indices=20903
NVIDIA B200
3.49ms
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=52831 · num_kv_indices=52815
NVIDIA B200
3.52ms
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=55007 · num_kv_indices=54991
NVIDIA B200
3.54ms
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [16, 32, 128] · num_pages=31260 · num_kv_indices=21991
NVIDIA B200
3.56ms
#7 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=57183 · num_kv_indices=57167
NVIDIA B200
3.60ms
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=59359 · num_kv_indices=59343
NVIDIA B200
3.62ms
#6 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [16, 32, 128] · num_pages=32348 · num_kv_indices=23079
NVIDIA B200
3.64ms
#7 of 7
2025-10-16
GQA paged decode h32 kv4 d128 ps1bf16 · [64, 32, 128] · num_pages=61535 · num_kv_indices=61519
NVIDIA B200
3.67ms
#6 of 7
2025-10-16
Reproduction-ready · How evidence levels are derived →
Source and license
sourcehttps://huggingface.co/datasets/flashinfer-ai/flashinfer-trace
commitda915083d4c7c5e61aa3005e3d17ae488e0fc71c
revision digestsha256:fca116d8f26b466b880288e9cf0180fb342554d21db40f32a8884639593cfdcf
license declaredApache-2.0
license concludedApache-2.0
authorsclaude-opus-4-1-20250805
imported2026-08-20
Techniques
Extracted from the mirrored source by pattern, never inferred. Each row cites its line.
online-softmax
m_new = tl.maximum(m_i, m_ij)Kernel source
main.py202 lines
import torch
import triton
import triton.language as tl
import math
@triton.jit
def gqa_paged_decode_kernel(
q_ptr, k_cache_ptr, v_cache_ptr,
kv_indptr_ptr, kv_indices_ptr,
output_ptr, lse_ptr,
sm_scale,
batch_size, num_pages,
stride_qb, stride_qh, stride_qd,
stride_kp, stride_kh, stride_kd,
stride_vp, stride_vh, stride_vd,
stride_ob, stride_oh, stride_od,
stride_lseb, stride_lseh,
log2_e,
BLOCK_SIZE: tl.constexpr,
HEAD_DIM: tl.constexpr,
NUM_QO_HEADS: tl.constexpr,
NUM_KV_HEADS: tl.constexpr,
GQA_RATIO: tl.constexpr,
):
# Get batch and head indices
bid = tl.program_id(0)
hid = tl.program_id(1)
if bid >= batch_size or hid >= NUM_QO_HEADS:
return
# Get KV head index for GQA
kv_hid = hid // GQA_RATIO
# Get page range for this batch
page_start = tl.load(kv_indptr_ptr + bid)
page_end = tl.load(kv_indptr_ptr + bid + 1)
num_tokens = page_end - page_start
if num_tokens <= 0:
# No KV cache for this batch element
d_range = tl.arange(0, HEAD_DIM)
output_offset = bid * stride_ob + hid * stride_oh + d_range * stride_od
tl.store(output_ptr + output_offset, tl.zeros((HEAD_DIM,), dtype=tl.bfloat16))
lse_offset = bid * stride_lseb + hid * stride_lseh
tl.store(lse_ptr + lse_offset, float('-inf'))
return
# Load query vector for this head
d_range = tl.arange(0, HEAD_DIM)
q_offset = bid * stride_qb + hid * stride_qh + d_range * stride_qd
q = tl.load(q_ptr + q_offset).to(tl.float32)
# Initialize accumulators for online softmax
m_i = float('-inf')
l_i = 0.0
acc = tl.zeros((HEAD_DIM,), dtype=tl.float32)
# Process KV cache in blocks
for token_idx in range(0, num_tokens, BLOCK_SIZE):
# Create mask for valid tokens in this block
token_range = tl.arange(0, BLOCK_SIZE)
token_pos = token_idx + token_range
mask = token_pos < num_tokens
# Load page indices for this block
page_indices = tl.load(
kv_indices_ptr + page_start + token_pos,
mask=mask,
other=0
)
# Compute attention scores for this block
scores = tl.zeros((BLOCK_SIZE,), dtype=tl.float32)
# Load K vectors and compute dot products
for i in range(BLOCK_SIZE):
if token_idx + i < num_tokens:
page_id = tl.load(kv_indices_ptr + page_start + token_idx + i)
k_offset = page_id * stride_kp + kv_hid * stride_kh + d_range * stride_kd
k = tl.load(k_cache_ptr + k_offset).to(tl.float32)
score = tl.sum(q * k) * sm_scale
scores = tl.where(token_range == i, score, scores)
# Apply mask to scores
scores = tl.where(mask, scores, float('-inf'))
# Find maximum score in this block
m_ij = tl.max(scores, axis=0)
m_new = tl.maximum(m_i, m_ij)
# Compute exponentials with numerical stability
exp_scores = tl.exp(scores - m_new)
exp_scores = tl.where(mask, exp_scores, 0.0)
# Update running statistics
alpha = tl.exp(m_i - m_new)
l_new = alpha * l_i + tl.sum(exp_scores)
# Scale previous accumulator
acc = acc * alpha
# Accumulate weighted V vectors
for i in range(BLOCK_SIZE):
if token_idx + i < num_tokens:
page_id = tl.load(kv_indices_ptr + page_start + token_idx + i)
v_offset = page_id * stride_vp + kv_hid * stride_vh + d_range * stride_vd
v = tl.load(v_cache_ptr + v_offset).to(tl.float32)
weight = tl.where(token_range == i, exp_scores, 0.0)
acc = acc + tl.sum(weight) * v
# Update state
m_i = m_new
l_i = l_new
# Normalize output
output = acc / l_i
# Store output
output_offset = bid * stride_ob + hid * stride_oh + d_range * stride_od
tl.store(output_ptr + output_offset, output.to(tl.bfloat16))
# Compute and store LSE (2-based)
# lse = (m_i + log(l_i)) / log(2) = (m_i + log(l_i)) * log2(e)
lse = (m_i + tl.log(l_i)) * log2_e
lse_offset = bid * stride_lseb + hid * stride_lseh
tl.store(lse_ptr + lse_offset, lse)
def run(q, k_cache, v_cache, kv_indptr, kv_indices, sm_scale=None):
# Handle device management
device = None
if q.is_cuda:
device = q.device
elif torch.cuda.is_available():
device = torch.device('cuda')
q = q.cuda()
k_cache = k_cache.cuda() if not k_cache.is_cuda else k_cache
v_cache = v_cache.cuda() if not v_cache.is_cuda else v_cache
kv_indptr = kv_indptr.cuda() if not kv_indptr.is_cuda else kv_indptr
kv_indices = kv_indices.cuda() if not kv_indices.is_cuda else kv_indices
else:
raise RuntimeError("CUDA is not available for GPU tensors")
# Get dimensions
batch_size, num_qo_heads, head_dim = q.shape
num_pages, page_size, num_kv_heads, _ = k_cache.shape
# Verify constants
assert num_qo_heads == 32, f"num_qo_heads must be 32, got {num_qo_heads}"
assert num_kv_heads == 4, f"num_kv_heads must be 4, got {num_kv_heads}"
assert head_dim == 128, f"head_dim must be 128, got {head_dim}"
assert page_size == 1, f"page_size must be 1, got {page_size}"
# Compute GQA ratio
gqa_ratio = num_qo_heads // num_kv_heads
# Set default sm_scale if not provided
if sm_scale is None:
sm_scale = 1.0 / math.sqrt(head_dim)
# Allocate output tensors
output = torch.zeros((batch_size, num_qo_heads, head_dim), dtype=torch.bfloat16, device=device)
lse = torch.full((batch_size, num_qo_heads), -float('inf'), dtype=torch.float32, device=device)
# Squeeze page_size dimension since it's 1
k_cache_flat = k_cache.squeeze(1)
v_cache_flat = v_cache.squeeze(1)
# Define block size for token processing
BLOCK_SIZE = 64
# Precompute log2(e) for LSE calculation
log2_e = 1.0 / math.log(2.0)
# Launch kernel
grid = (batch_size, num_qo_heads)
gqa_paged_decode_kernel[grid](
q, k_cache_flat, v_cache_flat,
kv_indptr, kv_indices,
output, lse,
sm_scale,
batch_size, num_pages,
q.stride(0), q.stride(1), q.stride(2),
k_cache_flat.stride(0), k_cache_flat.stride(1), k_cache_flat.stride(2),
v_cache_flat.stride(0), v_cache_flat.stride(1), v_cache_flat.stride(2),
output.stride(0), output.stride(1), output.stride(2),
lse.stride(0), lse.stride(1),
log2_e,
BLOCK_SIZE=BLOCK_SIZE,
HEAD_DIM=head_dim,
NUM_QO_HEADS=num_qo_heads,
NUM_KV_HEADS=num_kv_heads,
GQA_RATIO=gqa_ratio,
)
# Move outputs back to original device if needed
if not q.is_cuda and torch.cuda.is_available():
output = output.cpu()
lse = lse.cpu()
return output, lsescrolls · 202 lines total
Source code from FlashInfer-Bench (flashinfer-ai/flashinfer-trace) · Apache-2.0
Best evidence level for this revision: reproducible
JSON