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

Initial cuGraph C API - biased RW, C tests, script updates, cmake files, C library helpers #1799

Merged
merged 73 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
acf15bc
Merge pull request #37 from rapidsai/branch-0.17
aschaffer Nov 30, 2020
a584e0b
Merge pull request #38 from rapidsai/branch-0.18
aschaffer Dec 9, 2020
338b2d4
Merge pull request #39 from rapidsai/branch-0.18
aschaffer Dec 30, 2020
efd7e9a
Merge pull request #40 from rapidsai/branch-0.18
aschaffer Jan 12, 2021
a23ce0d
Merge pull request #41 from rapidsai/branch-0.19
aschaffer Feb 25, 2021
22b32d8
Merge pull request #42 from rapidsai/branch-0.19
aschaffer Mar 1, 2021
e5042fc
Merge pull request #43 from rapidsai/branch-0.19
aschaffer Mar 20, 2021
ca02ee4
Merge pull request #44 from rapidsai/branch-0.19
aschaffer Apr 7, 2021
79409e7
Merge pull request #45 from rapidsai/branch-0.20
aschaffer Apr 13, 2021
360c293
Merge pull request #46 from rapidsai/branch-0.20
aschaffer Apr 28, 2021
e57f261
Merge pull request #47 from rapidsai/branch-0.20
aschaffer May 6, 2021
a63cdea
Merge pull request #48 from rapidsai/branch-21.08
aschaffer Jun 9, 2021
7e6bf4c
Merge branch 'rapidsai:branch-21.08' into branch-21.08
aschaffer Jun 15, 2021
6f3b342
Merge branch 'rapidsai:branch-21.08' into branch-21.08
aschaffer Jul 19, 2021
fbf5f36
Merge branch 'rapidsai:branch-21.10' into branch-21.10
aschaffer Aug 5, 2021
ffacad0
Merge branch 'rapidsai:branch-21.10' into branch-21.10
aschaffer Aug 13, 2021
beaf0fb
Merge branch 'branch-21.10' of github.com:rapidsai/cugraph into fea_e…
aschaffer Aug 17, 2021
3b3131e
Merge branch 'branch-21.10' of https://github.com/rapidsai/cugraph in…
aschaffer Aug 23, 2021
16a998f
Merge branch 'branch-21.10' of github.com:rapidsai/cugraph into fea_e…
aschaffer Aug 30, 2021
03a2055
Prepare extended API for RW.
aschaffer Aug 31, 2021
b4fe88a
Merge branch 'branch-21.10' of github.com:rapidsai/cugraph into fea_e…
aschaffer Sep 1, 2021
b7b87a2
Preliminary RW type-erasure. Needs work.
aschaffer Sep 2, 2021
af0e21b
Fixed typed-erased return to work with move-only semantics. Fixed vis…
aschaffer Sep 4, 2021
08a6ee7
RW visitor test.
aschaffer Sep 8, 2021
0336827
Changed order of header inclusion to fix problematic warning.
aschaffer Sep 9, 2021
4e40752
Proto C-API.
aschaffer Sep 14, 2021
04110f6
Added a RW test utility function allowing raw pointers, for type-eras…
aschaffer Sep 15, 2021
c74ac7c
Type-erased return type to help the C-API avoid cascaded dispatch on …
aschaffer Sep 15, 2021
267435a
Merge branch 'branch-21.10' of github.com:rapidsai/cugraph into fea_e…
aschaffer Sep 15, 2021
43e5732
C-API: file / build structure and first files.
aschaffer Sep 17, 2021
2d45309
Updates to consolidate the libcugraph C API with the cpp source tree.
rlratzel Sep 20, 2021
1833356
Changed GLOBAL_TARGETS to include cugraph_c.
rlratzel Sep 20, 2021
569792a
Changed C-API prefix.
aschaffer Sep 21, 2021
f5cead2
Fix merge conflicts.
aschaffer Sep 21, 2021
903e93e
Prelim. graph reader visitor.
aschaffer Sep 22, 2021
fd85c38
Graph factory visitor.
aschaffer Sep 22, 2021
6a87781
SG Graph factory visitor.
aschaffer Sep 22, 2021
fc00dd4
Fixed graph factory call to satisfy the graph_meta_t contract.
aschaffer Sep 22, 2021
a0752da
Added graph envelope factory to the erased API.
aschaffer Sep 23, 2021
7a0cd27
Added graph allocator / deallocator implementation to the C-API.
aschaffer Sep 23, 2021
7065363
Added (mostly placeholder) C tests for C API, updated CI scripts, upd…
rlratzel Sep 23, 2021
53d4e18
Added temporary passing return code until test is finished.
rlratzel Sep 23, 2021
ff1637b
clang format fixes.
rlratzel Sep 23, 2021
4829f6a
Temporarily returning success until test is finished.
rlratzel Sep 23, 2021
d696a6b
Adding FAISS to the list of libs to link for the C API library. Still…
rlratzel Sep 24, 2021
7401159
Added other link libs as private to cover extra dependencies for comp…
rlratzel Sep 24, 2021
80e7adc
Moving FAISS to PUBLIC section in order to have build find library lo…
rlratzel Sep 24, 2021
4b85ee7
Moving all lib deps to public for now for consistency and to ensure a…
rlratzel Sep 24, 2021
450e269
Moved libcugraph.so to private after confirming that a local build wo…
rlratzel Sep 24, 2021
470835d
Added device_buffer management in the C-API.
aschaffer Sep 24, 2021
d3c112b
Merge branch 'fea_ext_binding_rw_biased' of github.com:aschaffer/cugr…
aschaffer Sep 24, 2021
5e95b45
Simplified device buffer usage.
aschaffer Sep 27, 2021
751435f
C-API raft::handle_t allocator/deallocator.
aschaffer Sep 27, 2021
afe39b7
C-API unique_ptr<sampling_params_t> allocator/deallocator.
aschaffer Sep 27, 2021
f5e0eac
C-API RW result deallocator.
aschaffer Sep 27, 2021
6d33664
Fixed the missing exten 'C'.
aschaffer Sep 27, 2021
45ca57c
Extractors for RW results and some cleanup / simplification of the C-…
aschaffer Sep 27, 2021
2626bf0
C-API RW extractors.
aschaffer Sep 27, 2021
f10ea06
C-API RW test checking functionality.
aschaffer Sep 27, 2021
1e3d4e9
C-API RW test checking functionality simplified / more readable.
aschaffer Sep 27, 2021
ac9c70d
C-API RW tests. Resources management: handle and device_buffers.
aschaffer Sep 28, 2021
1e17b33
Fix#1 for graph_envelope factory crash.
aschaffer Sep 28, 2021
f9f1006
Fixed graph_envelope creation crash.
aschaffer Sep 28, 2021
b8dd310
Clean-up.
aschaffer Sep 28, 2021
bb5be4d
Fixed some C-API inconsistencies.
aschaffer Sep 28, 2021
2f5b4ee
Added a graph_envelope_t unwrapper to be called from within C++ deleg…
aschaffer Sep 28, 2021
a59402b
Enabled negative tests on C-API graph creation.
aschaffer Sep 29, 2021
b82e006
Fixed graph_envelope unpacking in C-API RW wrapper.
aschaffer Sep 29, 2021
a78f678
RW back to back tests.
aschaffer Sep 29, 2021
c64e235
Fixed one no-op test to actually test.
aschaffer Sep 29, 2021
84c2377
Fixed failure handling in RW wrapper.
aschaffer Sep 29, 2021
bbadef7
Merge branch 'branch-21.12' of github.com:rapidsai/cugraph into fea_e…
aschaffer Oct 1, 2021
91251b5
Merge remote-tracking branch 'upstream/branch-21.12' into fea_ext_bin…
rlratzel Oct 7, 2021
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
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ if hasArg uninstall; then
# uninstall libcugraph
if [[ "$INSTALL_PREFIX" != "" ]]; then
rm -rf ${INSTALL_PREFIX}/include/cugraph
rm -rf ${INSTALL_PREFIX}/include/cugraph_c
rm -f ${INSTALL_PREFIX}/lib/libcugraph.so
rm -f ${INSTALL_PREFIX}/lib/libcugraph_c.so
fi
# This may be redundant given the above, but can also be used in case
# there are other installed files outside of the locations above.
Expand Down
11 changes: 10 additions & 1 deletion ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,21 @@ if (python ${CUGRAPH_ROOT}/ci/utils/is_pascal.py); then
echo "WARNING: skipping C++ tests on Pascal GPU arch."
else
echo "C++ gtests for cuGraph (single-GPU only)..."
for gt in $(find ./tests -name "*_TEST" | grep -v "MG_" || true); do
for gt in $(find ./tests -name "*_TEST" | grep -v "MG_\|CAPI_" || true); do
test_name=$(basename $gt)
echo "Running gtest $test_name"
${gt} ${GTEST_FILTER} ${GTEST_ARGS}
echo "Ran gtest $test_name : return code was: $?, test script exit code is now: $EXITCODE"
done
# FIXME: the C API tests do not generate XML, so CI systems will not show
# them in the GUI. Failing C API tests will still fail CI though, and the
# output will appear in logs.
for ct in $(find ./tests -name "CAPI_*_TEST"); do
test_name=$(basename $ct)
echo "Running C API test $test_name"
${ct}
echo "Ran C API test $test_name : return code was: $?, test script exit code is now: $EXITCODE"
done
fi

echo "Python pytest for pylibcugraph..."
Expand Down
125 changes: 90 additions & 35 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,27 @@ list(APPEND usable_arch_values ${latest_arch})

set(CMAKE_CUDA_ARCHITECTURES ${usable_arch_values})


# Write the version header
rapids_cmake_write_version_file(include/cugraph/version_config.hpp)
rapids_cmake_write_version_file(include/cugraph_c/version_config.hpp)

###################################################################################################
# - build type ------------------------------------------------------------------------------------
################################################################################
# - build type -----------------------------------------------------------------

# Set a default build type if none was specified
rapids_cmake_build_type(Release)

##############################################################################
# - User Options ------------------------------------------------------------
################################################################################
# - User Options --------------------------------------------------------------

option(BUILD_CUGRAPH_MG_TESTS "Build cuGraph multigpu algorithm tests" OFF)
set(BLAS_LIBRARIES "" CACHE STRING "Location of BLAS library for FAISS build.")
option(BUILD_STATIC_FAISS "Build the FAISS library for nearest neighbors search on GPU" OFF)
option(CMAKE_CUDA_LINEINFO "Enable the -lineinfo option for nvcc (useful for cuda-memcheck / profiler" OFF)
option(BUILD_TESTS "Configure CMake to build tests" ON)

###################################################################################################
# - compiler options ------------------------------------------------------------------------------
################################################################################
# - compiler options -----------------------------------------------------------

rapids_find_package(CUDAToolkit REQUIRED
BUILD_EXPORT_SET cugraph-exports
Expand Down Expand Up @@ -103,8 +103,8 @@ if(CMAKE_BUILD_TYPE MATCHES Debug)
list(APPEND CUGRAPH_CUDA_FLAGS -G -Xcompiler=-rdynamic)
endif()

###################################################################################################
# - find openmp -----------------------------------------------------------------------------------
################################################################################
# - find openmp ----------------------------------------------------------------

find_package(OpenMP)
if(OpenMP_FOUND)
Expand All @@ -113,22 +113,20 @@ if(OpenMP_FOUND)
endif()


###################################################################################################
# - find blas -------------------------------------------------------------------------------------
################################################################################
# - find blas ------------------------------------------------------------------

if(NOT DEFINED BLAS_LIBRARIES)
find_package( BLAS REQUIRED )
else()
message(STATUS "Manually setting BLAS to ${BLAS_LIBRARIES}")
endif()

###################################################################################################
# - find CPM based dependencies ------------------------------------------------------------------

################################################################################
# - find CPM based dependencies -----------------------------------------------

rapids_cpm_init()


include(cmake/thirdparty/get_thrust.cmake)
include(cmake/thirdparty/get_faiss.cmake)
include(cmake/thirdparty/get_nccl.cmake)
Expand All @@ -145,9 +143,8 @@ if(BUILD_TESTS)
include(cmake/thirdparty/get_gtest.cmake)
endif()


###################################################################################################
# - library targets -------------------------------------------------------------------------------
################################################################################
# - libcugraph library target --------------------------------------------------

add_library(cugraph SHARED
src/detail/utility_wrappers.cu
Expand Down Expand Up @@ -218,6 +215,8 @@ add_library(cugraph SHARED
src/visitors/graph_envelope.cpp
src/visitors/visitors_factory.cpp
src/visitors/bfs_visitor.cpp
src/visitors/rw_visitor.cpp
Copy link
Contributor

Choose a reason for hiding this comment

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

So, do we plan to place bindings related files under the cugrpah/cpp directory? Or we'd better separate the core libcugraph from the bindings related files? (i.e. placing bindings related files under something like cugraph/bindings)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The visitor implementation is not restricted to bindings only. It's meant to be (and it is) used for implementation purposes, too. These are cpp files. There will be a separate branch for the C-only API.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then, what about creating a separate directory under the cpp (similar to tests)? Is this directly relevant to libcugraph users? (someone willing to directly use our C++ API). If not, I am not sure it is a good idea to include this in our core libcugraph_(sg|mg).so.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it is. As you probably know Visitor is useful to enrich the functionality of an object (visitee) without having to add new methods to it, which may inflate the code and cause merge conflicts on high traffic headers, like graph*.hpp .

The visitor abstraction is being used in RW, for example, for exactly such reasons.

Also, this structuring of this code has been in place for a while. And it has been extensively discussed before-hand (at least 2 presentations and demos have been done). Constantly shuffling code around after the fact is counterproductive, confusing, and wasteful. If new code restructuring is in the works, then this is not the PR for it. This PR has different goals. We've already agreed on small, targeted PRs as opposed to all-inclusive major code restructuring ones.

There's also the question of what exactly is the criterion for code cut-off to be accepted in cugraph. If this is to be discussed, then, again, maybe this is something to discuss before-fact, not after. I am starting to get the feeling that it's increasingly hard to get code accepted in cugraph and a lot of effort is potentially wasted with code shuffling and reshuffling on what appears to be quite ad-hoc and last-moment criteria.

src/visitors/graph_make_visitor.cpp
)

set_target_properties(cugraph
Expand Down Expand Up @@ -252,8 +251,9 @@ target_link_options(cugraph PRIVATE "${CUGRAPH_BINARY_DIR}/fatbin.ld")

add_library(cugraph::cugraph ALIAS cugraph)

###################################################################################################
# - include paths ---------------------------------------------------------------------------------
################################################################################
# - include paths --------------------------------------------------------------

target_include_directories(cugraph
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../thirdparty"
Expand All @@ -264,8 +264,8 @@ target_include_directories(cugraph
"$<INSTALL_INTERFACE:include>"
)

###################################################################################################
# - link libraries --------------------------------------------------------------------------------
################################################################################
# - link libraries -------------------------------------------------------------
target_link_libraries(cugraph
PUBLIC
rmm::rmm
Expand All @@ -285,7 +285,7 @@ target_link_libraries(cugraph

if(OpenMP_CXX_FOUND)
target_link_libraries(cugraph PRIVATE
###################################################################################################
################################################################################
### Use ${OpenMP_CXX_LIB_NAMES} instead of OpenMP::OpenMP_CXX to avoid the following warnings.
###
### Cannot generate a safe runtime search path for target TARGET_NAME
Expand Down Expand Up @@ -334,17 +334,62 @@ target_link_libraries(cugraph PRIVATE
${OpenMP_CXX_LIB_NAMES})
endif()

################################################################################
# - C-API library --------------------------------------------------------------

add_library(cugraph_c SHARED
src/c_api/cugraph_api.cpp
)
add_library(cugraph::cugraph_c ALIAS cugraph_c)

###################################################################################################
# - generate tests --------------------------------------------------------------------------------
# Currently presuming we aren't calling any CUDA kernels in cugraph_c

set_target_properties(cugraph_c
PROPERTIES BUILD_RPATH "\$ORIGIN"
INSTALL_RPATH "\$ORIGIN"
# set target compile options
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
INTERFACE_POSITION_INDEPENDENT_CODE ON
)

target_compile_options(cugraph_c
PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${CUGRAPH_CXX_FLAGS}>"
)

################################################################################
# - C-API include paths --------------------------------------------------------
target_include_directories(cugraph_c
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/src"
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>"
)

################################################################################
# - C-API link libraries -------------------------------------------------------
target_link_libraries(cugraph_c
PUBLIC
FAISS::FAISS
rlratzel marked this conversation as resolved.
Show resolved Hide resolved
CUDA::cublas
CUDA::curand
CUDA::cusolver
CUDA::cusparse
PRIVATE
cugraph::cugraph
)

################################################################################
# - generate tests -------------------------------------------------------------

if(BUILD_TESTS)
include(CTest)
add_subdirectory(tests)
endif()

###################################################################################################
# - install targets -------------------------------------------------------------------------------
################################################################################
# - install targets ------------------------------------------------------------
rapids_cmake_install_lib_dir( lib_dir )
include(CPack)

Expand All @@ -358,8 +403,18 @@ install(DIRECTORY include/cugraph/
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/cugraph/version_config.hpp
DESTINATION include/cugraph)

################################################################################################
# - install export -------------------------------------------------------------------------------
install(TARGETS cugraph_c
DESTINATION ${lib_dir})

install(DIRECTORY include/cugraph_c/
DESTINATION include/cugraph_c)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/cugraph_c/version_config.hpp
DESTINATION include/cugraph_c)

################################################################################
# - install export -------------------------------------------------------------

set(doc_string
[=[
Provide targets for cuGraph.
Expand All @@ -376,24 +431,24 @@ thrust_create_target(cugraph::Thrust FROM_OPTIONS)

rapids_export(INSTALL cugraph
EXPORT_SET cugraph-exports
GLOBAL_TARGETS cugraph
GLOBAL_TARGETS cugraph cugraph_c
NAMESPACE cugraph::
DOCUMENTATION doc_string
FINAL_CODE_BLOCK code_string
)

################################################################################################
# - build export -------------------------------------------------------------------------------
################################################################################
# - build export ---------------------------------------------------------------
rapids_export(BUILD cugraph
EXPORT_SET cugraph-exports
GLOBAL_TARGETS cugraph
GLOBAL_TARGETS cugraph cugraph_c
NAMESPACE cugraph::
DOCUMENTATION doc_string
FINAL_CODE_BLOCK code_string
)

###################################################################################################
# - make documentation ----------------------------------------------------------------------------
################################################################################
# - make documentation ---------------------------------------------------------
# requires doxygen and graphviz to be installed
# from build directory, run make docs_cugraph

Expand Down
10 changes: 6 additions & 4 deletions cpp/include/cugraph/algorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
#pragma once

#include <cugraph/api_helpers.hpp>

#include <cugraph/dendrogram.hpp>
#include <cugraph/graph.hpp>
#include <cugraph/graph_view.hpp>
Expand Down Expand Up @@ -1309,8 +1311,8 @@ extract_ego(raft::handle_t const& handle,
* (compressed) format; when padding is used the output is a matrix of vertex paths and a matrix of
* edges paths (weights); in this case the matrices are stored in row major order; the vertex path
* matrix is padded with `num_vertices` values and the weight matrix is padded with `0` values;
* @param selector_type identifier for sampling strategy: uniform, biased, etc.; possible
* values{0==uniform, 1==biased}; defaults to 0 == uniform;
* @param sampling_strategy pointer for sampling strategy: uniform, biased, etc.; possible
* values{0==uniform, 1==biased, 2==node2vec}; defaults to nullptr == uniform;
* @return std::tuple<rmm::device_uvector<vertex_t>, rmm::device_uvector<weight_t>,
* rmm::device_uvector<index_t>> Triplet of either padded or coalesced RW paths; in the coalesced
* case (default), the return consists of corresponding vertex and edge weights for each, and
Expand All @@ -1330,8 +1332,8 @@ random_walks(raft::handle_t const& handle,
typename graph_t::vertex_type const* ptr_d_start,
index_t num_paths,
index_t max_depth,
bool use_padding = false,
int selector_type = 0);
bool use_padding = false,
std::unique_ptr<sampling_params_t> sampling_strategy = nullptr);

/**
* @brief Finds (weakly-connected-)component IDs of each vertices in the input graph.
Expand Down
43 changes: 43 additions & 0 deletions cpp/include/cugraph/api_helpers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.
*/

// Andrei Schaffer, aschaffer@nvidia.com
//
// This is a collection of aggregates used by (parts of) the API defined in algorithms.hpp;
// These aggregates get propagated to the C-only API (which is why they're non-template aggregates)

#pragma once

namespace cugraph {

enum class sampling_strategy_t : int { UNIFORM = 0, BIASED, NODE2VEC };

struct sampling_params_t {
sampling_params_t(void) {}

sampling_params_t(int sampling_type, double p = 1.0, double q = 1.0)
: sampling_type_(static_cast<sampling_strategy_t>(sampling_type)), p_(p), q_(q)
{
}

sampling_strategy_t sampling_type_{sampling_strategy_t::UNIFORM};

// node2vec specific:
//
double p_;
double q_;
};
} // namespace cugraph
8 changes: 8 additions & 0 deletions cpp/include/cugraph/visitors/bfs_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ struct bfs_visitor<vertex_t,
static return_t r{};
return r;
}

return_t&& get_result(void) override
{
static return_t r{};
return std::move(r);
}
};

template <typename vertex_t, typename edge_t, typename weight_t, bool st, bool mg>
Expand All @@ -71,6 +77,8 @@ struct bfs_visitor<vertex_t,

return_t const& get_result(void) const override { return result_; }

return_t&& get_result(void) override { return std::move(result_); }

private:
erased_pack_t& ep_;
return_t result_;
Expand Down
Loading