Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion python/pylibcugraph/pylibcugraph/CMakeLists.txt
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. You may obtain a copy of the License at
Expand Down Expand Up @@ -71,6 +71,7 @@ set(cython_sources
homogeneous_uniform_neighbor_sample.pyx
edge_id_lookup_table.pyx
decompress_to_edgelist.pyx
renumber_arbitrary_edgelist.pyx
)
set(linked_libraries cugraph::cugraph;cugraph::cugraph_c)

Expand Down
2 changes: 2 additions & 0 deletions python/pylibcugraph/pylibcugraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@

from pylibcugraph.decompress_to_edgelist import decompress_to_edgelist

from pylibcugraph.renumber_arbitrary_edgelist import renumber_arbitrary_edgelist


from pylibcugraph import exceptions

Expand Down
13 changes: 11 additions & 2 deletions python/pylibcugraph/pylibcugraph/_cugraph_c/graph_functions.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 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.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -34,7 +34,8 @@ from pylibcugraph._cugraph_c.similarity_algorithms cimport (
from pylibcugraph._cugraph_c.graph cimport cugraph_graph_t

from pylibcugraph._cugraph_c.array cimport (
cugraph_type_erased_device_array_view_t
cugraph_type_erased_device_array_view_t,
cugraph_type_erased_host_array_view_t,
)

cdef extern from "cugraph_c/graph_functions.h":
Expand Down Expand Up @@ -120,6 +121,14 @@ cdef extern from "cugraph_c/graph_functions.h":
cugraph_error_t** error
)

cdef cugraph_error_code_t cugraph_renumber_arbitrary_edgelist(
const cugraph_resource_handle_t* handle,
const cugraph_type_erased_host_array_view_t* renumber_map,
cugraph_type_erased_device_array_view_t* srcs,
cugraph_type_erased_device_array_view_t* dsts,
cugraph_error_t** error
)

###########################################################################
# induced_subgraph
ctypedef struct cugraph_induced_subgraph_result_t: # Deprecated
Expand Down
124 changes: 124 additions & 0 deletions python/pylibcugraph/pylibcugraph/renumber_arbitrary_edgelist.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Copyright (c) 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.
# 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.

# Have cython use python 3 syntax
# cython: language_level = 3

from libc.stdint cimport uintptr_t

from pylibcugraph.resource_handle cimport ResourceHandle

from pylibcugraph._cugraph_c.resource_handle cimport (
cugraph_resource_handle_t,
)
from pylibcugraph._cugraph_c.error cimport (
cugraph_error_code_t,
cugraph_error_t,
)
from pylibcugraph._cugraph_c.array cimport (
cugraph_type_erased_device_array_view_t,
cugraph_type_erased_host_array_view_t,
cugraph_type_erased_device_array_view_free,
cugraph_type_erased_device_array_view_create,
cugraph_type_erased_host_array_view_free,
cugraph_type_erased_host_array_view_create,
)

from pylibcugraph._cugraph_c.graph_functions cimport (
cugraph_renumber_arbitrary_edgelist,
)

from pylibcugraph.utils cimport (
assert_success,
assert_CAI_type,
assert_AI_type,
get_c_type_from_numpy_type,
)

def renumber_arbitrary_edgelist(
ResourceHandle handle,
renumber_map, # host array
srcs, # device array
dsts, # device array
):
"""
Multi-GPU supporting function that accepts a local edgelist
and global renumber map and renumbers the edgelist in place.

Parameters
----------
handle: ResourceHandle
Resource handle to use.
renumber_map: ndarray
Host array type containing the renumber map.
src: ndarray
Device array type containing the source vertices.
dst: ndarray
Device array type containing the destination vertices.

Returns
-------
Nothing.
"""

assert_CAI_type(srcs, "srcs")
assert_CAI_type(dsts, "dsts")

assert_AI_type(renumber_map, "renumber_map")

cdef uintptr_t cai_renumber_map_ptr = \
renumber_map.__array_interface__['data'][0]
cdef cugraph_type_erased_host_array_view_t* map_view = \
cugraph_type_erased_host_array_view_create(
<void*>cai_renumber_map_ptr,
len(renumber_map),
get_c_type_from_numpy_type(renumber_map.dtype)
)

cdef uintptr_t cai_srcs_ptr = \
srcs.__cuda_array_interface__['data'][0]
cdef cugraph_type_erased_device_array_view_t* srcs_view = \
cugraph_type_erased_device_array_view_create(
<void*>cai_srcs_ptr,
len(srcs),
get_c_type_from_numpy_type(srcs.dtype)
)

cdef uintptr_t cai_dsts_ptr = \
dsts.__cuda_array_interface__['data'][0]
cdef cugraph_type_erased_device_array_view_t* dsts_view = \
cugraph_type_erased_device_array_view_create(
<void*>cai_dsts_ptr,
len(dsts),
get_c_type_from_numpy_type(dsts.dtype)
)

cdef cugraph_resource_handle_t* handle_cptr = handle.c_resource_handle_ptr

cdef cugraph_error_t* err_cptr

cdef cugraph_error_code_t err_code = cugraph_renumber_arbitrary_edgelist(
handle_cptr,
map_view,
srcs_view,
dsts_view,
&err_cptr,
)

# Verify that the C API call completed successfully and fail if it did not.
assert_success(err_code, err_cptr, "cugraph_renumber_arbitrary_edgelist")

# Free the views
cugraph_type_erased_device_array_view_free(srcs_view)
cugraph_type_erased_device_array_view_free(dsts_view)
cugraph_type_erased_host_array_view_free(map_view)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) 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.
# 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.

import numpy as np
import cupy

from pylibcugraph import renumber_arbitrary_edgelist
from pylibcugraph.resource_handle import ResourceHandle


def test_renumber_arbitrary_edgelist():
renumber_map = np.array([5, 6, 1, 4, 0, 9])
srcs = cupy.array([1, 1, 4, 4, 5, 5, 0, 9])
dsts = cupy.array([6, 4, 5, 1, 4, 6, 1, 0])

renumber_arbitrary_edgelist(
ResourceHandle(),
renumber_map,
srcs,
dsts,
)

assert srcs.tolist() == [2, 2, 3, 3, 0, 0, 4, 5]
assert dsts.tolist() == [1, 3, 0, 2, 3, 1, 2, 4]
Loading