xref: /libCEED/rust/libceed-sys/c-src/backends/hip-ref/ceed-hip-ref.h (revision 437930d19388999b5cc2d76e2fe0d14f58fb41f3)
10d0321e0SJeremy L Thompson // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
20d0321e0SJeremy L Thompson // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
30d0321e0SJeremy L Thompson // All Rights reserved. See files LICENSE and NOTICE for details.
40d0321e0SJeremy L Thompson //
50d0321e0SJeremy L Thompson // This file is part of CEED, a collection of benchmarks, miniapps, software
60d0321e0SJeremy L Thompson // libraries and APIs for efficient high-order finite element and spectral
70d0321e0SJeremy L Thompson // element discretizations for exascale applications. For more information and
80d0321e0SJeremy L Thompson // source code availability see http://github.com/ceed.
90d0321e0SJeremy L Thompson //
100d0321e0SJeremy L Thompson // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
110d0321e0SJeremy L Thompson // a collaborative effort of two U.S. Department of Energy organizations (Office
120d0321e0SJeremy L Thompson // of Science and the National Nuclear Security Administration) responsible for
130d0321e0SJeremy L Thompson // the planning and preparation of a capable exascale ecosystem, including
140d0321e0SJeremy L Thompson // software, applications, hardware, advanced system engineering and early
150d0321e0SJeremy L Thompson // testbed platforms, in support of the nation's exascale computing imperative.
160d0321e0SJeremy L Thompson 
170d0321e0SJeremy L Thompson #ifndef _ceed_hip_h
180d0321e0SJeremy L Thompson #define _ceed_hip_h
190d0321e0SJeremy L Thompson 
200d0321e0SJeremy L Thompson #include <ceed/ceed.h>
210d0321e0SJeremy L Thompson #include <ceed/backend.h>
220d0321e0SJeremy L Thompson #include <hip/hip_runtime.h>
230d0321e0SJeremy L Thompson #include <hipblas.h>
240d0321e0SJeremy L Thompson #include "../hip/ceed-hip-common.h"
250d0321e0SJeremy L Thompson 
260d0321e0SJeremy L Thompson typedef struct {
270d0321e0SJeremy L Thompson   CeedScalar *h_array;
280d0321e0SJeremy L Thompson   CeedScalar *h_array_borrowed;
290d0321e0SJeremy L Thompson   CeedScalar *h_array_owned;
300d0321e0SJeremy L Thompson   CeedScalar *d_array;
310d0321e0SJeremy L Thompson   CeedScalar *d_array_borrowed;
320d0321e0SJeremy L Thompson   CeedScalar *d_array_owned;
330d0321e0SJeremy L Thompson } CeedVector_Hip;
340d0321e0SJeremy L Thompson 
350d0321e0SJeremy L Thompson typedef struct {
360d0321e0SJeremy L Thompson   hipModule_t module;
37*437930d1SJeremy L Thompson   hipFunction_t StridedTranspose;
38*437930d1SJeremy L Thompson   hipFunction_t StridedNoTranspose;
39*437930d1SJeremy L Thompson   hipFunction_t OffsetTranspose;
40*437930d1SJeremy L Thompson   hipFunction_t OffsetNoTranspose;
41*437930d1SJeremy L Thompson   CeedInt num_nodes;
420d0321e0SJeremy L Thompson   CeedInt *h_ind;
430d0321e0SJeremy L Thompson   CeedInt *h_ind_allocated;
440d0321e0SJeremy L Thompson   CeedInt *d_ind;
450d0321e0SJeremy L Thompson   CeedInt *d_ind_allocated;
46*437930d1SJeremy L Thompson   CeedInt *d_t_offsets;
47*437930d1SJeremy L Thompson   CeedInt *d_t_indices;
48*437930d1SJeremy L Thompson   CeedInt *d_l_vec_indices;
490d0321e0SJeremy L Thompson } CeedElemRestriction_Hip;
500d0321e0SJeremy L Thompson 
51*437930d1SJeremy L Thompson typedef struct {
52*437930d1SJeremy L Thompson   hipModule_t module;
53*437930d1SJeremy L Thompson   hipFunction_t Interp;
54*437930d1SJeremy L Thompson   hipFunction_t Grad;
55*437930d1SJeremy L Thompson   hipFunction_t Weight;
56*437930d1SJeremy L Thompson   CeedScalar *d_interp_1d;
57*437930d1SJeremy L Thompson   CeedScalar *d_grad_1d;
58*437930d1SJeremy L Thompson   CeedScalar *d_q_weight_1d;
59*437930d1SJeremy L Thompson } CeedBasis_Hip;
60*437930d1SJeremy L Thompson 
61*437930d1SJeremy L Thompson typedef struct {
62*437930d1SJeremy L Thompson   hipModule_t module;
63*437930d1SJeremy L Thompson   hipFunction_t Interp;
64*437930d1SJeremy L Thompson   hipFunction_t Grad;
65*437930d1SJeremy L Thompson   hipFunction_t Weight;
66*437930d1SJeremy L Thompson   CeedScalar *d_interp;
67*437930d1SJeremy L Thompson   CeedScalar *d_grad;
68*437930d1SJeremy L Thompson   CeedScalar *d_q_weight;
69*437930d1SJeremy L Thompson } CeedBasisNonTensor_Hip;
70*437930d1SJeremy L Thompson 
710d0321e0SJeremy L Thompson // We use a struct to avoid having to memCpy the array of pointers
720d0321e0SJeremy L Thompson // __global__ copies by value the struct.
730d0321e0SJeremy L Thompson typedef struct {
740d0321e0SJeremy L Thompson   const CeedScalar *inputs[CEED_FIELD_MAX];
750d0321e0SJeremy L Thompson   CeedScalar *outputs[CEED_FIELD_MAX];
760d0321e0SJeremy L Thompson } Fields_Hip;
770d0321e0SJeremy L Thompson 
780d0321e0SJeremy L Thompson typedef struct {
790d0321e0SJeremy L Thompson   hipModule_t module;
80*437930d1SJeremy L Thompson   char *qfunction_name;
81*437930d1SJeremy L Thompson   char *qfunction_source;
82*437930d1SJeremy L Thompson   hipFunction_t QFunction;
830d0321e0SJeremy L Thompson   Fields_Hip fields;
840d0321e0SJeremy L Thompson   void *d_c;
850d0321e0SJeremy L Thompson } CeedQFunction_Hip;
860d0321e0SJeremy L Thompson 
870d0321e0SJeremy L Thompson typedef struct {
880d0321e0SJeremy L Thompson   void *h_data;
890d0321e0SJeremy L Thompson   void *h_data_borrowed;
900d0321e0SJeremy L Thompson   void *h_data_owned;
910d0321e0SJeremy L Thompson   void *d_data;
920d0321e0SJeremy L Thompson   void *d_data_borrowed;
930d0321e0SJeremy L Thompson   void *d_data_owned;
940d0321e0SJeremy L Thompson } CeedQFunctionContext_Hip;
950d0321e0SJeremy L Thompson 
960d0321e0SJeremy L Thompson typedef struct {
970d0321e0SJeremy L Thompson   hipModule_t module;
980d0321e0SJeremy L Thompson   hipFunction_t linearDiagonal;
990d0321e0SJeremy L Thompson   hipFunction_t linearPointBlock;
1000d0321e0SJeremy L Thompson   CeedBasis basisin, basisout;
1010d0321e0SJeremy L Thompson   CeedElemRestriction diagrstr, pbdiagrstr;
1020d0321e0SJeremy L Thompson   CeedVector elemdiag, pbelemdiag;
1030d0321e0SJeremy L Thompson   CeedInt numemodein, numemodeout, nnodes;
1040d0321e0SJeremy L Thompson   CeedEvalMode *h_emodein, *h_emodeout;
1050d0321e0SJeremy L Thompson   CeedEvalMode *d_emodein, *d_emodeout;
1060d0321e0SJeremy L Thompson   CeedScalar *d_identity, *d_interpin, *d_interpout, *d_gradin, *d_gradout;
1070d0321e0SJeremy L Thompson } CeedOperatorDiag_Hip;
1080d0321e0SJeremy L Thompson 
1090d0321e0SJeremy L Thompson typedef struct {
1100d0321e0SJeremy L Thompson   CeedVector *evecs;   // E-vectors, inputs followed by outputs
1110d0321e0SJeremy L Thompson   CeedVector *qvecsin;    // Input Q-vectors needed to apply operator
1120d0321e0SJeremy L Thompson   CeedVector *qvecsout;   // Output Q-vectors needed to apply operator
1130d0321e0SJeremy L Thompson   CeedInt    numein;
1140d0321e0SJeremy L Thompson   CeedInt    numeout;
1150d0321e0SJeremy L Thompson   CeedInt    qfnumactivein, qfnumactiveout;
1160d0321e0SJeremy L Thompson   CeedVector *qfactivein;
1170d0321e0SJeremy L Thompson   CeedOperatorDiag_Hip *diag;
1180d0321e0SJeremy L Thompson } CeedOperator_Hip;
1190d0321e0SJeremy L Thompson 
1200d0321e0SJeremy L Thompson CEED_INTERN int CeedHipGetHipblasHandle(Ceed ceed, hipblasHandle_t *handle);
1210d0321e0SJeremy L Thompson 
1220d0321e0SJeremy L Thompson CEED_INTERN int CeedVectorCreate_Hip(CeedInt n, CeedVector vec);
1230d0321e0SJeremy L Thompson 
1240d0321e0SJeremy L Thompson CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mtype,
1250d0321e0SJeremy L Thompson     CeedCopyMode cmode, const CeedInt *indices, CeedElemRestriction r);
1260d0321e0SJeremy L Thompson 
1270d0321e0SJeremy L Thompson CEED_INTERN int CeedElemRestrictionCreateBlocked_Hip(const CeedMemType mtype,
1280d0321e0SJeremy L Thompson     const CeedCopyMode cmode, const CeedInt *indices,
1290d0321e0SJeremy L Thompson     const CeedElemRestriction res);
1300d0321e0SJeremy L Thompson 
1310d0321e0SJeremy L Thompson CEED_INTERN int CeedBasisApplyElems_Hip(CeedBasis basis, const CeedInt nelem,
1320d0321e0SJeremy L Thompson                                         CeedTransposeMode tmode, CeedEvalMode emode, const CeedVector u, CeedVector v);
1330d0321e0SJeremy L Thompson 
1340d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionApplyElems_Hip(CeedQFunction qf, const CeedInt Q,
1350d0321e0SJeremy L Thompson     const CeedVector *const u, const CeedVector *v);
1360d0321e0SJeremy L Thompson 
1370d0321e0SJeremy L Thompson CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P1d,
1380d0321e0SJeremy L Thompson     CeedInt Q1d,
1390d0321e0SJeremy L Thompson     const CeedScalar *interp1d,
1400d0321e0SJeremy L Thompson     const CeedScalar *grad1d,
1410d0321e0SJeremy L Thompson     const CeedScalar *qref1d,
1420d0321e0SJeremy L Thompson     const CeedScalar *qweight1d,
1430d0321e0SJeremy L Thompson     CeedBasis basis);
1440d0321e0SJeremy L Thompson 
1450d0321e0SJeremy L Thompson CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology, CeedInt, CeedInt,
1460d0321e0SJeremy L Thompson                                       CeedInt, const CeedScalar *,
1470d0321e0SJeremy L Thompson                                       const CeedScalar *, const CeedScalar *,
1480d0321e0SJeremy L Thompson                                       const CeedScalar *, CeedBasis);
1490d0321e0SJeremy L Thompson 
1500d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf);
1510d0321e0SJeremy L Thompson 
1520d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx);
1530d0321e0SJeremy L Thompson 
1540d0321e0SJeremy L Thompson CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op);
1550d0321e0SJeremy L Thompson 
1560d0321e0SJeremy L Thompson CEED_INTERN int CeedCompositeOperatorCreate_Hip(CeedOperator op);
1570d0321e0SJeremy L Thompson #endif
158