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

[RUNTIME][VULKAN] Seg fault in WorkspacePool's destructor (#5632) #5636

Merged
merged 2 commits into from
May 21, 2020
Merged
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
11 changes: 7 additions & 4 deletions src/runtime/vulkan/vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -75,7 +77,7 @@ class VulkanThreadEntry {
}

TVMContext ctx;
WorkspacePool pool;
std::unique_ptr<WorkspacePool> pool;
VulkanStream* Stream(size_t device_id);
VulkanStagingBuffer* StagingBuffer(int device_id, size_t size);

Expand Down Expand Up @@ -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<VulkanDeviceAPI>& Global() {
Expand Down Expand Up @@ -999,7 +1001,8 @@ VulkanStagingBuffer* VulkanThreadEntry::StagingBuffer(int device_id, size_t size
}

VulkanThreadEntry::VulkanThreadEntry()
: pool(static_cast<DLDeviceType>(kDLVulkan), VulkanDeviceAPI::Global()) {
: pool(std::make_unique<WorkspacePool>(static_cast<DLDeviceType>(kDLVulkan),
VulkanDeviceAPI::Global())) {
ctx.device_id = 0;
ctx.device_type = static_cast<DLDeviceType>(kDLVulkan);
}
Expand Down