From 3b048d1923bf34c87a082fbca417d4448568391a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=B5=E5=B0=8F=E5=87=A1?= <2672931+whyb@users.noreply.github.com> Date: Sun, 7 Apr 2024 23:19:27 +0800 Subject: [PATCH] destroy_gpu_instance() function wait for all devices to be idle before destroy (#4763) * destroy_gpu_instance() will internally ensure that all vulkan devices are idle before proceeding with destruction. --- src/gpu.cpp | 13 +++++++++++++ src/gpu.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/gpu.cpp b/src/gpu.cpp index 6daf45c8512..77a63f4b3be 100644 --- a/src/gpu.cpp +++ b/src/gpu.cpp @@ -2091,6 +2091,19 @@ void destroy_gpu_instance() if (g_instance.created == 0) return; + for (int i = 0; i < NCNN_MAX_GPU_COUNT; i++) + { + VulkanDevice* vulkan_device = g_default_vkdev[i]; + if (vulkan_device) + { + VkDevice vkdev = g_default_vkdev[i]->vkdevice(); + if (vkdev) + { + vkDeviceWaitIdle(vkdev); + } + } + } + // NCNN_LOGE("destroy_gpu_instance"); if (g_instance.glslang_initialized) diff --git a/src/gpu.h b/src/gpu.h index a8d7ff91fdf..4d131f71c8b 100644 --- a/src/gpu.h +++ b/src/gpu.h @@ -37,6 +37,7 @@ NCNN_EXPORT VkInstance get_gpu_instance(); // Destroy VkInstance object and free the memory of the associated object // Usually called in the destructor of the main program exit +// The function will internally ensure that all vulkan devices are idle before proceeding with destruction. NCNN_EXPORT void destroy_gpu_instance(); // vulkan core