From 58c3413a30e5b03208b6281651d38ee02c44f9c1 Mon Sep 17 00:00:00 2001 From: Lunderberg Date: Mon, 10 May 2021 22:57:48 -0700 Subject: [PATCH] [Bugfix][Vulkan] Call VulkanDeviceAPI destructor on program exit (#7997) Most of the TVM Global() functions allocate with "new" and do not deallocate, as the OS can clean up any leftover buffers at the end. In this case, we need the VulkanDeviceAPI destructor to call vkDestroyInstance, to prevent a segfault on exit when using some nvidia drivers. Co-authored-by: Eric Lunderberg --- src/runtime/vulkan/vulkan.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/runtime/vulkan/vulkan.cc b/src/runtime/vulkan/vulkan.cc index d82f6f40a143..b7fe2b1ceb21 100644 --- a/src/runtime/vulkan/vulkan.cc +++ b/src/runtime/vulkan/vulkan.cc @@ -412,8 +412,13 @@ class VulkanDeviceAPI final : public DeviceAPI { } static VulkanDeviceAPI* Global() { - static VulkanDeviceAPI* inst = new VulkanDeviceAPI(); - return inst; + // Most of the TVM Global() functions allocate with "new" and do + // not deallocate, as the OS can clean up any leftover buffers at + // the end. In this case, we need the VulkanDeviceAPI destructor + // to call vkDestroyInstance, to prevent a segfault on exit when + // using some nvidia drivers. + static VulkanDeviceAPI inst; + return &inst; } const VulkanContext& context(size_t device_id) const {