From 659677db329defd0f1e0e117b9cc163eb042e101 Mon Sep 17 00:00:00 2001 From: Brian Kelley Date: Fri, 10 Sep 2021 10:26:25 -0600 Subject: [PATCH 1/3] Added test for C's dimensions in spadd (simplified interface) --- unit_test/sparse/Test_Sparse_spadd.hpp | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/unit_test/sparse/Test_Sparse_spadd.hpp b/unit_test/sparse/Test_Sparse_spadd.hpp index f474ce82a2..12de662ee0 100644 --- a/unit_test/sparse/Test_Sparse_spadd.hpp +++ b/unit_test/sparse/Test_Sparse_spadd.hpp @@ -192,12 +192,58 @@ void test_spadd(lno_t numRows, lno_t numCols, size_type minNNZ, size_type maxNNZ } } +//Test spadd simplified interface: make sure C's dimensions match A and B, even when there are empty rows/cols +template +void test_spadd_known_columns() +{ + using crsMat_t = typename KokkosSparse::CrsMatrix; + using row_map_type = typename crsMat_t::row_map_type::non_const_type; + using entries_type = typename crsMat_t::index_type::non_const_type; + using values_type = typename crsMat_t::values_type::non_const_type; + using KAT = Kokkos::ArithTraits; + using KernelHandle = typename KokkosKernels::Experimental::KokkosKernelsHandle; + //Create A and B as 4x4 identity matrix, at the top-left of a 6x7 matrix of zeros + int nrows = 6; + int ncols = 7; + row_map_type Arowmap("rowmap", nrows + 1); + entries_type Aentries("rowmap", 4); + values_type Avalues("rowmap", 4); + { + auto rowmapHost = Kokkos::create_mirror_view(Arowmap); + auto entriesHost = Kokkos::create_mirror_view(Aentries); + auto valuesHost = Kokkos::create_mirror_view(Avalues); + for(int i = 0; i < 5; i++) + rowmapHost(i) = i; + for(int i = 5; i < nrows + 1; i++) + rowmapHost(i) = rowmapHost(i - 1); + for(int i = 0; i < 4; i++) + { + entriesHost(i) = i; + valuesHost(i) = KAT::one(); + } + Kokkos::deep_copy(Arowmap, rowmapHost); + Kokkos::deep_copy(Aentries, entriesHost); + Kokkos::deep_copy(Avalues, valuesHost); + } + crsMat_t A("A", nrows, ncols, 4, Avalues, Arowmap, Aentries); + crsMat_t C; + KernelHandle kh; + kh.create_spadd_handle(true); + KokkosSparse::spadd_symbolic(&kh, A, A, C); + KokkosSparse::spadd_numeric(&kh, KAT::one(), A, KAT::one(), A, C); + ASSERT_EQ(nrows, C.numRows()); + ASSERT_EQ(ncols, C.numCols()); + ASSERT_EQ(A.nnz(), C.nnz()); +} + #define EXECUTE_TEST(SCALAR, ORDINAL, OFFSET, DEVICE) \ TEST_F( TestCategory,sparse ## _ ## spadd_sorted_input ## _ ## SCALAR ## _ ## ORDINAL ## _ ## OFFSET ## _ ## DEVICE ) { \ test_spadd (10, 10, 0, 0, true); \ test_spadd (10, 10, 0, 2, true); \ test_spadd (100, 100, 50, 100, true); \ test_spadd (50, 50, 75, 100, true); \ + test_spadd_known_columns (); \ } \ TEST_F( TestCategory,sparse ## _ ## spadd_unsorted_input ## _ ## SCALAR ## _ ## ORDINAL ## _ ## OFFSET ## _ ## DEVICE ) { \ test_spadd (10, 10, 0, 0, false); \ From d4de6ca7890f192aea34b7e3489f5d0749a2c85e Mon Sep 17 00:00:00 2001 From: Brian Kelley Date: Fri, 10 Sep 2021 10:29:55 -0600 Subject: [PATCH 2/3] Fix C's dimensions in spadd simplified interface Also skips the "maximum_entry" kernel in CrsMatrix, which takes O(nnz) --- src/sparse/KokkosSparse_spadd.hpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/sparse/KokkosSparse_spadd.hpp b/src/sparse/KokkosSparse_spadd.hpp index 811c4c319c..ffa9866fc8 100644 --- a/src/sparse/KokkosSparse_spadd.hpp +++ b/src/sparse/KokkosSparse_spadd.hpp @@ -934,15 +934,12 @@ void spadd_symbolic(KernelHandle* handle, const AMatrix& A, const BMatrix& B, auto addHandle = handle->get_spadd_handle(); entries_type entriesC(Kokkos::view_alloc(Kokkos::WithoutInitializing, "entries"), addHandle->get_c_nnz()); - graph_type graphC(entriesC, row_mapC); - C = CMatrix("matrix", graphC); - // Finally since we already have the number of nnz handy // we can go ahead and allocate C's values and set them. values_type valuesC(Kokkos::view_alloc(Kokkos::WithoutInitializing, "values"), addHandle->get_c_nnz()); - C.values = valuesC; + C = CMatrix("matrix", A.numRows(), A.numCols(), addHandle->get_c_nnz(), valuesC, row_mapC, entriesC); } // Symbolic: count entries in each row in C to produce rowmap From 9f5887c461ce3c652bcaebd269adc2ca642888f7 Mon Sep 17 00:00:00 2001 From: Luc Berger Date: Fri, 10 Sep 2021 15:15:43 -0600 Subject: [PATCH 3/3] Remove unused type definition As we switch from graph constructor to view constructor we do not need the graph type anymore --- src/sparse/KokkosSparse_spadd.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sparse/KokkosSparse_spadd.hpp b/src/sparse/KokkosSparse_spadd.hpp index ffa9866fc8..f72c06b19c 100644 --- a/src/sparse/KokkosSparse_spadd.hpp +++ b/src/sparse/KokkosSparse_spadd.hpp @@ -912,7 +912,6 @@ template void spadd_symbolic(KernelHandle* handle, const AMatrix& A, const BMatrix& B, CMatrix& C) { - using graph_type = typename CMatrix::staticcrsgraph_type; using row_map_type = typename CMatrix::row_map_type::non_const_type; using entries_type = typename CMatrix::index_type::non_const_type; using values_type = typename CMatrix::values_type::non_const_type;