Skip to content

webgpu : avoid crash when offset is not multiple of 4 in WebGPU ggml_backend_tensor_get() implementation - #28045

Merged
fairydreaming merged 3 commits into
ggml-org:masterfrom
fairydreaming:webgpu-buffer-get-offset
Aug 31, 2026
Merged

webgpu : avoid crash when offset is not multiple of 4 in WebGPU ggml_backend_tensor_get() implementation#28045
fairydreaming merged 3 commits into
ggml-org:masterfrom
fairydreaming:webgpu-buffer-get-offset

Conversation

@fairydreaming

Copy link
Copy Markdown
Contributor

Overview

WebGPU uses CopyBufferToBuffer() that requires size and offsets to be multiplies of 4 in its ggml_backend_tensor_get() implementation. While the implementation rounds size internally, offset was not rounded, so it crashed for offset values not equal to a multiple of 4.

Additional information

This fix adds a local offset to make sure the global offset passed to CopyBufferToBuffer() is a multiple of 4.

Requirements

@fairydreaming
fairydreaming requested a review from a team as a code owner August 30, 2026 19:50
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning WebGPU labels Aug 30, 2026
Comment thread ggml/src/ggml-webgpu/ggml-webgpu.cpp Outdated
Comment thread ggml/src/ggml-webgpu/ggml-webgpu.cpp Outdated
@fairydreaming

Copy link
Copy Markdown
Contributor Author

@ggerganov WebGPU CI failed anyway because of #27960, so #28071 is needed too.

@CISC

CISC commented Aug 31, 2026

Copy link
Copy Markdown
Member

Bah, this again:
https://github.com/ggml-org/llama.cpp/actions/runs/33365844609/job/99406209639?pr=28045

@yomaytk yomaytk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

@fairydreaming
fairydreaming force-pushed the webgpu-buffer-get-offset branch from ef89f4f to 1510317 Compare August 31, 2026 07:59
Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
@fairydreaming
fairydreaming force-pushed the webgpu-buffer-get-offset branch from 1510317 to b74c0f6 Compare August 31, 2026 08:01
@fairydreaming

Copy link
Copy Markdown
Contributor Author

Bah, this again: https://github.com/ggml-org/llama.cpp/actions/runs/33365844609/job/99406209639?pr=28045

@CISC Should be OK now, but needs re-approval

@yomaytk

yomaytk commented Aug 31, 2026

Copy link
Copy Markdown
Member

Bah, this again:
https://github.com/ggml-org/llama.cpp/actions/runs/33365844609/job/99406209639?pr=28045

@fairydreaming FYI, We format the WebGPU C++ code with clangd version 22 or later. But the EditorConfig error looks like it's already been resolved :)

@fairydreaming

Copy link
Copy Markdown
Contributor Author

Bah, this again:
https://github.com/ggml-org/llama.cpp/actions/runs/33365844609/job/99406209639?pr=28045

@fairydreaming FYI, We format the WebGPU C++ code with clangd version 22 or later. But the EditorConfig error looks like it's already been resolved :)

@yomaytk Yeah, the reason was DOS/Windows EOL characters that GitHub added when I accepted @CISC review changes

@fairydreaming
fairydreaming merged commit 8e53fce into ggml-org:master Aug 31, 2026
25 of 29 checks passed
ilmmatias pushed a commit to ilmmatias/llama.cpp that referenced this pull request Sep 1, 2026
…backend_tensor_get() implementation (ggml-org#28045)

* webgpu : avoid crash when offset is not multiple of 4 in WebGPU ggml_backend_tensor_get() implementation

* chore : improve code readability

Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>

---------

Co-authored-by: Stanisław Szymczyk <sszymczy@gmail.com>
Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
fewtarius pushed a commit to fewtarius/CachyLLama that referenced this pull request Sep 5, 2026
…backend_tensor_get() implementation (ggml-org#28045)

* webgpu : avoid crash when offset is not multiple of 4 in WebGPU ggml_backend_tensor_get() implementation

* chore : improve code readability

Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>

---------

Co-authored-by: Stanisław Szymczyk <sszymczy@gmail.com>
Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
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 WebGPU

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants