Repository navigation
Vulkan: an RX 7600 behind a USB4/PCIe tunnel decodes 24 to 29 percent faster on the graphics queue #31096
joshuaswarren
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I measured this on a single card in a specific setup, so I'm asking before I submit a patch. The host is an Apple M2 Max laptop running Linux with a USB4/PCIe tunnel and 16K pages. The GPU is a Radeon RX 7600 (Navi 33) in an external enclosure. I used Mesa 26.2.5 RADV and llama.cpp build 65840ed. The model is Llama-2-7B Q4_0 with -ngl 100. For every run I set GGML_VK_DISABLE_MMVQ=1 and RADV_PERFTEST=nogttspill,dmashaders.
I ran llama-bench tg128 three times for each configuration, bracketing each with baseline runs. The default compute-only queue family gave 41.6 tok/s with flash attention off (fa 0) and 45.3 tok/s with it on (fa 1). When I set GGML_VK_ALLOW_GRAPHICS_QUEUE=1, I saw 53.7 and 56.3 tok/s. That is a 29% and 24% increase. Setting RADV_DEBUG=nocompute gives the same gain, but using both together does not stack. Prompt processing at 512 tokens didn't change. Perplexity on wikitext-2 with 16 chunks was identical on both queues: 7.0859 +/- 0.26536.
GGML_VK_PERF_LOGGER shows the kernels themselves run slower on the compute-only queue. ROPE takes 23.3 us versus 6.9 us. SET_ROWS takes 23.4 us versus 4.4 us. A q4_0 mat-vec takes 54.5 us versus 39.5 us. Total GPU time per token is 23.0 ms versus 17.6 ms.
I wrote a standalone repro of about 150 lines of C that runs one tiny compute shader without llama.cpp. With a static pipeline, both queue families take 0.1 to 0.4 us per dispatch. When the pipeline changes on every dispatch, the compute-only family takes 18 to 22 us per dispatch. The graphics family takes 0.3 to 5 us. This holds with or without a barrier between dispatches.
RADV emits the same packets for both queues at a pipeline change. Skipping the CP DMA shader prefetch changes nothing. It looks like the compute queue drains at each pipeline change on this setup. llama.cpp changes the pipeline for almost every op. That is where the 6 ms per token goes.
The code comment next to GGML_VK_ALLOW_GRAPHICS_QUEUE says avoiding the graphics queue can increase performance on RADV. I assume the default was measured on native PCIe. I have no native AMD card to compare with. So I don't know if the drain exists there or only behind the tunnel. I haven't measured native PCIe, other AMD cards, other models, or other apps.
Would you take an automatic fallback like a small startup probe similar to the repro, or a documented switch? Or should this stay an environment variable? I can send either as a PR with the repro attached.
AI assistance: AI agents (Claude) ran these measurements with me, helped analyze them and helped draft this text. The numbers are copied from the run logs, and I can post the logs.
The repro with qbench.c, tiny2.comp and a short README is in this gist: https://gist.github.com/joshuaswarren/c4feecce7fcca0d3416c42dafac9ff93
All reactions