@@ -151,6 +151,10 @@ ComputeGraph::ComputeGraph(GraphConfig config)
151151 config_.prepack_threshold_nbytes = 10 * MB;
152152 config_.prepack_initial_threshold_nbytes = 10 * MB;
153153 }
154+ if (config_.execute_threshold_node_count == 0 ) {
155+ config_.execute_threshold_node_count = 128 ;
156+ config_.execute_initial_threshold_node_count = 64 ;
157+ }
154158}
155159
156160ComputeGraph::~ComputeGraph () {
@@ -852,15 +856,38 @@ void ComputeGraph::execute() {
852856 context_->set_cmd (/* reusable = */ true );
853857
854858 context_->cmd_reset_querypool ();
859+ uint32_t encoded_node_count = 0 ;
855860
856861 for (std::unique_ptr<ExecuteNode>& node : execute_nodes_) {
857862 node->encode (this );
863+ encoded_node_count++;
864+
865+ // Threshold is reached when the node count reached
866+ // execute_initial_threshold_node_count or if its a multiple of
867+ // execute_threshold_node_count.
868+ const bool reached_threshold =
869+ encoded_node_count >= config_.execute_initial_threshold_node_count &&
870+ ((encoded_node_count - config_.execute_initial_threshold_node_count ) %
871+ config_.execute_threshold_node_count ==
872+ 0 );
873+
874+ // Create a new command buffer when threashold is reached
875+ if (reached_threshold) {
876+ context_->submit_cmd_to_gpu (VK_NULL_HANDLE, false );
877+ deferred_cmd_list_.emplace_back (std::move (context_->extract_cmd ()));
878+ context_->set_cmd (true );
879+ }
858880 }
859881
882+ vkapi::VulkanFence fence = context_->fences ().get_fence ();
883+ context_->submit_cmd_to_gpu (fence.get_submit_handle (), false );
884+ fence.wait ();
885+ context_->fences ().return_fence (fence);
860886 deferred_cmd_list_.emplace_back (std::move (context_->extract_cmd ()));
887+ } else {
888+ submit_deferred_cmds_and_wait ();
861889 }
862890
863- submit_deferred_cmds_and_wait ();
864891 execute_count_++;
865892}
866893
0 commit comments