Skip to content

Commit adf5a5b

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.
Pull Request resolved: #12529 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. ghstack-source-id: 296448615 @exported-using-ghexport Differential Revision: [D78360042](https://our.internmc.facebook.com/intern/diff/D78360042/)
1 parent 65701ab commit adf5a5b

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

backends/vulkan/runtime/graph/ComputeGraph.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -756,15 +756,16 @@ void ComputeGraph::prepare_pipelines() {
756756
vkapi::ComputePipelineCache::Hasher>();
757757
}
758758

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

770771
void ComputeGraph::prepack() {
@@ -786,10 +787,10 @@ void ComputeGraph::prepack() {
786787
// proceed. This results in lower load latency at the cost of higher peak
787788
// memory usage.
788789
if (reduce_peak_memory) {
789-
submit_current_cmd_and_wait();
790+
submit_current_cmd(/*final_use=*/true, /*wait=*/true);
790791
context_->flush();
791792
} else {
792-
submit_current_cmd();
793+
submit_current_cmd(/*final_use=*/true, /*wait=*/false);
793794
}
794795
staging_nbytes_in_cmd_ = 0;
795796
context_->set_cmd();
@@ -799,7 +800,7 @@ void ComputeGraph::prepack() {
799800
node->encode(this);
800801
i++;
801802
}
802-
submit_current_cmd_and_wait(/*final_use=*/true);
803+
submit_current_cmd(/*final_use=*/true, /*wait=*/true);
803804
context_->flush();
804805
staging_nbytes_in_cmd_ = 0;
805806
}
@@ -821,7 +822,7 @@ void ComputeGraph::encode_execute() {
821822

822823
void ComputeGraph::execute() {
823824
if (execute_pending_first_submission) {
824-
submit_current_cmd_and_wait(/*final_use=*/false);
825+
submit_current_cmd(/*final_use=*/false, /*wait=*/true);
825826
execute_pending_first_submission = false;
826827
} else {
827828
vkapi::VulkanFence fence = context_->fences().get_fence();

backends/vulkan/runtime/graph/ComputeGraph.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,9 @@ class ComputeGraph final {
836836

837837
/*
838838
* Submits the current command buffer in the Context to the GPU for execution,
839-
* and wait for it to complete before returning.
839+
* and wait for it to complete before returning, if wait is True.
840840
*/
841-
void submit_current_cmd_and_wait(const bool final_use = false);
841+
void submit_current_cmd(const bool final_use = false, bool wait = true);
842842

843843
public:
844844
//

0 commit comments

Comments
 (0)