Repository navigation
hip: fast packed-byte intrinsics for RDNA3/RDNA4 (v_perm_b32 + SWAR) - #322
bsorensen110 wants to merge 2 commits into
Conversation
__byte_perm, __vsub4, __vsubss4 and __vcmpne4 were emulated with per-lane loops. On gfx1100/gfx1201 HIP's __byte_perm lowers to private- memory byte-array traffic in the i-quant table lookups, and the packed byte loops cost the Q3_K/Q6_K dots and the sign expansion several times the instructions. - __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): gfx11/gfx12 have no packed 8-bit add/sub/compare in the ISA, so the lane isolation is done with the top-bit trick, not with ISA lanes. - tests/hip/fast_intrinsics_parity: independent host reference over 262144 cases - all 65536 byte pairs x 4096 selectors exhaustively, plus randomized mixed-lane words - with output guards. Registered as the hip_fast_intrinsics_parity CTest (HIP-only, like hip_intrinsics). Measured on a Radeon AI PRO R9700 (gfx1201), engine 0.1.30, Swift 1.5 IQ3_XXS, 131072 ctx, INT8 KV, MTP: sustained decode 55.0 -> 67.5 tok/s (three fresh 512-token trials per arm, same machine, same config); the 43-test HIP suite passes with the patch, including hip_intrinsics.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The parity test omits selector encodings 8–F and the PR overstates its Cartesian coverage.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Optimizes HIP packed-byte intrinsics for RDNA3/RDNA4 and adds parity testing.
Changes:
- Implements
v_perm_b32and SWAR packed-byte operations. - Adds exhaustive/randomized HIP parity coverage.
- Registers the new test with CMake.
| File | Description |
|---|---|
include/strata/hip_compat/intrinsics.hpp |
Adds optimized packed-byte intrinsics. |
tests/hip/fast_intrinsics_parity.cpp |
Tests intrinsic parity and buffer guards. |
CMakeLists.txt |
Registers the parity test. |
cmake/hip_backend.cmake |
Compiles the test as HIP. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| } | ||
|
|
||
| int main() { | ||
| constexpr size_t count = 262144, exhaustive = 65536, guard = 16; |
There was a problem hiding this comment.
@copilot Fix the code for this review comment.
When a review comment includes a suggested change, apply the suggestion exactly.
Do not make changes beyond what is described in the linked review comment.
|
@copilot Fix the code for all comments in this review thread. When a review comment includes a suggested change, apply the suggestion exactly. Do not make changes beyond what is described in the linked review thread. |
Fix test coverage. Cycle all 16-bit encodings Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Seems legit on my 7900 XTX. Good gain and correctness seems perfect after a few Astra reviews/parity tests/logit tests and benchs.
|
|
Thanks - the same intrinsics shipped in 0.1.31 from #262 (with a test that also covers selector bit 3). Closing as shipped. |


What
Speeds up the four emulated CUDA packed-byte intrinsics in
include/strata/hip_compat/intrinsics.hppon the validated wave32 architectures (gfx1100, gfx1201), and adds an exhaustive parity test.__byte_perm,__vsub4,__vsubss4and__vcmpne4are used in the i-quant dequant/sign paths (iq_kernels.cu: 28 uses,native_mmvq.cu: 14 uses). Today:__byte_permlowers to a byte-array access in private memory — scratch traffic in the table lookups.This patch:
__byte_perm→v_perm_b32in 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_b32is present and is the only 1:1 mapping.tests/hip/fast_intrinsics_parity.cpp(registered aship_fast_intrinsics_parity, HIP-only likehip_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:
hip_fast_intrinsics_parity: PASS (262144 cases / 1048576 operation results, all 65536 byte pairs, 4096 selectors, 16 guards).-E '^(ple_parity|platform_memory_test|expert_parity|pool_test)$', the same exclusions as the release docs;hip_prefill_hipblaslt_gemmskips, no gfx1201 table shipped).Notes