Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ktruss implementation #4059

Merged
merged 169 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 91 commits
Commits
Show all changes
169 commits
Select commit Hold shift + click to select a range
fad7a83
define ktruss and add it to the cmake list
jnke2016 Dec 13, 2023
6afb913
ktruss implementation
jnke2016 Dec 13, 2023
b68381f
add tests
jnke2016 Dec 13, 2023
b5ac46e
Merge remote-tracking branch 'upstream/branch-24.02' into branch-23.1…
jnke2016 Dec 13, 2023
cc284e4
update ktruss implementation
jnke2016 Dec 28, 2023
1635f87
update implementation
jnke2016 Jan 8, 2024
fa61f9b
rename to k_truss
jnke2016 Jan 9, 2024
87f45be
remove unused variables
jnke2016 Jan 9, 2024
74d24be
remove unsued variables
jnke2016 Jan 9, 2024
0656dd9
Merge remote-tracking branch 'upstream/branch-24.02' into branch-24.0…
jnke2016 Jan 9, 2024
dfbc33a
add an empty line between two functions
seunghwak Jan 16, 2024
e6f6784
added major_idx_from_major_nocheck
seunghwak Jan 16, 2024
c9c3a2b
add initial implementation of has_edge() and compute_multiplicity
seunghwak Jan 17, 2024
e827457
Merge branch 'branch-24.02' of https://github.com/rapidsai/cugraph in…
seunghwak Jan 17, 2024
06d4f77
move count_invalid_vertex_pairs to error_check_utils.cuh
seunghwak Jan 17, 2024
4b4fb46
refactor has_edge() and compute_multiplicity()
seunghwak Jan 17, 2024
7f25cfc
Merge branch 'branch-24.02' of https://github.com/rapidsai/cugraph in…
seunghwak Jan 17, 2024
a7d0fff
clang-format and copyright year
seunghwak Jan 17, 2024
becf133
to_host, to_device specialization for std::vector<bool>
seunghwak Jan 17, 2024
5d3ed2a
remove repetitive tests
seunghwak Jan 17, 2024
e8d0ccc
fix compile error
seunghwak Jan 17, 2024
737f438
add bool specialization for device_gatherv and device_allgatherv
seunghwak Jan 17, 2024
00789bf
add tests for has_edge() and compute_multiplicity
seunghwak Jan 17, 2024
0b45356
copyright year
seunghwak Jan 17, 2024
49f46d0
Merge branch 'branch-24.02' of https://github.com/rapidsai/cugraph in…
seunghwak Jan 17, 2024
7cfe60a
bug fix
seunghwak Jan 18, 2024
c81655d
Merge branch 'branch-24.02' of https://github.com/rapidsai/cugraph in…
seunghwak Jan 18, 2024
43f8485
bug fix in tests
seunghwak Jan 19, 2024
8ff673a
test bug fix
seunghwak Jan 20, 2024
7b0d132
Merge branch 'branch-24.02' of https://github.com/rapidsai/cugraph in…
seunghwak Jan 20, 2024
99c973f
unroll 'p, q' edges
jnke2016 Jan 21, 2024
2f3a4db
Merge remote-tracking branch 'upstream/branch-24.02' into branch-24.0…
jnke2016 Jan 21, 2024
d805440
Merge remote-tracking branch 'upstream/fea_has_edges' into branch-24.…
jnke2016 Jan 21, 2024
66ec45f
unroll invalid edges
jnke2016 Jan 25, 2024
246ec16
update edge unrolling
jnke2016 Jan 25, 2024
0286934
update edge unrolling
jnke2016 Jan 26, 2024
98b09cf
update edge unrolling
jnke2016 Jan 29, 2024
e354565
fix style
jnke2016 Jan 29, 2024
531d8c9
Merge remote-tracking branch 'upstream/branch-24.02' into branch-24.0…
jnke2016 Jan 29, 2024
0ea3de0
fix copyright
jnke2016 Jan 29, 2024
61d238c
identify new set of edges to be deleted
jnke2016 Jan 29, 2024
edfabea
fix style
jnke2016 Jan 29, 2024
4dffcf5
cleanup code and remove memory preallocation
jnke2016 Feb 14, 2024
d2694b7
remove temporary buffers and cleanup code
jnke2016 Feb 20, 2024
1130354
cleanup code and remove tmp buffers
jnke2016 Feb 20, 2024
66a2310
update docstrings for consistency
jnke2016 Feb 21, 2024
f2dd1f3
update docstrings for consistency
jnke2016 Feb 21, 2024
209335f
cleanup code
jnke2016 Feb 21, 2024
17a7013
update stopping criteria
jnke2016 Feb 21, 2024
e61d1b8
fix typo
jnke2016 Feb 21, 2024
1a64e0e
fix typo
jnke2016 Feb 21, 2024
0355693
resize indices array
jnke2016 Feb 21, 2024
28275b3
fix logic error
jnke2016 Feb 21, 2024
c362f45
add a routine to update both the number of edges and invalid edges fo…
jnke2016 Feb 22, 2024
55876aa
remove unused functor
jnke2016 Feb 26, 2024
873199f
rename variable
jnke2016 Feb 26, 2024
b1bdf25
update variable type
jnke2016 Feb 26, 2024
12b1c35
consolidate function
jnke2016 Feb 26, 2024
ca20811
replace atomicAdd by atomic_ref
jnke2016 Feb 26, 2024
990a8e9
add separate function for edge triangle count
jnke2016 Feb 27, 2024
78562a2
update trust call to remove edges and remove tmp variable
jnke2016 Feb 28, 2024
4f8159c
implement method for edge triangle count
jnke2016 Feb 28, 2024
bc7f181
mask edges only prior to calling nbr_intersection
jnke2016 Feb 28, 2024
2cfd553
fix style
jnke2016 Feb 28, 2024
f0fce6f
update fixme and remove unused variables
jnke2016 Feb 28, 2024
979f715
update thrust call
jnke2016 Feb 28, 2024
d71e5b0
remove unused code
jnke2016 Feb 28, 2024
d605fef
return appropriate type for ktruss
jnke2016 Feb 28, 2024
ce2e9f9
call k_core instead of core_number
jnke2016 Feb 28, 2024
6217057
merge redundant function and rename variable
jnke2016 Feb 28, 2024
67e64ce
merge similar functions
jnke2016 Feb 29, 2024
56fc131
remove redundant call
jnke2016 Feb 29, 2024
caf3dde
remove unnecessary sorting
jnke2016 Mar 1, 2024
2077dc3
update triangle count type
jnke2016 Mar 1, 2024
1b4c580
reorder cases
jnke2016 Mar 1, 2024
05ed540
replace thrust 'tabulation' by 'copy' which is more explicit
jnke2016 Mar 1, 2024
e824eb3
fix style
jnke2016 Mar 1, 2024
5e95bb4
add fixme
jnke2016 Mar 1, 2024
9a97490
remove invalid edges at the end of each iterations
jnke2016 Mar 4, 2024
0851b3e
Merge remote-tracking branch 'upstream/branch-24.04' into branch-24.0…
jnke2016 Mar 4, 2024
4126d70
remove unnecessary copy of edges
jnke2016 Mar 11, 2024
e517abe
fix style
jnke2016 Mar 11, 2024
085f4ea
Merge remote-tracking branch 'upstream/branch-24.04' into branch-24.0…
jnke2016 Mar 11, 2024
8694f31
remove unnecessary atomic operation
jnke2016 Mar 12, 2024
ccf1b6d
sort before and after nbr_intersection
jnke2016 Mar 12, 2024
9cc76bd
update docstrings
jnke2016 Mar 12, 2024
585c052
remove unnecessary thrust call
jnke2016 Mar 12, 2024
8fb2b5b
remove unnecessary variables
jnke2016 Mar 12, 2024
4be2cf6
move edge_triangle_count to algorithms.hpp
jnke2016 Mar 12, 2024
3ad4c20
remove raw pointer
jnke2016 Mar 12, 2024
d6fd0bf
leverage the new implementation of ktruss in the capi
jnke2016 Mar 12, 2024
31c8902
update edge masking call
jnke2016 Mar 13, 2024
eab194a
remove unused code
jnke2016 Mar 13, 2024
d2d6999
remove edge triangle count from the stable API
jnke2016 Mar 13, 2024
5817b3f
support more type combination
jnke2016 Mar 13, 2024
8c347c1
remove outdated fixme
jnke2016 Mar 14, 2024
874897e
remove unused variables
jnke2016 Mar 14, 2024
42c8ed8
rename function unrolling p, q edges
jnke2016 Mar 14, 2024
94fa611
remove unnecessary sorting
jnke2016 Mar 14, 2024
f30b4ff
add weights support
jnke2016 Mar 15, 2024
7cda92e
remove unnecessary arguments
jnke2016 Mar 15, 2024
a3f83ef
rename variable
jnke2016 Mar 16, 2024
3e03ef3
reorder variable declaration
jnke2016 Mar 16, 2024
d23a3ad
add suupport for more type combination
jnke2016 Mar 16, 2024
3ce4e31
remove legacy k_truss call
jnke2016 Mar 16, 2024
264a7a2
update the C tests to account for the fact that the new implementatio…
jnke2016 Mar 16, 2024
a678340
remove legacy k_truss
jnke2016 Mar 16, 2024
3426fd8
fetch latest changes
jnke2016 Mar 16, 2024
dbf220e
remove unused code and invalid type combination
jnke2016 Mar 16, 2024
5768ed3
fix style
jnke2016 Mar 16, 2024
3187183
update copyright
jnke2016 Mar 16, 2024
9c2c19d
rename legacy k-truss tests
jnke2016 Mar 16, 2024
7c2f4c4
remove debug prints
jnke2016 Mar 16, 2024
ee1d8c2
fix style
jnke2016 Mar 16, 2024
813aa83
update test dataset path
jnke2016 Mar 16, 2024
71b89a5
fix style
jnke2016 Mar 16, 2024
bfca100
rename test
jnke2016 Mar 16, 2024
cdf328b
fix style
jnke2016 Mar 16, 2024
c966eba
symmetrize edgelist to be consistant with the python API
jnke2016 Mar 16, 2024
e926fae
temporarily update tests
jnke2016 Mar 16, 2024
0704eba
fix style
jnke2016 Mar 16, 2024
4954e24
remove unused variables and propertly move edge weights
jnke2016 Mar 17, 2024
49433a7
update C tests
jnke2016 Mar 18, 2024
7858b3e
fix style
jnke2016 Mar 18, 2024
302eaa2
add k_truss c++ tests
jnke2016 Mar 22, 2024
bd8ac94
properly handle weights
jnke2016 Mar 22, 2024
b470713
rename c++ tests
jnke2016 Mar 22, 2024
f7a43ec
update c tests
jnke2016 Mar 22, 2024
7b80a8d
undo changes
jnke2016 Mar 22, 2024
68b97bd
fix style
jnke2016 Mar 22, 2024
8287244
Merge remote-tracking branch 'upstream/branch-24.04' into branch-24.0…
jnke2016 Mar 22, 2024
701d87f
undo syntax change
jnke2016 Mar 22, 2024
22527be
update path to utility functions
jnke2016 Mar 22, 2024
2ea7ed2
add c++ rmat tests
jnke2016 Mar 22, 2024
9bab048
fix style
jnke2016 Mar 22, 2024
a9cdb98
reorder includes
jnke2016 Mar 24, 2024
8297ae6
pure c++ implementation of reference k_truss and leverage csr format
jnke2016 Mar 24, 2024
406a317
rename reeference test file
jnke2016 Mar 24, 2024
a0a2d63
fix style
jnke2016 Mar 24, 2024
288251b
remove unused import
jnke2016 Mar 24, 2024
20597f9
remove unused import
jnke2016 Mar 24, 2024
a87f07a
add fixme for chunking
jnke2016 Mar 24, 2024
ecbc2ce
reorder member variables
jnke2016 Mar 24, 2024
e6e2166
update docstrings
jnke2016 Mar 24, 2024
3593436
remove outdated code and rename function
jnke2016 Mar 24, 2024
fbc5681
update datasets paths
jnke2016 Mar 24, 2024
a4fed55
fix style
jnke2016 Mar 24, 2024
2100e30
remove asymmetric datasets
jnke2016 Mar 24, 2024
b66bd1a
rename variable
jnke2016 Mar 25, 2024
048b408
avoid illegal memory access
jnke2016 Mar 25, 2024
3e03255
rename function for general purpose
jnke2016 Mar 25, 2024
8f75316
remove fixme
jnke2016 Mar 25, 2024
24a6f76
combine similar thrust calls
jnke2016 Mar 25, 2024
f95fc13
fix style
jnke2016 Mar 25, 2024
3f6928d
reduce the number of memory accesses and kernel launch
jnke2016 Mar 26, 2024
56d5010
rename functor
jnke2016 Mar 26, 2024
21b7b84
update include paths
jnke2016 Mar 26, 2024
59546b7
update include path and rename variables
jnke2016 Mar 26, 2024
b3ba407
remove device functions from reference implementation
jnke2016 Mar 26, 2024
5dba8b3
drop cuHornet and support all archs
jnke2016 Mar 26, 2024
8dae624
fix style
jnke2016 Mar 26, 2024
b5f0d3a
fix warning
jnke2016 Mar 26, 2024
c9ada76
extend sorting utility function
jnke2016 Mar 26, 2024
ce8e594
perform 'coo' comparison instead of 'csr'
jnke2016 Mar 26, 2024
9b51e5b
fix style
jnke2016 Mar 26, 2024
65024ea
enable 'int64_t' support for K-Truss
jnke2016 Mar 26, 2024
1d8c5d9
update docstring
jnke2016 Mar 26, 2024
aa327f9
update copyright
jnke2016 Mar 26, 2024
4549f10
update docstring
jnke2016 Mar 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ set(CUGRAPH_SOURCES
src/community/detail/refine_mg.cu
src/community/detail/mis_sg.cu
src/community/detail/mis_mg.cu
src/community/edge_triangle_count_sg.cu
src/detail/utility_wrappers.cu
src/structure/graph_view_mg.cu
src/structure/remove_self_loops.cu
Expand Down Expand Up @@ -226,6 +227,7 @@ set(CUGRAPH_SOURCES
src/community/legacy/ecg.cu
src/community/egonet_sg.cu
src/community/egonet_mg.cu
src/community/k_truss_sg.cu
src/sampling/random_walks.cu
src/sampling/random_walks_sg.cu
src/sampling/detail/prepare_next_frontier_sg.cu
Expand Down
52 changes: 46 additions & 6 deletions cpp/include/cugraph/algorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1842,7 +1842,7 @@ void weakly_connected_components(raft::handle_t const& handle,
enum class k_core_degree_type_t { IN = 0, OUT = 1, INOUT = 2 };

/**
* @brief Compute core numbers of individual vertices from K-core decomposition.
* @brief Compute core numbers of individual vertices from K-Core decomposition.
*
* The input graph should not have self-loops nor multi-edges. Currently, only undirected graphs are
* supported.
Expand All @@ -1855,11 +1855,11 @@ enum class k_core_degree_type_t { IN = 0, OUT = 1, INOUT = 2 };
* handles to various CUDA libraries) to run graph algorithms.
* @param graph_view Graph view object.
* @param core_numbers Pointer to the output core number array.
* @param degree_type Dictate whether to compute the K-core decomposition based on in-degrees,
* @param degree_type Dictate whether to compute the K-Core decomposition based on in-degrees,
* out-degrees, or in-degrees + out_degrees.
* @param k_first Find K-cores from K = k_first. Any vertices that do not belong to k_first-core
* @param k_first Find K-Cores from K = k_first. Any vertices that do not belong to k_first-core
* will have core numbers of 0.
* @param k_last Find K-cores to K = k_last. Any vertices that belong to (k_last)-core will have
* @param k_last Find K-Cores to K = k_last. Any vertices that belong to (k_last)-core will have
* their core numbers set to their degrees on k_last-core.
* @param do_expensive_check A flag to run expensive checks for input arguments (if set to `true`).
*/
Expand All @@ -1873,7 +1873,7 @@ void core_number(raft::handle_t const& handle,
bool do_expensive_check = false);

/**
* @brief Extract K Core of a graph
* @brief Extract K-Core of a graph
*
* @throws cugraph::logic_error when an error occurs.
*
Expand All @@ -1884,7 +1884,7 @@ void core_number(raft::handle_t const& handle,
* @param graph_view Graph view object.
* @param edge_weight_view Optional view object holding edge weights for @p graph_view.
* @param k Order of the core. This value must not be negative.
* @param degree_type Optional parameter to dictate whether to compute the K-core decomposition
* @param degree_type Optional parameter to dictate whether to compute the K-Core decomposition
* based on in-degrees, out-degrees, or in-degrees + out_degrees. One of @p
* degree_type and @p core_numbers must be specified.
* @param core_numbers Optional output from core_number algorithm. If not specified then
Expand Down Expand Up @@ -2040,6 +2040,46 @@ void triangle_count(raft::handle_t const& handle,
raft::device_span<edge_t> counts,
bool do_expensive_check = false);

/**
* @brief Count the number of triangles for each edge.
* @tparam vertex_t Type of vertex identifiers. Needs to be an integral type.
* @tparam edge_t Type of edge identifiers. Needs to be an integral type.
*
* @param handle RAFT handle object to encapsulate resources (e.g. CUDA stream, communicator, and
* handles to various CUDA libraries) to run graph algorithms.
* @param edgelist_srcs List of source vertex ids
* @param edgelist_dsts List of destination vertex ids
* @return triangle count of the edge list
*/
template <typename vertex_t, typename edge_t, bool store_transposed, bool multi_gpu>
rmm::device_uvector<edge_t> edge_triangle_count(
raft::handle_t const& handle,
graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu> const& graph_view,
raft::device_span<vertex_t> edgelist_srcs,
raft::device_span<vertex_t> edgelist_dsts);

/*
* @brief Compute K-Truss.
*
* Extract the K-Truss subgraph of a graph
*
* @tparam vertex_t Type of vertex identifiers. Needs to be an integral type.
* @tparam edge_t Type of edge identifiers. Needs to be an integral type.
* @tparam multi_gpu Flag indicating whether template instantiation should target single-GPU (false)
* @param handle RAFT handle object to encapsulate resources (e.g. CUDA stream, communicator, and
* handles to various CUDA libraries) to run graph algorithms.
* @param graph_view Graph view object.
* @param k The desired k to be used for extracting the K-Truss subgraph
* @param do_expensive_check A flag to run expensive checks for input arguments (if set to `true`).
* @return edge list of the K-Truss subgraph
*/
seunghwak marked this conversation as resolved.
Show resolved Hide resolved
template <typename vertex_t, typename edge_t, bool multi_gpu>
std::tuple<rmm::device_uvector<vertex_t>, rmm::device_uvector<vertex_t>> k_truss(
raft::handle_t const& handle,
graph_view_t<vertex_t, edge_t, false, multi_gpu> const& graph_view,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better match k_core, we should take std::optional<edge_property_view_t<edge_t, weight_t const*>> edge_weight_view and optionally return weights as well.

If this takes time to implement, you can add CUGRAPH_EXPECTS(edge_weights.has_value() == false, "unimplemented."); and address this in a follow-up PR.

edge_t k,
bool do_expensive_check = false);

/**
* @brief Compute Jaccard similarity coefficient
*
Expand Down
21 changes: 5 additions & 16 deletions cpp/src/c_api/legacy_k_truss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,13 @@ struct k_truss_functor : public cugraph::c_api::abstract_functor {
auto number_map = reinterpret_cast<rmm::device_uvector<vertex_t>*>(graph_->number_map_);

auto graph_view = graph->view();
rmm::device_uvector<vertex_t> src(0, handle_.get_stream());
rmm::device_uvector<vertex_t> dst(0, handle_.get_stream());
std::optional<rmm::device_uvector<weight_t>> wgt{std::nullopt};

std::tie(src, dst, wgt, std::ignore) = cugraph::decompress_to_edgelist(
auto [result_src, result_dst] = cugraph::k_truss<vertex_t, edge_t, multi_gpu>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are replacing the call to legacy ktruss with the call to primitive-based ktruss. That's great in that it saves python work (although we should still plan MG python work for 24.06). There's already issues for that work, we can update those issues.

However, if we do that, we should rename this file to k_truss.cpp since it will no longer be the legacy implementation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we should start addressing all the issues we should address before merging this PR.

handle_,
graph_view,
edge_weights ? std::make_optional(edge_weights->view()) : std::nullopt,
std::optional<cugraph::edge_property_view_t<edge_t, edge_t const*>>{std::nullopt},
std::optional<raft::device_span<vertex_t const>>(std::nullopt),
k_,
do_expensive_check_);

auto [result_src, result_dst, result_wgt] = cugraph::k_truss_subgraph(
handle_,
raft::device_span<vertex_t>(src.data(), src.size()),
raft::device_span<vertex_t>(dst.data(), dst.size()),
wgt ? std::make_optional(raft::device_span<weight_t>(wgt->data(), wgt->size()))
: std::nullopt,
graph_view.number_of_vertices(),
k_);

cugraph::unrenumber_int_vertices<vertex_t, multi_gpu>(
handle_,
result_src.data(),
Expand All @@ -127,9 +113,12 @@ struct k_truss_functor : public cugraph::c_api::abstract_functor {
result_ = new cugraph::c_api::cugraph_induced_subgraph_result_t{
new cugraph::c_api::cugraph_type_erased_device_array_t(result_src, graph_->vertex_type_),
new cugraph::c_api::cugraph_type_erased_device_array_t(result_dst, graph_->vertex_type_),
/*
wgt ? new cugraph::c_api::cugraph_type_erased_device_array_t(*result_wgt,
graph_->weight_type_)
: NULL,
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete dead code.

NULL,
NULL,
NULL,
new cugraph::c_api::cugraph_type_erased_device_array_t(edge_offsets,
Expand Down
169 changes: 169 additions & 0 deletions cpp/src/community/edge_triangle_count_impl.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
* Copyright (c) 2020-2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <cugraph/detail/decompress_edge_partition.cuh>
#include <cugraph/graph_functions.hpp>
#include <cugraph/graph_view.hpp>
#include <cugraph/partition_manager.hpp>
#include <cugraph/utilities/error.hpp>
#include <cugraph/utilities/mask_utils.cuh>

#include <raft/core/handle.hpp>
#include <raft/util/cudart_utils.hpp>

#include <rmm/device_uvector.hpp>

#include <thrust/adjacent_difference.h>
#include <thrust/binary_search.h>
#include <thrust/functional.h>
#include <thrust/iterator/zip_iterator.h>
#include <thrust/sort.h>
#include <thrust/tuple.h>

#include <detail/graph_partition_utils.cuh>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check pre-commit (as mentioned above). I believe these should now be in "" and before the other headers.

#include <prims/transform_reduce_dst_nbr_intersection_of_e_endpoints_by_v.cuh>
jnke2016 marked this conversation as resolved.
Show resolved Hide resolved

#include <optional>
#include <tuple>
#include <type_traits>
#include <vector>

namespace cugraph {

namespace detail {

template <typename vertex_t, typename edge_t, typename EdgeIterator>
struct update_edges_p_r_q_r_num_triangles {
size_t num_edges{}; // rename to num_edges
const edge_t edge_first_or_second{};
raft::device_span<size_t const> intersection_offsets{};
raft::device_span<vertex_t const> intersection_indices{};
raft::device_span<edge_t> num_triangles{};

EdgeIterator edge_first{};

__device__ void operator()(size_t i) const
{
auto itr = thrust::upper_bound(
thrust::seq, intersection_offsets.begin() + 1, intersection_offsets.end(), i);
auto idx = thrust::distance(intersection_offsets.begin() + 1, itr);
if (edge_first_or_second == 0) {
auto p_r_pair =
thrust::make_tuple(thrust::get<0>(*(edge_first + idx)), intersection_indices[i]);

// Find its position in 'edges'
auto itr_p_r_p_q =
thrust::lower_bound(thrust::seq,
edge_first,
edge_first + num_edges, // pass the number of vertex pairs
p_r_pair);

assert(*itr_p_r_p_q == p_r_pair);
idx = thrust::distance(edge_first, itr_p_r_p_q);
} else {
auto p_r_pair =
thrust::make_tuple(thrust::get<1>(*(edge_first + idx)), intersection_indices[i]);

// Find its position in 'edges'
auto itr_p_r_p_q =
thrust::lower_bound(thrust::seq,
edge_first,
edge_first + num_edges, // pass the number of vertex pairs
p_r_pair);
assert(*itr_p_r_p_q == p_r_pair);
idx = thrust::distance(edge_first, itr_p_r_p_q);
}
cuda::atomic_ref<edge_t, cuda::thread_scope_device> atomic_counter(num_triangles[idx]);
auto r = atomic_counter.fetch_add(edge_t{1}, cuda::std::memory_order_relaxed);
}
};

template <typename vertex_t, typename edge_t, bool store_transposed, bool multi_gpu>
std::enable_if_t<!multi_gpu, rmm::device_uvector<edge_t>> edge_triangle_count_impl(
raft::handle_t const& handle,
graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu> const& graph_view,
raft::device_span<vertex_t> edgelist_srcs,
raft::device_span<vertex_t> edgelist_dsts)
{
jnke2016 marked this conversation as resolved.
Show resolved Hide resolved
auto edge_first = thrust::make_zip_iterator(edgelist_srcs.begin(), edgelist_dsts.begin());

thrust::sort(handle.get_thrust_policy(), edge_first, edge_first + edgelist_srcs.size());

auto [intersection_offsets, intersection_indices] =
detail::nbr_intersection(handle,
graph_view,
cugraph::edge_dummy_property_t{}.view(),
edge_first,
edge_first + edgelist_srcs.size(),
std::array<bool, 2>{true, true},
false /*FIXME: pass 'do_expensive_check' as argument*/);

// FIXME: invalid type for unsigned integers.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this FIXME still relevant?

rmm::device_uvector<edge_t> num_triangles(edgelist_srcs.size(), handle.get_stream());

// Update the number of triangles of each (p, q) edges by looking at their intersection
// size
thrust::adjacent_difference(handle.get_thrust_policy(),
intersection_offsets.begin() + 1,
intersection_offsets.end(),
num_triangles.begin());

// Given intersection offsets and indices that are used to update the number of
// triangles of (p, q) edges where `r`s are the intersection indices, update
// the number of triangles of the pairs (p, r) and (q, r).

thrust::for_each(
handle.get_thrust_policy(),
thrust::make_counting_iterator<edge_t>(0),
thrust::make_counting_iterator<edge_t>(intersection_indices.size()),
update_edges_p_r_q_r_num_triangles<vertex_t, edge_t, decltype(edge_first)>{
edgelist_srcs.size(),
0,
raft::device_span<size_t const>(intersection_offsets.data(), intersection_offsets.size()),
raft::device_span<vertex_t const>(intersection_indices.data(), intersection_indices.size()),
raft::device_span<edge_t>(num_triangles.data(), num_triangles.size()),
edge_first});

thrust::for_each(
handle.get_thrust_policy(),
thrust::make_counting_iterator<edge_t>(0),
thrust::make_counting_iterator<edge_t>(intersection_indices.size()),
update_edges_p_r_q_r_num_triangles<vertex_t, edge_t, decltype(edge_first)>{
edgelist_srcs.size(),
1,
raft::device_span<size_t const>(intersection_offsets.data(), intersection_offsets.size()),
raft::device_span<vertex_t const>(intersection_indices.data(), intersection_indices.size()),
raft::device_span<edge_t>(num_triangles.data(), num_triangles.size()),
edge_first});

return num_triangles;
}

} // namespace detail

template <typename vertex_t, typename edge_t, bool store_transposed, bool multi_gpu>
rmm::device_uvector<edge_t> edge_triangle_count(
raft::handle_t const& handle,
graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu> const& graph_view,
raft::device_span<vertex_t> edgelist_srcs,
raft::device_span<vertex_t> edgelist_dsts)
{
return detail::edge_triangle_count_impl(handle, graph_view, edgelist_srcs, edgelist_dsts);
}

} // namespace cugraph
59 changes: 59 additions & 0 deletions cpp/src/community/edge_triangle_count_sg.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2021-2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <community/edge_triangle_count_impl.cuh>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be in "".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to address this.


namespace cugraph {

// SG instantiation
template rmm::device_uvector<int32_t> edge_triangle_count(
raft::handle_t const& handle,
cugraph::graph_view_t<int32_t, int32_t, false, false> const& graph_view,
raft::device_span<int32_t> edgelist_srcs,
raft::device_span<int32_t> edgelist_dsts);

template rmm::device_uvector<int64_t> edge_triangle_count(
raft::handle_t const& handle,
cugraph::graph_view_t<int32_t, int64_t, false, false> const& graph_view,
raft::device_span<int32_t> edgelist_srcs,
raft::device_span<int32_t> edgelist_dsts);

template rmm::device_uvector<int64_t> edge_triangle_count(
raft::handle_t const& handle,
cugraph::graph_view_t<int64_t, int64_t, false, false> const& graph_view,
raft::device_span<int64_t> edgelist_srcs,
raft::device_span<int64_t> edgelist_dsts);

template rmm::device_uvector<int32_t> edge_triangle_count(
raft::handle_t const& handle,
cugraph::graph_view_t<int64_t, int32_t, false, false> const& graph_view,
raft::device_span<int64_t> edgelist_srcs,
raft::device_span<int64_t> edgelist_dsts);
jnke2016 marked this conversation as resolved.
Show resolved Hide resolved

/*
template rmm::device_uvector<int64_t> edge_triangle_count(
raft::handle_t const& handle,
cugraph::graph_view_t<int64_t, int64_t, false, false> const& graph_view,
raft::device_span<int64_t> edgelist_srcs,
raft::device_span<int64_t> edgelist_dsts);

template rmm::device_uvector<int64_t> edge_triangle_count(
raft::handle_t const& handle,
cugraph::graph_view_t<int32_t, int64_t, false, false> const& graph_view,
raft::device_span<int64_t> edgelist_srcs,
raft::device_span<int64_t> edgelist_dsts);
*/
jnke2016 marked this conversation as resolved.
Show resolved Hide resolved

} // namespace cugraph
Loading
Loading