xref: /libCEED/rust/libceed-sys/c-src/backends/magma/ceed-magma.h (revision 868539c291cd6e4adc5c1e2f0ea123f6c9e198f6)
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_writeDofs(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 *indices,
102                        const double *du, double *dv);
103 
104   void magma_writeDofsTranspose(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   magma_int_t
111   magma_isdevptr(const void *A);
112 
113   int CeedBasisCreateTensorH1_Magma(CeedInt dim, CeedInt P1d,
114                                     CeedInt Q1d,
115                                     const CeedScalar *interp1d,
116                                     const CeedScalar *grad1d,
117                                     const CeedScalar *qref1d,
118                                     const CeedScalar *qweight1d,
119                                     CeedBasis basis);
120 
121   int CeedBasisCreateH1_Magma(CeedElemTopology topo, CeedInt dim,
122                               CeedInt ndof, CeedInt nqpts,
123                               const CeedScalar *interp,
124                               const CeedScalar *grad,
125                               const CeedScalar *qref,
126                               const CeedScalar *qweight,
127                               CeedBasis basis);
128 
129   int CeedElemRestrictionCreate_Magma(CeedMemType mtype,
130                                       CeedCopyMode cmode,
131                                       const CeedInt *indices,
132                                       CeedElemRestriction r);
133 
134   int CeedElemRestrictionCreateBlocked_Magma(const CeedMemType mtype,
135       const CeedCopyMode cmode,
136       const CeedInt *indices,
137       const CeedElemRestriction res);
138   #ifdef __cplusplus
139 }
140   #endif
141 
142 #define CeedDebug(...)
143 //#define CeedDebug(format, ...) fprintf(stderr, format, ## __VA_ARGS__)
144 
145 // comment the line below to use the default magma_is_devptr function
146 #define magma_is_devptr magma_isdevptr
147 
148 // batch stride, override using -DMAGMA_BATCH_STRIDE=<desired-value>
149 #ifndef MAGMA_BATCH_STRIDE
150 #define MAGMA_BATCH_STRIDE (1000)
151 #endif
152