Repository navigation
HIP: one product for a 2D src0 broadcast over a contiguous src1 batch - #423
Open
paleluna82-del wants to merge 1 commit into
Open
paleluna82-del wants to merge 1 commit into
paleluna82-del wants to merge 1 commit into
Conversation
A mul_mat with a 2D src0 and a contiguous batched src1/dst is the same product as one GEMM over all src1 columns. On HIP the batched form of such small per-batch products goes to batched hipBLASLt GEMMs that leave the GPU mostly idle (e.g. the Inkling 2 relative bias table, 1024 x 24 x 16 per token). Flatten the batch into the columns on HIP. CUDA is unchanged. GGML_CUDA_DISABLE_FLAT_BATCH=1 opts out. R9700 (gfx1201), ROCm 7.2.4, Inkling-2-Mini UD-Q4_K_M, q8_0 KV: pp2048 825 -> 1428, pp8192 724 -> 1383, pp512 and tg128 unchanged. KLD vs unflattened 0.000000 at -c 512 and -c 4096. test-backend-ops MUL_MAT: new broadcast cases (F32/F16/Q8_0, 512 and 7x3 batches, a permuted size-1 dim) pass, no new failures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On HIP, a
mul_matwith a 2D src0 broadcast over a contiguous batched src1 runs as batched hipBLASLt GEMMs. When the per-batch products are small, those leave the GPU mostly idle. The product equals one GEMM over all src1 columns, so on HIP the batch is flattened into the columns before dispatch. CUDA is unchanged.GGML_CUDA_DISABLE_FLAT_BATCH=1opts out.This is the backend-side replacement for the graph change I dropped from #406 (the Inkling 2 relative bias table, 1024 x 24 x 16 per token, which regressed prefill on B200 when done in the graph). Since it is backend-only, CUDA keeps its batched cuBLAS path.
Results (R9700 gfx1201, ROCm 7.2.4, Inkling-2-Mini UD-Q4_K_M, q8_0 KV, on top of #386 + #406)
GGML_CUDA_DISABLE_FLAT_BATCH=1)KLD with vs without: 0.000000 at -c 512 and -c 4096 (A/A floor, max 6e-5).
Testing
test-backend-ops -o MUL_MATon ROCm0: new broadcast cases (F32/F16/Q8_0 src0, 512 and 7x3 batches, a permuted size-1 dim) pass. The one failure (f16 m=16 n=2105344 k=32) also fails on the base and with the flattening disabled.-o MUL_MAT_ID1077/1077.GGML_USE_HIP.🤖 Generated with Claude Code