From 8791522226e84840d2ce5ba253c1cdd88a6ed596 Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Mon, 25 Oct 2021 15:38:32 -0400 Subject: [PATCH 01/19] Add graph creation routines --- cpp/CMakeLists.txt | 3 + cpp/include/cugraph_c/algorithms.h | 59 ++++++ cpp/include/cugraph_c/array.h | 67 +++++++ cpp/include/cugraph_c/graph.h | 64 +++++++ cpp/src/c_api/array.cpp | 171 ++++++++++++++++++ cpp/src/c_api/graph_mg.cpp | 37 ++++ cpp/src/c_api/graph_sg.cpp | 34 ++++ cpp/tests/CMakeLists.txt | 3 +- cpp/tests/c_api/c_test_utils.h | 6 + cpp/tests/c_api/create_graph_test.c | 94 ++++++++++ ...test.c => create_sg_graph_envelope_test.c} | 0 11 files changed, 537 insertions(+), 1 deletion(-) create mode 100644 cpp/include/cugraph_c/algorithms.h create mode 100644 cpp/include/cugraph_c/array.h create mode 100644 cpp/include/cugraph_c/graph.h create mode 100644 cpp/src/c_api/array.cpp create mode 100644 cpp/src/c_api/graph_mg.cpp create mode 100644 cpp/src/c_api/graph_sg.cpp create mode 100644 cpp/tests/c_api/create_graph_test.c rename cpp/tests/c_api/{create_sg_graph_test.c => create_sg_graph_envelope_test.c} (100%) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index f656e812ff2..00356b1ad4c 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -353,6 +353,9 @@ endif() add_library(cugraph_c SHARED src/c_api/cugraph_api.cpp + src/c_api/array.cpp + src/c_api/graph_sg.cpp + src/c_api/graph_mg.cpp ) add_library(cugraph::cugraph_c ALIAS cugraph_c) diff --git a/cpp/include/cugraph_c/algorithms.h b/cpp/include/cugraph_c/algorithms.h new file mode 100644 index 00000000000..877db0ce6c4 --- /dev/null +++ b/cpp/include/cugraph_c/algorithms.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021, 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. + */ + +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +cugraph_error_t pagerank(const cugraph_raft_handle_t* handle, + const cugraph_graph_t* graph, + cugraph_type_erased_device_array_t* pageranks, + cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, + double alpha, + double epsilon, + size_t max_iterations, + bool has_initial_guess, + bool do_expensive_check); + +cugraph_error_t personalized_pagerank( + const cugraph_raft_handle_t* handle, + const cugraph_graph_t* graph, + cugraph_type_erased_device_array_t* pageranks, + cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, + cugraph_type_erased_device_array_t* personalization_vertices, + cugraph_type_erased_device_array_t* personalization_values, + double alpha, + double epsilon, + size_t max_iterations, + bool has_initial_guess, + bool do_expensive_check); + +cugraph_error_t bfs(const cugraph_raft_handle_t* handle, + const cugraph_graph_t* graph, + cugraph_type_erased_device_array_t* distances, + cugraph_type_erased_device_array_t* predecessors, + const cugraph_type_erased_device_array_t* sources, + bool direction_optimizing, + vertex_t depth_limit, + bool do_expensive_check); + +#ifdef __cplusplus +} +#endif diff --git a/cpp/include/cugraph_c/array.h b/cpp/include/cugraph_c/array.h new file mode 100644 index 00000000000..6ff83123d7c --- /dev/null +++ b/cpp/include/cugraph_c/array.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021, 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. + */ + +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + void* data_; + size_t size_; + data_type_id_t type_; +} cugraph_type_erased_device_array_t; + +typedef struct { + void* data_; + size_t size_; + data_type_id_t type_; +} cugraph_type_erased_host_array_t; + +cugraph_type_erased_device_array_t* cugraph_type_erased_device_array_create( + const cugraph_raft_handle_t* raft_handle, data_type_id_t dtype, size_t n_elems); + +void cugraph_type_erased_device_array_free(cugraph_type_erased_device_array_t* p); + +size_t cugraph_type_erased_device_array_size(const cugraph_type_erased_device_array_t* p); +data_type_id_t cugraph_type_erased_device_array_type(const cugraph_type_erased_device_array_t* p); +void* cugraph_type_erased_device_array_pointer(const cugraph_type_erased_device_array_t* p); + +cugraph_type_erased_host_array_t* cugraph_type_erased_host_array_create( + const cugraph_raft_handle_t* raft_handle, data_type_id_t dtype, size_t n_elems); + +void cugraph_type_erased_host_array_free(cugraph_type_erased_host_array_t* p); + +size_t cugraph_type_erased_host_array_size(const cugraph_type_erased_host_array_t* p); +data_type_id_t cugraph_type_erased_host_array_type(const cugraph_type_erased_host_array_t* p); +void* cugraph_type_erased_host_array_pointer(const cugraph_type_erased_host_array_t* p); + +cugraph_error_t cugraph_type_erased_device_array_copy_from_host( + const cugraph_raft_handle_t* raft_handle, + cugraph_type_erased_device_array_t* dst, + const byte_t* h_src); + +cugraph_error_t cugraph_type_erased_device_array_copy_to_host( + const cugraph_raft_handle_t* raft_handle, + byte_t* h_dst, + const cugraph_type_erased_device_array_t* src); + +#ifdef __cplusplus +} +#endif diff --git a/cpp/include/cugraph_c/graph.h b/cpp/include/cugraph_c/graph.h new file mode 100644 index 00000000000..67d554b383f --- /dev/null +++ b/cpp/include/cugraph_c/graph.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2021, 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. + */ + +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + int align_; +} cugraph_graph_t; + +/* SG graph */ +cugraph_graph_t* cugraph_sg_graph_create(const cugraph_raft_handle_t* handle, + const cugraph_type_erased_device_array_t* src, + const cugraph_type_erased_device_array_t* dst, + const cugraph_type_erased_device_array_t* weights, + bool_t store_transposed, + size_t num_vertices, + size_t num_edges, + bool_t check, + bool_t is_symmetric, + bool_t is_multigraph); + +void cugraph_sg_graph_free(cugraph_graph_t* graph); + +/* MG graph */ +cugraph_graph_t* cugraph_mg_graph_create( + const cugraph_raft_handle_t* handle, + const cugraph_type_erased_device_array_t* src, + const cugraph_type_erased_device_array_t* dst, + const cugraph_type_erased_device_array_t* weights, + const cugraph_type_erased_host_array_t* vertex_partition_offsets, + const cugraph_type_erased_host_array_t* segment_offsets, + size_t num_segments, + bool_t store_transposed, + size_t num_vertices, + size_t num_edges, + bool_t check, + bool_t is_symmetric, + bool_t is_multigraph); + +void cugraph_mg_graph_free(cugraph_graph_t* graph); + +#ifdef __cplusplus +} +#endif diff --git a/cpp/src/c_api/array.cpp b/cpp/src/c_api/array.cpp new file mode 100644 index 00000000000..0cff3bac7d9 --- /dev/null +++ b/cpp/src/c_api/array.cpp @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2021, 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. + */ + +#include + +#include + +#include + +namespace c_api { + +typedef struct { + rmm::device_buffer* data_; + size_t size_; + size_t nbytes_; + data_type_id_t type_; +} cugraph_type_erased_device_array_t; + +typedef struct { + uint8_t* data_; + size_t size_; + size_t nbytes_; + data_type_id_t type_; +} cugraph_type_erased_host_array_t; + +} // namespace c_api + +extern "C" cugraph_type_erased_device_array_t* cugraph_type_erased_device_array_create( + const cugraph_raft_handle_t* handle, data_type_id_t dtype, size_t n_elems) +{ + try { + raft::handle_t const* raft_handle = reinterpret_cast(handle); + + if (!raft_handle) return nullptr; + + size_t nbytes = n_elems * (::data_type_sz[dtype]); + + c_api::cugraph_type_erased_device_array_t* ret_value = + new c_api::cugraph_type_erased_device_array_t{ + new rmm::device_buffer(nbytes, raft_handle->get_stream()), n_elems, nbytes, dtype}; + + return reinterpret_cast(ret_value); + } catch (...) { + return nullptr; + } +} + +extern "C" void cugraph_type_erased_device_array_free(cugraph_type_erased_device_array_t* p) +{ + auto internal_pointer = reinterpret_cast(p); + delete internal_pointer->data_; + delete internal_pointer; +} + +extern "C" size_t cugraph_type_erased_device_array_size(const cugraph_type_erased_device_array_t* p) +{ + auto internal_pointer = reinterpret_cast(p); + return internal_pointer->size_; +} + +extern "C" data_type_id_t cugraph_type_erased_device_array_type( + const cugraph_type_erased_device_array_t* p) +{ + auto internal_pointer = reinterpret_cast(p); + return internal_pointer->type_; +} + +extern "C" void* cugraph_type_erased_device_array_pointer( + const cugraph_type_erased_device_array_t* p) +{ + auto internal_pointer = reinterpret_cast(p); + return internal_pointer->data_->data(); +} + +extern "C" cugraph_type_erased_host_array_t* cugraph_type_erased_host_array_create( + const cugraph_raft_handle_t* handle, data_type_id_t dtype, size_t n_elems) +{ + try { + raft::handle_t const* raft_handle = reinterpret_cast(handle); + + if (!raft_handle) return nullptr; + + size_t nbytes = n_elems * (::data_type_sz[dtype]); + + c_api::cugraph_type_erased_host_array_t* ret_value = + new c_api::cugraph_type_erased_host_array_t{new uint8_t[nbytes], n_elems, nbytes, dtype}; + + return reinterpret_cast(ret_value); + } catch (...) { + return nullptr; + } +} + +extern "C" void cugraph_type_erased_host_array_free(cugraph_type_erased_host_array_t* p) +{ + auto internal_pointer = reinterpret_cast(p); + delete[] internal_pointer->data_; + delete internal_pointer; +} + +extern "C" size_t cugraph_type_erased_host_array_size(const cugraph_type_erased_host_array_t* p) +{ + auto internal_pointer = reinterpret_cast(p); + return internal_pointer->size_; +} + +extern "C" data_type_id_t cugraph_type_erased_host_array_type( + const cugraph_type_erased_host_array_t* p) +{ + auto internal_pointer = reinterpret_cast(p); + return internal_pointer->type_; +} + +extern "C" void* cugraph_type_erased_host_array_pointer(const cugraph_type_erased_host_array_t* p) +{ + auto internal_pointer = reinterpret_cast(p); + return internal_pointer->data_; +} + +extern "C" cugraph_error_t cugraph_type_erased_device_array_copy_from_host( + const cugraph_raft_handle_t* handle, cugraph_type_erased_device_array_t* dst, const byte_t* h_src) +{ + try { + raft::handle_t const* raft_handle = reinterpret_cast(handle); + auto internal_pointer = reinterpret_cast(dst); + + if (!raft_handle) return CUGRAPH_ALLOC_ERROR; + + raft::update_device(reinterpret_cast(internal_pointer->data_->data()), + h_src, + internal_pointer->nbytes_, + raft_handle->get_stream()); + + return CUGRAPH_SUCCESS; + } catch (...) { + return CUGRAPH_UNKNOWN_ERROR; + } +} + +extern "C" cugraph_error_t cugraph_type_erased_device_array_copy_to_host( + const cugraph_raft_handle_t* handle, byte_t* h_dst, const cugraph_type_erased_device_array_t* src) +{ + try { + raft::handle_t const* raft_handle = reinterpret_cast(handle); + auto internal_pointer = reinterpret_cast(src); + + if (!raft_handle) return CUGRAPH_ALLOC_ERROR; + + raft::update_host(h_dst, + reinterpret_cast(internal_pointer->data_->data()), + internal_pointer->nbytes_, + raft_handle->get_stream()); + + return CUGRAPH_SUCCESS; + } catch (...) { + return CUGRAPH_UNKNOWN_ERROR; + } +} diff --git a/cpp/src/c_api/graph_mg.cpp b/cpp/src/c_api/graph_mg.cpp new file mode 100644 index 00000000000..a0c7d9b8ea5 --- /dev/null +++ b/cpp/src/c_api/graph_mg.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021, 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. + */ + +#include + +extern "C" cugraph_graph_t* cugraph_mg_graph_create( + const cugraph_raft_handle_t* handle, + const cugraph_type_erased_device_array_t* src, + const cugraph_type_erased_device_array_t* dst, + const cugraph_type_erased_device_array_t* weights, + const cugraph_type_erased_host_array_t* vertex_partition_offsets, + const cugraph_type_erased_host_array_t* segment_offsets, + size_t num_segments, + bool_t store_transposed, + size_t num_vertices, + size_t num_edges, + bool_t check, + bool_t is_symmetric, + bool_t is_multigraph) +{ + return nullptr; +} + +extern "C" void cugraph_mg_graph_free(cugraph_graph_t* ptr_graph) {} diff --git a/cpp/src/c_api/graph_sg.cpp b/cpp/src/c_api/graph_sg.cpp new file mode 100644 index 00000000000..bf1cca9127a --- /dev/null +++ b/cpp/src/c_api/graph_sg.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021, 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. + */ + +#include + +extern "C" cugraph_graph_t* cugraph_sg_graph_create( + const cugraph_raft_handle_t* p_handle, + const cugraph_type_erased_device_array_t* src, + const cugraph_type_erased_device_array_t* dst, + const cugraph_type_erased_device_array_t* weights, + bool_t store_transposed, + size_t num_vertices, + size_t num_edges, + bool_t check, + bool_t is_symmetric, + bool_t is_multigraph) +{ + return nullptr; +} + +extern "C" void cugraph_sg_graph_free(cugraph_graph_t* ptr_graph) {} diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt index 55e865b1f8a..bfed58d4b7a 100644 --- a/cpp/tests/CMakeLists.txt +++ b/cpp/tests/CMakeLists.txt @@ -527,7 +527,8 @@ endif() ################################################################################################### # - C API tests ----------------------------------------------------------------------------------- -ConfigureCTest(CAPI_CREATE_SG_GRAPH_TEST c_api/create_sg_graph_test.c) +ConfigureCTest(CAPI_CREATE_SG_GRAPH_ENVELOPE_TEST c_api/create_sg_graph_envelope_test.c) +ConfigureCTest(CAPI_CREATE_GRAPH_TEST c_api/create_graph_test.c) ConfigureCTest(CAPI_RANDOM_WALKS_TEST c_api/random_walks_test.c) ################################################################################################### diff --git a/cpp/tests/c_api/c_test_utils.h b/cpp/tests/c_api/c_test_utils.h index c87eb0b6f08..44765777a64 100644 --- a/cpp/tests/c_api/c_test_utils.h +++ b/cpp/tests/c_api/c_test_utils.h @@ -17,6 +17,12 @@ #include #include +#define TEST_ASSERT(RETURN_VALUE, STATEMENT, MESSAGE) \ + { \ + (RETURN_VALUE) = !(STATEMENT); \ + if ((RETURN_VALUE)) { printf("ASSERTION FAILED: %s\n", (MESSAGE)); } \ + } + /* * Runs the function pointed to by "test" and returns the return code. Also * prints reporting info (using "test_name"): pass/fail and run time, to stdout. diff --git a/cpp/tests/c_api/create_graph_test.c b/cpp/tests/c_api/create_graph_test.c new file mode 100644 index 00000000000..8efac72cb46 --- /dev/null +++ b/cpp/tests/c_api/create_graph_test.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2021, 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. + */ + +#include "c_test_utils.h" /* RUN_TEST */ + +#include +#include + +/* + * Simple check of creating a graph from a COO on device memory. + */ +int test_create_sg_graph_simple() +{ + int test_ret_value = 0; + + typedef int32_t vertex_t; + typedef int32_t edge_t; + typedef float weight_t; + + cugraph_error_t ret_code = CUGRAPH_SUCCESS; + size_t num_edges = 8; + size_t num_vertices = 6; + + vertex_t h_src[] = {0, 1, 1, 2, 2, 2, 3, 4}; + vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; + weight_t h_wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; + + cugraph_raft_handle_t* p_handle = NULL; + cugraph_graph_t* p_graph = NULL; + + data_type_id_t vertex_tid = INT32; + data_type_id_t edge_tid = INT32; + data_type_id_t weight_tid = FLOAT32; + + p_handle = cugraph_create_handle(); + TEST_ASSERT(test_ret_value, p_handle != NULL, "raft handle creation failed."); + + cugraph_type_erased_device_array_t* src; + cugraph_type_erased_device_array_t* dst; + cugraph_type_erased_device_array_t* wgt; + + src = cugraph_type_erased_device_array_create(p_handle, vertex_tid, num_edges); + dst = cugraph_type_erased_device_array_create(p_handle, vertex_tid, num_edges); + wgt = cugraph_type_erased_device_array_create(p_handle, weight_tid, num_edges); + + ret_code = cugraph_type_erased_device_array_copy_from_host(p_handle, src, (byte_t*)h_src); + TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "src copy_from_host failed."); + + ret_code = cugraph_type_erased_device_array_copy_from_host(p_handle, dst, (byte_t*)h_dst); + TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "dst copy_from_host failed."); + + ret_code = cugraph_type_erased_device_array_copy_from_host(p_handle, wgt, (byte_t*)h_wgt); + TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "wgt copy_from_host failed."); + + p_graph = cugraph_sg_graph_create( + p_handle, src, dst, wgt, FALSE, num_vertices, num_edges, FALSE, FALSE, FALSE); + TEST_ASSERT(test_ret_value, p_graph != NULL, "graph creation failed."); + + cugraph_sg_graph_free(p_graph); + + cugraph_type_erased_device_array_free(wgt); + + cugraph_type_erased_device_array_free(dst); + + cugraph_type_erased_device_array_free(src); + + cugraph_free_handle(p_handle); + + // FIXME: Not implemented yet, so forcing test to pass... + // return test_ret_value; + return 0; +} + +/******************************************************************************/ + +int main(int argc, char** argv) +{ + int result = 0; + result |= RUN_TEST(test_create_sg_graph_simple); + return result; +} diff --git a/cpp/tests/c_api/create_sg_graph_test.c b/cpp/tests/c_api/create_sg_graph_envelope_test.c similarity index 100% rename from cpp/tests/c_api/create_sg_graph_test.c rename to cpp/tests/c_api/create_sg_graph_envelope_test.c From aa88d591bac5fe931677226808f0ccd2245e4b8e Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Tue, 26 Oct 2021 15:31:49 -0400 Subject: [PATCH 02/19] add some documentation --- cpp/include/cugraph_c/algorithms.h | 103 ++++++++++++++++++++++++----- cpp/include/cugraph_c/array.h | 8 +-- cpp/include/cugraph_c/graph.h | 38 ++++++++--- 3 files changed, 118 insertions(+), 31 deletions(-) diff --git a/cpp/include/cugraph_c/algorithms.h b/cpp/include/cugraph_c/algorithms.h index 877db0ce6c4..cc8f590c2da 100644 --- a/cpp/include/cugraph_c/algorithms.h +++ b/cpp/include/cugraph_c/algorithms.h @@ -22,33 +22,106 @@ extern "C" { #endif -cugraph_error_t pagerank(const cugraph_raft_handle_t* handle, - const cugraph_graph_t* graph, - cugraph_type_erased_device_array_t* pageranks, - cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, - double alpha, - double epsilon, - size_t max_iterations, - bool has_initial_guess, - bool do_expensive_check); +/** + * @brief Compute pagerank + * + * @param [in] handle Handle for accessing resources + * @param [in] graph Pointer to graph + * @param [out] vertex_ids Returns device pointer to vertex ids + * @param [out] pageranks Returns device pointer to pagerank scores + * @param [in] precomputed_vertex_out_weight_sums + * Optionally send in precomputed sume of vertex out weights + * (a performance optimization). Set to NULL if + * no value is passed. + * @param [in] alpha PageRank damping factor. + * @param [in] epsilon Error tolerance to check convergence. Convergence is assumed + * if the sum of the differences in PageRank values between two + * consecutive iterations is less than the number of vertices + * in the graph multiplied by @p epsilon. + * @param [in] max_iterations Maximum number of PageRank iterations. + * @param [in] has_initial_guess If set to `true`, values in the PageRank output array (pointed by + * @p pageranks) is used as initial PageRank values. If false, initial PageRank values are set + * to 1.0 divided by the number of vertices in the graph. + * @param do_expensive_check A flag to run expensive checks for input arguments (if set to `true`). + */ +cugraph_error_t pagerank( + const cugraph_raft_handle_t* handle, + const cugraph_graph_t* graph, + cugraph_type_erased_device_array_t** vertex_ids, + cugraph_type_erased_device_array_t** pageranks, + const cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, + double alpha, + double epsilon, + size_t max_iterations, + bool has_initial_guess, + bool do_expensive_check); +/** + * @brief Compute personalized pagerank + * + * @param [in] handle Handle for accessing resources + * @param [in] graph Pointer to graph + * @param [out] vertex_ids Returns device pointer to vertex ids + * @param [out] pageranks Returns device pointer to pagerank scores + * @param [in] precomputed_vertex_out_weight_sums + * Optionally send in precomputed sume of vertex out weights + * (a performance optimization). Set to NULL if + * no value is passed. + * @param [in] personalization_vertices Pointer to an array storing personalization vertex + * identifiers (compute personalized PageRank) + * @param [in] personalization_values Pointer to an array storing personalization values for the + * vertices in the personalization set. + * @param [in] alpha PageRank damping factor. + * @param [in] epsilon Error tolerance to check convergence. Convergence is assumed + * if the sum of the differences in PageRank values between two + * consecutive iterations is less than the number of vertices + * in the graph multiplied by @p epsilon. + * @param [in] max_iterations Maximum number of PageRank iterations. + * @param [in] has_initial_guess If set to `true`, values in the PageRank output array (pointed by + * @p pageranks) is used as initial PageRank values. If false, initial PageRank values are set + * to 1.0 divided by the number of vertices in the graph. + * @param do_expensive_check A flag to run expensive checks for input arguments (if set to `true`). + */ cugraph_error_t personalized_pagerank( const cugraph_raft_handle_t* handle, const cugraph_graph_t* graph, - cugraph_type_erased_device_array_t* pageranks, - cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, - cugraph_type_erased_device_array_t* personalization_vertices, - cugraph_type_erased_device_array_t* personalization_values, + cugraph_type_erased_device_array_t** vertex_ids, + cugraph_type_erased_device_array_t** pageranks, + const cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, + const cugraph_type_erased_device_array_t* personalization_vertices, + const cugraph_type_erased_device_array_t* personalization_values, double alpha, double epsilon, size_t max_iterations, bool has_initial_guess, bool do_expensive_check); +/** + * @brief Perform a breadth first search from a set of seed vertices. + * + * This function computes the distances (minimum number of hops to reach the vertex) from the source + * vertex. If @p predecessors is not NULL, this function calculates the predecessor of each + * vertex (parent vertex in the breadth-first search tree) as well. + * + * @param [in] handle Handle for accessing resources + * @param [in] graph Pointer to graph + * @param [out] vertex_ids Returns device pointer to vertex ids + * @param [out] distances Returns device pointer to distance from the seeds + * @param [out] predecessors Returns device pointer to distance from the seeds + * @param [in] sources Array of source vertices + * @param [in] direction_optimizing If set to true, this algorithm switches between the push based + * breadth-first search and pull based breadth-first search depending on the size of the + * breadth-first search frontier (currently unsupported). This option is valid only for symmetric + * input graphs. + * @param depth_limit Sets the maximum number of breadth-first search iterations. Any vertices + * farther than @p depth_limit hops from @p source_vertex will be marked as unreachable. + * @param do_expensive_check A flag to run expensive checks for input arguments (if set to `true`). + */ cugraph_error_t bfs(const cugraph_raft_handle_t* handle, const cugraph_graph_t* graph, - cugraph_type_erased_device_array_t* distances, - cugraph_type_erased_device_array_t* predecessors, + cugraph_type_erased_device_array_t** vertex_ids, + cugraph_type_erased_device_array_t** distances, + cugraph_type_erased_device_array_t** predecessors, const cugraph_type_erased_device_array_t* sources, bool direction_optimizing, vertex_t depth_limit, diff --git a/cpp/include/cugraph_c/array.h b/cpp/include/cugraph_c/array.h index 6ff83123d7c..9a89697ecda 100644 --- a/cpp/include/cugraph_c/array.h +++ b/cpp/include/cugraph_c/array.h @@ -23,15 +23,11 @@ extern "C" { #endif typedef struct { - void* data_; - size_t size_; - data_type_id_t type_; + int align_; } cugraph_type_erased_device_array_t; typedef struct { - void* data_; - size_t size_; - data_type_id_t type_; + int align_; } cugraph_type_erased_host_array_t; cugraph_type_erased_device_array_t* cugraph_type_erased_device_array_create( diff --git a/cpp/include/cugraph_c/graph.h b/cpp/include/cugraph_c/graph.h index 67d554b383f..a54fbebfa87 100644 --- a/cpp/include/cugraph_c/graph.h +++ b/cpp/include/cugraph_c/graph.h @@ -28,16 +28,34 @@ typedef struct { } cugraph_graph_t; /* SG graph */ -cugraph_graph_t* cugraph_sg_graph_create(const cugraph_raft_handle_t* handle, - const cugraph_type_erased_device_array_t* src, - const cugraph_type_erased_device_array_t* dst, - const cugraph_type_erased_device_array_t* weights, - bool_t store_transposed, - size_t num_vertices, - size_t num_edges, - bool_t check, - bool_t is_symmetric, - bool_t is_multigraph); +/** + * @brief Construct an SG graph + * + * @param [in] handle Handle for accessing resources + * @param [in] src Device array containing the source vertex ids + * @param [in] dst Device array containing the destination vertex ids + * @param [in] weights Device array containing the edge weights + * @param [in] store_transposed If true create the graph initially in transposed format + * @param [in] renumber If true, renumber vertices to make an efficient data structure. + * If false, do not renumber. Renumbering is required if the vertices are not sequential + * integer values from 0 to num_vertices. + * @param [in] do_expensive_check If true, do expensive checks to validate the input data + * is consistent with software assumptions. If false bypass these checks. + * @param [in] is_symmetric If true the input graph is symmetric + * @param [in] is_multigraph If true the input graph is a multi graph (can have multiple edges + * between a pair of vertices) + * @param [out] graph A pointer to the graph object + */ +cugraph_error_t cugraph_sg_graph_create(const cugraph_raft_handle_t* handle, + const cugraph_type_erased_device_array_t* src, + const cugraph_type_erased_device_array_t* dst, + const cugraph_type_erased_device_array_t* weights, + bool_t store_transposed, + bool_t renumber, + bool_t check, + bool_t is_symmetric, + bool_t is_multigraph, + cugraph_graph_t **graph); void cugraph_sg_graph_free(cugraph_graph_t* graph); From adeeba1cf7ad4f23766f29c1c59fc5233b285453 Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Tue, 26 Oct 2021 16:05:16 -0400 Subject: [PATCH 03/19] add a properties class --- cpp/include/cugraph_c/graph.h | 57 ++++++++++++++++++++++++++++------- cpp/src/c_api/graph_mg.cpp | 10 +++--- cpp/src/c_api/graph_sg.cpp | 14 ++++----- 3 files changed, 58 insertions(+), 23 deletions(-) diff --git a/cpp/include/cugraph_c/graph.h b/cpp/include/cugraph_c/graph.h index a54fbebfa87..9245e18fe59 100644 --- a/cpp/include/cugraph_c/graph.h +++ b/cpp/include/cugraph_c/graph.h @@ -27,7 +27,11 @@ typedef struct { int align_; } cugraph_graph_t; -/* SG graph */ +typedef struct { + bool is_symmetric; + bool is_multigraph; +} cugraph_graph_properties_t; + /** * @brief Construct an SG graph * @@ -41,40 +45,71 @@ typedef struct { * integer values from 0 to num_vertices. * @param [in] do_expensive_check If true, do expensive checks to validate the input data * is consistent with software assumptions. If false bypass these checks. - * @param [in] is_symmetric If true the input graph is symmetric - * @param [in] is_multigraph If true the input graph is a multi graph (can have multiple edges - * between a pair of vertices) + * @param [in] properties Properties of the graph * @param [out] graph A pointer to the graph object + * + * @return error code */ cugraph_error_t cugraph_sg_graph_create(const cugraph_raft_handle_t* handle, + const cugraph_graph_properties_t *properties, const cugraph_type_erased_device_array_t* src, const cugraph_type_erased_device_array_t* dst, const cugraph_type_erased_device_array_t* weights, bool_t store_transposed, bool_t renumber, bool_t check, - bool_t is_symmetric, - bool_t is_multigraph, cugraph_graph_t **graph); +/** + * @brief Destroy an SG graph + * + * @param [in] graph A pointer to the graph object to destroy + */ +// FIXME: This should probably just be cugraph_graph_free +// but didn't want to confuse with original cugraph_free_graph void cugraph_sg_graph_free(cugraph_graph_t* graph); -/* MG graph */ -cugraph_graph_t* cugraph_mg_graph_create( +/** + * @brief Construct an MG graph + * + * @param [in] handle Handle for accessing resources + * @param [in] src Device array containing the source vertex ids + * @param [in] dst Device array containing the destination vertex ids + * @param [in] weights Device array containing the edge weights + * @param [in] vertex_partition_offsets Host array containing the offsets for each vertex partition + * @param [in] segment_offsets Host array containing the offsets for each segment + * @param [in] store_transposed If true create the graph initially in transposed format + * @param [in] renumber If true, renumber vertices to make an efficient data structure. + * If false, do not renumber. Renumbering is required if the vertices are not sequential + * integer values from 0 to num_vertices. + * @param [in] do_expensive_check If true, do expensive checks to validate the input data + * is consistent with software assumptions. If false bypass these checks. + * @param [in] is_symmetric If true the input graph is symmetric + * @param [in] is_multigraph If true the input graph is a multi graph (can have multiple edges + * between a pair of vertices) + * @param [out] graph A pointer to the graph object + */ +cugraph_error_t cugraph_mg_graph_create( const cugraph_raft_handle_t* handle, + const cugraph_graph_properties_t *properties, const cugraph_type_erased_device_array_t* src, const cugraph_type_erased_device_array_t* dst, const cugraph_type_erased_device_array_t* weights, const cugraph_type_erased_host_array_t* vertex_partition_offsets, const cugraph_type_erased_host_array_t* segment_offsets, - size_t num_segments, bool_t store_transposed, size_t num_vertices, size_t num_edges, bool_t check, - bool_t is_symmetric, - bool_t is_multigraph); + cugraph_graph_t **graph); +/** + * @brief Destroy an MG graph + * + * @param [in] graph A pointer to the graph object to destroy + */ +// FIXME: This should probably just be cugraph_graph_free +// but didn't want to confuse with original cugraph_free_graph void cugraph_mg_graph_free(cugraph_graph_t* graph); #ifdef __cplusplus diff --git a/cpp/src/c_api/graph_mg.cpp b/cpp/src/c_api/graph_mg.cpp index a0c7d9b8ea5..c5ad2ee557e 100644 --- a/cpp/src/c_api/graph_mg.cpp +++ b/cpp/src/c_api/graph_mg.cpp @@ -16,22 +16,22 @@ #include -extern "C" cugraph_graph_t* cugraph_mg_graph_create( +extern "C" cugraph_error_t cugraph_mg_graph_create( const cugraph_raft_handle_t* handle, + const cugraph_graph_properties_t* properties, const cugraph_type_erased_device_array_t* src, const cugraph_type_erased_device_array_t* dst, const cugraph_type_erased_device_array_t* weights, const cugraph_type_erased_host_array_t* vertex_partition_offsets, const cugraph_type_erased_host_array_t* segment_offsets, - size_t num_segments, bool_t store_transposed, size_t num_vertices, size_t num_edges, bool_t check, - bool_t is_symmetric, - bool_t is_multigraph) + cugraph_graph_t** graph) { - return nullptr; + *graph = nullptr; + return CUGRAPH_UNKNOWN_ERROR; } extern "C" void cugraph_mg_graph_free(cugraph_graph_t* ptr_graph) {} diff --git a/cpp/src/c_api/graph_sg.cpp b/cpp/src/c_api/graph_sg.cpp index bf1cca9127a..ba4ab4563e7 100644 --- a/cpp/src/c_api/graph_sg.cpp +++ b/cpp/src/c_api/graph_sg.cpp @@ -16,19 +16,19 @@ #include -extern "C" cugraph_graph_t* cugraph_sg_graph_create( - const cugraph_raft_handle_t* p_handle, +extern "C" cugraph_error_t cugraph_sg_graph_create( + const cugraph_raft_handle_t* handle, + const cugraph_graph_properties_t* properties, const cugraph_type_erased_device_array_t* src, const cugraph_type_erased_device_array_t* dst, const cugraph_type_erased_device_array_t* weights, bool_t store_transposed, - size_t num_vertices, - size_t num_edges, + bool_t renumber, bool_t check, - bool_t is_symmetric, - bool_t is_multigraph) + cugraph_graph_t** graph) { - return nullptr; + *graph = nullptr; + return CUGRAPH_UNKNOWN_ERROR; } extern "C" void cugraph_sg_graph_free(cugraph_graph_t* ptr_graph) {} From e00d9311457840cf7da821b0feae42ebab272ba1 Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Tue, 26 Oct 2021 16:42:03 -0400 Subject: [PATCH 04/19] debugging --- cpp/include/cugraph_c/graph.h | 4 ++-- cpp/tests/c_api/create_graph_test.c | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cpp/include/cugraph_c/graph.h b/cpp/include/cugraph_c/graph.h index 9245e18fe59..da6399a347e 100644 --- a/cpp/include/cugraph_c/graph.h +++ b/cpp/include/cugraph_c/graph.h @@ -28,8 +28,8 @@ typedef struct { } cugraph_graph_t; typedef struct { - bool is_symmetric; - bool is_multigraph; + bool_t is_symmetric; + bool_t is_multigraph; } cugraph_graph_properties_t; /** diff --git a/cpp/tests/c_api/create_graph_test.c b/cpp/tests/c_api/create_graph_test.c index 8efac72cb46..1bac68b51e9 100644 --- a/cpp/tests/c_api/create_graph_test.c +++ b/cpp/tests/c_api/create_graph_test.c @@ -40,6 +40,10 @@ int test_create_sg_graph_simple() cugraph_raft_handle_t* p_handle = NULL; cugraph_graph_t* p_graph = NULL; + cugraph_graph_properties_t properties; + + properties.is_symmetric = FALSE; + properties.is_multigraph = FALSE; data_type_id_t vertex_tid = INT32; data_type_id_t edge_tid = INT32; @@ -65,9 +69,16 @@ int test_create_sg_graph_simple() ret_code = cugraph_type_erased_device_array_copy_from_host(p_handle, wgt, (byte_t*)h_wgt); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "wgt copy_from_host failed."); - p_graph = cugraph_sg_graph_create( - p_handle, src, dst, wgt, FALSE, num_vertices, num_edges, FALSE, FALSE, FALSE); - TEST_ASSERT(test_ret_value, p_graph != NULL, "graph creation failed."); + ret_code = cugraph_sg_graph_create(p_handle, + &properties, + src, + dst, + wgt, + FALSE, + FALSE, + FALSE, + &p_graph); + TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "graph creation failed."); cugraph_sg_graph_free(p_graph); From d68d4b82c489df0875046a6c04ea3de19215ef1b Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Tue, 26 Oct 2021 17:12:35 -0400 Subject: [PATCH 05/19] more documentation, some clang-format issues --- cpp/include/cugraph_c/array.h | 99 +++++++++++++++++++++++++++++++--- cpp/include/cugraph_c/graph.h | 10 ++-- cpp/tests/c_api/c_test_utils.h | 8 +-- 3 files changed, 102 insertions(+), 15 deletions(-) diff --git a/cpp/include/cugraph_c/array.h b/cpp/include/cugraph_c/array.h index 9a89697ecda..3dbf4932a07 100644 --- a/cpp/include/cugraph_c/array.h +++ b/cpp/include/cugraph_c/array.h @@ -30,31 +30,118 @@ typedef struct { int align_; } cugraph_type_erased_host_array_t; -cugraph_type_erased_device_array_t* cugraph_type_erased_device_array_create( - const cugraph_raft_handle_t* raft_handle, data_type_id_t dtype, size_t n_elems); +/** + * @brief Create a type erased device array + * + * @param [in] handle Handle for accessing resources + * @param [in] dtype The type of array to create + * @param [in] n_elems The number of elements in the array + * @param [out] array Pointer to the location to store the pointer to the device array + * @return error code + */ +cugraph_error_t cugraph_type_erased_device_array_create(const cugraph_raft_handle_t* handle, + data_type_id_t dtype, + size_t n_elems, + cugraph_type_erased_device_array_t** array); +/** + * @brief Destroy a type erased device array + * + * @param [in] p Pointer to the type erased device array + */ void cugraph_type_erased_device_array_free(cugraph_type_erased_device_array_t* p); +/** + * @brief Get the size of a type erased device array + * + * @param [in] p Pointer to the type erased device array + * @return The number of elements in the array + */ size_t cugraph_type_erased_device_array_size(const cugraph_type_erased_device_array_t* p); + +/** + * @brief Get the type of a type erased device array + * + * @param [in] p Pointer to the type erased device array + * @return The type of the elements in the array + */ data_type_id_t cugraph_type_erased_device_array_type(const cugraph_type_erased_device_array_t* p); + +/** + * @brief Get the raw pointer of the type erased device array + * + * @param [in] p Pointer to the type erased device array + * @return Pointer (device memory) for the data in the array + */ void* cugraph_type_erased_device_array_pointer(const cugraph_type_erased_device_array_t* p); -cugraph_type_erased_host_array_t* cugraph_type_erased_host_array_create( - const cugraph_raft_handle_t* raft_handle, data_type_id_t dtype, size_t n_elems); +/** + * @brief Create a type erased host array + * + * @param [in] handle Handle for accessing resources + * @param [in] dtype The type of array to create + * @param [in] n_elems The number of elements in the array + * @param [out] array Pointer to the location to store the pointer to the host array + */ +cugraph_error_t cugraph_type_erased_host_array_create(const cugraph_raft_handle_t* handle, + data_type_id_t dtype, + size_t n_elems, + cugraph_type_erased_host_array_t** array); +/** + * @brief Destroy a type erased host array + * + * @param [in] p Pointer to the type erased host array + */ void cugraph_type_erased_host_array_free(cugraph_type_erased_host_array_t* p); +/** + * @brief Get the size of a type erased host array + * + * @param [in] p Pointer to the type erased host array + * @return The number of elements in the array + */ size_t cugraph_type_erased_host_array_size(const cugraph_type_erased_host_array_t* p); + +/** + * @brief Get the type of a type erased host array + * + * @param [in] p Pointer to the type erased host array + * @return The type of the elements in the array + */ data_type_id_t cugraph_type_erased_host_array_type(const cugraph_type_erased_host_array_t* p); + +/** + * @brief Get the raw pointer of the type erased host array + * + * @param [in] p Pointer to the type erased host array + * @return Pointer (host memory) for the data in the array + */ void* cugraph_type_erased_host_array_pointer(const cugraph_type_erased_host_array_t* p); +/** + * @brief Copy data from host to a type erased device array + * + * @param [in] handle Handle for accessing resources + * @param [out] dst Pointer to the type erased device array + * @param [in] h_src Pointer to host array to copy into device memory + * @return error code + */ cugraph_error_t cugraph_type_erased_device_array_copy_from_host( - const cugraph_raft_handle_t* raft_handle, + const cugraph_raft_handle_t* handle, cugraph_type_erased_device_array_t* dst, const byte_t* h_src); +/** + * @brief Copy data from device to a type erased host array + * + * @param [in] handle Handle for accessing resources + * @param [out] h_dst Pointer to host array + * @param [in] src Pointer to the type erased device array to copy from + * @return error code + */ cugraph_error_t cugraph_type_erased_device_array_copy_to_host( - const cugraph_raft_handle_t* raft_handle, + const cugraph_raft_handle_t* handle, byte_t* h_dst, const cugraph_type_erased_device_array_t* src); diff --git a/cpp/include/cugraph_c/graph.h b/cpp/include/cugraph_c/graph.h index da6399a347e..c95f751ffd2 100644 --- a/cpp/include/cugraph_c/graph.h +++ b/cpp/include/cugraph_c/graph.h @@ -16,8 +16,8 @@ #pragma once -#include #include +#include #ifdef __cplusplus extern "C" { @@ -51,14 +51,14 @@ typedef struct { * @return error code */ cugraph_error_t cugraph_sg_graph_create(const cugraph_raft_handle_t* handle, - const cugraph_graph_properties_t *properties, + const cugraph_graph_properties_t* properties, const cugraph_type_erased_device_array_t* src, const cugraph_type_erased_device_array_t* dst, const cugraph_type_erased_device_array_t* weights, bool_t store_transposed, bool_t renumber, bool_t check, - cugraph_graph_t **graph); + cugraph_graph_t** graph); /** * @brief Destroy an SG graph @@ -91,7 +91,7 @@ void cugraph_sg_graph_free(cugraph_graph_t* graph); */ cugraph_error_t cugraph_mg_graph_create( const cugraph_raft_handle_t* handle, - const cugraph_graph_properties_t *properties, + const cugraph_graph_properties_t* properties, const cugraph_type_erased_device_array_t* src, const cugraph_type_erased_device_array_t* dst, const cugraph_type_erased_device_array_t* weights, @@ -101,7 +101,7 @@ cugraph_error_t cugraph_mg_graph_create( size_t num_vertices, size_t num_edges, bool_t check, - cugraph_graph_t **graph); + cugraph_graph_t** graph); /** * @brief Destroy an MG graph diff --git a/cpp/tests/c_api/c_test_utils.h b/cpp/tests/c_api/c_test_utils.h index 44765777a64..15d8ed6992b 100644 --- a/cpp/tests/c_api/c_test_utils.h +++ b/cpp/tests/c_api/c_test_utils.h @@ -17,11 +17,11 @@ #include #include -#define TEST_ASSERT(RETURN_VALUE, STATEMENT, MESSAGE) \ - { \ - (RETURN_VALUE) = !(STATEMENT); \ +#define TEST_ASSERT(RETURN_VALUE, STATEMENT, MESSAGE) \ + { \ + (RETURN_VALUE) = !(STATEMENT); \ if ((RETURN_VALUE)) { printf("ASSERTION FAILED: %s\n", (MESSAGE)); } \ - } + } /* * Runs the function pointed to by "test" and returns the return code. Also From 5c73f3a44a638fedf392e3f593004ee99dd0f9d9 Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Tue, 26 Oct 2021 18:01:01 -0400 Subject: [PATCH 06/19] rename cugraph_raft_handle_t to cugraph_handle_t --- cpp/CMakeLists.txt | 1 + cpp/include/cugraph_c/algorithms.h | 46 +++++++------- cpp/include/cugraph_c/array.h | 12 ++-- cpp/include/cugraph_c/cugraph_api.h | 27 ++++---- cpp/include/cugraph_c/graph.h | 4 +- cpp/src/c_api/array.cpp | 36 +++++++---- cpp/src/c_api/cugraph_api.cpp | 22 +++---- cpp/src/c_api/graph_mg.cpp | 2 +- cpp/src/c_api/graph_sg.cpp | 2 +- cpp/src/c_api/pagerank.cpp | 61 +++++++++++++++++++ cpp/tests/c_api/create_graph_test.c | 13 ++-- .../c_api/create_sg_graph_envelope_test.c | 4 +- cpp/tests/c_api/random_walks_test.c | 6 +- 13 files changed, 158 insertions(+), 78 deletions(-) create mode 100644 cpp/src/c_api/pagerank.cpp diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 00356b1ad4c..b5f5dcc0501 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -356,6 +356,7 @@ add_library(cugraph_c SHARED src/c_api/array.cpp src/c_api/graph_sg.cpp src/c_api/graph_mg.cpp + src/c_api/pagerank.cpp ) add_library(cugraph::cugraph_c ALIAS cugraph_c) diff --git a/cpp/include/cugraph_c/algorithms.h b/cpp/include/cugraph_c/algorithms.h index cc8f590c2da..fbf8fc52264 100644 --- a/cpp/include/cugraph_c/algorithms.h +++ b/cpp/include/cugraph_c/algorithms.h @@ -17,6 +17,7 @@ #pragma once #include +#include #ifdef __cplusplus extern "C" { @@ -27,8 +28,6 @@ extern "C" { * * @param [in] handle Handle for accessing resources * @param [in] graph Pointer to graph - * @param [out] vertex_ids Returns device pointer to vertex ids - * @param [out] pageranks Returns device pointer to pagerank scores * @param [in] precomputed_vertex_out_weight_sums * Optionally send in precomputed sume of vertex out weights * (a performance optimization). Set to NULL if @@ -43,26 +42,27 @@ extern "C" { * @p pageranks) is used as initial PageRank values. If false, initial PageRank values are set * to 1.0 divided by the number of vertices in the graph. * @param do_expensive_check A flag to run expensive checks for input arguments (if set to `true`). + * @param [out] vertex_ids Returns device pointer to vertex ids + * @param [out] pageranks Returns device pointer to pagerank scores + * @return error code */ cugraph_error_t pagerank( - const cugraph_raft_handle_t* handle, + const cugraph_handle_t* handle, const cugraph_graph_t* graph, - cugraph_type_erased_device_array_t** vertex_ids, - cugraph_type_erased_device_array_t** pageranks, const cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, double alpha, double epsilon, size_t max_iterations, bool has_initial_guess, - bool do_expensive_check); + bool do_expensive_check, + cugraph_type_erased_device_array_t** vertex_ids, + cugraph_type_erased_device_array_t** pageranks); /** * @brief Compute personalized pagerank * * @param [in] handle Handle for accessing resources * @param [in] graph Pointer to graph - * @param [out] vertex_ids Returns device pointer to vertex ids - * @param [out] pageranks Returns device pointer to pagerank scores * @param [in] precomputed_vertex_out_weight_sums * Optionally send in precomputed sume of vertex out weights * (a performance optimization). Set to NULL if @@ -81,12 +81,13 @@ cugraph_error_t pagerank( * @p pageranks) is used as initial PageRank values. If false, initial PageRank values are set * to 1.0 divided by the number of vertices in the graph. * @param do_expensive_check A flag to run expensive checks for input arguments (if set to `true`). + * @param [out] vertex_ids Returns device pointer to vertex ids + * @param [out] pageranks Returns device pointer to pagerank scores + * @return error code */ cugraph_error_t personalized_pagerank( - const cugraph_raft_handle_t* handle, + const cugraph_handle_t* handle, const cugraph_graph_t* graph, - cugraph_type_erased_device_array_t** vertex_ids, - cugraph_type_erased_device_array_t** pageranks, const cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, const cugraph_type_erased_device_array_t* personalization_vertices, const cugraph_type_erased_device_array_t* personalization_values, @@ -94,7 +95,9 @@ cugraph_error_t personalized_pagerank( double epsilon, size_t max_iterations, bool has_initial_guess, - bool do_expensive_check); + bool do_expensive_check, + cugraph_type_erased_device_array_t** vertex_ids, + cugraph_type_erased_device_array_t** pageranks); /** * @brief Perform a breadth first search from a set of seed vertices. @@ -105,9 +108,6 @@ cugraph_error_t personalized_pagerank( * * @param [in] handle Handle for accessing resources * @param [in] graph Pointer to graph - * @param [out] vertex_ids Returns device pointer to vertex ids - * @param [out] distances Returns device pointer to distance from the seeds - * @param [out] predecessors Returns device pointer to distance from the seeds * @param [in] sources Array of source vertices * @param [in] direction_optimizing If set to true, this algorithm switches between the push based * breadth-first search and pull based breadth-first search depending on the size of the @@ -116,16 +116,20 @@ cugraph_error_t personalized_pagerank( * @param depth_limit Sets the maximum number of breadth-first search iterations. Any vertices * farther than @p depth_limit hops from @p source_vertex will be marked as unreachable. * @param do_expensive_check A flag to run expensive checks for input arguments (if set to `true`). + * @param [out] vertex_ids Returns device pointer to vertex ids + * @param [out] distances Returns device pointer to distance from the seeds + * @param [out] predecessors Returns device pointer to distance from the seeds + * @return error code */ -cugraph_error_t bfs(const cugraph_raft_handle_t* handle, +cugraph_error_t bfs(const cugraph_handle_t* handle, const cugraph_graph_t* graph, - cugraph_type_erased_device_array_t** vertex_ids, - cugraph_type_erased_device_array_t** distances, - cugraph_type_erased_device_array_t** predecessors, const cugraph_type_erased_device_array_t* sources, bool direction_optimizing, - vertex_t depth_limit, - bool do_expensive_check); + size_t depth_limit, + bool do_expensive_check, + cugraph_type_erased_device_array_t** vertex_ids, + cugraph_type_erased_device_array_t** distances, + cugraph_type_erased_device_array_t** predecessors); #ifdef __cplusplus } diff --git a/cpp/include/cugraph_c/array.h b/cpp/include/cugraph_c/array.h index 3dbf4932a07..111dba4fec6 100644 --- a/cpp/include/cugraph_c/array.h +++ b/cpp/include/cugraph_c/array.h @@ -39,7 +39,7 @@ typedef struct { * @param [out] array Pointer to the location to store the pointer to the device array * @return error code */ -cugraph_error_t cugraph_type_erased_device_array_create(const cugraph_raft_handle_t* handle, +cugraph_error_t cugraph_type_erased_device_array_create(const cugraph_handle_t* handle, data_type_id_t dtype, size_t n_elems, cugraph_type_erased_device_array_t** array); @@ -83,7 +83,7 @@ void* cugraph_type_erased_device_array_pointer(const cugraph_type_erased_device_ * @param [in] n_elems The number of elements in the array * @param [out] array Pointer to the location to store the pointer to the host array */ -cugraph_error_t cugraph_type_erased_host_array_create(const cugraph_raft_handle_t* handle, +cugraph_error_t cugraph_type_erased_host_array_create(const cugraph_handle_t* handle, data_type_id_t dtype, size_t n_elems, cugraph_type_erased_host_array_t** array); @@ -128,9 +128,7 @@ void* cugraph_type_erased_host_array_pointer(const cugraph_type_erased_host_arra * @return error code */ cugraph_error_t cugraph_type_erased_device_array_copy_from_host( - const cugraph_raft_handle_t* handle, - cugraph_type_erased_device_array_t* dst, - const byte_t* h_src); + const cugraph_handle_t* handle, cugraph_type_erased_device_array_t* dst, const byte_t* h_src); /** * @brief Copy data from device to a type erased host array @@ -141,9 +139,7 @@ cugraph_error_t cugraph_type_erased_device_array_copy_from_host( * @return error code */ cugraph_error_t cugraph_type_erased_device_array_copy_to_host( - const cugraph_raft_handle_t* handle, - byte_t* h_dst, - const cugraph_type_erased_device_array_t* src); + const cugraph_handle_t* handle, byte_t* h_dst, const cugraph_type_erased_device_array_t* src); #ifdef __cplusplus } diff --git a/cpp/include/cugraph_c/cugraph_api.h b/cpp/include/cugraph_c/cugraph_api.h index 33ed1464c76..bef2b1a39d8 100644 --- a/cpp/include/cugraph_c/cugraph_api.h +++ b/cpp/include/cugraph_c/cugraph_api.h @@ -28,7 +28,8 @@ typedef enum cugraph_error_ { CUGRAPH_SUCCESS = 0, CUGRAPH_UNKNOWN_ERROR, CUGRAPH_INVALID_HANDLE, - CUGRAPH_ALLOC_ERROR + CUGRAPH_ALLOC_ERROR, + CUGRAPH_NOT_IMPLEMENTED } cugraph_error_t; typedef enum bool_ { FALSE = 0, TRUE = 1 } bool_t; @@ -42,16 +43,16 @@ extern int data_type_sz[]; /* C stub declarations */ -typedef struct cugraph_raft_handle_ { - int allign_; -} cugraph_raft_handle_t; +typedef struct cugraph_handle_ { + int align_; +} cugraph_handle_t; typedef struct cugraph_graph_envelope_ { - int allign_; + int align_; } cugraph_graph_envelope_t; typedef struct cugraph_erased_unique_ptr_ { - int allign_; + int align_; } cugraph_unique_ptr_t; typedef struct cugraph_device_buffer_ { @@ -117,7 +118,7 @@ cugraph_error_t extract_size_rw_result(cugraph_rw_ret_t* p_rw_ret, cugraph_device_buffer_t* p_d_buf_sz); /* algorithm wrapper*/ -cugraph_error_t cugraph_random_walks(const cugraph_raft_handle_t* ptr_handle, +cugraph_error_t cugraph_random_walks(const cugraph_handle_t* ptr_handle, cugraph_graph_envelope_t* ptr_graph_envelope, cugraph_device_buffer_t* ptr_d_start, size_t num_paths, @@ -127,7 +128,7 @@ cugraph_error_t cugraph_random_walks(const cugraph_raft_handle_t* ptr_handle, cugraph_rw_ret_t* ret); /* SG graph allocator*/ -cugraph_graph_envelope_t* cugraph_make_sg_graph(const cugraph_raft_handle_t* p_handle, +cugraph_graph_envelope_t* cugraph_make_sg_graph(const cugraph_handle_t* p_handle, data_type_id_t vertex_tid, data_type_id_t edge_tid, data_type_id_t weight_tid, @@ -145,7 +146,7 @@ cugraph_graph_envelope_t* cugraph_make_sg_graph(const cugraph_raft_handle_t* p_h void cugraph_free_graph(cugraph_graph_envelope_t* graph); /* rmm::device buffer allocator: fill pointer semantics*/ -cugraph_error_t cugraph_make_device_buffer(const cugraph_raft_handle_t* raft_handle, +cugraph_error_t cugraph_make_device_buffer(const cugraph_handle_t* handle, data_type_id_t dtype, size_t n_elems, cugraph_device_buffer_t* ptr_buffer); @@ -154,22 +155,22 @@ cugraph_error_t cugraph_make_device_buffer(const cugraph_raft_handle_t* raft_han void cugraph_free_device_buffer(cugraph_device_buffer_t* ptr_buffer); /* update dst device buffer from host src*/ -cugraph_error_t cugraph_update_device_buffer(const cugraph_raft_handle_t* raft_handle, +cugraph_error_t cugraph_update_device_buffer(const cugraph_handle_t* handle, data_type_id_t dtype, cugraph_device_buffer_t* ptr_dst, const byte_t* ptr_h_src); /* update src host buffer device src*/ -cugraph_error_t cugraph_update_host_buffer(const cugraph_raft_handle_t* raft_handle, +cugraph_error_t cugraph_update_host_buffer(const cugraph_handle_t* handle, data_type_id_t dtype, byte_t* ptr_h_dst, const cugraph_device_buffer_t* ptr_src); /* raft::handle_t allocator (for now; possibly a more encompassing handle in the future)*/ -cugraph_raft_handle_t* cugraph_create_handle(void); +cugraph_handle_t* cugraph_create_handle(void); /* raft::handle_t deallocator*/ -void cugraph_free_handle(cugraph_raft_handle_t* p_handle); +void cugraph_free_handle(cugraph_handle_t* p_handle); #ifdef __cplusplus } diff --git a/cpp/include/cugraph_c/graph.h b/cpp/include/cugraph_c/graph.h index c95f751ffd2..7d1dc856f7e 100644 --- a/cpp/include/cugraph_c/graph.h +++ b/cpp/include/cugraph_c/graph.h @@ -50,7 +50,7 @@ typedef struct { * * @return error code */ -cugraph_error_t cugraph_sg_graph_create(const cugraph_raft_handle_t* handle, +cugraph_error_t cugraph_sg_graph_create(const cugraph_handle_t* handle, const cugraph_graph_properties_t* properties, const cugraph_type_erased_device_array_t* src, const cugraph_type_erased_device_array_t* dst, @@ -90,7 +90,7 @@ void cugraph_sg_graph_free(cugraph_graph_t* graph); * @param [out] graph A pointer to the graph object */ cugraph_error_t cugraph_mg_graph_create( - const cugraph_raft_handle_t* handle, + const cugraph_handle_t* handle, const cugraph_graph_properties_t* properties, const cugraph_type_erased_device_array_t* src, const cugraph_type_erased_device_array_t* dst, diff --git a/cpp/src/c_api/array.cpp b/cpp/src/c_api/array.cpp index 0cff3bac7d9..5e3a4229052 100644 --- a/cpp/src/c_api/array.cpp +++ b/cpp/src/c_api/array.cpp @@ -38,13 +38,18 @@ typedef struct { } // namespace c_api -extern "C" cugraph_type_erased_device_array_t* cugraph_type_erased_device_array_create( - const cugraph_raft_handle_t* handle, data_type_id_t dtype, size_t n_elems) +extern "C" cugraph_error_t cugraph_type_erased_device_array_create( + const cugraph_handle_t* handle, + data_type_id_t dtype, + size_t n_elems, + cugraph_type_erased_device_array_t** array) { + *array = nullptr; + try { raft::handle_t const* raft_handle = reinterpret_cast(handle); - if (!raft_handle) return nullptr; + if (!raft_handle) return CUGRAPH_INVALID_HANDLE; size_t nbytes = n_elems * (::data_type_sz[dtype]); @@ -52,9 +57,10 @@ extern "C" cugraph_type_erased_device_array_t* cugraph_type_erased_device_array_ new c_api::cugraph_type_erased_device_array_t{ new rmm::device_buffer(nbytes, raft_handle->get_stream()), n_elems, nbytes, dtype}; - return reinterpret_cast(ret_value); + *array = reinterpret_cast(ret_value); + return CUGRAPH_SUCCESS; } catch (...) { - return nullptr; + return CUGRAPH_UNKNOWN_ERROR; } } @@ -85,22 +91,28 @@ extern "C" void* cugraph_type_erased_device_array_pointer( return internal_pointer->data_->data(); } -extern "C" cugraph_type_erased_host_array_t* cugraph_type_erased_host_array_create( - const cugraph_raft_handle_t* handle, data_type_id_t dtype, size_t n_elems) +extern "C" cugraph_error_t cugraph_type_erased_host_array_create( + const cugraph_handle_t* handle, + data_type_id_t dtype, + size_t n_elems, + cugraph_type_erased_host_array_t** array) { + *array = nullptr; + try { raft::handle_t const* raft_handle = reinterpret_cast(handle); - if (!raft_handle) return nullptr; + if (!raft_handle) return CUGRAPH_INVALID_HANDLE; size_t nbytes = n_elems * (::data_type_sz[dtype]); c_api::cugraph_type_erased_host_array_t* ret_value = new c_api::cugraph_type_erased_host_array_t{new uint8_t[nbytes], n_elems, nbytes, dtype}; - return reinterpret_cast(ret_value); + *array = reinterpret_cast(ret_value); + return CUGRAPH_SUCCESS; } catch (...) { - return nullptr; + return CUGRAPH_UNKNOWN_ERROR; } } @@ -131,7 +143,7 @@ extern "C" void* cugraph_type_erased_host_array_pointer(const cugraph_type_erase } extern "C" cugraph_error_t cugraph_type_erased_device_array_copy_from_host( - const cugraph_raft_handle_t* handle, cugraph_type_erased_device_array_t* dst, const byte_t* h_src) + const cugraph_handle_t* handle, cugraph_type_erased_device_array_t* dst, const byte_t* h_src) { try { raft::handle_t const* raft_handle = reinterpret_cast(handle); @@ -151,7 +163,7 @@ extern "C" cugraph_error_t cugraph_type_erased_device_array_copy_from_host( } extern "C" cugraph_error_t cugraph_type_erased_device_array_copy_to_host( - const cugraph_raft_handle_t* handle, byte_t* h_dst, const cugraph_type_erased_device_array_t* src) + const cugraph_handle_t* handle, byte_t* h_dst, const cugraph_type_erased_device_array_t* src) { try { raft::handle_t const* raft_handle = reinterpret_cast(handle); diff --git a/cpp/src/c_api/cugraph_api.cpp b/cpp/src/c_api/cugraph_api.cpp index 01c3882d0d5..689339e24cc 100644 --- a/cpp/src/c_api/cugraph_api.cpp +++ b/cpp/src/c_api/cugraph_api.cpp @@ -134,7 +134,7 @@ extern "C" cugraph_error_t extract_size_rw_result(cugraph_rw_ret_t* p_rw_ret, return helpers::extract_rw_result<2>(p_rw_ret, p_d_buf_sz); } -extern "C" cugraph_error_t cugraph_random_walks(const cugraph_raft_handle_t* ptr_handle, +extern "C" cugraph_error_t cugraph_random_walks(const cugraph_handle_t* ptr_handle, cugraph_graph_envelope_t* ptr_graph_envelope, cugraph_device_buffer_t* ptr_d_start, size_t num_paths, @@ -204,7 +204,7 @@ extern "C" cugraph_error_t cugraph_random_walks(const cugraph_raft_handle_t* ptr // graph factory: return pointer semantics (because it returns a stub); // -extern "C" cugraph_graph_envelope_t* cugraph_make_sg_graph(const cugraph_raft_handle_t* p_handle, +extern "C" cugraph_graph_envelope_t* cugraph_make_sg_graph(const cugraph_handle_t* p_handle, data_type_id_t vertex_tid, data_type_id_t edge_tid, data_type_id_t weight_tid, @@ -277,14 +277,14 @@ extern "C" void cugraph_free_graph(cugraph_graph_envelope_t* ptr_graph) // device buffer factory: fill pointer semantics (because the pointer is more than a stub); // -extern "C" cugraph_error_t cugraph_make_device_buffer(const cugraph_raft_handle_t* raft_handle, +extern "C" cugraph_error_t cugraph_make_device_buffer(const cugraph_handle_t* handle, data_type_id_t dtype, size_t n_elems, // ... of type `dtype` cugraph_device_buffer_t* ptr_buffer) { cugraph_error_t status = CUGRAPH_SUCCESS; try { - raft::handle_t const* p_raft_handle = reinterpret_cast(raft_handle); + raft::handle_t const* p_raft_handle = reinterpret_cast(handle); if (!p_raft_handle) return CUGRAPH_ALLOC_ERROR; @@ -304,7 +304,7 @@ extern "C" void cugraph_free_device_buffer(cugraph_device_buffer_t* ptr_buffer) delete ptr_rmm_d_buf; } -extern "C" cugraph_error_t cugraph_update_device_buffer(const cugraph_raft_handle_t* raft_handle, +extern "C" cugraph_error_t cugraph_update_device_buffer(const cugraph_handle_t* handle, data_type_id_t dtype, cugraph_device_buffer_t* ptr_dst, const byte_t* ptr_h_src) @@ -312,7 +312,7 @@ extern "C" cugraph_error_t cugraph_update_device_buffer(const cugraph_raft_handl cugraph_error_t status = CUGRAPH_SUCCESS; try { - raft::handle_t const* ptr_raft_handle = reinterpret_cast(raft_handle); + raft::handle_t const* ptr_raft_handle = reinterpret_cast(handle); if (!ptr_raft_handle) return CUGRAPH_ALLOC_ERROR; @@ -325,7 +325,7 @@ extern "C" cugraph_error_t cugraph_update_device_buffer(const cugraph_raft_handl return status; } -extern "C" cugraph_error_t cugraph_update_host_buffer(const cugraph_raft_handle_t* raft_handle, +extern "C" cugraph_error_t cugraph_update_host_buffer(const cugraph_handle_t* handle, data_type_id_t dtype, byte_t* ptr_h_dst, const cugraph_device_buffer_t* ptr_src) @@ -333,7 +333,7 @@ extern "C" cugraph_error_t cugraph_update_host_buffer(const cugraph_raft_handle_ cugraph_error_t status = CUGRAPH_SUCCESS; try { - raft::handle_t const* ptr_raft_handle = reinterpret_cast(raft_handle); + raft::handle_t const* ptr_raft_handle = reinterpret_cast(handle); if (!ptr_raft_handle) return CUGRAPH_ALLOC_ERROR; @@ -348,16 +348,16 @@ extern "C" cugraph_error_t cugraph_update_host_buffer(const cugraph_raft_handle_ return status; } -extern "C" cugraph_raft_handle_t* cugraph_create_handle(void) +extern "C" cugraph_handle_t* cugraph_create_handle(void) { try { - return reinterpret_cast(new raft::handle_t{}); + return reinterpret_cast(new raft::handle_t{}); } catch (...) { return nullptr; } } -extern "C" void cugraph_free_handle(cugraph_raft_handle_t* p_handle) +extern "C" void cugraph_free_handle(cugraph_handle_t* p_handle) { raft::handle_t* p_raft_handle = reinterpret_cast(p_handle); delete p_raft_handle; diff --git a/cpp/src/c_api/graph_mg.cpp b/cpp/src/c_api/graph_mg.cpp index c5ad2ee557e..737444b0741 100644 --- a/cpp/src/c_api/graph_mg.cpp +++ b/cpp/src/c_api/graph_mg.cpp @@ -17,7 +17,7 @@ #include extern "C" cugraph_error_t cugraph_mg_graph_create( - const cugraph_raft_handle_t* handle, + const cugraph_handle_t* handle, const cugraph_graph_properties_t* properties, const cugraph_type_erased_device_array_t* src, const cugraph_type_erased_device_array_t* dst, diff --git a/cpp/src/c_api/graph_sg.cpp b/cpp/src/c_api/graph_sg.cpp index ba4ab4563e7..07e108d516c 100644 --- a/cpp/src/c_api/graph_sg.cpp +++ b/cpp/src/c_api/graph_sg.cpp @@ -17,7 +17,7 @@ #include extern "C" cugraph_error_t cugraph_sg_graph_create( - const cugraph_raft_handle_t* handle, + const cugraph_handle_t* handle, const cugraph_graph_properties_t* properties, const cugraph_type_erased_device_array_t* src, const cugraph_type_erased_device_array_t* dst, diff --git a/cpp/src/c_api/pagerank.cpp b/cpp/src/c_api/pagerank.cpp new file mode 100644 index 00000000000..4860d568d11 --- /dev/null +++ b/cpp/src/c_api/pagerank.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2021, 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. + */ + +#include + +cugraph_error_t pagerank( + const cugraph_handle_t* handle, + const cugraph_graph_t* graph, + const cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, + double alpha, + double epsilon, + size_t max_iterations, + bool has_initial_guess, + bool do_expensive_check, + cugraph_type_erased_device_array_t** vertex_ids, + cugraph_type_erased_device_array_t** pageranks) +{ + // + // TODO: (all algorithms will have this + // basic construct, only defining here) + // 1) Adapt visitor implementation to handle cugraph_graph_t * + // instead of graph envelope + // 2) Create erased pack (or whatever is required) + // 3) Add calls here (as appropriate based on 1 and 2) to: + // a) if has_initial_guess, renumber the vertex_ids array + // and organize the pageranks accordingly + // b) cast graph as appropriate thing + // c) call visitor method for pagerank + // d) unrenumber result + return CUGRAPH_NOT_IMPLEMENTED; +} + +cugraph_error_t personalized_pagerank( + const cugraph_handle_t* handle, + const cugraph_graph_t* graph, + const cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, + const cugraph_type_erased_device_array_t* personalization_vertices, + const cugraph_type_erased_device_array_t* personalization_values, + double alpha, + double epsilon, + size_t max_iterations, + bool has_initial_guess, + bool do_expensive_check, + cugraph_type_erased_device_array_t** vertex_ids, + cugraph_type_erased_device_array_t** pageranks) +{ + return CUGRAPH_NOT_IMPLEMENTED; +} diff --git a/cpp/tests/c_api/create_graph_test.c b/cpp/tests/c_api/create_graph_test.c index 1bac68b51e9..926f981756e 100644 --- a/cpp/tests/c_api/create_graph_test.c +++ b/cpp/tests/c_api/create_graph_test.c @@ -38,7 +38,7 @@ int test_create_sg_graph_simple() vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; weight_t h_wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; - cugraph_raft_handle_t* p_handle = NULL; + cugraph_handle_t* p_handle = NULL; cugraph_graph_t* p_graph = NULL; cugraph_graph_properties_t properties; @@ -56,9 +56,14 @@ int test_create_sg_graph_simple() cugraph_type_erased_device_array_t* dst; cugraph_type_erased_device_array_t* wgt; - src = cugraph_type_erased_device_array_create(p_handle, vertex_tid, num_edges); - dst = cugraph_type_erased_device_array_create(p_handle, vertex_tid, num_edges); - wgt = cugraph_type_erased_device_array_create(p_handle, weight_tid, num_edges); + ret_code = cugraph_type_erased_device_array_create(p_handle, vertex_tid, num_edges, &src); + TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "src create failed."); + + ret_code = cugraph_type_erased_device_array_create(p_handle, vertex_tid, num_edges, &dst); + TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "dst create failed."); + + ret_code = cugraph_type_erased_device_array_create(p_handle, weight_tid, num_edges, &wgt); + TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "wgt create failed."); ret_code = cugraph_type_erased_device_array_copy_from_host(p_handle, src, (byte_t*)h_src); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "src copy_from_host failed."); diff --git a/cpp/tests/c_api/create_sg_graph_envelope_test.c b/cpp/tests/c_api/create_sg_graph_envelope_test.c index 2154f68cd07..e3cea393542 100644 --- a/cpp/tests/c_api/create_sg_graph_envelope_test.c +++ b/cpp/tests/c_api/create_sg_graph_envelope_test.c @@ -36,7 +36,7 @@ int test_create_sg_graph_simple() vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; weight_t h_wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; - cugraph_raft_handle_t* p_handle = NULL; + cugraph_handle_t* p_handle = NULL; cugraph_device_buffer_t dbuf_src; cugraph_device_buffer_t dbuf_dst; cugraph_device_buffer_t dbuf_wgt; @@ -114,7 +114,7 @@ int test_create_sg_graph_bad_arrays() int test_failed = 0; cugraph_graph_envelope_t* G = NULL; - cugraph_raft_handle_t handle; + cugraph_handle_t handle; cugraph_device_buffer_t* src_ptr = NULL; cugraph_device_buffer_t* dst_ptr = NULL; cugraph_device_buffer_t* weights_ptr = NULL; diff --git a/cpp/tests/c_api/random_walks_test.c b/cpp/tests/c_api/random_walks_test.c index caf22bdf1ec..9f253af998a 100644 --- a/cpp/tests/c_api/random_walks_test.c +++ b/cpp/tests/c_api/random_walks_test.c @@ -46,7 +46,7 @@ int test_random_walks_1() vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; weight_t h_wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; - cugraph_raft_handle_t* p_handle = NULL; + cugraph_handle_t* p_handle = NULL; cugraph_device_buffer_t dbuf_src; cugraph_device_buffer_t dbuf_dst; cugraph_device_buffer_t dbuf_wgt; @@ -199,7 +199,7 @@ int test_random_walks_2() vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; weight_t h_wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; - cugraph_raft_handle_t* p_handle = NULL; + cugraph_handle_t* p_handle = NULL; cugraph_device_buffer_t dbuf_src; cugraph_device_buffer_t dbuf_dst; cugraph_device_buffer_t dbuf_wgt; @@ -326,7 +326,7 @@ int test_random_walks_3() vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; weight_t h_wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; - cugraph_raft_handle_t* p_handle = NULL; + cugraph_handle_t* p_handle = NULL; cugraph_device_buffer_t dbuf_src; cugraph_device_buffer_t dbuf_dst; cugraph_device_buffer_t dbuf_wgt; From 61efaace7a4a2194d6bfb1492f54c0ee8b482f64 Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Wed, 27 Oct 2021 16:28:52 -0400 Subject: [PATCH 07/19] address PR review comments --- cpp/src/c_api/array.cpp | 4 ++-- cpp/src/c_api/bfs.cpp | 30 ++++++++++++++++++++++++++++++ cpp/src/c_api/graph_mg.cpp | 2 +- cpp/src/c_api/graph_sg.cpp | 2 +- 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 cpp/src/c_api/bfs.cpp diff --git a/cpp/src/c_api/array.cpp b/cpp/src/c_api/array.cpp index 5e3a4229052..8663efca988 100644 --- a/cpp/src/c_api/array.cpp +++ b/cpp/src/c_api/array.cpp @@ -30,7 +30,7 @@ typedef struct { } cugraph_type_erased_device_array_t; typedef struct { - uint8_t* data_; + std::byte* data_; size_t size_; size_t nbytes_; data_type_id_t type_; @@ -107,7 +107,7 @@ extern "C" cugraph_error_t cugraph_type_erased_host_array_create( size_t nbytes = n_elems * (::data_type_sz[dtype]); c_api::cugraph_type_erased_host_array_t* ret_value = - new c_api::cugraph_type_erased_host_array_t{new uint8_t[nbytes], n_elems, nbytes, dtype}; + new c_api::cugraph_type_erased_host_array_t{new std::byte[nbytes], n_elems, nbytes, dtype}; *array = reinterpret_cast(ret_value); return CUGRAPH_SUCCESS; diff --git a/cpp/src/c_api/bfs.cpp b/cpp/src/c_api/bfs.cpp new file mode 100644 index 00000000000..ee620b49f0c --- /dev/null +++ b/cpp/src/c_api/bfs.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021, 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. + */ + +#include + +cugraph_error_t bfs(const cugraph_handle_t* handle, + const cugraph_graph_t* graph, + const cugraph_type_erased_device_array_t* sources, + bool direction_optimizing, + size_t depth_limit, + bool do_expensive_check, + cugraph_type_erased_device_array_t** vertex_ids, + cugraph_type_erased_device_array_t** distances, + cugraph_type_erased_device_array_t** predecessors); +{ + return CUGRAPH_NOT_IMPLEMENTED; +} diff --git a/cpp/src/c_api/graph_mg.cpp b/cpp/src/c_api/graph_mg.cpp index 737444b0741..40426aad0ba 100644 --- a/cpp/src/c_api/graph_mg.cpp +++ b/cpp/src/c_api/graph_mg.cpp @@ -31,7 +31,7 @@ extern "C" cugraph_error_t cugraph_mg_graph_create( cugraph_graph_t** graph) { *graph = nullptr; - return CUGRAPH_UNKNOWN_ERROR; + return CUGRAPH_NOT_IMPLEMENTED; } extern "C" void cugraph_mg_graph_free(cugraph_graph_t* ptr_graph) {} diff --git a/cpp/src/c_api/graph_sg.cpp b/cpp/src/c_api/graph_sg.cpp index 07e108d516c..531669ca6db 100644 --- a/cpp/src/c_api/graph_sg.cpp +++ b/cpp/src/c_api/graph_sg.cpp @@ -28,7 +28,7 @@ extern "C" cugraph_error_t cugraph_sg_graph_create( cugraph_graph_t** graph) { *graph = nullptr; - return CUGRAPH_UNKNOWN_ERROR; + return CUGRAPH_NOT_IMPLEMENTED; } extern "C" void cugraph_sg_graph_free(cugraph_graph_t* ptr_graph) {} From 294921bb80fe7e7531b7f6191a05090bf732da8f Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Thu, 28 Oct 2021 15:48:13 -0400 Subject: [PATCH 08/19] make return structures for pagerank and bfs, clean up a few things --- cpp/include/cugraph_c/algorithms.h | 106 +++++++++++++++++++++++------ cpp/src/c_api/bfs.cpp | 58 +++++++++++++--- cpp/src/c_api/pagerank.cpp | 41 +++++++++-- 3 files changed, 170 insertions(+), 35 deletions(-) diff --git a/cpp/include/cugraph_c/algorithms.h b/cpp/include/cugraph_c/algorithms.h index fbf8fc52264..ecb0305d0f0 100644 --- a/cpp/include/cugraph_c/algorithms.h +++ b/cpp/include/cugraph_c/algorithms.h @@ -23,6 +23,38 @@ extern "C" { #endif +/** + * @brief Opaque pagerank result type + */ +typedef struct { + int align_; +} cugraph_pagerank_result_t; + +/** + * @brief Get the vertex ids from the pagerank result + * + * @param [in] result The result from pagerank + * @return type erased array of vertex ids + */ +cugraph_type_erased_device_array_t* cugraph_pagerank_result_get_vertices( + cugraph_pagerank_result_t* result); + +/** + * @brief Get the pagerank values from the pagerank result + * + * @param [in] result The result from pagerank + * @return type erased array of pagerank values + */ +cugraph_type_erased_device_array_t* cugraph_pagerank_result_get_pageranks( + cugraph_pagerank_result_t* result); + +/** + * @brief Free pagerank result + * + * @param [in] result The result from pagerank + */ +void cugraph_pagerank_result_free(cugraph_pagerank_result_t* result); + /** * @brief Compute pagerank * @@ -42,11 +74,10 @@ extern "C" { * @p pageranks) is used as initial PageRank values. If false, initial PageRank values are set * to 1.0 divided by the number of vertices in the graph. * @param do_expensive_check A flag to run expensive checks for input arguments (if set to `true`). - * @param [out] vertex_ids Returns device pointer to vertex ids - * @param [out] pageranks Returns device pointer to pagerank scores + * @param [out] result Opaque pointer to pagerank results * @return error code */ -cugraph_error_t pagerank( +cugraph_error_t cugraph_pagerank( const cugraph_handle_t* handle, const cugraph_graph_t* graph, const cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, @@ -55,8 +86,7 @@ cugraph_error_t pagerank( size_t max_iterations, bool has_initial_guess, bool do_expensive_check, - cugraph_type_erased_device_array_t** vertex_ids, - cugraph_type_erased_device_array_t** pageranks); + cugraph_pagerank_result_t** result); /** * @brief Compute personalized pagerank @@ -81,11 +111,10 @@ cugraph_error_t pagerank( * @p pageranks) is used as initial PageRank values. If false, initial PageRank values are set * to 1.0 divided by the number of vertices in the graph. * @param do_expensive_check A flag to run expensive checks for input arguments (if set to `true`). - * @param [out] vertex_ids Returns device pointer to vertex ids - * @param [out] pageranks Returns device pointer to pagerank scores + * @param [out] result Opaque pointer to pagerank results * @return error code */ -cugraph_error_t personalized_pagerank( +cugraph_error_t cugraph_personalized_pagerank( const cugraph_handle_t* handle, const cugraph_graph_t* graph, const cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, @@ -96,8 +125,48 @@ cugraph_error_t personalized_pagerank( size_t max_iterations, bool has_initial_guess, bool do_expensive_check, - cugraph_type_erased_device_array_t** vertex_ids, - cugraph_type_erased_device_array_t** pageranks); + cugraph_pagerank_result_t** result); + +/** + * @brief Opaque bfs result type + */ +typedef struct { + int align_; +} cugraph_bfs_result_t; + +/** + * @brief Get the vertex ids from the bfs result + * + * @param [in] result The result from bfs + * @return type erased array of vertex ids + */ +cugraph_type_erased_device_array_t* cugraph_bfs_result_get_vertices(cugraph_bfs_result_t* result); + +/** + * @brief Get the distances from the bfs result + * + * @param [in] result The result from bfs + * @return type erased array of distances + */ +cugraph_type_erased_device_array_t* cugraph_bfs_result_get_distances(cugraph_bfs_result_t* result); + +/** + * @brief Get the predecessors from the bfs result + * + * @param [in] result The result from bfs + * @return type erased array of predecessors. Value will be NULL if + * compute_predecessors was FALSE in the call to bfs that + * produced this result. + */ +cugraph_type_erased_device_array_t* cugraph_bfs_result_get_predecessors( + cugraph_bfs_result_t* result); + +/** + * @brief Free bfs result + * + * @param [in] result The result from bfs + */ +void cugraph_bfs_result_free(cugraph_bfs_result_t* result); /** * @brief Perform a breadth first search from a set of seed vertices. @@ -121,15 +190,14 @@ cugraph_error_t personalized_pagerank( * @param [out] predecessors Returns device pointer to distance from the seeds * @return error code */ -cugraph_error_t bfs(const cugraph_handle_t* handle, - const cugraph_graph_t* graph, - const cugraph_type_erased_device_array_t* sources, - bool direction_optimizing, - size_t depth_limit, - bool do_expensive_check, - cugraph_type_erased_device_array_t** vertex_ids, - cugraph_type_erased_device_array_t** distances, - cugraph_type_erased_device_array_t** predecessors); +cugraph_error_t cugraph_bfs(const cugraph_handle_t* handle, + const cugraph_graph_t* graph, + const cugraph_type_erased_device_array_t* sources, + bool direction_optimizing, + size_t depth_limit, + bool do_expensive_check, + bool compute_predecessors, + cugraph_bfs_result_t** result); #ifdef __cplusplus } diff --git a/cpp/src/c_api/bfs.cpp b/cpp/src/c_api/bfs.cpp index ee620b49f0c..4ba44e8a038 100644 --- a/cpp/src/c_api/bfs.cpp +++ b/cpp/src/c_api/bfs.cpp @@ -1,4 +1,4 @@ -/* +/const * * Copyright (c) 2021, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,15 +16,53 @@ #include -cugraph_error_t bfs(const cugraph_handle_t* handle, - const cugraph_graph_t* graph, - const cugraph_type_erased_device_array_t* sources, - bool direction_optimizing, - size_t depth_limit, - bool do_expensive_check, - cugraph_type_erased_device_array_t** vertex_ids, - cugraph_type_erased_device_array_t** distances, - cugraph_type_erased_device_array_t** predecessors); +namespace c_api { + +struct { + cugraph_type_erased_device_array_t* vertex_ids_; + cugraph_type_erased_device_array_t* distances_; + cugraph_type_erased_device_array_t* predecessors_; +} cugraph_bfs_result_t; + +} // namespace c_api + +extern "C" cugraph_type_erased_device_array_t* cugraph_bfs_result_get_vertices( + cugraph_bfs_result_t* result) +{ + auto internal_pointer = reinterpret_cast(p); + return internal_pointer->vertex_ids_; +} + +extern "C" cugraph_type_erased_device_array_t* cugraph_bfs_result_get_distances( + cugraph_bfs_result_t* result) +{ + auto internal_pointer = reinterpret_cast(p); + return internal_pointer->distances_; +} + +extern "C" cugraph_type_erased_device_array_t* cugraph_bfs_result_get_predecessors( + cugraph_bfs_result_t* result) +{ + auto internal_pointer = reinterpret_cast(p); + return internal_pointer->predecessors_; +} + +extern "C" void cugraph_bfs_result_free(cugraph_bfs_result_t* result) +{ + auto internal_pointer = reinterpret_cast(p); + delete internal_pointer->vertex_ids_; + delete internal_pointer->distances_; + delete internal_pointer->predecessors_; + delete internal_pointer_; +} + +extern "C" cugraph_error_t cugraph_bfs(const cugraph_handle_t* handle, + const cugraph_graph_t* graph, + const cugraph_type_erased_device_array_t* sources, + bool direction_optimizing, + size_t depth_limit, + bool do_expensive_check, + cugraph_bfs_result_t** result) { return CUGRAPH_NOT_IMPLEMENTED; } diff --git a/cpp/src/c_api/pagerank.cpp b/cpp/src/c_api/pagerank.cpp index 4860d568d11..07edb813709 100644 --- a/cpp/src/c_api/pagerank.cpp +++ b/cpp/src/c_api/pagerank.cpp @@ -16,7 +16,38 @@ #include -cugraph_error_t pagerank( +namespace c_api { + +struct cugraph_pagerank_result_t { + cugraph_type_erased_device_array_t* vertex_ids_; + cugraph_type_erased_device_array_t* pageranks_; +}; + +} // namespace c_api + +extern "C" cugraph_type_erased_device_array_t* cugraph_pagerank_result_get_vertices( + cugraph_pagerank_result_t* result) +{ + auto internal_pointer = reinterpret_cast(result); + return internal_pointer->vertex_ids_; +} + +extern "C" cugraph_type_erased_device_array_t* cugraph_pagerank_result_get_pageranks( + cugraph_pagerank_result_t* result) +{ + auto internal_pointer = reinterpret_cast(result); + return internal_pointer->pageranks_; +} + +extern "C" void cugraph_pagerank_result_free(cugraph_pagerank_result_t* result) +{ + auto internal_pointer = reinterpret_cast(result); + delete internal_pointer->vertex_ids_; + delete internal_pointer->pageranks_; + delete internal_pointer; +} + +extern "C" cugraph_error_t compute_pagerank( const cugraph_handle_t* handle, const cugraph_graph_t* graph, const cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, @@ -25,8 +56,7 @@ cugraph_error_t pagerank( size_t max_iterations, bool has_initial_guess, bool do_expensive_check, - cugraph_type_erased_device_array_t** vertex_ids, - cugraph_type_erased_device_array_t** pageranks) + cugraph_pagerank_result_t** result) { // // TODO: (all algorithms will have this @@ -43,7 +73,7 @@ cugraph_error_t pagerank( return CUGRAPH_NOT_IMPLEMENTED; } -cugraph_error_t personalized_pagerank( +extern "C" cugraph_error_t cugraph_personalized_pagerank( const cugraph_handle_t* handle, const cugraph_graph_t* graph, const cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, @@ -54,8 +84,7 @@ cugraph_error_t personalized_pagerank( size_t max_iterations, bool has_initial_guess, bool do_expensive_check, - cugraph_type_erased_device_array_t** vertex_ids, - cugraph_type_erased_device_array_t** pageranks) + cugraph_pagerank_result_t** result) { return CUGRAPH_NOT_IMPLEMENTED; } From 8869b8058c4cfb3ef82842d5881c9bf44b35d9ac Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Thu, 28 Oct 2021 20:21:11 -0400 Subject: [PATCH 09/19] fix clang-format issues --- cpp/src/c_api/bfs.cpp | 94 +++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 48 deletions(-) diff --git a/cpp/src/c_api/bfs.cpp b/cpp/src/c_api/bfs.cpp index 4ba44e8a038..cc139aea617 100644 --- a/cpp/src/c_api/bfs.cpp +++ b/cpp/src/c_api/bfs.cpp @@ -1,7 +1,5 @@ -/const * - * Copyright (c) 2021, NVIDIA CORPORATION. - * - * Licensed under the Apache License, Version 2.0 (the "License"); +/ const **Copyright(c) 2021, 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 * @@ -16,53 +14,53 @@ #include -namespace c_api { - -struct { - cugraph_type_erased_device_array_t* vertex_ids_; - cugraph_type_erased_device_array_t* distances_; - cugraph_type_erased_device_array_t* predecessors_; -} cugraph_bfs_result_t; +namespace c_api + { + struct { + cugraph_type_erased_device_array_t* vertex_ids_; + cugraph_type_erased_device_array_t* distances_; + cugraph_type_erased_device_array_t* predecessors_; + } cugraph_bfs_result_t; -} // namespace c_api + } // namespace c_api -extern "C" cugraph_type_erased_device_array_t* cugraph_bfs_result_get_vertices( - cugraph_bfs_result_t* result) -{ - auto internal_pointer = reinterpret_cast(p); - return internal_pointer->vertex_ids_; -} + extern "C" cugraph_type_erased_device_array_t* cugraph_bfs_result_get_vertices( + cugraph_bfs_result_t* result) + { + auto internal_pointer = reinterpret_cast(p); + return internal_pointer->vertex_ids_; + } -extern "C" cugraph_type_erased_device_array_t* cugraph_bfs_result_get_distances( - cugraph_bfs_result_t* result) -{ - auto internal_pointer = reinterpret_cast(p); - return internal_pointer->distances_; -} + extern "C" cugraph_type_erased_device_array_t* cugraph_bfs_result_get_distances( + cugraph_bfs_result_t* result) + { + auto internal_pointer = reinterpret_cast(p); + return internal_pointer->distances_; + } -extern "C" cugraph_type_erased_device_array_t* cugraph_bfs_result_get_predecessors( - cugraph_bfs_result_t* result) -{ - auto internal_pointer = reinterpret_cast(p); - return internal_pointer->predecessors_; -} + extern "C" cugraph_type_erased_device_array_t* cugraph_bfs_result_get_predecessors( + cugraph_bfs_result_t* result) + { + auto internal_pointer = reinterpret_cast(p); + return internal_pointer->predecessors_; + } -extern "C" void cugraph_bfs_result_free(cugraph_bfs_result_t* result) -{ - auto internal_pointer = reinterpret_cast(p); - delete internal_pointer->vertex_ids_; - delete internal_pointer->distances_; - delete internal_pointer->predecessors_; - delete internal_pointer_; -} + extern "C" void cugraph_bfs_result_free(cugraph_bfs_result_t* result) + { + auto internal_pointer = reinterpret_cast(p); + delete internal_pointer->vertex_ids_; + delete internal_pointer->distances_; + delete internal_pointer->predecessors_; + delete internal_pointer_; + } -extern "C" cugraph_error_t cugraph_bfs(const cugraph_handle_t* handle, - const cugraph_graph_t* graph, - const cugraph_type_erased_device_array_t* sources, - bool direction_optimizing, - size_t depth_limit, - bool do_expensive_check, - cugraph_bfs_result_t** result) -{ - return CUGRAPH_NOT_IMPLEMENTED; -} + extern "C" cugraph_error_t cugraph_bfs(const cugraph_handle_t* handle, + const cugraph_graph_t* graph, + const cugraph_type_erased_device_array_t* sources, + bool direction_optimizing, + size_t depth_limit, + bool do_expensive_check, + cugraph_bfs_result_t** result) + { + return CUGRAPH_NOT_IMPLEMENTED; + } From 3cbc0e2eeb8fd64c1859abdc16e29c4b572efcaf Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Fri, 29 Oct 2021 10:17:10 -0400 Subject: [PATCH 10/19] somehow mangled the copyright header in the last commit --- cpp/src/c_api/bfs.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cpp/src/c_api/bfs.cpp b/cpp/src/c_api/bfs.cpp index cc139aea617..5acc6374c50 100644 --- a/cpp/src/c_api/bfs.cpp +++ b/cpp/src/c_api/bfs.cpp @@ -1,5 +1,7 @@ -/ const **Copyright(c) 2021, NVIDIA CORPORATION.**Licensed under the Apache License, - Version 2.0(the "License"); +/* + * Copyright (c) 2021, 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 * From b829cfda59953bbd48def579e345ee7ac6d76503 Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Fri, 29 Oct 2021 10:23:17 -0400 Subject: [PATCH 11/19] fix clang-format issues --- cpp/src/c_api/bfs.cpp | 87 +++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/cpp/src/c_api/bfs.cpp b/cpp/src/c_api/bfs.cpp index 5acc6374c50..5d7e111bf76 100644 --- a/cpp/src/c_api/bfs.cpp +++ b/cpp/src/c_api/bfs.cpp @@ -16,53 +16,52 @@ #include -namespace c_api - { - struct { - cugraph_type_erased_device_array_t* vertex_ids_; - cugraph_type_erased_device_array_t* distances_; - cugraph_type_erased_device_array_t* predecessors_; - } cugraph_bfs_result_t; +namespace c_api { +struct { + cugraph_type_erased_device_array_t* vertex_ids_; + cugraph_type_erased_device_array_t* distances_; + cugraph_type_erased_device_array_t* predecessors_; +} cugraph_bfs_result_t; - } // namespace c_api +} // namespace c_api - extern "C" cugraph_type_erased_device_array_t* cugraph_bfs_result_get_vertices( - cugraph_bfs_result_t* result) - { - auto internal_pointer = reinterpret_cast(p); - return internal_pointer->vertex_ids_; - } +extern "C" cugraph_type_erased_device_array_t* cugraph_bfs_result_get_vertices( + cugraph_bfs_result_t* result) +{ + auto internal_pointer = reinterpret_cast(p); + return internal_pointer->vertex_ids_; +} - extern "C" cugraph_type_erased_device_array_t* cugraph_bfs_result_get_distances( - cugraph_bfs_result_t* result) - { - auto internal_pointer = reinterpret_cast(p); - return internal_pointer->distances_; - } +extern "C" cugraph_type_erased_device_array_t* cugraph_bfs_result_get_distances( + cugraph_bfs_result_t* result) +{ + auto internal_pointer = reinterpret_cast(p); + return internal_pointer->distances_; +} - extern "C" cugraph_type_erased_device_array_t* cugraph_bfs_result_get_predecessors( - cugraph_bfs_result_t* result) - { - auto internal_pointer = reinterpret_cast(p); - return internal_pointer->predecessors_; - } +extern "C" cugraph_type_erased_device_array_t* cugraph_bfs_result_get_predecessors( + cugraph_bfs_result_t* result) +{ + auto internal_pointer = reinterpret_cast(p); + return internal_pointer->predecessors_; +} - extern "C" void cugraph_bfs_result_free(cugraph_bfs_result_t* result) - { - auto internal_pointer = reinterpret_cast(p); - delete internal_pointer->vertex_ids_; - delete internal_pointer->distances_; - delete internal_pointer->predecessors_; - delete internal_pointer_; - } +extern "C" void cugraph_bfs_result_free(cugraph_bfs_result_t* result) +{ + auto internal_pointer = reinterpret_cast(p); + delete internal_pointer->vertex_ids_; + delete internal_pointer->distances_; + delete internal_pointer->predecessors_; + delete internal_pointer_; +} - extern "C" cugraph_error_t cugraph_bfs(const cugraph_handle_t* handle, - const cugraph_graph_t* graph, - const cugraph_type_erased_device_array_t* sources, - bool direction_optimizing, - size_t depth_limit, - bool do_expensive_check, - cugraph_bfs_result_t** result) - { - return CUGRAPH_NOT_IMPLEMENTED; - } +extern "C" cugraph_error_t cugraph_bfs(const cugraph_handle_t* handle, + const cugraph_graph_t* graph, + const cugraph_type_erased_device_array_t* sources, + bool direction_optimizing, + size_t depth_limit, + bool do_expensive_check, + cugraph_bfs_result_t** result) +{ + return CUGRAPH_NOT_IMPLEMENTED; +} From d1dcdd7886ccf0ef8bd7ef1d3822541159268ac9 Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Tue, 2 Nov 2021 11:08:06 -0400 Subject: [PATCH 12/19] change cugraph_handle_t to cugraph_resource_handle_t --- cpp/include/cugraph_c/algorithms.h | 6 +++--- cpp/include/cugraph_c/array.h | 8 ++++---- cpp/include/cugraph_c/cugraph_api.h | 18 +++++++++--------- cpp/include/cugraph_c/graph.h | 4 ++-- cpp/src/c_api/array.cpp | 8 ++++---- cpp/src/c_api/bfs.cpp | 2 +- cpp/src/c_api/cugraph_api.cpp | 16 ++++++++-------- cpp/src/c_api/graph_mg.cpp | 2 +- cpp/src/c_api/graph_sg.cpp | 2 +- cpp/src/c_api/pagerank.cpp | 4 ++-- cpp/tests/c_api/create_graph_test.c | 2 +- .../c_api/create_sg_graph_envelope_test.c | 4 ++-- cpp/tests/c_api/random_walks_test.c | 6 +++--- 13 files changed, 41 insertions(+), 41 deletions(-) diff --git a/cpp/include/cugraph_c/algorithms.h b/cpp/include/cugraph_c/algorithms.h index ecb0305d0f0..91760a11323 100644 --- a/cpp/include/cugraph_c/algorithms.h +++ b/cpp/include/cugraph_c/algorithms.h @@ -78,7 +78,7 @@ void cugraph_pagerank_result_free(cugraph_pagerank_result_t* result); * @return error code */ cugraph_error_t cugraph_pagerank( - const cugraph_handle_t* handle, + const cugraph_resource_handle_t* handle, const cugraph_graph_t* graph, const cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, double alpha, @@ -115,7 +115,7 @@ cugraph_error_t cugraph_pagerank( * @return error code */ cugraph_error_t cugraph_personalized_pagerank( - const cugraph_handle_t* handle, + const cugraph_resource_handle_t* handle, const cugraph_graph_t* graph, const cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, const cugraph_type_erased_device_array_t* personalization_vertices, @@ -190,7 +190,7 @@ void cugraph_bfs_result_free(cugraph_bfs_result_t* result); * @param [out] predecessors Returns device pointer to distance from the seeds * @return error code */ -cugraph_error_t cugraph_bfs(const cugraph_handle_t* handle, +cugraph_error_t cugraph_bfs(const cugraph_resource_handle_t* handle, const cugraph_graph_t* graph, const cugraph_type_erased_device_array_t* sources, bool direction_optimizing, diff --git a/cpp/include/cugraph_c/array.h b/cpp/include/cugraph_c/array.h index 111dba4fec6..238e28e71ca 100644 --- a/cpp/include/cugraph_c/array.h +++ b/cpp/include/cugraph_c/array.h @@ -39,7 +39,7 @@ typedef struct { * @param [out] array Pointer to the location to store the pointer to the device array * @return error code */ -cugraph_error_t cugraph_type_erased_device_array_create(const cugraph_handle_t* handle, +cugraph_error_t cugraph_type_erased_device_array_create(const cugraph_resource_handle_t* handle, data_type_id_t dtype, size_t n_elems, cugraph_type_erased_device_array_t** array); @@ -83,7 +83,7 @@ void* cugraph_type_erased_device_array_pointer(const cugraph_type_erased_device_ * @param [in] n_elems The number of elements in the array * @param [out] array Pointer to the location to store the pointer to the host array */ -cugraph_error_t cugraph_type_erased_host_array_create(const cugraph_handle_t* handle, +cugraph_error_t cugraph_type_erased_host_array_create(const cugraph_resource_handle_t* handle, data_type_id_t dtype, size_t n_elems, cugraph_type_erased_host_array_t** array); @@ -128,7 +128,7 @@ void* cugraph_type_erased_host_array_pointer(const cugraph_type_erased_host_arra * @return error code */ cugraph_error_t cugraph_type_erased_device_array_copy_from_host( - const cugraph_handle_t* handle, cugraph_type_erased_device_array_t* dst, const byte_t* h_src); + const cugraph_resource_handle_t* handle, cugraph_type_erased_device_array_t* dst, const byte_t* h_src); /** * @brief Copy data from device to a type erased host array @@ -139,7 +139,7 @@ cugraph_error_t cugraph_type_erased_device_array_copy_from_host( * @return error code */ cugraph_error_t cugraph_type_erased_device_array_copy_to_host( - const cugraph_handle_t* handle, byte_t* h_dst, const cugraph_type_erased_device_array_t* src); + const cugraph_resource_handle_t* handle, byte_t* h_dst, const cugraph_type_erased_device_array_t* src); #ifdef __cplusplus } diff --git a/cpp/include/cugraph_c/cugraph_api.h b/cpp/include/cugraph_c/cugraph_api.h index bef2b1a39d8..2648a97eed5 100644 --- a/cpp/include/cugraph_c/cugraph_api.h +++ b/cpp/include/cugraph_c/cugraph_api.h @@ -43,9 +43,9 @@ extern int data_type_sz[]; /* C stub declarations */ -typedef struct cugraph_handle_ { +typedef struct cugraph_resource_handle_ { int align_; -} cugraph_handle_t; +} cugraph_resource_handle_t; typedef struct cugraph_graph_envelope_ { int align_; @@ -118,7 +118,7 @@ cugraph_error_t extract_size_rw_result(cugraph_rw_ret_t* p_rw_ret, cugraph_device_buffer_t* p_d_buf_sz); /* algorithm wrapper*/ -cugraph_error_t cugraph_random_walks(const cugraph_handle_t* ptr_handle, +cugraph_error_t cugraph_random_walks(const cugraph_resource_handle_t* ptr_handle, cugraph_graph_envelope_t* ptr_graph_envelope, cugraph_device_buffer_t* ptr_d_start, size_t num_paths, @@ -128,7 +128,7 @@ cugraph_error_t cugraph_random_walks(const cugraph_handle_t* ptr_handle, cugraph_rw_ret_t* ret); /* SG graph allocator*/ -cugraph_graph_envelope_t* cugraph_make_sg_graph(const cugraph_handle_t* p_handle, +cugraph_graph_envelope_t* cugraph_make_sg_graph(const cugraph_resource_handle_t* p_handle, data_type_id_t vertex_tid, data_type_id_t edge_tid, data_type_id_t weight_tid, @@ -146,7 +146,7 @@ cugraph_graph_envelope_t* cugraph_make_sg_graph(const cugraph_handle_t* p_handle void cugraph_free_graph(cugraph_graph_envelope_t* graph); /* rmm::device buffer allocator: fill pointer semantics*/ -cugraph_error_t cugraph_make_device_buffer(const cugraph_handle_t* handle, +cugraph_error_t cugraph_make_device_buffer(const cugraph_resource_handle_t* handle, data_type_id_t dtype, size_t n_elems, cugraph_device_buffer_t* ptr_buffer); @@ -155,22 +155,22 @@ cugraph_error_t cugraph_make_device_buffer(const cugraph_handle_t* handle, void cugraph_free_device_buffer(cugraph_device_buffer_t* ptr_buffer); /* update dst device buffer from host src*/ -cugraph_error_t cugraph_update_device_buffer(const cugraph_handle_t* handle, +cugraph_error_t cugraph_update_device_buffer(const cugraph_resource_handle_t* handle, data_type_id_t dtype, cugraph_device_buffer_t* ptr_dst, const byte_t* ptr_h_src); /* update src host buffer device src*/ -cugraph_error_t cugraph_update_host_buffer(const cugraph_handle_t* handle, +cugraph_error_t cugraph_update_host_buffer(const cugraph_resource_handle_t* handle, data_type_id_t dtype, byte_t* ptr_h_dst, const cugraph_device_buffer_t* ptr_src); /* raft::handle_t allocator (for now; possibly a more encompassing handle in the future)*/ -cugraph_handle_t* cugraph_create_handle(void); +cugraph_resource_handle_t* cugraph_create_handle(void); /* raft::handle_t deallocator*/ -void cugraph_free_handle(cugraph_handle_t* p_handle); +void cugraph_free_handle(cugraph_resource_handle_t* p_handle); #ifdef __cplusplus } diff --git a/cpp/include/cugraph_c/graph.h b/cpp/include/cugraph_c/graph.h index 7d1dc856f7e..503af1b7777 100644 --- a/cpp/include/cugraph_c/graph.h +++ b/cpp/include/cugraph_c/graph.h @@ -50,7 +50,7 @@ typedef struct { * * @return error code */ -cugraph_error_t cugraph_sg_graph_create(const cugraph_handle_t* handle, +cugraph_error_t cugraph_sg_graph_create(const cugraph_resource_handle_t* handle, const cugraph_graph_properties_t* properties, const cugraph_type_erased_device_array_t* src, const cugraph_type_erased_device_array_t* dst, @@ -90,7 +90,7 @@ void cugraph_sg_graph_free(cugraph_graph_t* graph); * @param [out] graph A pointer to the graph object */ cugraph_error_t cugraph_mg_graph_create( - const cugraph_handle_t* handle, + const cugraph_resource_handle_t* handle, const cugraph_graph_properties_t* properties, const cugraph_type_erased_device_array_t* src, const cugraph_type_erased_device_array_t* dst, diff --git a/cpp/src/c_api/array.cpp b/cpp/src/c_api/array.cpp index 8663efca988..854b8ef29df 100644 --- a/cpp/src/c_api/array.cpp +++ b/cpp/src/c_api/array.cpp @@ -39,7 +39,7 @@ typedef struct { } // namespace c_api extern "C" cugraph_error_t cugraph_type_erased_device_array_create( - const cugraph_handle_t* handle, + const cugraph_resource_handle_t* handle, data_type_id_t dtype, size_t n_elems, cugraph_type_erased_device_array_t** array) @@ -92,7 +92,7 @@ extern "C" void* cugraph_type_erased_device_array_pointer( } extern "C" cugraph_error_t cugraph_type_erased_host_array_create( - const cugraph_handle_t* handle, + const cugraph_resource_handle_t* handle, data_type_id_t dtype, size_t n_elems, cugraph_type_erased_host_array_t** array) @@ -143,7 +143,7 @@ extern "C" void* cugraph_type_erased_host_array_pointer(const cugraph_type_erase } extern "C" cugraph_error_t cugraph_type_erased_device_array_copy_from_host( - const cugraph_handle_t* handle, cugraph_type_erased_device_array_t* dst, const byte_t* h_src) + const cugraph_resource_handle_t* handle, cugraph_type_erased_device_array_t* dst, const byte_t* h_src) { try { raft::handle_t const* raft_handle = reinterpret_cast(handle); @@ -163,7 +163,7 @@ extern "C" cugraph_error_t cugraph_type_erased_device_array_copy_from_host( } extern "C" cugraph_error_t cugraph_type_erased_device_array_copy_to_host( - const cugraph_handle_t* handle, byte_t* h_dst, const cugraph_type_erased_device_array_t* src) + const cugraph_resource_handle_t* handle, byte_t* h_dst, const cugraph_type_erased_device_array_t* src) { try { raft::handle_t const* raft_handle = reinterpret_cast(handle); diff --git a/cpp/src/c_api/bfs.cpp b/cpp/src/c_api/bfs.cpp index 5d7e111bf76..535a08333cf 100644 --- a/cpp/src/c_api/bfs.cpp +++ b/cpp/src/c_api/bfs.cpp @@ -55,7 +55,7 @@ extern "C" void cugraph_bfs_result_free(cugraph_bfs_result_t* result) delete internal_pointer_; } -extern "C" cugraph_error_t cugraph_bfs(const cugraph_handle_t* handle, +extern "C" cugraph_error_t cugraph_bfs(const cugraph_resource_handle_t* handle, const cugraph_graph_t* graph, const cugraph_type_erased_device_array_t* sources, bool direction_optimizing, diff --git a/cpp/src/c_api/cugraph_api.cpp b/cpp/src/c_api/cugraph_api.cpp index 689339e24cc..fb8204c4938 100644 --- a/cpp/src/c_api/cugraph_api.cpp +++ b/cpp/src/c_api/cugraph_api.cpp @@ -134,7 +134,7 @@ extern "C" cugraph_error_t extract_size_rw_result(cugraph_rw_ret_t* p_rw_ret, return helpers::extract_rw_result<2>(p_rw_ret, p_d_buf_sz); } -extern "C" cugraph_error_t cugraph_random_walks(const cugraph_handle_t* ptr_handle, +extern "C" cugraph_error_t cugraph_random_walks(const cugraph_resource_handle_t* ptr_handle, cugraph_graph_envelope_t* ptr_graph_envelope, cugraph_device_buffer_t* ptr_d_start, size_t num_paths, @@ -204,7 +204,7 @@ extern "C" cugraph_error_t cugraph_random_walks(const cugraph_handle_t* ptr_hand // graph factory: return pointer semantics (because it returns a stub); // -extern "C" cugraph_graph_envelope_t* cugraph_make_sg_graph(const cugraph_handle_t* p_handle, +extern "C" cugraph_graph_envelope_t* cugraph_make_sg_graph(const cugraph_resource_handle_t* p_handle, data_type_id_t vertex_tid, data_type_id_t edge_tid, data_type_id_t weight_tid, @@ -277,7 +277,7 @@ extern "C" void cugraph_free_graph(cugraph_graph_envelope_t* ptr_graph) // device buffer factory: fill pointer semantics (because the pointer is more than a stub); // -extern "C" cugraph_error_t cugraph_make_device_buffer(const cugraph_handle_t* handle, +extern "C" cugraph_error_t cugraph_make_device_buffer(const cugraph_resource_handle_t* handle, data_type_id_t dtype, size_t n_elems, // ... of type `dtype` cugraph_device_buffer_t* ptr_buffer) @@ -304,7 +304,7 @@ extern "C" void cugraph_free_device_buffer(cugraph_device_buffer_t* ptr_buffer) delete ptr_rmm_d_buf; } -extern "C" cugraph_error_t cugraph_update_device_buffer(const cugraph_handle_t* handle, +extern "C" cugraph_error_t cugraph_update_device_buffer(const cugraph_resource_handle_t* handle, data_type_id_t dtype, cugraph_device_buffer_t* ptr_dst, const byte_t* ptr_h_src) @@ -325,7 +325,7 @@ extern "C" cugraph_error_t cugraph_update_device_buffer(const cugraph_handle_t* return status; } -extern "C" cugraph_error_t cugraph_update_host_buffer(const cugraph_handle_t* handle, +extern "C" cugraph_error_t cugraph_update_host_buffer(const cugraph_resource_handle_t* handle, data_type_id_t dtype, byte_t* ptr_h_dst, const cugraph_device_buffer_t* ptr_src) @@ -348,16 +348,16 @@ extern "C" cugraph_error_t cugraph_update_host_buffer(const cugraph_handle_t* ha return status; } -extern "C" cugraph_handle_t* cugraph_create_handle(void) +extern "C" cugraph_resource_handle_t* cugraph_create_handle(void) { try { - return reinterpret_cast(new raft::handle_t{}); + return reinterpret_cast(new raft::handle_t{}); } catch (...) { return nullptr; } } -extern "C" void cugraph_free_handle(cugraph_handle_t* p_handle) +extern "C" void cugraph_free_handle(cugraph_resource_handle_t* p_handle) { raft::handle_t* p_raft_handle = reinterpret_cast(p_handle); delete p_raft_handle; diff --git a/cpp/src/c_api/graph_mg.cpp b/cpp/src/c_api/graph_mg.cpp index 40426aad0ba..48695333ded 100644 --- a/cpp/src/c_api/graph_mg.cpp +++ b/cpp/src/c_api/graph_mg.cpp @@ -17,7 +17,7 @@ #include extern "C" cugraph_error_t cugraph_mg_graph_create( - const cugraph_handle_t* handle, + const cugraph_resource_handle_t* handle, const cugraph_graph_properties_t* properties, const cugraph_type_erased_device_array_t* src, const cugraph_type_erased_device_array_t* dst, diff --git a/cpp/src/c_api/graph_sg.cpp b/cpp/src/c_api/graph_sg.cpp index 531669ca6db..18f11acfc9d 100644 --- a/cpp/src/c_api/graph_sg.cpp +++ b/cpp/src/c_api/graph_sg.cpp @@ -17,7 +17,7 @@ #include extern "C" cugraph_error_t cugraph_sg_graph_create( - const cugraph_handle_t* handle, + const cugraph_resource_handle_t* handle, const cugraph_graph_properties_t* properties, const cugraph_type_erased_device_array_t* src, const cugraph_type_erased_device_array_t* dst, diff --git a/cpp/src/c_api/pagerank.cpp b/cpp/src/c_api/pagerank.cpp index 07edb813709..4719ecaa90a 100644 --- a/cpp/src/c_api/pagerank.cpp +++ b/cpp/src/c_api/pagerank.cpp @@ -48,7 +48,7 @@ extern "C" void cugraph_pagerank_result_free(cugraph_pagerank_result_t* result) } extern "C" cugraph_error_t compute_pagerank( - const cugraph_handle_t* handle, + const cugraph_resource_handle_t* handle, const cugraph_graph_t* graph, const cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, double alpha, @@ -74,7 +74,7 @@ extern "C" cugraph_error_t compute_pagerank( } extern "C" cugraph_error_t cugraph_personalized_pagerank( - const cugraph_handle_t* handle, + const cugraph_resource_handle_t* handle, const cugraph_graph_t* graph, const cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, const cugraph_type_erased_device_array_t* personalization_vertices, diff --git a/cpp/tests/c_api/create_graph_test.c b/cpp/tests/c_api/create_graph_test.c index 926f981756e..aa7b8610928 100644 --- a/cpp/tests/c_api/create_graph_test.c +++ b/cpp/tests/c_api/create_graph_test.c @@ -38,7 +38,7 @@ int test_create_sg_graph_simple() vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; weight_t h_wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; - cugraph_handle_t* p_handle = NULL; + cugraph_resource_handle_t* p_handle = NULL; cugraph_graph_t* p_graph = NULL; cugraph_graph_properties_t properties; diff --git a/cpp/tests/c_api/create_sg_graph_envelope_test.c b/cpp/tests/c_api/create_sg_graph_envelope_test.c index e3cea393542..7dcc8b51ae9 100644 --- a/cpp/tests/c_api/create_sg_graph_envelope_test.c +++ b/cpp/tests/c_api/create_sg_graph_envelope_test.c @@ -36,7 +36,7 @@ int test_create_sg_graph_simple() vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; weight_t h_wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; - cugraph_handle_t* p_handle = NULL; + cugraph_resource_handle_t* p_handle = NULL; cugraph_device_buffer_t dbuf_src; cugraph_device_buffer_t dbuf_dst; cugraph_device_buffer_t dbuf_wgt; @@ -114,7 +114,7 @@ int test_create_sg_graph_bad_arrays() int test_failed = 0; cugraph_graph_envelope_t* G = NULL; - cugraph_handle_t handle; + cugraph_resource_handle_t handle; cugraph_device_buffer_t* src_ptr = NULL; cugraph_device_buffer_t* dst_ptr = NULL; cugraph_device_buffer_t* weights_ptr = NULL; diff --git a/cpp/tests/c_api/random_walks_test.c b/cpp/tests/c_api/random_walks_test.c index 9f253af998a..7bd05ee800c 100644 --- a/cpp/tests/c_api/random_walks_test.c +++ b/cpp/tests/c_api/random_walks_test.c @@ -46,7 +46,7 @@ int test_random_walks_1() vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; weight_t h_wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; - cugraph_handle_t* p_handle = NULL; + cugraph_resource_handle_t* p_handle = NULL; cugraph_device_buffer_t dbuf_src; cugraph_device_buffer_t dbuf_dst; cugraph_device_buffer_t dbuf_wgt; @@ -199,7 +199,7 @@ int test_random_walks_2() vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; weight_t h_wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; - cugraph_handle_t* p_handle = NULL; + cugraph_resource_handle_t* p_handle = NULL; cugraph_device_buffer_t dbuf_src; cugraph_device_buffer_t dbuf_dst; cugraph_device_buffer_t dbuf_wgt; @@ -326,7 +326,7 @@ int test_random_walks_3() vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; weight_t h_wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; - cugraph_handle_t* p_handle = NULL; + cugraph_resource_handle_t* p_handle = NULL; cugraph_device_buffer_t dbuf_src; cugraph_device_buffer_t dbuf_dst; cugraph_device_buffer_t dbuf_wgt; From 85f788865ad480a62e08ecdf36ffdd9e2550734d Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Tue, 2 Nov 2021 11:35:04 -0400 Subject: [PATCH 13/19] add an error object, rename current error to error code --- cpp/include/cugraph_c/algorithms.h | 20 ++--- cpp/include/cugraph_c/array.h | 30 ++++--- cpp/include/cugraph_c/cugraph_api.h | 62 ++++++------- cpp/include/cugraph_c/graph.h | 20 ++--- cpp/src/c_api/array.cpp | 17 ++-- cpp/src/c_api/bfs.cpp | 14 +-- cpp/src/c_api/cugraph_api.cpp | 90 ++++++++++--------- cpp/src/c_api/graph_mg.cpp | 2 +- cpp/src/c_api/graph_sg.cpp | 2 +- cpp/src/c_api/pagerank.cpp | 4 +- cpp/tests/c_api/create_graph_test.c | 2 +- .../c_api/create_sg_graph_envelope_test.c | 2 +- cpp/tests/c_api/random_walks_test.c | 6 +- 13 files changed, 139 insertions(+), 132 deletions(-) diff --git a/cpp/include/cugraph_c/algorithms.h b/cpp/include/cugraph_c/algorithms.h index 91760a11323..52ba556ea1e 100644 --- a/cpp/include/cugraph_c/algorithms.h +++ b/cpp/include/cugraph_c/algorithms.h @@ -77,7 +77,7 @@ void cugraph_pagerank_result_free(cugraph_pagerank_result_t* result); * @param [out] result Opaque pointer to pagerank results * @return error code */ -cugraph_error_t cugraph_pagerank( +cugraph_error_code_t cugraph_pagerank( const cugraph_resource_handle_t* handle, const cugraph_graph_t* graph, const cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, @@ -114,7 +114,7 @@ cugraph_error_t cugraph_pagerank( * @param [out] result Opaque pointer to pagerank results * @return error code */ -cugraph_error_t cugraph_personalized_pagerank( +cugraph_error_code_t cugraph_personalized_pagerank( const cugraph_resource_handle_t* handle, const cugraph_graph_t* graph, const cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, @@ -190,14 +190,14 @@ void cugraph_bfs_result_free(cugraph_bfs_result_t* result); * @param [out] predecessors Returns device pointer to distance from the seeds * @return error code */ -cugraph_error_t cugraph_bfs(const cugraph_resource_handle_t* handle, - const cugraph_graph_t* graph, - const cugraph_type_erased_device_array_t* sources, - bool direction_optimizing, - size_t depth_limit, - bool do_expensive_check, - bool compute_predecessors, - cugraph_bfs_result_t** result); +cugraph_error_code_t cugraph_bfs(const cugraph_resource_handle_t* handle, + const cugraph_graph_t* graph, + const cugraph_type_erased_device_array_t* sources, + bool direction_optimizing, + size_t depth_limit, + bool do_expensive_check, + bool compute_predecessors, + cugraph_bfs_result_t** result); #ifdef __cplusplus } diff --git a/cpp/include/cugraph_c/array.h b/cpp/include/cugraph_c/array.h index 238e28e71ca..926fddf0a10 100644 --- a/cpp/include/cugraph_c/array.h +++ b/cpp/include/cugraph_c/array.h @@ -39,10 +39,11 @@ typedef struct { * @param [out] array Pointer to the location to store the pointer to the device array * @return error code */ -cugraph_error_t cugraph_type_erased_device_array_create(const cugraph_resource_handle_t* handle, - data_type_id_t dtype, - size_t n_elems, - cugraph_type_erased_device_array_t** array); +cugraph_error_code_t cugraph_type_erased_device_array_create( + const cugraph_resource_handle_t* handle, + data_type_id_t dtype, + size_t n_elems, + cugraph_type_erased_device_array_t** array); /** * @brief Destroy a type erased device array @@ -83,10 +84,11 @@ void* cugraph_type_erased_device_array_pointer(const cugraph_type_erased_device_ * @param [in] n_elems The number of elements in the array * @param [out] array Pointer to the location to store the pointer to the host array */ -cugraph_error_t cugraph_type_erased_host_array_create(const cugraph_resource_handle_t* handle, - data_type_id_t dtype, - size_t n_elems, - cugraph_type_erased_host_array_t** array); +cugraph_error_code_t cugraph_type_erased_host_array_create( + const cugraph_resource_handle_t* handle, + data_type_id_t dtype, + size_t n_elems, + cugraph_type_erased_host_array_t** array); /** * @brief Destroy a type erased host array @@ -127,8 +129,10 @@ void* cugraph_type_erased_host_array_pointer(const cugraph_type_erased_host_arra * @param [in] h_src Pointer to host array to copy into device memory * @return error code */ -cugraph_error_t cugraph_type_erased_device_array_copy_from_host( - const cugraph_resource_handle_t* handle, cugraph_type_erased_device_array_t* dst, const byte_t* h_src); +cugraph_error_code_t cugraph_type_erased_device_array_copy_from_host( + const cugraph_resource_handle_t* handle, + cugraph_type_erased_device_array_t* dst, + const byte_t* h_src); /** * @brief Copy data from device to a type erased host array @@ -138,8 +142,10 @@ cugraph_error_t cugraph_type_erased_device_array_copy_from_host( * @param [in] src Pointer to the type erased device array to copy from * @return error code */ -cugraph_error_t cugraph_type_erased_device_array_copy_to_host( - const cugraph_resource_handle_t* handle, byte_t* h_dst, const cugraph_type_erased_device_array_t* src); +cugraph_error_code_t cugraph_type_erased_device_array_copy_to_host( + const cugraph_resource_handle_t* handle, + byte_t* h_dst, + const cugraph_type_erased_device_array_t* src); #ifdef __cplusplus } diff --git a/cpp/include/cugraph_c/cugraph_api.h b/cpp/include/cugraph_c/cugraph_api.h index 2648a97eed5..e4317e64731 100644 --- a/cpp/include/cugraph_c/cugraph_api.h +++ b/cpp/include/cugraph_c/cugraph_api.h @@ -16,6 +16,8 @@ #pragma once +#include + #include #include #include @@ -24,14 +26,6 @@ extern "C" { #endif -typedef enum cugraph_error_ { - CUGRAPH_SUCCESS = 0, - CUGRAPH_UNKNOWN_ERROR, - CUGRAPH_INVALID_HANDLE, - CUGRAPH_ALLOC_ERROR, - CUGRAPH_NOT_IMPLEMENTED -} cugraph_error_t; - typedef enum bool_ { FALSE = 0, TRUE = 1 } bool_t; typedef int8_t byte_t; @@ -106,26 +100,26 @@ void cugraph_free_sampling_strategy(cugraph_unique_ptr_t* p_sampling); void cugraph_free_rw_result(cugraph_rw_ret_t* p_rw_ret); /* RW result vertex extractor*/ -cugraph_error_t extract_vertex_rw_result(cugraph_rw_ret_t* p_rw_ret, - cugraph_device_buffer_t* p_d_buf_v); +cugraph_error_code_t extract_vertex_rw_result(cugraph_rw_ret_t* p_rw_ret, + cugraph_device_buffer_t* p_d_buf_v); /* RW result weights extractor*/ -cugraph_error_t extract_weight_rw_result(cugraph_rw_ret_t* p_rw_ret, - cugraph_device_buffer_t* p_d_buf_w); +cugraph_error_code_t extract_weight_rw_result(cugraph_rw_ret_t* p_rw_ret, + cugraph_device_buffer_t* p_d_buf_w); /* RW result size extractor*/ -cugraph_error_t extract_size_rw_result(cugraph_rw_ret_t* p_rw_ret, - cugraph_device_buffer_t* p_d_buf_sz); +cugraph_error_code_t extract_size_rw_result(cugraph_rw_ret_t* p_rw_ret, + cugraph_device_buffer_t* p_d_buf_sz); /* algorithm wrapper*/ -cugraph_error_t cugraph_random_walks(const cugraph_resource_handle_t* ptr_handle, - cugraph_graph_envelope_t* ptr_graph_envelope, - cugraph_device_buffer_t* ptr_d_start, - size_t num_paths, - size_t max_depth, - bool_t flag_use_padding, - cugraph_unique_ptr_t* ptr_sampling_strategy, - cugraph_rw_ret_t* ret); +cugraph_error_code_t cugraph_random_walks(const cugraph_resource_handle_t* ptr_handle, + cugraph_graph_envelope_t* ptr_graph_envelope, + cugraph_device_buffer_t* ptr_d_start, + size_t num_paths, + size_t max_depth, + bool_t flag_use_padding, + cugraph_unique_ptr_t* ptr_sampling_strategy, + cugraph_rw_ret_t* ret); /* SG graph allocator*/ cugraph_graph_envelope_t* cugraph_make_sg_graph(const cugraph_resource_handle_t* p_handle, @@ -146,25 +140,25 @@ cugraph_graph_envelope_t* cugraph_make_sg_graph(const cugraph_resource_handle_t* void cugraph_free_graph(cugraph_graph_envelope_t* graph); /* rmm::device buffer allocator: fill pointer semantics*/ -cugraph_error_t cugraph_make_device_buffer(const cugraph_resource_handle_t* handle, - data_type_id_t dtype, - size_t n_elems, - cugraph_device_buffer_t* ptr_buffer); +cugraph_error_code_t cugraph_make_device_buffer(const cugraph_resource_handle_t* handle, + data_type_id_t dtype, + size_t n_elems, + cugraph_device_buffer_t* ptr_buffer); /* rmm::device buffer de-allocator*/ void cugraph_free_device_buffer(cugraph_device_buffer_t* ptr_buffer); /* update dst device buffer from host src*/ -cugraph_error_t cugraph_update_device_buffer(const cugraph_resource_handle_t* handle, - data_type_id_t dtype, - cugraph_device_buffer_t* ptr_dst, - const byte_t* ptr_h_src); +cugraph_error_code_t cugraph_update_device_buffer(const cugraph_resource_handle_t* handle, + data_type_id_t dtype, + cugraph_device_buffer_t* ptr_dst, + const byte_t* ptr_h_src); /* update src host buffer device src*/ -cugraph_error_t cugraph_update_host_buffer(const cugraph_resource_handle_t* handle, - data_type_id_t dtype, - byte_t* ptr_h_dst, - const cugraph_device_buffer_t* ptr_src); +cugraph_error_code_t cugraph_update_host_buffer(const cugraph_resource_handle_t* handle, + data_type_id_t dtype, + byte_t* ptr_h_dst, + const cugraph_device_buffer_t* ptr_src); /* raft::handle_t allocator (for now; possibly a more encompassing handle in the future)*/ cugraph_resource_handle_t* cugraph_create_handle(void); diff --git a/cpp/include/cugraph_c/graph.h b/cpp/include/cugraph_c/graph.h index 503af1b7777..da1943cc606 100644 --- a/cpp/include/cugraph_c/graph.h +++ b/cpp/include/cugraph_c/graph.h @@ -50,15 +50,15 @@ typedef struct { * * @return error code */ -cugraph_error_t cugraph_sg_graph_create(const cugraph_resource_handle_t* handle, - const cugraph_graph_properties_t* properties, - const cugraph_type_erased_device_array_t* src, - const cugraph_type_erased_device_array_t* dst, - const cugraph_type_erased_device_array_t* weights, - bool_t store_transposed, - bool_t renumber, - bool_t check, - cugraph_graph_t** graph); +cugraph_error_code_t cugraph_sg_graph_create(const cugraph_resource_handle_t* handle, + const cugraph_graph_properties_t* properties, + const cugraph_type_erased_device_array_t* src, + const cugraph_type_erased_device_array_t* dst, + const cugraph_type_erased_device_array_t* weights, + bool_t store_transposed, + bool_t renumber, + bool_t check, + cugraph_graph_t** graph); /** * @brief Destroy an SG graph @@ -89,7 +89,7 @@ void cugraph_sg_graph_free(cugraph_graph_t* graph); * between a pair of vertices) * @param [out] graph A pointer to the graph object */ -cugraph_error_t cugraph_mg_graph_create( +cugraph_error_code_t cugraph_mg_graph_create( const cugraph_resource_handle_t* handle, const cugraph_graph_properties_t* properties, const cugraph_type_erased_device_array_t* src, diff --git a/cpp/src/c_api/array.cpp b/cpp/src/c_api/array.cpp index 854b8ef29df..67d5e79c3ee 100644 --- a/cpp/src/c_api/array.cpp +++ b/cpp/src/c_api/array.cpp @@ -38,7 +38,7 @@ typedef struct { } // namespace c_api -extern "C" cugraph_error_t cugraph_type_erased_device_array_create( +extern "C" cugraph_error_code_t cugraph_type_erased_device_array_create( const cugraph_resource_handle_t* handle, data_type_id_t dtype, size_t n_elems, @@ -60,6 +60,7 @@ extern "C" cugraph_error_t cugraph_type_erased_device_array_create( *array = reinterpret_cast(ret_value); return CUGRAPH_SUCCESS; } catch (...) { + // FIXME: Add details to new error object return CUGRAPH_UNKNOWN_ERROR; } } @@ -91,7 +92,7 @@ extern "C" void* cugraph_type_erased_device_array_pointer( return internal_pointer->data_->data(); } -extern "C" cugraph_error_t cugraph_type_erased_host_array_create( +extern "C" cugraph_error_code_t cugraph_type_erased_host_array_create( const cugraph_resource_handle_t* handle, data_type_id_t dtype, size_t n_elems, @@ -142,8 +143,10 @@ extern "C" void* cugraph_type_erased_host_array_pointer(const cugraph_type_erase return internal_pointer->data_; } -extern "C" cugraph_error_t cugraph_type_erased_device_array_copy_from_host( - const cugraph_resource_handle_t* handle, cugraph_type_erased_device_array_t* dst, const byte_t* h_src) +extern "C" cugraph_error_code_t cugraph_type_erased_device_array_copy_from_host( + const cugraph_resource_handle_t* handle, + cugraph_type_erased_device_array_t* dst, + const byte_t* h_src) { try { raft::handle_t const* raft_handle = reinterpret_cast(handle); @@ -162,8 +165,10 @@ extern "C" cugraph_error_t cugraph_type_erased_device_array_copy_from_host( } } -extern "C" cugraph_error_t cugraph_type_erased_device_array_copy_to_host( - const cugraph_resource_handle_t* handle, byte_t* h_dst, const cugraph_type_erased_device_array_t* src) +extern "C" cugraph_error_code_t cugraph_type_erased_device_array_copy_to_host( + const cugraph_resource_handle_t* handle, + byte_t* h_dst, + const cugraph_type_erased_device_array_t* src) { try { raft::handle_t const* raft_handle = reinterpret_cast(handle); diff --git a/cpp/src/c_api/bfs.cpp b/cpp/src/c_api/bfs.cpp index 535a08333cf..a71f7170b23 100644 --- a/cpp/src/c_api/bfs.cpp +++ b/cpp/src/c_api/bfs.cpp @@ -55,13 +55,13 @@ extern "C" void cugraph_bfs_result_free(cugraph_bfs_result_t* result) delete internal_pointer_; } -extern "C" cugraph_error_t cugraph_bfs(const cugraph_resource_handle_t* handle, - const cugraph_graph_t* graph, - const cugraph_type_erased_device_array_t* sources, - bool direction_optimizing, - size_t depth_limit, - bool do_expensive_check, - cugraph_bfs_result_t** result) +extern "C" cugraph_error_code_t cugraph_bfs(const cugraph_resource_handle_t* handle, + const cugraph_graph_t* graph, + const cugraph_type_erased_device_array_t* sources, + bool direction_optimizing, + size_t depth_limit, + bool do_expensive_check, + cugraph_bfs_result_t** result) { return CUGRAPH_NOT_IMPLEMENTED; } diff --git a/cpp/src/c_api/cugraph_api.cpp b/cpp/src/c_api/cugraph_api.cpp index fb8204c4938..daa7d989b06 100644 --- a/cpp/src/c_api/cugraph_api.cpp +++ b/cpp/src/c_api/cugraph_api.cpp @@ -54,7 +54,7 @@ cugraph::visitors::graph_envelope_t const& extract_graph_envelope( } template -cugraph_error_t extract_rw_result(cugraph_rw_ret_t* p_rw_ret, cugraph_device_buffer_t* p_d_buf) +cugraph_error_code_t extract_rw_result(cugraph_rw_ret_t* p_rw_ret, cugraph_device_buffer_t* p_d_buf) { if (!p_rw_ret) return CUGRAPH_ALLOC_ERROR; @@ -116,38 +116,38 @@ extern "C" void cugraph_free_rw_result(cugraph_rw_ret_t* p_rw_ret) delete p_ret; } -extern "C" cugraph_error_t extract_vertex_rw_result(cugraph_rw_ret_t* p_rw_ret, - cugraph_device_buffer_t* p_d_buf_v) +extern "C" cugraph_error_code_t extract_vertex_rw_result(cugraph_rw_ret_t* p_rw_ret, + cugraph_device_buffer_t* p_d_buf_v) { return helpers::extract_rw_result<0>(p_rw_ret, p_d_buf_v); } -extern "C" cugraph_error_t extract_weight_rw_result(cugraph_rw_ret_t* p_rw_ret, - cugraph_device_buffer_t* p_d_buf_w) +extern "C" cugraph_error_code_t extract_weight_rw_result(cugraph_rw_ret_t* p_rw_ret, + cugraph_device_buffer_t* p_d_buf_w) { return helpers::extract_rw_result<1>(p_rw_ret, p_d_buf_w); } -extern "C" cugraph_error_t extract_size_rw_result(cugraph_rw_ret_t* p_rw_ret, - cugraph_device_buffer_t* p_d_buf_sz) +extern "C" cugraph_error_code_t extract_size_rw_result(cugraph_rw_ret_t* p_rw_ret, + cugraph_device_buffer_t* p_d_buf_sz) { return helpers::extract_rw_result<2>(p_rw_ret, p_d_buf_sz); } -extern "C" cugraph_error_t cugraph_random_walks(const cugraph_resource_handle_t* ptr_handle, - cugraph_graph_envelope_t* ptr_graph_envelope, - cugraph_device_buffer_t* ptr_d_start, - size_t num_paths, - size_t max_depth, - bool_t flag_use_padding, - cugraph_unique_ptr_t* ptr_sampling_strategy, - cugraph_rw_ret_t* ret) +extern "C" cugraph_error_code_t cugraph_random_walks(const cugraph_resource_handle_t* ptr_handle, + cugraph_graph_envelope_t* ptr_graph_envelope, + cugraph_device_buffer_t* ptr_d_start, + size_t num_paths, + size_t max_depth, + bool_t flag_use_padding, + cugraph_unique_ptr_t* ptr_sampling_strategy, + cugraph_rw_ret_t* ret) { using namespace cugraph::visitors; using ptr_sampling_t = std::unique_ptr; - cugraph_error_t status = CUGRAPH_SUCCESS; + cugraph_error_code_t status = CUGRAPH_SUCCESS; if (!ret) return CUGRAPH_ALLOC_ERROR; @@ -204,19 +204,20 @@ extern "C" cugraph_error_t cugraph_random_walks(const cugraph_resource_handle_t* // graph factory: return pointer semantics (because it returns a stub); // -extern "C" cugraph_graph_envelope_t* cugraph_make_sg_graph(const cugraph_resource_handle_t* p_handle, - data_type_id_t vertex_tid, - data_type_id_t edge_tid, - data_type_id_t weight_tid, - bool_t st, - cugraph_device_buffer_t* p_src, - cugraph_device_buffer_t* p_dst, - cugraph_device_buffer_t* p_weights, - size_t num_vertices, - size_t num_edges, - bool_t check, - bool_t is_symmetric, - bool_t is_multigraph) +extern "C" cugraph_graph_envelope_t* cugraph_make_sg_graph( + const cugraph_resource_handle_t* p_handle, + data_type_id_t vertex_tid, + data_type_id_t edge_tid, + data_type_id_t weight_tid, + bool_t st, + cugraph_device_buffer_t* p_src, + cugraph_device_buffer_t* p_dst, + cugraph_device_buffer_t* p_weights, + size_t num_vertices, + size_t num_edges, + bool_t check, + bool_t is_symmetric, + bool_t is_multigraph) { using namespace cugraph::visitors; @@ -277,12 +278,12 @@ extern "C" void cugraph_free_graph(cugraph_graph_envelope_t* ptr_graph) // device buffer factory: fill pointer semantics (because the pointer is more than a stub); // -extern "C" cugraph_error_t cugraph_make_device_buffer(const cugraph_resource_handle_t* handle, - data_type_id_t dtype, - size_t n_elems, // ... of type `dtype` - cugraph_device_buffer_t* ptr_buffer) +extern "C" cugraph_error_code_t cugraph_make_device_buffer(const cugraph_resource_handle_t* handle, + data_type_id_t dtype, + size_t n_elems, // ... of type `dtype` + cugraph_device_buffer_t* ptr_buffer) { - cugraph_error_t status = CUGRAPH_SUCCESS; + cugraph_error_code_t status = CUGRAPH_SUCCESS; try { raft::handle_t const* p_raft_handle = reinterpret_cast(handle); @@ -304,12 +305,13 @@ extern "C" void cugraph_free_device_buffer(cugraph_device_buffer_t* ptr_buffer) delete ptr_rmm_d_buf; } -extern "C" cugraph_error_t cugraph_update_device_buffer(const cugraph_resource_handle_t* handle, - data_type_id_t dtype, - cugraph_device_buffer_t* ptr_dst, - const byte_t* ptr_h_src) +extern "C" cugraph_error_code_t cugraph_update_device_buffer( + const cugraph_resource_handle_t* handle, + data_type_id_t dtype, + cugraph_device_buffer_t* ptr_dst, + const byte_t* ptr_h_src) { - cugraph_error_t status = CUGRAPH_SUCCESS; + cugraph_error_code_t status = CUGRAPH_SUCCESS; try { raft::handle_t const* ptr_raft_handle = reinterpret_cast(handle); @@ -325,12 +327,12 @@ extern "C" cugraph_error_t cugraph_update_device_buffer(const cugraph_resource_h return status; } -extern "C" cugraph_error_t cugraph_update_host_buffer(const cugraph_resource_handle_t* handle, - data_type_id_t dtype, - byte_t* ptr_h_dst, - const cugraph_device_buffer_t* ptr_src) +extern "C" cugraph_error_code_t cugraph_update_host_buffer(const cugraph_resource_handle_t* handle, + data_type_id_t dtype, + byte_t* ptr_h_dst, + const cugraph_device_buffer_t* ptr_src) { - cugraph_error_t status = CUGRAPH_SUCCESS; + cugraph_error_code_t status = CUGRAPH_SUCCESS; try { raft::handle_t const* ptr_raft_handle = reinterpret_cast(handle); diff --git a/cpp/src/c_api/graph_mg.cpp b/cpp/src/c_api/graph_mg.cpp index 48695333ded..af84f5f607e 100644 --- a/cpp/src/c_api/graph_mg.cpp +++ b/cpp/src/c_api/graph_mg.cpp @@ -16,7 +16,7 @@ #include -extern "C" cugraph_error_t cugraph_mg_graph_create( +extern "C" cugraph_error_code_t cugraph_mg_graph_create( const cugraph_resource_handle_t* handle, const cugraph_graph_properties_t* properties, const cugraph_type_erased_device_array_t* src, diff --git a/cpp/src/c_api/graph_sg.cpp b/cpp/src/c_api/graph_sg.cpp index 18f11acfc9d..afc614d66e9 100644 --- a/cpp/src/c_api/graph_sg.cpp +++ b/cpp/src/c_api/graph_sg.cpp @@ -16,7 +16,7 @@ #include -extern "C" cugraph_error_t cugraph_sg_graph_create( +extern "C" cugraph_error_code_t cugraph_sg_graph_create( const cugraph_resource_handle_t* handle, const cugraph_graph_properties_t* properties, const cugraph_type_erased_device_array_t* src, diff --git a/cpp/src/c_api/pagerank.cpp b/cpp/src/c_api/pagerank.cpp index 4719ecaa90a..02d499e570b 100644 --- a/cpp/src/c_api/pagerank.cpp +++ b/cpp/src/c_api/pagerank.cpp @@ -47,7 +47,7 @@ extern "C" void cugraph_pagerank_result_free(cugraph_pagerank_result_t* result) delete internal_pointer; } -extern "C" cugraph_error_t compute_pagerank( +extern "C" cugraph_error_code_t compute_pagerank( const cugraph_resource_handle_t* handle, const cugraph_graph_t* graph, const cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, @@ -73,7 +73,7 @@ extern "C" cugraph_error_t compute_pagerank( return CUGRAPH_NOT_IMPLEMENTED; } -extern "C" cugraph_error_t cugraph_personalized_pagerank( +extern "C" cugraph_error_code_t cugraph_personalized_pagerank( const cugraph_resource_handle_t* handle, const cugraph_graph_t* graph, const cugraph_type_erased_device_array_t* precomputed_vertex_out_weight_sums, diff --git a/cpp/tests/c_api/create_graph_test.c b/cpp/tests/c_api/create_graph_test.c index aa7b8610928..a0030ad5691 100644 --- a/cpp/tests/c_api/create_graph_test.c +++ b/cpp/tests/c_api/create_graph_test.c @@ -30,7 +30,7 @@ int test_create_sg_graph_simple() typedef int32_t edge_t; typedef float weight_t; - cugraph_error_t ret_code = CUGRAPH_SUCCESS; + cugraph_error_code_t ret_code = CUGRAPH_SUCCESS; size_t num_edges = 8; size_t num_vertices = 6; diff --git a/cpp/tests/c_api/create_sg_graph_envelope_test.c b/cpp/tests/c_api/create_sg_graph_envelope_test.c index 7dcc8b51ae9..ba60ecb2013 100644 --- a/cpp/tests/c_api/create_sg_graph_envelope_test.c +++ b/cpp/tests/c_api/create_sg_graph_envelope_test.c @@ -28,7 +28,7 @@ int test_create_sg_graph_simple() typedef int32_t edge_t; typedef float weight_t; - cugraph_error_t ret_code = CUGRAPH_SUCCESS; + cugraph_error_code_t ret_code = CUGRAPH_SUCCESS; size_t num_edges = 8; size_t num_vertices = 6; diff --git a/cpp/tests/c_api/random_walks_test.c b/cpp/tests/c_api/random_walks_test.c index 7bd05ee800c..6568ff54cae 100644 --- a/cpp/tests/c_api/random_walks_test.c +++ b/cpp/tests/c_api/random_walks_test.c @@ -38,7 +38,7 @@ int test_random_walks_1() typedef int32_t edge_t; typedef float weight_t; - cugraph_error_t ret_code = CUGRAPH_SUCCESS; + cugraph_error_code_t ret_code = CUGRAPH_SUCCESS; size_t num_edges = 8; size_t num_vertices = 6; @@ -191,7 +191,7 @@ int test_random_walks_2() typedef int32_t edge_t; typedef float weight_t; - cugraph_error_t ret_code = CUGRAPH_SUCCESS; + cugraph_error_code_t ret_code = CUGRAPH_SUCCESS; size_t num_edges = 8; size_t num_vertices = 6; @@ -318,7 +318,7 @@ int test_random_walks_3() typedef int32_t edge_t; typedef float weight_t; - cugraph_error_t ret_code = CUGRAPH_SUCCESS; + cugraph_error_code_t ret_code = CUGRAPH_SUCCESS; size_t num_edges = 8; size_t num_vertices = 6; From 31e89a0666f3869d49303673ef827a3ea2df763f Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Tue, 2 Nov 2021 12:57:59 -0400 Subject: [PATCH 14/19] add error object to array calls --- cpp/include/cugraph_c/array.h | 28 +++++++++++++++------- cpp/src/c_api/array.cpp | 36 +++++++++++++++++++++-------- cpp/tests/c_api/create_graph_test.c | 13 ++++++----- 3 files changed, 54 insertions(+), 23 deletions(-) diff --git a/cpp/include/cugraph_c/array.h b/cpp/include/cugraph_c/array.h index 926fddf0a10..6759da9d061 100644 --- a/cpp/include/cugraph_c/array.h +++ b/cpp/include/cugraph_c/array.h @@ -37,13 +37,16 @@ typedef struct { * @param [in] dtype The type of array to create * @param [in] n_elems The number of elements in the array * @param [out] array Pointer to the location to store the pointer to the device array + * @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_type_erased_device_array_create( const cugraph_resource_handle_t* handle, data_type_id_t dtype, size_t n_elems, - cugraph_type_erased_device_array_t** array); + cugraph_type_erased_device_array_t** array, + cugraph_error_t** error); /** * @brief Destroy a type erased device array @@ -83,12 +86,15 @@ void* cugraph_type_erased_device_array_pointer(const cugraph_type_erased_device_ * @param [in] dtype The type of array to create * @param [in] n_elems The number of elements in the array * @param [out] array Pointer to the location to store the pointer to the host array + * @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_type_erased_host_array_create( - const cugraph_resource_handle_t* handle, - data_type_id_t dtype, - size_t n_elems, - cugraph_type_erased_host_array_t** array); +cugraph_error_code_t cugraph_type_erased_host_array_create(const cugraph_resource_handle_t* handle, + data_type_id_t dtype, + size_t n_elems, + cugraph_type_erased_host_array_t** array, + cugraph_error_t** error); /** * @brief Destroy a type erased host array @@ -127,12 +133,15 @@ void* cugraph_type_erased_host_array_pointer(const cugraph_type_erased_host_arra * @param [in] handle Handle for accessing resources * @param [out] dst Pointer to the type erased device array * @param [in] h_src Pointer to host array to copy into device memory + * @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_type_erased_device_array_copy_from_host( const cugraph_resource_handle_t* handle, cugraph_type_erased_device_array_t* dst, - const byte_t* h_src); + const byte_t* h_src, + cugraph_error_t** error); /** * @brief Copy data from device to a type erased host array @@ -140,12 +149,15 @@ cugraph_error_code_t cugraph_type_erased_device_array_copy_from_host( * @param [in] handle Handle for accessing resources * @param [out] h_dst Pointer to host array * @param [in] src Pointer to the type erased device array to copy from + * @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_type_erased_device_array_copy_to_host( const cugraph_resource_handle_t* handle, byte_t* h_dst, - const cugraph_type_erased_device_array_t* src); + const cugraph_type_erased_device_array_t* src, + cugraph_error_t** error); #ifdef __cplusplus } diff --git a/cpp/src/c_api/array.cpp b/cpp/src/c_api/array.cpp index 67d5e79c3ee..565c32a3f98 100644 --- a/cpp/src/c_api/array.cpp +++ b/cpp/src/c_api/array.cpp @@ -15,6 +15,7 @@ */ #include +#include #include @@ -42,9 +43,11 @@ extern "C" cugraph_error_code_t cugraph_type_erased_device_array_create( const cugraph_resource_handle_t* handle, data_type_id_t dtype, size_t n_elems, - cugraph_type_erased_device_array_t** array) + cugraph_type_erased_device_array_t** array, + cugraph_error_t** error) { *array = nullptr; + *error = nullptr; try { raft::handle_t const* raft_handle = reinterpret_cast(handle); @@ -59,8 +62,9 @@ extern "C" cugraph_error_code_t cugraph_type_erased_device_array_create( *array = reinterpret_cast(ret_value); return CUGRAPH_SUCCESS; - } catch (...) { - // FIXME: Add details to new error object + } catch (std::exception const& ex) { + auto tmp_error = new c_api::cugraph_error_t{ex.what()}; + *error = reinterpret_cast(tmp_error); return CUGRAPH_UNKNOWN_ERROR; } } @@ -96,9 +100,11 @@ extern "C" cugraph_error_code_t cugraph_type_erased_host_array_create( const cugraph_resource_handle_t* handle, data_type_id_t dtype, size_t n_elems, - cugraph_type_erased_host_array_t** array) + cugraph_type_erased_host_array_t** array, + cugraph_error_t** error) { *array = nullptr; + *error = nullptr; try { raft::handle_t const* raft_handle = reinterpret_cast(handle); @@ -112,7 +118,9 @@ extern "C" cugraph_error_code_t cugraph_type_erased_host_array_create( *array = reinterpret_cast(ret_value); return CUGRAPH_SUCCESS; - } catch (...) { + } catch (std::exception const& ex) { + auto tmp_error = new c_api::cugraph_error_t{ex.what()}; + *error = reinterpret_cast(tmp_error); return CUGRAPH_UNKNOWN_ERROR; } } @@ -146,8 +154,11 @@ extern "C" void* cugraph_type_erased_host_array_pointer(const cugraph_type_erase extern "C" cugraph_error_code_t cugraph_type_erased_device_array_copy_from_host( const cugraph_resource_handle_t* handle, cugraph_type_erased_device_array_t* dst, - const byte_t* h_src) + const byte_t* h_src, + cugraph_error_t** error) { + *error = nullptr; + try { raft::handle_t const* raft_handle = reinterpret_cast(handle); auto internal_pointer = reinterpret_cast(dst); @@ -160,7 +171,9 @@ extern "C" cugraph_error_code_t cugraph_type_erased_device_array_copy_from_host( raft_handle->get_stream()); return CUGRAPH_SUCCESS; - } catch (...) { + } catch (std::exception const& ex) { + auto tmp_error = new c_api::cugraph_error_t{ex.what()}; + *error = reinterpret_cast(tmp_error); return CUGRAPH_UNKNOWN_ERROR; } } @@ -168,8 +181,11 @@ extern "C" cugraph_error_code_t cugraph_type_erased_device_array_copy_from_host( extern "C" cugraph_error_code_t cugraph_type_erased_device_array_copy_to_host( const cugraph_resource_handle_t* handle, byte_t* h_dst, - const cugraph_type_erased_device_array_t* src) + const cugraph_type_erased_device_array_t* src, + cugraph_error_t** error) { + *error = nullptr; + try { raft::handle_t const* raft_handle = reinterpret_cast(handle); auto internal_pointer = reinterpret_cast(src); @@ -182,7 +198,9 @@ extern "C" cugraph_error_code_t cugraph_type_erased_device_array_copy_to_host( raft_handle->get_stream()); return CUGRAPH_SUCCESS; - } catch (...) { + } catch (std::exception const& ex) { + auto tmp_error = new c_api::cugraph_error_t{ex.what()}; + *error = reinterpret_cast(tmp_error); return CUGRAPH_UNKNOWN_ERROR; } } diff --git a/cpp/tests/c_api/create_graph_test.c b/cpp/tests/c_api/create_graph_test.c index a0030ad5691..d349fcde4af 100644 --- a/cpp/tests/c_api/create_graph_test.c +++ b/cpp/tests/c_api/create_graph_test.c @@ -31,6 +31,7 @@ int test_create_sg_graph_simple() typedef float weight_t; cugraph_error_code_t ret_code = CUGRAPH_SUCCESS; + cugraph_error_t *ret_error; size_t num_edges = 8; size_t num_vertices = 6; @@ -56,22 +57,22 @@ int test_create_sg_graph_simple() cugraph_type_erased_device_array_t* dst; cugraph_type_erased_device_array_t* wgt; - ret_code = cugraph_type_erased_device_array_create(p_handle, vertex_tid, num_edges, &src); + ret_code = cugraph_type_erased_device_array_create(p_handle, vertex_tid, num_edges, &src, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "src create failed."); - ret_code = cugraph_type_erased_device_array_create(p_handle, vertex_tid, num_edges, &dst); + ret_code = cugraph_type_erased_device_array_create(p_handle, vertex_tid, num_edges, &dst, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "dst create failed."); - ret_code = cugraph_type_erased_device_array_create(p_handle, weight_tid, num_edges, &wgt); + ret_code = cugraph_type_erased_device_array_create(p_handle, weight_tid, num_edges, &wgt, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "wgt create failed."); - ret_code = cugraph_type_erased_device_array_copy_from_host(p_handle, src, (byte_t*)h_src); + ret_code = cugraph_type_erased_device_array_copy_from_host(p_handle, src, (byte_t*)h_src, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "src copy_from_host failed."); - ret_code = cugraph_type_erased_device_array_copy_from_host(p_handle, dst, (byte_t*)h_dst); + ret_code = cugraph_type_erased_device_array_copy_from_host(p_handle, dst, (byte_t*)h_dst, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "dst copy_from_host failed."); - ret_code = cugraph_type_erased_device_array_copy_from_host(p_handle, wgt, (byte_t*)h_wgt); + ret_code = cugraph_type_erased_device_array_copy_from_host(p_handle, wgt, (byte_t*)h_wgt, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "wgt copy_from_host failed."); ret_code = cugraph_sg_graph_create(p_handle, From 72be269210f929f037a2ef0e7c9a1cdc4f94a575 Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Tue, 2 Nov 2021 13:13:45 -0400 Subject: [PATCH 15/19] missed file in last push --- cpp/include/cugraph_c/error.h | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 cpp/include/cugraph_c/error.h diff --git a/cpp/include/cugraph_c/error.h b/cpp/include/cugraph_c/error.h new file mode 100644 index 00000000000..40e142795e2 --- /dev/null +++ b/cpp/include/cugraph_c/error.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021, 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. + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum cugraph_error_code_ { + CUGRAPH_SUCCESS = 0, + CUGRAPH_UNKNOWN_ERROR, + CUGRAPH_INVALID_HANDLE, + CUGRAPH_ALLOC_ERROR, + CUGRAPH_NOT_IMPLEMENTED +} cugraph_error_code_t; + +typedef struct cugraph_error_ { + int align_; +} cugraph_error_t; + +/** + * @brief Return an error message + * + * @param [in] error The error object from some cugraph function call + * @return a C-style string that provides detail for the error + */ +const char *cugraph_error_message(const cugraph_error_t *error); + +#ifdef __cplusplus +} +#endif From 338cda88558e245a67b1633eb0991499618ef3fc Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Tue, 2 Nov 2021 13:42:12 -0400 Subject: [PATCH 16/19] fix clang-format issues --- cpp/include/cugraph_c/error.h | 9 ++++++++- cpp/src/c_api/array.cpp | 27 +++++++++++++++++++++------ cpp/tests/c_api/create_graph_test.c | 1 + 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/cpp/include/cugraph_c/error.h b/cpp/include/cugraph_c/error.h index 40e142795e2..836724b990a 100644 --- a/cpp/include/cugraph_c/error.h +++ b/cpp/include/cugraph_c/error.h @@ -38,7 +38,14 @@ typedef struct cugraph_error_ { * @param [in] error The error object from some cugraph function call * @return a C-style string that provides detail for the error */ -const char *cugraph_error_message(const cugraph_error_t *error); +const char* cugraph_error_message(const cugraph_error_t* error); + +/** + * @brief Destroy an error message + * + * @param [in] error The error object from some cugraph function call + */ +void cugraph_error_free(cugraph_error_t* error); #ifdef __cplusplus } diff --git a/cpp/src/c_api/array.cpp b/cpp/src/c_api/array.cpp index 565c32a3f98..4ecb3e3cc03 100644 --- a/cpp/src/c_api/array.cpp +++ b/cpp/src/c_api/array.cpp @@ -52,7 +52,11 @@ extern "C" cugraph_error_code_t cugraph_type_erased_device_array_create( try { raft::handle_t const* raft_handle = reinterpret_cast(handle); - if (!raft_handle) return CUGRAPH_INVALID_HANDLE; + if (!raft_handle) { + *error = + reinterpret_cast(new c_api::cugraph_error_t{"invalid resource handle"}); + return CUGRAPH_INVALID_HANDLE; + } size_t nbytes = n_elems * (::data_type_sz[dtype]); @@ -63,8 +67,7 @@ extern "C" cugraph_error_code_t cugraph_type_erased_device_array_create( *array = reinterpret_cast(ret_value); return CUGRAPH_SUCCESS; } catch (std::exception const& ex) { - auto tmp_error = new c_api::cugraph_error_t{ex.what()}; - *error = reinterpret_cast(tmp_error); + *error = reinterpret_cast(new c_api::cugraph_error_t{ex.what()}); return CUGRAPH_UNKNOWN_ERROR; } } @@ -109,7 +112,11 @@ extern "C" cugraph_error_code_t cugraph_type_erased_host_array_create( try { raft::handle_t const* raft_handle = reinterpret_cast(handle); - if (!raft_handle) return CUGRAPH_INVALID_HANDLE; + if (!raft_handle) { + *error = + reinterpret_cast(new c_api::cugraph_error_t{"invalid resource handle"}); + return CUGRAPH_INVALID_HANDLE; + } size_t nbytes = n_elems * (::data_type_sz[dtype]); @@ -163,7 +170,11 @@ extern "C" cugraph_error_code_t cugraph_type_erased_device_array_copy_from_host( raft::handle_t const* raft_handle = reinterpret_cast(handle); auto internal_pointer = reinterpret_cast(dst); - if (!raft_handle) return CUGRAPH_ALLOC_ERROR; + if (!raft_handle) { + *error = + reinterpret_cast(new c_api::cugraph_error_t{"invalid resource handle"}); + return CUGRAPH_INVALID_HANDLE; + } raft::update_device(reinterpret_cast(internal_pointer->data_->data()), h_src, @@ -190,7 +201,11 @@ extern "C" cugraph_error_code_t cugraph_type_erased_device_array_copy_to_host( raft::handle_t const* raft_handle = reinterpret_cast(handle); auto internal_pointer = reinterpret_cast(src); - if (!raft_handle) return CUGRAPH_ALLOC_ERROR; + if (!raft_handle) { + *error = + reinterpret_cast(new c_api::cugraph_error_t{"invalid resource handle"}); + return CUGRAPH_INVALID_HANDLE; + } raft::update_host(h_dst, reinterpret_cast(internal_pointer->data_->data()), diff --git a/cpp/tests/c_api/create_graph_test.c b/cpp/tests/c_api/create_graph_test.c index d349fcde4af..c92a838b7e6 100644 --- a/cpp/tests/c_api/create_graph_test.c +++ b/cpp/tests/c_api/create_graph_test.c @@ -95,6 +95,7 @@ int test_create_sg_graph_simple() cugraph_type_erased_device_array_free(src); cugraph_free_handle(p_handle); + cugraph_error_free(ret_error); // FIXME: Not implemented yet, so forcing test to pass... // return test_ret_value; From 29e6091bee6a79704c4e4f49328283dda1d72f27 Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Tue, 2 Nov 2021 15:12:08 -0400 Subject: [PATCH 17/19] add cugraph_error_t to all of the methods that return error codes --- cpp/CMakeLists.txt | 1 + cpp/include/cugraph_c/algorithms.h | 15 +++++++++--- cpp/include/cugraph_c/graph.h | 11 +++++++-- cpp/src/c_api/bfs.cpp | 3 ++- cpp/src/c_api/error.cpp | 36 +++++++++++++++++++++++++++++ cpp/src/c_api/graph_mg.cpp | 3 ++- cpp/src/c_api/graph_sg.cpp | 3 ++- cpp/src/c_api/pagerank.cpp | 6 +++-- cpp/tests/c_api/create_graph_test.c | 4 +++- 9 files changed, 71 insertions(+), 11 deletions(-) create mode 100644 cpp/src/c_api/error.cpp diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index b5f5dcc0501..19a83f823bc 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -354,6 +354,7 @@ endif() add_library(cugraph_c SHARED src/c_api/cugraph_api.cpp src/c_api/array.cpp + src/c_api/error.cpp src/c_api/graph_sg.cpp src/c_api/graph_mg.cpp src/c_api/pagerank.cpp diff --git a/cpp/include/cugraph_c/algorithms.h b/cpp/include/cugraph_c/algorithms.h index 52ba556ea1e..e07b2566491 100644 --- a/cpp/include/cugraph_c/algorithms.h +++ b/cpp/include/cugraph_c/algorithms.h @@ -75,6 +75,8 @@ void cugraph_pagerank_result_free(cugraph_pagerank_result_t* result); * to 1.0 divided by the number of vertices in the graph. * @param do_expensive_check A flag to run expensive checks for input arguments (if set to `true`). * @param [out] result Opaque pointer to pagerank results + * @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_pagerank( @@ -86,7 +88,8 @@ cugraph_error_code_t cugraph_pagerank( size_t max_iterations, bool has_initial_guess, bool do_expensive_check, - cugraph_pagerank_result_t** result); + cugraph_pagerank_result_t** result, + cugraph_error_t** error); /** * @brief Compute personalized pagerank @@ -112,6 +115,8 @@ cugraph_error_code_t cugraph_pagerank( * to 1.0 divided by the number of vertices in the graph. * @param do_expensive_check A flag to run expensive checks for input arguments (if set to `true`). * @param [out] result Opaque pointer to pagerank results + * @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_personalized_pagerank( @@ -125,7 +130,8 @@ cugraph_error_code_t cugraph_personalized_pagerank( size_t max_iterations, bool has_initial_guess, bool do_expensive_check, - cugraph_pagerank_result_t** result); + cugraph_pagerank_result_t** result, + cugraph_error_t** error); /** * @brief Opaque bfs result type @@ -188,6 +194,8 @@ void cugraph_bfs_result_free(cugraph_bfs_result_t* result); * @param [out] vertex_ids Returns device pointer to vertex ids * @param [out] distances Returns device pointer to distance from the seeds * @param [out] predecessors Returns device pointer to distance from the seeds + * @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_bfs(const cugraph_resource_handle_t* handle, @@ -197,7 +205,8 @@ cugraph_error_code_t cugraph_bfs(const cugraph_resource_handle_t* handle, size_t depth_limit, bool do_expensive_check, bool compute_predecessors, - cugraph_bfs_result_t** result); + cugraph_bfs_result_t** result, + cugraph_error_t** error); #ifdef __cplusplus } diff --git a/cpp/include/cugraph_c/graph.h b/cpp/include/cugraph_c/graph.h index da1943cc606..183841c68e0 100644 --- a/cpp/include/cugraph_c/graph.h +++ b/cpp/include/cugraph_c/graph.h @@ -47,6 +47,8 @@ typedef struct { * is consistent with software assumptions. If false bypass these checks. * @param [in] properties Properties of the graph * @param [out] graph A pointer to the graph 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 */ @@ -58,7 +60,8 @@ cugraph_error_code_t cugraph_sg_graph_create(const cugraph_resource_handle_t* ha bool_t store_transposed, bool_t renumber, bool_t check, - cugraph_graph_t** graph); + cugraph_graph_t** graph, + cugraph_error_t** error); /** * @brief Destroy an SG graph @@ -88,6 +91,9 @@ void cugraph_sg_graph_free(cugraph_graph_t* graph); * @param [in] is_multigraph If true the input graph is a multi graph (can have multiple edges * between a pair of vertices) * @param [out] graph A pointer to the graph 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_mg_graph_create( const cugraph_resource_handle_t* handle, @@ -101,7 +107,8 @@ cugraph_error_code_t cugraph_mg_graph_create( size_t num_vertices, size_t num_edges, bool_t check, - cugraph_graph_t** graph); + cugraph_graph_t** graph, + cugraph_error_t** error); /** * @brief Destroy an MG graph diff --git a/cpp/src/c_api/bfs.cpp b/cpp/src/c_api/bfs.cpp index a71f7170b23..f00c3cf7b65 100644 --- a/cpp/src/c_api/bfs.cpp +++ b/cpp/src/c_api/bfs.cpp @@ -61,7 +61,8 @@ extern "C" cugraph_error_code_t cugraph_bfs(const cugraph_resource_handle_t* han bool direction_optimizing, size_t depth_limit, bool do_expensive_check, - cugraph_bfs_result_t** result) + cugraph_bfs_result_t** result, + cugraph_error_t** error) { return CUGRAPH_NOT_IMPLEMENTED; } diff --git a/cpp/src/c_api/error.cpp b/cpp/src/c_api/error.cpp new file mode 100644 index 00000000000..7cf616d2276 --- /dev/null +++ b/cpp/src/c_api/error.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021, 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. + */ + +#include +#include + +extern "C" const char* cugraph_error_message(const cugraph_error_t* error) +{ + if (error != nullptr) { + auto internal_pointer = reinterpret_cast(error); + return internal_pointer->error_message.c_str(); + } else { + return nullptr; + } +} + +extern "C" void cugraph_error_free(cugraph_error_t* error) +{ + if (error != nullptr) { + auto internal_pointer = reinterpret_cast(error); + delete internal_pointer; + } +} diff --git a/cpp/src/c_api/graph_mg.cpp b/cpp/src/c_api/graph_mg.cpp index af84f5f607e..9fc3d9ba7af 100644 --- a/cpp/src/c_api/graph_mg.cpp +++ b/cpp/src/c_api/graph_mg.cpp @@ -28,7 +28,8 @@ extern "C" cugraph_error_code_t cugraph_mg_graph_create( size_t num_vertices, size_t num_edges, bool_t check, - cugraph_graph_t** graph) + cugraph_graph_t** graph, + cugraph_error_t** error) { *graph = nullptr; return CUGRAPH_NOT_IMPLEMENTED; diff --git a/cpp/src/c_api/graph_sg.cpp b/cpp/src/c_api/graph_sg.cpp index afc614d66e9..565a666a542 100644 --- a/cpp/src/c_api/graph_sg.cpp +++ b/cpp/src/c_api/graph_sg.cpp @@ -25,7 +25,8 @@ extern "C" cugraph_error_code_t cugraph_sg_graph_create( bool_t store_transposed, bool_t renumber, bool_t check, - cugraph_graph_t** graph) + cugraph_graph_t** graph, + cugraph_error_t** error) { *graph = nullptr; return CUGRAPH_NOT_IMPLEMENTED; diff --git a/cpp/src/c_api/pagerank.cpp b/cpp/src/c_api/pagerank.cpp index 02d499e570b..b1efa1c4cd6 100644 --- a/cpp/src/c_api/pagerank.cpp +++ b/cpp/src/c_api/pagerank.cpp @@ -56,7 +56,8 @@ extern "C" cugraph_error_code_t compute_pagerank( size_t max_iterations, bool has_initial_guess, bool do_expensive_check, - cugraph_pagerank_result_t** result) + cugraph_pagerank_result_t** result, + cugraph_error_t** error) { // // TODO: (all algorithms will have this @@ -84,7 +85,8 @@ extern "C" cugraph_error_code_t cugraph_personalized_pagerank( size_t max_iterations, bool has_initial_guess, bool do_expensive_check, - cugraph_pagerank_result_t** result) + cugraph_pagerank_result_t** result, + cugraph_error_t** error) { return CUGRAPH_NOT_IMPLEMENTED; } diff --git a/cpp/tests/c_api/create_graph_test.c b/cpp/tests/c_api/create_graph_test.c index c92a838b7e6..26d5c78b93f 100644 --- a/cpp/tests/c_api/create_graph_test.c +++ b/cpp/tests/c_api/create_graph_test.c @@ -59,6 +59,7 @@ int test_create_sg_graph_simple() ret_code = cugraph_type_erased_device_array_create(p_handle, vertex_tid, num_edges, &src, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "src create failed."); + TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); ret_code = cugraph_type_erased_device_array_create(p_handle, vertex_tid, num_edges, &dst, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "dst create failed."); @@ -83,7 +84,8 @@ int test_create_sg_graph_simple() FALSE, FALSE, FALSE, - &p_graph); + &p_graph, + &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "graph creation failed."); cugraph_sg_graph_free(p_graph); From 3b8978599c804519ba0afbf81837348cf7ba3f68 Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Tue, 2 Nov 2021 15:41:38 -0400 Subject: [PATCH 18/19] missed file in last commits --- cpp/src/c_api/error.hpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 cpp/src/c_api/error.hpp diff --git a/cpp/src/c_api/error.hpp b/cpp/src/c_api/error.hpp new file mode 100644 index 00000000000..4c9e5b7f06d --- /dev/null +++ b/cpp/src/c_api/error.hpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2021, 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. + */ + +#include + +namespace c_api { +struct cugraph_error_t { + std::string error_message; + + cugraph_error_t(const char* what) : error_message(what) {} +}; +} // namespace c_api From d4a20a7498f2e9a90c63beee423dce5f9217a426 Mon Sep 17 00:00:00 2001 From: Chuck Hastings Date: Tue, 2 Nov 2021 16:25:34 -0400 Subject: [PATCH 19/19] add bfs to cmake file, fix compilation errors --- cpp/CMakeLists.txt | 1 + cpp/include/cugraph_c/algorithms.h | 1 + cpp/src/c_api/bfs.cpp | 15 ++++++++------- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 19a83f823bc..97ea15270ca 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -358,6 +358,7 @@ add_library(cugraph_c SHARED src/c_api/graph_sg.cpp src/c_api/graph_mg.cpp src/c_api/pagerank.cpp + src/c_api/bfs.cpp ) add_library(cugraph::cugraph_c ALIAS cugraph_c) diff --git a/cpp/include/cugraph_c/algorithms.h b/cpp/include/cugraph_c/algorithms.h index e07b2566491..d8eccf5623c 100644 --- a/cpp/include/cugraph_c/algorithms.h +++ b/cpp/include/cugraph_c/algorithms.h @@ -17,6 +17,7 @@ #pragma once #include +#include #include #ifdef __cplusplus diff --git a/cpp/src/c_api/bfs.cpp b/cpp/src/c_api/bfs.cpp index f00c3cf7b65..d4d836b9561 100644 --- a/cpp/src/c_api/bfs.cpp +++ b/cpp/src/c_api/bfs.cpp @@ -17,42 +17,42 @@ #include namespace c_api { -struct { +struct cugraph_bfs_result_t { cugraph_type_erased_device_array_t* vertex_ids_; cugraph_type_erased_device_array_t* distances_; cugraph_type_erased_device_array_t* predecessors_; -} cugraph_bfs_result_t; +}; } // namespace c_api extern "C" cugraph_type_erased_device_array_t* cugraph_bfs_result_get_vertices( cugraph_bfs_result_t* result) { - auto internal_pointer = reinterpret_cast(p); + auto internal_pointer = reinterpret_cast(result); return internal_pointer->vertex_ids_; } extern "C" cugraph_type_erased_device_array_t* cugraph_bfs_result_get_distances( cugraph_bfs_result_t* result) { - auto internal_pointer = reinterpret_cast(p); + auto internal_pointer = reinterpret_cast(result); return internal_pointer->distances_; } extern "C" cugraph_type_erased_device_array_t* cugraph_bfs_result_get_predecessors( cugraph_bfs_result_t* result) { - auto internal_pointer = reinterpret_cast(p); + auto internal_pointer = reinterpret_cast(result); return internal_pointer->predecessors_; } extern "C" void cugraph_bfs_result_free(cugraph_bfs_result_t* result) { - auto internal_pointer = reinterpret_cast(p); + auto internal_pointer = reinterpret_cast(result); delete internal_pointer->vertex_ids_; delete internal_pointer->distances_; delete internal_pointer->predecessors_; - delete internal_pointer_; + delete internal_pointer; } extern "C" cugraph_error_code_t cugraph_bfs(const cugraph_resource_handle_t* handle, @@ -61,6 +61,7 @@ extern "C" cugraph_error_code_t cugraph_bfs(const cugraph_resource_handle_t* han bool direction_optimizing, size_t depth_limit, bool do_expensive_check, + bool compute_predecessors, cugraph_bfs_result_t** result, cugraph_error_t** error) {