diff --git a/gunrock/app/sm/sm_app.cu b/gunrock/app/sm/sm_app.cu index 414eaa337..9b9d14902 100644 --- a/gunrock/app/sm/sm_app.cu +++ b/gunrock/app/sm/sm_app.cu @@ -39,46 +39,35 @@ cudaError_t UseParameters(ParametersT ¶meters) { /* * @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 &query_graph, - gunrock::app::TestGraph &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++ diff --git a/gunrock/app/sm/sm_app.cuh b/gunrock/app/sm/sm_app.cuh index 6318a6240..4410c4f1e 100644 --- a/gunrock/app/sm/sm_app.cuh +++ b/gunrock/app/sm/sm_app.cuh @@ -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 - GraphT; + typedef typename gunrock::app::TestGraph GraphT; typedef typename GraphT::CsrT CsrT; // Setup parameters @@ -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 @@ -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 &query_graph, - gunrock::app::TestGraph &data_graph, - const int num_runs, - VertexT *subgraphs) -{ - typedef typename gunrock::app::TestGraph - 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("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++ diff --git a/unittests/test_lib_sm.h b/unittests/test_lib_sm.h new file mode 100644 index 000000000..ef1980f63 --- /dev/null +++ b/unittests/test_lib_sm.h @@ -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; + +} diff --git a/unittests/test_unittests.cu b/unittests/test_unittests.cu index 5252d23a2..c6cac0475 100644 --- a/unittests/test_unittests.cu +++ b/unittests/test_unittests.cu @@ -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"