xref: /libCEED/rust/libceed-sys/c-src/backends/cuda-shared/ceed-cuda-shared-basis.c (revision ca7355308a14805110a7d98dabf1f658d5ec16d5)
13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3c532df63SYohann //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
5c532df63SYohann //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
7c532df63SYohann 
849aac155SJeremy L Thompson #include <ceed.h>
9ec3da8bcSJed Brown #include <ceed/backend.h>
10437930d1SJeremy L Thompson #include <ceed/jit-tools.h>
113d576824SJeremy L Thompson #include <cuda.h>
123d576824SJeremy L Thompson #include <cuda_runtime.h>
1349aac155SJeremy L Thompson #include <stdbool.h>
143d576824SJeremy L Thompson #include <stddef.h>
15c532df63SYohann 
1649aac155SJeremy L Thompson #include "../cuda/ceed-cuda-common.h"
172b730f8bSJeremy L Thompson #include "../cuda/ceed-cuda-compile.h"
182b730f8bSJeremy L Thompson #include "ceed-cuda-shared.h"
19c532df63SYohann 
20ab213215SJeremy L Thompson //------------------------------------------------------------------------------
21ab213215SJeremy L Thompson // Device initalization
22ab213215SJeremy L Thompson //------------------------------------------------------------------------------
23eb7e6cafSJeremy L Thompson int CeedInit_CudaInterp(CeedScalar *d_B, CeedInt P_1d, CeedInt Q_1d, CeedScalar **c_B);
24eb7e6cafSJeremy L Thompson int CeedInit_CudaGrad(CeedScalar *d_B, CeedScalar *d_G, CeedInt P_1d, CeedInt Q_1d, CeedScalar **c_B_ptr, CeedScalar **c_G_ptr);
25eb7e6cafSJeremy L Thompson int CeedInit_CudaCollocatedGrad(CeedScalar *d_B, CeedScalar *d_G, CeedInt P_1d, CeedInt Q_1d, CeedScalar **c_B_ptr, CeedScalar **c_G_ptr);
26c532df63SYohann 
27ab213215SJeremy L Thompson //------------------------------------------------------------------------------
28ab213215SJeremy L Thompson // Apply basis
29ab213215SJeremy L Thompson //------------------------------------------------------------------------------
302b730f8bSJeremy L Thompson int CeedBasisApplyTensor_Cuda_shared(CeedBasis basis, const CeedInt num_elem, CeedTransposeMode t_mode, CeedEvalMode eval_mode, CeedVector u,
317f823360Sjeremylt                                      CeedVector v) {
32c532df63SYohann   Ceed                   ceed;
336dbfb411Snbeams   Ceed_Cuda             *ceed_Cuda;
34437930d1SJeremy L Thompson   CeedInt                dim, num_comp;
35*ca735530SJeremy L Thompson   const CeedScalar      *d_u;
36*ca735530SJeremy L Thompson   CeedScalar            *d_v;
37*ca735530SJeremy L Thompson   CeedBasis_Cuda_shared *data;
38*ca735530SJeremy L Thompson 
39*ca735530SJeremy L Thompson   CeedCallBackend(CeedBasisGetCeed(basis, &ceed));
40*ca735530SJeremy L Thompson   CeedCallBackend(CeedGetData(ceed, &ceed_Cuda));
41*ca735530SJeremy L Thompson   CeedCallBackend(CeedBasisGetData(basis, &data));
422b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetDimension(basis, &dim));
432b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetNumComponents(basis, &num_comp));
44c532df63SYohann 
45ab213215SJeremy L Thompson   // Read vectors
466574a04fSJeremy L Thompson   if (u != CEED_VECTOR_NONE) CeedCallBackend(CeedVectorGetArrayRead(u, CEED_MEM_DEVICE, &d_u));
476574a04fSJeremy L Thompson   else CeedCheck(eval_mode == CEED_EVAL_WEIGHT, ceed, CEED_ERROR_BACKEND, "An input vector is required for this CeedEvalMode");
482b730f8bSJeremy L Thompson   CeedCallBackend(CeedVectorGetArrayWrite(v, CEED_MEM_DEVICE, &d_v));
49c532df63SYohann 
50ab213215SJeremy L Thompson   // Apply basis operation
51437930d1SJeremy L Thompson   switch (eval_mode) {
52ab213215SJeremy L Thompson     case CEED_EVAL_INTERP: {
53437930d1SJeremy L Thompson       CeedInt P_1d, Q_1d;
54*ca735530SJeremy L Thompson 
552b730f8bSJeremy L Thompson       CeedCallBackend(CeedBasisGetNumNodes1D(basis, &P_1d));
562b730f8bSJeremy L Thompson       CeedCallBackend(CeedBasisGetNumQuadraturePoints1D(basis, &Q_1d));
57437930d1SJeremy L Thompson       CeedInt thread_1d = CeedIntMax(Q_1d, P_1d);
58*ca735530SJeremy L Thompson 
59eb7e6cafSJeremy L Thompson       CeedCallBackend(CeedInit_CudaInterp(data->d_interp_1d, P_1d, Q_1d, &data->c_B));
602b730f8bSJeremy L Thompson       void *interp_args[] = {(void *)&num_elem, &data->c_B, &d_u, &d_v};
61*ca735530SJeremy L Thompson 
624d537eeaSYohann       if (dim == 1) {
632b730f8bSJeremy L Thompson         CeedInt elems_per_block = CeedIntMin(ceed_Cuda->device_prop.maxThreadsDim[2], CeedIntMax(512 / thread_1d,
64e6f67ff7SJed Brown                                                                                                  1));  // avoid >512 total threads
652b730f8bSJeremy L Thompson         CeedInt grid            = num_elem / elems_per_block + ((num_elem / elems_per_block * elems_per_block < num_elem) ? 1 : 0);
66437930d1SJeremy L Thompson         CeedInt shared_mem      = elems_per_block * thread_1d * sizeof(CeedScalar);
67b2165e7aSSebastian Grimberg 
689e201c85SYohann         if (t_mode == CEED_TRANSPOSE) {
69eb7e6cafSJeremy L Thompson           CeedCallBackend(CeedRunKernelDimShared_Cuda(ceed, data->InterpTranspose, grid, thread_1d, 1, elems_per_block, shared_mem, interp_args));
709e201c85SYohann         } else {
71eb7e6cafSJeremy L Thompson           CeedCallBackend(CeedRunKernelDimShared_Cuda(ceed, data->Interp, grid, thread_1d, 1, elems_per_block, shared_mem, interp_args));
729e201c85SYohann         }
73074be161SYohann Dudouit       } else if (dim == 2) {
74437930d1SJeremy L Thompson         const CeedInt opt_elems[7] = {0, 32, 8, 6, 4, 2, 8};
75437930d1SJeremy L Thompson         // elems_per_block must be at least 1
762b730f8bSJeremy L Thompson         CeedInt elems_per_block = CeedIntMax(thread_1d < 7 ? opt_elems[thread_1d] / num_comp : 1, 1);
772b730f8bSJeremy L Thompson         CeedInt grid            = num_elem / elems_per_block + ((num_elem / elems_per_block * elems_per_block < num_elem) ? 1 : 0);
782b730f8bSJeremy L Thompson         CeedInt shared_mem      = elems_per_block * thread_1d * thread_1d * sizeof(CeedScalar);
79b2165e7aSSebastian Grimberg 
809e201c85SYohann         if (t_mode == CEED_TRANSPOSE) {
812b730f8bSJeremy L Thompson           CeedCallBackend(
82eb7e6cafSJeremy L Thompson               CeedRunKernelDimShared_Cuda(ceed, data->InterpTranspose, grid, thread_1d, thread_1d, elems_per_block, shared_mem, interp_args));
839e201c85SYohann         } else {
84eb7e6cafSJeremy L Thompson           CeedCallBackend(CeedRunKernelDimShared_Cuda(ceed, data->Interp, grid, thread_1d, thread_1d, elems_per_block, shared_mem, interp_args));
859e201c85SYohann         }
86074be161SYohann Dudouit       } else if (dim == 3) {
87437930d1SJeremy L Thompson         CeedInt elems_per_block = 1;
882b730f8bSJeremy L Thompson         CeedInt grid            = num_elem / elems_per_block + ((num_elem / elems_per_block * elems_per_block < num_elem) ? 1 : 0);
892b730f8bSJeremy L Thompson         CeedInt shared_mem      = elems_per_block * thread_1d * thread_1d * sizeof(CeedScalar);
90b2165e7aSSebastian Grimberg 
919e201c85SYohann         if (t_mode == CEED_TRANSPOSE) {
922b730f8bSJeremy L Thompson           CeedCallBackend(
93eb7e6cafSJeremy L Thompson               CeedRunKernelDimShared_Cuda(ceed, data->InterpTranspose, grid, thread_1d, thread_1d, elems_per_block, shared_mem, interp_args));
949e201c85SYohann         } else {
95eb7e6cafSJeremy L Thompson           CeedCallBackend(CeedRunKernelDimShared_Cuda(ceed, data->Interp, grid, thread_1d, thread_1d, elems_per_block, shared_mem, interp_args));
96074be161SYohann Dudouit         }
979e201c85SYohann       }
98ab213215SJeremy L Thompson     } break;
99ab213215SJeremy L Thompson     case CEED_EVAL_GRAD: {
100437930d1SJeremy L Thompson       CeedInt P_1d, Q_1d;
101*ca735530SJeremy L Thompson 
1022b730f8bSJeremy L Thompson       CeedCallBackend(CeedBasisGetNumNodes1D(basis, &P_1d));
1032b730f8bSJeremy L Thompson       CeedCallBackend(CeedBasisGetNumQuadraturePoints1D(basis, &Q_1d));
104437930d1SJeremy L Thompson       CeedInt thread_1d = CeedIntMax(Q_1d, P_1d);
105*ca735530SJeremy L Thompson 
1069e201c85SYohann       if (data->d_collo_grad_1d) {
107eb7e6cafSJeremy L Thompson         CeedCallBackend(CeedInit_CudaCollocatedGrad(data->d_interp_1d, data->d_collo_grad_1d, P_1d, Q_1d, &data->c_B, &data->c_G));
1089e201c85SYohann       } else {
109eb7e6cafSJeremy L Thompson         CeedCallBackend(CeedInit_CudaGrad(data->d_interp_1d, data->d_grad_1d, P_1d, Q_1d, &data->c_B, &data->c_G));
1109e201c85SYohann       }
1112b730f8bSJeremy L Thompson       void *grad_args[] = {(void *)&num_elem, &data->c_B, &data->c_G, &d_u, &d_v};
1124d537eeaSYohann       if (dim == 1) {
1132b730f8bSJeremy L Thompson         CeedInt elems_per_block = CeedIntMin(ceed_Cuda->device_prop.maxThreadsDim[2], CeedIntMax(512 / thread_1d,
114e6f67ff7SJed Brown                                                                                                  1));  // avoid >512 total threads
1152b730f8bSJeremy L Thompson         CeedInt grid            = num_elem / elems_per_block + ((num_elem / elems_per_block * elems_per_block < num_elem) ? 1 : 0);
116437930d1SJeremy L Thompson         CeedInt shared_mem      = elems_per_block * thread_1d * sizeof(CeedScalar);
117b2165e7aSSebastian Grimberg 
1189e201c85SYohann         if (t_mode == CEED_TRANSPOSE) {
119eb7e6cafSJeremy L Thompson           CeedCallBackend(CeedRunKernelDimShared_Cuda(ceed, data->GradTranspose, grid, thread_1d, 1, elems_per_block, shared_mem, grad_args));
1209e201c85SYohann         } else {
121eb7e6cafSJeremy L Thompson           CeedCallBackend(CeedRunKernelDimShared_Cuda(ceed, data->Grad, grid, thread_1d, 1, elems_per_block, shared_mem, grad_args));
1229e201c85SYohann         }
123074be161SYohann Dudouit       } else if (dim == 2) {
124437930d1SJeremy L Thompson         const CeedInt opt_elems[7] = {0, 32, 8, 6, 4, 2, 8};
125437930d1SJeremy L Thompson         // elems_per_block must be at least 1
1262b730f8bSJeremy L Thompson         CeedInt elems_per_block = CeedIntMax(thread_1d < 7 ? opt_elems[thread_1d] / num_comp : 1, 1);
1272b730f8bSJeremy L Thompson         CeedInt grid            = num_elem / elems_per_block + ((num_elem / elems_per_block * elems_per_block < num_elem) ? 1 : 0);
1282b730f8bSJeremy L Thompson         CeedInt shared_mem      = elems_per_block * thread_1d * thread_1d * sizeof(CeedScalar);
129b2165e7aSSebastian Grimberg 
1309e201c85SYohann         if (t_mode == CEED_TRANSPOSE) {
131eb7e6cafSJeremy L Thompson           CeedCallBackend(CeedRunKernelDimShared_Cuda(ceed, data->GradTranspose, grid, thread_1d, thread_1d, elems_per_block, shared_mem, grad_args));
1329e201c85SYohann         } else {
133eb7e6cafSJeremy L Thompson           CeedCallBackend(CeedRunKernelDimShared_Cuda(ceed, data->Grad, grid, thread_1d, thread_1d, elems_per_block, shared_mem, grad_args));
1349e201c85SYohann         }
135074be161SYohann Dudouit       } else if (dim == 3) {
136437930d1SJeremy L Thompson         CeedInt elems_per_block = 1;
1372b730f8bSJeremy L Thompson         CeedInt grid            = num_elem / elems_per_block + ((num_elem / elems_per_block * elems_per_block < num_elem) ? 1 : 0);
1382b730f8bSJeremy L Thompson         CeedInt shared_mem      = elems_per_block * thread_1d * thread_1d * sizeof(CeedScalar);
139b2165e7aSSebastian Grimberg 
1409e201c85SYohann         if (t_mode == CEED_TRANSPOSE) {
141eb7e6cafSJeremy L Thompson           CeedCallBackend(CeedRunKernelDimShared_Cuda(ceed, data->GradTranspose, grid, thread_1d, thread_1d, elems_per_block, shared_mem, grad_args));
1429e201c85SYohann         } else {
143eb7e6cafSJeremy L Thompson           CeedCallBackend(CeedRunKernelDimShared_Cuda(ceed, data->Grad, grid, thread_1d, thread_1d, elems_per_block, shared_mem, grad_args));
1449e201c85SYohann         }
145074be161SYohann Dudouit       }
146ab213215SJeremy L Thompson     } break;
147ab213215SJeremy L Thompson     case CEED_EVAL_WEIGHT: {
148437930d1SJeremy L Thompson       CeedInt Q_1d;
149*ca735530SJeremy L Thompson 
1502b730f8bSJeremy L Thompson       CeedCallBackend(CeedBasisGetNumQuadraturePoints1D(basis, &Q_1d));
151437930d1SJeremy L Thompson       void *weight_args[] = {(void *)&num_elem, (void *)&data->d_q_weight_1d, &d_v};
152074be161SYohann Dudouit       if (dim == 1) {
153437930d1SJeremy L Thompson         const CeedInt elems_per_block = 32 / Q_1d;
154b2165e7aSSebastian Grimberg         const CeedInt grid_size       = num_elem / elems_per_block + ((num_elem / elems_per_block * elems_per_block < num_elem) ? 1 : 0);
155b2165e7aSSebastian Grimberg 
156b2165e7aSSebastian Grimberg         CeedCallBackend(CeedRunKernelDim_Cuda(ceed, data->Weight, grid_size, Q_1d, elems_per_block, 1, weight_args));
157074be161SYohann Dudouit       } else if (dim == 2) {
158437930d1SJeremy L Thompson         const CeedInt opt_elems       = 32 / (Q_1d * Q_1d);
159437930d1SJeremy L Thompson         const CeedInt elems_per_block = opt_elems > 0 ? opt_elems : 1;
160b2165e7aSSebastian Grimberg         const CeedInt grid_size       = num_elem / elems_per_block + ((num_elem / elems_per_block * elems_per_block < num_elem) ? 1 : 0);
161b2165e7aSSebastian Grimberg 
162b2165e7aSSebastian Grimberg         CeedCallBackend(CeedRunKernelDim_Cuda(ceed, data->Weight, grid_size, Q_1d, Q_1d, elems_per_block, weight_args));
163074be161SYohann Dudouit       } else if (dim == 3) {
1649e201c85SYohann         const CeedInt opt_elems       = 32 / (Q_1d * Q_1d);
1659e201c85SYohann         const CeedInt elems_per_block = opt_elems > 0 ? opt_elems : 1;
166b2165e7aSSebastian Grimberg         const CeedInt grid_size       = num_elem / elems_per_block + ((num_elem / elems_per_block * elems_per_block < num_elem) ? 1 : 0);
167b2165e7aSSebastian Grimberg 
168b2165e7aSSebastian Grimberg         CeedCallBackend(CeedRunKernelDim_Cuda(ceed, data->Weight, grid_size, Q_1d, Q_1d, elems_per_block, weight_args));
169074be161SYohann Dudouit       }
170ab213215SJeremy L Thompson     } break;
171ab213215SJeremy L Thompson     // LCOV_EXCL_START
172ab213215SJeremy L Thompson     // Evaluate the divergence to/from the quadrature points
173ab213215SJeremy L Thompson     case CEED_EVAL_DIV:
174e15f9bd0SJeremy L Thompson       return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_DIV not supported");
175ab213215SJeremy L Thompson     // Evaluate the curl to/from the quadrature points
176ab213215SJeremy L Thompson     case CEED_EVAL_CURL:
177e15f9bd0SJeremy L Thompson       return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_CURL not supported");
178ab213215SJeremy L Thompson     // Take no action, BasisApply should not have been called
179ab213215SJeremy L Thompson     case CEED_EVAL_NONE:
1802b730f8bSJeremy L Thompson       return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_NONE does not make sense in this context");
181ab213215SJeremy L Thompson       // LCOV_EXCL_STOP
182c532df63SYohann   }
183c532df63SYohann 
184ab213215SJeremy L Thompson   // Restore vectors
185437930d1SJeremy L Thompson   if (eval_mode != CEED_EVAL_WEIGHT) {
1862b730f8bSJeremy L Thompson     CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u));
187c532df63SYohann   }
1882b730f8bSJeremy L Thompson   CeedCallBackend(CeedVectorRestoreArray(v, &d_v));
189e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
190c532df63SYohann }
191c532df63SYohann 
192ab213215SJeremy L Thompson //------------------------------------------------------------------------------
193ab213215SJeremy L Thompson // Destroy basis
194ab213215SJeremy L Thompson //------------------------------------------------------------------------------
195c532df63SYohann static int CeedBasisDestroy_Cuda_shared(CeedBasis basis) {
196c532df63SYohann   Ceed                   ceed;
197c532df63SYohann   CeedBasis_Cuda_shared *data;
198*ca735530SJeremy L Thompson 
199*ca735530SJeremy L Thompson   CeedCallBackend(CeedBasisGetCeed(basis, &ceed));
2002b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetData(basis, &data));
2012b730f8bSJeremy L Thompson   CeedCallCuda(ceed, cuModuleUnload(data->module));
2022b730f8bSJeremy L Thompson   CeedCallCuda(ceed, cudaFree(data->d_q_weight_1d));
2032b730f8bSJeremy L Thompson   CeedCallCuda(ceed, cudaFree(data->d_interp_1d));
2042b730f8bSJeremy L Thompson   CeedCallCuda(ceed, cudaFree(data->d_grad_1d));
2052b730f8bSJeremy L Thompson   CeedCallCuda(ceed, cudaFree(data->d_collo_grad_1d));
2062b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&data));
207e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
208c532df63SYohann }
209c532df63SYohann 
210ab213215SJeremy L Thompson //------------------------------------------------------------------------------
211ab213215SJeremy L Thompson // Create tensor basis
212ab213215SJeremy L Thompson //------------------------------------------------------------------------------
2132b730f8bSJeremy L Thompson int CeedBasisCreateTensorH1_Cuda_shared(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d,
2142b730f8bSJeremy L Thompson                                         const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis) {
215c532df63SYohann   Ceed                   ceed;
216*ca735530SJeremy L Thompson   char                  *basis_kernel_path, *basis_kernel_source;
217*ca735530SJeremy L Thompson   CeedInt                num_comp;
218*ca735530SJeremy L Thompson   const CeedInt          q_bytes      = Q_1d * sizeof(CeedScalar);
219*ca735530SJeremy L Thompson   const CeedInt          interp_bytes = q_bytes * P_1d;
220c532df63SYohann   CeedBasis_Cuda_shared *data;
221*ca735530SJeremy L Thompson 
222*ca735530SJeremy L Thompson   CeedCallBackend(CeedBasisGetCeed(basis, &ceed));
2232b730f8bSJeremy L Thompson   CeedCallBackend(CeedCalloc(1, &data));
224c532df63SYohann 
225ab213215SJeremy L Thompson   // Copy basis data to GPU
2262b730f8bSJeremy L Thompson   CeedCallCuda(ceed, cudaMalloc((void **)&data->d_q_weight_1d, q_bytes));
2272b730f8bSJeremy L Thompson   CeedCallCuda(ceed, cudaMemcpy(data->d_q_weight_1d, q_weight_1d, q_bytes, cudaMemcpyHostToDevice));
2282b730f8bSJeremy L Thompson   CeedCallCuda(ceed, cudaMalloc((void **)&data->d_interp_1d, interp_bytes));
2292b730f8bSJeremy L Thompson   CeedCallCuda(ceed, cudaMemcpy(data->d_interp_1d, interp_1d, interp_bytes, cudaMemcpyHostToDevice));
2302b730f8bSJeremy L Thompson   CeedCallCuda(ceed, cudaMalloc((void **)&data->d_grad_1d, interp_bytes));
2312b730f8bSJeremy L Thompson   CeedCallCuda(ceed, cudaMemcpy(data->d_grad_1d, grad_1d, interp_bytes, cudaMemcpyHostToDevice));
232c532df63SYohann 
233ab213215SJeremy L Thompson   // Compute collocated gradient and copy to GPU
234437930d1SJeremy L Thompson   data->d_collo_grad_1d    = NULL;
2359e201c85SYohann   bool has_collocated_grad = dim == 3 && Q_1d >= P_1d;
236*ca735530SJeremy L Thompson 
2379e201c85SYohann   if (has_collocated_grad) {
238437930d1SJeremy L Thompson     CeedScalar *collo_grad_1d;
239*ca735530SJeremy L Thompson 
2402b730f8bSJeremy L Thompson     CeedCallBackend(CeedMalloc(Q_1d * Q_1d, &collo_grad_1d));
2412b730f8bSJeremy L Thompson     CeedCallBackend(CeedBasisGetCollocatedGrad(basis, collo_grad_1d));
2422b730f8bSJeremy L Thompson     CeedCallCuda(ceed, cudaMalloc((void **)&data->d_collo_grad_1d, q_bytes * Q_1d));
2432b730f8bSJeremy L Thompson     CeedCallCuda(ceed, cudaMemcpy(data->d_collo_grad_1d, collo_grad_1d, q_bytes * Q_1d, cudaMemcpyHostToDevice));
2442b730f8bSJeremy L Thompson     CeedCallBackend(CeedFree(&collo_grad_1d));
245ac421f39SYohann   }
246ac421f39SYohann 
247ab213215SJeremy L Thompson   // Compile basis kernels
2482b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetNumComponents(basis, &num_comp));
2492b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetJitAbsolutePath(ceed, "ceed/jit-source/cuda/cuda-shared-basis-tensor.h", &basis_kernel_path));
25023d4529eSJeremy L Thompson   CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading Basis Kernel Source -----\n");
2512b730f8bSJeremy L Thompson   CeedCallBackend(CeedLoadSourceToBuffer(ceed, basis_kernel_path, &basis_kernel_source));
25223d4529eSJeremy L Thompson   CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading Basis Kernel Source Complete -----\n");
253eb7e6cafSJeremy L Thompson   CeedCallBackend(CeedCompile_Cuda(ceed, basis_kernel_source, &data->module, 8, "BASIS_Q_1D", Q_1d, "BASIS_P_1D", P_1d, "T_1D",
254eb7e6cafSJeremy L Thompson                                    CeedIntMax(Q_1d, P_1d), "BASIS_DIM", dim, "BASIS_NUM_COMP", num_comp, "BASIS_NUM_NODES", CeedIntPow(P_1d, dim),
255eb7e6cafSJeremy L Thompson                                    "BASIS_NUM_QPTS", CeedIntPow(Q_1d, dim), "BASIS_HAS_COLLOCATED_GRAD", has_collocated_grad));
256eb7e6cafSJeremy L Thompson   CeedCallBackend(CeedGetKernel_Cuda(ceed, data->module, "Interp", &data->Interp));
257eb7e6cafSJeremy L Thompson   CeedCallBackend(CeedGetKernel_Cuda(ceed, data->module, "InterpTranspose", &data->InterpTranspose));
258eb7e6cafSJeremy L Thompson   CeedCallBackend(CeedGetKernel_Cuda(ceed, data->module, "Grad", &data->Grad));
259eb7e6cafSJeremy L Thompson   CeedCallBackend(CeedGetKernel_Cuda(ceed, data->module, "GradTranspose", &data->GradTranspose));
260eb7e6cafSJeremy L Thompson   CeedCallBackend(CeedGetKernel_Cuda(ceed, data->module, "Weight", &data->Weight));
2612b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&basis_kernel_path));
2622b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&basis_kernel_source));
263c532df63SYohann 
2642b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisSetData(basis, data));
265ab213215SJeremy L Thompson 
266ab213215SJeremy L Thompson   // Register backend functions
2672b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApplyTensor_Cuda_shared));
2682b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroy_Cuda_shared));
269e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
270c532df63SYohann }
2712a86cc9dSSebastian Grimberg 
272ab213215SJeremy L Thompson //------------------------------------------------------------------------------
273