Skip to content

Commit

Permalink
[Bugfix][Vulkan] Call VulkanDeviceAPI destructor on program exit (#7997)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Lunderberg and Lunderberg committed May 11, 2021
1 parent 7b49744 commit 58c3413
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/runtime/vulkan/vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 58c3413

Please sign in to comment.