Skip to content

[ET-VK] 7/n Split dispatches between multiple command buffers. Split execute dispatch into multiple commands based on dispatch count. #12530

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

Open
wants to merge 2 commits into
base: gh/trivedivivek/127/base
Choose a base branch
from
Open
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
36 changes: 23 additions & 13 deletions backends/vulkan/runtime/graph/ComputeGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,13 @@ void ComputeGraph::submit_current_cmd(const bool final_use, bool wait) {
}
}

void ComputeGraph::wait_on_encode_execute() {
if (encode_execute_fence_) {
encode_execute_fence_.wait();
context_->fences().return_fence(encode_execute_fence_);
}
}

void ComputeGraph::prepack() {
int i = 0;
bool submitted = false;
Expand All @@ -793,7 +800,7 @@ void ComputeGraph::prepack() {
submit_current_cmd(/*final_use=*/true, /*wait=*/false);
}
staging_nbytes_in_cmd_ = 0;
context_->set_cmd();
context_->set_cmd(/*reusable = */ true);
submitted = true;
}

Expand All @@ -806,30 +813,33 @@ void ComputeGraph::prepack() {
}

void ComputeGraph::encode_execute() {
wait_on_encode_execute();
context_->flush();
context_->set_cmd(/*reusable = */ true);

context_->cmd_reset_querypool();
uint32_t encoded_node_count = 0;

for (std::unique_ptr<ExecuteNode>& node : execute_nodes_) {
node->encode(this);
encoded_node_count++;
if ((encoded_node_count % 64) == 0) {
submit_current_cmd(/*final_use=*/false, /*wait=*/false);
context_->set_cmd(true);
}
}

// Indicate execute nodes have been freshly encoded and needs to be submitted
// first
execute_pending_first_submission = true;
encode_execute_fence_ = context_->fences().get_fence();
context_->submit_cmd_to_gpu(
encode_execute_fence_.get_submit_handle(), /*final_use=*/false);
}

void ComputeGraph::execute() {
if (execute_pending_first_submission) {
submit_current_cmd(/*final_use=*/false, /*wait=*/true);
execute_pending_first_submission = false;
} else {
vkapi::VulkanFence fence = context_->fences().get_fence();
context_->submit_all_non_final_cmds(fence.get_submit_handle());
fence.wait();
context_->fences().return_fence(fence);
}
wait_on_encode_execute();
vkapi::VulkanFence fence = context_->fences().get_fence();
context_->submit_all_non_final_cmds(fence.get_submit_handle());
fence.wait();
context_->fences().return_fence(fence);
execute_count_++;
}

Expand Down
6 changes: 3 additions & 3 deletions backends/vulkan/runtime/graph/ComputeGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ class ComputeGraph final {
// current Context's command buffer is submitted now.
size_t staging_nbytes_in_cmd_ = 0;

// Flag to indicate if execute nodes have been freshly encoded and have not
// been submitted yet.
bool execute_pending_first_submission = false;
vkapi::VulkanFence encode_execute_fence_;

public:
//
Expand Down Expand Up @@ -850,6 +848,8 @@ class ComputeGraph final {
*/
void submit_current_cmd(const bool final_use = false, bool wait = true);

void wait_on_encode_execute();

public:
//
// Graph Prepacking
Expand Down
Loading