Skip to content

Commit

Permalink
make meta and graph simultaneously
Browse files Browse the repository at this point in the history
  • Loading branch information
bkj committed Oct 27, 2020
1 parent e706ee0 commit 5e39791
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 53 deletions.
4 changes: 2 additions & 2 deletions examples/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 10 additions & 9 deletions examples/sssp/sssp.cu
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@ void test_sssp(int num_arguments, char** argument_array) {
// --
// Build graph + metadata

auto G = graph::build::from_csr_t<memory_space_t::device>(&csr);
auto meta = graph::build::meta_from_csr_t(&csr);
auto [G, meta] = graph::build::from_csr_t<memory_space_t::device>(&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<weight_t> distances(n_vertices);
thrust::device_vector<vertex_t> predecessors(n_vertices);

// --
// Setup problem

Expand All @@ -46,14 +54,7 @@ void test_sssp(int num_arguments, char** argument_array) {
using problem_t = sssp::sssp_problem_t<graph_t, meta_t>;
using enactor_t = sssp::sssp_enactor_t<problem_t>;

vertex_t single_source = 0;
param_t param(single_source);

vertex_t n_vertices = meta[0].get_number_of_vertices();

thrust::device_vector<weight_t> distances(n_vertices);
thrust::device_vector<vertex_t> predecessors(n_vertices);

result_t result(
distances.data().get(),
predecessors.data().get()
Expand Down
40 changes: 18 additions & 22 deletions gunrock/graph/build.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#pragma once

#include <tuple>

namespace gunrock {
namespace graph {
namespace build {
Expand Down Expand Up @@ -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;
Expand All @@ -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<space, vertex_type, edge_type, weight_type>>;
Expand All @@ -113,8 +117,21 @@ auto from_csr_t(typename vertex_vector_t::value_type const& r,
} else {
host::csr_t<graph_type>(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<h_space, vertex_type, edge_type, weight_type>>;

return O;
typename vector<meta_type, h_space>::type P(1);
meta_type M;

M.set(r, c, nnz, nullptr, nullptr, nullptr);
host::csr_t<meta_type>(M, memory::raw_pointer_cast(P.data()));

return std::make_pair(O, P);
}

template <memory_space_t space, typename csr_t>
Expand All @@ -128,27 +145,6 @@ auto from_csr_t(csr_t* csr) {
csr->nonzero_values);
}

template <typename csr_t>
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<space, vertex_type, edge_type, weight_type>>;

typename vector<graph_type, space>::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<graph_type>(G, memory::raw_pointer_cast(O.data()));

return O;
}

} // namespace build
} // namespace graph
} // namespace gunrock
40 changes: 20 additions & 20 deletions gunrock/util/type_traits.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

#include <type_traits>

namespace std {
// namespace std {

// Supported in C++ 17 (https://en.cppreference.com/w/cpp/types/disjunction)
template <class...>
struct disjunction : std::false_type {};
template <class B1>
struct disjunction<B1> : B1 {};
template <class B1, class... Bn>
struct disjunction<B1, Bn...>
: std::conditional_t<bool(B1::value), B1, disjunction<Bn...>> {};
// // Supported in C++ 17 (https://en.cppreference.com/w/cpp/types/disjunction)
// template <class...>
// struct disjunction : std::false_type {};
// template <class B1>
// struct disjunction<B1> : B1 {};
// template <class B1, class... Bn>
// struct disjunction<B1, Bn...>
// : std::conditional_t<bool(B1::value), B1, disjunction<Bn...>> {};

template <class... B>
constexpr bool disjunction_v =
disjunction<B...>::value; // C++17 supports inline constexpr bool
// template <class... B>
// constexpr bool disjunction_v =
// disjunction<B...>::value; // C++17 supports inline constexpr bool

// Supported in C++ 17 (https://en.cppreference.com/w/cpp/types/is_arithmetic)
template <class T>
constexpr bool is_arithmetic_v = is_arithmetic<T>::value;
// // Supported in C++ 17 (https://en.cppreference.com/w/cpp/types/is_arithmetic)
// template <class T>
// constexpr bool is_arithmetic_v = is_arithmetic<T>::value;

// Supported in C++ 17
// (https://en.cppreference.com/w/cpp/types/is_floating_point)
template <class T>
constexpr bool is_floating_point_v = is_floating_point<T>::value;
} // namespace std
// // Supported in C++ 17
// // (https://en.cppreference.com/w/cpp/types/is_floating_point)
// template <class T>
// constexpr bool is_floating_point_v = is_floating_point<T>::value;
// } // namespace std

0 comments on commit 5e39791

Please sign in to comment.