Skip to content

Commit 01c8ced

Browse files
committed
Free staged parameter buffers at once
1 parent 04d7b27 commit 01c8ced

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

ggml/src/ggml-webgpu/ggml-webgpu.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ struct webgpu_param_buf_pool {
7676
return bufs;
7777
}
7878

79-
void free_bufs(const webgpu_param_bufs& bufs) {
79+
void free_bufs(std::vector<webgpu_param_bufs> bufs) {
8080
std::lock_guard<std::mutex> lock(mutex);
81-
free.push_back(bufs);
82-
cv.notify_one();
81+
free.insert(free.end(), bufs.begin(), bufs.end());
82+
cv.notify_all();
8383
}
8484

8585
void cleanup() {
@@ -222,9 +222,7 @@ static void ggml_backend_webgpu_submit_queue(webgpu_context& ctx) {
222222
GGML_LOG_ERROR("ggml_webgpu: Failed to submit commands: %s\n", message.data);
223223
}
224224
// Free the staged parameter buffers
225-
for (const auto& bufs : staged_param_bufs) {
226-
ctx->param_buf_pool.free_bufs(bufs);
227-
}
225+
ctx->param_buf_pool.free_bufs(staged_param_bufs);
228226
});
229227
}
230228

@@ -287,7 +285,7 @@ static void ggml_backend_webgpu_build_and_enqueue(webgpu_context& ctx, wgpu::Com
287285
if (status != wgpu::QueueWorkDoneStatus::Success) {
288286
GGML_LOG_ERROR("ggml_webgpu: Failed to submit commands: %s\n", message.data);
289287
}
290-
ctx->param_buf_pool.free_bufs(params_bufs);
288+
ctx->param_buf_pool.free_bufs({params_bufs});
291289
});
292290
} else {
293291
// Enqueue commands and only submit if we have enough staged commands

0 commit comments

Comments
 (0)