Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

free staging buffer early #22943

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions onnxruntime/core/providers/webgpu/buffer_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ constexpr std::initializer_list<std::pair<const size_t, size_t>> BUCKET_DEFAULT_
{4194304, 20},
{8388608, 10},
{12582912, 10},
{16777216, 10},
{16777216, 20},
{26214400, 15},
{33554432, 22},
{44236800, 2},
Expand Down Expand Up @@ -256,15 +256,14 @@ void BufferManager::Upload(void* src, WGPUBuffer dst, size_t size) {
desc.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::MapWrite;
desc.mappedAtCreation = true;

auto staging_buffer = context_.Device().CreateBuffer(&desc);
wgpu::Buffer staging_buffer = context_.Device().CreateBuffer(&desc);
auto mapped_data = staging_buffer.GetMappedRange();
memcpy(mapped_data, src, size);
staging_buffer.Unmap();

auto& command_encoder = context_.GetCommandEncoder();
context_.EndComputePass();
command_encoder.CopyBufferToBuffer(staging_buffer, 0, dst, 0, buffer_size);
pending_staging_buffers_.push_back(staging_buffer);
context_.Flush();
}

void BufferManager::MemCpy(WGPUBuffer src, WGPUBuffer dst, size_t size) {
Expand Down Expand Up @@ -330,7 +329,6 @@ void BufferManager::Download(WGPUBuffer src, void* dst, size_t size) {
}

void BufferManager::RefreshPendingBuffers() {
pending_staging_buffers_.clear();
storage_cache_->OnRefresh();
uniform_cache_->OnRefresh();
query_resolve_cache_->OnRefresh();
Expand Down
2 changes: 0 additions & 2 deletions onnxruntime/core/providers/webgpu/buffer_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ class BufferManager {
std::unique_ptr<IBufferCacheManager> uniform_cache_;
std::unique_ptr<IBufferCacheManager> query_resolve_cache_;
std::unique_ptr<IBufferCacheManager> default_cache_;

std::vector<wgpu::Buffer> pending_staging_buffers_;
};

class BufferManagerFactory {
Expand Down
Loading