[PR #597] [CLOSED] HIP: optional host-side expert-copy waits (0.88% earlier warm-prefill gain) #617

Closed
opened 2026-10-29 21:27:31 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/597
Author: @LostVector
Created: 10/28/2026
Status: ❌ Closed

Base: main ← Head: upstream/hip-host-copy-wait


📝 Commits (1)

  • 71d9110 HIP: add opt-in host wait before streamed expert-part reuse

📊 Changes

6 files changed (+148 additions, -1 deletions)

View changed files

📝 CMakeLists.txt (+2 -0)
➕ docs/DS4_HIP_HOST_COPY_WAIT.md (+29 -0)
📝 docs/SETTINGS.md (+11 -0)
➕ src/ds4/ds4_hip_copy_wait.hpp (+10 -0)
📝 src/ds4/ds4_model.cu (+15 -1)
➕ tests/ds4_hip_copy_wait_test.cu (+81 -0)

📄 Description

An earlier matched EXL3 test measured 0.88% lower warm-2K prefill latency, with exact checked logits, by changing where Maya waits before reusing an expert buffer. This draft exposes that scheduling choice on current upstream, disabled by default.

In plain terms: before new weights overwrite a VRAM slot, the previous computation must finish reading it. Today the GPU copy stream waits for that event. This option makes the device worker's CPU thread wait instead, then queues the copy. It preserves the same event dependency and data; it can change HIP queue scheduling and reduce submission overlap, so the best choice depends on the workload/driver.

Focused change

  • MAYA_DS4_HIP_HOST_COPY_WAIT=1; native STRATA_DS4_HIP_HOST_COPY_WAIT and DS4_HIP_HOST_COPY_WAIT aliases accepted.
  • Off by default. Only standard HIP copy_ahead changes; CUDA and the flow loader retain their existing paths.
  • No hardware IDs, model dimensions, expert format assumptions or cache-policy changes.
  • Compute still waits for filled, the host staging lifetime still uses its existing filled synchronization, and both modes wait for freed before slot overwrite. Return status uses existing model error handling.
  • No inference math, batching, virtual-slot layout, copy contents or accumulation-order change. This is not a fix for general driver/KFD stalls.

Why the host wait does not wait for an unsubmitted consumer

The queue condition is cp < kp + P; for a reused slot cp >= P, so its prior batch cp - P < kp. The consumer records freed[half] before incrementing kp and then calls copy_ahead. The event being waited on has therefore already been submitted. That invariant still holds at the current insertion point on v1.1.34 / 249f9a8.

Current-base validation

  • Clean Release HIP/gfx1201 maya-ds4 and ds4_hip_copy_wait_test builds; executable help smoke passed.
  • 512 streamed batches independently checked on two R9700s, using the actual production wait helper. Two nonblocking streams, a four-part ring, off/on/on/off arms, changing/non-power-of-two lengths, full guards and untouched-tail checks. Both modes exactly match an independent integer CPU reference and each other.
  • HIP API mapping and git diff --check passed. The existing serving process was not replaced.
  • This is a single-device ring-ordering test run on each card, not a new full-model or multi-GPU peer validation. CUDA/Windows/other AMD cards were not hardware-tested.

Historical timing scope

The earlier model test used two R9700s plus a 9070 XT, TP2/split36/4, 256K context, fixed expert residency/profile, and the earlier FMA16/packed-host/predecode/pruning stack. Warm 2048-token prefill used six balanced blocks / 24 observations: all blocks positive, mean latency reduction 0.8796%, block-based 95% interval 0.7483–1.0108%. Median 7518.923 → 7458.083 ms. Cold results were inconclusive; one decode pair established no speedup. Full cold/warm/repeat logits and 80 greedy tokens matched independent references, with zero cache moves and process swap in timing trials. Original fork PR #13 and raw protocol/results.

Those timings are evidence for the option, not measurements of this current-upstream port. Current batching/staging and surrounding kernels have evolved. A representative same-binary model comparison, including normal caching and multi-GPU execution, remains before any default recommendation. Documentation and the standalone reproducer are included.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/mw00/project-maya/pull/597 **Author:** [@LostVector](https://github.com/LostVector) **Created:** 10/28/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `upstream/hip-host-copy-wait` --- ### 📝 Commits (1) - [`71d9110`](https://github.com/mw00/project-maya/commit/71d9110f4c16c84fc6bd7996b7f459159064e3b1) HIP: add opt-in host wait before streamed expert-part reuse ### 📊 Changes **6 files changed** (+148 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+2 -0) ➕ `docs/DS4_HIP_HOST_COPY_WAIT.md` (+29 -0) 📝 `docs/SETTINGS.md` (+11 -0) ➕ `src/ds4/ds4_hip_copy_wait.hpp` (+10 -0) 📝 `src/ds4/ds4_model.cu` (+15 -1) ➕ `tests/ds4_hip_copy_wait_test.cu` (+81 -0) </details> ### 📄 Description **An earlier matched EXL3 test measured 0.88% lower warm-2K prefill latency, with exact checked logits, by changing where Maya waits before reusing an expert buffer.** This draft exposes that scheduling choice on current upstream, disabled by default. In plain terms: before new weights overwrite a VRAM slot, the previous computation must finish reading it. Today the GPU copy stream waits for that event. This option makes the device worker's CPU thread wait instead, then queues the copy. It preserves the same event dependency and data; it can change HIP queue scheduling and reduce submission overlap, so the best choice depends on the workload/driver. ### Focused change - `MAYA_DS4_HIP_HOST_COPY_WAIT=1`; native `STRATA_DS4_HIP_HOST_COPY_WAIT` and `DS4_HIP_HOST_COPY_WAIT` aliases accepted. - Off by default. Only standard HIP `copy_ahead` changes; CUDA and the flow loader retain their existing paths. - No hardware IDs, model dimensions, expert format assumptions or cache-policy changes. - Compute still waits for `filled`, the host staging lifetime still uses its existing `filled` synchronization, and both modes wait for `freed` before slot overwrite. Return status uses existing model error handling. - No inference math, batching, virtual-slot layout, copy contents or accumulation-order change. This is not a fix for general driver/KFD stalls. ### Why the host wait does not wait for an unsubmitted consumer The queue condition is `cp < kp + P`; for a reused slot `cp >= P`, so its prior batch `cp - P < kp`. The consumer records `freed[half]` before incrementing `kp` and then calls `copy_ahead`. The event being waited on has therefore already been submitted. That invariant still holds at the current insertion point on v1.1.34 / `249f9a8`. ### Current-base validation - Clean Release HIP/gfx1201 `maya-ds4` and `ds4_hip_copy_wait_test` builds; executable help smoke passed. - **512 streamed batches independently checked on two R9700s**, using the actual production wait helper. Two nonblocking streams, a four-part ring, off/on/on/off arms, changing/non-power-of-two lengths, full guards and untouched-tail checks. Both modes exactly match an independent integer CPU reference and each other. - HIP API mapping and `git diff --check` passed. The existing serving process was not replaced. - This is a single-device ring-ordering test run on each card, not a new full-model or multi-GPU peer validation. CUDA/Windows/other AMD cards were not hardware-tested. ### Historical timing scope The earlier model test used two R9700s plus a 9070 XT, TP2/split36/4, 256K context, fixed expert residency/profile, and the earlier FMA16/packed-host/predecode/pruning stack. Warm 2048-token prefill used six balanced blocks / 24 observations: all blocks positive, mean latency reduction **0.8796%**, block-based 95% interval **0.7483–1.0108%**. Median 7518.923 → 7458.083 ms. Cold results were inconclusive; one decode pair established no speedup. Full cold/warm/repeat logits and 80 greedy tokens matched independent references, with zero cache moves and process swap in timing trials. [Original fork PR #13 and raw protocol/results](https://github.com/LostVector/project-maya/pull/13). Those timings are evidence for the option, **not measurements of this current-upstream port**. Current batching/staging and surrounding kernels have evolved. A representative same-binary model comparison, including normal caching and multi-GPU execution, remains before any default recommendation. Documentation and the standalone reproducer are included. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:27:31 +07:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mw00/project-maya#617
No description provided.