Merges this subgraph with another.
| 63 | |
| 64 | /// Merges this subgraph with another. |
| 65 | void MergeWith(PartialSubgraph* other) |
| 66 | { |
| 67 | if (m_Parent == nullptr) |
| 68 | { |
| 69 | other = other->GetRepresentative(); |
| 70 | if (this == other) |
| 71 | { |
| 72 | // Already merged - no-op |
| 73 | return; |
| 74 | } |
| 75 | m_Parent = other; |
| 76 | |
| 77 | // Update others' dependency sets to point to the new representative rather than us. |
| 78 | // Keeping these up-to-date means we can rely on these sets containing representatives when |
| 79 | // we perform a lookup in HasAntecedent() and so don't need to resolve the representative for each element |
| 80 | // of the set. See description at the top of this class for more rationale. |
| 81 | for (PartialSubgraph* a : m_Antecedents) |
| 82 | { |
| 83 | size_t numErased = a->m_Dependants.erase(this); |
| 84 | if (numErased != 1) |
| 85 | { |
| 86 | throw armnn::Exception("number of dependents erased must only be 1."); |
| 87 | } |
| 88 | a->m_Dependants.insert(m_Parent); |
| 89 | } |
| 90 | for (PartialSubgraph* a : m_Dependants) |
| 91 | { |
| 92 | size_t numErased = a->m_Antecedents.erase(this); |
| 93 | if (numErased != 1) |
| 94 | { |
| 95 | throw armnn::Exception("number of antecedents erased must only be 1."); |
| 96 | } |
| 97 | IgnoreUnused(numErased); |
| 98 | a->m_Antecedents.insert(m_Parent); |
| 99 | } |
| 100 | |
| 101 | // Merge our dependency sets into our new representative. |
| 102 | // We no longer need to maintain our own sets, as requests will always be forwarded to the representative. |
| 103 | m_Parent->m_Antecedents.insert(m_Antecedents.begin(), m_Antecedents.end()); |
| 104 | m_Antecedents.clear(); |
| 105 | m_Parent->m_Dependants.insert(m_Dependants.begin(), m_Dependants.end()); |
| 106 | m_Dependants.clear(); |
| 107 | } |
| 108 | else |
| 109 | { |
| 110 | // Defer request to the representative |
| 111 | GetRepresentative()->MergeWith(other); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | /// Checks if this subgraph has been merged with the given subgraph. |
| 116 | bool IsMergedWith(PartialSubgraph* other) |
no test coverage detected