xref: /libCEED/rust/libceed-sys/c-src/backends/magma/ceed-magma.h (revision 38d0029a08e84b16bbdde77c27446234f5f09cf2)
1 // Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3 // reserved. See files LICENSE and NOTICE for details.
4 //
5 // This file is part of CEED, a collection of benchmarks, miniapps, software
6 // libraries and APIs for efficient high-order finite element and spectral
7 // element discretizations for exascale applications. For more information and
8 // source code availability see http://github.com/ceed.
9 //
10 // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11 // a collaborative effort of two U.S. Department of Energy organizations (Office
12 // of Science and the National Nuclear Security Administration) responsible for
13 // the planning and preparation of a capable exascale ecosystem, including
14 // software, applications, hardware, advanced system engineering and early
15 // testbed platforms, in support of the nation's exascale computing imperative.
16 
17 // magma functions specific to ceed
18 
19 #include <string.h>
20 #include <ceed-backend.h>
21 #include "magma.h"
22 
23 typedef struct {
24   CeedScalar *dqref1d;
25   CeedScalar *dinterp1d;
26   CeedScalar *dgrad1d;
27   CeedScalar *dqweight1d;
28 } CeedBasis_Magma;
29 
30 typedef struct {
31   CeedScalar *dqref;
32   CeedScalar *dinterp;
33   CeedScalar *dgrad;
34   CeedScalar *dqweight;
35 } CeedBasisNonTensor_Magma;
36 
37 typedef struct {
38   CeedInt *indices;
39   CeedInt *dindices;
40   int  own_;
41   int down_;            // cover a case where we own Device memory
42 } CeedElemRestriction_Magma;
43 
44 typedef struct {
45   const CeedScalar **inputs;
46   CeedScalar **outputs;
47   bool setupdone;
48 } CeedQFunction_Magma;
49 
50 #define USE_MAGMA_BATCH
51 #define USE_MAGMA_BATCH2
52 #define USE_MAGMA_BATCH3
53 #define USE_MAGMA_BATCH4
54 
55 #ifdef __cplusplus
56 CEED_INTERN {
57 #endif
58   void magmablas_dbasis_apply_batched_eval_interp(magma_int_t P, magma_int_t Q,
59       magma_int_t dim, magma_int_t ncomp,
60       const double *dT, CeedTransposeMode tmode,
61       const double *dU, magma_int_t u_elemstride,
62       magma_int_t u_compstride,
63       double *dV, magma_int_t v_elemstride,
64       magma_int_t v_compstride,
65       magma_int_t nelem);
66 
67   void magmablas_dbasis_apply_batched_eval_grad(magma_int_t P, magma_int_t Q,
68       magma_int_t dim, magma_int_t ncomp,
69       magma_int_t nqpt, const double* dinterp1d,
70       const double *dgrad1d, CeedTransposeMode tmode,
71       const double *dU, magma_int_t u_elemstride,
72       magma_int_t u_compstride, magma_int_t u_dimstride,
73       double *dV, magma_int_t v_elemstride,
74       magma_int_t v_compstride, magma_int_t v_dimstride,
75       magma_int_t dim_id, magma_int_t nelem);
76 
77   void magmablas_dbasis_apply_batched_eval_weight(magma_int_t Q, magma_int_t dim,
78       const double *dqweight1d, double *dV,
79       magma_int_t v_elemstride,
80       magma_int_t nelem);
81 
82   void magma_weight(magma_int_t grid, magma_int_t threads, magma_int_t nelem,
83                     magma_int_t Q,
84                     double *dqweight, double *dv);
85 
86   void magma_readDofs(const magma_int_t NCOMP,
87                       const magma_int_t nnodes,
88                       const magma_int_t esize,
89                       const magma_int_t nelem, magma_int_t *indices,
90                       const double *du, double *dv);
91 
92   void magma_readDofsTranspose(const magma_int_t NCOMP,
93                                const magma_int_t nnodes,
94                                const magma_int_t esize,
95                                const magma_int_t nelem, magma_int_t *indices,
96                                const double *du, double *dv);
97 
98   void magma_readDofsStrided(const magma_int_t NCOMP,
99                              const magma_int_t nnodes,
100                              const magma_int_t esize,
101                              const magma_int_t nelem, magma_int_t *strides,
102                              const double *du, double *dv);
103 
104   void magma_writeDofs(const magma_int_t NCOMP,
105                        const magma_int_t nnodes,
106                        const magma_int_t esize,
107                        const magma_int_t nelem, magma_int_t *indices,
108                        const double *du, double *dv);
109 
110   void magma_writeDofsTranspose(const magma_int_t NCOMP,
111                                 const magma_int_t nnodes,
112                                 const magma_int_t esize,
113                                 const magma_int_t nelem, magma_int_t *indices,
114                                 const double *du, double *dv);
115 
116   void magma_writeDofsStrided(const magma_int_t NCOMP,
117                               const magma_int_t nnodes,
118                               const magma_int_t esize,
119                               const magma_int_t nelem, magma_int_t *strides,
120                               const double *du, double *dv);
121 
122   magma_int_t
123   magma_isdevptr(const void *A);
124 
125   int CeedBasisCreateTensorH1_Magma(CeedInt dim, CeedInt P1d,
126                                     CeedInt Q1d,
127                                     const CeedScalar *interp1d,
128                                     const CeedScalar *grad1d,
129                                     const CeedScalar *qref1d,
130                                     const CeedScalar *qweight1d,
131                                     CeedBasis basis);
132 
133   int CeedBasisCreateH1_Magma(CeedElemTopology topo, CeedInt dim,
134                               CeedInt ndof, CeedInt nqpts,
135                               const CeedScalar *interp,
136                               const CeedScalar *grad,
137                               const CeedScalar *qref,
138                               const CeedScalar *qweight,
139                               CeedBasis basis);
140 
141   int CeedElemRestrictionCreate_Magma(CeedMemType mtype,
142                                       CeedCopyMode cmode,
143                                       const CeedInt *indices,
144                                       CeedElemRestriction r);
145 
146   int CeedElemRestrictionCreateBlocked_Magma(const CeedMemType mtype,
147       const CeedCopyMode cmode,
148       const CeedInt *indices,
149       const CeedElemRestriction res);
150   #ifdef __cplusplus
151 }
152   #endif
153 
154 #define CeedDebug(...)
155 //#define CeedDebug(format, ...) fprintf(stderr, format, ## __VA_ARGS__)
156 
157 // comment the line below to use the default magma_is_devptr function
158 #define magma_is_devptr magma_isdevptr
159 
160 // batch stride, override using -DMAGMA_BATCH_STRIDE=<desired-value>
161 #ifndef MAGMA_BATCH_STRIDE
162 #define MAGMA_BATCH_STRIDE (1000)
163 #endif
164