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

Enable edge masking in additional primitives #4126

Merged
merged 25 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0f7860e
update weight_sum_test to match other tests
seunghwak Jan 30, 2024
f22e31b
enalbe edge masking in compute_in|out_weight_sums
seunghwak Jan 30, 2024
d6848f5
test edge masking in mg_per_v_pair_transfomr_dst_nbr_weighted_interse…
seunghwak Jan 30, 2024
51efd36
bug fix
seunghwak Jan 31, 2024
3b814a3
add const to functions that can be const
seunghwak Feb 1, 2024
8f48eb9
update detail::extract_transform_v_frontier_e to support edge masking
seunghwak Feb 2, 2024
df6b4b6
replace uint32_t{0xffffffff} with raft::warp_full_mask()
seunghwak Feb 7, 2024
f1ad089
update/performance tune detail::extract_transform_v_froniter_e with e…
seunghwak Feb 7, 2024
3492ee9
mark fill_edge_src|dst_property.cuh as edge-masking ready
seunghwak Feb 7, 2024
3036bc7
add compute_number_of_edges_with_mask & compute_local_degree_with_mask
seunghwak Feb 7, 2024
fc3b380
add missing include
seunghwak Feb 7, 2024
217ef47
update extract_transform_v_frontier_outgoing_e to support edge masking
seunghwak Feb 7, 2024
6a44b55
update transform_reduce_v_frontier_outgoing_e_by_dst to support edge …
seunghwak Feb 7, 2024
60fd404
update extract_transform_e to support edge masking
seunghwak Feb 7, 2024
c5f556a
Merge branch 'branch-24.04' of https://github.com/rapidsai/cugraph in…
seunghwak Feb 7, 2024
d44c868
clang-format
seunghwak Feb 7, 2024
02de2b7
Merge branch 'branch-24.04' of https://github.com/rapidsai/cugraph in…
seunghwak Feb 8, 2024
f18fdf8
Merge branch 'branch-24.04' of https://github.com/rapidsai/cugraph in…
seunghwak Feb 9, 2024
1ddf922
resolve merge conflicts
seunghwak Feb 9, 2024
0b40837
copyright year
seunghwak Feb 9, 2024
b71f656
clang-format
seunghwak Feb 9, 2024
595ae92
fix compile error
seunghwak Feb 10, 2024
2cf155f
Merge branch 'branch-24.04' of https://github.com/rapidsai/cugraph in…
seunghwak Feb 12, 2024
c164b4c
Merge branch 'branch-24.04' of https://github.com/rapidsai/cugraph in…
seunghwak Feb 15, 2024
1089a60
Merge branch 'branch-24.04' of https://github.com/rapidsai/cugraph in…
seunghwak Feb 20, 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
230 changes: 230 additions & 0 deletions cpp/include/cugraph/edge_partition_device_view.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <cugraph/edge_partition_view.hpp>
#include <cugraph/utilities/error.hpp>
#include <cugraph/utilities/mask_utils.cuh>
#include <cugraph/utilities/misc_utils.cuh>

#include <raft/core/device_span.hpp>
Expand Down Expand Up @@ -92,6 +93,54 @@ struct local_degree_op_t {
}
};

template <typename vertex_t,
typename edge_t,
typename return_type_t,
bool multi_gpu,
bool use_dcs,
typename MaskIterator>
struct local_degree_with_mask_op_t {
raft::device_span<edge_t const> offsets{};
std::conditional_t<multi_gpu, vertex_t, std::byte /* dummy */> major_range_first{};

std::conditional_t<use_dcs, raft::device_span<vertex_t const>, std::byte /* dummy */>
dcs_nzd_vertices{};
std::conditional_t<use_dcs, vertex_t, std::byte /* dummy */> major_hypersparse_first{};

MaskIterator mask_first{};

__device__ return_type_t operator()(vertex_t major) const
{
if constexpr (multi_gpu) {
vertex_t idx{};
if constexpr (use_dcs) {
if (major < major_hypersparse_first) {
idx = major - major_range_first;
return static_cast<return_type_t>(
count_set_bits(mask_first, offsets[idx], offsets[idx + 1] - offsets[idx]));
} else {
auto major_hypersparse_idx =
major_hypersparse_idx_from_major_nocheck_impl(dcs_nzd_vertices, major);
if (major_hypersparse_idx) {
idx = (major_hypersparse_first - major_range_first) + *major_hypersparse_idx;
return static_cast<return_type_t>(
count_set_bits(mask_first, offsets[idx], offsets[idx + 1] - offsets[idx]));
} else {
return return_type_t{0};
}
}
} else {
idx = major - major_range_first;
return static_cast<return_type_t>(
count_set_bits(mask_first, offsets[idx], offsets[idx + 1] - offsets[idx]));
}
} else {
return static_cast<return_type_t>(
count_set_bits(mask_first, offsets[major], offsets[major + 1] - offsets[major]));
}
}
};

template <typename vertex_t, typename edge_t>
class edge_partition_device_view_base_t {
public:
Expand Down Expand Up @@ -255,6 +304,122 @@ class edge_partition_device_view_t<vertex_t, edge_t, multi_gpu, std::enable_if_t
return local_degrees;
}

template <typename MaskIterator, typename MajorIterator>
size_t compute_number_of_edges_with_mask(MaskIterator mask_first,
MajorIterator major_first,
MajorIterator major_last,
rmm::cuda_stream_view stream) const
{
return dcs_nzd_vertices_ ? thrust::transform_reduce(
rmm::exec_policy(stream),
major_first,
major_last,
detail::local_degree_with_mask_op_t<
vertex_t,
edge_t,
size_t /* no limit on majors.size(), so edge_t can overflow */,
multi_gpu,
true,
MaskIterator>{this->offsets_,
major_range_first_,
*dcs_nzd_vertices_,
*major_hypersparse_first_,
mask_first},
size_t{0},
thrust::plus<size_t>())
: thrust::transform_reduce(
rmm::exec_policy(stream),
major_first,
major_last,
detail::local_degree_with_mask_op_t<
vertex_t,
edge_t,
size_t /* no limit on majors.size(), so edge_t can overflow */,
multi_gpu,
false,
MaskIterator>{this->offsets_,
major_range_first_,
std::byte{0} /* dummy */,
std::byte{0} /* dummy */,
mask_first},
size_t{0},
thrust::plus<size_t>());
}

template <typename MaskIterator>
rmm::device_uvector<edge_t> compute_local_degrees_with_mask(MaskIterator mask_first,
rmm::cuda_stream_view stream) const
{
rmm::device_uvector<edge_t> local_degrees(this->major_range_size(), stream);
if (dcs_nzd_vertices_) {
assert(major_hypersparse_first_);
thrust::transform(
rmm::exec_policy(stream),
thrust::make_counting_iterator(this->major_range_first()),
thrust::make_counting_iterator(this->major_range_last()),
local_degrees.begin(),
detail::
local_degree_with_mask_op_t<vertex_t, edge_t, edge_t, multi_gpu, true, MaskIterator>{
this->offsets_,
major_range_first_,
*dcs_nzd_vertices_,
major_hypersparse_first_.value_or(vertex_t{0}),
mask_first});
} else {
thrust::transform(
rmm::exec_policy(stream),
thrust::make_counting_iterator(this->major_range_first()),
thrust::make_counting_iterator(this->major_range_last()),
local_degrees.begin(),
detail::
local_degree_with_mask_op_t<vertex_t, edge_t, edge_t, multi_gpu, false, MaskIterator>{
this->offsets_,
major_range_first_,
std::byte{0} /* dummy */,
std::byte{0} /* dummy */,
mask_first});
}
return local_degrees;
}

template <typename MaskIterator, typename MajorIterator>
rmm::device_uvector<edge_t> compute_local_degrees_with_mask(MaskIterator mask_first,
MajorIterator major_first,
MajorIterator major_last,
rmm::cuda_stream_view stream) const
{
rmm::device_uvector<edge_t> local_degrees(thrust::distance(major_first, major_last), stream);
if (dcs_nzd_vertices_) {
assert(major_hypersparse_first_);
thrust::transform(
rmm::exec_policy(stream),
major_first,
major_last,
local_degrees.begin(),
detail::
local_degree_with_mask_op_t<vertex_t, edge_t, edge_t, multi_gpu, true, MaskIterator>{
this->offsets_,
major_range_first_,
dcs_nzd_vertices_.value(),
major_hypersparse_first_.value_or(vertex_t{0}),
mask_first});
} else {
thrust::transform(
rmm::exec_policy(stream),
major_first,
major_last,
local_degrees.begin(),
detail::
local_degree_with_mask_op_t<vertex_t, edge_t, edge_t, multi_gpu, false, MaskIterator>{
this->offsets_,
major_range_first_,
std::byte{0} /* dummy */,
std::byte{0} /* dummy */,
mask_first});
}
return local_degrees;
}

__host__ __device__ vertex_t major_value_start_offset() const
{
return major_value_start_offset_;
Expand Down Expand Up @@ -440,6 +605,71 @@ class edge_partition_device_view_t<vertex_t, edge_t, multi_gpu, std::enable_if_t
return local_degrees;
}

template <typename MaskIterator, typename MajorIterator>
size_t compute_number_of_edges_with_mask(MaskIterator mask_first,
MajorIterator major_first,
MajorIterator major_last,
rmm::cuda_stream_view stream) const
{
return thrust::transform_reduce(
rmm::exec_policy(stream),
major_first,
major_last,
detail::local_degree_with_mask_op_t<
vertex_t,
edge_t,
size_t /* no limit on majors.size(), so edge_t can overflow */,
multi_gpu,
false,
MaskIterator>{this->offsets_,
std::byte{0} /* dummy */,
std::byte{0} /* dummy */,
std::byte{0} /* dummy */,
mask_first},
size_t{0},
thrust::plus<size_t>());
}

template <typename MaskIterator>
rmm::device_uvector<edge_t> compute_local_degrees_with_mask(MaskIterator mask_first,
rmm::cuda_stream_view stream) const
{
rmm::device_uvector<edge_t> local_degrees(this->major_range_size(), stream);
thrust::transform(
rmm::exec_policy(stream),
thrust::make_counting_iterator(this->major_range_first()),
thrust::make_counting_iterator(this->major_range_last()),
local_degrees.begin(),
detail::local_degree_with_mask_op_t<vertex_t, edge_t, edge_t, multi_gpu, false, MaskIterator>{
this->offsets_,
std::byte{0} /* dummy */,
std::byte{0} /* dummy */,
std::byte{0} /* dummy */,
mask_first});
return local_degrees;
}

template <typename MaskIterator, typename MajorIterator>
rmm::device_uvector<edge_t> compute_local_degrees_with_mask(MaskIterator mask_first,
MajorIterator major_first,
MajorIterator major_last,
rmm::cuda_stream_view stream) const
{
rmm::device_uvector<edge_t> local_degrees(thrust::distance(major_first, major_last), stream);
thrust::transform(
rmm::exec_policy(stream),
major_first,
major_last,
local_degrees.begin(),
detail::local_degree_with_mask_op_t<vertex_t, edge_t, edge_t, multi_gpu, false, MaskIterator>{
this->offsets_,
std::byte{0} /* dummy */,
std::byte{0} /* dummy */,
std::byte{0} /* dummy */,
mask_first});
return local_degrees;
}

__host__ __device__ vertex_t major_value_start_offset() const { return vertex_t{0}; }

__host__ __device__ thrust::optional<vertex_t> major_hypersparse_first() const noexcept
Expand Down
3 changes: 2 additions & 1 deletion cpp/include/cugraph/utilities/mask_utils.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, NVIDIA CORPORATION.
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,7 @@
#include <thrust/iterator/counting_iterator.h>
#include <thrust/iterator/transform_iterator.h>
#include <thrust/transform.h>
#include <thrust/transform_reduce.h>

namespace cugraph {

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/centrality/betweenness_centrality_impl.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023, NVIDIA CORPORATION.
* Copyright (c) 2022-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -69,7 +69,7 @@ struct extract_edge_e_op_t {
vertex_t dst,
thrust::tuple<vertex_t, edge_t, weight_t> src_props,
thrust::tuple<vertex_t, edge_t, weight_t> dst_props,
weight_t edge_centrality)
weight_t edge_centrality) const
{
return ((thrust::get<0>(dst_props) == d) && (thrust::get<0>(src_props) == (d - 1)))
? thrust::optional<thrust::tuple<vertex_t, vertex_t>>{thrust::make_tuple(src, dst)}
Expand Down
Loading
Loading