Skip to content

Commit

Permalink
destroy_gpu_instance() function wait for all devices to be idle befor…
Browse files Browse the repository at this point in the history
…e destroy (#4763)

* destroy_gpu_instance() will internally ensure that all vulkan devices are idle before proceeding with destruction.
  • Loading branch information
whyb authored Apr 7, 2024
1 parent 5dc998e commit 3b048d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3b048d1

Please sign in to comment.