Skip to content

Commit

Permalink
Buildbot test to see if we can properly unload vulkan using atexit().…
Browse files Browse the repository at this point in the history
… super hacky Proof-of-concept.
  • Loading branch information
mcourteaux committed Nov 27, 2024
1 parent 166cd92 commit 1c0617f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/runtime/vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1397,21 +1397,6 @@ WEAK __attribute__((constructor)) void register_vulkan_allocation_pool() {
halide_register_device_allocation_pool(&vulkan_allocation_pool);
}

WEAK __attribute__((destructor)) void halide_vulkan_cleanup() {
// FIXME: When the VK_LAYER_KHRONOS_validation is intercepting calls to the API, it will
// cause a segfault if it's invoked inside the destructor since it uses it's own global
// state to track object usage which is no longer valid once this call is invoked.
// Calling this destructor with the validator hooks in place will cause an uncaught
// exception for an uninitialized mutex lock. We can avoid the crash on exit by \
// bypassing the device release call and leak (!!!!)
// ISSUE: https://github.com/halide/Halide/issues/8290
const char *layer_names = vk_get_layer_names_internal(nullptr);
bool has_validation_layer = strstr(layer_names, "VK_LAYER_KHRONOS_validation");
if (!has_validation_layer) {
halide_vulkan_device_release(nullptr);
}
}

// --------------------------------------------------------------------------

} // namespace
Expand Down Expand Up @@ -1472,3 +1457,7 @@ WEAK halide_device_interface_t vulkan_device_interface = {
} // namespace Internal
} // namespace Runtime
} // namespace Halide

WEAK void halide_vulkan_cleanup() {
halide_vulkan_device_release(nullptr);
}
4 changes: 4 additions & 0 deletions src/runtime/vulkan_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
// Vulkan API Definition
// --------------------------------------------------------------------------

extern "C" WEAK void atexit(void (*fn)());
WEAK void halide_vulkan_cleanup();

namespace Halide {
namespace Runtime {
namespace Internal {
Expand Down Expand Up @@ -66,6 +69,7 @@ extern "C" WEAK void *halide_vulkan_get_symbol(void *user_context, const char *n
lib_vulkan = halide_load_library(lib_name);
if (lib_vulkan) {
debug(user_context) << " Loaded Vulkan loader library: " << lib_name << "\n";
atexit(halide_vulkan_cleanup);
break;
} else {
debug(user_context) << " Missing Vulkan loader library: " << lib_name << "\n";
Expand Down

0 comments on commit 1c0617f

Please sign in to comment.