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

Buildbot test to see if we can properly unload vulkan using atexit().… #8493

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
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);
}
6 changes: 6 additions & 0 deletions src/runtime/vulkan_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include "vulkan_internal.h"
#include "vulkan_memory.h"

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

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

namespace Halide {
Expand Down Expand Up @@ -504,6 +507,9 @@ int vk_create_context(void *user_context, VulkanMemoryAllocator **allocator,
return error_code;
}

// Proof-of-concept cleanup mechanism.
atexit(halide_vulkan_cleanup);

return halide_error_code_success;
}

Expand Down