Repository navigation
Conversation
The CUB-based ARGSORT/TOP_K (and sum/mean/cumsum) paths were compiled out for HIP, so those ops fell back to the shared-memory bitonic sort. That sort uses one thread per element, so it is limited to rows of 1024 elements; anything wider was reported as unsupported and ran on the CPU. For deepseek4 that meant every lightning-indexer TOP_K above 1024 context went to the host, adding a graph split per layer. hipCUB provides the device-wide sorts these paths need - the rocPRIM backend has DeviceRadixSort, DeviceSegmentedRadixSort, DeviceSegmentedSort, DeviceReduce and DeviceScan - so include it through a small cub-compat shim that aliases the cub namespace, and define GGML_CUDA_USE_CUB for HIP as well. hipCUB has no DeviceTopK and does not define CCCL_*, so CUB_TOP_K_AVAILABLE and STRIDED_ITERATOR_AVAILABLE stay disabled there: TOP_K keeps using the argsort + copy path and argsort keeps using the init_offsets kernel instead of a strided iterator. vendors/hip.h gains the stream-capture defines that the CUB argsort path needs now that it is compiled for HIP.
|
@ggml-org/ci Looks like CI hip workflows need to be updated to install hipcub dev package for this. Not sure about HIP Windows release, but I guess that's something to worry about later. |
|
So test this PR here with 4x gfx1200 9060xt and 1x gfx1151. No crash at 68727 PP context. |
|
@fairydreaming isn't hipcub included in rocm? |
@Geramy No idea, my adventure with AMD GPUs ended during Radeon R9 290 times. By the way, could you run some Thanks! |
|
@fairydreaming from AMD GitHub page directly |
|
Cline is working now including reasoning and cache with up to 172k tokens for me over rpc. Edit: by 193k tokens ca. 600mb VRAM increase per GPU i can observe. |
Well for some reason hipCUB header files were missing in the CI container during compilation, I see that it installs Ubuntu rocblas-dev and hipblas-dev packages, so maybe they also need to install libhipcub-dev or something. |
Yeah perhaps it depends on the ROCm version we are on too. Who will or can take care of that? |
@Geramy I don't know, if no one fixes it I'll see what I can do tomorrow (going to sleep soon). |
|
Confirmed to work on a Strix Halo: with this patch the tg speed stays correct even after >4-5k context (instead of having a big drop to 5 tok/s). 🎉 However, I'm wondering if the prefill speed doesn't get worse faster than with #26493, but that can be totally wrong, don't read too much into this. |
|
HIP quality check CI found some missing CUB function call return value error checks, so I added them. Compilation worked fine with added |
Co-authored-by: Georgi Gerganov <[email protected]>
|
@fairydreaming thanks! I didn’t see any of the CIs run or get approved to run did you do a few manually in actions? |
|
@Geramy Yeah, in this PR I have to approve workflows manually to run and they reset after each new commit. Probably you can see them in Actions history (ran about 4 hours ago). Now let's wait for someone from ggml-cuda to review and approve this. |
|
Follow-up: pinned down the graph-capture crash. It is not pool allocation growth — I tested that theory by rounding every pool request in the CUB paths up to power-of-two buckets (argsort.cu ×4, top-k.cu ×1) and the crash reproduces unchanged. The failing call is the sort itself: So on ROCm, hipCUB/rocPRIM's Suggestion: on HIP, either gate the CUB paths out of captured streams entirely (fall back to disabling graph capture for graphs containing wide TOP_K/ARGSORT), or document For the qwen4exp use case specifically, #27466's native radix kernel may compose better with HIP graphs since it has no library-internal stream operations — testing that now and will report there. |
@drluoto your crash is related to the rocPRIM version aka ROCm, this works properly on 7.13 and 7.14, which I believe llama.cpp has been upgraded to recently or is about to be upgraded to. |
|
@IMbackK can you test this again, I think I found the issue, this should be resolved on ROCm 7.13 and 7.14 |
|
this doesn't exist on 7.13 or 7.14 I've tested again and amd tested on the MI325X which also does not have any problem running it, my new guard I added prevents it compiling against 7.2.4 routing completely against the bad binary causing the segfault. |
The CUB-based ARGSORT/TOP_K (and sum/mean/cumsum) paths were compiled out for HIP, so those ops fell back to the shared-memory bitonic sort limited to rows of 1024 elements; wider rows ran on the CPU. hipCUB provides the device-wide sorts these paths need, so include it through the vendor headers and define GGML_CUDA_USE_CUB for HIP. hipCUB has no DeviceTopK and no CCCL_*, so CUB_TOP_K_AVAILABLE and STRIDED_ITERATOR_AVAILABLE stay disabled there: TOP_K keeps the argsort + copy path. squashed from PR ggml-org#26592 (CI workflow changes dropped)
|
So yes this works fine with ROCM 10.0 the graph issue has been resolved upstream. While we have another top_k kernel now and a lightning indexer is on the way this is thus less urget, its still usefull for the other kernels |
yes I could. |
|
@IMbackK are we still interested in merging this? I would like to open another PR in a bit, regarding another matter. |
JohannesGaessler
left a comment
There was a problem hiding this comment.
Based on static code analysis this PR seems correct to me. I can't judge whether the kernel selection logic is optimal in terms of performance. The AMD GPUs I have are an RX 6800, an RX 9060, a MI50, a MI100, and a Strix Halo Laptop. I can provide SSH access or benchmark the performance myself if someone tells me which commands to run.
|
I can verify on an R9700 (gfx1201) as well. |
|
In the meanwhile, please fix the conflicts :) |
Geramy
left a comment
There was a problem hiding this comment.
working on conflicts.
Overview
Since the CUB-based ARGSORT/TOP_K paths were never running on a HIP based device, I have enabled them and added a few missing hip graph functions. Originally those ops fell back to the shared-memory bitonic sort. That sort uses one thread per element, so it is limited to rows of 1024 elements; anything wider was reported as unsupported and ran on the CPU.
Additional information
I have added stream-capture functions missing from vendors/hip.h which is required in CUB argsort.
DeepSeek-V4-Flash UD-IQ1_S — 284B MoE, 78 GB
pp512prompt processing
tg32token generation
Qwen3.6-35B-A3B UD-Q4_K_XL
pp512prompt processing
tg32token generation
Requirements
@IMbackK @am17an @pwilkin