Skip to content

Commit

Permalink
google test added
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurawly committed Oct 31, 2019
1 parent 02f5589 commit 3b24048
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 96 deletions.
45 changes: 17 additions & 28 deletions gunrock/app/sm/sm_app.cu
Original file line number Diff line number Diff line change
Expand Up @@ -39,46 +39,35 @@ cudaError_t UseParameters(ParametersT &parameters) {

/*
* @brief Simple interface take in graph as CSR format
* @param[in] num_nodes Number of veritces in the input graph
* @param[in] num_edges Number of edges in the input graph
* @param[in] row_offsets CSR-formatted graph input row offsets
* @param[in] col_indices CSR-formatted graph input column indices
* @param[in] edge_values CSR-formatted graph input edge weights
* @param[in] num_runs Number of runs to perform SM
* @param[out] subgraphs Return number of subgraphs
* \return double Return accumulated elapsed times for all runs
* @param[in] num_nodes Number of veritces in the input data graph
* @param[in] num_edges Number of edges in the input data graph
* @param[in] row_offsets CSR-formatted data graph input row offsets
* @param[in] col_indices CSR-formatted data graph input column indices
* @param[in] num_query_nodes Number of veritces in the input query graph
* @param[in] num_query_edges Number of edges in the input query graph
* @param[in] query_row_offsets CSR-formatted graph input query row offsets
* @param[in] query_col_indices CSR-formatted graph input query column indices
* @param[in] num_runs Number of runs to perform SM
* @param[out] subgraphs Return number of subgraphs
* \return double Return accumulated elapsed times for all runs
*/
double sm(
const int num_nodes,
const int num_edges,
const int *row_offsets,
const int *col_indices,
const unsigned long *edge_values,
const int num_query_nodes,
const int num_query_edges,
const int *query_row_offsets,
const int *query_col_indices,
const int num_runs,
int *subgraphs)
{
return sm(num_nodes, num_edges, row_offsets, col_indices,
edge_values, 1 /* num_runs */, subgraphs);
num_query_nodes, num_query_edges, query_row_offsets,
query_col_indices, 1 /* num_runs */, subgraphs);
}

/*
* @brief Simple interface take in graph as Gunrock format
* @param[in] query_graph Query graph to be searched
* @param[in] data_graph data graph to be searched on
* @param[in] num_runs Number of runs to perform SM
* @param[out] subgraphs Return number of subgraphs
* \return double Return accumulated elapsed times for all runs
*/
double nv_sm(
gunrock::app::TestGraph<int, int, unsigned long,
gunrock::graph::HAS_CSR> &query_graph,
gunrock::app::TestGraph<int, int, unsigned long,
gunrock::graph::HAS_CSR> &data_graph,
const int num_runs,
int *subgraphs)
{
return nv_sm(query_graph, data_graph, 1 /* num_runs */, subgraphs);
}
// Leave this at the end of the file
// Local Variables:
// mode:c++
Expand Down
90 changes: 22 additions & 68 deletions gunrock/app/sm/sm_app.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -187,31 +187,35 @@ double gunrock_sm(

/*
* @brief Simple interface take in graph as CSR format
* @param[in] num_nodes Number of veritces in the input graph
* @param[in] num_edges Number of edges in the input graph
* @param[in] row_offsets CSR-formatted graph input row offsets
* @param[in] col_indices CSR-formatted graph input column indices
* @param[in] edge_values CSR-formatted graph input edge weights
* @param[in] num_runs Number of runs to perform SM
* @param[out] subgraphs Return number of subgraphs
* \return double Return accumulated elapsed times for all runs
* @param[in] num_nodes Number of veritces in the input data graph
* @param[in] num_edges Number of edges in the input data graph
* @param[in] row_offsets CSR-formatted data graph input row offsets
* @param[in] col_indices CSR-formatted data graph input column indices
* @param[in] num_query_nodes Number of veritces in the input query graph
* @param[in] num_query_edges Number of edges in the input query graph
* @param[in] query_row_offsets CSR-formatted query graph input row offsets
* @param[in] query_col_indices CSR-formatted query graph input column indices
* @param[in] num_runs Number of runs to perform SM
* @param[out] subgraphs Return number of subgraphs
* \return double Return accumulated elapsed times for all runs
*/
template <
typename VertexT = int,
typename SizeT = int,
typename GValueT = unsigned long>
typename SizeT = int>
double sm(
const SizeT num_nodes,
const SizeT num_edges,
const SizeT *row_offsets,
const VertexT *col_indices,
const GValueT *edge_values,
const SizeT num_query_nodes,
const SizeT num_query_edges,
const SizeT *query_row_offsets,
const VertexT *query_col_indices,
const int num_runs,
VertexT *subgraphs)
{
typedef typename gunrock::app::TestGraph<VertexT, SizeT, GValueT,
gunrock::graph::HAS_CSR>
GraphT;
typedef typename gunrock::app::TestGraph<VertexT, SizeT,
gunrock::graph::HAS_CSR> GraphT;
typedef typename GraphT::CsrT CsrT;

// Setup parameters
Expand All @@ -229,9 +233,12 @@ double sm(
data_graph.CsrT::Allocate(num_nodes, num_edges, gunrock::util::HOST);
data_graph.CsrT::row_offsets .SetPointer((SizeT *)row_offsets, num_nodes + 1, gunrock::util::HOST);
data_graph.CsrT::column_indices.SetPointer((VertexT *)col_indices, num_edges, gunrock::util::HOST);
data_graph.CsrT::edge_values .SetPointer((GValueT *)edge_values, num_edges, gunrock::util::HOST);
data_graph.FromCsr(data_graph.csr(), true, quiet);
gunrock::graphio::LoadGraph(parameters, data_graph);
data_graph.CsrT::Allocate(num_query_nodes, num_query_edges, gunrock::util::HOST);
data_graph.CsrT::query_row_offsets .SetPointer((SizeT *)query_row_offsets, num_query_nodes + 1, gunrock::util::HOST);
data_graph.CsrT::query_column_indices.SetPointer((VertexT *)query_col_indices, num_query_edges, gunrock::util::HOST);
data_graph.FromCsr(query_graph.csr(), true, quiet);
gunrock::graphio::LoadGraph(parameters, query_graph, "pattern-");

// Run the SM
Expand All @@ -243,59 +250,6 @@ double sm(
return elapsed_time;
}

/*
* @brief Simple interface take in graph as Gunrock format
* @param[in] query_graph The query graph pattern to search
* @param[in] data_graph The data graph to search on
* @param[in] num_runs Number of runs to perform SM
* @param[out] subgraphs Return number of subgraphs
* \return double Return accumulated elapsed times for all runs
*/
template <
typename VertexT = int,
typename SizeT = int,
typename GValueT = unsigned long>
double nv_sm(
gunrock::app::TestGraph<VertexT, SizeT, GValueT,
gunrock::graph::HAS_CSR> &query_graph,
gunrock::app::TestGraph<VertexT, SizeT, GValueT,
gunrock::graph::HAS_CSR> &data_graph,
const int num_runs,
VertexT *subgraphs)
{
typedef typename gunrock::app::TestGraph<VertexT, SizeT, GValueT,
gunrock::graph::HAS_CSR>
GraphT;
typedef typename GraphT::CsrT CsrT;

// Setup parameters
gunrock::util::Parameters parameters("sm");
gunrock::graphio::UseParameters(parameters);
gunrock::app::sm::UseParameters(parameters);
gunrock::app::UseParameters_test(parameters);
parameters.Parse_CommandLine(0, NULL);
parameters.Set("graph-type", "by-pass");
parameters.Set("num-runs", num_runs);
bool quiet = parameters.Get<bool>("quiet");
// GraphT data_graph;
// GraphT query_graph;
// Assign pointers into gunrock graph format
/* data_graph.CsrT::Allocate(num_nodes, num_edges, gunrock::util::HOST);
data_graph.CsrT::row_offsets .SetPointer((SizeT *)row_offsets, num_nodes + 1, gunrock::util::HOST);
data_graph.CsrT::column_indices.SetPointer((VertexT *)col_indices, num_edges, gunrock::util::HOST);
data_graph.CsrT::edge_values .SetPointer((GValueT *)edge_values, num_edges, gunrock::util::HOST);
data_graph.FromCsr(data_graph.csr(), true, quiet);
gunrock::graphio::LoadGraph(parameters, data_graph);
gunrock::graphio::LoadGraph(parameters, query_graph, "pattern-");
*/
// Run the SM
double elapsed_time = gunrock_sm(parameters, data_graph, query_graph, subgraphs);
// Cleanup
// data_graph.Release();
// query_graph.Release();

return elapsed_time;
}
// Leave this at the end of the file
// Local Variables:
// mode:c++
Expand Down
31 changes: 31 additions & 0 deletions unittests/test_lib_sm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* @brief Subgraph matching test for shared library advanced interface
* @file test_lib_sm.h
*/

TEST(sharedlibrary, sm) {

int num_data_nodes = 5, num_data_edges = 5;
int data_row_offsets[6] = {0, 2, 6, 7, 9};
int data_col_indices[5] = {1, 3, 0, 2, 3};

int num_query_nodes = 3, num_query_edges = 3;
int query_row_offsets[4] = {0, 2, 4, 6};
int query_col_indices[3] = {1, 2, 0};

int *sm_counts = new int [num_data_nodes];

double elapsed = sm(num_data_nodes, num_data_edges, data_row_offsets,
data_col_indices, num_query_nodes, num_query_edges,
query_row_offsets, query_col_indices, 1, sm_counts);

double counts[5] = {1, 1, 0, 1, 0};

for (int node = 0; node < num_data_nodes; ++node) {
EXPECT_EQ(sm_counts[node], counts[node])
<< "Number of matched subgraphs differ at node index " << node;
}

delete[] sm_counts; sm_counts = NULL;

}
3 changes: 3 additions & 0 deletions unittests/test_unittests.cu
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
// bug:: malloc_consolidate(): invalid chunk size
//#include "test_lib_pr.h"

// Tests Subgraph Matching
#include "test_lib_sm.h"

// Tests the RepeatFor Operator
#include "test_repeatfor.h"

Expand Down

0 comments on commit 3b24048

Please sign in to comment.