Skip to content

Commit

Permalink
[Bugfix][Vulkan] Call VulkanDeviceAPI destructor on program exit (apa…
Browse files Browse the repository at this point in the history
…che#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 <elunderberg@octoml.ai>
  • Loading branch information
2 people authored and Trevor Morris committed Jun 17, 2021
1 parent 1823f35 commit d16f361
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 d16f361

Please sign in to comment.