Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix destroy_gpu_instance crash #5353

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class __ncnn_vulkan_instance_holder
{
instance = 0;
created = 0;
glslang_initialized = false;

#if NCNN_VULKAN_LOADER
libvulkan = 0;
Expand All @@ -76,6 +77,7 @@ class __ncnn_vulkan_instance_holder

VkInstance instance;
int created;
bool glslang_initialized;

#if ENABLE_VALIDATION_LAYER
VkDebugUtilsMessengerEXT callback;
Expand Down Expand Up @@ -2061,7 +2063,7 @@ int create_gpu_instance(const char* driver_path)
// the default gpu device
g_default_gpu_index = find_default_vulkan_device_index();

glslang::InitializeProcess();
g_instance.glslang_initialized = glslang::InitializeProcess();

// the global __ncnn_vulkan_instance_holder destructor will call destroy_gpu_instance() on exit
// but it seems to be too late for nvidia driver :(
Expand Down Expand Up @@ -2091,7 +2093,8 @@ void destroy_gpu_instance()

// NCNN_LOGE("destroy_gpu_instance");

glslang::FinalizeProcess();
if (g_instance.glslang_initialized)
glslang::FinalizeProcess();
nihui marked this conversation as resolved.
Show resolved Hide resolved

for (int i = 0; i < NCNN_MAX_GPU_COUNT; i++)
{
Expand All @@ -2110,7 +2113,8 @@ void destroy_gpu_instance()
}
#endif // ENABLE_VALIDATION_LAYER

vkDestroyInstance(g_instance, 0);
if (vkDestroyInstance)
vkDestroyInstance(g_instance, 0);

g_instance.instance = 0;

Expand Down
Loading