[PR #322] [CLOSED] hip: fast packed-byte intrinsics for RDNA3/RDNA4 (v_perm_b32 + SWAR) #2574

Closed
opened 2026-11-04 02:01:28 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/322
Author: @bsorensen110
Created: 10/1/2026
Status: ❌ Closed

Base: main ← Head: fast-intrinsics-rdna4


📝 Commits (2)

  • 7e7e6e1 hip: fast packed-byte intrinsics for RDNA3/RDNA4 (v_perm_b32 + SWAR)
  • 2a57d8d Modify selector assignment in fast_intrinsics_parity.cpp

📊 Changes

4 files changed (+112 additions, -29 deletions)

View changed files

📝 CMakeLists.txt (+6 -0)
📝 cmake/hip_backend.cmake (+1 -1)
📝 include/strata/hip_compat/intrinsics.hpp (+30 -28)
➕ tests/hip/fast_intrinsics_parity.cpp (+75 -0)

📄 Description

What

Speeds up the four emulated CUDA packed-byte intrinsics in include/strata/hip_compat/intrinsics.hpp on the validated wave32 architectures (gfx1100, gfx1201), and adds an exhaustive parity test.

__byte_perm, __vsub4, __vsubss4 and __vcmpne4 are used in the i-quant dequant/sign paths (iq_kernels.cu: 28 uses, native_mmvq.cu: 14 uses). Today:

  • HIP's own __byte_perm lowers to a byte-array access in private memory — scratch traffic in the table lookups.
  • The packed-byte ops are per-lane scalar loops (8–12 instructions each).

This patch:

  • __byte_perm → v_perm_b32 in one instruction (selector nibbles spread to bytes, masked to 0–7).
  • __vsub4 / __vsubss4 / __vcmpne4 → branchless SWAR (Hacker's Delight 2-18 style). I probed the gfx1201 ISA directly: the RDNA1/2-era packed ops (v_sub_u8, v_add_u8, v_cmp_ne_u8, v_sub_u16, …) are not in the ISA, so lane isolation is done with the top-bit trick, not ISA lanes. v_perm_b32 is present and is the only 1:1 mapping.
  • tests/hip/fast_intrinsics_parity.cpp (registered as hip_fast_intrinsics_parity, HIP-only like hip_intrinsics): 262,144 cases against an independent host reference — all 65,536 byte pairs × 4,096 selectors exhaustively, plus randomized mixed-lane words, plus output guards.

Evidence

Radeon AI PRO R9700 (gfx1201), engine 0.1.30, Swift 1.5 IQ3_XXS, 131072 ctx, INT8 KV, MTP, same machine/config, three fresh 512-token trials per arm:

arm sustained decode
stock 0.1.30 55.0 tok/s
+ this patch 67.5 tok/s
  • hip_fast_intrinsics_parity: PASS (262144 cases / 1048576 operation results, all 65536 byte pairs, 4096 selectors, 16 guards).
  • HIP suite with the patch: 43/43 (-E '^(ple_parity|platform_memory_test|expert_parity|pool_test)$', the same exclusions as the release docs; hip_prefill_hipblaslt_gemm skips, no gfx1201 table shipped).
  • Real-model checks on the patched engine: arithmetic, system-marker recall, multi-turn recall, streaming, and native expert parity on both IQ3_XXS shards (layer 0 / layer 47) all passed.

Notes

  • CUDA path untouched; portable fallbacks kept for non-wave32 HIP targets.
  • This is the intrinsics portion of #262, rebased onto 0.1.30's native RDNA4 support and re-validated — 0.1.30 shipped the hardware support without this block.
  • The SWAR forms are branchless and overflow-safe; the exhaustive test covers every byte-pair for every selector, saturating edges 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/Niko1221/Strata/pull/322 **Author:** [@bsorensen110](https://github.com/bsorensen110) **Created:** 10/1/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fast-intrinsics-rdna4` --- ### 📝 Commits (2) - [`7e7e6e1`](https://github.com/Niko1221/Strata/commit/7e7e6e15d548728c42544ba01d8064f2e3935e2a) hip: fast packed-byte intrinsics for RDNA3/RDNA4 (v_perm_b32 + SWAR) - [`2a57d8d`](https://github.com/Niko1221/Strata/commit/2a57d8d0c2417ed5877993a60eb6db8096d6436c) Modify selector assignment in fast_intrinsics_parity.cpp ### 📊 Changes **4 files changed** (+112 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+6 -0) 📝 `cmake/hip_backend.cmake` (+1 -1) 📝 `include/strata/hip_compat/intrinsics.hpp` (+30 -28) ➕ `tests/hip/fast_intrinsics_parity.cpp` (+75 -0) </details> ### 📄 Description ## What Speeds up the four emulated CUDA packed-byte intrinsics in `include/strata/hip_compat/intrinsics.hpp` on the validated wave32 architectures (gfx1100, gfx1201), and adds an exhaustive parity test. `__byte_perm`, `__vsub4`, `__vsubss4` and `__vcmpne4` are used in the i-quant dequant/sign paths (`iq_kernels.cu`: 28 uses, `native_mmvq.cu`: 14 uses). Today: - HIP's own `__byte_perm` lowers to a byte-array access in private memory — scratch traffic in the table lookups. - The packed-byte ops are per-lane scalar loops (8–12 instructions each). This patch: - `__byte_perm` → **`v_perm_b32`** in one instruction (selector nibbles spread to bytes, masked to 0–7). - `__vsub4` / `__vsubss4` / `__vcmpne4` → branchless **SWAR** (Hacker's Delight 2-18 style). I probed the gfx1201 ISA directly: the RDNA1/2-era packed ops (`v_sub_u8`, `v_add_u8`, `v_cmp_ne_u8`, `v_sub_u16`, …) are **not in the ISA**, so lane isolation is done with the top-bit trick, not ISA lanes. `v_perm_b32` is present and is the only 1:1 mapping. - `tests/hip/fast_intrinsics_parity.cpp` (registered as `hip_fast_intrinsics_parity`, HIP-only like `hip_intrinsics`): 262,144 cases against an independent host reference — **all 65,536 byte pairs × 4,096 selectors exhaustively**, plus randomized mixed-lane words, plus output guards. ## Evidence Radeon AI PRO R9700 (gfx1201), engine 0.1.30, Swift 1.5 IQ3_XXS, 131072 ctx, INT8 KV, MTP, same machine/config, three fresh 512-token trials per arm: | arm | sustained decode | |---|---:| | stock 0.1.30 | 55.0 tok/s | | + this patch | **67.5 tok/s** | - `hip_fast_intrinsics_parity`: PASS (262144 cases / 1048576 operation results, all 65536 byte pairs, 4096 selectors, 16 guards). - HIP suite with the patch: **43/43** (`-E '^(ple_parity|platform_memory_test|expert_parity|pool_test)$'`, the same exclusions as the release docs; `hip_prefill_hipblaslt_gemm` skips, no gfx1201 table shipped). - Real-model checks on the patched engine: arithmetic, system-marker recall, multi-turn recall, streaming, and native expert parity on both IQ3_XXS shards (layer 0 / layer 47) all passed. ## Notes - CUDA path untouched; portable fallbacks kept for non-wave32 HIP targets. - This is the intrinsics portion of #262, rebased onto 0.1.30's native RDNA4 support and re-validated — 0.1.30 shipped the hardware support without this block. - The SWAR forms are branchless and overflow-safe; the exhaustive test covers every byte-pair for every selector, saturating edges included. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:01:28 +07:00
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#2574
No description provided.