Skip to content

Commit

Permalink
bfs: start migrating tests from bc to bfs
Browse files Browse the repository at this point in the history
  • Loading branch information
xcadet committed May 15, 2020
1 parent 3abcba8 commit 1f64548
Show file tree
Hide file tree
Showing 5 changed files with 348 additions and 61 deletions.
10 changes: 9 additions & 1 deletion cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,18 @@ ConfigureTest(PAGERANK_TEST "${PAGERANK_TEST_SRC}" "")
# - SSSP tests ------------------------------------------------------------------------------------
set(SSSP_TEST_SRCS
"${CMAKE_SOURCE_DIR}/../thirdparty/mmio/mmio.c"
"${CMAKE_CURRENT_SOURCE_DIR}/sssp/sssp_test.cu")
"${CMAKE_CURRENT_SOURCE_DIR}/traversal/sssp_test.cu")

ConfigureTest(SSSP_TEST "${SSSP_TEST_SRCS}" "")

###################################################################################################
# - BFS tests ------------------------------------------------------------------------------------
set(BFS_TEST_SRCS
"${CMAKE_SOURCE_DIR}/../thirdparty/mmio/mmio.c"
"${CMAKE_CURRENT_SOURCE_DIR}/traversal/bfs_test.cu")

ConfigureTest(BFS_TEST "${BFS_TEST_SRCS}" "")

###################################################################################################
# - LOUVAIN tests ---------------------------------------------------------------------------------

Expand Down
60 changes: 4 additions & 56 deletions cpp/tests/centrality/betweenness_centrality_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -242,42 +242,6 @@ template void reference_betweenness_centrality<int, int, double, double>(
// =============================================================================
// Utility functions
// =============================================================================
// FIXME: This could be useful in other testsuite (SSSP, BFS, ...)
template <typename VT, typename ET, typename WT>
void generate_graph_csr(CSR_Result_Weighted<VT, WT> &csr_result,
VT &m,
VT &nnz,
bool &is_directed,
std::string matrix_file)
{
FILE *fpin = fopen(matrix_file.c_str(), "r");
ASSERT_NE(fpin, nullptr) << "fopen (" << matrix_file << ") failure.";

VT k;
MM_typecode mc;
ASSERT_EQ(mm_properties<VT>(fpin, 1, &mc, &m, &k, &nnz), 0)
<< "could not read Matrix Market file properties"
<< "\n";
ASSERT_TRUE(mm_is_matrix(mc));
ASSERT_TRUE(mm_is_coordinate(mc));
ASSERT_FALSE(mm_is_complex(mc));
ASSERT_FALSE(mm_is_skew(mc));
is_directed = !mm_is_symmetric(mc);

// Allocate memory on host
std::vector<VT> cooRowInd(nnz), cooColInd(nnz);
std::vector<WT> cooVal(nnz);

// Read
ASSERT_EQ((mm_to_coo<VT, WT>(fpin, 1, nnz, &cooRowInd[0], &cooColInd[0], &cooVal[0], NULL)), 0)
<< "could not read matrix data"
<< "\n";
ASSERT_EQ(fclose(fpin), 0);

ConvertCOOtoCSR_weighted(&cooRowInd[0], &cooColInd[0], &cooVal[0], nnz, csr_result);
CUDA_CHECK_LAST();
}

// Compare while allowing relatie error of epsilon
// zero_threshold indicates when we should drop comparison for small numbers
template <typename T, typename precision_t>
Expand Down Expand Up @@ -340,7 +304,8 @@ class Tests_BC : public ::testing::TestWithParam<BC_Usecase> {
ET nnz;
CSR_Result_Weighted<VT, WT> csr_result;
bool is_directed = false;
generate_graph_csr<VT, ET, WT>(csr_result, m, nnz, is_directed, configuration.file_path_);
generate_graph_csr_from_mtx<VT, ET, WT>(
csr_result, m, nnz, is_directed, configuration.file_path_);
cudaDeviceSynchronize();
cugraph::experimental::GraphCSRView<VT, ET, WT> G(
csr_result.rowOffsets, csr_result.colIndices, csr_result.edgeWeights, m, nnz);
Expand Down Expand Up @@ -446,7 +411,8 @@ class Tests_BFS : public ::testing::TestWithParam<BFS_Usecase> {
ET nnz;
CSR_Result_Weighted<VT, WT> csr_result;
bool is_directed = false;
generate_graph_csr<VT, ET, WT>(csr_result, m, nnz, is_directed, configuration.file_path_);
generate_graph_csr_from_mtx<VT, ET, WT>(
csr_result, m, nnz, is_directed, configuration.file_path_);
cudaDeviceSynchronize();
cugraph::experimental::GraphCSRView<VT, ET, WT> G(
csr_result.rowOffsets, csr_result.colIndices, csr_result.edgeWeights, m, nnz);
Expand Down Expand Up @@ -517,8 +483,6 @@ class Tests_BFS : public ::testing::TestWithParam<BFS_Usecase> {
//==============================================================================
// Tests
//==============================================================================
// BC
// -----------------------------------------------------------------------------
// Verifiy Un-Normalized results
// Endpoint parameter is currently not usefull, is for later use
TEST_P(Tests_BC, CheckFP32_NO_NORMALIZE_NO_ENDPOINTS)
Expand Down Expand Up @@ -572,22 +536,6 @@ INSTANTIATE_TEST_CASE_P(simple_test,
BC_Usecase("test/datasets/wiki2003.mtx", 4),
BC_Usecase("test/datasets/wiki-Talk.mtx", 4)));

// BFS
// -----------------------------------------------------------------------------
// FIXME: This could be reused by Issue #778
TEST_P(Tests_BFS, CheckFP32) { run_current_test<int, int, float, float>(GetParam()); }

TEST_P(Tests_BFS, CheckFP64) { run_current_test<int, int, double, double>(GetParam()); }

INSTANTIATE_TEST_CASE_P(simple_test,
Tests_BFS,
::testing::Values(BFS_Usecase("test/datasets/karate.mtx", 0),
BFS_Usecase("test/datasets/polbooks.mtx", 0),
BFS_Usecase("test/datasets/netscience.mtx", 0),
BFS_Usecase("test/datasets/netscience.mtx", 100),
BFS_Usecase("test/datasets/wiki2003.mtx", 1000),
BFS_Usecase("test/datasets/wiki-Talk.mtx", 1000)));

int main(int argc, char **argv)
{
rmmInitialize(nullptr);
Expand Down
58 changes: 54 additions & 4 deletions cpp/tests/test_utils.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, NVIDIA CORPORATION.
* Copyright (c) 2019-2020, 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 @@ -47,9 +47,10 @@ extern "C" {
#include <rmm/rmm.h>

#include "cugraph.h"

#include "utilities/error_utils.h"

#include "converters/COOtoCSR.cuh"

#ifndef CUDA_RT_CALL
#define CUDA_RT_CALL(call) \
{ \
Expand Down Expand Up @@ -143,7 +144,7 @@ void printv(size_t n, T* vec, int offset)
dev_ptr + offset,
dev_ptr + offset + n,
std::ostream_iterator<T>(
std::cout, " ")); // Assume no RMM dependency; TODO: check / test (potential BUG !!!!!)
std::cout, " ")); // Assume no RMM dependency; FIXME: check / test (potential BUG !!!!!)
std::cout << std::endl;
}

Expand Down Expand Up @@ -841,8 +842,57 @@ bool gdf_csr_equal(gdf_column* a_off, gdf_column* a_ind, gdf_column* b_off, gdf_
return true;
}

// ============================================================================
// Generate data from an MTX, that can be used to Obtain a GraphCSRVIew
// ============================================================================
// FIXME: A similar function could be useful for CSC format
// There are functions above that operate coo -> csr and coo->csc
/**
* @tparam
*/
template <typename VT, typename ET, typename WT>
void generate_graph_csr_from_mtx(CSR_Result_Weighted<VT, WT>& csr_result,
VT& number_of_vertices,
VT& number_of_edges,
bool& directed,
std::string mtx_matrix_file)
{
FILE* fpin = fopen(mtx_matrix_file.c_str(), "r");
ASSERT_NE(fpin, nullptr) << "fopen (" << mtx_matrix_file << ") failure.";

VT number_of_columns = 0;
MM_typecode mm_typecode{0};
ASSERT_EQ(mm_properties<VT>(
fpin, 1, &mm_typecode, &number_of_vertices, &number_of_columns, &number_of_edges),
0)
<< "could not read Matrix Market file properties"
<< "\n";
ASSERT_TRUE(mm_is_matrix(mm_typecode));
ASSERT_TRUE(mm_is_coordinate(mm_typecode));
ASSERT_FALSE(mm_is_complex(mm_typecode));
ASSERT_FALSE(mm_is_skew(mm_typecode));
directed = !mm_is_symmetric(mm_typecode);

// Allocate memory on host
std::vector<VT> coo_row_ind(number_of_edges);
std::vector<VT> coo_col_ind(number_of_edges);
std::vector<WT> coo_val(number_of_edges);

// Read
ASSERT_EQ((mm_to_coo<VT, WT>(
fpin, 1, number_of_edges, &coo_row_ind[0], &coo_col_ind[0], &coo_val[0], NULL)),
0)
<< "could not read matrix data"
<< "\n";
ASSERT_EQ(fclose(fpin), 0);

ConvertCOOtoCSR_weighted(
&coo_row_ind[0], &coo_col_ind[0], &coo_val[0], number_of_edges, csr_result);
CUDA_CHECK_LAST();
}

////////////////////////////////////////////////////////////////////////////////
// TODO: move this code to rapids-core
// FIXME: move this code to rapids-core
////////////////////////////////////////////////////////////////////////////////

// Define RAPIDS_DATASET_ROOT_DIR using a preprocessor variable to
Expand Down
Loading

0 comments on commit 1f64548

Please sign in to comment.