From 5e397910963121918ae34cdccf14841a471aa19c Mon Sep 17 00:00:00 2001 From: bkj Date: Tue, 27 Oct 2020 23:11:45 +0000 Subject: [PATCH] make meta and graph simultaneously --- examples/Makefile.inc | 4 ++-- examples/sssp/sssp.cu | 19 +++++++++-------- gunrock/graph/build.hxx | 40 ++++++++++++++++-------------------- gunrock/util/type_traits.hxx | 40 ++++++++++++++++++------------------ 4 files changed, 50 insertions(+), 53 deletions(-) diff --git a/examples/Makefile.inc b/examples/Makefile.inc index f5dd0abf..89c62cb5 100644 --- a/examples/Makefile.inc +++ b/examples/Makefile.inc @@ -67,11 +67,11 @@ DEFINES = -DGIT_SHA1="\"$(shell git rev-parse HEAD)\"" # ARCH = -m64 # endif -NVCCFLAGS += -std=c++14 +NVCCFLAGS += -std=c++17 NVCCFLAGS += $(SM_TARGETS) NVCCFLAGS += --expt-extended-lambda --expt-relaxed-constexpr --use_fast_math --ptxas-options -v --relocatable-device-code true -CXXFLAGS += -std=c++14 +CXXFLAGS += -std=c++17 CXXFLAGS += -Wall CXXFLAGS += -Wno-unused-local-typedefs -Wno-strict-aliasing -Wno-unused-function -Wno-format-security diff --git a/examples/sssp/sssp.cu b/examples/sssp/sssp.cu index 963d0ec3..7c4c1097 100644 --- a/examples/sssp/sssp.cu +++ b/examples/sssp/sssp.cu @@ -32,12 +32,20 @@ void test_sssp(int num_arguments, char** argument_array) { // -- // Build graph + metadata - auto G = graph::build::from_csr_t(&csr); - auto meta = graph::build::meta_from_csr_t(&csr); + auto [G, meta] = graph::build::from_csr_t(&csr); using graph_t = decltype(G)::value_type; using meta_t = decltype(meta)::value_type; + // -- + // Params and memory allocation + + vertex_t single_source = 0; + + vertex_t n_vertices = meta[0].get_number_of_vertices(); + thrust::device_vector distances(n_vertices); + thrust::device_vector predecessors(n_vertices); + // -- // Setup problem @@ -46,14 +54,7 @@ void test_sssp(int num_arguments, char** argument_array) { using problem_t = sssp::sssp_problem_t; using enactor_t = sssp::sssp_enactor_t; - vertex_t single_source = 0; param_t param(single_source); - - vertex_t n_vertices = meta[0].get_number_of_vertices(); - - thrust::device_vector distances(n_vertices); - thrust::device_vector predecessors(n_vertices); - result_t result( distances.data().get(), predecessors.data().get() diff --git a/gunrock/graph/build.hxx b/gunrock/graph/build.hxx index ba718e23..166fb935 100644 --- a/gunrock/graph/build.hxx +++ b/gunrock/graph/build.hxx @@ -11,6 +11,8 @@ #pragma once +#include + namespace gunrock { namespace graph { namespace build { @@ -91,6 +93,7 @@ auto from_csr_t(typename vertex_vector_t::value_type const& r, edge_vector_t& Ap, vertex_vector_t& Aj, weight_vector_t& Ax) { + using vertex_type = typename vertex_vector_t::value_type; using edge_type = typename edge_vector_t::value_type; using weight_type = typename weight_vector_t::value_type; @@ -99,6 +102,7 @@ auto from_csr_t(typename vertex_vector_t::value_type const& r, auto Aj_ptr = memory::raw_pointer_cast(Aj.data()); auto Ax_ptr = memory::raw_pointer_cast(Ax.data()); + // Graph using graph_type = graph::graph_t< space, vertex_type, edge_type, weight_type, graph::graph_csr_t>; @@ -113,8 +117,21 @@ auto from_csr_t(typename vertex_vector_t::value_type const& r, } else { host::csr_t(G, memory::raw_pointer_cast(O.data())); } + + // Meta + constexpr memory_space_t h_space = memory_space_t::host; + + using meta_type = graph::graph_t< + h_space, vertex_type, edge_type, weight_type, + graph::graph_csr_t>; - return O; + typename vector::type P(1); + meta_type M; + + M.set(r, c, nnz, nullptr, nullptr, nullptr); + host::csr_t(M, memory::raw_pointer_cast(P.data())); + + return std::make_pair(O, P); } template @@ -128,27 +145,6 @@ auto from_csr_t(csr_t* csr) { csr->nonzero_values); } -template -auto meta_from_csr_t(csr_t* csr) { - using vertex_type = typename decltype(csr->row_offsets)::value_type; - using edge_type = typename decltype(csr->column_indices)::value_type; - using weight_type = typename decltype(csr->nonzero_values)::value_type; - - constexpr memory_space_t space = memory_space_t::host; - - using graph_type = graph::graph_t< - space, vertex_type, edge_type, weight_type, - graph::graph_csr_t>; - - typename vector::type O(1); - graph_type G; - - G.set(csr->number_of_rows, csr->number_of_columns, csr->number_of_nonzeros, nullptr, nullptr, nullptr); - host::csr_t(G, memory::raw_pointer_cast(O.data())); - - return O; -} - } // namespace build } // namespace graph } // namespace gunrock \ No newline at end of file diff --git a/gunrock/util/type_traits.hxx b/gunrock/util/type_traits.hxx index 01d1cde2..9df0b565 100644 --- a/gunrock/util/type_traits.hxx +++ b/gunrock/util/type_traits.hxx @@ -2,27 +2,27 @@ #include -namespace std { +// namespace std { -// Supported in C++ 17 (https://en.cppreference.com/w/cpp/types/disjunction) -template -struct disjunction : std::false_type {}; -template -struct disjunction : B1 {}; -template -struct disjunction - : std::conditional_t> {}; +// // Supported in C++ 17 (https://en.cppreference.com/w/cpp/types/disjunction) +// template +// struct disjunction : std::false_type {}; +// template +// struct disjunction : B1 {}; +// template +// struct disjunction +// : std::conditional_t> {}; -template -constexpr bool disjunction_v = - disjunction::value; // C++17 supports inline constexpr bool +// template +// constexpr bool disjunction_v = +// disjunction::value; // C++17 supports inline constexpr bool -// Supported in C++ 17 (https://en.cppreference.com/w/cpp/types/is_arithmetic) -template -constexpr bool is_arithmetic_v = is_arithmetic::value; +// // Supported in C++ 17 (https://en.cppreference.com/w/cpp/types/is_arithmetic) +// template +// constexpr bool is_arithmetic_v = is_arithmetic::value; -// Supported in C++ 17 -// (https://en.cppreference.com/w/cpp/types/is_floating_point) -template -constexpr bool is_floating_point_v = is_floating_point::value; -} // namespace std \ No newline at end of file +// // Supported in C++ 17 +// // (https://en.cppreference.com/w/cpp/types/is_floating_point) +// template +// constexpr bool is_floating_point_v = is_floating_point::value; +// } // namespace std \ No newline at end of file