From 1ccf17020b572b03f5c99d3b518befd661487955 Mon Sep 17 00:00:00 2001 From: Yun-Fly Date: Wed, 15 Mar 2023 15:28:59 +0800 Subject: [PATCH] backend: compiler: fix `content_map` merge (#5550) --- .../src/compiler/ir/graph/mixed_partition.cpp | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/backend/graph_compiler/core/src/compiler/ir/graph/mixed_partition.cpp b/src/backend/graph_compiler/core/src/compiler/ir/graph/mixed_partition.cpp index 89832265fff..8ae1c24baee 100644 --- a/src/backend/graph_compiler/core/src/compiler/ir/graph/mixed_partition.cpp +++ b/src/backend/graph_compiler/core/src/compiler/ir/graph/mixed_partition.cpp @@ -1624,8 +1624,24 @@ static void merge_parti_impl(mixed_parti_t *pa_to_merge, } } + // append inner loop anchor + for (auto &be_merged_anchor_map : parti_be_merged->fanchors_) { + // skip outer anchor + if (std::any_of(outer_loops_be_merged.begin(), + outer_loops_be_merged.begin() + merged_loop_size, + [&be_merged_anchor_map, &parti_be_merged]( + const for_loop &loop) { + return parti_be_merged->get_anchor_inside_loop(loop) + == be_merged_anchor_map; + })) { + continue; + } + be_merged_anchor_map->attach_parent_anchor( + max_to_merge_anchor_map, max_be_merged_anchor_map); + pa_to_merge->append_fusion_anchor(be_merged_anchor_map); + } + // merge outer loop anchor - std::unordered_set be_merged_anchor_masks; for (size_t i = 0; i < merged_loop_size; i++) { node_remap[outer_loops_be_merged[i]->var_.impl] = outer_loops_to_merge[i]->var_.impl; @@ -1635,33 +1651,19 @@ static void merge_parti_impl(mixed_parti_t *pa_to_merge, outer_loops_be_merged[i]), to_merge_anchor_map = pa_to_merge->get_anchor_inside_loop(outer_loops_to_merge[i]); - if (be_merged_anchor_map) { - be_merged_anchor_masks.insert(be_merged_anchor_map); - if (to_merge_anchor_map) { - to_merge_anchor_map->merge(be_merged_anchor_map); - // reset op anchor map if neccesary - if (i == merged_loop_size - 1) { - for (auto &op_anchor_pair : - parti_be_merged->op_anchor_map_) { - if (op_anchor_pair.second == be_merged_anchor_map) { - op_anchor_pair.second = to_merge_anchor_map; - } + if (be_merged_anchor_map && to_merge_anchor_map) { + to_merge_anchor_map->merge(be_merged_anchor_map); + // reset op anchor map if neccesary + if (i == merged_loop_size - 1) { + for (auto &op_anchor_pair : parti_be_merged->op_anchor_map_) { + if (op_anchor_pair.second == be_merged_anchor_map) { + op_anchor_pair.second = to_merge_anchor_map; } } } } } - // append inner loop anchor - for (auto &be_merged_anchor_map : parti_be_merged->fanchors_) { - if (be_merged_anchor_masks.find(be_merged_anchor_map) - != be_merged_anchor_masks.end()) - continue; - be_merged_anchor_map->attach_parent_anchor( - max_to_merge_anchor_map, max_be_merged_anchor_map); - pa_to_merge->append_fusion_anchor(be_merged_anchor_map); - } - /* * * * * * * * * * * * * * * * * * Step 3: Merge buf_alloc_ * * * * * * * * * * * * * * * * */