Skip to content

CUDA/HIP: INT8 convrot support on RDNA2 - #9

Open
noctrex wants to merge 4 commits into
leejet:int8_convrotfrom
noctrex:int8-convrot-rdna2
Open

CUDA/HIP: INT8 convrot support on RDNA2#9
noctrex wants to merge 4 commits into
leejet:int8_convrotfrom
noctrex:int8-convrot-rdna2

Conversation

@noctrex

@noctrex noctrex commented Aug 27, 2026

Copy link
Copy Markdown

Enables the INT8 convrot tensorwise mulmat on RDNA2 (gfx1030-class), previously rejected by supports_op.

Stacked on top of the open HIP enablement / H64 PRs (b688cbe, 0ec2d6a).
Once those merge, this PR reduces to the two RDNA2 commits.

Verification (V620 gfx1030, ROCm 7.14.0~pre3, ROCk 6.19.14, Ubuntu 24.04.4)

Correctness:

  • H64 exact-reference test: INT8 payload bit-exact (0/16640 bytes), F32 outputs exact (0/8320). Row scales agree within 64 ulp (GPU rotates with a radix-4 butterfly, the scalar reference sums sequentially; ulp differences do not move payload bytes).
  • GPU bitwise check, packed vs F32-input form, real model shapes: 0 mismatches at K=3840/10240, N=10240/3840/11520, M=8104 (Z-Image) and M=300 controls.
  • hipblasGemmEx route passes the same reference checks as the kernel route.
  • End-to-end (stable-diffusion.cpp): z_image_turbo (H64) and krea2_turbo (H256) generate correct 512x512 images.

Performance (full quantize+GEMM+epilogue, 5 iters):

case BLAS DP4A MMQ ratio
K=3840 N=10240 M=300 2.34ms 3.72ms 1.6x
K=6144 N=6144 M=300 1.31ms 3.41ms 2.6x
K=3840 N=10240 M=8104 16.72ms 94.60ms 5.7x
K=10240 N=3840 M=8104 17.29ms 98.26ms 5.7x
K=3840 N=11520 M=8104 18.70ms 106.78ms 5.7x

Known issue

If the op is not claimed by a GPU backend, the scheduler falls it back to CPU, where the padded (rows+1) GPU-quantized src1 trips GGML_ASSERT(ne1 == ne11) in ggml-cpu.c.
Unreachable with this gate in place, but a cross-backend fallback should tolerate the padding.

LLM Disclose: YES, used GLM-5.3 for the grunt work

noctrex and others added 4 commits August 25, 2026 21:00
Remove the blanket GGML_USE_HIP exclusion from the INT8 tensorwise
convrot ops and scope the capability check to GPUs with working
integer GEMM support (turing_mma_available, amd_wmma_available,
amd_mfma_available). RDNA2 stays excluded: hipBLASLt INT8 is broken
there.

vendors/hip.h: map CUDA_R_8I, CUDA_R_32I, CUBLAS_COMPUTE_32I and
__shfl_down_sync to their HIP equivalents. HIP's masked shuffle
templates require a 64-bit mask, so route to the maskless intrinsic
like the other __shfl_*_sync mappings.

Verified on gfx1100 (Windows ROCm 7.1): ggml tests/test-int8-convrot
passes, and CPU-vs-GPU output is bit-exact at real model shapes
(K=3840/10240, N up to 11520, 8104 rows).
Template the INT8 convrot quantization kernels on group_size and
instantiate 64 alongside 256. The Hadamard normalization is now
derived from the group size (2^-log4(group_size): 1/8 for G=64,
1/16 for G=256). The small-kernel max reduction uses a shared-memory
tree instead of warp shuffles so it stays correct for 16-thread
blocks. Capability gates accept group size 64 and 256.

Z-Image int8_tensorwise exports in the wild use convrot_groupsize
64; without this they fall back to CPU on every GPU backend.

Verified on gfx1100 (Windows ROCm 7.1): exact-reference tests pass
for H64 (single-group and multi-group packed GEMM), H256 unchanged,
and CPU-vs-GPU output is bit-exact at real Z-Image shapes.
hipblasGemmEx computes CUDA_R_8I x CUDA_R_8I -> CUDA_R_32I correctly on
gfx1030 with ROCm >= 7.14 (verified first-hand on a V620, Ubuntu Server
24.04.4) and is ~5.7x faster than the DP4A MMQ kernel at Z-Image shapes.
Extend ggml_cuda_i8_blas_available so both the supports_op gate and the
dispatch select BLAS on RDNA2; GGML_CUDA_FORCE_I8_MMQ still forces the
kernel for stacks with a broken rocBLAS INT8 route.
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