[webgpu] fix runtime error caused by buffer release too early#25485
Merged
[webgpu] fix runtime error caused by buffer release too early#25485
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a runtime error in the WebGPU buffer manager where buffers were being released prematurely, following optimizations introduced in #25276. The fix implements a deferred buffer release mechanism to prevent buffers from being freed while still in use.
Key changes:
- Buffers that can't be cached are now stored in a pending list instead of being immediately released
- Buffer release is deferred until the
OnRefreshmethod is called, ensuring buffers remain valid during execution - Added a new member variable to track pending buffers awaiting release
Comments suppressed due to low confidence (1)
onnxruntime/core/providers/webgpu/buffer_manager.cc:247
- The member variable 'pending_buffers' should follow the existing naming convention with a trailing underscore to match other private members like 'buckets_' and 'buckets_limit_'.
std::vector<std::pair<WGPUBuffer, size_t>> pending_buffers;
qjia7
approved these changes
Jul 22, 2025
Contributor
qjia7
left a comment
There was a problem hiding this comment.
Sorry that I though it was a revert. Now I understand the changes. LGTM. Thanks.
guschmue
approved these changes
Jul 22, 2025
sanketkaleoss
pushed a commit
to sanketkaleoss/onnxruntime
that referenced
this pull request
Aug 11, 2025
…oft#25485) ### Description Fix runtime error caused by buffer release too early ### Motivation and Context microsoft#25276 introduces buffer usage optimization, which reduced the peak GPU memory usage. However, the implementation may cause issue in some situations because the buffer is released too early. This PR fixes the issue.
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.
Description
Fix runtime error caused by buffer release too early
Motivation and Context
#25276 introduces buffer usage optimization, which reduced the peak GPU memory usage. However, the implementation may cause issue in some situations because the buffer is released too early. This PR fixes the issue.