Skip to content

Commit 7622df0

Browse files
authored
[ET-VK][ez] Move execute node threshold calculation from prepare_pipelines() to prepare() (#13497)
Title says it all; `prepare()` is a more appropriate place for this action than `prepare_pipelines()`. ## Motivation Fix potential floating point exception (divide-by-zero) during tests. Some tests don't call `prepare_pipelines()`, which means `execute_threshold_node_count_` is unititialized, causing a divide by zero in execute when trying to modulo with `execute_threshold_node_count_` Differential Revision: [D80468138](https://our.internmc.facebook.com/intern/diff/D80468138/) [ghstack-poisoned]
1 parent fe84495 commit 7622df0

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

backends/vulkan/runtime/graph/ComputeGraph.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -813,25 +813,8 @@ void ComputeGraph::prepare() {
813813
context_->initialize_querypool();
814814
}
815815

816-
for (SharedObject& shared_object : shared_objects_) {
817-
shared_object.allocate(this);
818-
shared_object.bind_users(this);
819-
}
820-
}
821-
822-
void ComputeGraph::prepare_pipelines() {
823-
for (std::unique_ptr<PrepackNode>& node : prepack_nodes_) {
824-
node->prepare_pipelines(this);
825-
}
826-
for (std::unique_ptr<ExecuteNode>& node : execute_nodes_) {
827-
node->prepare_pipelines(this);
828-
}
829-
context_->pipeline_cache().create_pipelines(pipeline_descriptors_);
830-
831-
pipeline_descriptors_ = std::unordered_set<
832-
vkapi::ComputePipelineCache::Key,
833-
vkapi::ComputePipelineCache::Hasher>();
834-
816+
// Calculate the threshold at which a new command buffer should be created
817+
// during execute()
835818
const size_t total_node_count = execute_nodes_.size();
836819
size_t init_threshold = config_.execute_initial_threshold_node_count;
837820
size_t count_threshold = config_.execute_threshold_node_count;
@@ -858,6 +841,25 @@ void ComputeGraph::prepare_pipelines() {
858841
}
859842

860843
execute_threshold_node_count_ = count_threshold;
844+
845+
for (SharedObject& shared_object : shared_objects_) {
846+
shared_object.allocate(this);
847+
shared_object.bind_users(this);
848+
}
849+
}
850+
851+
void ComputeGraph::prepare_pipelines() {
852+
for (std::unique_ptr<PrepackNode>& node : prepack_nodes_) {
853+
node->prepare_pipelines(this);
854+
}
855+
for (std::unique_ptr<ExecuteNode>& node : execute_nodes_) {
856+
node->prepare_pipelines(this);
857+
}
858+
context_->pipeline_cache().create_pipelines(pipeline_descriptors_);
859+
860+
pipeline_descriptors_ = std::unordered_set<
861+
vkapi::ComputePipelineCache::Key,
862+
vkapi::ComputePipelineCache::Hasher>();
861863
}
862864

863865
void ComputeGraph::submit_current_cmd(const bool final_use) {

0 commit comments

Comments
 (0)