Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions backends/vulkan/runtime/api/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,14 @@ void Context::submit_cmd_to_gpu(VkFence fence_handle, const bool final_use) {
}
}

void Context::flush() {
void Context::wait_for_queue() {
VK_CHECK(vkQueueWaitIdle(queue().handle));
}

void Context::clear_resources() {
command_pool_.flush();
descriptor_pool_.flush();

// If there is an existing command buffer, invalidate it
if (cmd_) {
cmd_.invalidate();
}
Expand All @@ -243,6 +244,11 @@ void Context::flush() {
images_to_clear_.clear();
}

void Context::flush() {
wait_for_queue();
clear_resources();
}

bool available() {
return context();
}
Expand Down
4 changes: 4 additions & 0 deletions backends/vulkan/runtime/api/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ class Context final {
return cmd_;
}

void wait_for_queue();

void clear_resources();

void flush();

#if defined(VK_KHR_pipeline_executable_properties) && \
Expand Down
19 changes: 14 additions & 5 deletions backends/vulkan/runtime/graph/ComputeGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,22 @@ ComputeGraph::ComputeGraph(GraphConfig config)
}

ComputeGraph::~ComputeGraph() {
values_.clear();
// Wait for all currently executing commands to complete before cleaning up.
// If wait_for_queue() throws an exception, still proceed with cleanup.
try {
context_->wait_for_queue();
} catch (...) {
}

prepack_nodes_.clear();
execute_nodes_.clear();
clear_deferred_cmds();
// Wrap in try/catch to ensure that destructor does not throw
try {
values_.clear();

context_->flush();
prepack_nodes_.clear();
execute_nodes_.clear();
clear_deferred_cmds();
} catch (...) {
}
}

std::vector<int64_t> ComputeGraph::extract_int_or_symint_list(
Expand Down
Loading