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

Address Leiden numbering issue #4845

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
46 changes: 26 additions & 20 deletions cpp/src/community/leiden_impl.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2024, NVIDIA CORPORATION.
* Copyright (c) 2022-2025, 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 @@ -604,26 +604,21 @@ void relabel_cluster_ids(raft::handle_t const& handle,
size_t num_nodes)
{
vertex_t local_cluster_id_first{0};

// Get unique cluster id and shuffle
remove_duplicates<vertex_t, multi_gpu>(handle, unique_cluster_ids);

if constexpr (multi_gpu) {
auto unique_cluster_range_lasts = cugraph::partition_manager::compute_partition_range_lasts(
handle, static_cast<vertex_t>(unique_cluster_ids.size()));

auto& comm = handle.get_comms();
auto const comm_size = comm.get_size();
auto const comm_rank = comm.get_rank();
auto& major_comm = handle.get_subcomm(cugraph::partition_manager::major_comm_name());
auto const major_comm_size = major_comm.get_size();
auto const major_comm_rank = major_comm.get_rank();
auto& minor_comm = handle.get_subcomm(cugraph::partition_manager::minor_comm_name());
auto const minor_comm_size = minor_comm.get_size();
auto const minor_comm_rank = minor_comm.get_rank();

auto vertex_partition_id =
partition_manager::compute_vertex_partition_id_from_graph_subcomm_ranks(
major_comm_size, minor_comm_size, major_comm_rank, minor_comm_rank);

local_cluster_id_first =
vertex_partition_id == 0 ? vertex_t{0} : unique_cluster_range_lasts[vertex_partition_id - 1];
auto cluster_ids_size_per_rank = cugraph::host_scalar_allgather(
handle.get_comms(), unique_cluster_ids.size(), handle.get_stream());

std::vector<vertex_t> cluster_ids_starts(cluster_ids_size_per_rank.size());
std::exclusive_scan(cluster_ids_size_per_rank.begin(),
cluster_ids_size_per_rank.end(),
cluster_ids_starts.begin(),
size_t{0});
auto& comm = handle.get_comms();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks good, functionally.

If you're going to pull out &comm from the handle, I'd do that at line 612 (right as you enter the if block and use comm also in the call to host_scalar_allgather. Otherwise I would just use handle.get_comms().get_rank() as the index in the next line.

But that's purely cosmetic.

local_cluster_id_first = cluster_ids_starts[comm.get_rank()];
}

rmm::device_uvector<vertex_t> numbering_indices(unique_cluster_ids.size(), handle.get_stream());
Expand Down Expand Up @@ -713,6 +708,17 @@ std::pair<size_t, weight_t> leiden(

detail::flatten_leiden_dendrogram(handle, graph_view, *dendrogram, clustering);

size_t local_num_verts = (*dendrogram).get_level_size_nocheck(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

dendrogram->get_level_size_nocheck(0);

rmm::device_uvector<vertex_t> unique_cluster_ids(local_num_verts, handle.get_stream());

thrust::copy(handle.get_thrust_policy(),
clustering,
clustering + local_num_verts,
unique_cluster_ids.begin());

detail::relabel_cluster_ids<vertex_t, multi_gpu>(
handle, unique_cluster_ids, clustering, local_num_verts);

return std::make_pair(dendrogram->num_levels(), modularity);
}

Expand Down
4 changes: 2 additions & 2 deletions python/cugraph/cugraph/dask/community/leiden.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ def leiden(
input_graph._plc_graph[w],
max_iter,
resolution,
random_state,
random_state + i,
theta,
do_expensive_check,
workers=[w],
allow_other_workers=False,
)
for w in Comms.get_workers()
for i, w in enumerate(Comms.get_workers())
]

wait(result)
Expand Down
Loading