Skip to content

Commit 8009309

Browse files
authored
Update edge triangle count to call a non detail primitive (#4630)
Create a non detail primitive that iterates over each input vertex pair and returns the common destination neighbor list pair in a CSR-like format. closes #3475 Authors: - Joseph Nke (https://github.com/jnke2016) Approvers: - Chuck Hastings (https://github.com/ChuckHastings) - Seunghwa Kang (https://github.com/seunghwak) URL: #4630
1 parent 52c4457 commit 8009309

9 files changed

+93
-19
lines changed

cpp/include/cugraph/algorithms.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1873,12 +1873,16 @@ void triangle_count(raft::handle_t const& handle,
18731873
* @param handle RAFT handle object to encapsulate resources (e.g. CUDA stream, communicator, and
18741874
* handles to various CUDA libraries) to run graph algorithms.
18751875
* @param graph_view Graph view object.
1876+
* * @param do_expensive_check A flag to run expensive checks for input arguments (if set to
1877+
* `true`).
18761878
*
18771879
* @return edge_property_t containing the edge triangle count
18781880
*/
18791881
template <typename vertex_t, typename edge_t, bool multi_gpu>
18801882
edge_property_t<graph_view_t<vertex_t, edge_t, false, multi_gpu>, edge_t> edge_triangle_count(
1881-
raft::handle_t const& handle, graph_view_t<vertex_t, edge_t, false, multi_gpu> const& graph_view);
1883+
raft::handle_t const& handle,
1884+
graph_view_t<vertex_t, edge_t, false, multi_gpu> const& graph_view,
1885+
bool do_expensive_check = false);
18821886

18831887
/*
18841888
* @brief Compute K-Truss.

cpp/src/community/edge_triangle_count_impl.cuh

+12-12
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
#include "detail/graph_partition_utils.cuh"
2020
#include "prims/edge_bucket.cuh"
21+
#include "prims/per_v_pair_dst_nbr_intersection.cuh"
2122
#include "prims/transform_e.cuh"
22-
#include "prims/transform_reduce_dst_nbr_intersection_of_e_endpoints_by_v.cuh"
2323

2424
#include <cugraph/detail/shuffle_wrappers.hpp>
2525
#include <cugraph/graph_functions.hpp>
@@ -124,7 +124,8 @@ struct extract_q_r {
124124
template <typename vertex_t, typename edge_t, bool store_transposed, bool multi_gpu>
125125
edge_property_t<graph_view_t<vertex_t, edge_t, false, multi_gpu>, edge_t> edge_triangle_count_impl(
126126
raft::handle_t const& handle,
127-
graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu> const& graph_view)
127+
graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu> const& graph_view,
128+
bool do_expensive_check)
128129
{
129130
using weight_t = float;
130131
rmm::device_uvector<vertex_t> edgelist_srcs(0, handle.get_stream());
@@ -158,14 +159,11 @@ edge_property_t<graph_view_t<vertex_t, edge_t, false, multi_gpu>, edge_t> edge_t
158159
num_remaining_edges -= chunk_size;
159160
// Perform 'nbr_intersection' in chunks to reduce peak memory.
160161
auto [intersection_offsets, intersection_indices] =
161-
detail::nbr_intersection(handle,
162-
graph_view,
163-
cugraph::edge_dummy_property_t{}.view(),
164-
edge_first + prev_chunk_size,
165-
edge_first + prev_chunk_size + chunk_size,
166-
std::array<bool, 2>{true, true},
167-
false /*FIXME: pass 'do_expensive_check' as argument*/);
168-
162+
per_v_pair_dst_nbr_intersection(handle,
163+
graph_view,
164+
edge_first + prev_chunk_size,
165+
edge_first + prev_chunk_size + chunk_size,
166+
do_expensive_check);
169167
// Update the number of triangles of each (p, q) edges by looking at their intersection
170168
// size
171169
thrust::for_each(
@@ -365,9 +363,11 @@ edge_property_t<graph_view_t<vertex_t, edge_t, false, multi_gpu>, edge_t> edge_t
365363

366364
template <typename vertex_t, typename edge_t, bool multi_gpu>
367365
edge_property_t<graph_view_t<vertex_t, edge_t, false, multi_gpu>, edge_t> edge_triangle_count(
368-
raft::handle_t const& handle, graph_view_t<vertex_t, edge_t, false, multi_gpu> const& graph_view)
366+
raft::handle_t const& handle,
367+
graph_view_t<vertex_t, edge_t, false, multi_gpu> const& graph_view,
368+
bool do_expensive_check)
369369
{
370-
return detail::edge_triangle_count_impl(handle, graph_view);
370+
return detail::edge_triangle_count_impl(handle, graph_view, do_expensive_check);
371371
}
372372

373373
} // namespace cugraph

cpp/src/community/edge_triangle_count_mg_v32_e32.cu

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace cugraph {
2020
// SG instantiation
2121
template edge_property_t<graph_view_t<int32_t, int32_t, false, true>, int32_t> edge_triangle_count(
2222
raft::handle_t const& handle,
23-
cugraph::graph_view_t<int32_t, int32_t, false, true> const& graph_view);
23+
cugraph::graph_view_t<int32_t, int32_t, false, true> const& graph_view,
24+
bool do_expensive_check);
2425

2526
} // namespace cugraph

cpp/src/community/edge_triangle_count_mg_v32_e64.cu

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace cugraph {
2020
// SG instantiation
2121
template edge_property_t<graph_view_t<int32_t, int64_t, false, true>, int64_t> edge_triangle_count(
2222
raft::handle_t const& handle,
23-
cugraph::graph_view_t<int32_t, int64_t, false, true> const& graph_view);
23+
cugraph::graph_view_t<int32_t, int64_t, false, true> const& graph_view,
24+
bool do_expensive_check);
2425

2526
} // namespace cugraph

cpp/src/community/edge_triangle_count_mg_v64_e64.cu

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace cugraph {
2020
// SG instantiation
2121
template edge_property_t<graph_view_t<int64_t, int64_t, false, true>, int64_t> edge_triangle_count(
2222
raft::handle_t const& handle,
23-
cugraph::graph_view_t<int64_t, int64_t, false, true> const& graph_view);
23+
cugraph::graph_view_t<int64_t, int64_t, false, true> const& graph_view,
24+
bool do_expensive_check);
2425

2526
} // namespace cugraph

cpp/src/community/edge_triangle_count_sg_v32_e32.cu

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace cugraph {
2020
// SG instantiation
2121
template edge_property_t<graph_view_t<int32_t, int32_t, false, false>, int32_t> edge_triangle_count(
2222
raft::handle_t const& handle,
23-
cugraph::graph_view_t<int32_t, int32_t, false, false> const& graph_view);
23+
cugraph::graph_view_t<int32_t, int32_t, false, false> const& graph_view,
24+
bool do_expensive_check);
2425

2526
} // namespace cugraph

cpp/src/community/edge_triangle_count_sg_v32_e64.cu

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace cugraph {
2020
// SG instantiation
2121
template edge_property_t<graph_view_t<int32_t, int64_t, false, false>, int64_t> edge_triangle_count(
2222
raft::handle_t const& handle,
23-
cugraph::graph_view_t<int32_t, int64_t, false, false> const& graph_view);
23+
cugraph::graph_view_t<int32_t, int64_t, false, false> const& graph_view,
24+
bool do_expensive_check);
2425

2526
} // namespace cugraph

cpp/src/community/edge_triangle_count_sg_v64_e64.cu

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace cugraph {
2020
// SG instantiation
2121
template edge_property_t<graph_view_t<int64_t, int64_t, false, false>, int64_t> edge_triangle_count(
2222
raft::handle_t const& handle,
23-
cugraph::graph_view_t<int64_t, int64_t, false, false> const& graph_view);
23+
cugraph::graph_view_t<int64_t, int64_t, false, false> const& graph_view,
24+
bool do_expensive_check);
2425

2526
} // namespace cugraph
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2024, NVIDIA CORPORATION.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#pragma once
17+
18+
#include "prims/detail/nbr_intersection.cuh"
19+
20+
#include <raft/core/handle.hpp>
21+
22+
#include <rmm/device_uvector.hpp>
23+
24+
#include <tuple>
25+
26+
namespace cugraph {
27+
28+
/**
29+
* @brief Iterate over each input vertex pair and returns the common destination neighbor list
30+
* pair in a CSR-like format
31+
*
32+
* Iterate over every vertex pair; intersect destination neighbor lists of the two vertices in the
33+
* pair and store the result in a CSR-like format
34+
*
35+
* @tparam GraphViewType Type of the passed non-owning graph object.
36+
* @tparam VertexPairIterator Type of the iterator for input vertex pairs.
37+
* @param handle RAFT handle object to encapsulate resources (e.g. CUDA stream, communicator, and
38+
* handles to various CUDA libraries) to run graph algorithms.
39+
* @param graph_view Non-owning graph object.
40+
* @param vertex_pair_first Iterator pointing to the first (inclusive) input vertex pair.
41+
* @param vertex_pair_last Iterator pointing to the last (exclusive) input vertex pair.
42+
* @param do_expensive_check A flag to run expensive checks for input arguments (if set to `true`).
43+
* @return std::tuple Tuple of intersection offsets and indices.
44+
*/
45+
template <typename GraphViewType, typename VertexPairIterator>
46+
std::tuple<rmm::device_uvector<size_t>, rmm::device_uvector<typename GraphViewType::vertex_type>>
47+
per_v_pair_dst_nbr_intersection(raft::handle_t const& handle,
48+
GraphViewType const& graph_view,
49+
VertexPairIterator vertex_pair_first,
50+
VertexPairIterator vertex_pair_last,
51+
bool do_expensive_check = false)
52+
{
53+
static_assert(!GraphViewType::is_storage_transposed);
54+
55+
return detail::nbr_intersection(handle,
56+
graph_view,
57+
cugraph::edge_dummy_property_t{}.view(),
58+
vertex_pair_first,
59+
vertex_pair_last,
60+
std::array<bool, 2>{true, true},
61+
do_expensive_check);
62+
}
63+
64+
} // namespace cugraph

0 commit comments

Comments
 (0)