From 024bcddd729c642a8e46c2b3216e7dd74b714936 Mon Sep 17 00:00:00 2001 From: Roman Lyamin Date: Fri, 30 Apr 2021 15:41:52 +0300 Subject: [PATCH] [IE CLDNN] Memory dependencies fix --- .../oooq_memory_dependencies.cpp | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/inference-engine/thirdparty/clDNN/src/graph_optimizer/oooq_memory_dependencies.cpp b/inference-engine/thirdparty/clDNN/src/graph_optimizer/oooq_memory_dependencies.cpp index 052d70bdc4f98e..c6f0c59ce082d9 100644 --- a/inference-engine/thirdparty/clDNN/src/graph_optimizer/oooq_memory_dependencies.cpp +++ b/inference-engine/thirdparty/clDNN/src/graph_optimizer/oooq_memory_dependencies.cpp @@ -92,15 +92,26 @@ void oooq_memory_dependencies::run(program_impl& p) { // every node has a bit array assigned to it // users or the node are marked with 1 bit in this array std::vector user_bitmap(num_nodes, bits_64(num_nodes)); + std::vector suspect_nodes; // init bitmaps from direct node users for (const auto& node : user_map) { for (const auto& user : node.first->get_users()) { user_bitmap[node.second].set(user_map.at(user)); } + + size_t num_nodes = 0; + for (const auto& dep : node.first->get_dependencies()) { + if (!dep->is_constant()) { + ++num_nodes; + } + } + if (num_nodes > 1) { + suspect_nodes.emplace_back(node.first); + } } - // Iteratively extend the users set by adding closure over existing users untill no change occurs. + // Iteratively extend the users set by adding closure over existing users until no change occurs. bool changed = true; while (changed) { changed = false; @@ -122,6 +133,29 @@ void oooq_memory_dependencies::run(program_impl& p) { return user_bitmap[A].is_set(B); }; + for (auto node : suspect_nodes) { + std::vector> deps; + for (auto& dep : node->get_dependencies()) { + deps.emplace_back(dep, user_map.at(dep)); + } + + std::sort(deps.begin(), deps.end(), [&deps] + (std::pair& a, std::pair& b) { + return a.second < b.second; + }); + + for (size_t i = 0; i < deps.size(); ++i) { + for (size_t j = i + 1; j < deps.size(); ++j) { + if (are_connected(deps[i].second, deps[j].second)) { + for (const auto& user : deps[j].first->get_users()) { + add_memory_dependency(deps[i].first, user); + add_memory_dependency(user, deps[i].first); + } + } + } + } + } + unsigned int A = 0; auto itr_A = processing_order.begin();