Skip to content

Commit

Permalink
remove test functions for removing self loops and multi-edges, use th…
Browse files Browse the repository at this point in the history
…e new library functions
  • Loading branch information
ChuckHastings committed Dec 1, 2023
1 parent afc00ee commit 54fb84e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 141 deletions.
20 changes: 18 additions & 2 deletions cpp/tests/utilities/test_graphs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,25 @@ construct_graph(raft::handle_t const& handle,

CUGRAPH_EXPECTS(d_src_v.size() <= static_cast<size_t>(std::numeric_limits<edge_t>::max()),
"Invalid template parameter: edge_t overflow.");
if (drop_self_loops) { remove_self_loops(handle, d_src_v, d_dst_v, d_weights_v); }
if (drop_self_loops) {
std::tie(d_src_v, d_dst_v, d_weights_v, std::ignore, std::ignore) =
cugraph::remove_self_loops<vertex_t, edge_t, weight_t, int32_t>(handle,
std::move(d_src_v),
std::move(d_dst_v),
std::move(d_weights_v),
std::nullopt,
std::nullopt);
}

if (drop_multi_edges) { sort_and_remove_multi_edges(handle, d_src_v, d_dst_v, d_weights_v); }
if (drop_multi_edges) {
std::tie(d_src_v, d_dst_v, d_weights_v, std::ignore, std::ignore) =
cugraph::remove_multi_edges<vertex_t, edge_t, weight_t, int32_t>(handle,
std::move(d_src_v),
std::move(d_dst_v),
std::move(d_weights_v),
std::nullopt,
std::nullopt);
}

graph_t<vertex_t, edge_t, store_transposed, multi_gpu> graph(handle);
std::optional<
Expand Down
126 changes: 0 additions & 126 deletions cpp/tests/utilities/thrust_wrapper.cu
Original file line number Diff line number Diff line change
Expand Up @@ -206,131 +206,5 @@ template void populate_vertex_ids(raft::handle_t const& handle,
rmm::device_uvector<int64_t>& d_vertices_v,
int64_t vertex_id_offset);

template <typename vertex_t, typename weight_t>
void remove_self_loops(raft::handle_t const& handle,
rmm::device_uvector<vertex_t>& d_src_v /* [INOUT] */,
rmm::device_uvector<vertex_t>& d_dst_v /* [INOUT] */,
std::optional<rmm::device_uvector<weight_t>>& d_weight_v /* [INOUT] */)
{
if (d_weight_v) {
auto edge_first = thrust::make_zip_iterator(
thrust::make_tuple(d_src_v.begin(), d_dst_v.begin(), (*d_weight_v).begin()));
d_src_v.resize(
thrust::distance(edge_first,
thrust::remove_if(
handle.get_thrust_policy(),
edge_first,
edge_first + d_src_v.size(),
[] __device__(auto e) { return thrust::get<0>(e) == thrust::get<1>(e); })),
handle.get_stream());
d_dst_v.resize(d_src_v.size(), handle.get_stream());
(*d_weight_v).resize(d_src_v.size(), handle.get_stream());
} else {
auto edge_first =
thrust::make_zip_iterator(thrust::make_tuple(d_src_v.begin(), d_dst_v.begin()));
d_src_v.resize(
thrust::distance(edge_first,
thrust::remove_if(
handle.get_thrust_policy(),
edge_first,
edge_first + d_src_v.size(),
[] __device__(auto e) { return thrust::get<0>(e) == thrust::get<1>(e); })),
handle.get_stream());
d_dst_v.resize(d_src_v.size(), handle.get_stream());
}

d_src_v.shrink_to_fit(handle.get_stream());
d_dst_v.shrink_to_fit(handle.get_stream());
if (d_weight_v) { (*d_weight_v).shrink_to_fit(handle.get_stream()); }
}

template void remove_self_loops(
raft::handle_t const& handle,
rmm::device_uvector<int32_t>& d_src_v /* [INOUT] */,
rmm::device_uvector<int32_t>& d_dst_v /* [INOUT] */,
std::optional<rmm::device_uvector<float>>& d_weight_v /* [INOUT] */);

template void remove_self_loops(
raft::handle_t const& handle,
rmm::device_uvector<int32_t>& d_src_v /* [INOUT] */,
rmm::device_uvector<int32_t>& d_dst_v /* [INOUT] */,
std::optional<rmm::device_uvector<double>>& d_weight_v /* [INOUT] */);

template void remove_self_loops(
raft::handle_t const& handle,
rmm::device_uvector<int64_t>& d_src_v /* [INOUT] */,
rmm::device_uvector<int64_t>& d_dst_v /* [INOUT] */,
std::optional<rmm::device_uvector<float>>& d_weight_v /* [INOUT] */);

template void remove_self_loops(
raft::handle_t const& handle,
rmm::device_uvector<int64_t>& d_src_v /* [INOUT] */,
rmm::device_uvector<int64_t>& d_dst_v /* [INOUT] */,
std::optional<rmm::device_uvector<double>>& d_weight_v /* [INOUT] */);

template <typename vertex_t, typename weight_t>
void sort_and_remove_multi_edges(
raft::handle_t const& handle,
rmm::device_uvector<vertex_t>& d_src_v /* [INOUT] */,
rmm::device_uvector<vertex_t>& d_dst_v /* [INOUT] */,
std::optional<rmm::device_uvector<weight_t>>& d_weight_v /* [INOUT] */)
{
if (d_weight_v) {
auto edge_first = thrust::make_zip_iterator(
thrust::make_tuple(d_src_v.begin(), d_dst_v.begin(), (*d_weight_v).begin()));
thrust::sort(handle.get_thrust_policy(), edge_first, edge_first + d_src_v.size());
d_src_v.resize(
thrust::distance(edge_first,
thrust::unique(handle.get_thrust_policy(),
edge_first,
edge_first + d_src_v.size(),
[] __device__(auto lhs, auto rhs) {
return (thrust::get<0>(lhs) == thrust::get<0>(rhs)) &&
(thrust::get<1>(lhs) == thrust::get<1>(rhs));
})),
handle.get_stream());
d_dst_v.resize(d_src_v.size(), handle.get_stream());
(*d_weight_v).resize(d_src_v.size(), handle.get_stream());
} else {
auto edge_first =
thrust::make_zip_iterator(thrust::make_tuple(d_src_v.begin(), d_dst_v.begin()));
thrust::sort(handle.get_thrust_policy(), edge_first, edge_first + d_src_v.size());
d_src_v.resize(
thrust::distance(
edge_first,
thrust::unique(handle.get_thrust_policy(), edge_first, edge_first + d_src_v.size())),
handle.get_stream());
d_dst_v.resize(d_src_v.size(), handle.get_stream());
}

d_src_v.shrink_to_fit(handle.get_stream());
d_dst_v.shrink_to_fit(handle.get_stream());
if (d_weight_v) { (*d_weight_v).shrink_to_fit(handle.get_stream()); }
}

template void sort_and_remove_multi_edges(
raft::handle_t const& handle,
rmm::device_uvector<int32_t>& d_src_v /* [INOUT] */,
rmm::device_uvector<int32_t>& d_dst_v /* [INOUT] */,
std::optional<rmm::device_uvector<float>>& d_weight_v /* [INOUT] */);

template void sort_and_remove_multi_edges(
raft::handle_t const& handle,
rmm::device_uvector<int32_t>& d_src_v /* [INOUT] */,
rmm::device_uvector<int32_t>& d_dst_v /* [INOUT] */,
std::optional<rmm::device_uvector<double>>& d_weight_v /* [INOUT] */);

template void sort_and_remove_multi_edges(
raft::handle_t const& handle,
rmm::device_uvector<int64_t>& d_src_v /* [INOUT] */,
rmm::device_uvector<int64_t>& d_dst_v /* [INOUT] */,
std::optional<rmm::device_uvector<float>>& d_weight_v /* [INOUT] */);

template void sort_and_remove_multi_edges(
raft::handle_t const& handle,
rmm::device_uvector<int64_t>& d_src_v /* [INOUT] */,
rmm::device_uvector<int64_t>& d_dst_v /* [INOUT] */,
std::optional<rmm::device_uvector<double>>& d_weight_v /* [INOUT] */);

} // namespace test
} // namespace cugraph
13 changes: 0 additions & 13 deletions cpp/tests/utilities/thrust_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,5 @@ void populate_vertex_ids(raft::handle_t const& handle,
rmm::device_uvector<vertex_t>& d_vertices_v /* [INOUT] */,
vertex_t vertex_id_offset);

template <typename vertex_t, typename weight_t>
void remove_self_loops(raft::handle_t const& handle,
rmm::device_uvector<vertex_t>& d_src_v /* [INOUT] */,
rmm::device_uvector<vertex_t>& d_dst_v /* [INOUT] */,
std::optional<rmm::device_uvector<weight_t>>& d_weight_v /* [INOUT] */);

template <typename vertex_t, typename weight_t>
void sort_and_remove_multi_edges(
raft::handle_t const& handle,
rmm::device_uvector<vertex_t>& d_src_v /* [INOUT] */,
rmm::device_uvector<vertex_t>& d_dst_v /* [INOUT] */,
std::optional<rmm::device_uvector<weight_t>>& d_weight_v /* [INOUT] */);

} // namespace test
} // namespace cugraph

0 comments on commit 54fb84e

Please sign in to comment.