Skip to content

Commit

Permalink
Merge pull request #623 from brian-kelley/Dist2InitialImprovements
Browse files Browse the repository at this point in the history
Dist2 initial improvements
  • Loading branch information
brian-kelley authored Mar 1, 2020
2 parents a5a7337 + be50fa9 commit 4d9abd8
Show file tree
Hide file tree
Showing 9 changed files with 1,102 additions and 1,107 deletions.
43 changes: 30 additions & 13 deletions perf_test/graph/KokkosGraph_color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,18 @@ void print_options(std::ostream &os, const char *app_name, unsigned int indent =
<< std::endl
<< spaces << "Parameters:" << std::endl
<< spaces << " Parallelism (select one of the following):" << std::endl
<< spaces << " --serial <N> Execute serially." << std::endl
#if defined(KOKKOS_ENABLE_SERIAL)
<< spaces << " --serial Execute serially." << std::endl
#endif
#if defined(KOKKOS_ENABLE_THREADS)
<< spaces << " --threads <N> Use N posix threads." << std::endl
#endif
#if defined(KOKKOS_ENABLE_OPENMP)
<< spaces << " --openmp <N> Use OpenMP with N threads." << std::endl
<< spaces << " --cuda Use CUDA" << std::endl
#endif
#if defined(KOKKOS_ENABLE_CUDA)
<< spaces << " --cuda <id> Use CUDA (device $id)" << std::endl
#endif
<< std::endl
<< spaces << " Required Parameters:" << std::endl
<< spaces << " --amtx <filename> Input file in Matrix Market format (.mtx)." << std::endl
Expand All @@ -93,7 +101,16 @@ void print_options(std::ostream &os, const char *app_name, unsigned int indent =
<< spaces << " " << std::endl;
}


static char* getNextArg(int& i, int argc, char** argv)
{
i++;
if(i >= argc)
{
std::cerr << "Error: expected additional command-line argument!\n";
exit(1);
}
return argv[i];
}

int parse_inputs (KokkosKernels::Experiment::Parameters &params, int argc, char **argv)
{
Expand All @@ -102,32 +119,32 @@ int parse_inputs (KokkosKernels::Experiment::Parameters &params, int argc, char

for ( int i = 1 ; i < argc ; ++i ) {
if ( 0 == strcasecmp( argv[i] , "--threads" ) ) {
params.use_threads = atoi( argv[++i] );
params.use_threads = atoi(getNextArg(i, argc, argv));
}
else if ( 0 == strcasecmp( argv[i] , "--serial" ) ) {
params.use_serial = atoi( argv[++i] );
params.use_serial = atoi(getNextArg(i, argc, argv));
}
else if ( 0 == strcasecmp( argv[i] , "--openmp" ) ) {
params.use_openmp = atoi( argv[++i] );
params.use_openmp = atoi(getNextArg(i, argc, argv));
}
else if ( 0 == strcasecmp( argv[i] , "--cuda" ) ) {
params.use_cuda = 1;
params.use_cuda = 1 + atoi(getNextArg(i, argc, argv));
}
else if ( 0 == strcasecmp( argv[i] , "--repeat" ) ) {
params.repeat = atoi( argv[++i] );
params.repeat = atoi(getNextArg(i, argc, argv));
}
else if ( 0 == strcasecmp( argv[i] , "--chunksize" ) ) {
params.chunk_size = atoi( argv[++i] ) ;
params.chunk_size = atoi(getNextArg(i, argc, argv));
}
else if ( 0 == strcasecmp( argv[i] , "--teamsize" ) ) {
params.team_size = atoi( argv[++i] ) ;
params.team_size = atoi(getNextArg(i, argc, argv));
}
else if ( 0 == strcasecmp( argv[i] , "--vectorsize" ) ) {
params.vector_size = atoi( argv[++i] ) ;
params.vector_size = atoi(getNextArg(i, argc, argv));
}
else if ( 0 == strcasecmp( argv[i] , "--amtx" ) ) {
got_required_param_amtx = true;
params.a_mtx_bin_file = argv[++i];
params.a_mtx_bin_file = getNextArg(i, argc, argv);
}
else if ( 0 == strcasecmp( argv[i] , "--dynamic" ) ) {
params.use_dynamic_scheduling = 1;
Expand All @@ -136,7 +153,7 @@ int parse_inputs (KokkosKernels::Experiment::Parameters &params, int argc, char
params.verbose = 1;
}
else if ( 0 == strcasecmp( argv[i] , "--outputfile" ) || 0 == strcasecmp( argv[i] , "-o" ) ) {
params.coloring_output_file = argv[++i];
params.coloring_output_file = getNextArg(i, argc, argv);
}
else if ( 0 == strcasecmp( argv[i] , "--algorithm" ) ) {
got_required_param_algorithm = true;
Expand Down
57 changes: 42 additions & 15 deletions perf_test/graph/KokkosGraph_color_d2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
//@HEADER
*/

// EXERCISE 1 Goal:
// Use Kokkos to parallelize the outer loop of <y,Ax> using Kokkos::parallel_reduce.
#include <stdlib.h>
#include <string>
#include <unistd.h>
Expand Down Expand Up @@ -109,10 +107,18 @@ void print_options(std::ostream &os, const char *app_name, unsigned int indent =
<< std::endl
<< spaces << "Parameters:" << std::endl
<< spaces << " Parallelism (select one of the following):" << std::endl
<< spaces << " --serial <N> Execute serially." << std::endl
#ifdef KOKKOS_ENABLE_SERIAL
<< spaces << " --serial Execute serially." << std::endl
#endif
#ifdef KOKKOS_ENABLE_THREADS
<< spaces << " --threads <N> Use N posix threads." << std::endl
#endif
#ifdef KOKKOS_ENABLE_OPENMP
<< spaces << " --openmp <N> Use OpenMP with N threads." << std::endl
<< spaces << " --cuda Use CUDA" << std::endl
#endif
#ifdef KOKKOS_ENABLE_CUDA
<< spaces << " --cuda <id> Use CUDA (device $id)" << std::endl
#endif
<< std::endl
<< spaces << " Required Parameters:" << std::endl
<< spaces << " --amtx <filename> Input file in Matrix Market format (.mtx)." << std::endl
Expand All @@ -123,6 +129,7 @@ void print_options(std::ostream &os, const char *app_name, unsigned int indent =
<< spaces << " COLORING_D2_VB - Vertex Based method using boolean forbidden array (Default)." << std::endl
<< spaces << " COLORING_D2_VB_BIT - VB with Bitvector Forbidden Array" << std::endl
<< spaces << " COLORING_D2_VB_BIT_EF - VB_BIT with Edge Filtering" << std::endl
<< spaces << " COLORING_D2_NB_BIT - VB_BIT with dynamic programming, default on parallel devices" << std::endl

<< std::endl
<< spaces << " Optional Parameters:" << std::endl
Expand All @@ -136,6 +143,16 @@ void print_options(std::ostream &os, const char *app_name, unsigned int indent =
<< spaces << " " << std::endl;
}

static char* getNextArg(int& i, int argc, char** argv)
{
i++;
if(i >= argc)
{
std::cerr << "Error: expected additional command-line argument!\n";
exit(1);
}
return argv[i];
}

int parse_inputs(KokkosKernels::Experiment::Parameters &params, int argc, char **argv)
{
Expand All @@ -146,41 +163,40 @@ int parse_inputs(KokkosKernels::Experiment::Parameters &params, int argc, char *
{
if(0 == strcasecmp(argv[i], "--threads"))
{
params.use_threads = atoi(argv[++i]);
params.use_threads = atoi(getNextArg(i, argc, argv));
}
else if(0 == strcasecmp(argv[i], "--serial"))
{
params.use_serial = atoi(argv[++i]);
params.use_serial = 1;
}
else if(0 == strcasecmp(argv[i], "--openmp"))
{
params.use_openmp = atoi(argv[++i]);
std::cout << "use_openmp = " << params.use_openmp << std::endl;
params.use_openmp = atoi(getNextArg(i, argc, argv));
}
else if(0 == strcasecmp(argv[i], "--cuda"))
{
params.use_cuda = 1;
params.use_cuda = 1 + atoi(getNextArg(i, argc, argv));
}
else if(0 == strcasecmp(argv[i], "--repeat"))
{
params.repeat = atoi(argv[++i]);
params.repeat = atoi(getNextArg(i, argc, argv));
}
else if(0 == strcasecmp(argv[i], "--chunksize"))
{
params.chunk_size = atoi(argv[++i]);
params.chunk_size = atoi(getNextArg(i, argc, argv));
}
else if(0 == strcasecmp(argv[i], "--teamsize"))
{
params.team_size = atoi(argv[++i]);
params.team_size = atoi(getNextArg(i, argc, argv));
}
else if(0 == strcasecmp(argv[i], "--vectorsize"))
{
params.vector_size = atoi(argv[++i]);
params.vector_size = atoi(getNextArg(i, argc, argv));
}
else if(0 == strcasecmp(argv[i], "--amtx"))
{
got_required_param_amtx = true;
params.a_mtx_bin_file = argv[++i];
params.a_mtx_bin_file = getNextArg(i, argc, argv);
}
else if(0 == strcasecmp(argv[i], "--dynamic"))
{
Expand Down Expand Up @@ -218,6 +234,11 @@ int parse_inputs(KokkosKernels::Experiment::Parameters &params, int argc, char *
params.algorithm = 5;
got_required_param_algorithm = true;
}
else if(0 == strcasecmp(argv[i], "COLORING_D2_NB_BIT"))
{
params.algorithm = 6;
got_required_param_algorithm = true;
}
else
{
std::cerr << "2-Unrecognized command line argument #" << i << ": " << argv[i] << std::endl;
Expand Down Expand Up @@ -353,6 +374,10 @@ void run_experiment(crsGraph_t crsGraph, int num_cols, Parameters params)
kh.create_distance2_graph_coloring_handle(COLORING_D2_VB_BIT_EF);
label_algorithm = "COLORING_D2_VB_BIT_EF";
break;
case 6:
kh.create_distance2_graph_coloring_handle(COLORING_D2_NB_BIT);
label_algorithm = "COLORING_D2_NB_BIT";
break;
default:
kh.create_distance2_graph_coloring_handle(COLORING_D2_VB);
label_algorithm = "COLORING_D2_VB";
Expand Down Expand Up @@ -640,7 +665,9 @@ int main(int argc, char *argv[])
<< "Sizeof(size_type): " << sizeof(kk_size_type) << std::endl;

const int num_threads = params.use_openmp; // Assumption is that use_openmp variable is provided as number of threads
const int device_id = 0;
int device_id = 0;
if(params.use_cuda)
device_id = params.use_cuda - 1;
Kokkos::initialize(Kokkos::InitArguments(num_threads, -1, device_id));

// Print out verbose information about the configuration of the run.
Expand Down
92 changes: 0 additions & 92 deletions src/graph/KokkosGraph_Distance1Color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ void graph_color_symbolic(
gch->set_vertex_colors(colors_out);
}



template <class KernelHandle,typename lno_row_view_t_, typename lno_nnz_view_t_>
void graph_color(
KernelHandle *handle,
Expand All @@ -136,96 +134,6 @@ void graph_color(
graph_color_symbolic(handle, num_rows, num_cols, row_map, entries, is_symmetric);
}


// Distance 2 graph coloring -- serial only --
// todo: move this over to the Distance2 handle
template <class KernelHandle,
typename lno_row_view_t_, typename lno_nnz_view_t_,
typename lno_col_view_t_, typename lno_colnnz_view_t_>
void graph_compute_distance2_color_serial(
KernelHandle *handle,
typename KernelHandle::nnz_lno_t num_rows,
typename KernelHandle::nnz_lno_t num_cols,
lno_row_view_t_ row_map,
lno_nnz_view_t_ row_entries,
//if graph is symmetric, simply give same for col_map and row_map, and row_entries and col_entries.
lno_col_view_t_ col_map,
lno_colnnz_view_t_ col_entries)
{

Kokkos::Impl::Timer timer;
typename KernelHandle::GraphColoringHandleType *gch = handle->get_graph_coloring_handle();

ColoringAlgorithm algorithm = gch->get_coloring_algo_type();

typedef typename KernelHandle::GraphColoringHandleType::color_view_t color_view_type;

// typedef typename Impl::GraphColor<typename KernelHandle::GraphColoringHandleType, lno_row_view_t_, lno_nnz_view_t_>BaseGraphColoring;

int num_phases = 0;

switch (algorithm)
{
#if 0 // SERIAL shouldn't be in the d2 coloring function since you can get it from graph_color()
case COLORING_SERIAL:
{
color_view_type colors_out = color_view_type("Graph Colors", num_rows);
BaseGraphColoring gc(num_rows, row_entries.extent(0), row_map, row_entries, gch);
gc.d2_color_graph/*<lno_col_view_t_,lno_colnnz_view_t_>*/(colors_out, num_phases, num_cols, col_map, col_entries);
gch->set_num_phases(num_phases);
gch->set_vertex_colors(colors_out);
break;
}
#endif

// todo: Remove SERIAL Distance-2 Graph Coloring from this interface
//
case COLORING_SERIAL2:
{
color_view_type colors_out = color_view_type("Graph Colors", num_rows);
Impl::GraphColor2<typename KernelHandle::GraphColoringHandleType, lno_row_view_t_, lno_nnz_view_t_>
gc(num_rows, row_entries.extent(0), row_map, row_entries, gch);
gc.d2_color_graph(colors_out, num_phases, num_cols, col_map, col_entries);
gch->set_num_phases(num_phases);
gch->set_vertex_colors(colors_out);
break;
}

default:
{
color_view_type colors_out = color_view_type("Graph Colors", num_rows);
Impl::GraphColor2<typename KernelHandle::GraphColoringHandleType, lno_row_view_t_, lno_nnz_view_t_>
gc(num_rows, row_entries.extent(0), row_map, row_entries, gch);
gc.d2_color_graph(colors_out, num_phases, num_cols, col_map, col_entries);
gch->set_num_phases(num_phases);
gch->set_vertex_colors(colors_out);
break;
}
}

double coloring_time = timer.seconds();
gch->add_to_overall_coloring_time(coloring_time);
gch->set_coloring_time(coloring_time);
}


#if defined(KOKKOS_ENABLE_DEPRECATED_CODE)
template <class KernelHandle, typename lno_row_view_t_, typename lno_nnz_view_t_, typename lno_col_view_t_, typename lno_colnnz_view_t_>
void d2_graph_color(KernelHandle *handle,
typename KernelHandle::nnz_lno_t num_rows,
typename KernelHandle::nnz_lno_t num_cols,
lno_row_view_t_ row_map,
lno_nnz_view_t_ row_entries,
//if graph is symmetric, simply give same for col_map and row_map, and row_entries and col_entries.
lno_col_view_t_ col_map,
lno_colnnz_view_t_ col_entries)
{
graph_compute_distance2_color_serial(handle, num_rows, num_cols, row_map, row_entries, col_map, col_entries);
std::cout << "Deprecation warning: d2_graph_color() will be replaced with graph_compute_distance2_color_serial()" << std::endl;
}
#endif


} // end namespace Experimental
} // end namespace KokkosGraph

Expand Down
Loading

0 comments on commit 4d9abd8

Please sign in to comment.