Skip to content
KernelIndex
Search⌘K

flashinfer / wrapper33cb6f

flashinfer_wrapper_33cb6f · FlashInfer-Bench baselines · python · Apache-2.0

Use it

Vendorable · source mirrored · Apache-2.0View source →

No package. Vendor the mirrored source: 53 lines, Apache-2.0, pinned at da91508.

main.py
curl "https://kernelindex.com/api/v1/implementations/flashinfer-flashinfer-wrapper-33cb6f?include=source"
interfacepython
revisionda915083d4c7
symbolrun
pathmain.py
Compatibility
measured onNVIDIA B200
declared hardwareNVIDIA A100, NVIDIA B200, NVIDIA H100, NVIDIA H20, NVIDIA H200
architecturesunknown
dtypesbf16, fp32, int32

Benchmark evidence

20 measurements across 1 GPU, fastest first.

Operation / workload
Hardware
Latency
Rank
Observed
NVIDIA B200
10.2µs
#1= of 2
2026-04-09
NVIDIA B200
10.2µs
#1 of 2
2026-04-09
NVIDIA B200
10.2µs
#1 of 2
2026-04-09
NVIDIA B200
10.3µs
#1 of 2
2026-04-09
NVIDIA B200
10.3µs
#2 of 2
2026-04-09
NVIDIA B200
12.2µs
#2 of 2
2026-04-09
NVIDIA B200
12.3µs
#1 of 2
2026-04-09
NVIDIA B200
12.3µs
#1 of 2
2026-04-09
NVIDIA B200
12.3µs
#1 of 2
2026-04-09
NVIDIA B200
12.3µs
#1 of 2
2026-04-09
Show all 20 measurements ›
NVIDIA B200
12.3µs
#2 of 2
2026-04-09
NVIDIA B200
12.3µs
#2 of 2
2026-04-09
NVIDIA B200
12.3µs
#2 of 2
2026-04-09
NVIDIA B200
12.3µs
#2 of 2
2026-04-09
NVIDIA B200
22.7µs
#1 of 2
2026-04-09
NVIDIA B200
23.9µs
#2 of 2
2026-04-09
NVIDIA B200
24.6µs
#1 of 2
2026-04-09
NVIDIA B200
24.6µs
#1 of 2
2026-04-09
NVIDIA B200
24.6µs
#2 of 2
2026-04-09
NVIDIA B200
24.6µs
#2 of 2
2026-04-09

Reproduction-ready · How evidence levels are derived →

Source and license

sourcehttps://huggingface.co/datasets/flashinfer-ai/flashinfer-trace
commitda915083d4c7c5e61aa3005e3d17ae488e0fc71c
revision digestsha256:fdf38318ea766afdda61fe7e9fb7c51696da2d903a6373327e53e57a4f0225f9
license declaredApache-2.0
license concludedApache-2.0
authorsbaseline
imported2026-08-16

Kernel source

main.py53 lines
import torch
import flashinfer

# GQA group_size=8 (8 qo_heads / 1 kv_heads) is a power-of-2 and is
# natively supported by FlashInfer kernels.

_WORKSPACE_SIZE_BYTES = 256 * 1024 * 1024
_workspace_cache = {}
_wrapper_cache = {}
_plan_state = {}


def _get_workspace(device):
    key = str(device)
    buf = _workspace_cache.get(key)
    if buf is None:
        buf = torch.empty(_WORKSPACE_SIZE_BYTES, dtype=torch.uint8, device=device)
        _workspace_cache[key] = buf
    return buf


def _get_wrapper(key, device):
    w = _wrapper_cache.get(key)
    if w is None:
        w = flashinfer.BatchPrefillWithRaggedKVCacheWrapper(_get_workspace(device), kv_layout="NHD")
        _wrapper_cache[key] = w
    return w


def run(q, k, v, qo_indptr, kv_indptr, sm_scale):
    total_q, num_qo_heads, head_dim = q.shape
    total_kv, num_kv_heads, _ = k.shape
    device = q.device
    wkey = (str(device), num_qo_heads, num_kv_heads, head_dim, q.dtype, k.dtype)
    wrapper = _get_wrapper(wkey, device)
    state = _plan_state.get(wkey)
    needs_plan = state is None or state["total_q"] != total_q or state["qo_ptr"] != qo_indptr.data_ptr()
    if needs_plan:
        wrapper.plan(
            qo_indptr=qo_indptr,
            kv_indptr=kv_indptr,
            num_qo_heads=num_qo_heads,
            num_kv_heads=num_kv_heads,
            head_dim_qk=head_dim,
            causal=True,
            sm_scale=float(sm_scale),
            q_data_type=q.dtype,
            kv_data_type=k.dtype,
        )
        _plan_state[wkey] = {"total_q": total_q, "qo_ptr": qo_indptr.data_ptr()}
    output, lse = wrapper.run(q, k, v, return_lse=True)
    return output, lse
scrolls · 53 lines total

Source code from FlashInfer-Bench (flashinfer-ai/flashinfer-trace) · Apache-2.0

Best evidence level for this revision: reproducible

JSON