xref: /libCEED/backends/cuda-shared/ceed-cuda-shared-basis.c (revision 46dc07349c44057b9efae59cd6a2d41f419237bd)
1c532df63SYohann // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
2c532df63SYohann // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
3c532df63SYohann // All Rights reserved. See files LICENSE and NOTICE for details.
4c532df63SYohann //
5c532df63SYohann // This file is part of CEED, a collection of benchmarks, miniapps, software
6c532df63SYohann // libraries and APIs for efficient high-order finite element and spectral
7c532df63SYohann // element discretizations for exascale applications. For more information and
8c532df63SYohann // source code availability see http://github.com/ceed.
9c532df63SYohann //
10c532df63SYohann // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11c532df63SYohann // a collaborative effort of two U.S. Department of Energy organizations (Office
12c532df63SYohann // of Science and the National Nuclear Security Administration) responsible for
13c532df63SYohann // the planning and preparation of a capable exascale ecosystem, including
14c532df63SYohann // software, applications, hardware, advanced system engineering and early
15c532df63SYohann // testbed platforms, in support of the nation's exascale computing imperative.
16c532df63SYohann 
17ec3da8bcSJed Brown #include <ceed/ceed.h>
18ec3da8bcSJed Brown #include <ceed/backend.h>
19437930d1SJeremy L Thompson #include <ceed/jit-tools.h>
203d576824SJeremy L Thompson #include <cuda.h>
213d576824SJeremy L Thompson #include <cuda_runtime.h>
223d576824SJeremy L Thompson #include <stddef.h>
23c532df63SYohann #include "ceed-cuda-shared.h"
246d69246aSJeremy L Thompson #include "../cuda/ceed-cuda-compile.h"
25c532df63SYohann 
26c532df63SYohann 
27ab213215SJeremy L Thompson //------------------------------------------------------------------------------
28ab213215SJeremy L Thompson // Device initalization
29ab213215SJeremy L Thompson //------------------------------------------------------------------------------
30437930d1SJeremy L Thompson int CeedCudaInitInterp(CeedScalar *d_B, CeedInt P_1d, CeedInt Q_1d,
31c532df63SYohann                        CeedScalar **c_B);
32437930d1SJeremy L Thompson int CeedCudaInitInterpGrad(CeedScalar *d_B, CeedScalar *d_G, CeedInt P_1d,
33437930d1SJeremy L Thompson                            CeedInt Q_1d, CeedScalar **c_B_ptr,
347f823360Sjeremylt                            CeedScalar **c_G_ptr);
35c532df63SYohann 
36ab213215SJeremy L Thompson //------------------------------------------------------------------------------
37ab213215SJeremy L Thompson // Apply basis
38ab213215SJeremy L Thompson //------------------------------------------------------------------------------
39437930d1SJeremy L Thompson int CeedBasisApplyTensor_Cuda_shared(CeedBasis basis, const CeedInt num_elem,
40437930d1SJeremy L Thompson                                      CeedTransposeMode t_mode,
41437930d1SJeremy L Thompson                                      CeedEvalMode eval_mode, CeedVector u,
427f823360Sjeremylt                                      CeedVector v) {
43c532df63SYohann   int ierr;
44c532df63SYohann   Ceed ceed;
45e15f9bd0SJeremy L Thompson   ierr = CeedBasisGetCeed(basis, &ceed); CeedChkBackend(ierr);
466dbfb411Snbeams   Ceed_Cuda *ceed_Cuda;
47e15f9bd0SJeremy L Thompson   CeedGetData(ceed, &ceed_Cuda); CeedChkBackend(ierr);
48c532df63SYohann   CeedBasis_Cuda_shared *data;
49e15f9bd0SJeremy L Thompson   CeedBasisGetData(basis, &data); CeedChkBackend(ierr);
50437930d1SJeremy L Thompson   const CeedInt transpose = t_mode == CEED_TRANSPOSE;
51437930d1SJeremy L Thompson   CeedInt dim, num_comp;
52e15f9bd0SJeremy L Thompson   ierr = CeedBasisGetDimension(basis, &dim); CeedChkBackend(ierr);
53437930d1SJeremy L Thompson   ierr = CeedBasisGetNumComponents(basis, &num_comp); CeedChkBackend(ierr);
54c532df63SYohann 
55ab213215SJeremy L Thompson   // Read vectors
56c532df63SYohann   const CeedScalar *d_u;
57c532df63SYohann   CeedScalar *d_v;
58437930d1SJeremy L Thompson   if (eval_mode != CEED_EVAL_WEIGHT) {
59e15f9bd0SJeremy L Thompson     ierr = CeedVectorGetArrayRead(u, CEED_MEM_DEVICE, &d_u); CeedChkBackend(ierr);
60c532df63SYohann   }
619c774eddSJeremy L Thompson   ierr = CeedVectorGetArrayWrite(v, CEED_MEM_DEVICE, &d_v); CeedChkBackend(ierr);
62c532df63SYohann 
63ab213215SJeremy L Thompson   // Clear v for transpose mode
64437930d1SJeremy L Thompson   if (t_mode == CEED_TRANSPOSE) {
65c532df63SYohann     CeedInt length;
66e15f9bd0SJeremy L Thompson     ierr = CeedVectorGetLength(v, &length); CeedChkBackend(ierr);
67e15f9bd0SJeremy L Thompson     ierr = cudaMemset(d_v, 0, length * sizeof(CeedScalar)); CeedChkBackend(ierr);
68c532df63SYohann   }
69ab213215SJeremy L Thompson 
70ab213215SJeremy L Thompson   // Apply basis operation
71437930d1SJeremy L Thompson   switch (eval_mode) {
72ab213215SJeremy L Thompson   case CEED_EVAL_INTERP: {
73437930d1SJeremy L Thompson     CeedInt P_1d, Q_1d;
74437930d1SJeremy L Thompson     ierr = CeedBasisGetNumNodes1D(basis, &P_1d); CeedChkBackend(ierr);
75437930d1SJeremy L Thompson     ierr = CeedBasisGetNumQuadraturePoints1D(basis, &Q_1d); CeedChkBackend(ierr);
76437930d1SJeremy L Thompson     CeedInt thread_1d = CeedIntMax(Q_1d, P_1d);
77437930d1SJeremy L Thompson     ierr = CeedCudaInitInterp(data->d_interp_1d, P_1d, Q_1d, &data->c_B);
78e15f9bd0SJeremy L Thompson     CeedChkBackend(ierr);
79437930d1SJeremy L Thompson     void *interp_args[] = {(void *) &num_elem, (void *) &transpose, &data->c_B,
80ccf0fe6fSjeremylt                            &d_u, &d_v
81ccf0fe6fSjeremylt                           };
824d537eeaSYohann     if (dim == 1) {
83437930d1SJeremy L Thompson       CeedInt elems_per_block = 32;
84437930d1SJeremy L Thompson       CeedInt grid = num_elem/elems_per_block +
85437930d1SJeremy L Thompson                      ((num_elem / elems_per_block*elems_per_block < num_elem) ? 1 : 0 );
86437930d1SJeremy L Thompson       CeedInt shared_mem = elems_per_block*thread_1d*sizeof(CeedScalar);
87437930d1SJeremy L Thompson       ierr = CeedRunKernelDimSharedCuda(ceed, data->Interp, grid, thread_1d, 1,
88437930d1SJeremy L Thompson                                         elems_per_block, shared_mem,
89437930d1SJeremy L Thompson                                         interp_args); CeedChkBackend(ierr);
90074be161SYohann Dudouit     } else if (dim == 2) {
91437930d1SJeremy L Thompson       const CeedInt opt_elems[7] = {0, 32, 8, 6, 4, 2, 8};
92437930d1SJeremy L Thompson       // elems_per_block must be at least 1
93437930d1SJeremy L Thompson       CeedInt elems_per_block = CeedIntMax(thread_1d < 7 ? opt_elems[thread_1d] /
94437930d1SJeremy L Thompson                                            num_comp : 1, 1);
95437930d1SJeremy L Thompson       CeedInt grid = num_elem / elems_per_block +
96437930d1SJeremy L Thompson                      ((num_elem / elems_per_block*elems_per_block < num_elem) ? 1 : 0 );
97437930d1SJeremy L Thompson       CeedInt shared_mem = num_comp*elems_per_block*thread_1d*thread_1d*sizeof(
98437930d1SJeremy L Thompson                              CeedScalar);
99437930d1SJeremy L Thompson       ierr = CeedRunKernelDimSharedCuda(ceed, data->Interp, grid, thread_1d,
100437930d1SJeremy L Thompson                                         thread_1d,
101437930d1SJeremy L Thompson                                         num_comp*elems_per_block, shared_mem,
102437930d1SJeremy L Thompson                                         interp_args); CeedChkBackend(ierr);
103074be161SYohann Dudouit     } else if (dim == 3) {
104437930d1SJeremy L Thompson       CeedInt elems_per_block = 1;
105437930d1SJeremy L Thompson       CeedInt grid = num_elem / elems_per_block +
106437930d1SJeremy L Thompson                      ((num_elem / elems_per_block*elems_per_block < num_elem) ? 1 : 0 );
107437930d1SJeremy L Thompson       CeedInt shared_mem = num_comp*elems_per_block*thread_1d*thread_1d*sizeof(
108437930d1SJeremy L Thompson                              CeedScalar);
109437930d1SJeremy L Thompson       ierr = CeedRunKernelDimSharedCuda(ceed, data->Interp, grid, thread_1d,
110437930d1SJeremy L Thompson                                         thread_1d,
111437930d1SJeremy L Thompson                                         num_comp*elems_per_block, shared_mem,
112437930d1SJeremy L Thompson                                         interp_args); CeedChkBackend(ierr);
113074be161SYohann Dudouit     }
114ab213215SJeremy L Thompson   } break;
115ab213215SJeremy L Thompson   case CEED_EVAL_GRAD: {
116437930d1SJeremy L Thompson     CeedInt P_1d, Q_1d;
117437930d1SJeremy L Thompson     ierr = CeedBasisGetNumNodes1D(basis, &P_1d); CeedChkBackend(ierr);
118437930d1SJeremy L Thompson     ierr = CeedBasisGetNumQuadraturePoints1D(basis, &Q_1d); CeedChkBackend(ierr);
119437930d1SJeremy L Thompson     CeedInt thread_1d = CeedIntMax(Q_1d, P_1d);
120437930d1SJeremy L Thompson     ierr = CeedCudaInitInterpGrad(data->d_interp_1d, data->d_grad_1d, P_1d,
121437930d1SJeremy L Thompson                                   Q_1d, &data->c_B, &data->c_G);
122e15f9bd0SJeremy L Thompson     CeedChkBackend(ierr);
123437930d1SJeremy L Thompson     void *grad_args[] = {(void *) &num_elem, (void *) &transpose, &data->c_B,
124ccf0fe6fSjeremylt                          &data->c_G, &d_u, &d_v
125ccf0fe6fSjeremylt                         };
1264d537eeaSYohann     if (dim == 1) {
127437930d1SJeremy L Thompson       CeedInt elems_per_block = 32;
128437930d1SJeremy L Thompson       CeedInt grid = num_elem / elems_per_block +
129437930d1SJeremy L Thompson                      ((num_elem / elems_per_block*elems_per_block<num_elem) ? 1 : 0 );
130437930d1SJeremy L Thompson       CeedInt shared_mem = elems_per_block*thread_1d*sizeof(CeedScalar);
131437930d1SJeremy L Thompson       ierr = CeedRunKernelDimSharedCuda(ceed, data->Grad, grid, thread_1d, 1,
132437930d1SJeremy L Thompson                                         elems_per_block, shared_mem, grad_args);
133e15f9bd0SJeremy L Thompson       CeedChkBackend(ierr);
134074be161SYohann Dudouit     } else if (dim == 2) {
135437930d1SJeremy L Thompson       const CeedInt opt_elems[7] = {0, 32, 8, 6, 4, 2, 8};
136437930d1SJeremy L Thompson       // elems_per_block must be at least 1
137437930d1SJeremy L Thompson       CeedInt elems_per_block = CeedIntMax(thread_1d < 7 ? opt_elems[thread_1d] /
138437930d1SJeremy L Thompson                                            num_comp : 1, 1);
139437930d1SJeremy L Thompson       CeedInt grid = num_elem / elems_per_block +
140437930d1SJeremy L Thompson                      ((num_elem / elems_per_block*elems_per_block < num_elem) ? 1 : 0 );
141437930d1SJeremy L Thompson       CeedInt shared_mem = num_comp*elems_per_block*thread_1d*thread_1d*sizeof(
142437930d1SJeremy L Thompson                              CeedScalar);
143437930d1SJeremy L Thompson       ierr = CeedRunKernelDimSharedCuda(ceed, data->Grad, grid, thread_1d, thread_1d,
144437930d1SJeremy L Thompson                                         num_comp*elems_per_block, shared_mem,
145437930d1SJeremy L Thompson                                         grad_args); CeedChkBackend(ierr);
146074be161SYohann Dudouit     } else if (dim == 3) {
147437930d1SJeremy L Thompson       CeedInt elems_per_block = 1;
148437930d1SJeremy L Thompson       CeedInt grid = num_elem / elems_per_block +
149437930d1SJeremy L Thompson                      ((num_elem / elems_per_block*elems_per_block < num_elem) ? 1 : 0 );
150437930d1SJeremy L Thompson       CeedInt shared_mem = num_comp*elems_per_block*thread_1d*thread_1d*sizeof(
151437930d1SJeremy L Thompson                              CeedScalar);
152437930d1SJeremy L Thompson       ierr = CeedRunKernelDimSharedCuda(ceed, data->Grad, grid, thread_1d, thread_1d,
153437930d1SJeremy L Thompson                                         num_comp*elems_per_block, shared_mem,
154437930d1SJeremy L Thompson                                         grad_args); CeedChkBackend(ierr);
155074be161SYohann Dudouit     }
156ab213215SJeremy L Thompson   } break;
157ab213215SJeremy L Thompson   case CEED_EVAL_WEIGHT: {
158437930d1SJeremy L Thompson     CeedInt Q_1d;
159437930d1SJeremy L Thompson     ierr = CeedBasisGetNumQuadraturePoints1D(basis, &Q_1d); CeedChkBackend(ierr);
160437930d1SJeremy L Thompson     void *weight_args[] = {(void *) &num_elem, (void *) &data->d_q_weight_1d, &d_v};
161074be161SYohann Dudouit     if (dim == 1) {
162437930d1SJeremy L Thompson       const CeedInt elems_per_block = 32 / Q_1d;
163437930d1SJeremy L Thompson       const CeedInt gridsize = num_elem / elems_per_block +
164437930d1SJeremy L Thompson                                ((num_elem / elems_per_block*elems_per_block < num_elem) ? 1 : 0 );
165437930d1SJeremy L Thompson       ierr = CeedRunKernelDimCuda(ceed, data->Weight, gridsize, Q_1d,
166437930d1SJeremy L Thompson                                   elems_per_block, 1, weight_args);
167e15f9bd0SJeremy L Thompson       CeedChkBackend(ierr);
168074be161SYohann Dudouit     } else if (dim == 2) {
169437930d1SJeremy L Thompson       const CeedInt opt_elems = 32 / (Q_1d * Q_1d);
170437930d1SJeremy L Thompson       const CeedInt elems_per_block = opt_elems > 0 ? opt_elems : 1;
171437930d1SJeremy L Thompson       const CeedInt gridsize = num_elem / elems_per_block +
172437930d1SJeremy L Thompson                                ((num_elem / elems_per_block*elems_per_block < num_elem) ? 1 : 0 );
173437930d1SJeremy L Thompson       ierr = CeedRunKernelDimCuda(ceed, data->Weight, gridsize, Q_1d, Q_1d,
174437930d1SJeremy L Thompson                                   elems_per_block, weight_args);
175e15f9bd0SJeremy L Thompson       CeedChkBackend(ierr);
176074be161SYohann Dudouit     } else if (dim == 3) {
177437930d1SJeremy L Thompson       const CeedInt gridsize = num_elem;
178437930d1SJeremy L Thompson       ierr = CeedRunKernelDimCuda(ceed, data->Weight, gridsize, Q_1d, Q_1d, Q_1d,
179437930d1SJeremy L Thompson                                   weight_args);
180e15f9bd0SJeremy L Thompson       CeedChkBackend(ierr);
181074be161SYohann Dudouit     }
182ab213215SJeremy L Thompson   } break;
183ab213215SJeremy L Thompson   // LCOV_EXCL_START
184ab213215SJeremy L Thompson   // Evaluate the divergence to/from the quadrature points
185ab213215SJeremy L Thompson   case CEED_EVAL_DIV:
186e15f9bd0SJeremy L Thompson     return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_DIV not supported");
187ab213215SJeremy L Thompson   // Evaluate the curl to/from the quadrature points
188ab213215SJeremy L Thompson   case CEED_EVAL_CURL:
189e15f9bd0SJeremy L Thompson     return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_CURL not supported");
190ab213215SJeremy L Thompson   // Take no action, BasisApply should not have been called
191ab213215SJeremy L Thompson   case CEED_EVAL_NONE:
192e15f9bd0SJeremy L Thompson     return CeedError(ceed, CEED_ERROR_BACKEND,
193ab213215SJeremy L Thompson                      "CEED_EVAL_NONE does not make sense in this context");
194ab213215SJeremy L Thompson     // LCOV_EXCL_STOP
195c532df63SYohann   }
196c532df63SYohann 
197ab213215SJeremy L Thompson   // Restore vectors
198437930d1SJeremy L Thompson   if (eval_mode != CEED_EVAL_WEIGHT) {
199e15f9bd0SJeremy L Thompson     ierr = CeedVectorRestoreArrayRead(u, &d_u); CeedChkBackend(ierr);
200c532df63SYohann   }
201e15f9bd0SJeremy L Thompson   ierr = CeedVectorRestoreArray(v, &d_v); CeedChkBackend(ierr);
202e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
203c532df63SYohann }
204c532df63SYohann 
205ab213215SJeremy L Thompson //------------------------------------------------------------------------------
206ab213215SJeremy L Thompson // Destroy basis
207ab213215SJeremy L Thompson //------------------------------------------------------------------------------
208c532df63SYohann static int CeedBasisDestroy_Cuda_shared(CeedBasis basis) {
209c532df63SYohann   int ierr;
210c532df63SYohann   Ceed ceed;
211e15f9bd0SJeremy L Thompson   ierr = CeedBasisGetCeed(basis, &ceed); CeedChkBackend(ierr);
212c532df63SYohann 
213c532df63SYohann   CeedBasis_Cuda_shared *data;
214e15f9bd0SJeremy L Thompson   ierr = CeedBasisGetData(basis, &data); CeedChkBackend(ierr);
215c532df63SYohann 
216c532df63SYohann   CeedChk_Cu(ceed, cuModuleUnload(data->module));
217c532df63SYohann 
218437930d1SJeremy L Thompson   ierr = cudaFree(data->d_q_weight_1d); CeedChk_Cu(ceed, ierr);
219437930d1SJeremy L Thompson   ierr = cudaFree(data->d_interp_1d); CeedChk_Cu(ceed, ierr);
220437930d1SJeremy L Thompson   ierr = cudaFree(data->d_grad_1d); CeedChk_Cu(ceed, ierr);
221437930d1SJeremy L Thompson   ierr = cudaFree(data->d_collo_grad_1d); CeedChk_Cu(ceed, ierr);
222c532df63SYohann 
223e15f9bd0SJeremy L Thompson   ierr = CeedFree(&data); CeedChkBackend(ierr);
224c532df63SYohann 
225e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
226c532df63SYohann }
227c532df63SYohann 
228ab213215SJeremy L Thompson //------------------------------------------------------------------------------
229ab213215SJeremy L Thompson // Create tensor basis
230ab213215SJeremy L Thompson //------------------------------------------------------------------------------
231437930d1SJeremy L Thompson int CeedBasisCreateTensorH1_Cuda_shared(CeedInt dim, CeedInt P_1d, CeedInt Q_1d,
232437930d1SJeremy L Thompson                                         const CeedScalar *interp_1d,
233437930d1SJeremy L Thompson                                         const CeedScalar *grad_1d,
234437930d1SJeremy L Thompson                                         const CeedScalar *q_ref_1d,
235437930d1SJeremy L Thompson                                         const CeedScalar *q_weight_1d,
236c532df63SYohann                                         CeedBasis basis) {
237c532df63SYohann   int ierr;
238c532df63SYohann   Ceed ceed;
239e15f9bd0SJeremy L Thompson   ierr = CeedBasisGetCeed(basis, &ceed); CeedChkBackend(ierr);
240c532df63SYohann   CeedBasis_Cuda_shared *data;
241e15f9bd0SJeremy L Thompson   ierr = CeedCalloc(1, &data); CeedChkBackend(ierr);
242c532df63SYohann 
243ab213215SJeremy L Thompson   // Copy basis data to GPU
244437930d1SJeremy L Thompson   const CeedInt q_bytes = Q_1d * sizeof(CeedScalar);
245437930d1SJeremy L Thompson   ierr = cudaMalloc((void **)&data->d_q_weight_1d, q_bytes);
246437930d1SJeremy L Thompson   CeedChk_Cu(ceed, ierr);
247437930d1SJeremy L Thompson   ierr = cudaMemcpy(data->d_q_weight_1d, q_weight_1d, q_bytes,
248c532df63SYohann                     cudaMemcpyHostToDevice); CeedChk_Cu(ceed, ierr);
249c532df63SYohann 
250437930d1SJeremy L Thompson   const CeedInt interp_bytes = q_bytes * P_1d;
251437930d1SJeremy L Thompson   ierr = cudaMalloc((void **)&data->d_interp_1d, interp_bytes);
252437930d1SJeremy L Thompson   CeedChk_Cu(ceed, ierr);
253437930d1SJeremy L Thompson   ierr = cudaMemcpy(data->d_interp_1d, interp_1d, interp_bytes,
254c532df63SYohann                     cudaMemcpyHostToDevice); CeedChk_Cu(ceed, ierr);
255c532df63SYohann 
256437930d1SJeremy L Thompson   ierr = cudaMalloc((void **)&data->d_grad_1d, interp_bytes);
257437930d1SJeremy L Thompson   CeedChk_Cu(ceed, ierr);
258437930d1SJeremy L Thompson   ierr = cudaMemcpy(data->d_grad_1d, grad_1d, interp_bytes,
259c532df63SYohann                     cudaMemcpyHostToDevice); CeedChk_Cu(ceed, ierr);
260c532df63SYohann 
261ab213215SJeremy L Thompson   // Compute collocated gradient and copy to GPU
262437930d1SJeremy L Thompson   data->d_collo_grad_1d = NULL;
263437930d1SJeremy L Thompson   if (dim == 3 && Q_1d >= P_1d) {
264437930d1SJeremy L Thompson     CeedScalar *collo_grad_1d;
265437930d1SJeremy L Thompson     ierr = CeedMalloc(Q_1d*Q_1d, &collo_grad_1d); CeedChkBackend(ierr);
266437930d1SJeremy L Thompson     ierr = CeedBasisGetCollocatedGrad(basis, collo_grad_1d); CeedChkBackend(ierr);
267437930d1SJeremy L Thompson     ierr = cudaMalloc((void **)&data->d_collo_grad_1d, q_bytes * Q_1d);
268ac421f39SYohann     CeedChk_Cu(ceed, ierr);
269437930d1SJeremy L Thompson     ierr = cudaMemcpy(data->d_collo_grad_1d, collo_grad_1d, q_bytes * Q_1d,
270ac421f39SYohann                       cudaMemcpyHostToDevice); CeedChk_Cu(ceed, ierr);
271437930d1SJeremy L Thompson     ierr = CeedFree(&collo_grad_1d); CeedChkBackend(ierr);
272ac421f39SYohann   }
273ac421f39SYohann 
274ab213215SJeremy L Thompson   // Compile basis kernels
275437930d1SJeremy L Thompson   CeedInt num_comp;
276437930d1SJeremy L Thompson   ierr = CeedBasisGetNumComponents(basis, &num_comp); CeedChkBackend(ierr);
277437930d1SJeremy L Thompson   char *basis_kernel_path, *basis_kernel_source;
278437930d1SJeremy L Thompson   ierr = CeedPathConcatenate(ceed, __FILE__, "kernels/cuda-shared-basis.h",
279437930d1SJeremy L Thompson                              &basis_kernel_path); CeedChkBackend(ierr);
280*46dc0734SJeremy L Thompson   CeedDebug256(ceed, 2, "----- Loading Basis Kernel Source -----\n");
281437930d1SJeremy L Thompson   ierr = CeedLoadSourceToBuffer(ceed, basis_kernel_path, &basis_kernel_source);
282437930d1SJeremy L Thompson   CeedChkBackend(ierr);
283*46dc0734SJeremy L Thompson   CeedDebug256(ceed, 2, "----- Loading Basis Kernel Source Complete -----\n");
284437930d1SJeremy L Thompson   ierr = CeedCompileCuda(ceed, basis_kernel_source, &data->module, 8,
285437930d1SJeremy L Thompson                          "Q1D", Q_1d,
286437930d1SJeremy L Thompson                          "P1D", P_1d,
287437930d1SJeremy L Thompson                          "T1D", CeedIntMax(Q_1d, P_1d),
288437930d1SJeremy L Thompson                          "BASIS_BUF_LEN", num_comp * CeedIntPow(Q_1d > P_1d ?
289437930d1SJeremy L Thompson                              Q_1d : P_1d, dim),
290c532df63SYohann                          "BASIS_DIM", dim,
291437930d1SJeremy L Thompson                          "BASIS_NCOMP", num_comp,
292437930d1SJeremy L Thompson                          "BASIS_ELEMSIZE", CeedIntPow(P_1d, dim),
293437930d1SJeremy L Thompson                          "BASIS_NQPT", CeedIntPow(Q_1d, dim)
294e15f9bd0SJeremy L Thompson                         ); CeedChkBackend(ierr);
295437930d1SJeremy L Thompson   ierr = CeedGetKernelCuda(ceed, data->module, "Interp", &data->Interp);
296e15f9bd0SJeremy L Thompson   CeedChkBackend(ierr);
297437930d1SJeremy L Thompson   ierr = CeedGetKernelCuda(ceed, data->module, "Grad", &data->Grad);
298e15f9bd0SJeremy L Thompson   CeedChkBackend(ierr);
299437930d1SJeremy L Thompson   ierr = CeedGetKernelCuda(ceed, data->module, "Weight", &data->Weight);
300e15f9bd0SJeremy L Thompson   CeedChkBackend(ierr);
301437930d1SJeremy L Thompson   ierr = CeedFree(&basis_kernel_path); CeedChkBackend(ierr);
302437930d1SJeremy L Thompson   ierr = CeedFree(&basis_kernel_source); CeedChkBackend(ierr);
303c532df63SYohann 
304e15f9bd0SJeremy L Thompson   ierr = CeedBasisSetData(basis, data); CeedChkBackend(ierr);
305ab213215SJeremy L Thompson 
306ab213215SJeremy L Thompson   // Register backend functions
307c532df63SYohann   ierr = CeedSetBackendFunction(ceed, "Basis", basis, "Apply",
308c532df63SYohann                                 CeedBasisApplyTensor_Cuda_shared);
309e15f9bd0SJeremy L Thompson   CeedChkBackend(ierr);
310c532df63SYohann   ierr = CeedSetBackendFunction(ceed, "Basis", basis, "Destroy",
311e15f9bd0SJeremy L Thompson                                 CeedBasisDestroy_Cuda_shared); CeedChkBackend(ierr);
312e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
313c532df63SYohann }
314ab213215SJeremy L Thompson //------------------------------------------------------------------------------
315