Skip to content

[Engine] AMD: opt-in int8 matrix-core kernel for prompts - #292

Open
okada-shogo wants to merge 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/hip-int8-tiles
Open

okada-shogo wants to merge 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/hip-int8-tiles

Conversation

@okada-shogo

@okada-shogo okada-shogo commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem and result

On AMD, Inkling 2's prompt expert products run in FP16: RDNA3 uses the FP16 tiles (gemm_iq_f16_grouped), and RDNA4 uses a loop that dequantizes each expert's whole matrix to FP16 and calls rocBLAS. On CUDA (Ampere and newer), the same products run on the int8 kernel (i8_mma.cuh). That kernel was CUDA-only (mma.sync, ldmatrix, cp.async), so gemm_iq_i8_takes() returned false on HIP.

This PR ports the int8 kernel to the RDNA3 (gfx11) and RDNA4 (gfx12) int8 matrix-core (WMMA) instructions. It is opt-in with STRATA_POLY_HIP_INT8=1; without the flag nothing changes. Prompts get 14-44% faster on an RX 9070 XT and 115-117% faster on an RX 7800 XT.

The weight decoders, the activation quantizer and the host API are the same code as on CUDA, and the integer sums are scaled and added in the same order. So a product has the same bits as CUDA's int8 kernel on the same inputs; this was checked for all 21 types the kernel takes. With the flag, the activations are int8 with a scale per 32 values (FP16 keeps 11 bits). This is the same rounding class as CUDA's default on Ampere and newer.

Prompt tok/s, mean of 3 runs, default prompt batch, same machine for both columns:

Card Model Measure main this PR alone (STRATA_POLY_HIP_INT8=1) Change
RX 9070 XT 16 GB IQ4_NL prompt 2,048 (tok/s) 1,010.4 1,154.9 +14.3%
RX 9070 XT 16 GB IQ4_NL prompt 8,192 (tok/s) 773.2 970.2 +25.5%
RX 9070 XT 16 GB UD-Q2_K_XL prompt 2,048 (tok/s) 1,086.3 1,425.8 +31.3%
RX 9070 XT 16 GB UD-Q2_K_XL prompt 8,192 (tok/s) 1,235.7 1,775.0 +43.6%
RX 7800 XT 16 GB UD-Q2_K_XL prompt 2,048 (tok/s) 420.9 906.4 +115.4%
RX 7800 XT 16 GB UD-Q2_K_XL prompt 8,192 (tok/s) 417.5 905.7 +116.9%
  • RX 9070 XT: rented Salad host, Ryzen 9 9900X3D, 62 GB RAM, ROCm 7.2.4. IQ4_NL keeps ~2,380 of 3,072 experts in VRAM; UD-Q2 keeps all.
  • RX 7800 XT: rented Salad host, 23 GB RAM, all experts in VRAM. It ran the build's gfx1100 code with HSA_OVERRIDE_GFX_VERSION=11.0.0 on both sides (the build had no gfx1101 code object).
  • main's default is the FP16 tiles on RDNA3 and the BLAS loop on RDNA4.
Speed with --prompt-batch 2048 (tok/s)

Mean of 3 runs, same machines. The RX 9070 XT's main column is from the first A/B run on the same box and binary
(main's path is unchanged code).

Card Model Measure main this PR alone Change
RX 9070 XT 16 GB IQ4_NL prompt 2,048 (tok/s) 1,462.3 1,881.3 +28.7%
RX 9070 XT 16 GB IQ4_NL prompt 8,192 (tok/s) 1,013.6 1,193.5 +17.7%
RX 9070 XT 16 GB UD-Q2_K_XL prompt 2,048 (tok/s) 1,461.6 1,705.6 +16.7%
RX 9070 XT 16 GB UD-Q2_K_XL prompt 8,192 (tok/s) 1,766.2 2,196.1 +24.3%
RX 7800 XT 16 GB UD-Q2_K_XL prompt 2,048 (tok/s) 504.9 1,000.6 +98.2%
RX 7800 XT 16 GB UD-Q2_K_XL prompt 8,192 (tok/s) 503.1 1,004.3 +99.6%
Each run (tok/s)
Card Model Measure Build Run 1 Run 2 Run 3
RX 9070 XT IQ4_NL prompt 2,048 (tok/s) main 1,012.4 1,014.5 1,004.4
RX 9070 XT IQ4_NL prompt 2,048 (tok/s) this PR alone 1,155.7 1,153.0 1,156.1
RX 9070 XT IQ4_NL prompt 8,192 (tok/s) main 762.3 781.2 776.2
RX 9070 XT IQ4_NL prompt 8,192 (tok/s) this PR alone 972.0 970.6 967.9
RX 9070 XT UD-Q2_K_XL prompt 2,048 (tok/s) main 1,089.0 1,085.8 1,084.0
RX 9070 XT UD-Q2_K_XL prompt 2,048 (tok/s) this PR alone 1,435.5 1,427.5 1,414.5
RX 9070 XT UD-Q2_K_XL prompt 8,192 (tok/s) main 1,237.5 1,234.1 1,235.5
RX 9070 XT UD-Q2_K_XL prompt 8,192 (tok/s) this PR alone 1,778.8 1,773.2 1,773.1
RX 7800 XT UD-Q2_K_XL prompt 2,048 (tok/s) main 419.2 419.3 424.3
RX 7800 XT UD-Q2_K_XL prompt 2,048 (tok/s) this PR alone 907.8 905.2 906.3
RX 7800 XT UD-Q2_K_XL prompt 8,192 (tok/s) main 416.2 417.2 419.1
RX 7800 XT UD-Q2_K_XL prompt 8,192 (tok/s) this PR alone 904.4 902.8 909.8

Side order rotated each round; one warm-up per side first. One greedy request per run through --serve,
--prompt-cache 0 --conversation-cache-mib 0 --kv fp16.

Accuracy, UD-Q2_K_XL on the RX 7800 XT with all experts in VRAM. Four different 2,048-token texts; for each, the last prompt row plus 32 decode rows (132 rows in all). The reference's greedy tokens are fed to the other engines:

Against main's default KL median KL mean without the top row KL max Same top token
main again (repeat control) 0 (bytes equal) 0 0 132/132
main, 2,400 experts in VRAM (placement control) 3.9e-4 4.7e-2 4.8 128/132
this PR alone, STRATA_POLY_HIP_INT8=1 8.0e-4 1.3e-2 1.09 126/132

Related discussion

In PR #200's review, VecSzn asked to split the AMD work into separate PRs. The int8 tiles use the idea of llama.cpp/ggml's MMQ
(int8 activations per 32-value block, integer sums scaled per block). Our fork's inkling2-amd-preview branch used it
on HIP through llama.cpp. This PR is our own code on main's kernel. NVFP4 on the int8 tiles follows Tako88's approach.

Approach

  • i8_mma.cuh, under __HIPCC__: the block keeps its shape (64 weight rows x 16 NJ activation rows, 256 values a
    stage, codes in LDS, the next stage read into registers while this one is multiplied). The products use
    v_wmma_i32_16x16x16_iu8: gfx11 takes duplicated 16-value operands, gfx12 takes 8 values a lane. For each
    32-value block (16 for a type with a scale per 16), sum * (weight scale * activation scale) is added to the FP32
    sum, then the minimum's term, as on CUDA. Barriers are LDS-only. The next stage's reads have no branches, so the
    compiler does not wait for all of them in the middle. HIP has no cp.async path and no 128-row tile.
  • i8_mma.cu now builds on HIP. gfx906 still takes the stubs in iq_kernels.cu.
  • mmq_own.cu: STRATA_POLY_HIP_INT8=1 sends a matrix to the int8 kernel where it takes it. NVFP4 goes with it
    unless STRATA_PREFILL_NVFP4 names a mode.
  • A launch whose blocks pass the grid's y side (65,535) now goes as runs of matrices instead of failing. A row's
    product does not depend on its launch, so the bits are the same.
  • mmq_paths_test: STRATA_MMQ_TEST_DUMP=DIR writes each int8 product's floats and the inputs' hashes.
    STRATA_MMQ_TEST_REF=DIR compares them with another card's dump and fails on any byte. New int8 cases: matrices of
    500 rows (not whole tiles of 64), launches of 10 and 20 rows (the 16- and 32-row tiles), small experts, Q2_0, and
    70,000 one-row matrices by offset (more blocks than a grid side).

Validation

Passed:

  • Bit check against CUDA, at this PR's head: STRATA_POLY_HIP_INT8=1 STRATA_PREFILL_NVFP4=w4a8 STRATA_MMQ_TEST_REF=DIR poly_mmq_paths_test, DIR = the dumps of poly_mmq_paths_test --turing-int8 on an RTX 2070 (sm_75). RX 7900 XT
    (gfx1100): 168/168 products byte-identical, 122 ok, PASS. RX 9070 XT (gfx1201): the same, 168/168, 122 ok, PASS. The 168 products
    are dense, experts with ids, rows by index, 500-row matrices times 10, 20 and 256 rows, and small experts, for Q4_0
    Q5_0 Q5_1 Q8_0 Q2_K Q3_K Q4_K Q5_K Q6_K IQ2_XXS IQ2_XS IQ3_XXS IQ1_S IQ4_NL IQ3_S IQ2_S IQ4_XS IQ1_M MXFP4 NVFP4
    Q2_0 at K = 2,048, and Q8_0 IQ4_NL NVFP4 at K = 1,152. The 70,000-matrix launch gives the dense product's bits on
    all three cards.
  • Earlier revision of the kernel (same kernel code; fewer test shapes): 69/69 byte-identical on RX 9070 XT, RX 7900
    XTX (gfx1100) and RX 7800 XT (gfx1101 running gfx1100 code). Without the flag (main's path) on the RX 9070 XT:
    23/23 ok.
  • Speed and accuracy as in the tables above.
  • Builds at this PR's head (on main 36e654b): HIP gfx1100;gfx1201 (strata-poly, poly_mmq_paths_test), ROCm
    7.2.4; CUDA sm_75 (strata-poly, poly_mmq_paths_test), CUDA 12.9. The speed and accuracy numbers are from the
    same kernel code on main cdfae80.

Failed:

  • none observed

Not run:

  • CUDA identity of the full engine: the CUDA path of i8_mma.cuh is unchanged code (the HIP parts are under
    #if), so only a build was done.
  • A real gfx1101 code object, gfx1151, gfx1200: not built or not run.
  • Decode speed: the flag changes only prompt products.

Limits

  • Opt-in only. The default stays the FP16 tiles (RDNA3) and the BLAS loop (RDNA4).
  • The kernel reaches ~40-50 int8 TOPS on the RX 9070 XT for Inkling 2's expert shapes, a fraction of the card's peak.
    On the same box, llama.cpp's MMQ build of our stack was 1,202 / 979 tok/s (IQ4_NL 2K / 8K) against 1,155 / 970 here;
    the inkling2-amd-preview branch was faster (2,021 / 1,096), mostly outside the expert products.

🤖 Generated with Claude Code

…_POLY_HIP_INT8=1)

The int8 prompt kernel (i8_mma.cuh) gets a HIP body: the same block (64 weight
rows x 16 NJ activation rows, 256 values a stage, the weights decoded to int8 in
LDS by the same decoders, the next stage read into registers while this one is
multiplied), with the products on v_wmma_i32_16x16x16_iu8 (gfx11: duplicated
16-value operands; gfx12: 8 values a lane) and LDS-only barriers.  The next
stage's reads are made without branches (put() zeros what is not there), so
the compiler counts them and does not wait for all of them in the middle.  Each 32-value
block's integer sum (16 for a type with a scale per 16) is scaled and added in
the same order as the CUDA m16n8k32 / m16n8k16 path, so a product has the same
bits as CUDA's int8 kernel: poly_mmq_paths_test's new STRATA_MMQ_TEST_DUMP dumps
are byte-identical between an RTX 2070 (--turing-int8) and an RX 9070 XT
(gfx1201), an RX 7900 XTX (gfx1100) and an RX 7800 XT (gfx1101 running the
gfx1100 code), for all 20 types the kernel takes.

A launch whose blocks pass the grid's y side (65,535) goes as runs of
matrices instead of failing (a row's product does not depend on its launch).
poly_mmq_paths_test also covers matrices of 500 rows (not whole tiles), launches
of 10 and 20 rows (the 16- and 32-row tiles), small experts, Q2_0, and 70,000
one-row matrices by offset; STRATA_MMQ_TEST_REF=DIR fails the test where a
product's bytes differ from another card's dump.

strata-poly takes it on HIP only with STRATA_POLY_HIP_INT8=1 (mmq_own.cu):
int8 activations are a rounding change against HIP's FP16 tiles and BLAS loop,
the same class as CUDA's default on Ampere and newer.  NVFP4 goes with it
unless STRATA_PREFILL_NVFP4 names a mode.  Unset, nothing changes.  gfx906
keeps the stubs.

The idea of int8 activations a 32-value block with per-block scaled integer
sums is llama.cpp/ggml's MMQ, which our inkling2-amd-preview branch (PR simplexai-labs#200's
AMD work) ran on HIP through llama.cpp; NVFP4 on the int8 tiles follows
Tako88's approach.  The code here is our own, on main's kernel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@okada-shogo okada-shogo changed the title [Engine] strata-poly on AMD: prompt products on the RDNA3/RDNA4 int8 matrix cores (opt-in, STRATA_POLY_HIP_INT8=1) [Engine] AMD RDNA3/RDNA4: int8 matrix-core kernel for prompt expert products (opt-in, STRATA_POLY_HIP_INT8=1) Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] AMD RDNA3/RDNA4: int8 matrix-core kernel for prompt expert products (opt-in, STRATA_POLY_HIP_INT8=1) [Engine] AMD RDNA3/RDNA4: run prompt expert products on the int8 matrix cores (opt-in STRATA_POLY_HIP_INT8=1, +14-117% prompt speed) Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] AMD RDNA3/RDNA4: run prompt expert products on the int8 matrix cores (opt-in STRATA_POLY_HIP_INT8=1, +14-117% prompt speed) [Engine] AMD RDNA3/4: opt-in int8 matrix-core kernel for prompts (+14-117% prompt) Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] AMD RDNA3/4: opt-in int8 matrix-core kernel for prompts (+14-117% prompt) [Engine] AMD: opt-in int8 matrix-core kernel for prompts Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant