Commit d97db73
committed
[ROCm] QDP: order default-stream setup before forked-stream kernels
Restore the non-blocking forked stream on all platforms and fix the
actual root cause of the Windows gfx1201 stream-test regression: a
missing ordering between default-stream buffer setup and a kernel
launched on a non-blocking stream that consumes it.
Background: fork_default_stream creates a hipStreamNonBlocking stream to
match cudarc and preserve the dual-stream copy/compute overlap. The
encoders set up their input (htod) and output (alloc_zeros) buffers with
the blocking shim copies, which run on the NULL/default stream, then
launch the norm/encode kernels on the caller's forked stream.
CUDA's legacy default stream is synchronizing, so on NVIDIA that setup is
implicitly ordered before the forked-stream kernel reads the buffer. HIP's
default stream is NOT synchronizing relative to a non-blocking stream, so
the kernel raced the setup and read stale/zero data; the norm came back as
the zero-initialized value and the result was wrong. A previous change
worked around this by creating a blocking stream on Windows, which masked
every such site at once but sacrificed the pipeline overlap and was
attributed to a nonexistent "cache coherency gap" in the Windows runtime.
A minimal HIP reproducer shows the runtime is correct: a kernel on a
non-blocking stream that is properly ordered against the default stream
(stream sync, device sync, or an event wait) reads back correct data on
both the Adrenalin and ROCm runtimes; only the unordered case fails.
The fix synchronizes the default stream at the end of the blocking
alloc_zeros / htod copies (sync_default_stream), restoring the
CUDA-equivalent ordering on every platform without touching the async
pipeline (which uses async copies on explicit streams, not these blocking
paths). The forked stream is non-blocking again everywhere. The symmetric
readback hazard (a NULL-stream dtoh after a forked-stream kernel) is closed
where it was still missing a sync: the f64/f32 batch norm-validation copies
in amplitude.rs and the phase batch finiteness-probe copy in phase.rs now
synchronize the caller's stream before reading back, matching the idiom the
other encoders already use.
This is arch-unified: correct on wave32 (gfx1100/gfx1151/gfx1201) and
wave64 (gfx90a). On Linux the default stream is already synchronizing, so
the added sync is a harmless no-op-cost ordering point.
Authored with the assistance of Claude (Anthropic).
Test Plan
gfx1201 (RX 9070 XT, Windows 11, TheRock ROCm 7.14, HIP_VISIBLE_DEVICES=0):
```
export QDP_USE_HIP=1 QDP_HIP_ARCH_LIST=gfx1201 HIP_VISIBLE_DEVICES=0
cargo build -p qdp-core -p qdp-kernels --no-default-features --features hip
cargo test -p qdp-core -p qdp-kernels --no-default-features --features hip -- --test-threads=1
```
All suites pass, 0 failures. The three previously-regressed stream tests
pass with the non-blocking stream restored:
test_l2_norm_batch_kernel_stream,
test_encode_from_gpu_ptr_f32_with_stream_non_default_success,
test_encode_batch_from_gpu_ptr_f32_with_stream_success. qdp-core lib 77,
gpu_ptr_encoding 68 (all 10 _with_stream variants pass), amplitude 21,
angle 10, and all other GPU and non-GPU suites green.1 parent 90b6006 commit d97db73
3 files changed
Lines changed: 49 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
414 | 414 | | |
415 | 415 | | |
416 | 416 | | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
417 | 423 | | |
418 | 424 | | |
419 | 425 | | |
| |||
646 | 652 | | |
647 | 653 | | |
648 | 654 | | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
649 | 661 | | |
650 | 662 | | |
651 | 663 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
353 | 353 | | |
354 | 354 | | |
355 | 355 | | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
356 | 365 | | |
357 | 366 | | |
358 | 367 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
63 | | - | |
64 | 62 | | |
65 | 63 | | |
66 | 64 | | |
| |||
71 | 69 | | |
72 | 70 | | |
73 | 71 | | |
74 | | - | |
75 | 72 | | |
76 | | - | |
77 | | - | |
78 | 73 | | |
79 | 74 | | |
80 | 75 | | |
| |||
92 | 87 | | |
93 | 88 | | |
94 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
95 | 108 | | |
96 | 109 | | |
97 | 110 | | |
| |||
305 | 318 | | |
306 | 319 | | |
307 | 320 | | |
| 321 | + | |
308 | 322 | | |
309 | 323 | | |
310 | 324 | | |
| |||
354 | 368 | | |
355 | 369 | | |
356 | 370 | | |
| 371 | + | |
357 | 372 | | |
358 | 373 | | |
359 | 374 | | |
| |||
400 | 415 | | |
401 | 416 | | |
402 | 417 | | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
414 | 426 | | |
415 | 427 | | |
416 | 428 | | |
417 | 429 | | |
418 | | - | |
419 | | - | |
420 | 430 | | |
421 | 431 | | |
422 | 432 | | |
| |||
0 commit comments