From 338b6263100999224fb85cd468fa6bae8118966d Mon Sep 17 00:00:00 2001 From: Yi Wang Date: Wed, 20 May 2020 13:23:53 -0700 Subject: [PATCH] [RUNTIME][VULKAN] Seg fault in WorkspacePool's destructor (#5632) * fixed this issue by changing WorkspacePool's destruction order --- src/runtime/vulkan/vulkan.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/runtime/vulkan/vulkan.cc b/src/runtime/vulkan/vulkan.cc index 207a86a71c92..93e066031480 100644 --- a/src/runtime/vulkan/vulkan.cc +++ b/src/runtime/vulkan/vulkan.cc @@ -56,6 +56,8 @@ class VulkanThreadEntry { // the instance and device get destroyed. // The destruction need to be manually called // to ensure the destruction order. + + pool.reset(); streams_.clear(); for (const auto& kv : staging_buffers_) { if (!kv.second) { @@ -75,7 +77,7 @@ class VulkanThreadEntry { } TVMContext ctx; - WorkspacePool pool; + std::unique_ptr pool; VulkanStream* Stream(size_t device_id); VulkanStagingBuffer* StagingBuffer(int device_id, size_t size); @@ -331,11 +333,11 @@ class VulkanDeviceAPI final : public DeviceAPI { } void* AllocWorkspace(TVMContext ctx, size_t size, DLDataType type_hint) final { - return VulkanThreadEntry::ThreadLocal()->pool.AllocWorkspace(ctx, size); + return VulkanThreadEntry::ThreadLocal()->pool->AllocWorkspace(ctx, size); } void FreeWorkspace(TVMContext ctx, void* data) final { - VulkanThreadEntry::ThreadLocal()->pool.FreeWorkspace(ctx, data); + VulkanThreadEntry::ThreadLocal()->pool->FreeWorkspace(ctx, data); } static const std::shared_ptr& Global() { @@ -999,7 +1001,7 @@ VulkanStagingBuffer* VulkanThreadEntry::StagingBuffer(int device_id, size_t size } VulkanThreadEntry::VulkanThreadEntry() - : pool(static_cast(kDLVulkan), VulkanDeviceAPI::Global()) { + : pool(std::make_unique(static_cast(kDLVulkan), VulkanDeviceAPI::Global())) { ctx.device_id = 0; ctx.device_type = static_cast(kDLVulkan); }