Skip to content

feat(hip): events, stream waits and device memory info - #630

Merged
ashhart merged 1 commit into
ashhart:mainfrom
jkuepker:hip-events-main
Oct 12, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
jkuepker:hip-events-main

Conversation

@jkuepker

Copy link
Copy Markdown
Contributor

This adds HIP events, stream waits and device memory info to #463's runtime, matching the CUDA module:

  • Event, either timing or ordering-only, with record, synchronize, done and elapsedMs.
  • Stream.done and Stream.wait(event).
  • Context.memInfo, from hipMemGetInfo.

A query that returns hipErrorNotReady means the work is unfinished, not that it failed. Any other result still fails.

Nothing in the open HIP PRs (#607, #609, #611, #612, #613, #617) adds events, stream waits or hipMemGetInfo. #611's memory usage counts the bytes this process holds, while memInfo is the driver's free/total for the device, so the two answer different questions. #611 and #617 append next to this in abi.zig, context.zig, runtime_tests.hip and runtime_tests.zig. All of those are keep-both merges, and I'm happy to rebase onto whichever lands first.

How it's tested

  • Ordering: a probe kernel sleeps before one write, so the GPU test has queued work to observe. Right after queueing, the event and the stream both report unfinished. A second stream that waits on the event reads the written value, and the timed span is positive. Without the wait, the reader returns the zero fill, so the test fails if the wait is missing.
  • Memory info: the total must be at least 1 GiB and stay the same between calls. A 64 MiB allocation must lower free memory. That check skips, and says so, when another process leaves less than 128 MiB free.
  • Host-side mock tests: they check that not_ready maps to unfinished, that other query failures still fail, and that memInfo refuses impossible driver counts.

Receipt

Setup: two AMD Radeon AI PRO R9700 cards (gfx1201, 32 GB each), ROCm 7.2.1 in rocm/dev-ubuntu-24.04:7.2.1-complete, Zig 0.17.0, this branch at 52449e0b (on main 9041e20a), each card tested on its own (HIP_VISIBLE_DEVICES).

step card 0 card 1
zig build hip-host-test 33/33 (host only)
hip-gpu-test -Dhip-arch=gfx1201 25/25 25/25
hip-affine-test -Dhip-arch=gfx1201 25/25 25/25
hip-gpu-test -Dhip-arch=gfx1151 (wrong arch, must fail) 23 pass, 2 fail: UnsupportedArchitecture same
hip-affine-test -Dhip-arch=gfx1151 (wrong arch, must fail) 21 pass, 4 fail: UnsupportedArchitecture same
hip-gpu-test with the reader.wait(end) line removed (must fail) 24 pass, 1 fail: the event test reads 0, expected 12648430 same

No test skipped; the memory check ran with both cards free.

Mac, on this branch:

  • zig build test -Dcpu=apple_m1: exit 0, no test errors.
  • zig build --help: the HIP steps and options still register.
  • python3 tools/zig/lean_check.py: 542 problems on main 9041e20a and 542 on this branch.

Earlier runs of this events code, stacked on the multi-architecture branch before #463 landed:

  • gfx1151 (Strix Halo) by @ThinkOffApp, on 907911c and 2b20f268.
  • gfx1150 (Radeon 890M) by @millaguie, on 907911c.

Both included the negative control: with the wait removed, the ordering test fails.

The events code hasn't changed since. Two edits in the tests since then: the event test now builds its own single-image list, the way main's tests do, and two comments (runtime_tests.hip, runtime_tests.zig) no longer quote timings.

Mirrors the CUDA module: Event (timing or ordering-only) with record,
synchronize, done and elapsedMs; Stream.done and Stream.wait(event); and
Context.memInfo from hipMemGetInfo. hipErrorNotReady from a query means
unfinished work, not failure; other results still fail.

A probe kernel that sleeps before one write gives the GPU tests queued work
to observe: right after queueing, the event and stream report unfinished;
a second stream that waits on the event reads the written value, and the
timed span is positive. Without the wait the reader returns the zero fill,
so the ordering check fails when the wait is missing.

memInfo is checked on the device for a stable total of at least 1 GiB. The
check that a 64 MiB allocation lowers free memory skips, and says so, when
another process leaves less than 128 MiB free.
@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thanks, @jkuepker. #611 landed first (56150e6), and as you expected it touches the same four files. We merged yours on top locally, keeping both sides: memInfo beside attribute and name in context.zig, your probe kernel beside tf_hip_wave, your constants and test lines in abi.zig, and your three tests appended whole in runtime_tests.zig. zig fmt and hip-host-test pass. We can't build the HIP GPU tests here, though, because none of our machines has hipcc. Could you rebase onto main and run hip-gpu-test on your card, as you offered? We'll land it as soon as it's up.

@ashhart ashhart mentioned this pull request Oct 10, 2026
@ThinkOffApp

Copy link
Copy Markdown
Contributor

gfx1151 receipt at this head (Strix Halo: Ryzen AI Max+ 395, Radeon 8060S), fresh Zig cache per step:

  • Ubuntu 26.04.1, Linux 7.0.0, Zig 0.17.0, Ubuntu's packaged HIP 7.1.52801, -Dhip-arch=gfx1151
  • hip-host-test 33/33, hip-gpu-test 25/25, hip-affine-test 25/25. Nothing skipped, so the memory check ran.
  • Linux zig build test: 37/37 steps, 384/384 tests.
  • Not repeated here: the wrong-arch and removed-wait negative controls (your gfx1201 table has them).

@BlivionIaG

Copy link
Copy Markdown
Contributor

Receipt for this PR on main (56150e6, with #611), the four files merged keeping both sides as you did. W7800 (gfx1100) and V620 (gfx1030), HIP 7.14, fresh Zig cache:

  • hip-gpu-test, hip-affine-test and hip-host-test: 66/66 on each GPU, including the event ordering and timing test and both memory-info tests.
  • Linux zig build test: 37/37 steps, 430/430 tests.

#631 also runs on top of it, taking this PR's Context.memInfo in place of its own: GPU runtime and kernel tests 100/100 on both GPUs, logits byte-identical to #490 on Qwen3.6-35B-A3B, and tf-qwen35-test check 46/46 on each.

@ashhart
ashhart merged commit 8b78fc1 into ashhart:main Oct 12, 2026
2 checks passed
@ashhart

ashhart commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Thank you, @jkuepker. This landed in 1.0.8. No rebase was needed from you after all: we did it on our side, as we should have. Sorry for asking.

The negative controls in particular made this easy to trust without a card.

BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
The change landed rebased onto the 1.0.8 candidate as 5a89c22e3 with its author kept; this keeps the PR's head in the history with no change to the tree.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants