Skip to content
KernelIndex
Search⌘K

submission 218864

lucifer_0000007 · python · License unknown

Use it

Vendorable · source mirrored · license unknownView source →

No package. Vendor the mirrored source: 59 lines, June 9 Researcher Reciprocity License v1.0.

submissio.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-nvfp4-dual-gemm-218864?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
NVFP4 dual GEMMsuite of 4 cases
NVIDIA B200
30.6µs
#253 of 420
2025-12-27

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:dcbaa932aaf886dbb87990fd9210fac4dccce7bbdbd5c0fee62fc69e0aff653d
license declaredunknown
license concludedunknown
authorslucifer_0000007
imported2026-08-26

Kernel source

submissio.py59 lines
import torch
from task import input_t, output_t

# Use reduce-overhead to enable CUDA Graphs and minimize dispatch latency
@torch.compile(mode="reduce-overhead")
def processing_loop(a, b1, b2, sfa_permuted, sfb1_permuted, sfb2_permuted, c):
    m, K_packed, l = a.shape
    
    # Pre-process Scales INSIDE the graph
    # Optimizes layout: Permute to [L, Mb, Kb, 32, 4, 4] -> Flatten
    # sfa_permuted is [32, 4, Mb, 4, Kb, L]
    # Permute indices: 5, 2, 4, 0, 1, 3
    sfa_p = sfa_permuted.permute(5, 2, 4, 0, 1, 3).contiguous().flatten(1, 5)
    sfb1_p = sfb1_permuted.permute(5, 2, 4, 0, 1, 3).contiguous().flatten(1, 5)
    sfb2_p = sfb2_permuted.permute(5, 2, 4, 0, 1, 3).contiguous().flatten(1, 5)
    
    # Iterate over L
    for i in range(l):
        # Extract slices
        a_slice = a[:, :, i]
        b1_slice = b1[:, :, i]
        b2_slice = b2[:, :, i]
        
        # Scales (contiguous slice due to pre-permute)
        scale_a = sfa_p[i, :]
        scale_b1 = sfb1_p[i, :]
        scale_b2 = sfb2_p[i, :]
        
        # GEMM
        # Use float32 output for precision correctness
        res1 = torch._scaled_mm(
            a_slice,
            b1_slice.t(), 
            scale_a,
            scale_b1,
            bias=None,
            out_dtype=torch.float32
        )
        
        res2 = torch._scaled_mm(
            a_slice,
            b2_slice.t(),
            scale_a,
            scale_b2,
            bias=None,
            out_dtype=torch.float32
        )
        
        # Elementwise
        c[:, :, i] = (torch.nn.functional.silu(res1) * res2).to(torch.float16)
    return c

def custom_kernel(data: input_t) -> output_t:
    a, b1, b2, sfa, sfb1, sfb2, sfa_permuted, sfb1_permuted, sfb2_permuted, c = data
    
    # Directly call the compiled loop with raw permuted inputs
    # The permutation logic is moved inside to be captured by CUDA Graphs
    return processing_loop(a, b1, b2, sfa_permuted, sfb1_permuted, sfb2_permuted, c)
scrolls · 59 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