Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MG support to the C API #2110

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
19d8258
add MG support to the C API
ChuckHastings Mar 11, 2022
76819af
fix clang-format issues
ChuckHastings Mar 11, 2022
0307dad
update copyright date
ChuckHastings Mar 11, 2022
7209dc0
Updated pylibcugraph for C API changes to resource handle.
rlratzel Mar 11, 2022
ae8b037
tabs->spaces
rlratzel Mar 11, 2022
fee1344
Merge remote-tracking branch 'upstream/branch-22.04' into fea_c_api_m…
rlratzel Mar 12, 2022
4b75e18
Updated latest branch-22.04 pylibcugraph code for compatibility with …
rlratzel Mar 12, 2022
932881e
remove references to gmock (unnecessary)
ChuckHastings Mar 14, 2022
5bc0bdf
remove gmock from link information
ChuckHastings Mar 14, 2022
fda72f0
Removed gmock from libcugraph recipe, pinned gtest to 1.10.0 in libcu…
rlratzel Mar 15, 2022
08cf507
Added FIXME comment about gtest version pin.
rlratzel Mar 15, 2022
505b3b5
Adding gmock back since it appears to be needed by cmake step.
rlratzel Mar 15, 2022
fb689d2
Another attempt at removing gmock.
rlratzel Mar 15, 2022
cc46438
Adding back gmock, which seems to be needed by other cmake files.
rlratzel Mar 15, 2022
2929f18
Updated CI GPU build script to (hopefully) ensure matching cudf/libcu…
rlratzel Mar 15, 2022
67209d0
Merge branch 'remove_gmock_references' into fea_c_api_mg_implementation
rlratzel Mar 15, 2022
fff6eab
Merge remote-tracking branch 'upstream/branch-22.04' into fea_c_api_m…
rlratzel Mar 15, 2022
4c0e123
make changes based on PR comments
ChuckHastings Mar 15, 2022
b1ee1d7
Merge branch 'fea_c_api_mg_implementation' of github.com:chuckhasting…
ChuckHastings Mar 15, 2022
24fe735
fix copyright year
ChuckHastings Mar 15, 2022
b605603
include stdint.h since we're using int32_t now to define alignment mo…
ChuckHastings Mar 15, 2022
87b1279
Added testing label and FIXME.
rlratzel Mar 16, 2022
25967b7
Merge branch 'fea_c_api_mg_implementation' of https://github.com/chuc…
rlratzel Mar 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ endif()

add_library(cugraph_c SHARED
src/c_api/cugraph_api.cpp
src/c_api/resource_handle.cpp
src/c_api/array.cpp
src/c_api/error.cpp
src/c_api/graph_sg.cpp
Expand Down
3 changes: 2 additions & 1 deletion cpp/cmake/thirdparty/get_raft.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ function(find_and_configure_raft)
GIT_TAG ${PKG_PINNED_TAG}
SOURCE_SUBDIR cpp
OPTIONS
"BUILD_TESTS OFF"
"RAFT_COMPILE_LIBRARIES OFF"
"BUILD_TESTS OFF"
"BUILD_BENCH OFF"
seunghwak marked this conversation as resolved.
Show resolved Hide resolved
)

if(raft_ADDED)
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/cugraph_c/algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

#pragma once

#include <cugraph_c/cugraph_api.h>
#include <cugraph_c/error.h>
#include <cugraph_c/graph.h>
#include <cugraph_c/resource_handle.h>

#ifdef __cplusplus
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/cugraph_c/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#pragma once

#include <cugraph_c/cugraph_api.h>
#include <cugraph_c/resource_handle.h>

#ifdef __cplusplus
extern "C" {
Expand Down
22 changes: 2 additions & 20 deletions cpp/include/cugraph_c/cugraph_api.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, NVIDIA CORPORATION.
* Copyright (c) 2021-2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
#pragma once

#include <cugraph_c/error.h>
#include <cugraph_c/resource_handle.h>

#include <cuda_runtime_api.h>
#include <stddef.h>
Expand All @@ -26,21 +27,8 @@
extern "C" {
#endif

typedef enum bool_ { FALSE = 0, TRUE = 1 } bool_t;

typedef int8_t byte_t;

typedef enum data_type_id_ { INT32 = 0, INT64, FLOAT32, FLOAT64, NTYPES } data_type_id_t;

/* sizes in Bytes for data_type_id_t*/
extern int data_type_sz[];

/* C stub declarations */

typedef struct cugraph_resource_handle_ {
int align_;
} cugraph_resource_handle_t;

typedef struct cugraph_graph_envelope_ {
int align_;
} cugraph_graph_envelope_t;
Expand Down Expand Up @@ -160,12 +148,6 @@ cugraph_error_code_t cugraph_update_host_buffer(const cugraph_resource_handle_t*
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_resource_handle(void);

/* raft::handle_t deallocator*/
void cugraph_free_resource_handle(cugraph_resource_handle_t* p_handle);

#ifdef __cplusplus
}
#endif
24 changes: 10 additions & 14 deletions cpp/include/cugraph_c/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,16 @@ void cugraph_sg_graph_free(cugraph_graph_t* graph);
* 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,
const cugraph_graph_properties_t* properties,
const cugraph_type_erased_device_array_view_t* src,
const cugraph_type_erased_device_array_view_t* dst,
const cugraph_type_erased_device_array_view_t* weights,
const cugraph_type_erased_host_array_view_t* vertex_partition_offsets,
const cugraph_type_erased_host_array_view_t* segment_offsets,
bool_t store_transposed,
size_t num_vertices,
size_t num_edges,
bool_t check,
cugraph_graph_t** graph,
cugraph_error_t** error);
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_view_t* src,
const cugraph_type_erased_device_array_view_t* dst,
const cugraph_type_erased_device_array_view_t* weights,
bool_t store_transposed,
size_t num_edges,
bool_t check,
cugraph_graph_t** graph,
cugraph_error_t** error);
seunghwak marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Destroy an MG graph
Expand Down
73 changes: 73 additions & 0 deletions cpp/include/cugraph_c/resource_handle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2022, 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 <cugraph_c/error.h>

#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum bool_ { FALSE = 0, TRUE = 1 } bool_t;

typedef int8_t byte_t;

typedef enum data_type_id_ { INT32 = 0, INT64, FLOAT32, FLOAT64, NTYPES } data_type_id_t;

/* sizes in Bytes for data_type_id_t*/
extern int data_type_sz[];
seunghwak marked this conversation as resolved.
Show resolved Hide resolved

typedef struct cugraph_resource_handle_ {
int align_;
seunghwak marked this conversation as resolved.
Show resolved Hide resolved
} cugraph_resource_handle_t;

/**
* @brief Construct a resource handle
*
* @param [in] raft_handle Handle for accessing resources
* If NULL, we will create a raft handle
* internally
*
* @return A graph resource handle
*/
cugraph_resource_handle_t* cugraph_create_resource_handle(void* raft_handle);

/**
* @brief get rank from resource handle
*
* If the resource handle has been configured for multi-gpu, this will return
* the rank for this worker. If the resource handle has not been configured for
* multi-gpu this will always return 0.
*
* @param [in] handle Handle for accessing resources
* @return rank
*/
int cugraph_resource_handle_get_rank(const cugraph_resource_handle_t* handle);

/**
* @brief Free resources in the resource handle
*
* @param [in] handle Handle for accessing resources
*/
void cugraph_free_resource_handle(cugraph_resource_handle_t* handle);

#ifdef __cplusplus
}
#endif
47 changes: 23 additions & 24 deletions cpp/src/c_api/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

#include <c_api/array.hpp>
#include <c_api/error.hpp>

#include <raft/handle.hpp>
#include <c_api/resource_handle.hpp>

namespace cugraph {
namespace c_api {
Expand All @@ -41,18 +40,18 @@ extern "C" cugraph_error_code_t cugraph_type_erased_device_array_create(
*error = nullptr;

try {
raft::handle_t const* raft_handle = reinterpret_cast<raft::handle_t const*>(handle);

if (!raft_handle) {
if (!handle) {
*error = reinterpret_cast<cugraph_error_t*>(
new cugraph::c_api::cugraph_error_t{"invalid resource handle"});
return CUGRAPH_INVALID_HANDLE;
}

auto p_handle = reinterpret_cast<cugraph::c_api::cugraph_resource_handle_t const*>(handle);

size_t n_bytes = n_elems * (::data_type_sz[dtype]);

auto ret_value = new cugraph::c_api::cugraph_type_erased_device_array_t(
n_elems, n_bytes, dtype, raft_handle->get_stream());
n_elems, n_bytes, dtype, p_handle->handle_->get_stream());

*array = reinterpret_cast<cugraph_type_erased_device_array_t*>(ret_value);
return CUGRAPH_SUCCESS;
Expand Down Expand Up @@ -140,14 +139,14 @@ extern "C" cugraph_error_code_t cugraph_type_erased_host_array_create(
*error = nullptr;

try {
raft::handle_t const* raft_handle = reinterpret_cast<raft::handle_t const*>(handle);

if (!raft_handle) {
if (!handle) {
*error = reinterpret_cast<cugraph_error_t*>(
new cugraph::c_api::cugraph_error_t{"invalid resource handle"});
return CUGRAPH_INVALID_HANDLE;
}

auto p_handle = reinterpret_cast<cugraph::c_api::cugraph_resource_handle_t const*>(handle);

size_t n_bytes = n_elems * (::data_type_sz[dtype]);

*array = reinterpret_cast<cugraph_type_erased_host_array_t*>(
Expand Down Expand Up @@ -233,20 +232,20 @@ extern "C" cugraph_error_code_t cugraph_type_erased_device_array_view_copy_from_
*error = nullptr;

try {
raft::handle_t const* raft_handle = reinterpret_cast<raft::handle_t const*>(handle);
auto internal_pointer =
reinterpret_cast<cugraph::c_api::cugraph_type_erased_device_array_view_t*>(dst);

if (!raft_handle) {
if (!handle) {
*error = reinterpret_cast<cugraph_error_t*>(
new cugraph::c_api::cugraph_error_t{"invalid resource handle"});
return CUGRAPH_INVALID_HANDLE;
}

auto p_handle = reinterpret_cast<cugraph::c_api::cugraph_resource_handle_t const*>(handle);
auto internal_pointer =
reinterpret_cast<cugraph::c_api::cugraph_type_erased_device_array_view_t*>(dst);

raft::update_device(reinterpret_cast<byte_t*>(internal_pointer->data_),
h_src,
internal_pointer->num_bytes(),
raft_handle->get_stream());
p_handle->handle_->get_stream());

return CUGRAPH_SUCCESS;
} catch (std::exception const& ex) {
Expand All @@ -265,20 +264,20 @@ extern "C" cugraph_error_code_t cugraph_type_erased_device_array_view_copy_to_ho
*error = nullptr;

try {
raft::handle_t const* raft_handle = reinterpret_cast<raft::handle_t const*>(handle);
auto internal_pointer =
reinterpret_cast<cugraph::c_api::cugraph_type_erased_device_array_view_t const*>(src);

if (!raft_handle) {
if (!handle) {
*error = reinterpret_cast<cugraph_error_t*>(
new cugraph::c_api::cugraph_error_t{"invalid resource handle"});
return CUGRAPH_INVALID_HANDLE;
}

auto p_handle = reinterpret_cast<cugraph::c_api::cugraph_resource_handle_t const*>(handle);
auto internal_pointer =
reinterpret_cast<cugraph::c_api::cugraph_type_erased_device_array_view_t const*>(src);

raft::update_host(h_dst,
reinterpret_cast<byte_t const*>(internal_pointer->data_),
internal_pointer->num_bytes(),
raft_handle->get_stream());
p_handle->handle_->get_stream());

return CUGRAPH_SUCCESS;
} catch (std::exception const& ex) {
Expand All @@ -297,13 +296,13 @@ extern "C" cugraph_error_code_t cugraph_type_erased_device_array_view_copy(
*error = nullptr;

try {
raft::handle_t const* raft_handle = reinterpret_cast<raft::handle_t const*>(handle);
auto p_handle = reinterpret_cast<cugraph::c_api::cugraph_resource_handle_t const*>(handle);
auto internal_pointer_dst =
reinterpret_cast<cugraph::c_api::cugraph_type_erased_device_array_view_t*>(dst);
auto internal_pointer_src =
reinterpret_cast<cugraph::c_api::cugraph_type_erased_device_array_view_t const*>(src);

if (!raft_handle) {
if (!handle) {
*error = reinterpret_cast<cugraph_error_t*>(
new cugraph::c_api::cugraph_error_t{"invalid resource handle"});
return CUGRAPH_INVALID_HANDLE;
Expand All @@ -318,7 +317,7 @@ extern "C" cugraph_error_code_t cugraph_type_erased_device_array_view_copy(
raft::copy(reinterpret_cast<byte_t*>(internal_pointer_dst->data_),
reinterpret_cast<byte_t const*>(internal_pointer_src->data_),
internal_pointer_src->num_bytes(),
raft_handle->get_stream());
p_handle->handle_->get_stream());

return CUGRAPH_SUCCESS;
} catch (std::exception const& ex) {
Expand Down
7 changes: 3 additions & 4 deletions cpp/src/c_api/bfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
#include <c_api/abstract_functor.hpp>
#include <c_api/graph.hpp>
#include <c_api/paths_result.hpp>
#include <c_api/resource_handle.hpp>
#include <c_api/utils.hpp>

#include <cugraph/algorithms.hpp>
#include <cugraph/detail/utility_wrappers.hpp>
#include <cugraph/graph_functions.hpp>

#include <raft/handle.hpp>

namespace cugraph {
namespace c_api {

Expand All @@ -40,15 +39,15 @@ struct bfs_functor : public abstract_functor {
bool do_expensive_check_;
cugraph_paths_result_t* result_{};

bfs_functor(cugraph_resource_handle_t const* handle,
bfs_functor(::cugraph_resource_handle_t const* handle,
::cugraph_graph_t* graph,
::cugraph_type_erased_device_array_view_t* sources,
bool direction_optimizing,
size_t depth_limit,
bool compute_predecessors,
bool do_expensive_check)
: abstract_functor(),
handle_(*reinterpret_cast<raft::handle_t const*>(handle)),
handle_(*reinterpret_cast<cugraph::c_api::cugraph_resource_handle_t const*>(handle)->handle_),
graph_(reinterpret_cast<cugraph::c_api::cugraph_graph_t*>(graph)),
sources_(reinterpret_cast<cugraph::c_api::cugraph_type_erased_device_array_view_t*>(sources)),
direction_optimizing_(direction_optimizing),
Expand Down
17 changes: 1 addition & 16 deletions cpp/src/c_api/cugraph_api.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, NVIDIA CORPORATION.
* Copyright (c) 2021-2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -349,18 +349,3 @@ extern "C" cugraph_error_code_t cugraph_update_host_buffer(const cugraph_resourc
}
return status;
}

extern "C" cugraph_resource_handle_t* cugraph_create_resource_handle(void)
{
try {
return reinterpret_cast<cugraph_resource_handle_t*>(new raft::handle_t{});
} catch (...) {
return nullptr;
}
}

extern "C" void cugraph_free_resource_handle(cugraph_resource_handle_t* p_handle)
{
raft::handle_t* p_raft_handle = reinterpret_cast<raft::handle_t*>(p_handle);
delete p_raft_handle;
}
Loading