Command Palette

Search for a command to run...

UnylyUnyly
Back to skills

benchmark-kernel

FreeNo executable scriptsNot checked

Guide for benchmarking FlashInfer kernels with CUPTI timing

flashinfer-aiby flashinfer-ai★ 7,044 GitHub stars20 installs in other catalogs

About this skill

Tutorial: Benchmarking FlashInfer Kernels

This tutorial shows you how to accurately benchmark FlashInfer kernels.

Goal

Measure the performance of FlashInfer kernels:

  • Get accurate GPU kernel execution time
  • Compare multiple backends (FlashAttention2/3, cuDNN, CUTLASS, TensorRT-LLM)
  • Generate reproducible benchmark results
  • Save results to CSV for analysis

Timing Methods

FlashInfer supports two timing methods:

  1. CUPTI (Preferred): Hardware-level profiling for most accurate GPU kernel time

    • Measures pure GPU compute time without host-device overhead
    • Requires cupti-python >= 13.0.0 (CUDA 13+)
  2. CUDA Events (Fallback): Standard CUDA event timing

    • Automatically used if CUPTI is not available
    • Good accuracy, slight overhead from host synchronization

The framework automatically uses CUPTI if available, otherwise falls back to CUDA events.

Autotuner timing (separate from the benchmark framework above). The AutoTuner's internal per-tactic timing has its own selector, FLASHINFER_AUTOTUNE_TIMER: globaltimer forces the GPU %globaltimer register, cuda_event forces cudaEvent, and unset/auto uses %globaltimer only when Confidential Computing (CC) is detected. Under CC cudaEventElapsedTime is unreliable (can go negative), which would corrupt tactic ranking — the globaltimer path avoids that. CC auto-detection can be overridden with FLASHINFER_CONFIDENTIAL_COMPUTE=0/1. (Full env-var reference in AGENTS.md.)

Installation

Install CUPTI (Recommended)

For the most accurate benchmarking:

pip install -U cupti-python

Requirements: CUDA 13+ (CUPTI version 13+)

Without CUPTI

If you don't install CUPTI, the framework will:

  • Print a warning: CUPTI is not installed. Falling back to CUDA events.
  • Automatically use CUDA events for timing
  • Still provide good benchmark results

Method 1: Using flashinfer_benchmark.py (Recommended)

Step 1: Choose Your Test Routine

Available routines:

  • Attention: BatchDecodeWithPagedKVCacheWrapper, BatchPrefillWithPagedKVCacheWrapper, BatchPrefillWithRaggedKVCacheWrapper, BatchMLAPagedAttentionWrapper, trtllm_batch_decode_sparse_mla_dsv4
  • GEMM: bmm_fp8, gemm_fp8_nt_groupwise, group_gemm_fp8_nt_groupwise, mm_fp4
  • MOE: trtllm_fp4_block_scale_moe, trtllm_fp8_block_scale_moe, trtllm_fp8_per_tensor_scale_moe, cutlass_fused_moe

Step 2: Run a Single Benchmark

Example - Benchmark decode attention:

# CUPTI will be used automatically if installed
python benchmarks/flashinfer_benchmark.py \
    --routine BatchDecodeWithPagedKVCacheWrapper \
    --backends fa2 fa2_tc cudnn \
    --page_size 16 \
    --batch_size 32 \
    --s_qo 1 \
    --s_kv 2048 \
    --num_qo_heads 32 \
    --num_kv_heads 8 \
    --head_dim_qk 128 \
    --head_dim_vo 128 \
    --q_dtype bfloat16 \
    --kv_dtype bfloat16 \
    --num_iters 30 \
    --dry_run_iters 5 \
    --refcheck \
    -vv

Example - Benchmark FP8 GEMM:

python benchmarks/flashinfer_benchmark.py \
    --routine bmm_fp8 \
    --backends cudnn cublas cutlass \
    --batch_size 256 \
    --m 1 \
    --n 1024 \
    --k 7168 \
    --input_dtype fp8_e4m3 \
    --mat2_dtype fp8_e4m3 \
    --out_dtype bfloat16 \
    --refcheck \
    -vv \
    --generate_repro_command

Timing behavior:

  • ✅ If CUPTI installed: Uses CUPTI (most accurate)
  • ⚠️ If CUPTI not installed: Automatically falls back to CUDA events with warning
  • 🔧 To force CUDA events: Add --use_cuda_events flag

Step 3: Understand the Output

[INFO] FlashInfer version: 0.6.0
[VVERBOSE] gpu_name = 'NVIDIA_H100_PCIe'
[PERF] fa2            :: median time 0.145 ms; std 0.002 ms; achieved tflops 125.3 TFLOPs/sec; achieved tb_per_sec 1.87 TB/sec
[PERF] fa2_tc         :: median time 0.138 ms; std 0.001 ms; achieved tflops 131.5 TFLOPs/sec; achieved tb_per_sec 1.96 TB/sec
[PERF] cudnn          :: median time 0.142 ms; std 0.001 ms; achieved tflops 127.8 TFLOPs/sec; achieved tb_per_sec 1.91 TB/sec

Key metrics:

  • median time: Median kernel execution time (lower is better)
  • std: Standard deviation (lower means more consistent)
  • achieved tflops: Effective TFLOPS throughput
  • achieved tb_per_sec: Memory bandwidth utilization

Step 4: Run Batch Benchmarks

Create a test list file my_benchmarks.txt:

--routine BatchDecodeWithPagedKVCacheWrapper --backends fa2 cudnn --page_size 16 --batch_size 32 --s_kv 2048 --num_qo_heads 32 --num_kv_heads 8 --head_dim_qk 128 --head_dim_vo 128
--routine BatchDecodeWithPagedKVCacheWrapper --backends fa2 cudnn --page_size 16 --batch_size 64 --s_kv 4096 --num_qo_heads 32 --num_kv_heads 8 --head_dim_qk 128 --head_dim_vo 128
--routine bmm_fp8 --backends cudnn cutlass --batch_size 256 --m 1 --n 1024 --k 7168 --input_dtype fp8_e4m3 --mat2_dtype fp8_e4m3 --out_dtype bfloat16

Run all tests:

python benchmarks/flashinfer_benchmark.py \
    --tes
Full SKILL.md on GitHub

Install benchmark-kernel in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

FAQ

What does the benchmark-kernel skill do?

Guide for benchmarking FlashInfer kernels with CUPTI timing

How do I install the benchmark-kernel skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the benchmark-kernel skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare benchmark-kernel with