diff --git a/include/pass_mpi_collective.hpp b/include/pass_mpi_collective.hpp index 4bb63dbea14e8c3e0cb8a751c03bbc83679ac3aa..cbeb7abd22ddea5709bbf692b6ed329e9b7e7c6a 100644 --- a/include/pass_mpi_collective.hpp +++ b/include/pass_mpi_collective.hpp @@ -2,8 +2,6 @@ #include <gcc-plugin.h> // declare opt_pass #include <tree-pass.h> -// set -#include <set> /* Enum to represent the collective operations */ #define DEFMPICOLLECTIVES(CODE, NAME) CODE, @@ -25,14 +23,15 @@ const char *const mpi_collective_name[] = struct bb_data { mpi_collective_code mpi_code; - std::set<basic_block> dom; - std::set<basic_block> post_dom; - std::set<basic_block> dom_front; - std::set<basic_block> post_dom_front; + bitmap_head dom; + bitmap_head post_dom; + bitmap_head dom_front; + bitmap_head post_dom_front; + int collective_rank[LAST_AND_UNUSED_MPI_COLLECTIVE_CODE]; + bitmap_head seens; int mark1; // for graph parkour int mark2; - int *collective_rank; - bitmap_head seens; + }; struct edge_data @@ -47,10 +46,9 @@ class pass_mpi_collective : public opt_pass { public: - int *collective_max_rank; + int collective_max_rank[LAST_AND_UNUSED_MPI_COLLECTIVE_CODE]; pass_mpi_collective(gcc::context *ctxt); - ~pass_mpi_collective(); pass_mpi_collective *clone(); bool gate(function *fun); @@ -95,16 +93,16 @@ public: void __rank_collective(basic_block bb); //post-dom set of same-rank collectives - bool __is_pd_set_mpi_coll_rank(function *fun, basic_block bb, int rank - - , int mpi_code, bitmap pds); - bitmap get_set_mpi_coll_rank(function *fun, int rank, int mpi_code); + bool __is_pd_set_mpi_coll_rank(function *fun, + basic_block bb, int rank, int mpi_code, bitmap pds); + void get_set_mpi_coll_rank(function *fun, + int rank, int mpi_code, bitmap pds); //post-dom set frontier - bitmap get_frontier_from_pds(function *fun, bitmap pds); - + void get_frontier_from_pds(function *fun, bitmap pds, bitmap pdf); + //err warning - void raise_warning_if_mpi_very_wrong(function *fun); + void raise_warning_if_mpi_wrong(function *fun); void better_rank_collective(function *fun); int __better_rank_collective(basic_block bb, diff --git a/src/pass_mpi_collective.cpp b/src/pass_mpi_collective.cpp index 97aefa59d8501ce5c65837a81dbbc39dfc83451e..cd4ac195948bbfcb9776653773d337aa825bca0f 100644 --- a/src/pass_mpi_collective.cpp +++ b/src/pass_mpi_collective.cpp @@ -12,8 +12,6 @@ #include <bitmap.h> // basename #include <filesystem> -// set -#include <set> // list #include <list> @@ -38,19 +36,12 @@ const pass_data my_pass_data = pass_mpi_collective::pass_mpi_collective(gcc::context *ctxt) : opt_pass(my_pass_data, ctxt) { - collective_max_rank = - new int[(int) LAST_AND_UNUSED_MPI_COLLECTIVE_CODE]; for (int i = 0; i < LAST_AND_UNUSED_MPI_COLLECTIVE_CODE; ++i) { collective_max_rank[i] = 0; } } -pass_mpi_collective::~pass_mpi_collective() -{ - delete collective_max_rank; -} - pass_mpi_collective *pass_mpi_collective::clone() { return new pass_mpi_collective(g); @@ -90,12 +81,12 @@ unsigned int pass_mpi_collective::execute(function *fun) //bitmap_head pdf = get_frontier_from_pds(fun, &pdbitmap); //debug_bitmap(&pdf); - - printf("[][][][][][][][][][]\n"); - raise_warning_if_mpi_very_wrong(fun); cfgviz_dump(fun, "_split"); + printf("[][][][][][][][][][]\n"); + raise_warning_if_mpi_wrong(fun); + free_dom_data(); free_bb_aux(fun); free_edge_aux(fun); @@ -219,18 +210,24 @@ void pass_mpi_collective::split_blocks(function *fun) void pass_mpi_collective::alloc_bb_aux(function *fun) { basic_block bb; + FOR_ALL_BB_FN(bb, fun) { bb->aux = (bb_data *) new bb_data(); bb_data *data = ((bb_data *) bb->aux); - data->collective_rank = - new int[(int) LAST_AND_UNUSED_MPI_COLLECTIVE_CODE]; + data->mpi_code = LAST_AND_UNUSED_MPI_COLLECTIVE_CODE; + bitmap_initialize(&data->dom, &bitmap_default_obstack); + bitmap_initialize(&data->post_dom, &bitmap_default_obstack); + bitmap_initialize(&data->dom_front, &bitmap_default_obstack); + bitmap_initialize(&data->post_dom_front, &bitmap_default_obstack); for (int i = 0; i < LAST_AND_UNUSED_MPI_COLLECTIVE_CODE; ++i) { data->collective_rank[i] = 0; } bitmap_initialize(&data->seens, &bitmap_default_obstack); } + + reset_bb_mark(fun); } // gestions des aux @@ -264,7 +261,10 @@ void pass_mpi_collective::free_bb_aux(function *fun) if (bb->aux != NULL) { bb_data *data = ((bb_data *) bb->aux); - delete data->collective_rank; + bitmap_clear(&data->dom); + bitmap_clear(&data->post_dom); + bitmap_clear(&data->dom_front); + bitmap_clear(&data->post_dom_front); bitmap_clear(&data->seens); delete (bb_data *) bb->aux; bb->aux = NULL; @@ -294,7 +294,7 @@ void pass_mpi_collective::label_dom(function *fun) { if (dom_gccvec[i]->index != bb->index) { - data->dom.insert(dom_gccvec[i]); + bitmap_set_bit(&data->dom, dom_gccvec[i]->index); } } @@ -304,7 +304,7 @@ void pass_mpi_collective::label_dom(function *fun) { if (post_dom_gccvec[i]->index != bb->index) { - data->post_dom.insert(post_dom_gccvec[i]); + bitmap_set_bit(&data->post_dom, post_dom_gccvec[i]->index); } } } @@ -336,11 +336,11 @@ void pass_mpi_collective::label_dom_front(function *fun) while (runner != dom_bb) { data = (bb_data *) runner->aux; - if (data->dom_front.count(bb) > 0) + if (bitmap_bit_p(&data->dom_front, bb->index)) { break; } - data->dom_front.insert(bb); + bitmap_set_bit(&data->dom_front, bb->index); runner = get_immediate_dominator(CDI_DOMINATORS, runner); } } @@ -363,11 +363,11 @@ void pass_mpi_collective::label_dom_front(function *fun) while (runner != dom_bb) { data = (bb_data *) runner->aux; - if (data->post_dom_front.count(bb) > 0) + if (bitmap_bit_p(&data->post_dom_front, bb->index)) { break; } - data->post_dom_front.insert(bb); + bitmap_set_bit(&data->post_dom_front, bb->index); runner = get_immediate_dominator(CDI_POST_DOMINATORS, runner); } } @@ -653,18 +653,18 @@ int pass_mpi_collective::__better_rank_collective(basic_block bb, return next_rank; } -bool pass_mpi_collective::__is_pd_set_mpi_coll_rank(function *fun - , basic_block bb - , int rank - , int mpi_code - , bitmap pds) +bool pass_mpi_collective::__is_pd_set_mpi_coll_rank(function *fun, + basic_block bb, int rank, int mpi_code, bitmap pds) { edge e; edge_iterator ei; + bool is_pd_by_set;//is postdominated by set + int count_edges;// nb. of succs that are not loop. //printf("entered bb->index : %i\n",bb->index); ((bb_data *) bb->aux)->mark1 = 1; + // if we are on an MPI collective of the requiered rank. if (((bb_data *) bb->aux)->mpi_code == mpi_code && ((bb_data *) bb->aux)->collective_rank[mpi_code] == rank) //if we are in the pd set @@ -674,14 +674,8 @@ bool pass_mpi_collective::__is_pd_set_mpi_coll_rank(function *fun return true; } - if (bb == EXIT_BLOCK_PTR_FOR_FN(fun)) - { - //printf("Exit block ; %i is 0\n", bb->index); - return false; - } - - bool is_pd_by_set = true;//is postdominated by set - int count_edges = 0; + is_pd_by_set = true; + count_edges = 0; FOR_EACH_EDGE(e, ei, bb->succs) { @@ -693,16 +687,19 @@ bool pass_mpi_collective::__is_pd_set_mpi_coll_rank(function *fun count_edges++; //printf("%i: %i\n",bb->index, count_edges); + // cache or travell if (((bb_data *) e->dest->aux)->mark1) { - //printf("node %i already visited.. jumping out...\n", e->dest->index); + //printf("node %i already visited.. jumping out...\n", + // e->dest->index); is_pd_by_set = is_pd_by_set && bitmap_bit_p(pds, e->dest->index); - continue; //if already visited, ignore } - - is_pd_by_set = - __is_pd_set_mpi_coll_rank(fun, e->dest, rank, mpi_code, pds) - && is_pd_by_set; + else + { + is_pd_by_set = + __is_pd_set_mpi_coll_rank(fun, e->dest, rank, mpi_code, pds) + && is_pd_by_set; + } } if (count_edges == 0) @@ -711,31 +708,26 @@ bool pass_mpi_collective::__is_pd_set_mpi_coll_rank(function *fun return false; //we are in a leaf } - if (is_pd_by_set) // add the bb to the pdset if it is pd by set. + if (is_pd_by_set) { + // add the bb to the pdset if it is post dominated by set bitmap_set_bit(pds, bb->index); } + //printf("I now know that %i is %b\n", bb->index, is_pd_by_set); return is_pd_by_set; } -bitmap pass_mpi_collective::get_set_mpi_coll_rank(function *fun - , int rank - , int mpi_code) +void pass_mpi_collective::get_set_mpi_coll_rank(function *fun, + int rank, int mpi_code, bitmap pds) { - bitmap set_post_dommed; - set_post_dommed = new bitmap_head(); - bitmap_initialize(set_post_dommed, &bitmap_default_obstack); - - __is_pd_set_mpi_coll_rank(fun, ENTRY_BLOCK_PTR_FOR_FN(fun) - , rank, mpi_code, set_post_dommed); + __is_pd_set_mpi_coll_rank(fun, ENTRY_BLOCK_PTR_FOR_FN(fun), + rank, mpi_code, pds); reset_bb_mark(fun); - - return set_post_dommed; } -bitmap pass_mpi_collective::get_frontier_from_pds(function *fun - , bitmap pds) +void pass_mpi_collective::get_frontier_from_pds(function *fun, + bitmap pds, bitmap pdf) { //we check each bb, if a bb is in the postdom set, we check its //most adjacents preds. If a pred is not in the postdom set, it @@ -744,10 +736,6 @@ bitmap pass_mpi_collective::get_frontier_from_pds(function *fun edge e; edge_iterator ei; - bitmap pdf; - pdf = new bitmap_head(); - bitmap_initialize(pdf, &bitmap_default_obstack); - FOR_ALL_BB_FN(bb, fun) { if (bitmap_bit_p(pds, bb->index)) @@ -756,33 +744,56 @@ bitmap pass_mpi_collective::get_frontier_from_pds(function *fun FOR_EACH_EDGE(e, ei, bb->preds) { //printf("\tchecking out my parent %i\n", e->src->index); - if (!bitmap_bit_p(pds, e->src->index)) + if (! ((edge_data *) e->aux)->loop && !bitmap_bit_p(pds, e->src->index)) { bitmap_set_bit(pdf, e->src->index); } } } } - return pdf; } -void pass_mpi_collective::raise_warning_if_mpi_very_wrong(function *fun) +void pass_mpi_collective::raise_warning_if_mpi_wrong(function *fun) { for (int mpi_code = 0; mpi_code < LAST_AND_UNUSED_MPI_COLLECTIVE_CODE; - ++mpi_code) + ++mpi_code) { - bitmap pds; - bitmap pdf; - + bitmap_head pds_head; + bitmap_head pdf_head; + bitmap pds = &pds_head; + bitmap pdf = &pdf_head; + bitmap tmp = NULL; + + bitmap_initialize(pds, &bitmap_default_obstack); + bitmap_initialize(pdf, &bitmap_default_obstack); + int stop = 0; + for (int i = 1 ; i < collective_max_rank[mpi_code] + 1 ; i++) { - printf("mpi_code: %i at rank: %i\n", mpi_code, i); - pds = get_set_mpi_coll_rank(fun, i, mpi_code); - pdf = get_frontier_from_pds(fun, pds); - - debug_bitmap(pds); - debug_bitmap(pdf); + // TODO: split in 2, get mpi set & find set post dom + get_set_mpi_coll_rank(fun, i, mpi_code, pds); + + while(! bitmap_empty_p(pds)){ + stop++; + if(stop > 10) + return; + get_frontier_from_pds(fun, pds, pdf); + + printf("----\n"); + debug_bitmap(pds); + debug_bitmap(pdf); + + bitmap_clear(pds); + + // swap pds & pdf + { + tmp = pdf; + pdf = pds; + pds = tmp; + } + // pds = + } } } } @@ -819,6 +830,9 @@ void pass_mpi_collective::cfgviz_internal_dump(function *fun, FILE *out) edge_iterator eit; edge e; + bitmap_iterator bi; + unsigned int index; + fprintf(out, "Digraph G{\n"); FOR_ALL_BB_FN(bb, fun) { @@ -831,42 +845,39 @@ void pass_mpi_collective::cfgviz_internal_dump(function *fun, FILE *out) data->collective_rank[data->mpi_code]); } - if (! data->dom.empty()) + if (! bitmap_empty_p(&data->dom)) { fprintf(out, "|dom("); - for (basic_block bb2 : data->dom) - { - fprintf(out, "%d,", bb2->index); + + EXECUTE_IF_SET_IN_BITMAP(&data->dom, 0, index, bi){ + fprintf(out, "%d,", index); } fprintf(out, ")"); } - if (! data->post_dom.empty()) + if (! bitmap_empty_p(&data->post_dom)) { fprintf(out, "|post_dom("); - for (basic_block bb2 : data->post_dom) - { - fprintf(out, "%d,", bb2->index); + EXECUTE_IF_SET_IN_BITMAP(&data->post_dom, 0, index, bi){ + fprintf(out, "%d,", index); } fprintf(out, ")"); } - if (! data->dom_front.empty()) + if (! bitmap_empty_p(&data->dom_front)) { fprintf(out, "|dom_front("); - for (basic_block bb2 : data->dom_front) - { - fprintf(out, "%d,", bb2->index); + EXECUTE_IF_SET_IN_BITMAP(&data->dom_front, 0, index, bi){ + fprintf(out, "%d,", index); } fprintf(out, ")"); } - if (! data->post_dom_front.empty()) + if (! bitmap_empty_p(&data->post_dom_front)) { fprintf(out, "|post_dom_front("); - for (basic_block bb2 : data->post_dom_front) - { - fprintf(out, "%d,", bb2->index); + EXECUTE_IF_SET_IN_BITMAP(&data->post_dom_front, 0, index, bi){ + fprintf(out, "%d,", index); } fprintf(out, ")"); }