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 4, 2021
1 parent b47d11e commit 024bcdd
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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_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;
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*, uint>> 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*, uint>& a, std::pair<cldnn::program_node*, uint>& 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 024bcdd

Please sign in to comment.