submission 142242
NewFreezer · python · License unknown
Use it
Vendorable · source mirrored · license unknownView source →
No package. Vendor the mirrored source: 62 lines, June 9 Researcher Reciprocity License v1.0.
based.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-nvfp4-gemm-142242?include=source"interfacepython
Compatibility
measured onNVIDIA B200
declared hardwareNVIDIA B200
architecturessm_100
dtypesfp8_e4m3, nvfp4
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:1aed0af7e3304c88709b2cbcf21ddb12fdbfe47f6ab953423976093efaecdec9
license declaredunknown
license concludedunknown
authorsNewFreezer
imported2026-08-26
Techniques
Extracted from the mirrored source by pattern, never inferred. Each row cites its line.
fp4
Reference implementation of block-scale fp4 gemmKernel source
based.py62 lines
import torch
def custom_kernel(data):
"""
Reference implementation of block-scale fp4 gemm
Args:
data: Tuple that expands to:
a: torch.Tensor[float4e2m1fn] of shape [m, k, l],
b: torch.Tensor[float4e2m1fn] of shape [n, k, l],
sfa: torch.Tensor[float8_e4m3fnuz] of shape [m, k // 16, l],
sfb: torch.Tensor[float8_e4m3fnuz] of shape [n, k // 16, l],
sfa_permuted: torch.Tensor[float8_e4m3fnuz] of shape [32, 4, rest_m, 4, rest_k, l],
sfb_permuted: torch.Tensor[float8_e4m3fnuz] of shape [32, 4, rest_n, 4, rest_k, l],
c: torch.Tensor[float16] of shape [m, n, l]
Returns:
Tensor containing output in float16
c: torch.Tensor[float16] of shape [m, n, l]
"""
# c: [m, n, l] is pre-allocated memory to avoid timing allocation overhead.
a, b, sfa, sfb, _, _, c = data
# Get dimensions from MxNxL layout
_, _, l = c.shape
# Call torch._scaled_mm to compute the GEMM result
for l_idx in range(l):
# Convert the scale factor tensor to blocked format
scale_a = to_blocked(sfa[:, :, l_idx])
scale_b = to_blocked(sfb[:, :, l_idx])
# (m, k) @ (n, k).T -> (m, n)
res = torch._scaled_mm(
a[:, :, l_idx],
b[:, :, l_idx].transpose(0, 1),
scale_a.cuda(),
scale_b.cuda(),
bias=None,
out_dtype=torch.float16,
)
c[:, :, l_idx] = res
return c
# Helper function to convert scale factor tensor to blocked format
def to_blocked(input_matrix):
rows, cols = input_matrix.shape
# Please ensure rows and cols are multiples of 128 and 4 respectively
n_row_blocks = ceil_div(rows, 128)
n_col_blocks = ceil_div(cols, 4)
padded = input_matrix
blocks = padded.view(n_row_blocks, 128, n_col_blocks, 4).permute(0, 2, 1, 3)
rearranged = blocks.reshape(-1, 4, 32, 4).transpose(1, 2).reshape(-1, 32, 16)
return rearranged.flatten()
# Helper function for ceiling division
def ceil_div(a, b):
return (a + b - 1) // bscrolls · 62 lines total
Source code from GPU Mode and the KernelBot dataset · June 9 Researcher Reciprocity License v1.0
Best evidence level for this revision: reported
JSON