Skip to content

Commit

Permalink
Count self-loops and multi-edges (#1939)
Browse files Browse the repository at this point in the history
Close #537

Count the number of self-loops & multi-edges.

- [x] API update
- [x] Implement count self-loops
- [x] Implement count multi-edges
- [x] Add C++ test suites.

Authors:
  - Seunghwa Kang (https://github.com/seunghwak)

Approvers:
  - Chuck Hastings (https://github.com/ChuckHastings)
  - Kumar Aatish (https://github.com/kaatish)

URL: #1939
  • Loading branch information
seunghwak authored Nov 11, 2021
1 parent 0730fea commit 0678065
Show file tree
Hide file tree
Showing 11 changed files with 801 additions and 18 deletions.
4 changes: 2 additions & 2 deletions cpp/include/cugraph/detail/decompress_matrix_partition.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ __global__ void for_all_major_for_all_nbr_mid_degree(
auto major =
matrix_partition.get_major_from_major_offset_nocheck(static_cast<vertex_t>(major_offset));
vertex_t const* indices{nullptr};
thrust::optional<weight_t const*> weights{nullptr};
thrust::optional<weight_t const*> weights{thrust::nullopt};
edge_t local_degree{};
thrust::tie(indices, weights, local_degree) = matrix_partition.get_local_edges(major_offset);
auto local_offset = matrix_partition.get_local_offset(major_offset);
Expand All @@ -81,7 +81,7 @@ __global__ void for_all_major_for_all_nbr_high_degree(
auto major =
matrix_partition.get_major_from_major_offset_nocheck(static_cast<vertex_t>(major_offset));
vertex_t const* indices{nullptr};
thrust::optional<weight_t const*> weights{nullptr};
thrust::optional<weight_t const*> weights{thrust::nullopt};
edge_t local_degree{};
thrust::tie(indices, weights, local_degree) =
matrix_partition.get_local_edges(static_cast<vertex_t>(major_offset));
Expand Down
6 changes: 6 additions & 0 deletions cpp/include/cugraph/graph_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,9 @@ class graph_view_t<vertex_t,
weight_t compute_max_in_weight_sum(raft::handle_t const& handle) const;
weight_t compute_max_out_weight_sum(raft::handle_t const& handle) const;

edge_t count_self_loops(raft::handle_t const& handle) const;
edge_t count_multi_edges(raft::handle_t const& handle) const;

std::optional<vertex_t const*> get_local_sorted_unique_edge_row_begin() const
{
return local_sorted_unique_edge_row_first_;
Expand Down Expand Up @@ -833,6 +836,9 @@ class graph_view_t<vertex_t,
weight_t compute_max_in_weight_sum(raft::handle_t const& handle) const;
weight_t compute_max_out_weight_sum(raft::handle_t const& handle) const;

edge_t count_self_loops(raft::handle_t const& handle) const;
edge_t count_multi_edges(raft::handle_t const& handle) const;

std::optional<vertex_t const*> get_local_sorted_unique_edge_row_begin() const
{
return std::nullopt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ __global__ void for_all_major_for_all_nbr_hypersparse(
auto major_idx =
major_start_offset + idx; // major_offset != major_idx in the hypersparse region
vertex_t const* indices{nullptr};
thrust::optional<weight_t const*> weights{nullptr};
thrust::optional<weight_t const*> weights{thrust::nullopt};
edge_t local_degree{};
thrust::tie(indices, weights, local_degree) =
matrix_partition.get_local_edges(static_cast<vertex_t>(major_idx));
Expand Down Expand Up @@ -195,7 +195,7 @@ __global__ void for_all_major_for_all_nbr_low_degree(
while (idx < static_cast<size_t>(major_last - major_first)) {
auto major_offset = major_start_offset + idx;
vertex_t const* indices{nullptr};
thrust::optional<weight_t const*> weights{nullptr};
thrust::optional<weight_t const*> weights{thrust::nullopt};
edge_t local_degree{};
thrust::tie(indices, weights, local_degree) =
matrix_partition.get_local_edges(static_cast<vertex_t>(major_offset));
Expand Down Expand Up @@ -316,7 +316,7 @@ __global__ void for_all_major_for_all_nbr_mid_degree(
while (idx < static_cast<size_t>(major_last - major_first)) {
auto major_offset = major_start_offset + idx;
vertex_t const* indices{nullptr};
thrust::optional<weight_t const*> weights{nullptr};
thrust::optional<weight_t const*> weights{thrust::nullopt};
edge_t local_degree{};
thrust::tie(indices, weights, local_degree) = matrix_partition.get_local_edges(major_offset);
[[maybe_unused]] auto e_op_result_sum =
Expand Down Expand Up @@ -409,7 +409,7 @@ __global__ void for_all_major_for_all_nbr_high_degree(
while (idx < static_cast<size_t>(major_last - major_first)) {
auto major_offset = major_start_offset + idx;
vertex_t const* indices{nullptr};
thrust::optional<weight_t const*> weights{nullptr};
thrust::optional<weight_t const*> weights{thrust::nullopt};
edge_t local_degree{};
thrust::tie(indices, weights, local_degree) = matrix_partition.get_local_edges(major_offset);
[[maybe_unused]] auto e_op_result_sum =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ __global__ void for_all_major_for_all_nbr_hypersparse(
auto major_idx =
major_start_offset + idx; // major_offset != major_idx in the hypersparse region
vertex_t const* indices{nullptr};
thrust::optional<weight_t const*> weights{nullptr};
thrust::optional<weight_t const*> weights{thrust::nullopt};
edge_t local_degree{};
thrust::tie(indices, weights, local_degree) =
matrix_partition.get_local_edges(static_cast<vertex_t>(major_idx));
Expand Down Expand Up @@ -174,7 +174,7 @@ __global__ void for_all_major_for_all_nbr_low_degree(
auto major =
matrix_partition.get_major_from_major_offset_nocheck(static_cast<vertex_t>(major_offset));
vertex_t const* indices{nullptr};
thrust::optional<weight_t const*> weights{nullptr};
thrust::optional<weight_t const*> weights{thrust::nullopt};
edge_t local_degree{};
thrust::tie(indices, weights, local_degree) =
matrix_partition.get_local_edges(static_cast<vertex_t>(major_offset));
Expand Down Expand Up @@ -234,7 +234,7 @@ __global__ void for_all_major_for_all_nbr_mid_degree(
auto major =
matrix_partition.get_major_from_major_offset_nocheck(static_cast<vertex_t>(major_offset));
vertex_t const* indices{nullptr};
thrust::optional<weight_t const*> weights{nullptr};
thrust::optional<weight_t const*> weights{thrust::nullopt};
edge_t local_degree{};
thrust::tie(indices, weights, local_degree) =
matrix_partition.get_local_edges(static_cast<vertex_t>(major_offset));
Expand Down Expand Up @@ -290,7 +290,7 @@ __global__ void for_all_major_for_all_nbr_high_degree(
auto major =
matrix_partition.get_major_from_major_offset_nocheck(static_cast<vertex_t>(major_offset));
vertex_t const* indices{nullptr};
thrust::optional<weight_t const*> weights{nullptr};
thrust::optional<weight_t const*> weights{thrust::nullopt};
edge_t local_degree{};
thrust::tie(indices, weights, local_degree) =
matrix_partition.get_local_edges(static_cast<vertex_t>(major_offset));
Expand Down
8 changes: 4 additions & 4 deletions cpp/include/cugraph/prims/transform_reduce_e.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ __global__ void for_all_major_for_all_nbr_hypersparse(
auto major_idx =
major_start_offset + idx; // major_offset != major_idx in the hypersparse region
vertex_t const* indices{nullptr};
thrust::optional<weight_t const*> weights{nullptr};
thrust::optional<weight_t const*> weights{thrust::nullopt};
edge_t local_degree{};
thrust::tie(indices, weights, local_degree) = matrix_partition.get_local_edges(major_idx);
auto sum = thrust::transform_reduce(
Expand Down Expand Up @@ -159,7 +159,7 @@ __global__ void for_all_major_for_all_nbr_low_degree(
while (idx < static_cast<size_t>(major_last - major_first)) {
auto major_offset = major_start_offset + idx;
vertex_t const* indices{nullptr};
thrust::optional<weight_t const*> weights{nullptr};
thrust::optional<weight_t const*> weights{thrust::nullopt};
edge_t local_degree{};
thrust::tie(indices, weights, local_degree) = matrix_partition.get_local_edges(major_offset);
auto sum = thrust::transform_reduce(
Expand Down Expand Up @@ -246,7 +246,7 @@ __global__ void for_all_major_for_all_nbr_mid_degree(
while (idx < static_cast<size_t>(major_last - major_first)) {
auto major_offset = major_start_offset + idx;
vertex_t const* indices{nullptr};
thrust::optional<weight_t const*> weights{nullptr};
thrust::optional<weight_t const*> weights{thrust::nullopt};
edge_t local_degree{};
thrust::tie(indices, weights, local_degree) = matrix_partition.get_local_edges(major_offset);
for (edge_t i = lane_id; i < local_degree; i += raft::warp_size()) {
Expand Down Expand Up @@ -317,7 +317,7 @@ __global__ void for_all_major_for_all_nbr_high_degree(
while (idx < static_cast<size_t>(major_last - major_first)) {
auto major_offset = major_start_offset + idx;
vertex_t const* indices{nullptr};
thrust::optional<weight_t const*> weights{nullptr};
thrust::optional<weight_t const*> weights{thrust::nullopt};
edge_t local_degree{};
thrust::tie(indices, weights, local_degree) = matrix_partition.get_local_edges(major_offset);
for (edge_t i = threadIdx.x; i < local_degree; i += blockDim.x) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ __global__ void for_all_frontier_row_for_all_nbr_hypersparse(
auto row_offset = matrix_partition.get_major_offset_from_major_nocheck(row);
auto row_idx = row_start_offset + *row_hypersparse_idx;
vertex_t const* indices{nullptr};
thrust::optional<weight_t const*> weights{nullptr};
thrust::optional<weight_t const*> weights{thrust::nullopt};
edge_t local_out_degree{};
thrust::tie(indices, weights, local_out_degree) = matrix_partition.get_local_edges(row_idx);
for (edge_t i = 0; i < local_out_degree; ++i) {
Expand Down Expand Up @@ -360,7 +360,7 @@ __global__ void for_all_frontier_row_for_all_nbr_low_degree(
}
auto row_offset = matrix_partition.get_major_offset_from_major_nocheck(row);
vertex_t const* indices{nullptr};
thrust::optional<weight_t const*> weights{nullptr};
thrust::optional<weight_t const*> weights{thrust::nullopt};
edge_t local_out_degree{};
thrust::tie(indices, weights, local_out_degree) = matrix_partition.get_local_edges(row_offset);
for (edge_t i = 0; i < local_out_degree; ++i) {
Expand Down Expand Up @@ -428,7 +428,7 @@ __global__ void for_all_frontier_row_for_all_nbr_mid_degree(
}
auto row_offset = matrix_partition.get_major_offset_from_major_nocheck(row);
vertex_t const* indices{nullptr};
thrust::optional<weight_t const*> weights{nullptr};
thrust::optional<weight_t const*> weights{thrust::nullopt};
edge_t local_out_degree{};
thrust::tie(indices, weights, local_out_degree) = matrix_partition.get_local_edges(row_offset);
for (edge_t i = lane_id; i < local_out_degree; i += raft::warp_size()) {
Expand Down Expand Up @@ -494,7 +494,7 @@ __global__ void for_all_frontier_row_for_all_nbr_high_degree(
}
auto row_offset = matrix_partition.get_major_offset_from_major_nocheck(row);
vertex_t const* indices{nullptr};
thrust::optional<weight_t const*> weights{nullptr};
thrust::optional<weight_t const*> weights{thrust::nullopt};
edge_t local_out_degree{};
thrust::tie(indices, weights, local_out_degree) = matrix_partition.get_local_edges(row_offset);
for (edge_t i = threadIdx.x; i < local_out_degree; i += blockDim.x) {
Expand Down
Loading

0 comments on commit 0678065

Please sign in to comment.