Skip to content

Commit 8cd9ea8

Browse files
okada-shogoclaude
andcommitted
kernels: the 16-value codebook lookups through v_perm_b32 on every HIP card
table16_lookup() (IQ4_NL, IQ4_XS, MXFP4, the formats of 16 values) took llama.cpp's v_perm_b32 sequence on gfx906 only, and the __byte_perm one elsewhere. Both give the same bytes; on RDNA4 the v_perm_b32 one is faster. In our first Inkling engine (PR #200) on an RX 9070 XT (gfx1201, ROCm 7.2.4), 8 cached IQ4_NL experts' products read at 337 -> 411 GB/s (2,304 values) and 244 -> 349 (1,152), and Inkling 2 Mini IQ4_NL wrote 256 tokens after 302 at 43.2 -> 45.6 tok/s, medians of 3. So every HIP build takes it. CUDA builds compile the same code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b681c69 commit 8cd9ea8

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎engine/src/kernels/cuda/native_mmvq.cu‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,9 @@ __device__ __align__(4) int8_t mxfp4_values[16] = {0, 1, 2, 3, 4, 6, 8, 12, 0, -
605605

606606
// Eight four-bit codes of q4 looked up in a codebook of 16: the even nibbles' values in .x, the odd ones' in .y.
607607
__device__ __forceinline__ int2 table16_lookup(const int8_t* table, int q4) {
608-
#if defined(STRATA_HIP_GFX906)
609-
// AMD: llama.cpp's HIP lookup (see iq_kernels.cu get_int_from_table_16): 4 v_perm_b32 per 8 values
608+
#if defined(__HIPCC__)
609+
// AMD: llama.cpp's HIP lookup (see iq_kernels.cu get_int_from_table_16): 4 v_perm_b32 per 8 values, and 2 to pick
610+
// the halves - the same bytes as the __byte_perm sequence below, which was slower on RDNA4
610611
const uint32_t* v32 = reinterpret_cast<const uint32_t*>(table);
611612
const uint32_t q_even = (uint32_t) q4, q_odd = (uint32_t) q4 >> 4;
612613
const uint32_t el = __builtin_amdgcn_perm(v32[1], v32[0], q_even & 0x07070707u);

0 commit comments

Comments
 (0)