opencl : fix Q8 tensor readback from generic buffers#164
Draft
gianni-cor wants to merge 5 commits into
Draft
Conversation
Assisted-by: GPT-5.5 Co-authored-by: Cursor <cursoragent@cursor.com>
jesusmb1995
approved these changes
Jun 19, 2026
dev-nid
approved these changes
Jun 19, 2026
Assisted-by: GPT-5.5 Co-authored-by: Cursor <cursoragent@cursor.com>
Mixed or unknown Q8_0 layouts now produce a clear unsupported-layout error instead of an assertion. Co-authored-by: Cursor <cursoragent@cursor.com>
…outs. The SOA path copies the split q and d buffers linearly, which is only correct when those buffers are still in logical block order. On Adreno, Q8_0 SOA weights may be transposed in-place after upload for matmul performance. Once that happens, tensor view_offs no longer maps directly to a linear physical offset in the transposed q and d buffers. A view or shape-changing copy could therefore copy the wrong blocks. This change tracks whether a Q8_0 SOA extra was Adreno-transposed and rejects unsafe transposed SOA copies. Transposed SOA copies remain allowed only for full, non-view, same-shape tensors, where copying the raw physical representation is still valid. Co-authored-by: Cursor <cursoragent@cursor.com>
…uristic, but cache tensors are mutable and participate in view copies during cache shifting. Transposing their SOA q/d buffers makes view_offs unsafe and caused OpenCL scheduling to reject the preallocated cache view copy. This change limits the Adreno Q8_0 transpose to weight buffers only, and makes readback/matmul dispatch use the recorded adreno_transposed flag rather than re-running the shape heuristic. Co-authored-by: Cursor <cursoragent@cursor.com>
jesusmb1995
approved these changes
Jun 22, 2026
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.
Summary
Fixes OpenCL tensor readback for quantized tensor types when the tensor is backed by the generic OpenCL buffer layout instead of the SOA quantized-weight layout.
The crash happened because
ggml_backend_opencl_buffer_get_tensor()selected Q4/Q5/Q6/Q8 restore kernels based only ontensor->type. KV-cache tensors withcache-type-k=q8_0can use the generic OpenCL tensor extra, so the readback path could mis-cast that extra as a quantized SOA extra and pass invalid OpenCL handles to the restore kernel.This change gates each quantized restore path on whether
tensor->extrabelongs to the matching SOA extra pool. Generic tensors now fall through to the normaldata_devicereadback path.Validation
ggml-opencl,llama-completion, andtest-backend-opson Android.GPUOpenCL: QUALCOMM Adreno(TM) 830.