xref: /libCEED/backends/hip-ref/ceed-hip-ref-basis.c (revision ecc88aeb6e47c91d01ac230341895a796d10ab95)
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.
30d0321e0SJeremy L Thompson //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
50d0321e0SJeremy L Thompson //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
70d0321e0SJeremy L Thompson 
80d0321e0SJeremy L Thompson #include <ceed/backend.h>
92b730f8bSJeremy L Thompson #include <ceed/ceed.h>
10437930d1SJeremy L Thompson #include <ceed/jit-tools.h>
110d0321e0SJeremy L Thompson #include <hip/hip_runtime.h>
122b730f8bSJeremy L Thompson 
130d0321e0SJeremy L Thompson #include "../hip/ceed-hip-compile.h"
142b730f8bSJeremy L Thompson #include "ceed-hip-ref.h"
150d0321e0SJeremy L Thompson 
160d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
170d0321e0SJeremy L Thompson // Basis apply - tensor
180d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
192b730f8bSJeremy L Thompson int CeedBasisApply_Hip(CeedBasis basis, const CeedInt num_elem, CeedTransposeMode t_mode, CeedEvalMode eval_mode, CeedVector u, CeedVector v) {
200d0321e0SJeremy L Thompson   Ceed ceed;
212b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetCeed(basis, &ceed));
220d0321e0SJeremy L Thompson   Ceed_Hip *ceed_Hip;
232b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetData(ceed, &ceed_Hip));
240d0321e0SJeremy L Thompson   CeedBasis_Hip *data;
252b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetData(basis, &data));
26437930d1SJeremy L Thompson   const CeedInt transpose      = t_mode == CEED_TRANSPOSE;
27437930d1SJeremy L Thompson   const int     max_block_size = 64;
280d0321e0SJeremy L Thompson 
290d0321e0SJeremy L Thompson   // Read vectors
300d0321e0SJeremy L Thompson   const CeedScalar *d_u;
310d0321e0SJeremy L Thompson   CeedScalar       *d_v;
32437930d1SJeremy L Thompson   if (eval_mode != CEED_EVAL_WEIGHT) {
332b730f8bSJeremy L Thompson     CeedCallBackend(CeedVectorGetArrayRead(u, CEED_MEM_DEVICE, &d_u));
340d0321e0SJeremy L Thompson   }
352b730f8bSJeremy L Thompson   CeedCallBackend(CeedVectorGetArrayWrite(v, CEED_MEM_DEVICE, &d_v));
360d0321e0SJeremy L Thompson 
370d0321e0SJeremy L Thompson   // Clear v for transpose operation
38437930d1SJeremy L Thompson   if (t_mode == CEED_TRANSPOSE) {
391f9221feSJeremy L Thompson     CeedSize length;
402b730f8bSJeremy L Thompson     CeedCallBackend(CeedVectorGetLength(v, &length));
412b730f8bSJeremy L Thompson     CeedCallHip(ceed, hipMemset(d_v, 0, length * sizeof(CeedScalar)));
420d0321e0SJeremy L Thompson   }
430d0321e0SJeremy L Thompson 
440d0321e0SJeremy L Thompson   // Basis action
45437930d1SJeremy L Thompson   switch (eval_mode) {
460d0321e0SJeremy L Thompson     case CEED_EVAL_INTERP: {
472b730f8bSJeremy L Thompson       void   *interp_args[] = {(void *)&num_elem, (void *)&transpose, &data->d_interp_1d, &d_u, &d_v};
48437930d1SJeremy L Thompson       CeedInt Q_1d, dim;
492b730f8bSJeremy L Thompson       CeedCallBackend(CeedBasisGetNumQuadraturePoints1D(basis, &Q_1d));
502b730f8bSJeremy L Thompson       CeedCallBackend(CeedBasisGetDimension(basis, &dim));
51437930d1SJeremy L Thompson       CeedInt block_size = CeedIntMin(CeedIntPow(Q_1d, dim), max_block_size);
520d0321e0SJeremy L Thompson 
532b730f8bSJeremy L Thompson       CeedCallBackend(CeedRunKernelHip(ceed, data->Interp, num_elem, block_size, interp_args));
540d0321e0SJeremy L Thompson     } break;
550d0321e0SJeremy L Thompson     case CEED_EVAL_GRAD: {
562b730f8bSJeremy L Thompson       void   *grad_args[] = {(void *)&num_elem, (void *)&transpose, &data->d_interp_1d, &data->d_grad_1d, &d_u, &d_v};
57437930d1SJeremy L Thompson       CeedInt block_size  = max_block_size;
580d0321e0SJeremy L Thompson 
592b730f8bSJeremy L Thompson       CeedCallBackend(CeedRunKernelHip(ceed, data->Grad, num_elem, block_size, grad_args));
600d0321e0SJeremy L Thompson     } break;
610d0321e0SJeremy L Thompson     case CEED_EVAL_WEIGHT: {
62437930d1SJeremy L Thompson       void     *weight_args[] = {(void *)&num_elem, (void *)&data->d_q_weight_1d, &d_v};
63437930d1SJeremy L Thompson       const int block_size    = 64;
64437930d1SJeremy L Thompson       int       grid_size     = num_elem / block_size;
652b730f8bSJeremy L Thompson       if (block_size * grid_size < num_elem) grid_size += 1;
660d0321e0SJeremy L Thompson 
672b730f8bSJeremy L Thompson       CeedCallBackend(CeedRunKernelHip(ceed, data->Weight, grid_size, block_size, weight_args));
680d0321e0SJeremy L Thompson     } break;
690d0321e0SJeremy L Thompson     // LCOV_EXCL_START
700d0321e0SJeremy L Thompson     // Evaluate the divergence to/from the quadrature points
710d0321e0SJeremy L Thompson     case CEED_EVAL_DIV:
720d0321e0SJeremy L Thompson       return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_DIV not supported");
730d0321e0SJeremy L Thompson     // Evaluate the curl to/from the quadrature points
740d0321e0SJeremy L Thompson     case CEED_EVAL_CURL:
750d0321e0SJeremy L Thompson       return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_CURL not supported");
760d0321e0SJeremy L Thompson     // Take no action, BasisApply should not have been called
770d0321e0SJeremy L Thompson     case CEED_EVAL_NONE:
782b730f8bSJeremy L Thompson       return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_NONE does not make sense in this context");
790d0321e0SJeremy L Thompson       // LCOV_EXCL_STOP
800d0321e0SJeremy L Thompson   }
810d0321e0SJeremy L Thompson 
820d0321e0SJeremy L Thompson   // Restore vectors
83437930d1SJeremy L Thompson   if (eval_mode != CEED_EVAL_WEIGHT) {
842b730f8bSJeremy L Thompson     CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u));
850d0321e0SJeremy L Thompson   }
862b730f8bSJeremy L Thompson   CeedCallBackend(CeedVectorRestoreArray(v, &d_v));
870d0321e0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
880d0321e0SJeremy L Thompson }
890d0321e0SJeremy L Thompson 
900d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
910d0321e0SJeremy L Thompson // Basis apply - non-tensor
920d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
932b730f8bSJeremy L Thompson int CeedBasisApplyNonTensor_Hip(CeedBasis basis, const CeedInt num_elem, CeedTransposeMode t_mode, CeedEvalMode eval_mode, CeedVector u,
942b730f8bSJeremy L Thompson                                 CeedVector v) {
950d0321e0SJeremy L Thompson   Ceed ceed;
962b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetCeed(basis, &ceed));
970d0321e0SJeremy L Thompson   Ceed_Hip *ceed_Hip;
982b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetData(ceed, &ceed_Hip));
990d0321e0SJeremy L Thompson   CeedBasisNonTensor_Hip *data;
1002b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetData(basis, &data));
101437930d1SJeremy L Thompson   CeedInt num_nodes, num_qpts;
1022b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetNumQuadraturePoints(basis, &num_qpts));
1032b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetNumNodes(basis, &num_nodes));
104437930d1SJeremy L Thompson   const CeedInt transpose     = t_mode == CEED_TRANSPOSE;
1050d0321e0SJeremy L Thompson   int           elemsPerBlock = 1;
1062b730f8bSJeremy L Thompson   int           grid          = num_elem / elemsPerBlock + ((num_elem / elemsPerBlock * elemsPerBlock < num_elem) ? 1 : 0);
1070d0321e0SJeremy L Thompson 
1080d0321e0SJeremy L Thompson   // Read vectors
1090d0321e0SJeremy L Thompson   const CeedScalar *d_u;
1100d0321e0SJeremy L Thompson   CeedScalar       *d_v;
111437930d1SJeremy L Thompson   if (eval_mode != CEED_EVAL_WEIGHT) {
1122b730f8bSJeremy L Thompson     CeedCallBackend(CeedVectorGetArrayRead(u, CEED_MEM_DEVICE, &d_u));
1130d0321e0SJeremy L Thompson   }
1142b730f8bSJeremy L Thompson   CeedCallBackend(CeedVectorGetArrayWrite(v, CEED_MEM_DEVICE, &d_v));
1150d0321e0SJeremy L Thompson 
1160d0321e0SJeremy L Thompson   // Clear v for transpose operation
117437930d1SJeremy L Thompson   if (t_mode == CEED_TRANSPOSE) {
1181f9221feSJeremy L Thompson     CeedSize length;
1192b730f8bSJeremy L Thompson     CeedCallBackend(CeedVectorGetLength(v, &length));
1202b730f8bSJeremy L Thompson     CeedCallHip(ceed, hipMemset(d_v, 0, length * sizeof(CeedScalar)));
1210d0321e0SJeremy L Thompson   }
1220d0321e0SJeremy L Thompson 
1230d0321e0SJeremy L Thompson   // Apply basis operation
124437930d1SJeremy L Thompson   switch (eval_mode) {
1250d0321e0SJeremy L Thompson     case CEED_EVAL_INTERP: {
1262b730f8bSJeremy L Thompson       void     *interp_args[] = {(void *)&num_elem, (void *)&transpose, &data->d_interp, &d_u, &d_v};
1272b730f8bSJeremy L Thompson       const int block_size_x  = transpose ? num_nodes : num_qpts;
1282b730f8bSJeremy L Thompson       CeedCallBackend(CeedRunKernelDimHip(ceed, data->Interp, grid, block_size_x, 1, elemsPerBlock, interp_args));
1290d0321e0SJeremy L Thompson     } break;
1300d0321e0SJeremy L Thompson     case CEED_EVAL_GRAD: {
1312b730f8bSJeremy L Thompson       void     *grad_args[]  = {(void *)&num_elem, (void *)&transpose, &data->d_grad, &d_u, &d_v};
1322b730f8bSJeremy L Thompson       const int block_size_x = transpose ? num_nodes : num_qpts;
1332b730f8bSJeremy L Thompson       CeedCallBackend(CeedRunKernelDimHip(ceed, data->Grad, grid, block_size_x, 1, elemsPerBlock, grad_args));
1340d0321e0SJeremy L Thompson     } break;
1350d0321e0SJeremy L Thompson     case CEED_EVAL_WEIGHT: {
136437930d1SJeremy L Thompson       void *weight_args[] = {(void *)&num_elem, (void *)&data->d_q_weight, &d_v};
1372b730f8bSJeremy L Thompson       CeedCallBackend(CeedRunKernelDimHip(ceed, data->Weight, grid, num_qpts, 1, elemsPerBlock, weight_args));
1380d0321e0SJeremy L Thompson     } break;
1390d0321e0SJeremy L Thompson     // LCOV_EXCL_START
1400d0321e0SJeremy L Thompson     // Evaluate the divergence to/from the quadrature points
1410d0321e0SJeremy L Thompson     case CEED_EVAL_DIV:
1420d0321e0SJeremy L Thompson       return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_DIV not supported");
1430d0321e0SJeremy L Thompson     // Evaluate the curl to/from the quadrature points
1440d0321e0SJeremy L Thompson     case CEED_EVAL_CURL:
1450d0321e0SJeremy L Thompson       return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_CURL not supported");
1460d0321e0SJeremy L Thompson     // Take no action, BasisApply should not have been called
1470d0321e0SJeremy L Thompson     case CEED_EVAL_NONE:
1482b730f8bSJeremy L Thompson       return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_NONE does not make sense in this context");
1490d0321e0SJeremy L Thompson       // LCOV_EXCL_STOP
1500d0321e0SJeremy L Thompson   }
1510d0321e0SJeremy L Thompson 
1520d0321e0SJeremy L Thompson   // Restore vectors
153437930d1SJeremy L Thompson   if (eval_mode != CEED_EVAL_WEIGHT) {
1542b730f8bSJeremy L Thompson     CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u));
1550d0321e0SJeremy L Thompson   }
1562b730f8bSJeremy L Thompson   CeedCallBackend(CeedVectorRestoreArray(v, &d_v));
1570d0321e0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1580d0321e0SJeremy L Thompson }
1590d0321e0SJeremy L Thompson 
1600d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
1610d0321e0SJeremy L Thompson // Destroy tensor basis
1620d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
1630d0321e0SJeremy L Thompson static int CeedBasisDestroy_Hip(CeedBasis basis) {
1640d0321e0SJeremy L Thompson   Ceed ceed;
1652b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetCeed(basis, &ceed));
1660d0321e0SJeremy L Thompson 
1670d0321e0SJeremy L Thompson   CeedBasis_Hip *data;
1682b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetData(basis, &data));
1690d0321e0SJeremy L Thompson 
1702b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipModuleUnload(data->module));
1710d0321e0SJeremy L Thompson 
1722b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipFree(data->d_q_weight_1d));
1732b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipFree(data->d_interp_1d));
1742b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipFree(data->d_grad_1d));
1752b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&data));
176437930d1SJeremy L Thompson 
1770d0321e0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1780d0321e0SJeremy L Thompson }
1790d0321e0SJeremy L Thompson 
1800d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
1810d0321e0SJeremy L Thompson // Destroy non-tensor basis
1820d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
1830d0321e0SJeremy L Thompson static int CeedBasisDestroyNonTensor_Hip(CeedBasis basis) {
1840d0321e0SJeremy L Thompson   Ceed ceed;
1852b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetCeed(basis, &ceed));
1860d0321e0SJeremy L Thompson 
1870d0321e0SJeremy L Thompson   CeedBasisNonTensor_Hip *data;
1882b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetData(basis, &data));
1890d0321e0SJeremy L Thompson 
1902b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipModuleUnload(data->module));
1910d0321e0SJeremy L Thompson 
1922b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipFree(data->d_q_weight));
1932b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipFree(data->d_interp));
1942b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipFree(data->d_grad));
1952b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&data));
196437930d1SJeremy L Thompson 
1970d0321e0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1980d0321e0SJeremy L Thompson }
1990d0321e0SJeremy L Thompson 
2000d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
2010d0321e0SJeremy L Thompson // Create tensor
2020d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
2032b730f8bSJeremy L Thompson int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d,
2042b730f8bSJeremy L Thompson                                 const CeedScalar *qref1d, const CeedScalar *q_weight_1d, CeedBasis basis) {
2050d0321e0SJeremy L Thompson   Ceed ceed;
2062b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetCeed(basis, &ceed));
2070d0321e0SJeremy L Thompson   CeedBasis_Hip *data;
2082b730f8bSJeremy L Thompson   CeedCallBackend(CeedCalloc(1, &data));
2090d0321e0SJeremy L Thompson 
2100d0321e0SJeremy L Thompson   // Copy data to GPU
211437930d1SJeremy L Thompson   const CeedInt q_bytes = Q_1d * sizeof(CeedScalar);
2122b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMalloc((void **)&data->d_q_weight_1d, q_bytes));
2132b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMemcpy(data->d_q_weight_1d, q_weight_1d, q_bytes, hipMemcpyHostToDevice));
2140d0321e0SJeremy L Thompson 
215437930d1SJeremy L Thompson   const CeedInt interp_bytes = q_bytes * P_1d;
2162b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMalloc((void **)&data->d_interp_1d, interp_bytes));
2172b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMemcpy(data->d_interp_1d, interp_1d, interp_bytes, hipMemcpyHostToDevice));
2180d0321e0SJeremy L Thompson 
2192b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMalloc((void **)&data->d_grad_1d, interp_bytes));
2202b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMemcpy(data->d_grad_1d, grad_1d, interp_bytes, hipMemcpyHostToDevice));
2210d0321e0SJeremy L Thompson 
222*ecc88aebSJeremy L Thompson   // Compile basis kernels
2230d0321e0SJeremy L Thompson   CeedInt ncomp;
2242b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetNumComponents(basis, &ncomp));
225437930d1SJeremy L Thompson   char *basis_kernel_path, *basis_kernel_source;
2262b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetJitAbsolutePath(ceed, "ceed/jit-source/hip/hip-ref-basis-tensor.h", &basis_kernel_path));
22746dc0734SJeremy L Thompson   CeedDebug256(ceed, 2, "----- Loading Basis Kernel Source -----\n");
2282b730f8bSJeremy L Thompson   CeedCallBackend(CeedLoadSourceToBuffer(ceed, basis_kernel_path, &basis_kernel_source));
22946dc0734SJeremy L Thompson   CeedDebug256(ceed, 2, "----- Loading Basis Kernel Source Complete! -----\n");
2302b730f8bSJeremy L Thompson   CeedCallBackend(CeedCompileHip(ceed, basis_kernel_source, &data->module, 7, "BASIS_Q_1D", Q_1d, "BASIS_P_1D", P_1d, "BASIS_BUF_LEN",
2312b730f8bSJeremy L Thompson                                  ncomp * CeedIntPow(Q_1d > P_1d ? Q_1d : P_1d, dim), "BASIS_DIM", dim, "BASIS_NUM_COMP", ncomp, "BASIS_NUM_NODES",
2322b730f8bSJeremy L Thompson                                  CeedIntPow(P_1d, dim), "BASIS_NUM_QPTS", CeedIntPow(Q_1d, dim)));
2332b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetKernelHip(ceed, data->module, "Interp", &data->Interp));
2342b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetKernelHip(ceed, data->module, "Grad", &data->Grad));
2352b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetKernelHip(ceed, data->module, "Weight", &data->Weight));
2362b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&basis_kernel_path));
2372b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&basis_kernel_source));
238437930d1SJeremy L Thompson 
2392b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisSetData(basis, data));
2400d0321e0SJeremy L Thompson 
2412b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApply_Hip));
2422b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroy_Hip));
2430d0321e0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
2440d0321e0SJeremy L Thompson }
2450d0321e0SJeremy L Thompson 
2460d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
2470d0321e0SJeremy L Thompson // Create non-tensor
2480d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
2492b730f8bSJeremy L Thompson int CeedBasisCreateH1_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, const CeedScalar *grad,
2502b730f8bSJeremy L Thompson                           const CeedScalar *qref, const CeedScalar *q_weight, CeedBasis basis) {
2510d0321e0SJeremy L Thompson   Ceed ceed;
2522b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetCeed(basis, &ceed));
2530d0321e0SJeremy L Thompson   CeedBasisNonTensor_Hip *data;
2542b730f8bSJeremy L Thompson   CeedCallBackend(CeedCalloc(1, &data));
2550d0321e0SJeremy L Thompson 
2560d0321e0SJeremy L Thompson   // Copy basis data to GPU
257437930d1SJeremy L Thompson   const CeedInt q_bytes = num_qpts * sizeof(CeedScalar);
2582b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMalloc((void **)&data->d_q_weight, q_bytes));
2592b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMemcpy(data->d_q_weight, q_weight, q_bytes, hipMemcpyHostToDevice));
2600d0321e0SJeremy L Thompson 
261437930d1SJeremy L Thompson   const CeedInt interp_bytes = q_bytes * num_nodes;
2622b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMalloc((void **)&data->d_interp, interp_bytes));
2632b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMemcpy(data->d_interp, interp, interp_bytes, hipMemcpyHostToDevice));
2640d0321e0SJeremy L Thompson 
265437930d1SJeremy L Thompson   const CeedInt grad_bytes = q_bytes * num_nodes * dim;
2662b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMalloc((void **)&data->d_grad, grad_bytes));
2672b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMemcpy(data->d_grad, grad, grad_bytes, hipMemcpyHostToDevice));
2680d0321e0SJeremy L Thompson 
2690d0321e0SJeremy L Thompson   // Compile basis kernels
2700d0321e0SJeremy L Thompson   CeedInt ncomp;
2712b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetNumComponents(basis, &ncomp));
272437930d1SJeremy L Thompson   char *basis_kernel_path, *basis_kernel_source;
2732b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetJitAbsolutePath(ceed, "ceed/jit-source/hip/hip-ref-basis-nontensor.h", &basis_kernel_path));
27446dc0734SJeremy L Thompson   CeedDebug256(ceed, 2, "----- Loading Basis Kernel Source -----\n");
2752b730f8bSJeremy L Thompson   CeedCallBackend(CeedLoadSourceToBuffer(ceed, basis_kernel_path, &basis_kernel_source));
27646dc0734SJeremy L Thompson   CeedDebug256(ceed, 2, "----- Loading Basis Kernel Source Complete! -----\n");
2772b730f8bSJeremy L Thompson   CeedCallBackend(CeedCompileHip(ceed, basis_kernel_source, &data->module, 4, "BASIS_Q", num_qpts, "BASIS_P", num_nodes, "BASIS_DIM", dim,
2782b730f8bSJeremy L Thompson                                  "BASIS_NUM_COMP", ncomp));
2792b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetKernelHip(ceed, data->module, "Interp", &data->Interp));
2802b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetKernelHip(ceed, data->module, "Grad", &data->Grad));
2812b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetKernelHip(ceed, data->module, "Weight", &data->Weight));
2822b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&basis_kernel_path));
2832b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&basis_kernel_source));
2842b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisSetData(basis, data));
2850d0321e0SJeremy L Thompson 
2860d0321e0SJeremy L Thompson   // Register backend functions
2872b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApplyNonTensor_Hip));
2882b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroyNonTensor_Hip));
2890d0321e0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
2900d0321e0SJeremy L Thompson }
2910d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
292