Skip to content

Commit ca0cd21

Browse files
qjia7fs-eire
andauthored
[webgpu] Use LazyRelease for prepack allocator (#27077)
BUG #27068 --------- Co-authored-by: Yulong Wang <7679871+fs-eire@users.noreply.github.com>
1 parent ec4f6bf commit ca0cd21

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

onnxruntime/core/providers/webgpu/webgpu_context.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ void WebGpuContext::Initialize(const WebGpuContextConfig& config) {
139139
config.buffer_cache_config.uniform.mode,
140140
config.buffer_cache_config.query_resolve.mode);
141141

142-
// create initializer buffer manager. cache is always disabled for initializer buffer manager
142+
// create initializer buffer manager.
143143
initializer_buffer_mgr_ = BufferManagerFactory::Create(*this,
144-
BufferCacheMode::Disabled,
145-
BufferCacheMode::Disabled,
144+
BufferCacheMode::LazyRelease,
145+
BufferCacheMode::LazyRelease,
146146
BufferCacheMode::Disabled);
147147

148148
// create program manager

onnxruntime/core/providers/webgpu/webgpu_kernel.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ Status WebGpuKernel::PrePack(const Tensor& tensor, int input_idx, AllocatorPtr /
4949

5050
Status s = PrePackInternal(context, tensor, input_idx, ep_.PrepackAllocator(), is_packed);
5151

52+
if (is_packed) {
53+
// Flush pending commands to ensure GPU buffer creations are completed.
54+
// This allows the initializer buffer manager to release temporary buffers and reduce memory usage.
55+
webgpu_context_.Flush(webgpu_context_.InitializerBufferManager());
56+
}
57+
5258
if (webgpu_context_.ValidationMode() >= ValidationMode::Full) {
5359
ORT_RETURN_IF_ERROR(webgpu_context_.PopErrorScope());
5460
}

0 commit comments

Comments
 (0)