Skip to content

Commit

Permalink
GMRES: fixing some type issues related to memory space instantiation
Browse files Browse the repository at this point in the history
Basically one wants to be very careful about only instantiating View
or other object with an execution space only as it might generate a
memory type mismatch down the road
  • Loading branch information
lucbv authored and ndellingwood committed Mar 6, 2023
1 parent 3831a68 commit 1ae5b7d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
6 changes: 4 additions & 2 deletions example/gmres/test_prec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ int main(int argc, char* argv[]) {
using OT = int;
using EXSP = Kokkos::DefaultExecutionSpace;
using MESP = typename EXSP::memory_space;
using CRS = KokkosSparse::CrsMatrix<ST, OT, EXSP, void, OT>;
using CRS =
KokkosSparse::CrsMatrix<ST, OT, Kokkos::Device<EXSP, MESP>, void, OT>;

using ViewVectorType = Kokkos::View<ST*, Kokkos::LayoutLeft, EXSP>;
using ViewVectorType =
Kokkos::View<ST*, Kokkos::LayoutLeft, Kokkos::Device<EXSP, MESP>>;
using KernelHandle =
KokkosKernels::Experimental::KokkosKernelsHandle<OT, OT, ST, EXSP, MESP,
MESP>;
Expand Down
11 changes: 6 additions & 5 deletions sparse/src/KokkosSparse_MatrixPrec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class MatrixPrec : public KokkosSparse::Experimental::Preconditioner<CRS> {
public:
using ScalarType = typename std::remove_const<typename CRS::value_type>::type;
using EXSP = typename CRS::execution_space;
using MEMSP = typename CRS::memory_space;
using karith = typename Kokkos::ArithTraits<ScalarType>;

//! Constructor:
Expand All @@ -80,11 +81,11 @@ class MatrixPrec : public KokkosSparse::Experimental::Preconditioner<CRS> {
///\cdot X\f$.
///// The typical case is \f$\beta = 0\f$ and \f$\alpha = 1\f$.
//
virtual void apply(const Kokkos::View<const ScalarType *, EXSP> &X,
const Kokkos::View<ScalarType *, EXSP> &Y,
const char transM[] = "N",
ScalarType alpha = karith::one(),
ScalarType beta = karith::zero()) const {
virtual void apply(
const Kokkos::View<const ScalarType *, Kokkos::Device<EXSP, MEMSP>> &X,
const Kokkos::View<ScalarType *, Kokkos::Device<EXSP, MEMSP>> &Y,
const char transM[] = "N", ScalarType alpha = karith::one(),
ScalarType beta = karith::zero()) const {
KokkosSparse::spmv(transM, alpha, A, X, beta, Y);
}
//@}
Expand Down
11 changes: 6 additions & 5 deletions sparse/src/KokkosSparse_Preconditioner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Preconditioner {
public:
using ScalarType = typename std::remove_const<typename CRS::value_type>::type;
using EXSP = typename CRS::execution_space;
using MEMSP = typename CRS::memory_space;
using karith = typename Kokkos::ArithTraits<ScalarType>;

//! Constructor:
Expand All @@ -80,11 +81,11 @@ class Preconditioner {
///\cdot X\f$.
///// The typical case is \f$\beta = 0\f$ and \f$\alpha = 1\f$.
//
virtual void apply(const Kokkos::View<const ScalarType *, EXSP> &X,
const Kokkos::View<ScalarType *, EXSP> &Y,
const char transM[] = "N",
ScalarType alpha = karith::one(),
ScalarType beta = karith::zero()) const = 0;
virtual void apply(
const Kokkos::View<const ScalarType *, Kokkos::Device<EXSP, MEMSP>> &X,
const Kokkos::View<ScalarType *, Kokkos::Device<EXSP, MEMSP>> &Y,
const char transM[] = "N", ScalarType alpha = karith::one(),
ScalarType beta = karith::zero()) const = 0;
//@}

//! Set this preconditioner's parameters.
Expand Down

0 comments on commit 1ae5b7d

Please sign in to comment.