-
Notifications
You must be signed in to change notification settings - Fork 0
essentials/sssp + cugraph #3
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
base: branch-21.06
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| conda env create --name cugraph_dev --file conda/environments/cugraph_dev_cuda11.0.yml | ||
| conda activate cugraph_dev | ||
|
|
||
| # fix version of gcc | ||
| sudo apt install gcc-8 g++-8 gcc-9 g++-9 gcc-10 g++-10 | ||
| sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 --slave /usr/bin/g++ g++ /usr/bin/g++-9 --slave /usr/bin/gcov gcov /usr/bin/gcov-9 | ||
|
|
||
| PARALLEL_LEVEL=12 ./build.sh clean | ||
|
|
||
| # libcugraph | ||
| cd cpp | ||
| mkdir build | ||
| cd build | ||
| cmake .. -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX | ||
| make -j | ||
| make install | ||
|
|
||
| cd ../../ | ||
| cd python | ||
| python setup.py build_ext --inplace | ||
| python setup.py install | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,7 +72,7 @@ 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) | ||
| option(BUILD_TESTS "Configure CMake to build tests" OFF) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. build faster |
||
|
|
||
| ################################################################################################### | ||
| # - compiler options ------------------------------------------------------------------------------ | ||
|
|
@@ -146,6 +146,7 @@ include(cmake/thirdparty/get_cuco.cmake) | |
| include(cmake/thirdparty/get_cuhornet.cmake) | ||
|
|
||
| include(cmake/thirdparty/get_gunrock.cmake) | ||
| include(cmake/thirdparty/get_essentials.cmake) | ||
|
|
||
| if(BUILD_TESTS) | ||
| include(cmake/thirdparty/get_gtest.cmake) | ||
|
|
@@ -164,6 +165,7 @@ add_library(cugraph SHARED | |
| src/link_analysis/gunrock_hits.cpp | ||
| src/traversal/bfs.cu | ||
| src/traversal/sssp.cu | ||
| src/traversal/gunrock_sssp.cu | ||
| src/traversal/tsp.cu | ||
| src/link_prediction/jaccard.cu | ||
| src/link_prediction/overlap.cu | ||
|
|
@@ -175,7 +177,7 @@ add_library(cugraph SHARED | |
| src/community/leiden.cu | ||
| src/community/ktruss.cu | ||
| src/community/ecg.cu | ||
| src/community/triangles_counting.cu | ||
| # src/community/triangles_counting.cu | ||
| src/community/extract_subgraph_by_vertex.cu | ||
| src/community/egonet.cu | ||
| src/sampling/random_walks.cu | ||
|
|
@@ -197,7 +199,7 @@ add_library(cugraph SHARED | |
| src/experimental/pagerank.cu | ||
| src/experimental/katz_centrality.cu | ||
| src/tree/mst.cu | ||
| src/components/weakly_connected_components.cu | ||
| # src/components/weakly_connected_components.cu | ||
| src/structure/create_graph_from_edgelist.cu | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. error building these maybe? |
||
| src/utilities/host_barrier.cpp | ||
| ) | ||
|
|
@@ -263,6 +265,7 @@ target_link_libraries(cugraph | |
| FAISS::FAISS | ||
| gunrock | ||
| NCCL::NCCL | ||
| essentials | ||
| ) | ||
|
|
||
| if(OpenMP_CXX_FOUND) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| function(find_and_configure_essentials) | ||
| rapids_cpm_find( | ||
| essentials 0.0 | ||
| GLOBAL_TARGETS essentials | ||
| CPM_ARGS | ||
| GIT_REPOSITORY https://github.com/gunrock/essentials/ | ||
| GIT_TAG 52ea059b1d824778e15fe3c240ffaf8f02e8a105 | ||
| OPTIONS "ESSENTIALS_BUILD_EXAMPLES OFF" | ||
| ) | ||
|
|
||
| if(NOT TARGET essentials) | ||
| add_library(essentials IMPORTED INTERFACE GLOBAL) | ||
| target_include_directories(essentials INTERFACE | ||
| "${essentials_SOURCE_DIR}/include" | ||
| ) | ||
| endif() | ||
| endfunction() | ||
|
|
||
| find_and_configure_essentials() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #include <algorithm> | ||
| #include <cugraph/utilities/error.hpp> | ||
|
|
||
| #include <cugraph/graph.hpp> | ||
|
|
||
| #include <gunrock/algorithms/sssp.hxx> | ||
|
|
||
| namespace cugraph { | ||
|
|
||
| namespace E = ::gunrock; // gunrock/essentials | ||
|
|
||
| template <typename VT, typename ET, typename WT> | ||
| void gunrock_sssp(GraphCSRView<VT, ET, WT> const &graph, | ||
| WT *distances, | ||
| VT *predecessors, | ||
| VT source_vertex) | ||
| { | ||
|
|
||
| printf("gunrock_sssp: ok\n"); | ||
|
|
||
| auto G = E::graph::build::from_csr<E::memory_space_t::device, E::graph::view_t::csr>( | ||
| graph.number_of_vertices, | ||
| graph.number_of_vertices, | ||
| graph.number_of_edges, | ||
| graph.offsets, | ||
| graph.indices, | ||
| graph.edge_data | ||
| ); | ||
|
|
||
| E::sssp::run(G, source_vertex, distances, predecessors); | ||
| } | ||
|
|
||
| // explicit instantiation | ||
| template void gunrock_sssp<int, int, float>(GraphCSRView<int, int, float> const &graph, | ||
| float *distances, | ||
| int *predecessors, | ||
| int source_vertex); | ||
|
|
||
| } // namespace cugraph | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the actual API call to essentials -- everything else in this pull is boilerplate wrappers + build stuff |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,15 +15,15 @@ | |
| ecg, | ||
| ktruss_subgraph, | ||
| k_truss, | ||
| louvain, | ||
| # louvain, | ||
| leiden, | ||
| spectralBalancedCutClustering, | ||
| spectralModularityMaximizationClustering, | ||
| analyzeClustering_modularity, | ||
| analyzeClustering_edge_cut, | ||
| analyzeClustering_ratio_cut, | ||
| subgraph, | ||
| triangles, | ||
| # triangles, | ||
| ego_graph, | ||
| batched_ego_graphs, | ||
| ) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe couldn't get these to build? didn't try very hard |
||
|
|
@@ -85,6 +85,7 @@ | |
| bfs, | ||
| bfs_edges, | ||
| sssp, | ||
| gunrock_sssp, | ||
| shortest_path, | ||
| filter_unreachable, | ||
| shortest_path_length, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from cugraph.structure.graph_utilities cimport * | ||
|
|
||
| cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": | ||
|
|
||
| cdef void call_gunrock_sssp[vertex_t, weight_t]( | ||
| const handle_t &handle, | ||
| const graph_container_t &g, | ||
| vertex_t *identifiers, | ||
| weight_t *distances, | ||
| vertex_t *predecessors, | ||
| vertex_t start_vertex) except + |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| from cugraph.traversal import gunrock_sssp_wrapper | ||
|
|
||
| def gunrock_sssp(G, source=0): | ||
| return gunrock_sssp_wrapper.gunrock_sssp(G, source) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| # Copyright (c) 2019-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. | ||
|
|
||
| # cython: profile=False | ||
| # distutils: language = c++ | ||
| # cython: embedsignature = True | ||
| # cython: language_level = 3 | ||
|
|
||
| cimport cugraph.traversal.gunrock_sssp as c_sssp | ||
| from cugraph.structure.graph_utilities cimport * | ||
| from cugraph.structure import graph_primtypes_wrapper | ||
| from libcpp cimport bool | ||
| from libc.stdint cimport uintptr_t | ||
| import cudf | ||
| import numpy as np | ||
|
|
||
|
|
||
| def gunrock_sssp(input_graph, source): | ||
| """ | ||
| Call sssp | ||
| """ | ||
| # Step 1: Declare the different variables | ||
| cdef graph_container_t graph_container | ||
| # FIXME: Offsets and indices are currently hardcoded to int, but this may | ||
| # not be acceptable in the future. | ||
| numberTypeMap = {np.dtype("int32") : <int>numberTypeEnum.int32Type, | ||
| np.dtype("float32") : <int>numberTypeEnum.floatType} | ||
|
|
||
| # Pointers required for CSR Graph | ||
| cdef uintptr_t c_offsets_ptr = <uintptr_t> NULL # Pointer to the CSR offsets | ||
| cdef uintptr_t c_indices_ptr = <uintptr_t> NULL # Pointer to the CSR indices | ||
| cdef uintptr_t c_weights_ptr = <uintptr_t> NULL # Pointer to the CSR weights | ||
| cdef uintptr_t c_local_verts = <uintptr_t> NULL; | ||
| cdef uintptr_t c_local_edges = <uintptr_t> NULL; | ||
| cdef uintptr_t c_local_offsets = <uintptr_t> NULL; | ||
| weight_t = np.dtype("float32") | ||
|
|
||
| # Pointers for SSSP / BFS | ||
| cdef uintptr_t c_identifier_ptr = <uintptr_t> NULL # Pointer to the DataFrame 'vertex' Series | ||
| cdef uintptr_t c_distance_ptr = <uintptr_t> NULL # Pointer to the DataFrame 'distance' Series | ||
| cdef uintptr_t c_predecessor_ptr = <uintptr_t> NULL # Pointer to the DataFrame 'predecessor' Series | ||
|
|
||
| cdef unique_ptr[handle_t] handle_ptr | ||
| handle_ptr.reset(new handle_t()) | ||
| handle_ = handle_ptr.get(); | ||
|
|
||
| # Step 2: Verify that input_graph has the expected format | ||
| # the SSSP implementation expects CSR format | ||
| if not input_graph.adjlist: | ||
| input_graph.view_adj_list() | ||
|
|
||
| # Step 3: Extract CSR offsets, indices and indices | ||
| # - offsets: int (signed, 32-bit) | ||
| # - indices: int (signed, 32-bit) | ||
| # - weights: float / double | ||
| # Extract data_type from weights (not None: float / double, None: signed int 32-bit) | ||
| [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) | ||
| [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) | ||
| c_offsets_ptr = offsets.__cuda_array_interface__['data'][0] | ||
| c_indices_ptr = indices.__cuda_array_interface__['data'][0] | ||
|
|
||
| if weights is not None: | ||
| weight_t = weights.dtype | ||
| c_weights_ptr = weights.__cuda_array_interface__['data'][0] | ||
|
|
||
| # Step 4: Setup number of vertices and number of edges | ||
| num_verts = input_graph.number_of_vertices() | ||
| num_edges = input_graph.number_of_edges(directed_edges=True) | ||
|
|
||
| # Step 5: Check if source index is valid | ||
| if not 0 <= source < num_verts: | ||
| raise ValueError("Starting vertex should be between 0 to number of vertices") | ||
|
|
||
| # Step 6: Generation of the result cudf.DataFrame | ||
| # Distances depends on data_type (c.f. Step 3) | ||
| df = cudf.DataFrame() | ||
|
|
||
| df['vertex'] = cudf.Series(np.zeros(num_verts, dtype=np.int32)) | ||
| df['distance'] = cudf.Series(np.zeros(num_verts, dtype=weight_t)) | ||
| df['predecessor'] = cudf.Series(np.zeros(num_verts, dtype=np.int32)) | ||
|
|
||
| # Step 7: Associate <uintptr_t> to cudf Series | ||
| c_identifier_ptr = df['vertex'].__cuda_array_interface__['data'][0] | ||
| c_distance_ptr = df['distance'].__cuda_array_interface__['data'][0] | ||
| c_predecessor_ptr = df['predecessor'].__cuda_array_interface__['data'][0] | ||
|
|
||
| # Step 8: Dispatch to SSSP / BFS Based on weights | ||
| # - weights is not None: SSSP float or SSSP double | ||
| # - weights is None: BFS | ||
| populate_graph_container_legacy(graph_container, | ||
| <graphTypeEnum>(<int>(graphTypeEnum.LegacyCSR)), | ||
| handle_[0], | ||
| <void*>c_offsets_ptr, <void*>c_indices_ptr, <void*>c_weights_ptr, | ||
| <numberTypeEnum>(<int>(numberTypeEnum.int32Type)), | ||
| <numberTypeEnum>(<int>(numberTypeEnum.int32Type)), | ||
| <numberTypeEnum>(<int>(numberTypeMap[weight_t])), | ||
| num_verts, num_edges, | ||
| <int*>c_local_verts, <int*>c_local_edges, <int*>c_local_offsets) | ||
|
|
||
| if weight_t == np.float32: | ||
| c_sssp.call_gunrock_sssp[int, float](handle_[0], | ||
| graph_container, | ||
| <int*> c_identifier_ptr, | ||
| <float*> c_distance_ptr, | ||
| <int*> c_predecessor_ptr, | ||
| <int> source) | ||
| else: # This case should not happen | ||
| raise NotImplementedError | ||
|
|
||
| return df | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrapper of SSSP method -- stolen from cugraph's sssp implementation |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scratch build commands