Skip to content

fix the case where the buffer for past_state == present_state#28753

Merged
guschmue merged 2 commits into
mainfrom
gs/lattm-shared-buffer
Jun 3, 2026
Merged

fix the case where the buffer for past_state == present_state#28753
guschmue merged 2 commits into
mainfrom
gs/lattm-shared-buffer

Conversation

@guschmue

@guschmue guschmue commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

in the case we pass the same buffer for past_state and present_state, dawn complains about the buffer bound as input/RO and the same buffer being bound as output/RW.

@guschmue guschmue added the ep:WebGPU ort-web webgpu provider label Jun 2, 2026
@guschmue
guschmue requested a review from Copilot June 2, 2026 17:31

Copilot AI 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.

Pull request overview

This PR addresses a WebGPU/Dawn validation issue that occurs when past_state and present_state alias the same underlying buffer, which previously caused the same buffer to be bound twice with incompatible access modes (RO input + RW output). The fix avoids dual-binding by re-routing reads to the output binding (when safe) and, for causal conv, splitting state update into a follow-up dispatch when in-place aliasing is detected.

Changes:

  • LinearAttention: when past_state aliases present_state, stop binding initial_state as an input and instead read the initial state from present_state in the shader.
  • CausalConvWithState: when conv_state aliases present_state, skip writing present_state in the main convolution shader and run a second shader dispatch to update state in-place.
  • Extend shader template parameters / cache hints to account for the new aliasing modes and generated shader variants.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
onnxruntime/contrib_ops/webgpu/bert/linear_attention.wgsl.template Adds a template-controlled path to load the initial state from present_state when buffers alias.
onnxruntime/contrib_ops/webgpu/bert/linear_attention.h Extends LinearAttentionProgram to carry the aliasing flag into shader generation.
onnxruntime/contrib_ops/webgpu/bert/linear_attention.cc Detects aliasing, adjusts bindings, and adds the new template parameter and cache hint component.
onnxruntime/contrib_ops/webgpu/bert/causal_conv_with_state.wgsl.template Wraps present_state writes with a template flag so it can be disabled when aliasing would cause RO/RW dual-bind.
onnxruntime/contrib_ops/webgpu/bert/causal_conv_with_state.h Adds an output_present_state flag to the main program and introduces a dedicated update-state program.
onnxruntime/contrib_ops/webgpu/bert/causal_conv_with_state.cc Detects aliasing, conditionally omits present_state output binding, and runs a second dispatch to update state when needed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread onnxruntime/contrib_ops/webgpu/bert/causal_conv_with_state.h
@guschmue
guschmue merged commit e26ad80 into main Jun 3, 2026
87 of 88 checks passed
@guschmue
guschmue deleted the gs/lattm-shared-buffer branch June 3, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ep:WebGPU ort-web webgpu provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants