Skip to content

Commit 0c52ca0

Browse files
committed
[ET-VK] 7/n Split dispatches between multiple command buffers. Split execute dispatch into multiple commands based on dispatch count.
Differential Revision: [D78360039](https://our.internmc.facebook.com/intern/diff/D78360039/) ghstack-source-id: 296448618 Pull Request resolved: #12530
1 parent adf5a5b commit 0c52ca0

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

backends/vulkan/runtime/graph/ComputeGraph.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,13 @@ void ComputeGraph::submit_current_cmd(const bool final_use, bool wait) {
768768
}
769769
}
770770

771+
void ComputeGraph::wait_on_encode_execute() {
772+
if (encode_execute_fence_) {
773+
encode_execute_fence_.wait();
774+
context_->fences().return_fence(encode_execute_fence_);
775+
}
776+
}
777+
771778
void ComputeGraph::prepack() {
772779
int i = 0;
773780
bool submitted = false;
@@ -793,7 +800,7 @@ void ComputeGraph::prepack() {
793800
submit_current_cmd(/*final_use=*/true, /*wait=*/false);
794801
}
795802
staging_nbytes_in_cmd_ = 0;
796-
context_->set_cmd();
803+
context_->set_cmd(/*reusable = */ true);
797804
submitted = true;
798805
}
799806

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

808815
void ComputeGraph::encode_execute() {
816+
wait_on_encode_execute();
809817
context_->flush();
810818
context_->set_cmd(/*reusable = */ true);
811819

812820
context_->cmd_reset_querypool();
821+
uint32_t encoded_node_count = 0;
813822

814823
for (std::unique_ptr<ExecuteNode>& node : execute_nodes_) {
815824
node->encode(this);
825+
encoded_node_count++;
826+
if ((encoded_node_count % 64) == 0) {
827+
submit_current_cmd(/*final_use=*/false, /*wait=*/false);
828+
context_->set_cmd(true);
829+
}
816830
}
817831

818-
// Indicate execute nodes have been freshly encoded and needs to be submitted
819-
// first
820-
execute_pending_first_submission = true;
832+
encode_execute_fence_ = context_->fences().get_fence();
833+
context_->submit_cmd_to_gpu(
834+
encode_execute_fence_.get_submit_handle(), /*final_use=*/false);
821835
}
822836

823837
void ComputeGraph::execute() {
824-
if (execute_pending_first_submission) {
825-
submit_current_cmd(/*final_use=*/false, /*wait=*/true);
826-
execute_pending_first_submission = false;
827-
} else {
828-
vkapi::VulkanFence fence = context_->fences().get_fence();
829-
context_->submit_all_non_final_cmds(fence.get_submit_handle());
830-
fence.wait();
831-
context_->fences().return_fence(fence);
832-
}
838+
wait_on_encode_execute();
839+
vkapi::VulkanFence fence = context_->fences().get_fence();
840+
context_->submit_all_non_final_cmds(fence.get_submit_handle());
841+
fence.wait();
842+
context_->fences().return_fence(fence);
833843
execute_count_++;
834844
}
835845

backends/vulkan/runtime/graph/ComputeGraph.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ class ComputeGraph final {
204204
// current Context's command buffer is submitted now.
205205
size_t staging_nbytes_in_cmd_ = 0;
206206

207-
// Flag to indicate if execute nodes have been freshly encoded and have not
208-
// been submitted yet.
209-
bool execute_pending_first_submission = true;
207+
vkapi::VulkanFence encode_execute_fence_;
210208

211209
public:
212210
//
@@ -840,6 +838,8 @@ class ComputeGraph final {
840838
*/
841839
void submit_current_cmd(const bool final_use = false, bool wait = true);
842840

841+
void wait_on_encode_execute();
842+
843843
public:
844844
//
845845
// Graph Prepacking

0 commit comments

Comments
 (0)