This repository has been archived by the owner on Dec 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from bkj/dev/api_20201120
API improvements.
- Loading branch information
Showing
13 changed files
with
580 additions
and
675 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.