[PR #3553] [Engine] let a HIP helper read pinned expert rows in place #4686

Open
opened 2026-11-07 15:38:20 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3553
Author: @sakuumomo
Created: 10/21/2026
Status: 🔄 Open

Base: main ← Head: pr/engine-hybrid-apu-pin


📝 Commits (10+)

  • e05bf4a Add an opt-in build that runs CUDA and HIP in one process
  • f8e0e29 A hybrid build follows 0.2.2's HIP rules for a HIP primary: the early PLE flag and side-thread launch rule, the queue priming, and the integrated-GPU cache reserve
  • b17e8dc docs: the hybrid CUDA+HIP build (opt-in), its devices and its probe command
  • cf3d713 A hybrid build follows 0.2.3's drafter rules for a HIP primary too: the dflash2 stream priority and fork defaults, the Strix Halo window cap and the 12 GB card line
  • bf40f37 hip_compat: cover the CUDA usages main's drafter brings to the HIP copy
  • 8843b4e hip_compat: drop grid_constant on the HIP copy
  • 0d8075f hybrid: do not glob the dsv41 engine path into strata
  • 256cd07 hybrid: keep the moe_ws family out of the HIP glob - upstream #3752 (GP100 weight-stationary experts) landed with the 0.2.7 rebase, after this file was written. The kernels are pure PTX (prmt/mad.wide/f16x2 asm): on the CUDA side they are strata_mmq sources only under STRATA_EXPERIMENTAL_SM60, gated at run time to machines whose every GPU is cc 6.0. A hip-src copy of them fails on 'invalid output constraint =f' / 'invalid instruction' in the gfx1150 pass, and could never dispatch on an AMD device - so they belong beside the gdn_chunk/mmq_nvfp4/mmq_kq_lib exclusions. moko flavor build was the witness: moe_ws_down/gu_iq2/gu_iq3 were the only FAILED targets.
  • 1b8fa69 hybrid: speak CUDA 13's plain runtime API names
  • 1b97058 hybrid(cmake): keep upstream 0.2.12's NVIDIA-only trees out of the HIP glob

📊 Changes

28 files changed (+2850 additions, -62 deletions)

View changed files

📝 CMakeLists.txt (+36 -5)
➕ cmake/hip-host-tramp.py (+99 -0)
➕ cmake/hybrid.cmake (+406 -0)
➕ cmake/prefix-hip.py (+97 -0)
📝 docs/AMD_HIP.md (+25 -1)
📝 docs/MULTI_GPU.md (+2 -1)
📝 include/strata/core/device.hpp (+3 -4)
📝 include/strata/core/expert_cache.hpp (+1 -1)
📝 include/strata/core/expert_source.hpp (+14 -0)
📝 include/strata/core/remote_experts.hpp (+22 -1)
📝 include/strata/hip_compat/cublas_v2.h (+4 -0)
📝 include/strata/hip_compat/cuda_runtime.h (+9 -0)
➕ include/strata/hip_compat/hybrid_ordinal.h (+53 -0)
📝 src/core/device.cu (+88 -3)
📝 src/core/device_main.cpp (+9 -0)
📝 src/core/dflash2.cpp (+16 -0)
📝 src/core/expert_cache.cpp (+33 -14)
📝 src/core/expert_source.cpp (+66 -1)
➕ src/core/hip_api.h (+103 -0)
➕ src/core/hybrid_hip.cpp (+336 -0)

...and 8 more files

📄 Description

Depends on #3551.

Merge #3551 first. This branch is that pull request plus one commit, 604b2cf3. Until #3551 is merged, the file list here includes the hybrid build as well. The change that belongs to this pull request is that last commit only: 161 lines in five files (git diff 10fdcb31..604b2cf3).

A merge commit of #3551 leaves this pull request showing only 604b2cf3. A squash of #3551 keeps the hybrid diff here, and this branch then needs a rebase onto that squash.

Problem and result: With STRATA_HYBRID, a pinned expert the helper can see was still the primary's row, so the primary copied it over PCIe. That row is now the helper's, and the primary does not copy it. The first helper claims the row, so a second HIP device does not launch the same rows. holds() stays cache membership. Decode uses claims(), which is the cache or a pin that device can read. With STRATA_HYBRID off, the previous holds() body and the previous cache lookup stay.

Related discussion: #3551, which this change needs. No separate issue.

Approach: claims() is compiled only with STRATA_HYBRID. A failed map, a 64-byte miss, a lost exchange, a soft commit, or an unregistered pin leaves the row on the CPU. The one-token path and the multi-token path both set the owned kind from owns() after a successful begin().

Validation:
Passed: four compiles of 604b2cf3 on Linux x86-64. STRATA_BUILD_TESTS=OFF and STRATA_PORTABLE=ON on the Nix builds.
HIP, STRATA_HYBRID off: STRATA_ENABLE_HIP=ON, STRATA_ENABLE_CUDA=OFF, CMAKE_HIP_ARCHITECTURES=gfx1030, STRATA_PREFILL_MMQ=ON, HIP 7.2.3. CMake reported "Strata: HIP enabled, arch gfx1030" and did not report a hybrid build. Output /nix/store/zm4ln1bi1v0ahalc4y1wzi5i1nzhifhy-strata-hip-0.2.1 (strata and strata-device).
CUDA, STRATA_HYBRID off: STRATA_ENABLE_CUDA=ON, STRATA_ENABLE_HIP=OFF, CMAKE_CUDA_ARCHITECTURES=89-real, STRATA_PREFILL_MMQ=OFF, CUDA 12.9.86, gcc 14.4.0. CMake reported "Strata: CUDA enabled, arch 89-real" and did not report a hybrid build. Output /nix/store/qv2y92cv0q6csg5v9mh9wgq9dipq4ygg-strata-cuda-0.2.1 (strata and strata-device).
STRATA_HYBRID=ON: the same CUDA flags, plus HIP gfx1150. CMake reported CUDA arch 89-real, "Strata hybrid: gfx1150", and that hipBLASLt solution-table dispatch is available. Output /nix/store/xwbnkgp4jg00cisqn2fw19nr5rqf9z9p-strata-hybrid-0.2.1 (strata and strata-device).
SYCL: the strata-sycl-dev image from sycl/tools/Dockerfile (oneAPI 2026.1.0, no AOT device). sycl/tools/build.sh strata printed BUILD EXIT 0 and errors: 0. Binary /tmp/strata-wt-pin/build-sycl/strata. The SYCL port compiles its own copies of the five files in this commit, so this build checks the shared headers this commit inherits from #3551.
The author ran it on two Linux machines and reports that both function as intended. The laptop has an RTX 4060 and a Radeon 890M and serves with STRATA_HYBRID, which is the build that compiles this rule. The desktop has an RX 6800 and an RX 6900 XT and serves with the HIP build, which keeps the previous cache lookup. No command log or timing was attached to that report.
Failed: none observed.
Not run: a trace showing a pinned row stayed off the PCIe copy. A SYCL process on a device.

Limits: The ownership rule is compiled only into the hybrid build. A default CUDA, HIP, or SYCL build keeps the previous cache lookup.

Changes since the last update (2026-10-27)

  • Both branches in this stack were rebased onto upstream main (0.2.6, 4b9e05a2); content re-landed verbatim. The dependency note above now reads: this branch is the rebased #3551 branch (b32dee9c) plus one commit — the diff belonging to this pull request is b32dee9c..86c072bb. The 10fdcb31/604b2cf3 hashes in the original text are the pre-rebase lineage.
  • Equivalent content (the same rebased delta on the owner's deploy branch nixos, pin 3032afd8) serves daily on both machines: the laptop runs the hybrid build, which compiles this ownership rule; the desktop runs HIP-only, keeping the previous cache lookup.
  • Serve-side follow-up PRs in the same stack: #4306 (session ladder) and #4307 (unload that works). Neither touches this diff.

Changes since the last update (2026-10-30)

  • Re-restacked on the rebased #3551 branch, onto upstream v0.2.8 (870aedd9). This branch is the rebased #3551 branch (5fa28548) plus one commit - the diff owned by this pull request is 5fa28548..9c09a1d2, content-identical to 10fdcb31..604b2cf3 (161 lines in five files). New tip 9c09a1d2.
  • The rebuilt 0.2.8 deploy lineage passes every owner gate; the CUDA+HIP hybrid flavor build - the build that compiles this ownership rule - and the HIP-only build are green with installCheck.

Changes since the last update (2026-11-07)

  • Re-restacked on the rebased #3551 branch, onto upstream v0.2.12 (123bad4a). This branch is the rebased #3551 branch (1b97058c) plus one commit - the diff owned by this pull request is 1b97058c..3fb0726c, content-identical to 10fdcb31..604b2cf3 and range-diff-equal to the pre-glob-fix restack c201b3bb..3502c77d (167 insertions, 2 deletions, five files). New tip 3fb0726c.
  • The 0.2.12 deploy lineage (nixos @ c3e4cdc4) passes the owner gates; the CUDA+HIP hybrid flavor build - the build that compiles this ownership rule - and the HIP-only build are green with installCheck. metal-link and title jobs are green on the new head; the PR is mergeable against current main.

Branch commits were re-signed (GPG ed25519) on 2026-11-07; trees are unchanged from the validated work. The pre-rebase tip 9c09a1d2 stays fetchable as an ancestor of the train tag pin-f6f00908.

Dependencies: #3551 — this branch is that branch plus its one commit; the diff owned by this pull request is 1b97058c..3fb0726c.


🔄 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/Niko1221/Strata/pull/3553 **Author:** [@sakuumomo](https://github.com/sakuumomo) **Created:** 10/21/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/engine-hybrid-apu-pin` --- ### 📝 Commits (10+) - [`e05bf4a`](https://github.com/Niko1221/Strata/commit/e05bf4a9ef929944dbd2df41fa7a8a072a36f3ec) Add an opt-in build that runs CUDA and HIP in one process - [`f8e0e29`](https://github.com/Niko1221/Strata/commit/f8e0e292c72c3be3223cf083a2d018c393d3da8f) A hybrid build follows 0.2.2's HIP rules for a HIP primary: the early PLE flag and side-thread launch rule, the queue priming, and the integrated-GPU cache reserve - [`b17e8dc`](https://github.com/Niko1221/Strata/commit/b17e8dc18911d4212ceeeeef69c430e7fb58291f) docs: the hybrid CUDA+HIP build (opt-in), its devices and its probe command - [`cf3d713`](https://github.com/Niko1221/Strata/commit/cf3d7135343d443c4d5a1e452368d6231421403e) A hybrid build follows 0.2.3's drafter rules for a HIP primary too: the dflash2 stream priority and fork defaults, the Strix Halo window cap and the 12 GB card line - [`bf40f37`](https://github.com/Niko1221/Strata/commit/bf40f37ec536d0813fbc3df483bf3d63afac00ca) hip_compat: cover the CUDA usages main's drafter brings to the HIP copy - [`8843b4e`](https://github.com/Niko1221/Strata/commit/8843b4ef28911e3df670650cac7918899957b388) hip_compat: drop __grid_constant__ on the HIP copy - [`0d8075f`](https://github.com/Niko1221/Strata/commit/0d8075f9e84b495952a37f0eb967afdf8fc7ee63) hybrid: do not glob the dsv41 engine path into strata - [`256cd07`](https://github.com/Niko1221/Strata/commit/256cd076eb332f76970f7f6a895c8bd90d786683) hybrid: keep the moe_ws family out of the HIP glob - upstream #3752 (GP100 weight-stationary experts) landed with the 0.2.7 rebase, after this file was written. The kernels are pure PTX (prmt/mad.wide/f16x2 asm): on the CUDA side they are strata_mmq sources only under STRATA_EXPERIMENTAL_SM60, gated at run time to machines whose every GPU is cc 6.0. A hip-src copy of them fails on 'invalid output constraint =f' / 'invalid instruction' in the gfx1150 pass, and could never dispatch on an AMD device - so they belong beside the gdn_chunk/mmq_nvfp4/mmq_kq_lib exclusions. moko flavor build was the witness: moe_ws_down/gu_iq2/gu_iq3 were the only FAILED targets. - [`1b8fa69`](https://github.com/Niko1221/Strata/commit/1b8fa69a751a25ef00a1355e5d5dcc45ee38124c) hybrid: speak CUDA 13's plain runtime API names - [`1b97058`](https://github.com/Niko1221/Strata/commit/1b97058cb4cd508e9e4768865272e87c9b499b08) hybrid(cmake): keep upstream 0.2.12's NVIDIA-only trees out of the HIP glob ### 📊 Changes **28 files changed** (+2850 additions, -62 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+36 -5) ➕ `cmake/hip-host-tramp.py` (+99 -0) ➕ `cmake/hybrid.cmake` (+406 -0) ➕ `cmake/prefix-hip.py` (+97 -0) 📝 `docs/AMD_HIP.md` (+25 -1) 📝 `docs/MULTI_GPU.md` (+2 -1) 📝 `include/strata/core/device.hpp` (+3 -4) 📝 `include/strata/core/expert_cache.hpp` (+1 -1) 📝 `include/strata/core/expert_source.hpp` (+14 -0) 📝 `include/strata/core/remote_experts.hpp` (+22 -1) 📝 `include/strata/hip_compat/cublas_v2.h` (+4 -0) 📝 `include/strata/hip_compat/cuda_runtime.h` (+9 -0) ➕ `include/strata/hip_compat/hybrid_ordinal.h` (+53 -0) 📝 `src/core/device.cu` (+88 -3) 📝 `src/core/device_main.cpp` (+9 -0) 📝 `src/core/dflash2.cpp` (+16 -0) 📝 `src/core/expert_cache.cpp` (+33 -14) 📝 `src/core/expert_source.cpp` (+66 -1) ➕ `src/core/hip_api.h` (+103 -0) ➕ `src/core/hybrid_hip.cpp` (+336 -0) _...and 8 more files_ </details> ### 📄 Description Depends on #3551. Merge #3551 first. This branch is that pull request plus one commit, `604b2cf3`. Until #3551 is merged, the file list here includes the hybrid build as well. The change that belongs to this pull request is that last commit only: 161 lines in five files (`git diff 10fdcb31..604b2cf3`). A merge commit of #3551 leaves this pull request showing only `604b2cf3`. A squash of #3551 keeps the hybrid diff here, and this branch then needs a rebase onto that squash. Problem and result: With `STRATA_HYBRID`, a pinned expert the helper can see was still the primary's row, so the primary copied it over PCIe. That row is now the helper's, and the primary does not copy it. The first helper claims the row, so a second HIP device does not launch the same rows. `holds()` stays cache membership. Decode uses `claims()`, which is the cache or a pin that device can read. With `STRATA_HYBRID` off, the previous `holds()` body and the previous cache lookup stay. Related discussion: #3551, which this change needs. No separate issue. Approach: `claims()` is compiled only with `STRATA_HYBRID`. A failed map, a 64-byte miss, a lost exchange, a soft commit, or an unregistered pin leaves the row on the CPU. The one-token path and the multi-token path both set the owned kind from `owns()` after a successful `begin()`. Validation: Passed: four compiles of `604b2cf3` on Linux x86-64. `STRATA_BUILD_TESTS=OFF` and `STRATA_PORTABLE=ON` on the Nix builds. HIP, `STRATA_HYBRID` off: `STRATA_ENABLE_HIP=ON`, `STRATA_ENABLE_CUDA=OFF`, `CMAKE_HIP_ARCHITECTURES=gfx1030`, `STRATA_PREFILL_MMQ=ON`, HIP 7.2.3. CMake reported "Strata: HIP enabled, arch gfx1030" and did not report a hybrid build. Output `/nix/store/zm4ln1bi1v0ahalc4y1wzi5i1nzhifhy-strata-hip-0.2.1` (`strata` and `strata-device`). CUDA, `STRATA_HYBRID` off: `STRATA_ENABLE_CUDA=ON`, `STRATA_ENABLE_HIP=OFF`, `CMAKE_CUDA_ARCHITECTURES=89-real`, `STRATA_PREFILL_MMQ=OFF`, CUDA 12.9.86, gcc 14.4.0. CMake reported "Strata: CUDA enabled, arch 89-real" and did not report a hybrid build. Output `/nix/store/qv2y92cv0q6csg5v9mh9wgq9dipq4ygg-strata-cuda-0.2.1` (`strata` and `strata-device`). `STRATA_HYBRID=ON`: the same CUDA flags, plus HIP gfx1150. CMake reported CUDA arch 89-real, "Strata hybrid: gfx1150", and that hipBLASLt solution-table dispatch is available. Output `/nix/store/xwbnkgp4jg00cisqn2fw19nr5rqf9z9p-strata-hybrid-0.2.1` (`strata` and `strata-device`). SYCL: the `strata-sycl-dev` image from `sycl/tools/Dockerfile` (oneAPI 2026.1.0, no AOT device). `sycl/tools/build.sh strata` printed `BUILD EXIT 0` and `errors: 0`. Binary `/tmp/strata-wt-pin/build-sycl/strata`. The SYCL port compiles its own copies of the five files in this commit, so this build checks the shared headers this commit inherits from #3551. The author ran it on two Linux machines and reports that both function as intended. The laptop has an RTX 4060 and a Radeon 890M and serves with `STRATA_HYBRID`, which is the build that compiles this rule. The desktop has an RX 6800 and an RX 6900 XT and serves with the HIP build, which keeps the previous cache lookup. No command log or timing was attached to that report. Failed: none observed. Not run: a trace showing a pinned row stayed off the PCIe copy. A SYCL process on a device. Limits: The ownership rule is compiled only into the hybrid build. A default CUDA, HIP, or SYCL build keeps the previous cache lookup. ## Changes since the last update (2026-10-27) - Both branches in this stack were rebased onto upstream `main` (0.2.6, `4b9e05a2`); content re-landed verbatim. The dependency note above now reads: this branch is the rebased #3551 branch (`b32dee9c`) plus one commit — the diff belonging to this pull request is `b32dee9c..86c072bb`. The `10fdcb31`/`604b2cf3` hashes in the original text are the pre-rebase lineage. - Equivalent content (the same rebased delta on the owner's deploy branch `nixos`, pin `3032afd8`) serves daily on both machines: the laptop runs the hybrid build, which compiles this ownership rule; the desktop runs HIP-only, keeping the previous cache lookup. - Serve-side follow-up PRs in the same stack: #4306 (session ladder) and #4307 (unload that works). Neither touches this diff. ## Changes since the last update (2026-10-30) - Re-restacked on the rebased #3551 branch, onto upstream `v0.2.8` (`870aedd9`). This branch is the rebased #3551 branch (`5fa28548`) plus one commit - the diff owned by this pull request is `5fa28548..9c09a1d2`, content-identical to `10fdcb31..604b2cf3` (161 lines in five files). New tip `9c09a1d2`. - The rebuilt 0.2.8 deploy lineage passes every owner gate; the CUDA+HIP hybrid flavor build - the build that compiles this ownership rule - and the HIP-only build are green with installCheck. ## Changes since the last update (2026-11-07) - Re-restacked on the rebased #3551 branch, onto upstream `v0.2.12` (`123bad4a`). This branch is the rebased #3551 branch (`1b97058c`) plus one commit - the diff owned by this pull request is `1b97058c..3fb0726c`, content-identical to `10fdcb31..604b2cf3` and range-diff-equal to the pre-glob-fix restack `c201b3bb..3502c77d` (167 insertions, 2 deletions, five files). New tip `3fb0726c`. - The 0.2.12 deploy lineage (`nixos` @ `c3e4cdc4`) passes the owner gates; the CUDA+HIP hybrid flavor build - the build that compiles this ownership rule - and the HIP-only build are green with installCheck. metal-link and title jobs are green on the new head; the PR is mergeable against current `main`. Branch commits were re-signed (GPG ed25519) on 2026-11-07; trees are unchanged from the validated work. The pre-rebase tip `9c09a1d2` stays fetchable as an ancestor of the train tag `pin-f6f00908`. Dependencies: #3551 — this branch is that branch plus its one commit; the diff owned by this pull request is `1b97058c..3fb0726c`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
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
Niko1221/Strata#4686
No description provided.