From 01c8ced232fffdd670a3919741cabdc4e9a63b9f Mon Sep 17 00:00:00 2001 From: Reese Levine Date: Wed, 30 Jul 2025 14:27:29 -0700 Subject: [PATCH] Free staged parameter buffers at once --- ggml/src/ggml-webgpu/ggml-webgpu.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/ggml/src/ggml-webgpu/ggml-webgpu.cpp b/ggml/src/ggml-webgpu/ggml-webgpu.cpp index a3f41da1b1..dcc32e88ef 100644 --- a/ggml/src/ggml-webgpu/ggml-webgpu.cpp +++ b/ggml/src/ggml-webgpu/ggml-webgpu.cpp @@ -76,10 +76,10 @@ struct webgpu_param_buf_pool { return bufs; } - void free_bufs(const webgpu_param_bufs& bufs) { + void free_bufs(std::vector bufs) { std::lock_guard lock(mutex); - free.push_back(bufs); - cv.notify_one(); + free.insert(free.end(), bufs.begin(), bufs.end()); + cv.notify_all(); } void cleanup() { @@ -222,9 +222,7 @@ static void ggml_backend_webgpu_submit_queue(webgpu_context& ctx) { GGML_LOG_ERROR("ggml_webgpu: Failed to submit commands: %s\n", message.data); } // Free the staged parameter buffers - for (const auto& bufs : staged_param_bufs) { - ctx->param_buf_pool.free_bufs(bufs); - } + ctx->param_buf_pool.free_bufs(staged_param_bufs); }); } @@ -287,7 +285,7 @@ static void ggml_backend_webgpu_build_and_enqueue(webgpu_context& ctx, wgpu::Com if (status != wgpu::QueueWorkDoneStatus::Success) { GGML_LOG_ERROR("ggml_webgpu: Failed to submit commands: %s\n", message.data); } - ctx->param_buf_pool.free_bufs(params_bufs); + ctx->param_buf_pool.free_bufs({params_bufs}); }); } else { // Enqueue commands and only submit if we have enough staged commands