Skip to content

Vulkan: route large matmuls to medium tile on Adreno - #24877

Merged
0cc4m merged 5 commits into
ggml-org:masterfrom
Raman-Raje:adreno_vulkan
Jul 11, 2026
Merged

0cc4m merged 5 commits into
ggml-org:masterfrom
Raman-Raje:adreno_vulkan

Conversation

@Raman-Raje

@Raman-Raje Raman-Raje commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Overview

On Qualcomm Adreno GPUs (Vulkan backend), inference with q4_0 models breaks, once the prompt grows past ~200 tokens and the batch exceeds 32. Short prompts
work fine.

Additional information

For non-coopmat devices, ggml_vk_guess_matmul_pipeline picks the tile by M/N:
M,N <= 32 -> small, <= 64 -> medium, otherwise -> large. With a long prompt the large q4_0 tile gets selected, and that shader fails on Adreno.

The per-type guard (ggml_vk_matmul_shmem_support) doesn't disable the large tile here because its computed footprint (~16.9 KB) is under the reported maxComputeSharedMemorySize, so the large tile stays enabled and is hit at runtime.

Before: crashes/hangs on long prompts with q4_0 on Adreno.
After: long-prompt inference completes; short prompts unchanged.

Requirements

I have read and agree with the contributing guidelines
AI usage disclosure: NO

The llama-cli was breaking for longer promts sizes for q4_0 quantized networks. Causing due to insufficient shared memory.
@Raman-Raje
Raman-Raje requested a review from a team as a code owner June 21, 2026 17:38
@github-actions github-actions Bot added Vulkan Issues specific to the Vulkan backend ggml changes relating to the ggml tensor library for machine learning labels Jun 21, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Jun 21, 2026

Copy link
Copy Markdown

Hi @Raman-Raje, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • AI-generated content: This project does not accept PRs, descriptions or commit messages that are fully or predominantly AI-generated. If you have used AI to assist you in writing code, please make sure to disclose that explicitly.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@jeffbolznv

Copy link
Copy Markdown
Contributor

The code should be checking against the shared memory limit already. How much shared memory does the device support? Which specific shader is causing an issue? What is your command line to reproduce the failure?

@Raman-Raje Raman-Raje changed the title Vulkan: fix shared memory overflow for large matmuls on Adreno Vulkan: route large matmuls to medium tile on Adreno Jun 21, 2026

@Raman-Raje Raman-Raje left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the dead code

@Raman-Raje Raman-Raje left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jeffbolznv.

Llama-cli fails when the batch exceeds 64 with a long (>200 token) prompt; with batch ≤ 64 the same long prompts work fine.

./llama-cli -m models/Llama-3B-Q4_0.gguf -p <prompt with 200 tokens>

The large q4_0 matmul tile. For non-coopmat devices, ggml_vk_guess_matmul_pipeline routes M,N > 64 to mmp->l, so the large tile gets selected at that point and breaks on Adreno. Forcing the medium tile (mul_mat_l = false) fixes it.

@jeffbolznv

Copy link
Copy Markdown
Contributor

So the shared memory thing was just the AI guessing? Please share the exact symptoms you're seeing, and also run with the vulkan validation layers enabled if possible.

@Raman-Raje

Raman-Raje commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Without changes:
promt used: ./bin/llama-cli -m models/Llama-3.2-1B-Instruct-Q4_0.gguf -f ai.txt -c 2048 &> test.log

vulkan debug shader log:
ggml_vulkan: 0 = Adreno (TM) 840 (Qualcomm Technologies Inc. Adreno Vulkan Driver) | uma: 1 | fp16: 1 | bf16: 0 | warp size: 64 | shared memory: 32768 | int dot: 0 | matrix cores: KHR_coopmat
ggml_backend_vk_buffer_init_tensor(0xb400007af6258210 (0xb4000079a6266460), 0xb400007925e45460)
ggml_backend_vk_synchronize()
ggml_vk_synchronize()
ggml_vk_graph_cleanup()
ggml_vk_command_pool_cleanup()
ggml_backend_vk_cpy_tensor_async(0xb400007925e17d00 -> 0xb4000079150bdb70, size=8192)
ggml_vk_create_context(0xb40000792625d598)
ggml_vk_ctx_begin(Vulkan0)
ggml_vk_buffer_write_async(8192)
ggml_vk_buffer_write_2d_async(8192, 1)
ggml_vk_sync_buffers()
ggml_backend_vk_synchronize()
ggml_vk_synchronize()
ggml_vk_ctx_end(0xb40000792625d598, 1)
ggml_vk_submit(0xb40000792625d598, 0x0)
0.08.618.199 E srv update_slots: decode() failed: vk::Queue::submit: ErrorDeviceLost
0.08.618.216 E srv send_error: task id = 0, error: decode() failed: vk::Queue::submit: ErrorDeviceLost

wich changes works fine

@0cc4m

0cc4m commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Why also disable the small pipeline? That was done for MoltenVK due to correctness issues.

@Raman-Raje

Copy link
Copy Markdown
Contributor Author

Why also disable the small pipeline? That was done for MoltenVK due to correctness issues.

UPdated changes

@Raman-Raje

Copy link
Copy Markdown
Contributor Author

@jeffbolznv please review

@jeffbolznv jeffbolznv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to understand the failure better, but there's a chance it's just a compiler bug so I'm OK with this.

@Raman-Raje Raman-Raje closed this Jul 6, 2026
@Raman-Raje Raman-Raje reopened this Jul 6, 2026
@0cc4m

0cc4m commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

This is not gonna get merged if you keep changing it, I have to retrigger the CI every time.

@Raman-Raje

Copy link
Copy Markdown
Contributor Author

it was closed by mistake. Will avoid it. Thanks

@Raman-Raje

Copy link
Copy Markdown
Contributor Author

@0cc4m Is anything missing from my side to merge this..?

@0cc4m
0cc4m merged commit 76f2798 into ggml-org:master Jul 11, 2026
27 checks passed
@0cc4m

0cc4m commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

No, thank you for the reminder.

satindergrewal pushed a commit to satindergrewal/llama.cpp that referenced this pull request Aug 12, 2026
* [Vulkan] Fixes llama-cli breaking over longer promts sizes

The llama-cli was breaking for longer promts sizes for q4_0 quantized networks. Causing due to insufficient shared memory.

* Removed the un-used Adreno device

* Updated matmul for small pipeline.
zbrad pushed a commit to zbrad/llama.cpp that referenced this pull request Sep 10, 2026
* [Vulkan] Fixes llama-cli breaking over longer promts sizes

The llama-cli was breaking for longer promts sizes for q4_0 quantized networks. Causing due to insufficient shared memory.

* Removed the un-used Adreno device

* Updated matmul for small pipeline.
@Raman-Raje
Raman-Raje deleted the adreno_vulkan branch October 22, 2026 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning Vulkan Issues specific to the Vulkan backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants