From 8c09b6a4c915e8917d2a72af176a18f6cf633029 Mon Sep 17 00:00:00 2001 From: Brian Kelley Date: Wed, 22 Jan 2020 14:13:36 -0700 Subject: [PATCH 1/3] D1 color: use conflict resolution scheme enum instead of magic numbers 0,1,2 --- .../impl/KokkosGraph_Distance1Color_impl.hpp | 33 ++++++------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/graph/impl/KokkosGraph_Distance1Color_impl.hpp b/src/graph/impl/KokkosGraph_Distance1Color_impl.hpp index b68ff84755..28c4668929 100644 --- a/src/graph/impl/KokkosGraph_Distance1Color_impl.hpp +++ b/src/graph/impl/KokkosGraph_Distance1Color_impl.hpp @@ -789,7 +789,7 @@ class GraphColor_VB:public GraphColor (nv_, ne_, row_map, entries, coloring_handle), _serialConflictResolution(coloring_handle->get_serial_conflict_resolution()), _ticToc(coloring_handle->get_tictoc()), - _conflictlist(), + _conflict_scheme(coloring_handle->get_conflict_list_type()), _pps_ratio(coloring_handle->get_min_reduction_for_conflictlist()), _min_vertex_cut_off(coloring_handle->get_min_elements_for_conflictlist()), _edge_filtering(coloring_handle->get_vb_edge_filtering()), @@ -840,19 +840,6 @@ class GraphColor_VB:public GraphColor _use_color_set = 0; break; - - } - - switch (coloring_handle->get_conflict_list_type()){ - case COLORING_NOCONFLICT: - this->_conflictlist = 0; - break; - case COLORING_ATOMIC: - this->_conflictlist = 1; - break; - case COLORING_PPS: - this->_conflictlist = 2; - break; } } @@ -872,7 +859,7 @@ class GraphColor_VB:public GraphColor _ticToc) { std::cout << "\tVB params:" << std::endl - << "\tuseConflictList:" << int (this->_conflictlist) << std::endl + << "\tuseConflictList:" << int (this->_conflict_scheme) << std::endl << "\talgorithm:" << (int)this->_use_color_set << std::endl << "\tserialConflictResolution:" << (int) this->_serialConflictResolution << std::endl << "\tticToc:" << (int) this->_ticToc << std::endl @@ -921,11 +908,11 @@ class GraphColor_VB:public GraphColor _conflictlist > 0){ + if (this->_conflict_scheme!= COLORING_NOCONFLICT){ // Vertices to recolor. Will swap with vertexList. next_iteration_recolorList = nnz_lno_temp_work_view_t(Kokkos::ViewAllocateWithoutInitializing("recolorList"), this->nv); next_iteration_recolorListLength = single_dim_index_view_type("recolorListLength"); - if (this->_conflictlist == 2) { + if (this->_conflict_scheme == COLORING_PPS) { pps_work_view = nnz_lno_temp_work_view_t("pps_view", this->nv); } } @@ -1011,7 +998,7 @@ class GraphColor_VB:public GraphColor _serialConflictResolution) break; // Break after first iteration. - if (this->_conflictlist && swap_work_arrays && (iter + 1< this->_max_num_iterations)){ + if (this->_conflict_scheme != COLORING_NOCONFLICT && swap_work_arrays && (iter + 1< this->_max_num_iterations)){ // Swap recolorList and vertexList nnz_lno_temp_work_view_t temp = current_vertexList; current_vertexList = next_iteration_recolorList; @@ -1216,7 +1203,7 @@ class GraphColor_VB:public GraphColor _conflictlist == 0){ + if (this->_conflict_scheme == COLORING_NOCONFLICT){ if (this->_use_color_set == 0 || this->_use_color_set == 2){ functorFindConflicts_No_Conflist conf( this->nv, xadj_, adj_, vertex_colors_); Kokkos::parallel_reduce("KokkosGraph::GraphColoring::FindConflicts::CaseA", my_exec_space(0, current_vertexListLength_), conf, numUncolored); @@ -1226,7 +1213,7 @@ class GraphColor_VB:public GraphColor _conflictlist == 2){ //IF PPS + else if (this->_conflict_scheme == COLORING_PPS){ //IF PPS if (this->_use_color_set == 0 || this->_use_color_set == 2){ // Check for conflicts. Compute numUncolored == numConflicts. functorFindConflicts_PPS conf(this->nv, xadj_, adj_,vertex_colors_,current_vertexList_,next_iteration_recolorList_); @@ -1309,7 +1296,7 @@ class GraphColor_VB:public GraphColor _conflictlist){ + if (this->_conflict_scheme != COLORING_NOCONFLICT){ end = current_vertexListLength_; h_recolor_list = Kokkos::create_mirror_view (current_vertexList_); Kokkos::deep_copy (h_recolor_list, current_vertexList_); @@ -1324,7 +1311,7 @@ class GraphColor_VB:public GraphColor _conflictlist){ + if (this->_conflict_scheme != COLORING_NOCONFLICT){ i = h_recolor_list(k); } else { From 79570ef05c390cef10d85f90be083c8aabb4d8f3 Mon Sep 17 00:00:00 2001 From: Brian Kelley Date: Wed, 22 Jan 2020 17:06:20 -0700 Subject: [PATCH 2/3] Removed the need for pps work view, fused kernels PPS worklist construction (VB and EB) now happens in a single scan, without using a temporary array to store indices. Faster and saves memory. --- .../impl/KokkosGraph_Distance1Color_impl.hpp | 214 +++++------------- 1 file changed, 59 insertions(+), 155 deletions(-) diff --git a/src/graph/impl/KokkosGraph_Distance1Color_impl.hpp b/src/graph/impl/KokkosGraph_Distance1Color_impl.hpp index 28c4668929..42de37d036 100644 --- a/src/graph/impl/KokkosGraph_Distance1Color_impl.hpp +++ b/src/graph/impl/KokkosGraph_Distance1Color_impl.hpp @@ -903,18 +903,12 @@ class GraphColor_VB:public GraphColor _conflict_scheme!= COLORING_NOCONFLICT){ // Vertices to recolor. Will swap with vertexList. next_iteration_recolorList = nnz_lno_temp_work_view_t(Kokkos::ViewAllocateWithoutInitializing("recolorList"), this->nv); next_iteration_recolorListLength = single_dim_index_view_type("recolorListLength"); - if (this->_conflict_scheme == COLORING_PPS) { - pps_work_view = nnz_lno_temp_work_view_t("pps_view", this->nv); - } } nnz_lno_t numUncolored = this->nv; @@ -974,8 +968,7 @@ class GraphColor_VB:public GraphColor xadj, adj_copy, colors, vertex_color_set, current_vertexList, current_vertexListLength, - next_iteration_recolorList, next_iteration_recolorListLength, - pps_work_view); + next_iteration_recolorList, next_iteration_recolorListLength); } else { numUncolored = this->findConflicts( @@ -983,8 +976,7 @@ class GraphColor_VB:public GraphColor xadj, this->adj, colors, vertex_color_set, current_vertexList, current_vertexListLength, - next_iteration_recolorList, next_iteration_recolorListLength, - pps_work_view); + next_iteration_recolorList, next_iteration_recolorListLength); } MyExecSpace().fence(); @@ -1184,9 +1176,8 @@ class GraphColor_VB:public GraphColor nnz_lno_t findConflicts( @@ -1198,8 +1189,7 @@ class GraphColor_VB:public GraphColor _conflict_scheme == COLORING_PPS){ //IF PPS + else if (this->_conflict_scheme == COLORING_PPS){ if (this->_use_color_set == 0 || this->_use_color_set == 2){ // Check for conflicts. Compute numUncolored == numConflicts. - functorFindConflicts_PPS conf(this->nv, xadj_, adj_,vertex_colors_,current_vertexList_,next_iteration_recolorList_); + functorFindConflicts_PPS conf(this->nv, xadj_, adj_,vertex_colors_,current_vertexList_); Kokkos::parallel_reduce("KokkosGraph::GraphColoring::FindConflicts::CaseC", my_exec_space(0, current_vertexListLength_), conf, numUncolored); } else { - functorFindConflicts_PPS_IMP conf(this->nv, - xadj_, adj_,vertex_colors_, vertex_color_set_, - current_vertexList_,next_iteration_recolorList_); + functorFindConflicts_PPS_IMP conf( + this->nv, xadj_, adj_,vertex_colors_, vertex_color_set_, current_vertexList_); Kokkos::parallel_reduce("KokkosGraph::GraphColoring::FindConflicts::CaseD", my_exec_space(0, current_vertexListLength_), conf, numUncolored); } - if( numUncolored && (current_vertexListLength_ >= this->_min_vertex_cut_off) && (double (numUncolored) / current_vertexListLength_ < (1.0 - this->_pps_ratio))){ if (this->_ticToc){ @@ -1235,23 +1223,15 @@ class GraphColor_VB:public GraphColor (current_vertexList_, next_iteration_recolorList_, pps_work_view)); - - MyExecSpace().fence(); - Kokkos::parallel_for ("KokkosGraph::GraphColoring::CreateNewWorkArray", - my_exec_space(0, current_vertexListLength_), - create_new_work_array(current_vertexList_, next_iteration_recolorList_, pps_work_view)); + ppsWorklistFunctorVB(this->nv, current_vertexList_, next_iteration_recolorList_)); } else { swap_work_arrays = false; } } - else { //IF ATOMIC + else { // worklist scheme COLORING_ATOMIC if (this->_use_color_set == 0 || this->_use_color_set == 2){ // Check for conflicts. Compute numUncolored == numConflicts. functorFindConflicts_Atomic conf(this->nv, @@ -1941,27 +1921,20 @@ class GraphColor_VB:public GraphColor - struct parallel_prefix_sum{ + struct ppsWorklistFunctorVB { + nnz_lno_t _nv; view_type _vertexList; view_type _recolorList; - view_type _pps_view; - - parallel_prefix_sum( - view_type vertexList, - view_type recolorList, - view_type pps_view): - _vertexList(vertexList),_recolorList(recolorList),_pps_view(pps_view){} - KOKKOS_INLINE_FUNCTION - void operator()(const typename view_type::non_const_value_type ii, size_t& update, const bool final) const { - typename view_type::non_const_value_type w = _vertexList(ii); - update += _recolorList(w); - if (final) { - _pps_view(w) = (update); - } - } - }; - - - /** - * Functor for creating new worklist using pps - */ - template - struct create_new_work_array{ - view_type _vertexList; - view_type _recolorList; - view_type _pps_view; - - create_new_work_array( - view_type vertexList, - view_type recolorList, - view_type pps_view): - _vertexList(vertexList),_recolorList(recolorList),_pps_view(pps_view){} + ppsWorklistFunctorVB( + nnz_lno_t nv, + const view_type& vertexList, + const view_type& recolorList) + : _nv(nv), _vertexList(vertexList), _recolorList(recolorList) + {} KOKKOS_INLINE_FUNCTION - void operator()(const typename view_type::non_const_value_type ii) const { - typename view_type::non_const_value_type w = _vertexList(ii); - typename view_type::non_const_value_type left_work = 0; - if (ii > 0){ - left_work = _pps_view(_vertexList(ii - 1)); - } - typename view_type::non_const_value_type pps_current = _pps_view(w); - if(pps_current != left_work){ - typename view_type::non_const_value_type future_index = pps_current; - _recolorList(future_index - 1) = w; + void operator()(nnz_lno_t i, nnz_lno_t& update, const bool final) const + { + nnz_lno_t w = _vertexList(i); + if(w >= _nv) + { + if(final) + _recolorList(update) = w - _nv; + update++; } } }; - /** * Converting VBCS colors to final colors. */ @@ -3001,18 +2940,9 @@ class GraphColor_EB:public GraphColor Date: Wed, 22 Jan 2020 17:51:27 -0700 Subject: [PATCH 3/3] Fix shadow warning --- src/graph/impl/KokkosGraph_Distance1Color_impl.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graph/impl/KokkosGraph_Distance1Color_impl.hpp b/src/graph/impl/KokkosGraph_Distance1Color_impl.hpp index 42de37d036..f469f0a694 100644 --- a/src/graph/impl/KokkosGraph_Distance1Color_impl.hpp +++ b/src/graph/impl/KokkosGraph_Distance1Color_impl.hpp @@ -2257,10 +2257,10 @@ class GraphColor_VB:public GraphColor