Skip to content

Commit c89c2d1

Browse files
authored
vulkan: mutex around vkQueueSubmit (#14127)
This fixes the remaining crash in test-thread-safety on my system.
1 parent 3555b30 commit c89c2d1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ struct vk_command_pool {
168168
vk_queue *q;
169169
};
170170

171+
// Prevent simultaneous submissions to the same queue.
172+
// This could be per vk_queue if we stopped having two vk_queue structures
173+
// sharing the same vk::Queue.
174+
static std::mutex queue_mutex;
175+
171176
struct vk_queue {
172177
uint32_t queue_family_index;
173178
vk::Queue queue;
@@ -1266,6 +1271,7 @@ static vk::CommandBuffer ggml_vk_create_cmd_buffer(vk_device& device, vk_command
12661271
static void ggml_vk_submit(vk_context& ctx, vk::Fence fence) {
12671272
if (ctx->seqs.empty()) {
12681273
if (fence) {
1274+
std::lock_guard<std::mutex> guard(queue_mutex);
12691275
ctx->p->q->queue.submit({}, fence);
12701276
}
12711277
return;
@@ -1335,6 +1341,7 @@ static void ggml_vk_submit(vk_context& ctx, vk::Fence fence) {
13351341
}
13361342
}
13371343

1344+
std::lock_guard<std::mutex> guard(queue_mutex);
13381345
ctx->p->q->queue.submit(submit_infos, fence);
13391346

13401347
ctx->seqs.clear();

0 commit comments

Comments
 (0)