Skip to content

Commit

Permalink
Deterministic coloring: adding unit-test
Browse files Browse the repository at this point in the history
  • Loading branch information
lucbv committed Jun 18, 2018
1 parent 6d1bfeb commit 3b9575e
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 75 deletions.
2 changes: 1 addition & 1 deletion src/blas/KokkosBlas1_dot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ dot (const XVector& x, const YVector& y)
Kokkos::HostSpace,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > RVector_Internal;

typename XVector::non_const_value_type result;
typename XVector::non_const_value_type result = 0;
RVector_Internal R = RVector_Internal(&result);
XVector_Internal X = x;
YVector_Internal Y = y;
Expand Down
2 changes: 1 addition & 1 deletion src/blas/impl/KokkosBlas1_team_dot_spec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct TeamDot<TeamType, XV, YV, false> {
typedef typename IPT::dot_type dot_type;

static KOKKOS_INLINE_FUNCTION dot_type team_dot (const TeamType& team, const XV& X, const YV& Y) {
dot_type result;
dot_type result = 0.0; //Kokkos::Details::ArithTraits<dot_type>zero();
int N = X.extent(0);
Kokkos::parallel_reduce(Kokkos::TeamThreadRange(team,N), [&] (const int& i, dot_type& val) {
val += IPT::dot(X(i),Y(i));// X(i) * Y(i)
Expand Down
2 changes: 1 addition & 1 deletion src/blas/impl/KokkosBlas1_team_nrm2_spec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct TeamNrm2<TeamType, XV, false> {
typedef Kokkos::Details::ArithTraits<typename IPT::mag_type> AT;

static KOKKOS_INLINE_FUNCTION mag_type team_nrm2 (const TeamType& team, const XV& X) {
mag_type result;
mag_type result = 0.0; //Kokkos::Details::ArithTraits<mag_type>zero();
int N = X.extent(0);
Kokkos::parallel_reduce(Kokkos::TeamThreadRange(team,N), [&] (const int& i, mag_type& val) {
const typename IPT::mag_type tmp = IPT::norm (X(i));
Expand Down
85 changes: 15 additions & 70 deletions src/graph/impl/KokkosGraph_GraphColor_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2491,36 +2491,22 @@ class GraphColor_VBD:public GraphColor <HandleType,lno_row_view_t_,lno_nnz_view_
<< "\tchunkSize:" << this->_chunkSize << std::endl;
}

if (this->_ticToc) {
std::cout << std::endl << "Step 1: compute the score array and maxColors" << std::endl;
}
nnz_lno_t numVertices = this->nv;

size_type maxColors = 0;
const_lno_row_view_t myXadj = this->xadj;
const_lno_nnz_view_t myAdj = this->adj;
nnz_lno_persistent_work_view_t score
= nnz_lno_persistent_work_view_t(Kokkos::ViewAllocateWithoutInitializing("score"), numVertices);
typedef typename Kokkos::Experimental::Max<size_type, MyExecSpace> maxScoreReducerType;
maxScoreReducerType maxScoreReducer(maxColors);
functorScoreCalcution<nnz_lno_persistent_work_view_t, size_type, MyExecSpace> scoreCalcution(score, myXadj);
functorScoreCalculation<nnz_lno_persistent_work_view_t, size_type, MyExecSpace> scoreCalculation(score, myXadj);
Kokkos::parallel_reduce("Deterministic Coloring: compute initial scores", numVertices,
scoreCalcution, maxScoreReducer);
scoreCalculation, maxScoreReducer);

if (this->_ticToc) {
Kokkos::parallel_for("print score", 1,
KOKKOS_LAMBDA(const int dummy) {
printf("Score: {");
for(int scoreIdx = 0; scoreIdx < numVertices - 1; ++scoreIdx) {
printf("%d, ", score(scoreIdx));
}
printf("%d}\n", score(numVertices - 1));
});
// print1DView("Score", this->nv, score);
std::cout << "maxColors: " << maxColors << std::endl;

std::cout << std::endl
<< "Step 2: compute the dependency list and the initial new frontier" << std::endl;
}
if (this->_ticToc) {
std::cout << "maxColors: " << maxColors << std::endl;
}

// Create the dependency list of the graph
nnz_lno_persistent_work_view_t dependency
Expand Down Expand Up @@ -2553,54 +2539,25 @@ class GraphColor_VBD:public GraphColor <HandleType,lno_row_view_t_,lno_nnz_view_
}
});

if (this->_ticToc) {
std::cout << std::endl << "Step 3: loop until newFrontier is empty" << std::endl;
}

Kokkos::deep_copy(host_newFrontierSize, newFrontierSize);
while(host_newFrontierSize() > 0) {
++num_loops;
// First swap fontier with newFrontier and fontierSize with newFrontierSize
// reset newFrontierSize
{
auto swap_tmp = frontierSize;
frontierSize = newFrontierSize;
newFrontierSize = swap_tmp;
host_newFrontierSize() = 0;
Kokkos::deep_copy(newFrontierSize, host_newFrontierSize);
}
std::cout << "Done swapping frontier sizes!" << std::endl;
Kokkos::parallel_for("Swap frontier sizes", 1,
KOKKOS_LAMBDA(const int dummy) {
frontierSize() = newFrontierSize();
newFrontierSize() = 0;
});
Kokkos::deep_copy(host_frontierSize, frontierSize);
{
auto swap_tmp = frontier;
frontier = newFrontier;
newFrontier = swap_tmp;
}
std::cout << "Done swapping frontiers!" << std::endl;

if (this->_ticToc) {
Kokkos::parallel_for("print dependency", 1,
KOKKOS_LAMBDA(const int dummy) {
printf("Dependency: {");
for(int vertexIdx = 0; vertexIdx < numVertices - 1; ++vertexIdx) {
printf("%d, ", dependency(vertexIdx));
}
printf("%d}\n", dependency(numVertices - 1));
});
Kokkos::parallel_for("print frontier", 1,
KOKKOS_LAMBDA(const int dummy) {
printf("Frontier: {");
for(int frontierIdx = 0; frontierIdx < (int)frontierSize() - 1; ++frontierIdx) {
printf("%d, ", frontier(frontierIdx));
}
printf("%d}\n", frontier(frontierSize() - 1));
});
// print1DView("Dependency", numVertices, dependency);
// print1DView("Frontier", frontierSize(), frontier);
}

// Loop over nodes in the frontier
// First variant without bit array, easier to understand/program
Kokkos::deep_copy(host_frontierSize, frontierSize);
if(this->_use_color_set == 0) {
Kokkos::parallel_for("Deterministic Coloring: color nodes in frontier", host_frontierSize(),
KOKKOS_LAMBDA(const size_type frontierIdx) {
Expand Down Expand Up @@ -2693,36 +2650,24 @@ class GraphColor_VBD:public GraphColor <HandleType,lno_row_view_t_,lno_nnz_view_
Kokkos::deep_copy(host_newFrontierSize, newFrontierSize);
} // while newFrontierSize

if (this->_ticToc) {
// print1DView("Colors", numVertices, colors);
}

} // color_graph()

// void print1DView(const std::string label, const size_type frontierSize,
// const nnz_lno_temp_work_view_t frontier) {
// std::cout << label << ": {";
// for(size_type frontierIdx = 0; frontierIdx < frontierSize-1; ++frontierIdx) {
// std::cout << frontier(frontierIdx) << "; ";
// }
// std::cout << frontier(frontierSize - 1) << "}" << std::endl;
// } // printFrontier

template <class score_type, class max_type, class execution_space>
struct functorScoreCalcution {
struct functorScoreCalculation {
typedef typename Kokkos::Experimental::Max<max_type, execution_space>::value_type valueType;
score_type score_;
const_lno_row_view_t numNeighbors_;

functorScoreCalcution(score_type score, const_lno_row_view_t numNeighbors)
functorScoreCalculation(score_type score, const_lno_row_view_t numNeighbors)
: score_(score), numNeighbors_(numNeighbors) {}

KOKKOS_INLINE_FUNCTION
void operator() (const int i, valueType &update) const {
score_(i) = numNeighbors_(i + 1) - numNeighbors_(i);
update = ( (valueType) score_(i) < update ? update : (valueType) score_(i) );
}
}; // functorScoreCalcution()
}; // functorScoreCalculation()


}; // class GraphColor_VBD
Expand Down
4 changes: 4 additions & 0 deletions unit_test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ ifeq ($(KOKKOSKERNELS_INTERNAL_TEST_OPENMP), 1)
OBJ_OPENMP += Test_OpenMP_Sparse_replaceSumIntoLonger.o
OBJ_OPENMP += Test_OpenMP_Sparse_replaceSumInto.o
OBJ_OPENMP += Test_OpenMP_Graph_graph_color.o
OBJ_OPENMP += Test_OpenMP_Graph_graph_color_deterministic.o
OBJ_OPENMP += Test_OpenMP_Graph_graph_color_d2.o
OBJ_OPENMP += Test_OpenMP_Common_ArithTraits.o
OBJ_OPENMP += Test_OpenMP_Common_set_bit_count.o
Expand Down Expand Up @@ -225,6 +226,7 @@ ifeq ($(KOKKOSKERNELS_INTERNAL_TEST_CUDA), 1)
OBJ_CUDA += Test_Cuda_Sparse_replaceSumIntoLonger.o
OBJ_CUDA += Test_Cuda_Sparse_replaceSumInto.o
OBJ_CUDA += Test_Cuda_Graph_graph_color.o
OBJ_CUDA += Test_Cuda_Graph_graph_color_deterministic.o
OBJ_CUDA += Test_Cuda_Graph_graph_color_d2.o
OBJ_CUDA += Test_Cuda_Common_ArithTraits.o
OBJ_CUDA += Test_Cuda_Common_set_bit_count.o
Expand Down Expand Up @@ -320,6 +322,7 @@ ifeq ($(KOKKOSKERNELS_INTERNAL_TEST_SERIAL), 1)
OBJ_SERIAL += Test_Serial_Sparse_replaceSumIntoLonger.o
OBJ_SERIAL += Test_Serial_Sparse_replaceSumInto.o
OBJ_SERIAL += Test_Serial_Graph_graph_color.o
OBJ_SERIAL += Test_Serial_Graph_graph_color_deterministic.o
OBJ_SERIAL += Test_Serial_Graph_graph_color_d2.o
OBJ_SERIAL += Test_Serial_Common_ArithTraits.o
OBJ_SERIAL += Test_Serial_Common_set_bit_count.o
Expand Down Expand Up @@ -422,6 +425,7 @@ ifeq ($(KOKKOSKERNELS_INTERNAL_TEST_THREADS), 1)
OBJ_THREADS += Test_Threads_Sparse_replaceSumInto.o
OBJ_THREADS += Test_Threads_Sparse_CrsMatrix.o
OBJ_THREADS += Test_Threads_Graph_graph_color.o
OBJ_THREADS += Test_Threads_Graph_graph_color_deterministic.o
OBJ_THREADS += Test_Threads_Graph_graph_color_d2.o
OBJ_THREADS += Test_Threads_Common_ArithTraits.o
OBJ_THREADS += Test_Threads_Common_set_bit_count.o
Expand Down
2 changes: 2 additions & 0 deletions unit_test/cuda/Test_Cuda_Graph_graph_color_deterministic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include<Test_Cuda.hpp>
#include<Test_Graph_graph_color_deterministic.hpp>
4 changes: 2 additions & 2 deletions unit_test/graph/Test_Graph_graph_color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ void test_coloring(lno_t numRows,size_type nnz, lno_t bandwidth, lno_t row_size_
graph_t static_graph (sym_adj, sym_xadj);
input_mat = crsMat_t("CrsMatrix", numCols, newValues, static_graph);

ColoringAlgorithm coloring_algorithms[] = {COLORING_DEFAULT, COLORING_SERIAL, COLORING_VB, COLORING_VBBIT, COLORING_VBCS, COLORING_EB};
ColoringAlgorithm coloring_algorithms[] = {COLORING_DEFAULT, COLORING_SERIAL, COLORING_VB, COLORING_VBBIT, COLORING_VBCS, COLORING_EB, COLORING_VBD, COLORING_VBDBIT};

for (int ii = 0; ii < 6; ++ii){
for (int ii = 0; ii < 8; ++ii){
ColoringAlgorithm coloring_algorithm = coloring_algorithms[ii];
color_view_t vector_colors;
size_t num_colors;
Expand Down
Loading

0 comments on commit 3b9575e

Please sign in to comment.