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 eb31b44
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ add_app(hist)
add_app(iir_blur)
add_app(interpolate)
add_app(lens_blur)
add_app(linear_algebra)
# add_app(linear_algebra)
# add_app(linear_blur) # TODO(#5374): missing CMake build
add_app(local_laplacian)
add_app(max_filter)
Expand Down
18 changes: 4 additions & 14 deletions src/runtime/vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1397,20 +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);
}
}

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

Expand Down Expand Up @@ -1472,3 +1458,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);
}
5 changes: 5 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 All @@ -46,6 +49,7 @@ extern WEAK halide_device_interface_t vulkan_device_interface;
// the Vulkan loader shared library/DLL, and then get the symbol from it.
WEAK void *lib_vulkan = nullptr;


extern "C" WEAK void *halide_vulkan_get_symbol(void *user_context, const char *name) {
// Only try to load the library if the library isn't already
// loaded, or we can't load the symbol from the process already.
Expand All @@ -66,6 +70,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 eb31b44

Please sign in to comment.