Actual source code: hipsparsematimpl.h
1: /* Portions of this code are under:
2: Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
3: */
4: #pragma once
6: #include <petscpkg_version.h>
7: #include <../src/vec/vec/impls/seq/cupm/vecseqcupm.hpp>
8: #include <../src/sys/objects/device/impls/cupm/cupmthrustutility.hpp>
9: #include <petsc/private/petsclegacycupmblas.h>
11: #include <hipsparse/hipsparse.h>
12: #include "hip/hip_runtime.h"
14: #include <algorithm>
15: #include <vector>
17: #include <thrust/device_vector.h>
18: #include <thrust/device_ptr.h>
19: #include <thrust/device_malloc_allocator.h>
20: #include <thrust/transform.h>
21: #include <thrust/functional.h>
22: #include <thrust/sequence.h>
23: #include <thrust/system/system_error.h>
25: #if PetscDefined(USE_COMPLEX)
26: #if PetscDefined(USE_REAL_SINGLE)
27: const hipComplex PETSC_HIPSPARSE_ONE = {1.0f, 0.0f};
28: const hipComplex PETSC_HIPSPARSE_ZERO = {0.0f, 0.0f};
29: #define hipsparseXcsrilu02_bufferSize(a, b, c, d, e, f, g, h, i) hipsparseCcsrilu02_bufferSize(a, b, c, d, (hipComplex *)e, f, g, h, i)
30: #define hipsparseXcsrilu02_analysis(a, b, c, d, e, f, g, h, i, j) hipsparseCcsrilu02_analysis(a, b, c, d, (hipComplex *)e, f, g, h, i, j)
31: #define hipsparseXcsrilu02(a, b, c, d, e, f, g, h, i, j) hipsparseCcsrilu02(a, b, c, d, (hipComplex *)e, f, g, h, i, j)
32: #define hipsparseXcsric02_bufferSize(a, b, c, d, e, f, g, h, i) hipsparseCcsric02_bufferSize(a, b, c, d, (hipComplex *)e, f, g, h, i)
33: #define hipsparseXcsric02_analysis(a, b, c, d, e, f, g, h, i, j) hipsparseCcsric02_analysis(a, b, c, d, (hipComplex *)e, f, g, h, i, j)
34: #define hipsparseXcsric02(a, b, c, d, e, f, g, h, i, j) hipsparseCcsric02(a, b, c, d, (hipComplex *)e, f, g, h, i, j)
35: #elif PetscDefined(USE_REAL_DOUBLE)
36: const hipDoubleComplex PETSC_HIPSPARSE_ONE = {1.0, 0.0};
37: const hipDoubleComplex PETSC_HIPSPARSE_ZERO = {0.0, 0.0};
38: #define hipsparseXcsrilu02_bufferSize(a, b, c, d, e, f, g, h, i) hipsparseZcsrilu02_bufferSize(a, b, c, d, (hipDoubleComplex *)e, f, g, h, i)
39: #define hipsparseXcsrilu02_analysis(a, b, c, d, e, f, g, h, i, j) hipsparseZcsrilu02_analysis(a, b, c, d, (hipDoubleComplex *)e, f, g, h, i, j)
40: #define hipsparseXcsrilu02(a, b, c, d, e, f, g, h, i, j) hipsparseZcsrilu02(a, b, c, d, (hipDoubleComplex *)e, f, g, h, i, j)
41: #define hipsparseXcsric02_bufferSize(a, b, c, d, e, f, g, h, i) hipsparseZcsric02_bufferSize(a, b, c, d, (hipDoubleComplex *)e, f, g, h, i)
42: #define hipsparseXcsric02_analysis(a, b, c, d, e, f, g, h, i, j) hipsparseZcsric02_analysis(a, b, c, d, (hipDoubleComplex *)e, f, g, h, i, j)
43: #define hipsparseXcsric02(a, b, c, d, e, f, g, h, i, j) hipsparseZcsric02(a, b, c, d, (hipDoubleComplex *)e, f, g, h, i, j)
44: #endif /* Single or double */
45: #else /* not complex */
46: const PetscScalar PETSC_HIPSPARSE_ONE = 1.0;
47: const PetscScalar PETSC_HIPSPARSE_ZERO = 0.0;
48: #if PetscDefined(USE_REAL_SINGLE)
49: #define hipsparseXcsrilu02_bufferSize hipsparseScsrilu02_bufferSize
50: #define hipsparseXcsrilu02_analysis hipsparseScsrilu02_analysis
51: #define hipsparseXcsrilu02 hipsparseScsrilu02
52: #define hipsparseXcsric02_bufferSize hipsparseScsric02_bufferSize
53: #define hipsparseXcsric02_analysis hipsparseScsric02_analysis
54: #define hipsparseXcsric02 hipsparseScsric02
55: #elif PetscDefined(USE_REAL_DOUBLE)
56: #define hipsparseXcsrilu02_bufferSize hipsparseDcsrilu02_bufferSize
57: #define hipsparseXcsrilu02_analysis hipsparseDcsrilu02_analysis
58: #define hipsparseXcsrilu02 hipsparseDcsrilu02
59: #define hipsparseXcsric02_bufferSize hipsparseDcsric02_bufferSize
60: #define hipsparseXcsric02_analysis hipsparseDcsric02_analysis
61: #define hipsparseXcsric02 hipsparseDcsric02
62: #endif /* Single or double */
63: #endif /* complex or not */
65: #define csrsvInfo_t csrsv2Info_t
66: #define hipsparseCreateCsrsvInfo hipsparseCreateCsrsv2Info
67: #define hipsparseDestroyCsrsvInfo hipsparseDestroyCsrsv2Info
68: #if PetscDefined(USE_COMPLEX)
69: #if PetscDefined(USE_REAL_SINGLE)
70: #define hipsparseXcsrsv_buffsize(a, b, c, d, e, f, g, h, i, j) hipsparseCcsrsv2_bufferSize(a, b, c, d, e, (hipComplex *)(f), g, h, i, j)
71: #define hipsparseXcsrsv_analysis(a, b, c, d, e, f, g, h, i, j, k) hipsparseCcsrsv2_analysis(a, b, c, d, e, (const hipComplex *)(f), g, h, i, j, k)
72: #define hipsparseXcsrsv_solve(a, b, c, d, e, f, g, h, i, j, k, l, m, n) hipsparseCcsrsv2_solve(a, b, c, d, (const hipComplex *)(e), f, (const hipComplex *)(g), h, i, j, (const hipComplex *)(k), (hipComplex *)(l), m, n)
73: #elif PetscDefined(USE_REAL_DOUBLE)
74: #define hipsparseXcsrsv_buffsize(a, b, c, d, e, f, g, h, i, j) hipsparseZcsrsv2_bufferSize(a, b, c, d, e, (hipDoubleComplex *)(f), g, h, i, j)
75: #define hipsparseXcsrsv_analysis(a, b, c, d, e, f, g, h, i, j, k) hipsparseZcsrsv2_analysis(a, b, c, d, e, (const hipDoubleComplex *)(f), g, h, i, j, k)
76: #define hipsparseXcsrsv_solve(a, b, c, d, e, f, g, h, i, j, k, l, m, n) hipsparseZcsrsv2_solve(a, b, c, d, (const hipDoubleComplex *)(e), f, (const hipDoubleComplex *)(g), h, i, j, (const hipDoubleComplex *)(k), (hipDoubleComplex *)(l), m, n)
77: #endif /* Single or double */
78: #else /* not complex */
79: #if PetscDefined(USE_REAL_SINGLE)
80: #define hipsparseXcsrsv_buffsize hipsparseScsrsv2_bufferSize
81: #define hipsparseXcsrsv_analysis hipsparseScsrsv2_analysis
82: #define hipsparseXcsrsv_solve hipsparseScsrsv2_solve
83: #elif PetscDefined(USE_REAL_DOUBLE)
84: #define hipsparseXcsrsv_buffsize hipsparseDcsrsv2_bufferSize
85: #define hipsparseXcsrsv_analysis hipsparseDcsrsv2_analysis
86: #define hipsparseXcsrsv_solve hipsparseDcsrsv2_solve
87: #endif /* Single or double */
88: #endif /* not complex */
90: // #define cusparse_csr2csc cusparseCsr2cscEx2
91: #if PetscDefined(USE_COMPLEX)
92: #if PetscDefined(USE_REAL_SINGLE)
93: #define hipsparse_scalartype HIP_C_32F
94: #define hipsparse_csr_spgeam(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) hipsparseCcsrgeam2(a, b, c, (hipComplex *)d, e, f, (hipComplex *)g, h, i, (hipComplex *)j, k, l, (hipComplex *)m, n, o, p, (hipComplex *)q, r, s, t)
95: #define hipsparse_csr_spgeam_bufferSize(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) \
96: hipsparseCcsrgeam2_bufferSizeExt(a, b, c, (hipComplex *)d, e, f, (hipComplex *)g, h, i, (hipComplex *)j, k, l, (hipComplex *)m, n, o, p, (hipComplex *)q, r, s, t)
97: #elif PetscDefined(USE_REAL_DOUBLE)
98: #define hipsparse_scalartype HIP_C_64F
99: #define hipsparse_csr_spgeam(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) \
100: hipsparseZcsrgeam2(a, b, c, (hipDoubleComplex *)d, e, f, (hipDoubleComplex *)g, h, i, (hipDoubleComplex *)j, k, l, (hipDoubleComplex *)m, n, o, p, (hipDoubleComplex *)q, r, s, t)
101: #define hipsparse_csr_spgeam_bufferSize(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) \
102: hipsparseZcsrgeam2_bufferSizeExt(a, b, c, (hipDoubleComplex *)d, e, f, (hipDoubleComplex *)g, h, i, (hipDoubleComplex *)j, k, l, (hipDoubleComplex *)m, n, o, p, (hipDoubleComplex *)q, r, s, t)
103: #endif /* Single or double */
104: #else /* not complex */
105: #if PetscDefined(USE_REAL_SINGLE)
106: #define hipsparse_scalartype HIP_R_32F
107: #define hipsparse_csr_spgeam hipsparseScsrgeam2
108: #define hipsparse_csr_spgeam_bufferSize hipsparseScsrgeam2_bufferSizeExt
109: #elif PetscDefined(USE_REAL_DOUBLE)
110: #define hipsparse_scalartype HIP_R_64F
111: #define hipsparse_csr_spgeam hipsparseDcsrgeam2
112: #define hipsparse_csr_spgeam_bufferSize hipsparseDcsrgeam2_bufferSizeExt
113: #endif /* Single or double */
114: #endif /* complex or not */
116: #if PetscDefined(USE_COMPLEX)
117: #if PetscDefined(USE_REAL_SINGLE)
118: #define hipsparse_scalartype HIP_C_32F
119: #define hipsparse_csr_spmv(a, b, c, d, e, f, g, h, i, j, k, l, m) hipsparseCcsrmv((a), (b), (c), (d), (e), (hipComplex *)(f), (g), (hipComplex *)(h), (i), (j), (hipComplex *)(k), (hipComplex *)(l), (hipComplex *)(m))
120: #define hipsparse_csr_spmm(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) hipsparseCcsrmm((a), (b), (c), (d), (e), (f), (hipComplex *)(g), (h), (hipComplex *)(i), (j), (k), (hipComplex *)(l), (m), (hipComplex *)(n), (hipComplex *)(o), (p))
121: #define hipsparse_csr2csc(a, b, c, d, e, f, g, h, i, j, k, l) hipsparseCcsr2csc((a), (b), (c), (d), (hipComplex *)(e), (f), (g), (hipComplex *)(h), (i), (j), (k), (l))
122: #define hipsparse_hyb_spmv(a, b, c, d, e, f, g, h) hipsparseChybmv((a), (b), (hipComplex *)(c), (d), (e), (hipComplex *)(f), (hipComplex *)(g), (hipComplex *)(h))
123: #define hipsparse_csr2hyb(a, b, c, d, e, f, g, h, i, j) hipsparseCcsr2hyb((a), (b), (c), (d), (hipComplex *)(e), (f), (g), (h), (i), (j))
124: #define hipsparse_hyb2csr(a, b, c, d, e, f) hipsparseChyb2csr((a), (b), (c), (hipComplex *)(d), (e), (f))
125: #define hipsparse_csr_spgemm(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) hipsparseCcsrgemm(a, b, c, d, e, f, g, h, (hipComplex *)i, j, k, l, m, (hipComplex *)n, o, p, q, (hipComplex *)r, s, t)
126: // #define hipsparse_csr_spgeam(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) hipsparseCcsrgeam(a, b, c, (hipComplex *)d, e, f, (hipComplex *)g, h, i, (hipComplex *)j, k, l, (hipComplex *)m, n, o, p, (hipComplex *)q, r, s)
127: #elif PetscDefined(USE_REAL_DOUBLE)
128: #define hipsparse_scalartype HIP_C_64F
129: #define hipsparse_csr_spmv(a, b, c, d, e, f, g, h, i, j, k, l, m) hipsparseZcsrmv((a), (b), (c), (d), (e), (hipDoubleComplex *)(f), (g), (hipDoubleComplex *)(h), (i), (j), (hipDoubleComplex *)(k), (hipDoubleComplex *)(l), (hipDoubleComplex *)(m))
130: #define hipsparse_csr_spmm(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) \
131: hipsparseZcsrmm((a), (b), (c), (d), (e), (f), (hipDoubleComplex *)(g), (h), (hipDoubleComplex *)(i), (j), (k), (hipDoubleComplex *)(l), (m), (hipDoubleComplex *)(n), (hipDoubleComplex *)(o), (p))
132: #define hipsparse_csr2csc(a, b, c, d, e, f, g, h, i, j, k, l) hipsparseZcsr2csc((a), (b), (c), (d), (hipDoubleComplex *)(e), (f), (g), (hipDoubleComplex *)(h), (i), (j), (k), (l))
133: #define hipsparse_hyb_spmv(a, b, c, d, e, f, g, h) hipsparseZhybmv((a), (b), (hipDoubleComplex *)(c), (d), (e), (hipDoubleComplex *)(f), (hipDoubleComplex *)(g), (hipDoubleComplex *)(h))
134: #define hipsparse_csr2hyb(a, b, c, d, e, f, g, h, i, j) hipsparseZcsr2hyb((a), (b), (c), (d), (hipDoubleComplex *)(e), (f), (g), (h), (i), (j))
135: #define hipsparse_hyb2csr(a, b, c, d, e, f) hipsparseZhyb2csr((a), (b), (c), (hipDoubleComplex *)(d), (e), (f))
136: #define hipsparse_csr_spgemm(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) hipsparseZcsrgemm(a, b, c, d, e, f, g, h, (hipDoubleComplex *)i, j, k, l, m, (hipDoubleComplex *)n, o, p, q, (hipDoubleComplex *)r, s, t)
137: // #define hipsparse_csr_spgeam(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) hipsparseZcsrgeam(a, b, c, (hipDoubleComplex *)d, e, f, (hipDoubleComplex *)g, h, i, (hipDoubleComplex *)j, k, l, (hipDoubleComplex *)m, n, o, p, (hipDoubleComplex *)q, r, s)
138: #endif /* Single or double */
139: #else /* not complex */
140: #if PetscDefined(USE_REAL_SINGLE)
141: #define hipsparse_scalartype HIP_R_32F
142: #define hipsparse_csr_spmv hipsparseScsrmv
143: #define hipsparse_csr_spmm hipsparseScsrmm
144: #define hipsparse_csr2csc hipsparseScsr2csc
145: #define hipsparse_hyb_spmv hipsparseShybmv
146: #define hipsparse_csr2hyb hipsparseScsr2hyb
147: #define hipsparse_hyb2csr hipsparseShyb2csr
148: #define hipsparse_csr_spgemm hipsparseScsrgemm
149: // #define hipsparse_csr_spgeam hipsparseScsrgeam
150: #elif PetscDefined(USE_REAL_DOUBLE)
151: #define hipsparse_scalartype HIP_R_64F
152: #define hipsparse_csr_spmv hipsparseDcsrmv
153: #define hipsparse_csr_spmm hipsparseDcsrmm
154: #define hipsparse_csr2csc hipsparseDcsr2csc
155: #define hipsparse_hyb_spmv hipsparseDhybmv
156: #define hipsparse_csr2hyb hipsparseDcsr2hyb
157: #define hipsparse_hyb2csr hipsparseDhyb2csr
158: #define hipsparse_csr_spgemm hipsparseDcsrgemm
159: // #define hipsparse_csr_spgeam hipsparseDcsrgeam
160: #endif /* Single or double */
161: #endif /* complex or not */
163: #define THRUSTINTARRAY thrust::device_vector<PetscInt>
164: #define THRUSTARRAY thrust::device_vector<PetscScalar>
166: /* A CSR matrix nonzero structure */
167: struct CsrMatrix {
168: PetscInt num_rows;
169: PetscInt num_cols;
170: PetscInt num_entries;
171: THRUSTINTARRAY *row_offsets;
172: THRUSTINTARRAY *column_indices;
173: THRUSTARRAY *values;
174: };
176: /* This is struct holding the relevant data needed to a MatSolve */
177: struct Mat_SeqAIJHIPSPARSETriFactorStruct {
178: /* Data needed for triangular solve */
179: hipsparseMatDescr_t descr;
180: hipsparseOperation_t solveOp;
181: CsrMatrix *csrMat;
182: csrsvInfo_t solveInfo;
183: hipsparseSolvePolicy_t solvePolicy; /* whether level information is generated and used */
184: int solveBufferSize;
185: void *solveBuffer;
186: size_t csr2cscBufferSize; /* to transpose the triangular factor (only used for CUDA >= 11.0) */
187: void *csr2cscBuffer;
188: PetscScalar *AA_h; /* managed host buffer for moving values to the GPU */
189: };
191: /* This is a larger struct holding all the triangular factors for a solve, transpose solve, and any indices used in a reordering */
192: struct Mat_SeqAIJHIPSPARSETriFactors {
193: THRUSTINTARRAY *rpermIndices; /* indices used for any reordering */
194: THRUSTINTARRAY *cpermIndices; /* indices used for any reordering */
195: THRUSTARRAY *workVector;
196: PetscInt nnz; /* number of nonzeros ... need this for accurate logging between ICC and ILU */
197: hipDeviceProp_t dev_prop;
198: PetscBool init_dev_prop;
200: PetscScalar *csrVal, *diag; // the diagonal D in UtDU of Cholesky
201: int *csrRowPtr32, *csrColIdx32; // i,j of M. hipsparseShcsrilu02/ic02() etc require 32-bit indices
202: PetscInt *csrRowPtr, *csrColIdx; // i, j of M on device for HIP APIs that support 64-bit indices
203: PetscScalar *csrVal_h, *diag_h; // Since LU is done on host, we prepare a factored matrix in regular csr format on host and then copy it to device
204: PetscInt *csrRowPtr_h; // csrColIdx_h is temporary, so it is not here
206: /* Mixed mat descriptor types? yes, different hipsparse APIs use different types */
207: hipsparseMatDescr_t matDescr_M;
208: hipsparseSpMatDescr_t spMatDescr_L, spMatDescr_U, spMatDescr_Lt, spMatDescr_Ut;
209: hipsparseSpSVDescr_t spsvDescr_L, spsvDescr_Lt, spsvDescr_U, spsvDescr_Ut;
210: hipsparseDnVecDescr_t dnVecDescr_X, dnVecDescr_Y;
211: PetscScalar *X, *Y; /* data array of dnVec X and Y */
213: /* Mixed size types? yes, CUDA-11.7.0 declared cusparseDcsrilu02_bufferSizeExt() that returns size_t but did not implement it! */
214: int factBufferSize_M; /* M ~= LU or LLt */
215: size_t spsvBufferSize_L, spsvBufferSize_Lt, spsvBufferSize_U, spsvBufferSize_Ut;
216: /* hipsparse needs various buffers for factorization and solve of L, U, Lt, or Ut.
217: To save memory, we share the factorization buffer with one of spsvBuffer_L/U.
218: */
219: void *factBuffer_M, *spsvBuffer_L, *spsvBuffer_U, *spsvBuffer_Lt, *spsvBuffer_Ut;
221: csrilu02Info_t ilu0Info_M;
222: csric02Info_t ic0Info_M;
223: int structural_zero, numerical_zero;
224: hipsparseSolvePolicy_t policy_M;
226: /* In MatSolveTranspose() for ILU0, we use the two flags to do on-demand solve */
227: PetscBool createdTransposeSpSVDescr; /* Have we created SpSV descriptors for Lt, Ut? */
228: PetscBool updatedTransposeSpSVAnalysis; /* Have we ever updated (done) SpSV analysis for Lt, Ut */
229: PetscBool updatedSpSVAnalysis; /* Have we ever updated (done) SpSV Analysis for L, U? */
231: PetscLogDouble numericFactFlops; /* Estimated FLOPs in ILU0/ICC0 numeric factorization */
232: };
234: struct Mat_HipsparseSpMV {
235: PetscBool initialized; /* Don't rely on spmvBuffer != NULL to test if the struct is initialized, */
236: size_t spmvBufferSize; /* since I'm not sure if smvBuffer can be NULL even after hipsparseSpMV_bufferSize() */
237: void *spmvBuffer;
238: hipsparseDnVecDescr_t vecXDescr, vecYDescr; /* descriptors for the dense vectors and matrix in y=op(A)x */
239: hipsparseSpMatDescr_t matDescr;
240: };
242: /* This is struct holding the relevant data needed to a MatMult */
243: struct Mat_SeqAIJHIPSPARSEMultStruct {
244: void *mat; /* opaque pointer to a matrix. This could be either a hipsparseHybMat_t or a CsrMatrix */
245: hipsparseMatDescr_t descr; /* Data needed to describe the matrix for a multiply */
246: THRUSTINTARRAY *cprowIndices; /* compressed row indices used in the parallel SpMV */
247: PetscScalar *alpha_one; /* pointer to a device "scalar" storing the alpha parameter in the SpMV */
248: PetscScalar *beta_zero; /* pointer to a device "scalar" storing the beta parameter in the SpMV as zero*/
249: PetscScalar *beta_one; /* pointer to a device "scalar" storing the beta parameter in the SpMV as one */
250: hipsparseSpMatDescr_t matDescr; /* descriptor for the matrix, used by SpMM */
251: hipsparseSpMatDescr_t matDescr_SpMM[3]; /* descriptors used by SpMM when the rows of the matrix are compressed, one per operation */
252: Mat_HipsparseSpMV hipSpMV[3]; /* different Mat_CusparseSpMV structs for non-transpose, transpose, conj-transpose */
253: Mat_SeqAIJHIPSPARSEMultStruct() : matDescr(NULL)
254: {
255: for (int i = 0; i < 3; i++) {
256: hipSpMV[i].initialized = PETSC_FALSE;
257: matDescr_SpMM[i] = NULL;
258: }
259: }
260: };
262: /* This is a larger struct holding all the matrices for a SpMV, and SpMV Transpose */
263: struct Mat_SeqAIJHIPSPARSE {
264: Mat_SeqAIJHIPSPARSEMultStruct *mat; /* pointer to the matrix on the GPU */
265: Mat_SeqAIJHIPSPARSEMultStruct *matTranspose; /* pointer to the matrix on the GPU (for the transpose ... useful for BiCG) */
266: THRUSTARRAY *workVector; /* pointer to a workvector to which we can copy the relevant indices of a vector we want to multiply */
267: THRUSTINTARRAY *rowoffsets_gpu; /* rowoffsets on GPU in non-compressed-row format. It is used to convert CSR to CSC */
268: PetscInt nrows; /* number of rows of the matrix seen by GPU */
269: MatHIPSPARSEStorageFormat format; /* the storage format for the matrix on the device */
270: PetscBool use_cpu_solve; /* Use AIJ_Seq (I)LU solve */
271: PetscObjectState nonzerostate; /* track nonzero state to possibly recreate the GPU matrix */
272: size_t csr2cscBufferSize; /* stuff used to compute the matTranspose above */
273: void *csr2cscBuffer; /* This is used as a C struct and is calloc'ed by PetscNewLog() */
274: // hipsparseCsr2CscAlg_t csr2cscAlg; /* algorithms can be selected from command line options */
275: hipsparseSpMVAlg_t spmvAlg;
276: hipsparseSpMMAlg_t spmmAlg;
277: THRUSTINTARRAY *csr2csc_i;
278: THRUSTINTARRAY *coords; /* permutation array used in MatSeqAIJHIPSPARSEMergeMats */
279: };
281: typedef struct Mat_SeqAIJHIPSPARSETriFactors *Mat_SeqAIJHIPSPARSETriFactors_p;
283: PETSC_INTERN PetscErrorCode MatSeqAIJHIPSPARSECopyToGPU(Mat);
284: PETSC_INTERN PetscErrorCode MatSeqAIJHIPSPARSEMergeMats(Mat, Mat, MatReuse, Mat *);
285: PETSC_INTERN PetscErrorCode MatSeqAIJHIPSPARSETriFactors_Reset(Mat_SeqAIJHIPSPARSETriFactors_p *);
287: using VecSeq_HIP = Petsc::vec::cupm::impl::VecSeq_CUPM<Petsc::device::cupm::DeviceType::HIP>;
289: static inline bool isHipMem(const void *data)
290: {
291: using namespace Petsc::device::cupm;
292: auto mtype = PETSC_MEMTYPE_HOST;
294: PetscFunctionBegin;
295: PetscCallAbort(PETSC_COMM_SELF, impl::Interface<DeviceType::HIP>::PetscCUPMGetMemType(data, &mtype));
296: PetscFunctionReturn(PetscMemTypeDevice(mtype));
297: }