ReadingResearchRadarInvestment framework
Sign in / Sign up
← Back to reading
NewsMaterial5 min readDisconfirmAI Editorial

AMD's PC Sampling: Two Methods That Turn GPU Hotspot Hunting from Counter-Guessing into a Diagnostic Loop

A ROCm engineering blog details how software-based (host-trap) and hardware-based (stochastic) PC sampling complement each other to identify where GPU time is spent and why waves stall there. A worked GEMM example shows the full loop: host-trap pinpoints a single hot line, stochastic reveals 93% of stalls are WAITCNT on uncoalesced global loads, an LDS-tiling rewrite achieves ~3.0× speedup, and re-running both methods confirms the stall pattern shifted from memory-bound to issue-bound.

2026-11-26 08:00 GMT+8

Hardware performance counters tell you a GPU kernel is memory-bound, that occupancy is low, or that L2 miss rates are high. They do not tell you which line of your code is responsible. This gap between aggregate metrics and source-level attribution is the problem AMD's ROCprofiler-SDK PC Sampling addresses, and a November 2026 blog post by Vladimir Indic walks through how two complementary methods close it.

PC sampling works by periodically capturing the program counter of executing waves on the GPU, then aggregating thousands of samples into a statistical hotspot profile. Unlike instrumentation-based approaches, it requires no kernel modification, no recompilation, and no serialization of concurrent execution. The sampled binary is the same binary that runs in production. The method resolves hotspots to individual instructions, and — when the binary carries debug symbols — maps them back to source lines.

The SDK provides two methods that target the same problem from different directions. Software-based host-trap sampling runs a background thread on the host CPU that periodically fires a trap signal broadcast to every compute unit. Each CU with a resident wave in the targeted slot pauses, captures its state (PC, exec mask, dispatch ID, wave coordinates), writes it to a GPU buffer, and resumes. The interval is specified in microseconds and the method is available on AMD CDNA GPUs starting with the MI200 series. Hardware-based stochastic sampling lives on each CU: every N GPU cycles, dedicated hardware picks one resident wave, snapshots its state, and writes it to a buffer. No host involvement. It requires CDNA 3 or later and adds four fields per sample: whether the wave issued an instruction that cycle, what type of instruction it was, the stall reason if it did not issue, and the number of waves resident on the CU.

Sign in / Sign up
ReadingResearchRadarInvestment framework

The distinction between the two methods is sharp: host-trap tells you where time is spent; stochastic tells you why waves stall at that location. Host-trap has no microarchitectural state and suffers a 1–2 instruction sampling skid, meaning the reported PC can sit one or two instructions past the costly one. Stochastic has no skid — the captured PC is the wave's actual PC at the sampled cycle — but requires newer hardware and generates larger data volumes.

The blog demonstrates both methods on a naive global-memory GEMM kernel (one SIMD thread per output element, no tiling) running on a single AMD Instinct MI300A with ROCm rocm-10.1.0. The kernel takes 357.1 ms for an 8192×8192×8192 multiply. Host-trap sampling at a 1 ms interval produces 86,239 source-mapped samples after filtering out the warmup dispatch. Of these, 96.3% land on line 76 — the inner-loop body where the multiply-accumulate happens. The remaining 3.6% sit on line 74, the loop header. A single hotspot, but host-trap cannot explain why the wave is stuck there.

Switching to stochastic sampling at the hardware ceiling of 2^20 cycles produces 167,891 samples. The same line 76 now shows a 96.9% stall rate: waves issued an instruction in only 3.1% of samples. Breaking down the stall reasons, 93.1% of non-issue cycles are WAITCNT — the wave is parked on s_waitcnt vmcnt, waiting for an outstanding vector-memory load to return. The diagnosis is concrete: fetch-bound on uncoalesced global loads of matrix B, with no data reuse across threads. The B access pattern strides by n=8192 elements between adjacent workgroup rows, so every FMA pays the full global-memory round trip.

The blog then applies the natural fix: a 16×16 LDS-tiled variant that stages A and B tiles into local data share, so each loaded value is reused by 16 threads instead of 1. The tiled kernel runs in 118.0 ms — a ~3.0× speedup. Re-running both sampling methods confirms the diagnosis moved. Host-trap sample count drops from 86,239 to 26,628, tracking the wall-time reduction. The single 96% hotspot dissolves into a spread across compute (line 109, 44.1%), a guard (line 107, 10.3%), and two synchronization points. Stochastic sampling shows the hot compute line's stall rate dropped from 96.9% to 85.2%, and WAITCNT's share of non-issue cycles fell from 93.1% to 67.5%.

That percentage comparison, however, understates the actual improvement. The blog makes a point of this: 93.1% of 157,442 non-issue samples is 146,507 WAITCNT samples, while 67.5% of 17,798 non-issue samples is 12,008 — roughly 12.2× fewer WAITCNT samples in absolute terms. The lesson generalizes: when comparing stall percentages between two runs, multiply by the per-line non-issue count before drawing conclusions. A smaller percentage of a much larger pile can still be the bigger problem.

The remaining stall profile on the tiled kernel tells a coherent story. The first __syncthreads (line 103) shows 96.6% stall rate, split between WAITCNT (51.6%, draining the just-issued tile loads) and BARRIER_WAIT (47.3%, the barrier itself). The second __syncthreads (line 113) shows 99.8% BARRIER_WAIT with essentially no WAITCNT, confirming the next-tier bottleneck is synchronization, not memory traffic. The inner-loop guard and tile-load guard show ALU_DEPENDENCY and ARBITER_NOT_WIN — issue-side stalls typical of a kernel closer to compute-bound. The global-memory wait has been confined to the staging barrier, amortized across 16 FMAs, exactly where you want it.

The blog positions PC sampling within a broader diagnostic hierarchy: kernel-trace gives the dispatch timeline, PMC counters characterize the bottleneck class, PC sampling localizes to a source line and explains the stall, and Advanced Thread Trace provides cycle-accurate wave-level detail on a subset of CUs. PC sampling can serve as a standalone first-pass triage tool across an entire application without preselecting a target kernel. The author notes that PMC and PC sampling cannot run simultaneously on the same agent, so multi-phase investigations require separate invocations.

Practical constraints deserve emphasis. Stochastic intervals must be powers of two in [2^8, 2^20] cycles; the blog discourages values below 2^16 due to data volume and per-sample perturbation. Very short kernels (under ~5 microseconds) may produce too few stochastic samples to be useful — the cycle-based clock does not tick often enough relative to kernel lifetime. Output files grow quickly: long-running workloads at aggressive intervals can produce multi-gigabyte CSVs. Source-line attribution requires building with -g; without debug symbols, the Instruction_Comment column is empty and you are left reading assembly. The method is scoped to CDNA architectures and is not productized on RDNA.

Sources

  • rocm.blogs.amd.comROCm Blogs↗
Continue researching →