diff --git a/cpp/include/cugraph/graph_functions.hpp b/cpp/include/cugraph/graph_functions.hpp index 03ba83c62e0..61bf30e86a2 100644 --- a/cpp/include/cugraph/graph_functions.hpp +++ b/cpp/include/cugraph/graph_functions.hpp @@ -347,8 +347,7 @@ extract_induced_subgraphs( * @param handle RAFT handle object to encapsulate resources (e.g. CUDA stream, communicator, and * handles to various CUDA libraries) to run graph algorithms. * @param vertex_span If valid, part of the entire set of vertices in the graph to be renumbered. - * The first tuple element is the pointer to the array and the second tuple element is the size of - * the array. This parameter can be used to include isolated vertices. If multi-GPU, applying the + * This parameter can be used to include isolated vertices. If multi-GPU, applying the * compute_gpu_id_from_vertex_t to every vertex should return the local GPU ID for this function to * work (vertices should be pre-shuffled). * @param edgelist_rows Vector of edge row (source) vertex IDs. @@ -369,7 +368,7 @@ template , std::optional>> create_graph_from_edgelist(raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, diff --git a/cpp/src/structure/create_graph_from_edgelist.cpp b/cpp/src/structure/create_graph_from_edgelist.cpp index a8a51c5cb83..151ba4e307b 100644 --- a/cpp/src/structure/create_graph_from_edgelist.cpp +++ b/cpp/src/structure/create_graph_from_edgelist.cpp @@ -40,14 +40,13 @@ std::enable_if_t< multi_gpu, std::tuple, std::optional>>> -create_graph_from_edgelist_impl( - raft::handle_t const& handle, - std::optional> local_vertex_span, - rmm::device_uvector&& edgelist_rows, - rmm::device_uvector&& edgelist_cols, - std::optional>&& edgelist_weights, - graph_properties_t graph_properties, - bool renumber) +create_graph_from_edgelist_impl(raft::handle_t const& handle, + std::optional>&& local_vertex_span, + rmm::device_uvector&& edgelist_rows, + rmm::device_uvector&& edgelist_cols, + std::optional>&& edgelist_weights, + graph_properties_t graph_properties, + bool renumber) { CUGRAPH_EXPECTS(renumber, "renumber should be true if multi_gpu is true."); @@ -114,7 +113,8 @@ create_graph_from_edgelist_impl( *vertex_partition_segment_offsets) = cugraph::renumber_edgelist( handle, - local_vertex_span, + std::optional>{std::make_tuple( + (*local_vertex_span).data(), static_cast((*local_vertex_span).size()))}, major_ptrs, minor_ptrs, edgelist_edge_counts, @@ -156,7 +156,7 @@ std::enable_if_t< std::tuple, std::optional>>> create_graph_from_edgelist_impl(raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -172,7 +172,8 @@ create_graph_from_edgelist_impl(raft::handle_t const& handle, std::tie(*renumber_map_labels, *segment_offsets) = cugraph::renumber_edgelist( handle, - vertex_span, + std::optional>{ + std::make_tuple((*vertex_span).data(), static_cast((*vertex_span).size()))}, store_transposed ? edgelist_cols.data() : edgelist_rows.data(), store_transposed ? edgelist_rows.data() : edgelist_cols.data(), static_cast(edgelist_rows.size())); @@ -183,7 +184,7 @@ create_graph_from_edgelist_impl(raft::handle_t const& handle, num_vertices = static_cast((*renumber_map_labels).size()); } else { if (vertex_span) { - num_vertices = std::get<1>(*vertex_span); + num_vertices = static_cast((*vertex_span).size()); } else { num_vertices = 1 + cugraph::detail::compute_maximum_vertex_id( handle.get_stream_view(), edgelist_rows, edgelist_cols); @@ -215,7 +216,7 @@ template , std::optional>> create_graph_from_edgelist(raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -224,7 +225,7 @@ create_graph_from_edgelist(raft::handle_t const& handle, { return create_graph_from_edgelist_impl( handle, - vertex_span, + std::move(vertex_span), std::move(edgelist_rows), std::move(edgelist_cols), std::move(edgelist_weights), @@ -238,7 +239,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -249,7 +250,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -260,7 +261,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -271,7 +272,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -282,7 +283,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -293,7 +294,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -304,7 +305,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -315,7 +316,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -326,7 +327,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -337,7 +338,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -348,7 +349,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -359,7 +360,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -370,7 +371,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -381,7 +382,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -392,7 +393,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -403,7 +404,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -414,7 +415,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -425,7 +426,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -436,7 +437,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -447,7 +448,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -458,7 +459,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -469,7 +470,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -480,7 +481,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, @@ -491,7 +492,7 @@ template std::tuple, std::optional>> create_graph_from_edgelist( raft::handle_t const& handle, - std::optional> vertex_span, + std::optional>&& vertex_span, rmm::device_uvector&& edgelist_rows, rmm::device_uvector&& edgelist_cols, std::optional>&& edgelist_weights, diff --git a/cpp/src/structure/renumber_edgelist.cu b/cpp/src/structure/renumber_edgelist.cu index c6b28e0134c..9e593e3f169 100644 --- a/cpp/src/structure/renumber_edgelist.cu +++ b/cpp/src/structure/renumber_edgelist.cu @@ -276,10 +276,13 @@ std::tuple, std::vector> compute_renumbe labels.shrink_to_fit(handle.get_stream()); counts.shrink_to_fit(handle.get_stream()); - // 4. if vertices != nullptr, add isolated vertices + auto num_non_isolated_vertices = static_cast(labels.size()); + + // 4. if vertex_span.has_value() == true, append isolated vertices - rmm::device_uvector isolated_vertices(0, handle.get_stream()); if (vertex_span) { + rmm::device_uvector isolated_vertices(0, handle.get_stream()); + auto [vertices, num_vertices] = *vertex_span; auto num_isolated_vertices = thrust::count_if( rmm::exec_policy(handle.get_stream_view()), @@ -296,30 +299,25 @@ std::tuple, std::vector> compute_renumbe [label_first = labels.begin(), label_last = labels.end()] __device__(auto v) { return !thrust::binary_search(thrust::seq, label_first, label_last, v); }); - } - if (isolated_vertices.size() > 0) { - labels.resize(labels.size() + isolated_vertices.size(), handle.get_stream()); - counts.resize(labels.size(), handle.get_stream()); - thrust::copy(rmm::exec_policy(handle.get_stream_view()), - isolated_vertices.begin(), - isolated_vertices.end(), - labels.end() - isolated_vertices.size()); - thrust::fill(rmm::exec_policy(handle.get_stream_view()), - counts.end() - isolated_vertices.size(), - counts.end(), - edge_t{0}); + if (isolated_vertices.size() > 0) { + labels.resize(labels.size() + isolated_vertices.size(), handle.get_stream()); + thrust::copy(rmm::exec_policy(handle.get_stream_view()), + isolated_vertices.begin(), + isolated_vertices.end(), + labels.end() - isolated_vertices.size()); + } } - // 6. sort by degree + // 5. sort non-isolated vertices by degree thrust::sort_by_key(rmm::exec_policy(handle.get_stream_view()), counts.begin(), - counts.end(), + counts.begin() + num_non_isolated_vertices, labels.begin(), thrust::greater()); - // 7. compute segment_offsets + // 6. compute segment_offsets static_assert(detail::num_sparse_segments_per_vertex_partition == 3); static_assert((detail::low_degree_threshold <= detail::mid_degree_threshold) && @@ -353,7 +351,7 @@ std::tuple, std::vector> compute_renumbe handle.get_stream()); auto zero_vertex = vertex_t{0}; - auto vertex_count = static_cast(counts.size()); + auto vertex_count = static_cast(labels.size()); d_segment_offsets.set_element_async(0, zero_vertex, handle.get_stream()); d_segment_offsets.set_element_async( num_segments_per_vertex_partition, vertex_count, handle.get_stream()); @@ -668,6 +666,7 @@ renumber_edgelist( edgelist_const_major_vertices, edgelist_const_minor_vertices, edgelist_edge_counts); + // 2. initialize partition_t object, number_of_vertices, and number_of_edges for the coarsened // graph diff --git a/cpp/tests/community/mg_louvain_test.cpp b/cpp/tests/community/mg_louvain_test.cpp index 227bd8eff1e..4ceacba2acd 100644 --- a/cpp/tests/community/mg_louvain_test.cpp +++ b/cpp/tests/community/mg_louvain_test.cpp @@ -129,8 +129,7 @@ class Louvain_MG_Testfixture : public ::testing::TestWithParam std::tie(*sg_graph, std::ignore) = cugraph::create_graph_from_edgelist( handle, - std::optional>{ - std::make_tuple(d_vertices.data(), static_cast(d_vertices.size()))}, + std::move(d_vertices), std::move(d_edgelist_rows), std::move(d_edgelist_cols), std::move(d_edgelist_weights), diff --git a/cpp/tests/components/wcc_graphs.cu b/cpp/tests/components/wcc_graphs.cu index db848a22aa0..8254eaa1b1a 100644 --- a/cpp/tests/components/wcc_graphs.cu +++ b/cpp/tests/components/wcc_graphs.cu @@ -71,8 +71,7 @@ LineGraph_Usecase::construct_graph(raft::handle_t const& handle, return cugraph:: create_graph_from_edgelist( handle, - std::optional>{ - std::make_tuple(vertices_v.data(), static_cast(vertices_v.size()))}, + std::move(vertices_v), std::move(src_v), std::move(dst_v), std::nullopt, diff --git a/cpp/tests/utilities/matrix_market_file_utilities.cu b/cpp/tests/utilities/matrix_market_file_utilities.cu index 20006b339ea..42f047db811 100644 --- a/cpp/tests/utilities/matrix_market_file_utilities.cu +++ b/cpp/tests/utilities/matrix_market_file_utilities.cu @@ -408,8 +408,7 @@ read_graph_from_matrix_market_file(raft::handle_t const& handle, return cugraph:: create_graph_from_edgelist( handle, - std::optional>{ - std::make_tuple(d_vertices.data(), static_cast(d_vertices.size()))}, + std::move(d_vertices), std::move(d_edgelist_rows), std::move(d_edgelist_cols), std::move(d_edgelist_weights), diff --git a/cpp/tests/utilities/rmat_utilities.cpp b/cpp/tests/utilities/rmat_utilities.cpp index 7702b4285b5..370f16b9c61 100644 --- a/cpp/tests/utilities/rmat_utilities.cpp +++ b/cpp/tests/utilities/rmat_utilities.cpp @@ -184,8 +184,7 @@ generate_graph_from_rmat_params(raft::handle_t const& handle, return cugraph:: create_graph_from_edgelist( handle, - std::optional>{ - std::make_tuple(d_vertices.data(), static_cast(d_vertices.size()))}, + std::move(d_vertices), std::move(d_edgelist_rows), std::move(d_edgelist_cols), std::move(d_edgelist_weights),