Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #10 from bkj/dev/api_20201120
Browse files Browse the repository at this point in the history
API improvements.
  • Loading branch information
neoblizz authored Nov 20, 2020
2 parents de2606f + cafda93 commit 3d1cdc7
Show file tree
Hide file tree
Showing 13 changed files with 580 additions and 675 deletions.
28 changes: 14 additions & 14 deletions examples/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ SM_TARGETS = $(GEN_SM61)
#-------------------------------------------------------------------------------

ifeq (DARWIN, $(findstring DARWIN, $(OSUPPER)))
OMP_INC = -I"/usr/local/include/libiomp"
OMP_LINK = -Xlinker /usr/local/lib/libiomp5.dylib
OMP_INC = -I"/usr/local/include/libiomp"
OMP_LINK = -Xlinker /usr/local/lib/libiomp5.dylib
else
OMP_INC =
OMP_LINK = -Xcompiler -fopenmp -Xlinker -lgomp
OMP_INC =
OMP_LINK = -Xcompiler -fopenmp -Xlinker -lgomp
endif

EXT_INC = ../../externals
CUDA_INC = -I"$(shell dirname $(NVCC))/../include"
MGPU_INC = -I"$(EXT_INC)/moderngpu/src"
JSON_INC = -I"$(EXT_INC)/rapidjson/include"
MTX_INC = -I"$(EXT_INC)/mtx"
EXT_INC = ../../externals
CUDA_INC = -I"$(shell dirname $(NVCC))/../include"
MGPU_INC = -I"$(EXT_INC)/moderngpu/src"
JSON_INC = -I"$(EXT_INC)/rapidjson/include"
MTX_INC = -I"$(EXT_INC)/mtx"

CUB = -lcub
CUSPARSE = -lcusparse
CUB = -lcub
CUSPARSE = -lcusparse

GUNROCK_DEF = -Xcompiler -DGUNROCKVERSION=2.0.0
LINK = $(BOOST_LINK) $(OMP_LINK) $(METIS_LINK) $(GUNROCK_DEF)
INC = -I.. -I../.. $(CUDA_CPP) $(OMP_INC) $(MGPU_INC) $(CUB_INC) $(JSON_INC) $(CUDA_INC) $(MTX_INC) $(LINK)
GUNROCK_DEF = -Xcompiler -DGUNROCKVERSION=2.0.0
LINK = $(BOOST_LINK) $(OMP_LINK) $(METIS_LINK) $(GUNROCK_DEF)
INC = -I.. -I../.. $(CUDA_CPP) $(OMP_INC) $(MGPU_INC) $(CUB_INC) $(JSON_INC) $(CUDA_INC) $(MTX_INC) $(LINK)

#-------------------------------------------------------------------------------
# Defines
Expand Down
104 changes: 44 additions & 60 deletions examples/color/color.cu
Original file line number Diff line number Diff line change
@@ -1,80 +1,64 @@
#include <cstdlib> // EXIT_SUCCESS
#include <set>

#include <gunrock/applications/color/color.hxx>
#include <gunrock/applications/color.hxx>

using namespace gunrock;

/**
* @brief Count unique number of colors used to color the graph.
*
* @tparam T
* @param v
* @return std::size_t
*/
template <typename T>
std::size_t unique_colors(const thrust::host_vector<T>& v) {
std::size_t num_unique_elements = 0;
std::unordered_set<int> set;

for (const auto& elem : v) {
if (set.find(elem) == set.end()) {
set.insert(elem);
++num_unique_elements;
}
}

return num_unique_elements;
}
using namespace memory;

void test_color(int num_arguments, char** argument_array) {
using vertex_t = int;
using edge_t = int;
using weight_t = float;

constexpr memory::memory_space_t space = memory::memory_space_t::device;


if (num_arguments != 2) {
std::cerr << "usage: ./bin/color filename.mtx" << std::endl;
std::cerr << "usage: ./bin/<program-name> filename.mtx" << std::endl;
exit(1);
}

// Load Matrix-Market file & convert the resultant COO into CSR format.

// --
// Define types

using vertex_t = int;
using edge_t = int;
using weight_t = float;

// --
// IO

std::string filename = argument_array[1];

io::matrix_market_t<vertex_t, edge_t, weight_t> mm;
auto coo = mm.load(filename);
format::csr_t<memory::memory_space_t::host, vertex_t, edge_t, weight_t> csr;
csr = coo;

// Move data to device.
thrust::device_vector<edge_t> d_Ap = csr.row_offsets;
thrust::device_vector<vertex_t> d_Aj = csr.column_indices;
thrust::device_vector<weight_t> d_Ax = csr.nonzero_values;
format::csr_t<memory::memory_space_t::device, vertex_t, edge_t, weight_t> csr;
csr.from_coo(mm.load(filename));

thrust::device_vector<vertex_t> d_colors(csr.number_of_rows);

// calling color
float elapsed =
color::execute<space>(csr.number_of_rows, // number of vertices
csr.number_of_columns, // number of columns
csr.number_of_nonzeros, // number of edges
d_Ap, // row_offsets
d_Aj, // column_indices
d_Ax, // nonzero values
d_colors // output colors
);

thrust::host_vector<vertex_t> colors = d_colors;
std::cout << "Number of Colors: " << unique_colors(colors) << std::endl;
std::cout << "Colors (output) = ";
thrust::copy(d_colors.begin(), d_colors.end(),
std::ostream_iterator<vertex_t>(std::cout, " "));
// --
// Build graph + metadata

auto [G, meta] = graph::build::from_csr_t<memory_space_t::device>(&csr);

// --
// Params and memory allocation

vertex_t n_vertices = meta[0].get_number_of_vertices();
thrust::device_vector<vertex_t> colors(n_vertices);

// --
// Run problem

float elapsed = gunrock::color::run(
G,
meta,
colors.data().get()
);

// --
// Log

std::cout << "Distances (output) = ";
thrust::copy(colors.begin(), colors.end(), std::ostream_iterator<weight_t>(std::cout, " "));
std::cout << std::endl;

std::cout << "color Elapsed Time: " << elapsed << " (ms)" << std::endl;
}

int main(int argc, char** argv) {
test_color(argc, argv);
return EXIT_SUCCESS;
}
}
70 changes: 45 additions & 25 deletions examples/sssp/sssp.cu
Original file line number Diff line number Diff line change
@@ -1,44 +1,64 @@
#include <cstdlib> // EXIT_SUCCESS

#include <gunrock/applications/sssp/sssp.hxx>
#include <gunrock/applications/sssp.hxx>

using namespace gunrock;
using namespace memory;

void test_sssp(int num_arguments, char** argument_array) {
using vertex_t = int;
using edge_t = int;
using weight_t = float;


if (num_arguments != 2) {
std::cerr << "usage: ./bin/color filename.mtx" << std::endl;
std::cerr << "usage: ./bin/<program-name> filename.mtx" << std::endl;
exit(1);
}

// Load Matrix-Market file & convert the resultant COO into CSR format.

// --
// Define types

using vertex_t = int;
using edge_t = int;
using weight_t = float;

// --
// IO

std::string filename = argument_array[1];

io::matrix_market_t<vertex_t, edge_t, weight_t> mm;
auto coo = mm.load(filename);

// convert coo to csr
format::csr_t<memory_space_t::device, vertex_t, edge_t, weight_t> csr;
csr = coo; // Able to convert host-based coo_t to device-based csr (or host
// to host). As of right now, it requires coo to be host side.

vertex_t source = 0;
thrust::device_vector<weight_t> d_distances(csr.number_of_rows);
format::csr_t<memory::memory_space_t::device, vertex_t, edge_t, weight_t> csr;
csr.from_coo(mm.load(filename));

// calling sssp
float elapsed = sssp::execute(csr, // device csr_t sparse data
source, // single source
d_distances // output distances
// --
// Build graph + metadata

auto [G, meta] = graph::build::from_csr_t<memory_space_t::device>(&csr);

// --
// Params and memory allocation

vertex_t single_source = 0;

vertex_t n_vertices = meta->get_number_of_vertices();
thrust::device_vector<weight_t> distances(n_vertices);
thrust::device_vector<vertex_t> predecessors(n_vertices);

// --
// Run problem

float elapsed = gunrock::sssp::run(
G,
meta,
single_source,
distances.data().get(),
predecessors.data().get()
);


// --
// Log

std::cout << "Distances (output) = ";
thrust::copy(d_distances.begin(), d_distances.end(),
std::ostream_iterator<weight_t>(std::cout, " "));
thrust::copy(distances.begin(), distances.end(), std::ostream_iterator<weight_t>(std::cout, " "));
std::cout << std::endl;

std::cout << "SSSP Elapsed Time: " << elapsed << " (ms)" << std::endl;
}

Expand Down
Loading

0 comments on commit 3d1cdc7

Please sign in to comment.