From aae235785445b7792d444fa7ea551378a5519133 Mon Sep 17 00:00:00 2001 From: Charles Hastings Date: Wed, 17 Jul 2024 12:12:50 -0700 Subject: [PATCH] add PLC bindings for biased sampling --- cpp/include/cugraph_c/properties.h | 79 +++++++++++++++---- .../pylibcugraph/_cugraph_c/properties.pxd | 29 +++++++ .../_cugraph_c/sampling_algorithms.pxd | 21 +++++ 3 files changed, 113 insertions(+), 16 deletions(-) create mode 100644 python/pylibcugraph/pylibcugraph/_cugraph_c/properties.pxd diff --git a/cpp/include/cugraph_c/properties.h b/cpp/include/cugraph_c/properties.h index e4f2a4b20a7..d7775bbf783 100644 --- a/cpp/include/cugraph_c/properties.h +++ b/cpp/include/cugraph_c/properties.h @@ -55,13 +55,14 @@ typedef struct { /** * @brief Create a vertex property * - * @param [in] handle Handle for accessing resources - * @param [in] graph Pointer to graph. - * @param [in] vertex_ids Device array of vertex ids - * @param [in] property Device array of vertex property - * @param [out] result Pointer to the location to store the pointer to the vertex property object - * @param [out] error Pointer to an error object storing details of any error. Will - * be populated if error code is not CUGRAPH_SUCCESS + * @param [in] handle Handle for accessing resources + * @param [in] graph Pointer to graph. + * @param [in] vertex_ids Device array of vertex ids + * @param [in] property Device array of vertex property + * @param [in] default_property Device array of vertex property + * @param [out] result Pointer to the location to store the pointer to the vertex property object + * @param [out] error Pointer to an error object storing details of any error. Will + * be populated if error code is not CUGRAPH_SUCCESS * @return error code */ cugraph_error_code_t cugraph_vertex_property_create( @@ -69,20 +70,22 @@ cugraph_error_code_t cugraph_vertex_property_create( const cugraph_graph_t * graph, const cugraph_type_erased_device_array_t* vertex_ids, const cugraph_type_erased_device_array_t* properties, + const cugraph_type_erased_scalar_t* default_property, cugraph_vertex_property_t** result, cugraph_error_t** error); /** - * @brief Create a edge property + * @brief Create an edge property * - * @param [in] handle Handle for accessing resources - * @param [in] graph Pointer to graph. - * @param [in] lookup_container Lookup map - * @param [in] edge_ids Device array of edge ids - * @param [in] property Device array of edge property - * @param [out] result Pointer to the location to store the pointer to the edge property object - * @param [out] error Pointer to an error object storing details of any error. Will - * be populated if error code is not CUGRAPH_SUCCESS + * @param [in] handle Handle for accessing resources + * @param [in] graph Pointer to graph. + * @param [in] lookup_container Lookup map + * @param [in] edge_ids Device array of edge ids + * @param [in] property Device array of edge property + * @param [in] default_property Device array of vertex property + * @param [out] result Pointer to the location to store the pointer to the edge property object + * @param [out] error Pointer to an error object storing details of any error. Will + * be populated if error code is not CUGRAPH_SUCCESS * @return error code */ cugraph_error_code_t cugraph_edge_property_create( @@ -91,9 +94,53 @@ cugraph_error_code_t cugraph_edge_property_create( const cugraph_lookup_container_t* lookup_container, const cugraph_type_erased_device_array_t* edge_ids, const cugraph_type_erased_device_array_t* properties, + const cugraph_type_erased_scalar_t* default_property, cugraph_edge_property_t** result, cugraph_error_t** error); +/** + * @brief Update an existing vertex property + * + * @param [in] handle Handle for accessing resources + * @param [in] graph Pointer to graph. + * @param [in] vertex_ids Device array of vertex ids to update + * @param [in] property Device array of vertex properties to update + * @param [in/out] result Pointer to the vertex property object to update + * @param [out] error Pointer to an error object storing details of any error. Will + * be populated if error code is not CUGRAPH_SUCCESS + * @return error code + */ +cugraph_error_code_t cugraph_vertex_property_update( + const cugraph_resource_handle_t* handle, + const cugraph_graph_t * graph, + const cugraph_type_erased_device_array_t* vertex_ids, + const cugraph_type_erased_device_array_t* properties, + const cugraph_type_erased_scalar_t* default_property, + cugraph_vertex_property_view_t* result, + cugraph_error_t** error); + +/** + * @brief Update an existing edge property + * + * @param [in] handle Handle for accessing resources + * @param [in] graph Pointer to graph. + * @param [in] lookup_container Lookup map + * @param [in] edge_ids Device array of edge ids to update + * @param [in] property Device array of edge properties to update + * @param [in/out] result Pointer to the edge property object to update + * @param [out] error Pointer to an error object storing details of any error. Will + * be populated if error code is not CUGRAPH_SUCCESS + * @return error code + */ +cugraph_error_code_t cugraph_edge_property_create( + const cugraph_resource_handle_t* handle, + const cugraph_graph_t * graph, + const cugraph_lookup_container_t* lookup_container, + const cugraph_type_erased_device_array_t* edge_ids, + const cugraph_type_erased_device_array_t* properties, + cugraph_edge_property_view_t* result, + cugraph_error_t** error); + /** * @brief Create a vertex_property_view from a vertex property * diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/properties.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/properties.pxd new file mode 100644 index 00000000000..2838de3d0ab --- /dev/null +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/properties.pxd @@ -0,0 +1,29 @@ +# Copyright (c) 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. +# 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 + +cdef extern from "cugraph_c/properties.h": + + ctypedef struct cugraph_vertex_property_t: + pass + + ctypedef struct cugraph_edge_property_t: + pass + + ctypedef struct cugraph_vertex_property_view_t: + pass + + ctypedef struct cugraph_edge_property_view_t: + pass diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/sampling_algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/sampling_algorithms.pxd index dbd3ef4b7e1..0f852d9cecd 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/sampling_algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/sampling_algorithms.pxd @@ -40,6 +40,10 @@ from pylibcugraph._cugraph_c.array cimport ( cugraph_type_erased_device_array_t, ) +from pylibcugraph._cugraph_c.properties cimport ( + cugraph_edge_property_view_t, +) + cdef extern from "cugraph_c/sampling_algorithms.h": ########################################################################### @@ -59,6 +63,23 @@ cdef extern from "cugraph_c/sampling_algorithms.h": cugraph_error_t** error ) + cdef cugraph_error_code_t cugraph_biased_neighbor_sample( + const cugraph_resource_handle_t* handle, + cugraph_graph_t* graph, + const cugraph_edge_property_view_t* edge_biases, + const cugraph_type_erased_device_array_view_t* start_vertices, + const cugraph_type_erased_device_array_view_t* start_vertex_labels, + const cugraph_type_erased_device_array_view_t* label_list, + const cugraph_type_erased_device_array_view_t* label_to_comm_rank, + const cugraph_type_erased_device_array_view_t* label_offsets, + const cugraph_type_erased_host_array_view_t* fan_out, + cugraph_rng_state_t* rng_state, + const cugraph_sampling_options_t* options, + bool_t do_expensive_check, + cugraph_sample_result_t** result, + cugraph_error_t** error + ) + cdef cugraph_error_code_t cugraph_test_uniform_neighborhood_sample_result_create( const cugraph_resource_handle_t* handle, const cugraph_type_erased_device_array_view_t* srcs,