analyze-kernel-bottleneck
Systematically identify whether a GPU kernel is compute-bound, memory-bound, or latency-bound using roofline analysis, occupancy calculations, compute/load…
Skill by Philipp Thoss
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/pjt222-analyze-kernel-bottleneck
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/analyze-kernel-bottleneck
Tools it pre-approves 4
From allowed-tools in SKILL.md: the agent may use these without asking you each time.
ReadGrepGlobBash
What's inside
- Skill name
analyze-kernel-bottleneck- Description
- Systematically identify whether a GPU kernel is compute-bound, memory-bound, or latency-bound using roofline analysis, occupancy calculations, compute/load ratio per tile, and SASS instruction inspection. Produces a decision matrix for optimization strategy selection (cp.async, warp interleaving, tiling, double-buffering, or CuAssembler hand-tuning).
- License
- MIT
- Allowed tools
- Read, Grep, Glob, Bash
- Metadata
- tags: gpu, roofline, occupancy, sass, tensor-core, bottleneck-analysis, compute-load-ratio · author: Philipp Thoss · domain: gpu-optimization · version: 1.0 · language: CUDA · complexity: advanced
- Instructions
- 293 lines in SKILL.md · view on GitHub
Before installing
- Pre-approves any shell command
Files (1)
- SKILL.md
SKILL.md (first lines)
# Analyze Kernel Bottleneck Systematically identify whether a GPU kernel is compute-bound, memory-bound, or latency-bound by measuring baseline performance, classifying on the roofline, computing occupancy and compute/load ratio per tile, inspecting SASS instruction mix and stall codes, checking the shared memory cliff, and applying a decision matrix to select the right optimization strategy. ## When to Use - Before optimizing any CUDA kernel -- establish baseline and classify bottleneck type - After writing a first working version of a kernel to identify the optimization path - When a kernel underperforms expectations relative to theoretical peak - When deciding between cp.async, larger tiles, or algorithmic restructuring ## Inputs - **Required**: Compiled kernel (`.cubin` or `.cu` source with build command) - **Required**: Benchmark harness that launches the kernel with CUDA event timing - **Required**: Problem dimensions (e.g., M, N, K for GEMM; seq_len, heads, head_dim for attention) - **Optional**: Target GPU architecture (default: GA104 / sm_86 / RTX 3070 Ti) - **Optional**: Expected peak utilization percentage for comparison - **Optional**: Prior profiling data (Nsight Compute reports) ## Procedure ### Step 1: Measure Baseline Performance Run the kernel with CUDA events (`BenchTimer`), record time in milliseconds. Calculate effective throughput metrics: 1. **Compile** the kernel if not already built: ```bash nvcc --cubin -arch=sm_86 -O2 -o kernel.sm_86.cubin kernel.cu nvcc -arch=sm_86 -O2 -o bench bench.cu -lcuda -I../../phase2/common ``` 2. **Run** with representative problem sizes, ensuring warmup runs precede measurement: ```bash ./bench 4096 4096 4096 ``` 3. **Record** kernel time in ms from CUDA events (not wall-clock). 4. **Calculate** effective GFLOPS and effective bandwidth: - GEMM: `effective_gflops = (2 * M * N * K) / (time_ms / 1000) / 1e9` - Bandwidth-limited kernels: `effective_bw = total_bytes / (time_ms / 1000) / 1e9` - Flash Attention: `effective_gflops = (4 * batch * heads * seq_len^2 * head_dim) / (time_ms / 1000) / 1e9` **Got:** Baseline numbers: kernel time in ms, effective GFLOPS, and effective bandwidth. **If fail:** Check that the kernel launches without error (`CHECK_CU` macro). Verify warmup runs precede measurement. Ensure problem dimensions are large enough to saturate the GPU (small problems may bottleneck on launch overhead). ### Step 2: Classify on the Roofline Compute arithmetic intensity and compare against the machine balance point to classify the kernel: 1. **Calculate arithmetic intensity**: `AI = FLOPs / bytes_loaded_from_global_memory`. Count only unique bytes loaded from DRAM (not shared memory or register reuse). 2. **Look up machine balance point**: `balance = peak_compute / peak_bandwidth`. 3. **Classify**: If `AI < balance`, the kernel is memory-bound. If `AI > balance`, the kernel is compute-bound. **GA104 (RTX 3070 Ti) Reference Values:** | Resource | Peak | Unit | |---|---|---| | FP32 FFMA | 21.7 | TFLOPS | | FP16 Tensor Core (HMMA) | 174 | TFLOPS | | INT8 Tensor Core (IMMA) | 696 | TOPS | | DRAM Bandwidth | 608 | GB/s | | L2 Cache | 4 | MB | | SMs | 48 | | **Derived Balance Points:** | Precision | Balance Point (FLOP/byte) | |---|---| | FP32 FFMA | 21700 / 608 = 35.7 | | FP16 TC | 174000 / 608 = 286.2 | | INT8 TC | 696000 / 608 = 1144.7 | 4. **Compute attained fraction**: `attained = effective_throughput / peak_throughput`. If memory-bound: compare effective bandwidth to 608 GB/s. If compute-bound: compare effective GFLOPS to the relevant peak. **Got:** Classification as compute-bound, memory-bound, or latency-bound (low occupancy causing neither compute nor memory saturation) with numerical justification. **If fail:** Recheck byte counting. Watch for redundant re-reads (e.g., 9x in direct conv2d without im2col). If neither compute nor memory is saturated, the kernel is likely latency-bound (see Step 3). ### Step 3: Calculate Occupancy Determine active warps per SM from the launch configuration and resource usage: 1. **Extract resource usage**: ```bash nvcc --cubin -arch=sm_86 -O2 --resource-usage -o kernel.sm_86.cubin kernel.cu 2>&1 | grep -E 'registers|smem' ``` 2. **From launch config**: `warps_per_block = threads_per_block / 32`. 3. **Compute blocks/SM** from each limiting factor: - Register limit: `floor(65536 / (registers_per_thread * threads_per_block))` - Smem limit: `floor(available_smem_per_SM / smem_per_block)` -- see Step 6 for cliff - Warp limit: `floor(48 / warps_per_block)` (GA104 max: 48 warps/SM) - Block limit: 16 blocks/SM max on GA104 4. **Actual blocks/SM** = `min(register_limit, smem_limit, warp_limit, block_limit)`. 5. **Active warps/SM** = `blocks_per_SM * warps_per_block`. 6. **Key threshold**: 8 warps/SM is sufficient for latency hiding on GA104. Below 8 = structural problem causing latency-bound behavior. **Got:** Occupancy table showing blocks/SM, active warps/SM, and the limiting factor (registers, smem, or warps). **If fail:** Check `cuFuncSetAttribute` for dynamic shared memory. Verify `--resource-usage` reports match the actual launch configuration. If register count is unexpectedly high, try `--maxrregcount=N` to cap registers (trading register spills for occupancy). ### Step 4: Compute the Compute/Load Ratio Per Tile Count compute instructions and load bytes per K-tile from SASS (not source code): 1. **Disassemble**: ```bash cuobjdump -sass kernel.sm_86.cubin > kernel.sass ``` 2. **Count compute instructions per tile** (the inner loop over one K-tile): - `grep -c 'HMMA' kernel.sass` -- FP16 Tensor Core ops - `grep -c 'IMMA' kernel.sass` -- INT8 Tensor Core ops - `grep -c 'FFMA' kernel.sass` -- FP32 fused multiply-add 3. **Count global loads per tile**: - `grep -c 'LDG' kernel.sass` -- global memory loads - Multiply by bytes per load (typically 16 bytes for LDG.128) 4. **Calculate ratio**: `compute_ops / load_ops` per tile. 5. **Classify** using the cp.async decision threshold (from gpu_reflections.md Insight 2): - **High** (>20:1): cp.async is net-negative; warp interleaving already hides DRAM latency. Focus on algorithmic changes. Reference: Flash Attention has 64 HMMA per tile = high ratio, cp.async measured -5%. - **Medium** (5-20:1): cp.async may help, benchmark both paths.
From pjt222/agent-almanac, MIT.
More from pjt222/agent-almanac
- 0.616score
adaptic
Philipp Thoss
Master skill composing the 5-step synoptic cycle for panoramic synthesis across multiple domains.
SkillBFreshness: B★ 42Claude Code +9 - 0.616score
add-puzzle-type
Philipp Thoss
Scaffold a new puzzle type across all 10+ pipeline integration points in jigsawR.
SkillBFreshness: B★ 42Claude Code +9 - 0.616score
add-rcpp-integration
Philipp Thoss
Add Rcpp or RcppArmadillo integration to an R package for high-performance C++ code.
SkillBFreshness: B★ 42Claude Code +9 - 0.616score
aikido
Philipp Thoss
Practice aikido as a defensive martial art emphasizing harmony, redirection, and controlled resolution.
SkillBFreshness: B★ 42Claude Code +9 - 0.616score
analyze-codebase-for-mcp
Philipp Thoss
Analyze an arbitrary codebase to identify functions, APIs, and data sources suitable for exposure as MCP tools, producing a tool specification document.
SkillBFreshness: B★ 42Claude Code +9 - 0.616score
analyze-codebase-workflow
Philipp Thoss
Analyze an arbitrary codebase to auto-detect workflows, data pipelines, and file dependencies using putior's put_auto() engine.
SkillBFreshness: B★ 42Claude Code +9 - 0.616score
analyze-diffusion-dynamics
Philipp Thoss
Analyze the dynamics of diffusion processes using stochastic differential equations, Fokker-Planck equations, first-passage time distributions, and parameter…
SkillBFreshness: B★ 42Claude Code +9 - 0.616score
analyze-generative-diffusion-model
Philipp Thoss
Analyze pre-trained generative diffusion models (Stable Diffusion, DALL-E, Flux) by computing quality metrics (FID, IS, CLIP score, precision/recall)…
SkillBFreshness: B★ 42Claude Code +9 - 0.616score
analyze-magnetic-field
Philipp Thoss
Calculate and visualize magnetic fields produced by current distributions using the Biot-Savart law, Ampere's law, and magnetic dipole approximations.
SkillBFreshness: B★ 42Claude Code - 0.616score
analyze-magnetic-levitation
Philipp Thoss
Analyze magnetic levitation systems by applying Earnshaw's theorem to determine whether passive static levitation is possible, then identifying the…
SkillBFreshness: B★ 42Claude Code - 0.616score
analyze-prime-numbers
Philipp Thoss
Analyze prime numbers using primality tests, factorization algorithms, prime distribution analysis, and sieve methods.
SkillBFreshness: B★ 42Claude Code +9 - 0.616score
adapt-architecture
Philipp Thoss
Execute structural metamorphosis using strangler fig migration, chrysalis phases, and interface preservation.
SkillBFreshness: B★ 42Claude Code +9
Signals
- Stars
- 42
- Forks
- 5
- Open issues
- 182
- Last commit (this folder)
- Aug 17, 2026 (2 months ago)
- Last release
- Aug 26, 2026 (2 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- Version
- 1.0
- License
- MIT
- Repository
- github.com/pjt222/agent-almanac
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from Philipp Thoss
- 0.616score
adaptic
Philipp Thoss
Master skill composing the 5-step synoptic cycle for panoramic synthesis across multiple domains.
SkillBFreshness: B★ 42Claude Code +9 - 0.616score
add-puzzle-type
Philipp Thoss
Scaffold a new puzzle type across all 10+ pipeline integration points in jigsawR.
SkillBFreshness: B★ 42Claude Code +9 - 0.616score
add-rcpp-integration
Philipp Thoss
Add Rcpp or RcppArmadillo integration to an R package for high-performance C++ code.
SkillBFreshness: B★ 42Claude Code +9 - 0.616score
aikido
Philipp Thoss
Practice aikido as a defensive martial art emphasizing harmony, redirection, and controlled resolution.
SkillBFreshness: B★ 42Claude Code +9 - 0.616score
analyze-codebase-for-mcp
Philipp Thoss
Analyze an arbitrary codebase to identify functions, APIs, and data sources suitable for exposure as MCP tools, producing a tool specification document.
SkillBFreshness: B★ 42Claude Code +9 - 0.616score
adapt-architecture
Philipp Thoss
Execute structural metamorphosis using strangler fig migration, chrysalis phases, and interface preservation.
SkillBFreshness: B★ 42Claude Code +9
Cite this page
analyze-kernel-bottleneck skill. Agent Mart. https://agentmart.dev/skills/pjt222-analyze-kernel-bottleneck (last updated 2026-10-24)