[PR #245] [MERGED] HIP: experimental gfx908 (Instinct MI100, wave64) support #422

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/245
Author: @nsaxploit
Created: 10/17/2026
Status: ✅ Merged
Merged: 10/21/2026
Merged by: @mw00

Base: main ← Head: hip-gfx908-wave64


📝 Commits (1)

  • 54b7bf3 HIP: experimental gfx908 (wave64) support via the hip_compat half-wavefront layer

📊 Changes

7 files changed (+94 additions, -11 deletions)

View changed files

📝 cmake/hip_backend.cmake (+17 -2)
📝 include/strata/hip_compat/cuda_runtime.h (+25 -1)
📝 include/strata/hip_compat/intrinsics.hpp (+32 -1)
📝 maya.py (+3 -1)
📝 src/core/device.cu (+7 -2)
📝 tests/hip/glm_prefill_attention.cpp (+6 -2)
📝 tests/hip/intrinsics.cpp (+4 -2)

📄 Description

Experimental gfx908 (AMD Instinct MI100, CDNA1, wave64) support for the HIP backend, plus the small >2-GPU maya.py change requested in #229 — against v1.1.15.

What

Every kernel stays written for a 32-lane warp: on gfx908 a CUDA warp becomes the logical 32-lane half of the 64-lane wavefront (the approach inherited from Strata's experimental gfx906/908 layer), so arithmetic, lane mapping and reduction order match wave32. Nothing in the kernel sources changes — the mapping lives entirely in the force-included hip_compat layer, with the gfx908 v_dot4_i32_i8 branch for __dp4a.

Per request 1: wave32 builds compile exactly as today

All wave64 behaviour sits behind one new define, STRATA_HIP_WAVE64, which cmake/hip_backend.cmake sets only when a wave64 arch (currently gfx908) appears in CMAKE_HIP_ARCHITECTURES, and which reaches every CXX+HIP TU through the same INTERFACE definition channel as STRATA_HIP_ARCHS:

  • HIP_DISABLE_WARP_SYNC_BUILTINS (before hip_runtime.h)
  • coherent mapped host allocs (hipHostMallocCoherent on hipHostMallocMapped) — the wave64-only cudaHostAlloc overloads; the #else restores the previous #define cudaHostAlloc hipHostMalloc
  • wavefront-scope __syncwarp fences (wave32 #else = the previous HIP_VERSION_MAJOR < 7 + workgroup-scope code verbatim)
  • ballot per-half shift (__ballot(p) >> (__lane_id() & 32), shift is 0 on wave32 — wave32 keeps the plain cast)
  • __nanosleep scaling (wave32 keeps s_sleep(1))

So the mapped-host and fence paths that the Strix Halo / RDNA / APU cards lean on are untouched on wave32 — for your Radeon 8065S check, a wave32 build preprocesses to the same code as main. gfx906 / MI50: it fits the same layer (wave64, v_dot4_i32_i8 exists on CDNA1's gfx906 sibling too) but is not in the arch list yet — if the owner in #193 wants it, adding one word to _strata_hip_wave64 and a dp4a branch is all it takes; happy to do that in a follow-up or here.

Per request 2: >2 GPUs kept small

One maya.py hunk (separate commit): --gpus on the HIP path accepts 1..MAX_GPUS distinct indices instead of exactly two — the engine's layer split has always supported up to 16 parts. It overlaps #183 (@izabera); whichever lands second rebases.

Files (7)

file what changed
cmake/hip_backend.cmake gfx908 wave64 arch list + configure status line, STRATA_HIP_WAVE64 detection, the gated INTERFACE define
include/strata/hip_compat/cuda_runtime.h warp-sync builtin disable + coherent mapped cudaHostAlloc, both behind #ifdef STRATA_HIP_WAVE64
include/strata/hip_compat/intrinsics.hpp wavefront-scope syncwarp, per-half ballot, sleep scaling — gated; CDNA sdot4 branch for dp4a (arch-gated as the gfx1030 one is)
src/core/device.cu arch_problem() accepts warpSize 64 when the binary was compiled for that exact arch
tests/hip/intrinsics.cpp probe accepts wave32 or wave64
tests/hip/glm_prefill_attention.cpp skip the rocWMMA f16q phase on cards without WMMA (see note below)
maya.py HIP_ARCHS_WAVE64 = ("gfx908",) tier in the usable list, archs line HIP_ARCHS + unvalidated + wave64 (wave32 setups get the exact same list as today) — commit 1; >2-GPU --gpus — commit 2

Note on tests/hip/glm_prefill_attention.cpp (pre-existing gap, not wave64-specific): the test's rocWMMA f16q phase called mla_attn_f16q unconditionally, but on any arch outside gfx11/gfx12 that kernel's device pass compiles to a trap (STRATA_ROCWMMA 0 — rocWMMA's config.hpp only knows gfx11/gfx12), so the phase hard-failed on gfx908 … and would have on gfx1030 too. The engine itself never takes it: glm_prefill.cu's mla_attn_path() returns F32 there (and that is the kernel measured below). The phase now skips with the same guard mla_attn_path() uses — the sibling wmma2 phase already skipped like this.

Hardware & numbers

4× AMD Instinct MI100 32 GB (gfx908), EPYC 7402, 251.6 GB RAM, Debian 13, ROCm 7.2.4; Maya-S24, context 262144, --kv-streaming on, 100% of routed experts in VRAM (12384/15040), CPU lane off.

From ./maya.sh --bench on this branch (v1.1.15 + the PR, gated build):

  • decode: mean 63.2 tok/s over 3 answers of 256 tokens (greedy, thinking off): 63.9 / 60.2 / 65.5
  • prefill: 456 tok/s @ 2048 tokens, 494 tok/s @ 8192 tokens
  • split [0,12)/[12,24)/[24,36)/[36,45) across the four cards, one 64 KB host hop per boundary per token, vram hit 100.00%

For comparison, the v1.1.12 numbers from #229 (same box, ungated local diff): 58.5 tok/s decode, 455 / 493 prefill — v1.1.15's kernel work picks up the rest.

Parity results

HIP_VISIBLE_DEVICES=0 ctest --test-dir build-hip --output-on-failure --timeout 60 with the parity set — rebuilt from this branch's final (gated) code:

 1/14 Test #10: hip_expert_cache_staging .........   Passed    0.25 sec
 2/14 Test #12: hip_intrinsics ...................   Passed    0.26 sec
 3/14 Test #13: hip_handoff ......................   Passed    0.33 sec
 4/14 Test #14: hip_glm_handoff ..................   Passed    0.36 sec
 5/14 Test #15: hip_glm_prefill_attention ........   Passed    0.27 sec
 6/14 Test #21: iq1_s_parity .....................   Passed    0.32 sec
 7/14 Test #24: glm_hc_parity ....................   Passed    0.33 sec
 8/14 Test #26: glm_kda_parity ...................   Passed    0.28 sec
 9/14 Test #27: glm_ffn_parity ...................   Passed    0.26 sec
10/14 Test #28: glm_dsa_parity ...................   Passed    0.24 sec
11/14 Test #30: glm_layer_parity .................   Passed    0.29 sec
12/14 Test #31: glm_model_test ...................   Passed    0.73 sec
13/14 Test #54: hip_device_selftest ..............   Passed    0.24 sec
14/14 Test #63: hip_prefill_mmq_parity ...........   Passed    0.98 sec

100% tests passed, 0 tests failed out of 14
Total Test time (real) = 5.16 sec

HIP_VISIBLE_DEVICES=0 build-hip/hip_expert_kernel_bench --parity-only --sweep:

GPU 0: AMD Instinct MI100 (gfx908:sramecc+:xnack-), free=32720.0 MiB, graph_calls=60 rounds=7 (median)
fixture gu=16 down=22 experts=8 n_embd=4096 n_ff=2048 pools=1 weights=53.5 MiB shared=off
parity gu16 signs case0             max_abs=0.000e+00 rel_L2=0.000e+00 bit_identical=yes PASS
...
parity down22 production case5      max_abs=0.000e+00 rel_L2=0.000e+00 bit_identical=yes PASS
hip_expert_kernel_bench: PASS

621/621 sweep cases PASS, 0 failures, every case bit_identical=yes (max_abs=0.000e+00) — the gu16/gu22 × down22 expert kernels through the half-wavefront mapping reproduce the reference bit-for-bit.

GPU-free checks as well: tools/check_hip_compat.py clean, tools.test_maya_hip + tools.test_hip_archs all green (the archs asserts still hold).

Build & run (ROCm 7)

cmake -S . -B build-hip -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_PREFIX_PATH=/opt/rocm-7.2.4 \
  -DCMAKE_HIP_COMPILER=/opt/rocm-7.2.4/llvm/bin/clang++ \
  -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF \
  -DSTRATA_PREFILL_MMQ=ON -DSTRATA_NATIVE_EXPERTS=ON \
  -DSTRATA_BUILD_TESTS=ON \
  -DSTRATA_GGML_DIR=$PWD/third_party/llama.cpp \
  '-DCMAKE_HIP_ARCHITECTURES=gfx908'
cmake --build build-hip -j "$(nproc)"
export LD_LIBRARY_PATH=/opt/rocm/lib
HIP_VISIBLE_DEVICES=0 ctest --test-dir build-hip --output-on-failure --timeout 60 \
  -R '^(glm_(hc|kda|ffn|dsa|layer)_parity|glm_model_test|hip_intrinsics|hip_(glm_handoff|glm_prefill_attention|handoff|device_selftest|prefill_mmq_parity|expert_cache_staging)|iq1_s_parity)$'
HIP_VISIBLE_DEVICES=0 build-hip/hip_expert_kernel_bench --parity-only --sweep

With gfx908 accepted, ./maya.sh --backend hip --check lists the cards as usable and the normal setup path passes these flags itself.

Status: experimental — validated on this 4× MI100 box only (build, parity suite, benchmark, serving at 262144 context). No MI50/other-wave64 coverage yet; gfx906 offered above. Credit: the half-wavefront layer descends from Strata's experimental gfx906/908 work; thanks to @mw00 for the gating review request that made this diff wave32-safe.

Closes #229 (report)


🔄 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/245 **Author:** [@nsaxploit](https://github.com/nsaxploit) **Created:** 10/17/2026 **Status:** ✅ Merged **Merged:** 10/21/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `hip-gfx908-wave64` --- ### 📝 Commits (1) - [`54b7bf3`](https://github.com/mw00/project-maya/commit/54b7bf3384c0f6466592479d187306d019d68fec) HIP: experimental gfx908 (wave64) support via the hip_compat half-wavefront layer ### 📊 Changes **7 files changed** (+94 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `cmake/hip_backend.cmake` (+17 -2) 📝 `include/strata/hip_compat/cuda_runtime.h` (+25 -1) 📝 `include/strata/hip_compat/intrinsics.hpp` (+32 -1) 📝 `maya.py` (+3 -1) 📝 `src/core/device.cu` (+7 -2) 📝 `tests/hip/glm_prefill_attention.cpp` (+6 -2) 📝 `tests/hip/intrinsics.cpp` (+4 -2) </details> ### 📄 Description Experimental **gfx908 (AMD Instinct MI100, CDNA1, wave64)** support for the HIP backend, plus the small >2-GPU `maya.py` change requested in #229 — against **v1.1.15**. ## What Every kernel stays written for a 32-lane warp: on gfx908 a CUDA warp becomes the *logical 32-lane half* of the 64-lane wavefront (the approach inherited from Strata's experimental gfx906/908 layer), so arithmetic, lane mapping and reduction order match wave32. Nothing in the kernel sources changes — the mapping lives entirely in the force-included `hip_compat` layer, with the gfx908 `v_dot4_i32_i8` branch for `__dp4a`. ## Per request 1: wave32 builds compile exactly as today All wave64 behaviour sits behind **one new define, `STRATA_HIP_WAVE64`**, which `cmake/hip_backend.cmake` sets only when a wave64 arch (currently `gfx908`) appears in `CMAKE_HIP_ARCHITECTURES`, and which reaches every CXX+HIP TU through the same INTERFACE definition channel as `STRATA_HIP_ARCHS`: - `HIP_DISABLE_WARP_SYNC_BUILTINS` (before `hip_runtime.h`) - coherent mapped host allocs (`hipHostMallocCoherent` on `hipHostMallocMapped`) — the wave64-only `cudaHostAlloc` overloads; the `#else` restores the previous `#define cudaHostAlloc hipHostMalloc` - wavefront-scope `__syncwarp` fences (wave32 `#else` = the previous `HIP_VERSION_MAJOR < 7` + workgroup-scope code verbatim) - ballot per-half shift (`__ballot(p) >> (__lane_id() & 32)`, shift is 0 on wave32 — wave32 keeps the plain cast) - `__nanosleep` scaling (wave32 keeps `s_sleep(1)`) So the mapped-host and fence paths that the Strix Halo / RDNA / APU cards lean on are untouched on wave32 — for your Radeon 8065S check, a wave32 build preprocesses to the same code as `main`. **gfx906 / MI50**: it fits the same layer (wave64, `v_dot4_i32_i8` exists on CDNA1's gfx906 sibling too) but is not in the arch list yet — if the owner in #193 wants it, adding one word to `_strata_hip_wave64` and a `dp4a` branch is all it takes; happy to do that in a follow-up or here. ## Per request 2: >2 GPUs kept small One `maya.py` hunk (separate commit): `--gpus` on the HIP path accepts `1..MAX_GPUS` distinct indices instead of exactly two — the engine's layer split has always supported up to 16 parts. It overlaps #183 (@izabera); whichever lands second rebases. ## Files (7) | file | what changed | |---|---| | `cmake/hip_backend.cmake` | `gfx908` wave64 arch list + configure status line, `STRATA_HIP_WAVE64` detection, the gated INTERFACE define | | `include/strata/hip_compat/cuda_runtime.h` | warp-sync builtin disable + coherent mapped `cudaHostAlloc`, both behind `#ifdef STRATA_HIP_WAVE64` | | `include/strata/hip_compat/intrinsics.hpp` | wavefront-scope `syncwarp`, per-half ballot, sleep scaling — gated; CDNA `sdot4` branch for `dp4a` (arch-gated as the gfx1030 one is) | | `src/core/device.cu` | `arch_problem()` accepts `warpSize 64` when the binary was compiled for that exact arch | | `tests/hip/intrinsics.cpp` | probe accepts wave32 **or** wave64 | | `tests/hip/glm_prefill_attention.cpp` | skip the rocWMMA **f16q** phase on cards without WMMA (see note below) | | `maya.py` | `HIP_ARCHS_WAVE64 = ("gfx908",)` tier in the usable list, archs line `HIP_ARCHS + unvalidated + wave64` (wave32 setups get the exact same list as today) — commit 1; >2-GPU `--gpus` — commit 2 | **Note on `tests/hip/glm_prefill_attention.cpp`** (pre-existing gap, not wave64-specific): the test's rocWMMA f16q phase called `mla_attn_f16q` unconditionally, but on any arch outside gfx11/gfx12 that kernel's device pass compiles to a trap (`STRATA_ROCWMMA 0` — rocWMMA's `config.hpp` only knows gfx11/gfx12), so the phase hard-failed on gfx908 … and would have on gfx1030 too. The engine itself never takes it: `glm_prefill.cu`'s `mla_attn_path()` returns `F32` there (and that is the kernel measured below). The phase now skips with the same guard `mla_attn_path()` uses — the sibling wmma2 phase already skipped like this. ## Hardware & numbers 4× **AMD Instinct MI100 32 GB** (gfx908), EPYC 7402, 251.6 GB RAM, Debian 13, **ROCm 7.2.4**; Maya-S24, context **262144**, `--kv-streaming on`, 100% of routed experts in VRAM (12384/15040), CPU lane off. From `./maya.sh --bench` on **this branch** (v1.1.15 + the PR, gated build): - **decode: mean 63.2 tok/s** over 3 answers of 256 tokens (greedy, thinking off): 63.9 / 60.2 / 65.5 - **prefill: 456 tok/s @ 2048 tokens, 494 tok/s @ 8192 tokens** - split `[0,12)/[12,24)/[24,36)/[36,45)` across the four cards, one 64 KB host hop per boundary per token, `vram hit 100.00%` For comparison, the v1.1.12 numbers from #229 (same box, ungated local diff): 58.5 tok/s decode, 455 / 493 prefill — v1.1.15's kernel work picks up the rest. ## Parity results `HIP_VISIBLE_DEVICES=0 ctest --test-dir build-hip --output-on-failure --timeout 60` with the parity set — rebuilt from this branch's final (gated) code: ``` 1/14 Test #10: hip_expert_cache_staging ......... Passed 0.25 sec 2/14 Test #12: hip_intrinsics ................... Passed 0.26 sec 3/14 Test #13: hip_handoff ...................... Passed 0.33 sec 4/14 Test #14: hip_glm_handoff .................. Passed 0.36 sec 5/14 Test #15: hip_glm_prefill_attention ........ Passed 0.27 sec 6/14 Test #21: iq1_s_parity ..................... Passed 0.32 sec 7/14 Test #24: glm_hc_parity .................... Passed 0.33 sec 8/14 Test #26: glm_kda_parity ................... Passed 0.28 sec 9/14 Test #27: glm_ffn_parity ................... Passed 0.26 sec 10/14 Test #28: glm_dsa_parity ................... Passed 0.24 sec 11/14 Test #30: glm_layer_parity ................. Passed 0.29 sec 12/14 Test #31: glm_model_test ................... Passed 0.73 sec 13/14 Test #54: hip_device_selftest .............. Passed 0.24 sec 14/14 Test #63: hip_prefill_mmq_parity ........... Passed 0.98 sec 100% tests passed, 0 tests failed out of 14 Total Test time (real) = 5.16 sec ``` `HIP_VISIBLE_DEVICES=0 build-hip/hip_expert_kernel_bench --parity-only --sweep`: ``` GPU 0: AMD Instinct MI100 (gfx908:sramecc+:xnack-), free=32720.0 MiB, graph_calls=60 rounds=7 (median) fixture gu=16 down=22 experts=8 n_embd=4096 n_ff=2048 pools=1 weights=53.5 MiB shared=off parity gu16 signs case0 max_abs=0.000e+00 rel_L2=0.000e+00 bit_identical=yes PASS ... parity down22 production case5 max_abs=0.000e+00 rel_L2=0.000e+00 bit_identical=yes PASS hip_expert_kernel_bench: PASS ``` **621/621 sweep cases PASS, 0 failures, every case `bit_identical=yes` (`max_abs=0.000e+00`)** — the gu16/gu22 × down22 expert kernels through the half-wavefront mapping reproduce the reference bit-for-bit. GPU-free checks as well: `tools/check_hip_compat.py` clean, `tools.test_maya_hip` + `tools.test_hip_archs` all green (the archs asserts still hold). ## Build & run (ROCm 7) ```sh cmake -S . -B build-hip -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_PREFIX_PATH=/opt/rocm-7.2.4 \ -DCMAKE_HIP_COMPILER=/opt/rocm-7.2.4/llvm/bin/clang++ \ -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF \ -DSTRATA_PREFILL_MMQ=ON -DSTRATA_NATIVE_EXPERTS=ON \ -DSTRATA_BUILD_TESTS=ON \ -DSTRATA_GGML_DIR=$PWD/third_party/llama.cpp \ '-DCMAKE_HIP_ARCHITECTURES=gfx908' cmake --build build-hip -j "$(nproc)" export LD_LIBRARY_PATH=/opt/rocm/lib HIP_VISIBLE_DEVICES=0 ctest --test-dir build-hip --output-on-failure --timeout 60 \ -R '^(glm_(hc|kda|ffn|dsa|layer)_parity|glm_model_test|hip_intrinsics|hip_(glm_handoff|glm_prefill_attention|handoff|device_selftest|prefill_mmq_parity|expert_cache_staging)|iq1_s_parity)$' HIP_VISIBLE_DEVICES=0 build-hip/hip_expert_kernel_bench --parity-only --sweep ``` With `gfx908` accepted, `./maya.sh --backend hip --check` lists the cards as usable and the normal setup path passes these flags itself. **Status:** experimental — validated on this 4× MI100 box only (build, parity suite, benchmark, serving at 262144 context). No MI50/other-wave64 coverage yet; gfx906 offered above. Credit: the half-wavefront layer descends from Strata's experimental gfx906/908 work; thanks to @mw00 for the gating review request that made this diff wave32-safe. Closes #229 (report) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:25:13 +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#422
No description provided.