10 #ifndef KOKKOS_CRSMATRIX_MP_VECTOR_HPP
11 #define KOKKOS_CRSMATRIX_MP_VECTOR_HPP
13 #include <type_traits>
17 #include "KokkosSparse_CrsMatrix.hpp"
19 #include "KokkosSparse_spmv.hpp"
22 #include "Kokkos_Core.hpp"
33 template<
class T,
class = std::
void_t<> >
34 struct const_type_impl {
39 struct const_type_impl<T,
40 std::void_t<typename T::const_type> > {
41 using type =
typename T::const_type;
45 using const_type_t =
typename const_type_impl<T>::type;
53 template <
typename Matrix,
typename InputVector,
typename OutputVector,
54 typename Update = MultiplyAssign,
55 typename Enabled =
void>
65 template <
typename MatrixDevice,
66 typename MatrixStorage,
67 typename MatrixOrdinal,
68 typename MatrixMemory,
70 typename InputStorage,
72 typename OutputStorage,
80 Kokkos::View< const Sacado::MP::Vector<InputStorage>*,
82 Kokkos::View< Sacado::MP::Vector<OutputStorage>*,
85 #ifdef KOKKOS_ENABLE_CUDA
86 , typename std::enable_if<
87 !std::is_same<typename MatrixDevice::execution_space,Kokkos::Cuda>::value >::type
102 typedef KokkosSparse::CrsMatrix<
const MatrixValue,
128 KOKKOS_INLINE_FUNCTION
132 const size_type iEntryBegin = m_A.graph.row_map[iRow];
133 const size_type iEntryEnd = m_A.graph.row_map[iRow+1];
135 for (
size_type iEntry = iEntryBegin; iEntry < iEntryEnd; ++iEntry) {
136 size_type iCol = m_A.graph.entries(iEntry);
137 sum += m_A.values(iEntry) * m_x(iCol);
139 m_update( m_y(iRow), sum );
147 const size_type row_count = A.graph.row_map.extent(0)-1;
148 Kokkos::parallel_for( row_count,
MPMultiply(A,x,y,update) );
159 template <
typename MatrixDevice,
160 typename MatrixStorage,
161 typename MatrixOrdinal,
162 typename MatrixMemory,
164 typename InputStorage,
166 typename OutputStorage,
167 typename ... OutputP,
174 Kokkos::View< const Sacado::MP::Vector<InputStorage>**,
176 Kokkos::View< Sacado::MP::Vector<OutputStorage>**,
179 #ifdef KOKKOS_ENABLE_CUDA
180 , typename std::enable_if<
181 !std::is_same<typename MatrixDevice::execution_space,Kokkos::Cuda>::value >::type
194 typedef KokkosSparse::CrsMatrix<
const MatrixValue,
221 KOKKOS_INLINE_FUNCTION
227 for (
size_type col=0; col<num_col; ++col) {
229 const size_type iEntryBegin = m_A.graph.row_map[iRow];
230 const size_type iEntryEnd = m_A.graph.row_map[iRow+1];
232 for (
size_type iEntry = iEntryBegin; iEntry < iEntryEnd; ++iEntry) {
233 size_type iCol = m_A.graph.entries(iEntry);
234 sum += m_A.values(iEntry) * m_x(iCol,col);
236 m_update( m_y(iRow,col), sum );
247 const size_type row_count = A.graph.row_map.extent(0)-1;
248 Kokkos::parallel_for( row_count,
MPMultiply(A,x,y,update) );
259 template <
typename MatrixDevice,
260 typename MatrixStorage,
261 typename MatrixOrdinal,
262 typename MatrixMemory,
264 typename InputStorage,
266 typename OutputStorage,
267 typename ... OutputP,
274 Kokkos::View< const Sacado::MP::Vector<InputStorage>*,
276 Kokkos::View< Sacado::MP::Vector<OutputStorage>*,
323 template <
typename MatrixDevice,
324 typename MatrixStorage,
325 typename MatrixOrdinal,
326 typename MatrixMemory,
328 typename InputStorage,
330 typename OutputStorage,
331 typename ... OutputP,
338 Kokkos::View< const Sacado::MP::Vector<InputStorage>**,
340 Kokkos::View< Sacado::MP::Vector<OutputStorage>**,
389 template <
typename MatrixDevice,
390 typename MatrixStorage,
391 typename MatrixOrdinal,
392 typename MatrixMemory,
394 typename InputStorage,
396 typename OutputStorage,
397 typename ... OutputP>
403 Kokkos::View< const Sacado::MP::Vector<InputStorage>*,
405 Kokkos::View< Sacado::MP::Vector<OutputStorage>*,
446 template <
typename MatrixDevice,
447 typename MatrixStorage,
448 typename MatrixOrdinal,
449 typename MatrixMemory,
451 typename InputStorage,
453 typename OutputStorage,
454 typename ... OutputP>
460 Kokkos::View< const Sacado::MP::Vector<InputStorage>**,
462 Kokkos::View< Sacado::MP::Vector<OutputStorage>**,
498 namespace KokkosSparse {
501 #if KOKKOSKERNELS_VERSION >= 40199
502 typename ExecutionSpace,
504 #if KOKKOSKERNELS_VERSION >= 40299
513 typename ... OutputP>
514 typename std::enable_if<
517 #if KOKKOSKERNELS_VERSION >= 40299
518 && KokkosSparse::is_crs_matrix_v<MatrixType>
519 && (Kokkos::View< OutputType, OutputP... >::rank() == 1)
523 #
if KOKKOSKERNELS_VERSION >= 40199
524 const ExecutionSpace& space,
526 #
if KOKKOSKERNELS_VERSION < 40299
527 KokkosKernels::Experimental::Controls,
534 const Kokkos::View< InputType, InputP... >& x,
536 const Kokkos::View< OutputType, OutputP... >& y
537 #
if KOKKOSKERNELS_VERSION < 40299
542 typedef Kokkos::View< OutputType, OutputP... > OutputVectorType;
543 typedef Kokkos::View< InputType, InputP... > InputVectorType;
544 using input_vector_type = const_type_t<InputVectorType>;
545 typedef typename InputVectorType::array_type::non_const_value_type
value_type;
547 #if KOKKOSKERNELS_VERSION >= 40199
548 if(space != ExecutionSpace()) {
550 "Stokhos spmv not implemented for non-default execution space instance");
555 "Stokhos spmv not implemented for transposed or conjugated matrix-vector multiplies");
560 "MV_Multiply not implemented for non-constant a or b");
563 value_type aa = Sacado::Value<AlphaType>::eval(a);
564 value_type bb = Sacado::Value<BetaType>::eval(b);
570 input_vector_type, OutputVectorType,
571 UpdateType> multiply_type;
572 multiply_type::apply( A, x, y, UpdateType() );
578 input_vector_type, OutputVectorType,
579 UpdateType> multiply_type;
580 multiply_type::apply( A, x, y, UpdateType(aa) );
588 input_vector_type, OutputVectorType,
589 UpdateType> multiply_type;
590 multiply_type::apply( A, x, y, UpdateType() );
596 input_vector_type, OutputVectorType,
597 UpdateType> multiply_type;
598 multiply_type::apply( A, x, y, UpdateType(aa) );
605 input_vector_type, OutputVectorType,
606 UpdateType> multiply_type;
607 multiply_type::apply( A, x, y, UpdateType(aa,bb) );
612 #if KOKKOSKERNELS_VERSION >= 40199
613 typename ExecutionSpace,
615 #if KOKKOSKERNELS_VERSION >= 40299
624 typename ... OutputP>
625 typename std::enable_if<
628 #if KOKKOSKERNELS_VERSION >= 40299
629 && KokkosSparse::is_crs_matrix_v<MatrixType>
630 && (Kokkos::View< OutputType, OutputP... >::rank() == 2)
634 #
if KOKKOSKERNELS_VERSION >= 40199
635 const ExecutionSpace& space,
637 #
if KOKKOSKERNELS_VERSION < 40299
638 KokkosKernels::Experimental::Controls,
645 const Kokkos::View< InputType, InputP... >& x,
647 const Kokkos::View< OutputType, OutputP... >& y
648 #
if KOKKOSKERNELS_VERSION < 40299
653 #if KOKKOSKERNELS_VERSION >= 40199
654 if(space != ExecutionSpace()) {
656 "Stokhos spmv not implemented for non-default execution space instance");
661 "Stokhos spmv not implemented for transposed or conjugated matrix-vector multiplies");
663 if (y.extent(1) == 1) {
664 auto y_1D = subview(y, Kokkos::ALL(), 0);
665 auto x_1D = subview(x, Kokkos::ALL(), 0);
666 #if KOKKOSKERNELS_VERSION >= 40299
667 spmv(space, handle, mode, a, A, x_1D, b, y_1D);
668 #elif (KOKKOSKERNELS_VERSION < 40299) && (KOKKOSKERNELS_VERSION >= 40199)
669 spmv(space, KokkosKernels::Experimental::Controls(), mode, a, A, x_1D, b, y_1D, RANK_ONE());
671 spmv(KokkosKernels::Experimental::Controls(), mode, a, A, x_1D, b, y_1D, RANK_ONE());
675 typedef Kokkos::View< OutputType, OutputP... > OutputVectorType;
676 typedef Kokkos::View< InputType, InputP... > InputVectorType;
677 using input_vector_type = const_type_t<InputVectorType>;
678 typedef typename InputVectorType::array_type::non_const_value_type
value_type;
682 "Stokhos spmv not implemented for non-constant a or b");
685 value_type aa = Sacado::Value<AlphaType>::eval(a);
686 value_type bb = Sacado::Value<BetaType>::eval(b);
692 input_vector_type, OutputVectorType,
693 UpdateType> multiply_type;
694 multiply_type::apply( A, x, y, UpdateType() );
700 input_vector_type, OutputVectorType,
701 UpdateType> multiply_type;
702 multiply_type::apply( A, x, y, UpdateType(aa) );
710 input_vector_type, OutputVectorType,
711 UpdateType> multiply_type;
712 multiply_type::apply( A, x, y, UpdateType() );
718 input_vector_type, OutputVectorType,
719 UpdateType> multiply_type;
720 multiply_type::apply( A, x, y, UpdateType(aa) );
727 input_vector_type, OutputVectorType,
728 UpdateType> multiply_type;
729 multiply_type::apply( A, x, y, UpdateType(aa,bb) );
execution_space::size_type size_type
Sacado::MP::Vector< OutputStorage > OutputVectorValue
Kokkos::View< OutputVectorValue **, OutputP... > output_vector_type
Sacado::MP::Vector< OutputStorage > OutputVectorValue
Sacado::MP::Vector< InputStorage > InputVectorValue
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y)
const output_vector_type m_y
MPMultiply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)
OutputVectorValue scalar_type
Sacado::MP::Vector< InputStorage > InputVectorValue
KOKKOS_INLINE_FUNCTION void operator()(const size_type iRow) const
Sacado::MP::Vector< OutputStorage > OutputVectorValue
MatrixDevice::execution_space execution_space
Sacado::MP::Vector< MatrixStorage > MatrixValue
matrix_type::const_type const_matrix_type
Kokkos::DefaultExecutionSpace execution_space
Sacado::MP::Vector< MatrixStorage > MatrixValue
matrix_type::const_type const_matrix_type
execution_space::size_type size_type
MatrixDevice::execution_space execution_space
Kokkos::View< OutputVectorValue *, OutputP... > output_vector_type
Sacado::MP::Vector< OutputStorage > OutputVectorValue
Kokkos::View< OutputVectorValue *, OutputP... > output_vector_type
KOKKOS_INLINE_FUNCTION void raise_error(const char *msg)
Kokkos::View< const InputVectorValue **, InputP... > input_vector_type
Kokkos::View< const InputVectorValue **, InputP... > input_vector_type
Kokkos::View< OutputVectorValue *, OutputP... > output_vector_type
matrix_type::values_type matrix_values_type
Sacado::MP::Vector< MatrixStorage > MatrixValue
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)
Sacado::MP::Vector< MatrixStorage > MatrixValue
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
MatrixDevice::execution_space execution_space
Sacado::MP::Vector< OutputStorage > OutputVectorValue
matrix_type::values_type matrix_values_type
matrix_type::values_type matrix_values_type
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
KOKKOS_INLINE_FUNCTION void operator()(const size_type iRow) const
Sacado::MP::Vector< InputStorage > InputVectorValue
Sacado::MP::Vector< InputStorage > InputVectorValue
MatrixDevice::execution_space execution_space
KOKKOS_INLINE_FUNCTION bool is_constant(const T &x)
execution_space::size_type size_type
Sacado::MP::Vector< InputStorage > InputVectorValue
const update_type m_update
MPMultiply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)
execution_space::size_type size_type
Sacado::MP::Vector< InputStorage > InputVectorValue
KokkosSparse::CrsMatrix< const MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
OutputVectorValue scalar_type
OutputVectorValue scalar_type
KokkosSparse::CrsMatrix< const MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
execution_space::size_type size_type
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)
Sacado::MP::Vector< MatrixStorage > MatrixValue
Kokkos::View< const InputVectorValue *, InputP... > input_vector_type
const input_vector_type m_x
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
std::enable_if< Kokkos::is_view_uq_pce< Kokkos::View< InputType, InputP... > >::value &&Kokkos::is_view_uq_pce< Kokkos::View< OutputType, OutputP... > >::value >::type spmv(KokkosKernels::Experimental::Controls, const char mode[], const AlphaType &a, const MatrixType &A, const Kokkos::View< InputType, InputP... > &x, const BetaType &b, const Kokkos::View< OutputType, OutputP... > &y, const RANK_ONE)
const input_vector_type m_x
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y)
OutputVectorValue scalar_type
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
MatrixDevice::execution_space execution_space
Kokkos::View< const InputVectorValue **, InputP... > input_vector_type
const update_type m_update
Kokkos::View< OutputVectorValue **, OutputP... > output_vector_type
Kokkos::View< const InputVectorValue *, InputP... > input_vector_type
Kokkos::View< OutputVectorValue **, OutputP... > output_vector_type
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)
Sacado::MP::Vector< MatrixStorage > MatrixValue
Kokkos::View< const InputVectorValue *, InputP... > input_vector_type
execution_space::size_type size_type
std::enable_if< Kokkos::is_view_uq_pce< Kokkos::View< RD, RP...> >::value &&Kokkos::is_view_uq_pce< Kokkos::View< XD, XP...> >::value >::type sum(const Kokkos::View< RD, RP...> &r, const Kokkos::View< XD, XP...> &x)
void update(const ValueType &alpha, VectorType &x, const ValueType &beta, const VectorType &y)
MatrixDevice::execution_space execution_space
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)
const output_vector_type m_y
Sacado::MP::Vector< OutputStorage > OutputVectorValue