Skip to content

Commit

Permalink
[IE CLDNN] Memory dependencies fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyamin-Roman committed May 11, 2021
1 parent 1e3b06f commit 9dfcd1a
Showing 1 changed file with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ void oooq_memory_dependencies::run(program_impl& p) {

// maps program nodes to bimap vector ids
auto user_map = std::map<program_node*, unsigned int>();
unsigned int i = 0;
unsigned int processing_order_idx = 0;
for (auto node : processing_order) {
user_map[node] = i++;
user_map[node] = processing_order_idx++;
}

unsigned int num_nodes = static_cast<unsigned int>(user_map.size());
Expand All @@ -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<bits_64> user_bitmap(num_nodes, bits_64(num_nodes));
std::vector<program_node*> 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_dep_nodes = 0;
for (const auto& dep : node.first->get_dependencies()) {
if (!dep->is_constant()) {
++num_dep_nodes;
}
}
if (num_dep_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;
Expand All @@ -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<std::pair<program_node*, unsigned int>> deps;
for (auto& dep : node->get_dependencies()) {
deps.emplace_back(dep, user_map.at(dep));
}

std::sort(deps.begin(), deps.end(), [&deps]
(std::pair<cldnn::program_node*, unsigned int>& a, std::pair<cldnn::program_node*, unsigned int>& 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();

Expand Down

0 comments on commit 9dfcd1a

Please sign in to comment.