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

Migrate SG and MG BFS to pylibcugraph #2284

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fb2d21c
Merge pull request #1 from rapidsai/branch-22.06
alexbarghi-nv May 16, 2022
cfdb13b
Merge branch 'rapidsai:branch-22.06' into branch-22.06
alexbarghi-nv May 17, 2022
29f6a8b
sg and mg bfs plc migration work
alexbarghi-nv May 17, 2022
3c00af1
remove cufile
alexbarghi-nv May 17, 2022
47388f8
Merge remote-tracking branch 'origin/branch-22.06' into branch-22.06-…
alexbarghi-nv May 17, 2022
a151b63
Merge pull request #2 from rapidsai/branch-22.06
alexbarghi-nv May 17, 2022
764782a
Merge remote-tracking branch 'origin/branch-22.06' into branch-22.06-…
alexbarghi-nv May 17, 2022
42c9e16
add bfs mg c api test, small fixes
alexbarghi-nv May 18, 2022
af0eb2a
remove testing files
alexbarghi-nv May 18, 2022
97b76e7
update mg bfs test
alexbarghi-nv May 19, 2022
3b9914f
Add Alex B's mg_bfs_test, add mg_sssp_test, fix support for MG in bfs…
ChuckHastings May 19, 2022
0dbe0b5
Merge pull request #3 from ChuckHastings/fix_add_shuffle_to_capi_algo…
alexbarghi-nv May 19, 2022
59f3760
add updates
alexbarghi-nv May 20, 2022
9d61c35
fixes
alexbarghi-nv May 20, 2022
969a56a
various fixes
alexbarghi-nv May 20, 2022
d2323ab
Remove test files
alexbarghi-nv May 20, 2022
e743538
add line at end of file
alexbarghi-nv May 20, 2022
a7eaefc
fix style
alexbarghi-nv May 20, 2022
3c08809
fix style
alexbarghi-nv May 20, 2022
0651f13
remove experimental warning, fix build issue
alexbarghi-nv May 20, 2022
9cac9ed
Delete cufile.log
alexbarghi-nv May 20, 2022
9f074a3
remove old wrappers
alexbarghi-nv May 20, 2022
c5fc19a
Merge branch 'branch-22.06-pylibcugraph-bfs' of https://github.com/al…
alexbarghi-nv May 20, 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/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ if(BUILD_CUGRAPH_MG_TESTS)
ConfigureCTestMG(MG_CAPI_HITS c_api/mg_hits_test.c c_api/mg_test_utils.cpp)
ConfigureCTestMG(MG_CAPI_UNIFORM_NEIGHBOR_SAMPLE c_api/mg_uniform_neighbor_sample_test.c c_api/mg_test_utils.cpp)
ConfigureCTestMG(MG_CAPI_TRIANGLE_COUNT c_api/mg_triangle_count_test.c c_api/mg_test_utils.cpp)
ConfigureCTestMG(MG_CAPI_BFS c_api/mg_bfs_test.c c_api/mg_test_utils.cpp)
alexbarghi-nv marked this conversation as resolved.
Show resolved Hide resolved
else()
message(FATAL_ERROR "OpenMPI NOT found, cannot build MG tests.")
endif()
Expand Down
182 changes: 182 additions & 0 deletions cpp/tests/c_api/mg_bfs_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
* 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.
* 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 "mg_test_utils.h" /* RUN_TEST */

#include <cugraph_c/algorithms.h>
#include <cugraph_c/graph.h>

#include <math.h>

typedef int32_t vertex_t;
typedef int32_t edge_t;
typedef float weight_t;

int generic_bfs_test(
const cugraph_resource_handle_t* p_handle,
vertex_t* h_src,
vertex_t* h_dst,
weight_t* h_wgt,
vertex_t* h_seeds,
vertex_t const* expected_distances,
vertex_t const* expected_predecessors,
size_t num_vertices,
size_t num_edges,
size_t num_seeds,
size_t depth_limit,
bool_t store_transposed) {
int test_ret_value = 0;

cugraph_error_code_t ret_code = CUGRAPH_SUCCESS;
cugraph_error_t* ret_error;

cugraph_graph_t* p_graph = NULL;
cugraph_paths_result_t* paths_result = NULL;
cugraph_type_erased_device_array_t* p_sources = NULL;
cugraph_type_erased_device_array_view_t* p_source_view = NULL;

ret_code =
cugraph_type_erased_device_array_create(p_handle, num_seeds, INT32, &p_sources, &ret_error);
TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "p_sources create failed.");

p_source_view = cugraph_type_erased_device_array_view(p_sources);

ret_code = cugraph_type_erased_device_array_view_copy_from_host(
p_handle, p_source_view, (byte_t*)h_seeds, &ret_error);
TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "src copy_from_host failed.");

ret_code = create_mg_test_graph(
p_handle, h_src, h_dst, h_wgt, num_edges, store_transposed, FALSE, &p_graph, &ret_error);

TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "create_mg_test_graph failed.");

ret_code = cugraph_bfs(p_handle,
p_graph,
p_source_view,
FALSE,
10000000,
TRUE,
TRUE,
&paths_result,
&ret_error);

TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error));
TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "cugraph_bfs failed.");

cugraph_type_erased_device_array_view_t* vertices;
cugraph_type_erased_device_array_view_t* distances;
cugraph_type_erased_device_array_view_t* predecessors;

vertices = cugraph_paths_result_get_vertices(paths_result);
predecessors = cugraph_paths_result_get_predecessors(paths_result);
distances = cugraph_paths_result_get_distances(paths_result);

vertex_t h_vertices[num_vertices];
vertex_t h_predecessors[num_vertices];
vertex_t h_distances[num_vertices];

ret_code = cugraph_type_erased_device_array_view_copy_to_host(
p_handle, (byte_t*)h_vertices, vertices, &ret_error);
TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "copy_to_host failed.");

ret_code = cugraph_type_erased_device_array_view_copy_to_host(
p_handle, (byte_t*)h_distances, distances, &ret_error);
TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "copy_to_host failed.");

ret_code = cugraph_type_erased_device_array_view_copy_to_host(
p_handle, (byte_t*)h_predecessors, predecessors, &ret_error);
TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "copy_to_host failed.");

size_t num_local_vertices = cugraph_type_erased_device_array_view_size(vertices);

for (int i = 0; (i < num_local_vertices) && (test_ret_value == 0); ++i) {
printf("%d %d\n", expected_distances[h_vertices[i]], h_distances[i]);
TEST_ASSERT(test_ret_value,
expected_distances[h_vertices[i]] == h_distances[i],
"bfs distances don't match");


printf("%d %d\n", expected_predecessors[h_vertices[i]], h_predecessors[i]);
TEST_ASSERT(test_ret_value,
expected_predecessors[h_vertices[i]] == h_predecessors[i],
"bfs predecessors don't match");
}

cugraph_paths_result_free(paths_result);
cugraph_mg_graph_free(p_graph);
cugraph_error_free(ret_error);

return test_ret_value;
}

int test_bfs(const cugraph_resource_handle_t* p_handle)
{
size_t num_edges = 8;
size_t num_vertices = 6;

vertex_t src[] = {0, 1, 1, 2, 2, 2, 3, 4};
vertex_t dst[] = {1, 3, 4, 0, 1, 3, 5, 5};
weight_t wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f};
vertex_t seeds[] = {0};
vertex_t expected_distances[] = {0, 1, 2147483647, 2, 2, 3};
vertex_t expected_predecessors[] = {-1, 0, -1, 1, 1, 3};

// Bfs wants store_transposed = FALSE
return generic_bfs_test(p_handle,
src,
dst,
wgt,
seeds,
expected_distances,
expected_predecessors,
num_vertices,
num_edges,
1,
10,
FALSE);
}

int main(int argc, char** argv)
{
// Set up MPI:
int comm_rank;
int comm_size;
int num_gpus_per_node;
cudaError_t status;
int mpi_status;
cugraph_resource_handle_t* handle = NULL;
cugraph_error_t* ret_error;
cugraph_error_code_t ret_code = CUGRAPH_SUCCESS;
int prows = 1;

C_MPI_TRY(MPI_Init(&argc, &argv));
C_MPI_TRY(MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank));
C_MPI_TRY(MPI_Comm_size(MPI_COMM_WORLD, &comm_size));
C_CUDA_TRY(cudaGetDeviceCount(&num_gpus_per_node));
C_CUDA_TRY(cudaSetDevice(comm_rank % num_gpus_per_node));

void* raft_handle = create_raft_handle(prows);
handle = cugraph_create_resource_handle(raft_handle);
int result = 0;
result |= RUN_MG_TEST(test_bfs, handle);

cugraph_free_resource_handle(handle);
free_raft_handle(raft_handle);

C_MPI_TRY(MPI_Finalize());

return result;
}
1 change: 1 addition & 0 deletions python/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.cpp
__pycache__
testing
Loading