← Back to Home

Notes on AMD GPU Scheduling and Its “Worst Practices”

My notes on Otterness & Anderson’s paper (UNC Chapel Hill, Real-Time Systems 2022 / RTNS 2021). Everything was measured on a Radeon VII with ROCm 4.2. One idea per note, plus a little toy you can poke at.

1. Open stack, no docs

ROCm is open source, but it’s huge and almost nothing about how it schedules work is written down. So the authors followed a kernel launch through every layer and mapped what happens. Here’s the stack, top to bottom.

HIP API (your code) ROCclr (runtime) HSA runtime (ROCr) amdgpu / KFD driver GPU firmware + hardware (ACEs, SEs, CUs) Scheduling rules are spreadacross all of these layers, with very few docs.The paper traces it end to endin its appendix flowcharts.

2. Streams: ordered inside, parallel across

A kernel is a pile of thread blocks, up to 1,024 threads each. Inside one HIP stream, work runs in order (FIFO). Across streams, work can overlap. That overlap is the whole reason scheduling matters.

Stream AStream B K1 K2 (waits for K1) K3 (overlaps K1 and K2) time →

3. Prior work is mostly NVIDIA

Earlier real-time GPU research mostly targeted NVIDIA, and since that stack is closed it relied on black-box tests, reverse engineering, or working with the vendor. AMD is open, so here they just read the source and then checked it with experiments.

NVIDIA (prior work)Closed driver, so black-box tests, reverse engineering, vendor help.
AMD (this paper)Open driver and runtime, so read the code, then confirm with experiments.

4. The test GPU

A Radeon VII: 4 shader engines (SEs) with 15 compute units (CUs) each, so 60 CUs. One CU holds up to 2,048 threads, which means the whole GPU can have 122,880 threads resident at once.

Compute units60 = 4 × 15
Max resident threads122,880

5. Same math, different block sizes

Both tasks multiply 1,024×1,024 matrices, one thread per output. The only difference is block shape. MM1024 uses 1,024 blocks of 32×32 threads. MM256 uses 4,096 blocks of 16×16. One MM1024 block is the same work as four MM256 blocks, but the small ones can squeeze into gaps the big ones can’t use.

MM1024 block: 1,024 threads 4 × MM256 blocks: 256 threads each = Total work is identical.Small blocks fit into gapsthat big blocks can’t use.

6. The weird numbers

Two things jump out. Under full sharing, MM256 is the nastiest neighbor you can pick. And the uneven split (an even split plus one CU borrowed from the competitor’s half) is roughly 10× slower than everything else.

MeanWorst case

Table 1, in ms (mean / worst case). Bars are on a 0–105 ms scale.

7. Streams share 4 queues

Your streams don’t each get their own queue. ROCclr maps them onto a shared pool of 4 HSA queues by default. Two streams that land on the same queue get serialized, even though you declared them independent. The way out: a stream created with a CU mask gets a dedicated queue.

Streams6

8. Only 32 hardware queue slots

The hardware can run 32 queues at once: 4 ACEs × 8 slots. Go past that and the GPU time-slices all the queues, with no priority. For real-time work, the paper’s advice is to turn oversubscription off.

Active queues (all processes)20

9. Small blocks cut ahead

ACEs hand out blocks in strict order. But when a big block doesn’t fit, small blocks from the other kernel take the freed space first, so MM256 ends up holding almost the whole GPU. Toy model of one CU (8 slots × 256 threads):

MM1024 block (4 slots)MM256 block (1 slot)
t = 0
MM1024 share of CU–
MM256 share of CU–

Illustration only. In the paper’s measured timelines, MM256 grabs nearly all GPU capacity once it starts.

10. One lone CU stalls everything

The ACE walks the shader engines in order, and it only skips an SE if every CU on it is masked off. Leave a single CU enabled and dispatch has to wait on that one contended CU every lap around.

Blocks dispatched0
Ticks spent waiting0

Illustration. Measured effect: 7.6 ms → 101.5 ms worst case for MM1024 vs. MM256.

11. CU masks interleave across SEs

You set masks at stream creation with hipExtStreamCreateWithCUMask. Mask bits interleave across the SEs (bit i goes to SE i mod 4), so the layout you pick matters. For uneven splits, spreading CUs across all SEs beats packing whole SEs.

MM1024 (measured)MM256SharedLone CU on an SE
MM1024 mean–
MM1024 worst case–

Table 2 values, in ms. The grid shows each layout schematically.

12. Other AMD gotchas

If you’re porting from CUDA, be careful: NVIDIA doesn’t let small blocks cut ahead, so ported code might quietly depend on that ordering. Queue multiplexing is another source of contention, and one environment variable tunes it.

Re-test ported codeRe-check block-order and performance assumptions on AMD.
Tune queue sharingGPU_MAX_HW_QUEUES=8 ./app changes the HSA queue pool size (default 4, see 7).

13. Takeaways

If you want predictable latency on AMD GPUs, you have to know the internal scheduling rules, or you pay for it in worst-case response time.

Source: Otterness & Anderson, “Exploring AMD GPU Scheduling Details by Experimenting With ‘Worst Practices’” — paper PDF. The toys in 9 and 10 are simplified illustrations, not the paper’s data.