diff --git a/inference-engine/src/cldnn_engine/cldnn_program.cpp b/inference-engine/src/cldnn_engine/cldnn_program.cpp index 57e96a14201..22a55d743bd 100644 --- a/inference-engine/src/cldnn_engine/cldnn_program.cpp +++ b/inference-engine/src/cldnn_engine/cldnn_program.cpp @@ -325,28 +325,24 @@ void Program::InitProfileInfo(const std::string& layerName, // TODO: Does it make sense to add such method to ngraph core? bool IsNodeOnConstPath(const std::shared_ptr& node) { - std::list> nodes_to_process = { node }; - while (!nodes_to_process.empty()) { - auto current_node = nodes_to_process.front(); - nodes_to_process.pop_front(); - - for (size_t i = 0; i < current_node->get_input_size(); i++) { - auto input_node = current_node->get_input_node_shared_ptr(i); - - // If input is constant, then drop if from the processing list - if (std::dynamic_pointer_cast(input_node) != nullptr) - continue; - - // If the node doesn't have any parents and it's not a constant, then we deal with dynamic path - if (input_node->get_input_size() == 0) { + std::set> nodes_processed = {}; + std::function&)> is_const_node = [&nodes_processed, &is_const_node](const std::shared_ptr& node) { + if (nodes_processed.count(node)) return true; + nodes_processed.insert(node); + // If input is constant, then drop if from the processing list + if (std::dynamic_pointer_cast(node) != nullptr) + return true; + // If the node doesn't have any parents and it's not a constant, then we deal with dynamic path + if (node->get_input_size() == 0) + return false; + for (size_t i = 0; i < node->get_input_size(); i++) { + auto input_node = node->get_input_node_shared_ptr(i); + if (!is_const_node(input_node)) return false; - } - - nodes_to_process.insert(nodes_to_process.end(), input_node); } - } - - return true; + return true; + }; + return is_const_node(node); } } // namespace CLDNNPlugin