[PR #5518] [Engine] HIP: alignas(16) int4 staging arrays do not compile (the two sites #778 left) #5491

Open
opened 2026-11-08 02:48:06 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5518
Author: @rwkeyes
Created: 11/7/2026
Status: 🔄 Open

Base: main ← Head: hip/aligned-shared-int4-staging


📝 Commits (1)

  • 98a74cd HIP: the two int4 staging arrays #778 left behind do not compile

📊 Changes

1 file changed (+10 additions, -2 deletions)

View changed files

📝 src/kernels/cuda/iq_kernels.cu (+10 -2)

📄 Description

Problem and result

v0.2.12 does not build for HIP: two expert-decode kernels stage their int4 rows as __shared__ alignas(16) int4,
and HIP clang rejects that placement. This is the same defect #778 fixed for the shared grid buffers — the two
int4 staging arrays were not converted when that fix landed, so those kernels never compile.

Before (146df3c4, ROCm 7.1.1, -DSTRATA_ENABLE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx1100):

src/kernels/cuda/iq_kernels.cu:2591:16: error: 'alignas' attribute cannot be applied to types
 2591 |     __shared__ alignas(16) int4 s_u[ED_NC * 2 * ED_XB];
src/kernels/cuda/iq_kernels.cu:2778:16: error: 'alignas' attribute cannot be applied to types
 2778 |     __shared__ alignas(16) int4 s_u[ED_NC * 2 * ED_HB];
FAILED: CMakeFiles/strata_kernels.dir/src/kernels/cuda/iq_kernels.cu.o

After: both declarations use a STRATA_SHARED_ALIGN16_INT4 macro with the same two forms as the existing
STRATA_SHARED_ALIGN16_U32 (__attribute__((aligned(16))) after the declarator under HIP, alignas(16) before it
otherwise), the object compiles, and the gfx1100 engine builds.

Follow-up to #778 ("iq_kernels: portable aligned shared-memory declaration for gfx1030", closed). That fix
introduced STRATA_SHARED_ALIGN16_U32 and converted the grid buffers; these two int4 sites in the same file were
left with the old declaration. I did not find an open issue covering them, and this is a build failure rather than a
behaviour change, so it goes straight to a PR.

Approach

Ten lines in src/kernels/cuda/iq_kernels.cu, no other file:

  • one macro beside the existing one, with the same #if defined(__HIPCC__) split — the __attribute__ form where
    HIP clang needs it, the alignas form where nvcc with MSVC as host requires it (the reason #778 is split at all);
  • the two declarations become STRATA_SHARED_ALIGN16_INT4(s_u, ...). Same size, same alignment, same layout — this
    changes no arithmetic and no memory footprint.

Nothing else in the tree is touched: no CMake, no other kernel, no version bump.

Validation

Passed:

  • HIP, the changed translation unit, ROCm 7.1.1, gfx1100:
    ninja CMakeFiles/strata_kernels.dir/src/kernels/cuda/iq_kernels.cu.o → object produced (6 534 784 B).
    The same command on the unmodified tag fails with the two errors quoted above.
  • CUDA, the same file (the other branch of the macro), CUDA 12.6, -DCMAKE_CUDA_ARCHITECTURES=89:
    object produced (11 587 504 B) — the nvcc path is unchanged.
  • Full HIP engine build and link, gfx1100: ninja -C build-hip-full -j10 strata → [164/164] Linking HIP executable strata, 0 errors, engine 60 162 624 B, and ./strata --help rc=0 with
    hipv4-amdgcn-amd-amdhsa--gfx1100 in the binary (a real gfx1100 device image, not a CPU fallback). Configure:
    -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_BUILD_TESTS=OFF -DSTRATA_PREFILL_MMQ=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON -DCMAKE_HIP_ARCHITECTURES=gfx1100 with ROCm 7.1.1's clang
    — i.e. the option set setup.py's HIP path uses, which I had left out of my first attempt (it then stopped at the
    link on undefined symbol: strata::prefill::fused::dm_f16_used(), because STRATA_PREFILL_MMQ=OFF drops
    src/prefill/moe_fused_iq.cu from that archive). My error, not the tree's; corrected here rather than dropped.

Failed: the unmodified tag's HIP build, on the two lines above (that is the bug).

Not run:

  • No HIP hardware run: this host has an Intel Arc Pro B70 and no AMD discrete GPU, so the gfx1100 engine can be
    built but not executed here. I am not claiming it runs, only that it builds.
  • No other HIP architecture (gfx1201, gfx1030) built; the fix is the same declaration for all of them, and #778's
    report was gfx1030, but I did not build those.
  • No CUDA hardware run either (no NVIDIA GPU on this host).

Limits

  • Two lines of a build fix; the only claim is that the file compiles for HIP where it did not, and for CUDA as before.
    Whether these kernels are numerically correct on an AMD card is not something this host can establish.
  • If a future change reintroduces __shared__ alignas(16) <vector type> in this file, the same trap returns — the
    macros are the only thing preventing it, so a grep for that spelling is worth keeping in review.

AI assistance was used to locate the failing sites and run the builds; the failing and passing compile lines above are
from the commands shown, on the ROCm and CUDA toolchains named.


🔄 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/5518 **Author:** [@rwkeyes](https://github.com/rwkeyes) **Created:** 11/7/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `hip/aligned-shared-int4-staging` --- ### 📝 Commits (1) - [`98a74cd`](https://github.com/Niko1221/Strata/commit/98a74cd6217d576cd4821a8f78a6c981cfd6a702) HIP: the two int4 staging arrays #778 left behind do not compile ### 📊 Changes **1 file changed** (+10 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/kernels/cuda/iq_kernels.cu` (+10 -2) </details> ### 📄 Description ## Problem and result `v0.2.12` does not build for HIP: two expert-decode kernels stage their int4 rows as `__shared__ alignas(16) int4`, and HIP clang rejects that placement. This is the same defect **#778** fixed for the shared *grid* buffers — the two `int4` staging arrays were not converted when that fix landed, so those kernels never compile. **Before** (`146df3c4`, ROCm 7.1.1, `-DSTRATA_ENABLE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx1100`): ``` src/kernels/cuda/iq_kernels.cu:2591:16: error: 'alignas' attribute cannot be applied to types 2591 | __shared__ alignas(16) int4 s_u[ED_NC * 2 * ED_XB]; src/kernels/cuda/iq_kernels.cu:2778:16: error: 'alignas' attribute cannot be applied to types 2778 | __shared__ alignas(16) int4 s_u[ED_NC * 2 * ED_HB]; FAILED: CMakeFiles/strata_kernels.dir/src/kernels/cuda/iq_kernels.cu.o ``` **After:** both declarations use a `STRATA_SHARED_ALIGN16_INT4` macro with the same two forms as the existing `STRATA_SHARED_ALIGN16_U32` (`__attribute__((aligned(16)))` after the declarator under HIP, `alignas(16)` before it otherwise), the object compiles, and the gfx1100 engine builds. ## Related discussion Follow-up to **#778** ("iq_kernels: portable aligned shared-memory declaration for gfx1030", closed). That fix introduced `STRATA_SHARED_ALIGN16_U32` and converted the grid buffers; these two `int4` sites in the same file were left with the old declaration. I did not find an open issue covering them, and this is a build failure rather than a behaviour change, so it goes straight to a PR. ## Approach Ten lines in `src/kernels/cuda/iq_kernels.cu`, no other file: * one macro beside the existing one, with the same `#if defined(__HIPCC__)` split — the `__attribute__` form where HIP clang needs it, the `alignas` form where nvcc with MSVC as host requires it (the reason #778 is split at all); * the two declarations become `STRATA_SHARED_ALIGN16_INT4(s_u, ...)`. Same size, same alignment, same layout — this changes no arithmetic and no memory footprint. Nothing else in the tree is touched: no CMake, no other kernel, no version bump. ## Validation **Passed:** * **HIP, the changed translation unit**, ROCm 7.1.1, gfx1100: `ninja CMakeFiles/strata_kernels.dir/src/kernels/cuda/iq_kernels.cu.o` → object produced (6 534 784 B). The same command on the unmodified tag fails with the two errors quoted above. * **CUDA, the same file** (the other branch of the macro), CUDA 12.6, `-DCMAKE_CUDA_ARCHITECTURES=89`: object produced (11 587 504 B) — the nvcc path is unchanged. * **Full HIP engine build and link, gfx1100:** `ninja -C build-hip-full -j10 strata` → `[164/164] Linking HIP executable strata`, 0 errors, engine **60 162 624 B**, and `./strata --help` rc=0 with `hipv4-amdgcn-amd-amdhsa--gfx1100` in the binary (a real gfx1100 device image, not a CPU fallback). Configure: `-DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_BUILD_TESTS=OFF -DSTRATA_PREFILL_MMQ=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON -DCMAKE_HIP_ARCHITECTURES=gfx1100` with ROCm 7.1.1's clang — i.e. the option set `setup.py`'s HIP path uses, which I had left out of my first attempt (it then stopped at the link on `undefined symbol: strata::prefill::fused::dm_f16_used()`, because `STRATA_PREFILL_MMQ=OFF` drops `src/prefill/moe_fused_iq.cu` from that archive). My error, not the tree's; corrected here rather than dropped. **Failed:** the unmodified tag's HIP build, on the two lines above (that is the bug). **Not run:** * No HIP **hardware** run: this host has an Intel Arc Pro B70 and no AMD discrete GPU, so the gfx1100 engine can be built but not executed here. I am not claiming it runs, only that it builds. * No other HIP architecture (`gfx1201`, `gfx1030`) built; the fix is the same declaration for all of them, and #778's report was gfx1030, but I did not build those. * No CUDA hardware run either (no NVIDIA GPU on this host). ## Limits * Two lines of a build fix; the only claim is that the file compiles for HIP where it did not, and for CUDA as before. Whether these kernels are numerically correct on an AMD card is not something this host can establish. * If a future change reintroduces `__shared__ alignas(16) <vector type>` in this file, the same trap returns — the macros are the only thing preventing it, so a `grep` for that spelling is worth keeping in review. AI assistance was used to locate the failing sites and run the builds; the failing and passing compile lines above are from the commands shown, on the ROCm and CUDA toolchains named. --- <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#5491
No description provided.