Skip to content

Commit

Permalink
SPRASE- SpADD: moving spadd out of experimental
Browse files Browse the repository at this point in the history
Signed-off-by: Luc Berger-Vergiat <[email protected]>
  • Loading branch information
lucbv committed Feb 4, 2025
1 parent bda4562 commit e5f91f0
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 11 deletions.
6 changes: 3 additions & 3 deletions perf_test/sparse/KokkosSparse_spadd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void run_experiment(int argc, char** argv, CommonInputParams) {
double numericTime = 0;

// Do an untimed warm up symbolic, and preallocate space for C entries/values
spadd_symbolic(exec_space{}, &kh, A.numRows(), A.numCols(), A.graph.row_map, A.graph.entries, B.graph.row_map,
KokkosSparse::spadd_symbolic(exec_space{}, &kh, A.numRows(), A.numCols(), A.graph.row_map, A.graph.entries, B.graph.row_map,
B.graph.entries, row_mapC);

bool use_kk = !params.use_cusparse && !params.use_mkl;
Expand Down Expand Up @@ -312,7 +312,7 @@ void run_experiment(int argc, char** argv, CommonInputParams) {
for (int sumRep = 0; sumRep < params.repeat; sumRep++) {
timer.reset();
if (use_kk) {
spadd_symbolic(exec_space{}, &kh, A.numRows(), A.numCols(), A.graph.row_map, A.graph.entries, B.graph.row_map,
KokkosSparse::spadd_symbolic(exec_space{}, &kh, A.numRows(), A.numCols(), A.graph.row_map, A.graph.entries, B.graph.row_map,
B.graph.entries, row_mapC);
c_nnz = addHandle->get_c_nnz();
} else if (params.use_cusparse) {
Expand Down Expand Up @@ -365,7 +365,7 @@ void run_experiment(int argc, char** argv, CommonInputParams) {
}
#endif
} else {
spadd_numeric(exec_space{}, &kh, A.numRows(), A.numCols(), A.graph.row_map, A.graph.entries, A.values,
KokkosSparse::spadd_numeric(exec_space{}, &kh, A.numRows(), A.numCols(), A.graph.row_map, A.graph.entries, A.values,
1.0, // A, alpha
B.graph.row_map, B.graph.entries, B.values,
1.0, // B, beta
Expand Down
4 changes: 2 additions & 2 deletions sparse/impl/KokkosSparse_par_ilut_numeric_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,14 +621,14 @@ struct IlutWrap {
// TODO: let compute_residual_norm also take an execution space argument and
// use that for exec!
typename KHandle::HandleExecSpace exec{};
KokkosSparse::Experimental::spadd_symbolic(exec, &kh, m, n, A_row_map, A_entries, LU_row_map, LU_entries,
KokkosSparse::spadd_symbolic(exec, &kh, m, n, A_row_map, A_entries, LU_row_map, LU_entries,
R_row_map);

const size_type r_nnz = addHandle->get_c_nnz();
Kokkos::resize(exec, R_entries, r_nnz);
Kokkos::resize(exec, R_values, r_nnz);

KokkosSparse::Experimental::spadd_numeric(exec, &kh, m, n, A_row_map, A_entries, A_values, 1., LU_row_map,
KokkosSparse::spadd_numeric(exec, &kh, m, n, A_row_map, A_entries, A_values, 1., LU_row_map,
LU_entries, LU_values, -1., R_row_map, R_entries, R_values);
// TODO: how to make this policy use exec?
auto policy = ih.get_default_team_policy();
Expand Down
53 changes: 49 additions & 4 deletions sparse/src/KokkosSparse_spadd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "KokkosSparse_spadd_symbolic_spec.hpp"

namespace KokkosSparse {
namespace Experimental {

// Symbolic: count entries in each row in C to produce rowmap
// kernel handle has information about whether it is sorted add or not.
Expand Down Expand Up @@ -199,7 +198,6 @@ template <typename KernelHandle, typename... Args>
void spadd_numeric(KernelHandle *handle, Args... args) {
spadd_numeric(typename KernelHandle::HandleExecSpace{}, handle, args...);
}
} // namespace Experimental

// Symbolic: count entries in each row in C to produce rowmap
// kernel handle has information about whether it is sorted add or not.
Expand All @@ -223,7 +221,7 @@ void spadd_symbolic(const ExecSpace &exec, KernelHandle *handle, const AMatrix &
Kokkos::deep_copy(exec, row_mapC, A.graph.row_map);
addHandle->set_c_nnz(A.graph.entries.extent(0));
} else {
KokkosSparse::Experimental::spadd_symbolic(exec, handle, A.numRows(), A.numCols(), A.graph.row_map, A.graph.entries,
KokkosSparse::spadd_symbolic(exec, handle, A.numRows(), A.numCols(), A.graph.row_map, A.graph.entries,
B.graph.row_map, B.graph.entries, row_mapC);
}

Expand Down Expand Up @@ -251,7 +249,7 @@ void spadd_numeric(const ExecSpace &exec, KernelHandle *handle, const AScalar al
Kokkos::deep_copy(exec, C.graph.entries, A.graph.entries);
KokkosBlas::scal(exec, C.values, alpha, A.values);
} else {
KokkosSparse::Experimental::spadd_numeric(exec, handle, A.numRows(), A.numCols(), A.graph.row_map, A.graph.entries,
KokkosSparse::spadd_numeric(exec, handle, A.numRows(), A.numCols(), A.graph.row_map, A.graph.entries,
A.values, alpha, B.graph.row_map, B.graph.entries, B.values, beta,
C.graph.row_map, C.graph.entries, C.values);
}
Expand All @@ -270,6 +268,53 @@ void spadd_numeric(KernelHandle *handle, const AScalar alpha, const AMatrix &A,
spadd_numeric(typename AMatrix::execution_space{}, handle, alpha, A, beta, B, C);
}

// Pre-promotion namespace being deprecated for move
// to main namespace
namespace Experimental {

template <typename ExecSpace, typename KernelHandle, typename alno_row_view_t_, typename alno_nnz_view_t_,
typename blno_row_view_t_, typename blno_nnz_view_t_, typename clno_row_view_t_>
[[deprecated("spadd_symbolic was promoted out of Experimental, please use KokkosSparse::spadd_symbolic instead.")]]
void spadd_symbolic(const ExecSpace &exec, KernelHandle *handle,
typename KernelHandle::const_nnz_lno_t m, // same type as column indices
typename KernelHandle::const_nnz_lno_t n, const alno_row_view_t_ a_rowmap,
const alno_nnz_view_t_ a_entries, const blno_row_view_t_ b_rowmap, const blno_nnz_view_t_ b_entries,
clno_row_view_t_ c_rowmap) {
KokkosSparse::spadd_symbolic(exec, handle, m, n, a_rowmap, a_entries, b_rowmap, b_entries, c_rowmap);
}

// one without an execution space arg
template <typename KernelHandle, typename... Args>
[[deprecated("spadd_symbolic was promoted out of Experimental, please use KokkosSparse::spadd_symbolic instead.")]]
void spadd_symbolic(KernelHandle *handle, Args... args) {
KokkosSparse::spadd_symbolic(typename KernelHandle::HandleExecSpace{}, handle, args...);
}

template <typename ExecSpace, typename KernelHandle, typename alno_row_view_t_, typename alno_nnz_view_t_,
typename ascalar_t_, typename ascalar_nnz_view_t_, typename blno_row_view_t_, typename blno_nnz_view_t_,
typename bscalar_t_, typename bscalar_nnz_view_t_, typename clno_row_view_t_, typename clno_nnz_view_t_,
typename cscalar_nnz_view_t_>
[[deprecated("spadd_numeric was promoted out of Experimental, please use KokkosSparse::spadd_numeric instead.")]]
void spadd_numeric(const ExecSpace &exec, KernelHandle *handle, typename KernelHandle::const_nnz_lno_t m,
typename KernelHandle::const_nnz_lno_t n, const alno_row_view_t_ a_rowmap,
const alno_nnz_view_t_ a_entries, const ascalar_nnz_view_t_ a_values, const ascalar_t_ alpha,
const blno_row_view_t_ b_rowmap, const blno_nnz_view_t_ b_entries,
const bscalar_nnz_view_t_ b_values, const bscalar_t_ beta, const clno_row_view_t_ c_rowmap,
clno_nnz_view_t_ c_entries, cscalar_nnz_view_t_ c_values) {

KokkosSparse::spadd_numeric(exec, handle, m, n, a_rowmap, a_entries, a_values, alpha, b_rowmap, b_entries, b_values, beta, c_rowmap, c_entries, c_values);

}

// one without an execution space arg
template <typename KernelHandle, typename... Args>
[[deprecated("spadd_numeric was promoted out of Experimental, please use KokkosSparse::spadd_numeric instead.")]]
void spadd_numeric(KernelHandle *handle, Args... args) {

KokkosSparse::spadd_numeric(handle, args...);

}
} // namespace Experimental
} // namespace KokkosSparse

#undef SAME_TYPE
Expand Down
4 changes: 2 additions & 2 deletions sparse/unit_test/Test_Sparse_spadd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ void test_spadd(lno_t numRows, lno_t numCols, size_type minNNZ, size_type maxNNZ
Kokkos::deep_copy(c_row_map, (size_type)5);
auto addHandle = handle.get_spadd_handle();
typename Device::execution_space exec{};
KokkosSparse::Experimental::spadd_symbolic(exec, &handle, numRows, numCols, A.graph.row_map, A.graph.entries,
KokkosSparse::spadd_symbolic(exec, &handle, numRows, numCols, A.graph.row_map, A.graph.entries,
B.graph.row_map, B.graph.entries, c_row_map);
size_type c_nnz = addHandle->get_c_nnz();
// Fill values, entries with incorrect incorret
values_type c_values(Kokkos::view_alloc(Kokkos::WithoutInitializing, "C values"), c_nnz);
Kokkos::deep_copy(c_values, ((typename KAT::mag_type)5) * KAT::one());
entries_type c_entries("C entries", c_nnz);
Kokkos::deep_copy(c_entries, (lno_t)5);
KokkosSparse::Experimental::spadd_numeric(exec, &handle, numRows, numCols, A.graph.row_map, A.graph.entries, A.values,
KokkosSparse::spadd_numeric(exec, &handle, numRows, numCols, A.graph.row_map, A.graph.entries, A.values,
KAT::one(), B.graph.row_map, B.graph.entries, B.values, KAT::one(),
c_row_map, c_entries, c_values);
// done with handle
Expand Down

0 comments on commit e5f91f0

Please sign in to comment.