Skip to content

Commit

Permalink
deprecate number_of_edges() in graph_view.hpp and replace this with c…
Browse files Browse the repository at this point in the history
…ompute_number_of_edges
  • Loading branch information
seunghwak committed Nov 29, 2023
1 parent 3a24f30 commit 2d04112
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 26 deletions.
12 changes: 7 additions & 5 deletions cpp/include/cugraph/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class graph_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if_t<mu
graph_meta_t<vertex_t, edge_t, multi_gpu> meta,
bool do_expensive_check = false);

edge_t number_of_edges() const { return this->number_of_edges_; }

graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu> view() const
{
std::vector<raft::device_span<edge_t const>> offsets(edge_partition_offsets_.size());
Expand Down Expand Up @@ -201,7 +203,7 @@ class graph_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if_t<mu
graph_view_meta_t<vertex_t, edge_t, store_transposed, multi_gpu>{
this->number_of_vertices(),
this->number_of_edges(),
this->graph_properties(),
this->properties_,
partition_,
edge_partition_segment_offsets_,
local_sorted_unique_edge_srcs,
Expand Down Expand Up @@ -279,15 +281,15 @@ class graph_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if_t<!m
graph_meta_t<vertex_t, edge_t, multi_gpu> meta,
bool do_expensive_check = false);

edge_t number_of_edges() const { return this->number_of_edges_; }

graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu> view() const
{
return graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu>(
raft::device_span<edge_t const>(offsets_.data(), offsets_.size()),
raft::device_span<vertex_t const>(indices_.data(), indices_.size()),
graph_view_meta_t<vertex_t, edge_t, store_transposed, multi_gpu>{this->number_of_vertices(),
this->number_of_edges(),
this->graph_properties(),
segment_offsets_});
graph_view_meta_t<vertex_t, edge_t, store_transposed, multi_gpu>{
this->number_of_vertices(), this->number_of_edges(), this->properties_, segment_offsets_});
}

private:
Expand Down
31 changes: 22 additions & 9 deletions cpp/include/cugraph/graph_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,6 @@ class graph_base_t {
properties_(properties){};

vertex_t number_of_vertices() const { return number_of_vertices_; }
edge_t number_of_edges() const
{
CUGRAPH_EXPECTS(!(this->has_edge_mask()), "unimplemented.");
return number_of_edges_;
}

template <typename vertex_type = vertex_t>
std::enable_if_t<std::is_signed<vertex_type>::value, bool> is_valid_vertex(vertex_type v) const
Expand Down Expand Up @@ -300,13 +295,11 @@ class graph_base_t {
}

protected:
graph_properties_t graph_properties() const { return properties_; }
edge_t number_of_edges_{0};
graph_properties_t properties_{};

private:
vertex_t number_of_vertices_{0};
edge_t number_of_edges_{0};

graph_properties_t properties_{};

std::optional<edge_property_view_t<edge_t, uint32_t const*, bool>> edge_mask_view_{std::nullopt};
};
Expand Down Expand Up @@ -635,6 +628,16 @@ class graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if
major_value_range_start_offset);
}

// FIXME: deprecated, replaced with copmute_number_of_edges (which works with or without edge
// masking)
edge_t number_of_edges() const
{
CUGRAPH_EXPECTS(!(this->has_edge_mask()), "unimplemented.");
return this->number_of_edges_;
}

edge_t compute_number_of_edges(raft::handle_t const& handle) const;

rmm::device_uvector<edge_t> compute_in_degrees(raft::handle_t const& handle) const;
rmm::device_uvector<edge_t> compute_out_degrees(raft::handle_t const& handle) const;

Expand Down Expand Up @@ -906,6 +909,16 @@ class graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if
offsets_, indices_, this->number_of_vertices());
}

// FIXME: deprecated, replaced with copmute_number_of_edges (which works with or without edge
// masking)
edge_t number_of_edges() const
{
CUGRAPH_EXPECTS(!(this->has_edge_mask()), "unimplemented.");
return this->number_of_edges_;
}

edge_t compute_number_of_edges(raft::handle_t const& handle) const;

rmm::device_uvector<edge_t> compute_in_degrees(raft::handle_t const& handle) const;
rmm::device_uvector<edge_t> compute_out_degrees(raft::handle_t const& handle) const;

Expand Down
9 changes: 5 additions & 4 deletions cpp/src/prims/per_v_transform_reduce_incoming_outgoing_e.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,11 @@ void per_v_transform_reduce_e(raft::handle_t const& handle,
value_size = sizeof(T);
}

auto avg_vertex_degree = graph_view.number_of_vertices() > 0
? (static_cast<double>(graph_view.number_of_edges()) /
static_cast<double>(graph_view.number_of_vertices()))
: double{0.0};
auto avg_vertex_degree =
graph_view.number_of_vertices() > 0
? (static_cast<double>(graph_view.compute_number_of_edges(handle)) /
static_cast<double>(graph_view.number_of_vertices()))
: double{0.0};

num_streams =
std::min(static_cast<size_t>(avg_vertex_degree * (static_cast<double>(sizeof(vertex_t)) /
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/prims/update_edge_src_dst_property.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ void update_edge_minor_property(raft::handle_t const& handle,
bcast_size *= sizeof(typename EdgeMinorPropertyOutputWrapper::value_type);
}
auto num_concurrent_bcasts =
(static_cast<size_t>(graph_view.number_of_edges() / comm_size) * sizeof(vertex_t)) /
(static_cast<size_t>(graph_view.compute_number_of_edges(handle) / comm_size) *
sizeof(vertex_t)) /
std::max(bcast_size, size_t{1});
num_concurrent_bcasts = std::max(num_concurrent_bcasts, size_t{1});
num_concurrent_bcasts = std::min(num_concurrent_bcasts, static_cast<size_t>(major_comm_size));
Expand Down
32 changes: 32 additions & 0 deletions cpp/src/structure/graph_view_impl.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,38 @@ graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if_t<!mu
// skip expensive error checks as this function is only called by graph_t
}

template <typename vertex_t, typename edge_t, bool store_transposed, bool multi_gpu>
edge_t graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if_t<multi_gpu>>::
compute_number_of_edges(raft::handle_t const& handle) const
{
if (this->has_edge_mask()) {
edge_t ret{};
auto value_firsts = (*(this->edge_mask_view())).value_firsts();
auto edge_counts = (*(this->edge_mask_view())).edge_counts();
for (size_t i = 0; i < value_firsts.size(); ++i) {
ret += static_cast<edge_t>(detail::count_set_bits(handle, value_firsts[i], edge_counts[i]));
}
return ret;
} else {
return this->number_of_edges_;
}
}

template <typename vertex_t, typename edge_t, bool store_transposed, bool multi_gpu>
edge_t graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if_t<!multi_gpu>>::
compute_number_of_edges(raft::handle_t const& handle) const
{
if (this->has_edge_mask()) {
auto value_firsts = (*(this->edge_mask_view())).value_firsts();
auto edge_counts = (*(this->edge_mask_view())).edge_counts();
assert(value_firsts.size() == 0);
assert(edge_counts.size() == 0);
return static_cast<edge_t>(detail::count_set_bits(handle, value_firsts[0], edge_counts[0]));
} else {
return this->number_of_edges_;
}
}

template <typename vertex_t, typename edge_t, bool store_transposed, bool multi_gpu>
rmm::device_uvector<edge_t>
graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if_t<multi_gpu>>::
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/traversal/od_shortest_distances_impl.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ rmm::device_uvector<weight_t> od_shortest_distances(
// 1. check input arguments

auto const num_vertices = graph_view.number_of_vertices();
auto const num_edges = graph_view.number_of_edges();
auto const num_edges = graph_view.compute_number_of_edges(handle);

CUGRAPH_EXPECTS(num_vertices != 0 || (origins.size() == 0 && destinations.size() == 0),
"Invalid input argument: the input graph is empty but origins.size() > 0 or "
Expand Down Expand Up @@ -1049,7 +1049,7 @@ rmm::device_uvector<weight_t> od_shortest_distances(
CUGRAPH_EXPECTS(!graph_view.has_edge_mask(), "unimplemented.");

auto const num_vertices = graph_view.number_of_vertices();
auto const num_edges = graph_view.number_of_edges();
auto const num_edges = graph_view.compute_number_of_edges(handle);

weight_t average_vertex_degree =
static_cast<weight_t>(num_edges) / static_cast<weight_t>(num_vertices);
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/traversal/sssp_impl.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void sssp(raft::handle_t const& handle,
"GraphViewType should support the push model.");

auto const num_vertices = push_graph_view.number_of_vertices();
auto const num_edges = push_graph_view.number_of_edges();
auto const num_edges = push_graph_view.compute_number_of_edges(handle);
if (num_vertices == 0) { return; }

// implements the Near-Far Pile method in
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/utilities/cugraph_ops_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ops::graph::csc<EdgeTypeT, NodeTypeT> get_graph(
ops::graph::csc<EdgeTypeT, NodeTypeT> graph;
graph.n_src_nodes = gview.number_of_vertices();
graph.n_dst_nodes = gview.number_of_vertices();
graph.n_indices = gview.number_of_edges();
graph.n_indices = gview.local_edge_partition_view().number_of_edges();
// FIXME this is sufficient for now, but if there is a fast (cached) way
// of getting max degree, use that instead
graph.dst_max_in_degree = std::numeric_limits<EdgeTypeT>::max();
Expand Down
2 changes: 1 addition & 1 deletion cpp/tests/link_analysis/hits_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class Tests_Hits : public ::testing::TestWithParam<std::tuple<Hits_Usecase, inpu
offsets.data(),
indices.data(),
unrenumbered_graph_view.number_of_vertices(),
unrenumbered_graph_view.number_of_edges(),
unrenumbered_graph_view.compute_number_of_edges(handle),
maximum_iterations,
(hits_usecase.check_initial_input) ? std::make_optional(initial_random_hubs.data())
: std::nullopt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ class Tests_MGPerVRandomSelectTransformOutgoingE
sg_graph_view.local_edge_partition_view().offsets().begin(),
sg_graph_view.local_edge_partition_view().offsets().end(),
sg_offsets.begin());
rmm::device_uvector<vertex_t> sg_indices(sg_graph_view.number_of_edges(),
handle_->get_stream());
rmm::device_uvector<vertex_t> sg_indices(
sg_graph_view.local_edge_partition_view().indices().size(), handle_->get_stream());
thrust::copy(handle_->get_thrust_policy(),
sg_graph_view.local_edge_partition_view().indices().begin(),
sg_graph_view.local_edge_partition_view().indices().end(),
Expand Down

0 comments on commit 2d04112

Please sign in to comment.