Skip to content
FunCoding

blackwell-kernel-profiling

Profile and debug CUDA, CUTLASS, Triton, and PyTorch kernels on NVIDIA Blackwell GPUs (B200/GB200 SM100, B300/GB300 SM103, RTX Blackwell SM120, GB10 SM121) using Nsight Systems, Nsight Compute, Torch Profiler, and the repository's architecture and abort-attribution rules.

Star
2,262
License
Apache-2.0
Last commit
Dec 1, 2026

.agents/skills/blackwell-kernel-profiling/SKILL.md

View on GitHub

Blackwell Kernel Profiling and Architecture Discipline

Use this skill when compiling, profiling, or debugging GPU kernels across Blackwell targets under code/.

Architecture identities (never conflate)

  • SM100 (sm_100 / sm_100a): B200 / GB200 (the shared CUDA 13.0 + PyTorch 2.14.1 setup.sh baseline).
  • SM103 (sm_103 / sm_103a): B300 / GB300 (separate environment and qualification path, never substituted with SM100 receipts).
  • SM120 (sm_120) and SM121 (sm_121): RTX Blackwell and GB10 (separate feature constraints, no datacenter tcgen05 cluster assumptions).

Use core/common/cuda_arch.mk (ARCH=sm_100, sm_103, sm_120, sm_121) and core/harness/arch_config.py. Preserve explicit unsupported-target diagnostics instead of silently rewriting one architecture into another.

Cold-cache abort and toolchain attribution

Before adding any compiler flag, architecture guard, or kernel workaround for a Triton, Inductor, CUTLASS, or CUDA failure:

  1. Reproduce with cold caches (TRITON_CACHE_DIR, TORCHINDUCTOR_CACHE_DIR, CUDA_CACHE_PATH pointed at a fresh temp directory) to separate stale cache bugs from real toolchain failures.
  2. Isolate the exact failing layer (CUDA driver, nvcc/ptxas, CUTLASS 4.5.2, Triton 3.8.0, Inductor, or runtime ABI) and capture the raw error message.
  3. Prefer fixing the root cause in kernel code or build configuration. Document any unavoidable hardware/toolchain boundary with exact version pins and a clear SKIPPED: or hard diagnostic.

Profilers and capture hygiene

Run commands from code/ after sourcing the pinned environment (runtime-env.sh):

# PyTorch profiler (initializes Kineto/CUPTI before capture)
python -m cli.aisp profile torch tests/fixtures/mcp_torch_profile_target.py \
  --mode full --output-name smoke-torch --timeout 60

# Nsight Systems 2026.5.1 timeline (cuda, nvtx, osrt)
python -m cli.aisp profile nsys \
  "python tests/fixtures/mcp_torch_profile_target.py" \
  --output-name smoke-nsys --timeout 60

# Nsight Compute 2026.2.1 kernel metrics (discover real metric names first)
ncu --list-sections
ncu --set basic --export kernel_run_01 python <script>

# Deep-dive nsys/ncu explanation for human engineers or AI coding agents
python -m cli.aisp profile explain artifacts/runs/<run_id>/profiles/<pair_dir> --format md
python -m cli.aisp profile explain path/to/report.ncu-rep --include-source --format json
python -m cli.aisp profile compare-nsys artifacts/runs/<run_id>/profiles/<pair_dir>
python -m cli.aisp profile compare-ncu artifacts/runs/<run_id>/profiles/<pair_dir> --include-ncu-details

Two-tier agent optimization loop (CLI + MCP)

Keep the inner edit loop fast and gate deeper profiling deliberately so ncu kernel replay (10x-100x overhead and exclusive GPU profiler lock) never blocks iteration:

  1. Fast inner loop (<10s, --profile none): Run python -m cli.aisp bench run --targets <target> --profile none (or MCP benchmark_verify + run_benchmarks) to check VerifyRunner numerical parity and CUDA-Event speedup. Inspect -Xptxas=-v during CUDA extension builds for zero register spills.
  2. Timeline & hotspot triage (nsys): Capture with --profile minimal (default in tier1-nightly.yml) or aisp profile nsys / MCP profile_nsys, then call aisp profile explain <report.nsys-rep> (or MCP profile_explain / compare_nsys) to separate micro-kernel launch storms, host sync stalls, H2D copies, and dominant GPU kernels.
  3. Kernel roofline deep dive (ncu): Filter directly to the hotspot kernel with aisp profile ncu <script> --kernel-filter <name> --metric-set roofline --launch-count 5 (or MCP profile_ncu), then run aisp profile explain <report.ncu-rep> --include-source --include-disassembly (or MCP profile_explain / compare_ncu) to classify DRAM vs SM/Tensor Core vs L2 vs occupancy/register-spill bottlenecks and feed concrete next-step hypotheses back into the agent.
  4. Automated CI/harness evaluation: Every --profile minimal|roofline|deep_dive run automatically attaches profile_evaluation (PASS/WARN/INFO, regime shift, metric deltas, and warnings) to benchmark_test_results.json, benchmark_test_results.md, and the Tier-1 nightly GitHub Step Summary.

For multi-rank NCCL or distributed captures that deadlock under default NCU process-tree replay, follow the rank-local TCP workflow in docs/tooling-and-profiling.md and core/profiling/ncu_torchrun_capture.py.

Evidence rules

  • Never substitute profiled duration for a separately measured end-to-end timing.
  • Confirm that a Torch trace actually contains CUDA kernel, memcpy, or memset events with positive durations before citing GPU activity.
  • Materialize baseline and candidate profile files directly under named artifact paths instead of pairing symlinks.
  • Inspect NCU roofline, occupancy, stall reasons, and HBM vs L2 traffic before claiming a kernel optimization mechanism.

Read code/docs/blackwell_tcgen05_nvfp4_guide.md when authoring or tuning sm_100a FP4/FP8 decode, MoE, hybrid DeltaNet, or TP=2 NVLink P2P kernels:

  • Match precision to batch regime: persistent W4A16 for B = 1..4, native tcgen05 W4A4/W8A8 for dense B >= 8, and MXFP4 (W4A8: MXFP8 acts x MXFP4 weights) as the default high-batch MoE FP4 path (zero activation calibration via E8M0 scales).
  • Clear flashinfer.autotuner.AutoTuner.get().clear_cache() per batch size with real non-zero tokens before tuning, broadcast Rank 0's winning tactic map to peer TP ranks (dist.broadcast_object_list) to prevent +3.7 ms NVLink barrier skew, and verify global_scale direction with a 1-GEMM mag_ratio test instead of trusting docstrings.
  • Read peer-written NVLink 5 P2P buffers with double-buffered IPC slots (epoch & 1) and L1-bypassing .cv loads (__ldcv / ld.global.cv.*) so CUDA Graph replays never serve stale L1 lines or race across epochs.
  • Prefer register-direct Tensor Core mma.m16n8k32.e4m3 / mma.m16n8k16.bf16 over scalar SIMT FP8 GEMVs at B = 1..8, overlap Shared Expert with Routed MoE on a second CUDA stream inside the CUDA Graph, and absorb W_uk/W_uv for NoPE MLA.
  • Benchmark tcgen05 decode inside a CUDA Graph after a >= 40-replay boost-clock warmup, verify graph_diff < 1e-3, and report apples-to-apples Full + argmax latency alongside held-out cosine and top-1 parity.

Similar Skills

rea-analysis-optimization

MOmorluto/rea485k7,690 new stars in the last 7 days

codebase-design

MAmattpocock/skills336k4,217 new stars in the last 7 days

Featured

diagnosing-bugs

Diagnose hard bugs and performance regressions by building a feedback loop with tests or scripts.

MAmattpocock/skills336k4,217 new stars in the last 7 days

setup-ts-deep-modules

MAmattpocock/skills336k4,217 new stars in the last 7 days

code-review

MAmattpocock/skills336k4,217 new stars in the last 7 days

implement

MAmattpocock/skills336k4,217 new stars in the last 7 days