From a3d1c55c66363b166142c57ea7a7043cf5d025d1 Mon Sep 17 00:00:00 2001 From: Jeff Bolz Date: Mon, 16 Jun 2025 00:21:08 -0600 Subject: [PATCH] vulkan: mutex around vkQueueSubmit (llama/14127) This fixes the remaining crash in test-thread-safety on my system. --- ggml/src/ggml-vulkan/ggml-vulkan.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vulkan.cpp index 32d64074..8d62303a 100644 --- a/ggml/src/ggml-vulkan/ggml-vulkan.cpp +++ b/ggml/src/ggml-vulkan/ggml-vulkan.cpp @@ -168,6 +168,11 @@ struct vk_command_pool { vk_queue *q; }; +// Prevent simultaneous submissions to the same queue. +// This could be per vk_queue if we stopped having two vk_queue structures +// sharing the same vk::Queue. +static std::mutex queue_mutex; + struct vk_queue { uint32_t queue_family_index; vk::Queue queue; @@ -1266,6 +1271,7 @@ static vk::CommandBuffer ggml_vk_create_cmd_buffer(vk_device& device, vk_command static void ggml_vk_submit(vk_context& ctx, vk::Fence fence) { if (ctx->seqs.empty()) { if (fence) { + std::lock_guard guard(queue_mutex); ctx->p->q->queue.submit({}, fence); } return; @@ -1335,6 +1341,7 @@ static void ggml_vk_submit(vk_context& ctx, vk::Fence fence) { } } + std::lock_guard guard(queue_mutex); ctx->p->q->queue.submit(submit_infos, fence); ctx->seqs.clear();