Skip to content

hrx: sleep through long stream waits instead of spinning a CPU core - #44

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-sleeping-wait
Sep 29, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-sleeping-wait

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

This fixes a CPU core that stayed busy for the whole of every decode token on HRX, heating the APU.

Cause: the per-token wait is hrx_stream_wait, which goes to ROCr's hsa_signal_wait_scacquire on the stream timeline, and it never sleeps.

  • The timeline advances with every completed command, about 900 per 27B decode token.
  • Each advance returns the KFD event ioctl at once.
  • Measured on the waiting thread over 6 s: 35% user + 65% system, with only 30 context switches.

On Strix Halo that costs about 10 W of package power. It is the difference between 74 °C and 90–93 °C during 27B decode; runs were hitting our 93 °C bench guard, and the box has already power-cycled once on a thermal trip.

Fix (runtime/hrx-sleeping-wait.{h,cpp}, our file):

  • When a wait is expected to be long, sleep through 80% of it, then finish with the normal hrx_stream_wait. "Long" means the shortest of the last four waits at that call site is over 20 ms.
  • Shorter waits are unchanged. Sleeping through 3–10 ms tokens cost small models 2–5%, because the host work between tokens then runs on a clocked-down core.
  • The new wait is used at two call sites: the graph-replay wait and backend synchronize.
  • ONEBIT_HRX_BLOCKING_WAIT=1 turns it off.

Results, A/B interleaved on HRX0 (Strix Halo, gfx1151):

Blocking wait This PR
27B tg384: waiting thread (ticks per 6 s) ~600 ~120
27B package power 133–137 W 124–129 W
27B Tctl during decode (peak) 83–89 °C (85–91) 71–74 °C (74–76)
27B decode 12.11–12.12 tok/s 12.06–12.07 tok/s (−0.4%)
Qwen3-0.6B decode 323.7–324.7 323.5–323.9
ZAYA1-8B decode 95.0–95.3 94.9–95.2

ZAYA prefill wikitext PPL is unchanged at 41.9971.

🤖 Generated with Claude Code

The per-token wait (hrx_stream_wait -> ROCr hsa_signal_wait_scacquire on the
stream timeline) never sleeps: the timeline advances with every completed
command (~900 per 27B decode token) and each advance returns the KFD event
ioctl at once. The waiting thread ran a full core the whole token (35% user
+ 65% system, 30 context switches in 6 s), adding ~10 W to the APU package
and the difference between ~74 C and 90-93 C during 27B decode on Strix Halo.

runtime/hrx-sleeping-wait.{h,cpp} (our file): when a wait is expected to be
long (the shortest of the last four waits at the call site is over 20 ms),
sleep through 80% of it, then finish with the normal hrx_stream_wait. Shorter
waits are unchanged: sleeping through 3-10 ms tokens cost small models 2-5%
(host work between tokens then runs on a clocked-down core). Hooked into the
graph-replay wait and backend synchronize. ONEBIT_HRX_BLOCKING_WAIT=1 turns
it off.

Qwen3.8-27B UD-Q4_K_XL, HRX0 tg384, A/B interleaved: waiting thread 600 ->
~120 ticks per 6 s; package 133-137 -> 124-129 W; Tctl during decode 83-89
-> 71-74 C (peaks 85-91 -> 74-76); decode 12.11-12.12 -> 12.06-12.07 tok/s
(-0.4%). Qwen3-0.6B (323.7-324.7 vs 323.5-323.9) and ZAYA1-8B (95.0-95.3 vs
94.9-95.2) unchanged. ZAYA prefill wikitext PPL 41.9971 (unchanged).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the ggml label Sep 29, 2026
@bong-water-water-bong
bong-water-water-bong merged commit 6617e78 into 1bit/hrx-vulkan-patched Sep 29, 2026
10 of 24 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/hrx-sleeping-wait branch November 12, 2026 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant