Skip to content

Commit 135a0f4

Browse files
committed
[ET-VK] 6/n Split dispatches between multiple command buffers. Repurpose submit_current_cmd_and_wait to wait based on input flag.
This diff makes changes to the `submit_current_cmd_and_wait` function in the `ComputeGraph` class to repurpose it to wait for command buffer completion based on an input flag. The function is renamed to `submit_current_cmd` and now takes an additional `wait` parameter. If `wait` is `true`, the function submits the command buffer to the GPU and waits for its completion. Otherwise, it only submits the command buffer without waiting. Differential Revision: [D78360042](https://our.internmc.facebook.com/intern/diff/D78360042/) ghstack-source-id: 296443189 Pull Request resolved: #12529
1 parent 7754797 commit 135a0f4

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

backends/vulkan/runtime/graph/ComputeGraph.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -759,11 +759,16 @@ void ComputeGraph::prepare_pipelines() {
759759
vkapi::ComputePipelineCache::Hasher>();
760760
}
761761

762-
void ComputeGraph::submit_current_cmd_and_wait(const bool final_use) {
763-
vkapi::VulkanFence fence = context_->fences().get_fence();
764-
context_->submit_cmd_to_gpu(fence.get_submit_handle(), final_use);
765-
fence.wait();
766-
context_->fences().return_fence(fence);
762+
void ComputeGraph::submit_current_cmd(const bool final_use, bool wait) {
763+
if (wait) {
764+
// Submit and wait for command buffer
765+
vkapi::VulkanFence fence = context_->fences().get_fence();
766+
context_->submit_cmd_to_gpu(fence.get_submit_handle(), final_use);
767+
fence.wait();
768+
context_->fences().return_fence(fence);
769+
} else {
770+
context_->submit_cmd_to_gpu(VK_NULL_HANDLE, final_use);
771+
}
767772
}
768773

769774
void ComputeGraph::encode_prepack() {
@@ -772,13 +777,9 @@ void ComputeGraph::encode_prepack() {
772777
}
773778
}
774779

775-
void ComputeGraph::prepack() const {
780+
void ComputeGraph::prepack() {
776781
// Submit and execute the command buffer
777-
vkapi::VulkanFence fence = context_->fences().get_fence();
778-
context_->submit_cmd_to_gpu(fence.get_submit_handle(), /*final_use = */ true);
779-
fence.wait();
780-
context_->fences().return_fence(fence);
781-
782+
submit_current_cmd(/*final_use = */ true, /*wait = */ true);
782783
context_->flush();
783784
}
784785

@@ -791,7 +792,7 @@ void ComputeGraph::run_prepack() {
791792
size_t threshold = submitted ? config_.prepack_threshold_nbytes
792793
: config_.prepack_initial_threshold_nbytes;
793794
if (not_terminal && staging_nbytes_in_cmd_ > threshold) {
794-
submit_current_cmd_and_wait(/*final_use=*/true);
795+
submit_current_cmd(/*final_use=*/true, /*wait=*/true);
795796
context_->flush();
796797
staging_nbytes_in_cmd_ = 0;
797798
context_->set_cmd();
@@ -801,7 +802,7 @@ void ComputeGraph::run_prepack() {
801802
node->encode(this);
802803
i++;
803804
}
804-
submit_current_cmd_and_wait(/*final_use=*/true);
805+
submit_current_cmd(/*final_use=*/true, /*wait=*/true);
805806
context_->flush();
806807
staging_nbytes_in_cmd_ = 0;
807808
}
@@ -823,7 +824,7 @@ void ComputeGraph::encode_execute() {
823824

824825
void ComputeGraph::execute() {
825826
if (execute_pending_first_submission) {
826-
submit_current_cmd_and_wait(/*final_use=*/false);
827+
submit_current_cmd(/*final_use=*/false, /*wait=*/true);
827828
execute_pending_first_submission = false;
828829
} else {
829830
vkapi::VulkanFence fence = context_->fences().get_fence();

backends/vulkan/runtime/graph/ComputeGraph.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,9 @@ class ComputeGraph final {
825825

826826
/*
827827
* Submits the current command buffer in the Context to the GPU for execution,
828-
* and wait for it to complete before returning.
828+
* and wait for it to complete before returning, if wait is True.
829829
*/
830-
void submit_current_cmd_and_wait(const bool final_use = false);
830+
void submit_current_cmd(const bool final_use = false, bool wait = true);
831831

832832
public:
833833
//
@@ -839,7 +839,7 @@ class ComputeGraph final {
839839
}
840840

841841
void encode_prepack();
842-
void prepack() const;
842+
void prepack();
843843

844844
/*
845845
* Executes prepacking operations to transfer model weight data from the CPU

0 commit comments

Comments
 (0)