Advanced Multi-Physics (AMP)
On-Line Documentation
SpGEMM_Hip.h
Go to the documentation of this file.
1#ifndef included_AMP_SpGEMM_Hip
2#define included_AMP_SpGEMM_Hip
3
4#include "AMP/utils/hip/Helper_Hip.h"
5
6#include <rocsparse/rocsparse.h>
7
8#include <cstdint>
9#include <type_traits>
10
11namespace AMP::LinearAlgebra {
12
13// This class wraps the operations in the rocsparse-spgemm example found at
14// https://rocm.docs.amd.com/projects/rocSPARSE/en/latest/reference/generic.html#rocsparse-spgemm
15// while maintaining the rocsparse handle and internal temp buffer allocation.
16// Allocations for the result matrix are done by the caller of this class, not internally here.
17template<typename rowidx_t, typename colidx_t, typename scalar_t>
18class VendorSpGEMM
19{
20 // Only signed int 32's and 64's are supported for index types
21 // Only floats and doubles supported for value types
22 static_assert( std::is_same_v<rowidx_t, int> || std::is_same_v<rowidx_t, long long> );
23 static_assert( std::is_same_v<colidx_t, int> || std::is_same_v<colidx_t, long long> );
24 static_assert( std::is_same_v<scalar_t, float> || std::is_same_v<scalar_t, double> );
25
26
27 // 64 bit row pointers with 32 bit column indices is invalid
28 // TODO: cusparse does *not* allow mixed types for these currently,
29 // and for consistency we disallow it here in the rocsparse side too
30 // add this assert and remove the prior one if that ever changes
31 // static_assert( std::is_same_v<rowidx_t, int> ||
32 // (std::is_same_v<rowidx_t, long long> && std::is_same_v<colidx_t, long long>)
33 // );
34 static_assert( std::is_same_v<rowidx_t, colidx_t> );
35
36public:
37 VendorSpGEMM( const int64_t M_,
38 const int64_t N_,
39 const int64_t K_,
40 const int64_t A_nnz,
41 rowidx_t *A_rs,
42 colidx_t *A_cols,
43 scalar_t *A_vals,
44 const int64_t B_nnz,
45 rowidx_t *B_rs,
46 colidx_t *B_cols,
47 scalar_t *B_vals,
48 rowidx_t *C_rs );
49
51
52 int64_t getCnnz();
53
54 void compute( rowidx_t *C_rs, colidx_t *C_cols, scalar_t *C_vals );
55
56private:
57 const int64_t M;
58 const int64_t N;
59 const int64_t K;
60
61 scalar_t alpha;
62 scalar_t beta;
63
64 rocsparse_indextype itype;
65 rocsparse_indextype jtype;
66 rocsparse_datatype ttype;
67
68 rocsparse_handle handle;
69
70 rocsparse_spmat_descr matA;
71 rocsparse_spmat_descr matB;
72 rocsparse_spmat_descr matC;
73 rocsparse_spmat_descr matD;
74
77};
78
79} // namespace AMP::LinearAlgebra
80
81#endif
void compute(rowidx_t *C_rs, colidx_t *C_cols, scalar_t *C_vals)
VendorSpGEMM(const int64_t M_, const int64_t N_, const int64_t K_, const int64_t A_nnz, rowidx_t *A_rs, colidx_t *A_cols, scalar_t *A_vals, const int64_t B_nnz, rowidx_t *B_rs, colidx_t *B_cols, scalar_t *B_vals, rowidx_t *C_rs)
rocsparse_spmat_descr matC
Definition SpGEMM_Hip.h:72
rocsparse_indextype jtype
Definition SpGEMM_Hip.h:65
rocsparse_spmat_descr matD
Definition SpGEMM_Hip.h:73
rocsparse_indextype itype
Definition SpGEMM_Hip.h:64
rocsparse_spmat_descr matA
Definition SpGEMM_Hip.h:70
rocsparse_spmat_descr matB
Definition SpGEMM_Hip.h:71



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