From 5dc9b50200b8917b27c5336b109026fc0bcb4d2e Mon Sep 17 00:00:00 2001 From: ssjia Date: Mon, 18 Aug 2025 10:28:07 -0700 Subject: [PATCH] [ET-VK][ez] Move execute node threshold calculation from `prepare_pipelines()` to `prepare()` 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] --- .../vulkan/runtime/graph/ComputeGraph.cpp | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/backends/vulkan/runtime/graph/ComputeGraph.cpp b/backends/vulkan/runtime/graph/ComputeGraph.cpp index acd20c9ee44..33bfe8e3675 100644 --- a/backends/vulkan/runtime/graph/ComputeGraph.cpp +++ b/backends/vulkan/runtime/graph/ComputeGraph.cpp @@ -813,25 +813,8 @@ void ComputeGraph::prepare() { context_->initialize_querypool(); } - for (SharedObject& shared_object : shared_objects_) { - shared_object.allocate(this); - shared_object.bind_users(this); - } -} - -void ComputeGraph::prepare_pipelines() { - for (std::unique_ptr& node : prepack_nodes_) { - node->prepare_pipelines(this); - } - for (std::unique_ptr& node : execute_nodes_) { - node->prepare_pipelines(this); - } - context_->pipeline_cache().create_pipelines(pipeline_descriptors_); - - pipeline_descriptors_ = std::unordered_set< - vkapi::ComputePipelineCache::Key, - vkapi::ComputePipelineCache::Hasher>(); - + // Calculate the threshold at which a new command buffer should be created + // during execute() const size_t total_node_count = execute_nodes_.size(); size_t init_threshold = config_.execute_initial_threshold_node_count; size_t count_threshold = config_.execute_threshold_node_count; @@ -858,6 +841,25 @@ void ComputeGraph::prepare_pipelines() { } execute_threshold_node_count_ = count_threshold; + + for (SharedObject& shared_object : shared_objects_) { + shared_object.allocate(this); + shared_object.bind_users(this); + } +} + +void ComputeGraph::prepare_pipelines() { + for (std::unique_ptr& node : prepack_nodes_) { + node->prepare_pipelines(this); + } + for (std::unique_ptr& node : execute_nodes_) { + node->prepare_pipelines(this); + } + context_->pipeline_cache().create_pipelines(pipeline_descriptors_); + + pipeline_descriptors_ = std::unordered_set< + vkapi::ComputePipelineCache::Key, + vkapi::ComputePipelineCache::Hasher>(); } void ComputeGraph::submit_current_cmd(const bool final_use) {