]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
vulkan: mutex around vkQueueSubmit (#14127)
authorJeff Bolz <redacted>
Mon, 16 Jun 2025 06:21:08 +0000 (00:21 -0600)
committerGitHub <redacted>
Mon, 16 Jun 2025 06:21:08 +0000 (08:21 +0200)
This fixes the remaining crash in test-thread-safety on my system.

ggml/src/ggml-vulkan/ggml-vulkan.cpp

index 32d6407441535401b4b911e67eed1dac78f55dcb..8d62303aabd7ff4c90926e9aea683704b25f0931 100644 (file)
@@ -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<std::mutex> 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<std::mutex> guard(queue_mutex);
     ctx->p->q->queue.submit(submit_infos, fence);
 
     ctx->seqs.clear();