Advanced Multi-Physics (AMP)
On-Line Documentation
CSRMatrixOperationsKokkos.h
Go to the documentation of this file.
1#ifndef included_CSRMatrixOperationsKokkos_H_
2#define included_CSRMatrixOperationsKokkos_H_
3
4#include "AMP/AMP_TPLs.h"
5#include "AMP/matrices/CSRConfig.h"
6#include "AMP/matrices/data/CSRMatrixData.h"
7#include "AMP/matrices/data/MatrixData.h"
8#include "AMP/matrices/operations/MatrixOperations.h"
9#include "AMP/matrices/operations/default/CSRMatrixOperationsDefault.h"
10#include "AMP/matrices/operations/kokkos/CSRLocalMatrixOperationsKokkos.h"
11#include "AMP/utils/Memory.h"
12#include "AMP/vectors/Vector.h"
13
14#ifdef AMP_USE_DEVICE
15 #include "AMP/matrices/operations/device/CSRMatrixOperationsDevice.h"
16#endif
17
18#include <type_traits>
19
20#ifdef AMP_USE_KOKKOS
21
22 #include "Kokkos_Core.hpp"
23
24namespace AMP::LinearAlgebra {
25
26template<typename Config,
27 #ifdef AMP_USE_DEVICE
28 class ExecSpace = typename std::conditional<alloc_info<Config::allocator>::mem_loc ==
30 Kokkos::DefaultHostExecutionSpace,
31 Kokkos::DefaultExecutionSpace>::type,
32 class ViewSpace = typename std::conditional<
33 alloc_info<Config::allocator>::mem_loc == AMP::Utilities::MemoryType::host,
34 Kokkos::HostSpace,
35 typename std::conditional<
36 alloc_info<Config::allocator>::mem_loc == AMP::Utilities::MemoryType::managed,
37 Kokkos::SharedSpace,
38 typename Kokkos::DefaultExecutionSpace::memory_space>::type>::type
39 #else
40 class ExecSpace = Kokkos::DefaultHostExecutionSpace,
41 class ViewSpace = Kokkos::HostSpace
42 #endif
43 >
44class CSRMatrixOperationsKokkos : public MatrixOperations
45{
46public:
47 static_assert( std::is_same_v<typename Config::allocator_type::value_type, void> );
48
49 using config_type = Config;
50 using allocator_type = typename Config::allocator_type;
51 using matrixdata_t = CSRMatrixData<Config>;
52 using localmatrixdata_t = typename matrixdata_t::localmatrixdata_t;
53
54 using localops_t = CSRLocalMatrixOperationsKokkos<Config, ExecSpace, ViewSpace>;
55
56 using gidx_t = typename Config::gidx_t;
57 using lidx_t = typename Config::lidx_t;
58 using scalar_t = typename Config::scalar_t;
59
60 CSRMatrixOperationsKokkos()
61 : d_exec_space(),
62 d_localops_diag( std::make_shared<localops_t>( d_exec_space ) ),
63 d_localops_offd( std::make_shared<localops_t>( d_exec_space ) )
64 {
65 }
66
72 void mult( std::shared_ptr<const Vector> x,
73 MatrixData const &A,
74 std::shared_ptr<Vector> y ) override;
75
81 void multTranspose( std::shared_ptr<const Vector> in,
82 MatrixData const &A,
83 std::shared_ptr<Vector> out ) override;
84
89 void scale( AMP::Scalar alpha, MatrixData &A ) override;
90
97 void scale( AMP::Scalar alpha, std::shared_ptr<const Vector> D, MatrixData &A ) override;
98
105 void scaleInv( AMP::Scalar alpha, std::shared_ptr<const Vector> D, MatrixData &A ) override;
106
112 void matMatMult( std::shared_ptr<MatrixData> A,
113 std::shared_ptr<MatrixData> B,
114 std::shared_ptr<MatrixData> C ) override;
115
121 void axpy( AMP::Scalar alpha, const MatrixData &X, MatrixData &Y ) override;
122
126 void setScalar( AMP::Scalar alpha, MatrixData &A ) override;
127
131 void zero( MatrixData &A ) override;
132
136 void setDiagonal( std::shared_ptr<const Vector> in, MatrixData &A ) override;
137
140 void setIdentity( MatrixData &A ) override;
141
146 void extractDiagonal( MatrixData const &A, std::shared_ptr<Vector> buf ) override;
147
152 void getRowSums( MatrixData const &A, std::shared_ptr<Vector> buf ) override;
153
158 void getRowSumsAbsolute( MatrixData const &A,
159 std::shared_ptr<Vector> buf,
160 const bool remove_zeros = false ) override;
161
165 AMP::Scalar LinfNorm( const MatrixData &X ) const override;
166
172 void copy( const MatrixData &X, MatrixData &Y ) override;
173
179 void copyCast( const MatrixData &X, MatrixData &Y ) override;
180
181 template<typename ConfigIn>
182 static void copyCast( CSRMatrixData<ConfigIn> *X, CSRMatrixData<Config> *Y );
183
184 std::string type() const override { return "CSRMatrixOperationsKokkos"; }
185
191 void writeRestart( int64_t fid ) const override;
192
193 CSRMatrixOperationsKokkos( int64_t, AMP::IO::RestartManager * )
194 : d_exec_space(),
195 d_localops_diag( std::make_shared<localops_t>( d_exec_space ) ),
196 d_localops_offd( std::make_shared<localops_t>( d_exec_space ) )
197 {
198 }
199
200protected:
201 ExecSpace d_exec_space;
202 std::shared_ptr<localops_t> d_localops_diag;
203 std::shared_ptr<localops_t> d_localops_offd;
204
205 // This currently forwards SpGEMM operations to either default ops or device ops
206 // so internal versions of each are held
207 CSRMatrixOperationsDefault<Config> d_matrixOpsDefault;
208 #ifdef AMP_USE_DEVICE
209 CSRMatrixOperationsDevice<Config> d_matrixOpsDevice;
210 #endif
211};
212
213} // namespace AMP::LinearAlgebra
214
215#endif
216#endif
#define X(C)
Class to manage reading/writing restart data.
Scalar is a class used to store a scalar variable that may be different types/precision.
Definition Scalar.h:21
void copy(size_t N, const T1 *src, T2 *dst)
Perform copy with conversion if necessary.
void copyCast(const size_t len, const T1 *vec_in, T2 *vec_out)
void zero(void *dest, std::size_t count)
Perform memory zero (pointer may be in any memory space)



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:40.
Comments on this page