xref: /libCEED/backends/hip-ref/ceed-hip-ref-basis.c (revision 2a86cc9d4dbfce2964c7e8927a1e6db8d19a41fc)
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 
849aac155SJeremy L Thompson #include <ceed.h>
90d0321e0SJeremy L Thompson #include <ceed/backend.h>
10437930d1SJeremy L Thompson #include <ceed/jit-tools.h>
110d0321e0SJeremy L Thompson #include <hip/hip_runtime.h>
122b730f8bSJeremy L Thompson 
1349aac155SJeremy L Thompson #include "../hip/ceed-hip-common.h"
140d0321e0SJeremy L Thompson #include "../hip/ceed-hip-compile.h"
152b730f8bSJeremy L Thompson #include "ceed-hip-ref.h"
160d0321e0SJeremy L Thompson 
170d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
180d0321e0SJeremy L Thompson // Basis apply - tensor
190d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
202b730f8bSJeremy L Thompson int CeedBasisApply_Hip(CeedBasis basis, const CeedInt num_elem, CeedTransposeMode t_mode, CeedEvalMode eval_mode, CeedVector u, CeedVector v) {
210d0321e0SJeremy L Thompson   Ceed ceed;
222b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetCeed(basis, &ceed));
230d0321e0SJeremy L Thompson   Ceed_Hip *ceed_Hip;
242b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetData(ceed, &ceed_Hip));
250d0321e0SJeremy L Thompson   CeedBasis_Hip *data;
262b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetData(basis, &data));
27437930d1SJeremy L Thompson   const CeedInt transpose      = t_mode == CEED_TRANSPOSE;
28437930d1SJeremy L Thompson   const int     max_block_size = 64;
290d0321e0SJeremy L Thompson 
300d0321e0SJeremy L Thompson   // Read vectors
310d0321e0SJeremy L Thompson   const CeedScalar *d_u;
320d0321e0SJeremy L Thompson   CeedScalar       *d_v;
33437930d1SJeremy L Thompson   if (eval_mode != CEED_EVAL_WEIGHT) {
342b730f8bSJeremy L Thompson     CeedCallBackend(CeedVectorGetArrayRead(u, CEED_MEM_DEVICE, &d_u));
350d0321e0SJeremy L Thompson   }
362b730f8bSJeremy L Thompson   CeedCallBackend(CeedVectorGetArrayWrite(v, CEED_MEM_DEVICE, &d_v));
370d0321e0SJeremy L Thompson 
380d0321e0SJeremy L Thompson   // Clear v for transpose operation
39437930d1SJeremy L Thompson   if (t_mode == CEED_TRANSPOSE) {
401f9221feSJeremy L Thompson     CeedSize length;
412b730f8bSJeremy L Thompson     CeedCallBackend(CeedVectorGetLength(v, &length));
422b730f8bSJeremy L Thompson     CeedCallHip(ceed, hipMemset(d_v, 0, length * sizeof(CeedScalar)));
430d0321e0SJeremy L Thompson   }
440d0321e0SJeremy L Thompson 
450d0321e0SJeremy L Thompson   // Basis action
46437930d1SJeremy L Thompson   switch (eval_mode) {
470d0321e0SJeremy L Thompson     case CEED_EVAL_INTERP: {
482b730f8bSJeremy L Thompson       void   *interp_args[] = {(void *)&num_elem, (void *)&transpose, &data->d_interp_1d, &d_u, &d_v};
49437930d1SJeremy L Thompson       CeedInt Q_1d, dim;
502b730f8bSJeremy L Thompson       CeedCallBackend(CeedBasisGetNumQuadraturePoints1D(basis, &Q_1d));
512b730f8bSJeremy L Thompson       CeedCallBackend(CeedBasisGetDimension(basis, &dim));
52437930d1SJeremy L Thompson       CeedInt block_size = CeedIntMin(CeedIntPow(Q_1d, dim), max_block_size);
530d0321e0SJeremy L Thompson 
542b730f8bSJeremy L Thompson       CeedCallBackend(CeedRunKernelHip(ceed, data->Interp, num_elem, block_size, interp_args));
550d0321e0SJeremy L Thompson     } break;
560d0321e0SJeremy L Thompson     case CEED_EVAL_GRAD: {
572b730f8bSJeremy L Thompson       void   *grad_args[] = {(void *)&num_elem, (void *)&transpose, &data->d_interp_1d, &data->d_grad_1d, &d_u, &d_v};
58437930d1SJeremy L Thompson       CeedInt block_size  = max_block_size;
590d0321e0SJeremy L Thompson 
602b730f8bSJeremy L Thompson       CeedCallBackend(CeedRunKernelHip(ceed, data->Grad, num_elem, block_size, grad_args));
610d0321e0SJeremy L Thompson     } break;
620d0321e0SJeremy L Thompson     case CEED_EVAL_WEIGHT: {
63437930d1SJeremy L Thompson       void     *weight_args[] = {(void *)&num_elem, (void *)&data->d_q_weight_1d, &d_v};
64437930d1SJeremy L Thompson       const int block_size    = 64;
65437930d1SJeremy L Thompson       int       grid_size     = num_elem / block_size;
662b730f8bSJeremy L Thompson       if (block_size * grid_size < num_elem) grid_size += 1;
670d0321e0SJeremy L Thompson 
682b730f8bSJeremy L Thompson       CeedCallBackend(CeedRunKernelHip(ceed, data->Weight, grid_size, block_size, weight_args));
690d0321e0SJeremy L Thompson     } break;
700d0321e0SJeremy L Thompson     // LCOV_EXCL_START
710d0321e0SJeremy L Thompson     // Evaluate the divergence to/from the quadrature points
720d0321e0SJeremy L Thompson     case CEED_EVAL_DIV:
730d0321e0SJeremy L Thompson       return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_DIV not supported");
740d0321e0SJeremy L Thompson     // Evaluate the curl to/from the quadrature points
750d0321e0SJeremy L Thompson     case CEED_EVAL_CURL:
760d0321e0SJeremy L Thompson       return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_CURL not supported");
770d0321e0SJeremy L Thompson     // Take no action, BasisApply should not have been called
780d0321e0SJeremy L Thompson     case CEED_EVAL_NONE:
792b730f8bSJeremy L Thompson       return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_NONE does not make sense in this context");
800d0321e0SJeremy L Thompson       // LCOV_EXCL_STOP
810d0321e0SJeremy L Thompson   }
820d0321e0SJeremy L Thompson 
830d0321e0SJeremy L Thompson   // Restore vectors
84437930d1SJeremy L Thompson   if (eval_mode != CEED_EVAL_WEIGHT) {
852b730f8bSJeremy L Thompson     CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u));
860d0321e0SJeremy L Thompson   }
872b730f8bSJeremy L Thompson   CeedCallBackend(CeedVectorRestoreArray(v, &d_v));
880d0321e0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
890d0321e0SJeremy L Thompson }
900d0321e0SJeremy L Thompson 
910d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
920d0321e0SJeremy L Thompson // Basis apply - non-tensor
930d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
942b730f8bSJeremy L Thompson int CeedBasisApplyNonTensor_Hip(CeedBasis basis, const CeedInt num_elem, CeedTransposeMode t_mode, CeedEvalMode eval_mode, CeedVector u,
952b730f8bSJeremy L Thompson                                 CeedVector v) {
960d0321e0SJeremy L Thompson   Ceed ceed;
972b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetCeed(basis, &ceed));
980d0321e0SJeremy L Thompson   Ceed_Hip *ceed_Hip;
992b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetData(ceed, &ceed_Hip));
1000d0321e0SJeremy L Thompson   CeedBasisNonTensor_Hip *data;
1012b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetData(basis, &data));
102437930d1SJeremy L Thompson   CeedInt num_nodes, num_qpts;
1032b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetNumQuadraturePoints(basis, &num_qpts));
1042b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetNumNodes(basis, &num_nodes));
105437930d1SJeremy L Thompson   const CeedInt transpose     = t_mode == CEED_TRANSPOSE;
1060d0321e0SJeremy L Thompson   int           elemsPerBlock = 1;
1072b730f8bSJeremy L Thompson   int           grid          = num_elem / elemsPerBlock + ((num_elem / elemsPerBlock * elemsPerBlock < num_elem) ? 1 : 0);
1080d0321e0SJeremy L Thompson 
1090d0321e0SJeremy L Thompson   // Read vectors
1100d0321e0SJeremy L Thompson   const CeedScalar *d_u;
1110d0321e0SJeremy L Thompson   CeedScalar       *d_v;
112437930d1SJeremy L Thompson   if (eval_mode != CEED_EVAL_WEIGHT) {
1132b730f8bSJeremy L Thompson     CeedCallBackend(CeedVectorGetArrayRead(u, CEED_MEM_DEVICE, &d_u));
1140d0321e0SJeremy L Thompson   }
1152b730f8bSJeremy L Thompson   CeedCallBackend(CeedVectorGetArrayWrite(v, CEED_MEM_DEVICE, &d_v));
1160d0321e0SJeremy L Thompson 
1170d0321e0SJeremy L Thompson   // Clear v for transpose operation
118437930d1SJeremy L Thompson   if (t_mode == CEED_TRANSPOSE) {
1191f9221feSJeremy L Thompson     CeedSize length;
1202b730f8bSJeremy L Thompson     CeedCallBackend(CeedVectorGetLength(v, &length));
1212b730f8bSJeremy L Thompson     CeedCallHip(ceed, hipMemset(d_v, 0, length * sizeof(CeedScalar)));
1220d0321e0SJeremy L Thompson   }
1230d0321e0SJeremy L Thompson 
1240d0321e0SJeremy L Thompson   // Apply basis operation
125437930d1SJeremy L Thompson   switch (eval_mode) {
1260d0321e0SJeremy L Thompson     case CEED_EVAL_INTERP: {
1272b730f8bSJeremy L Thompson       void     *interp_args[] = {(void *)&num_elem, (void *)&transpose, &data->d_interp, &d_u, &d_v};
1282b730f8bSJeremy L Thompson       const int block_size_x  = transpose ? num_nodes : num_qpts;
1292b730f8bSJeremy L Thompson       CeedCallBackend(CeedRunKernelDimHip(ceed, data->Interp, grid, block_size_x, 1, elemsPerBlock, interp_args));
1300d0321e0SJeremy L Thompson     } break;
1310d0321e0SJeremy L Thompson     case CEED_EVAL_GRAD: {
1322b730f8bSJeremy L Thompson       void     *grad_args[]  = {(void *)&num_elem, (void *)&transpose, &data->d_grad, &d_u, &d_v};
1332b730f8bSJeremy L Thompson       const int block_size_x = transpose ? num_nodes : num_qpts;
1342b730f8bSJeremy L Thompson       CeedCallBackend(CeedRunKernelDimHip(ceed, data->Grad, grid, block_size_x, 1, elemsPerBlock, grad_args));
1350d0321e0SJeremy L Thompson     } break;
1360d0321e0SJeremy L Thompson     case CEED_EVAL_WEIGHT: {
137437930d1SJeremy L Thompson       void *weight_args[] = {(void *)&num_elem, (void *)&data->d_q_weight, &d_v};
1382b730f8bSJeremy L Thompson       CeedCallBackend(CeedRunKernelDimHip(ceed, data->Weight, grid, num_qpts, 1, elemsPerBlock, weight_args));
1390d0321e0SJeremy L Thompson     } break;
1400d0321e0SJeremy L Thompson     // LCOV_EXCL_START
1410d0321e0SJeremy L Thompson     // Evaluate the divergence to/from the quadrature points
1420d0321e0SJeremy L Thompson     case CEED_EVAL_DIV:
1430d0321e0SJeremy L Thompson       return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_DIV not supported");
1440d0321e0SJeremy L Thompson     // Evaluate the curl to/from the quadrature points
1450d0321e0SJeremy L Thompson     case CEED_EVAL_CURL:
1460d0321e0SJeremy L Thompson       return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_CURL not supported");
1470d0321e0SJeremy L Thompson     // Take no action, BasisApply should not have been called
1480d0321e0SJeremy L Thompson     case CEED_EVAL_NONE:
1492b730f8bSJeremy L Thompson       return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_NONE does not make sense in this context");
1500d0321e0SJeremy L Thompson       // LCOV_EXCL_STOP
1510d0321e0SJeremy L Thompson   }
1520d0321e0SJeremy L Thompson 
1530d0321e0SJeremy L Thompson   // Restore vectors
154437930d1SJeremy L Thompson   if (eval_mode != CEED_EVAL_WEIGHT) {
1552b730f8bSJeremy L Thompson     CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u));
1560d0321e0SJeremy L Thompson   }
1572b730f8bSJeremy L Thompson   CeedCallBackend(CeedVectorRestoreArray(v, &d_v));
1580d0321e0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1590d0321e0SJeremy L Thompson }
1600d0321e0SJeremy L Thompson 
1610d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
1620d0321e0SJeremy L Thompson // Destroy tensor basis
1630d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
1640d0321e0SJeremy L Thompson static int CeedBasisDestroy_Hip(CeedBasis basis) {
1650d0321e0SJeremy L Thompson   Ceed ceed;
1662b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetCeed(basis, &ceed));
1670d0321e0SJeremy L Thompson 
1680d0321e0SJeremy L Thompson   CeedBasis_Hip *data;
1692b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetData(basis, &data));
1700d0321e0SJeremy L Thompson 
1712b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipModuleUnload(data->module));
1720d0321e0SJeremy L Thompson 
1732b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipFree(data->d_q_weight_1d));
1742b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipFree(data->d_interp_1d));
1752b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipFree(data->d_grad_1d));
1762b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&data));
177437930d1SJeremy L Thompson 
1780d0321e0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1790d0321e0SJeremy L Thompson }
1800d0321e0SJeremy L Thompson 
1810d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
1820d0321e0SJeremy L Thompson // Destroy non-tensor basis
1830d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
1840d0321e0SJeremy L Thompson static int CeedBasisDestroyNonTensor_Hip(CeedBasis basis) {
1850d0321e0SJeremy L Thompson   Ceed ceed;
1862b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetCeed(basis, &ceed));
1870d0321e0SJeremy L Thompson 
1880d0321e0SJeremy L Thompson   CeedBasisNonTensor_Hip *data;
1892b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetData(basis, &data));
1900d0321e0SJeremy L Thompson 
1912b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipModuleUnload(data->module));
1920d0321e0SJeremy L Thompson 
1932b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipFree(data->d_q_weight));
1942b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipFree(data->d_interp));
1952b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipFree(data->d_grad));
1962b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&data));
197437930d1SJeremy L Thompson 
1980d0321e0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1990d0321e0SJeremy L Thompson }
2000d0321e0SJeremy L Thompson 
2010d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
2020d0321e0SJeremy L Thompson // Create tensor
2030d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
2042b730f8bSJeremy L Thompson int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d,
2052b730f8bSJeremy L Thompson                                 const CeedScalar *qref1d, const CeedScalar *q_weight_1d, CeedBasis basis) {
2060d0321e0SJeremy L Thompson   Ceed ceed;
2072b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetCeed(basis, &ceed));
2080d0321e0SJeremy L Thompson   CeedBasis_Hip *data;
2092b730f8bSJeremy L Thompson   CeedCallBackend(CeedCalloc(1, &data));
2100d0321e0SJeremy L Thompson 
2110d0321e0SJeremy L Thompson   // Copy data to GPU
212437930d1SJeremy L Thompson   const CeedInt q_bytes = Q_1d * sizeof(CeedScalar);
2132b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMalloc((void **)&data->d_q_weight_1d, q_bytes));
2142b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMemcpy(data->d_q_weight_1d, q_weight_1d, q_bytes, hipMemcpyHostToDevice));
2150d0321e0SJeremy L Thompson 
216437930d1SJeremy L Thompson   const CeedInt interp_bytes = q_bytes * P_1d;
2172b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMalloc((void **)&data->d_interp_1d, interp_bytes));
2182b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMemcpy(data->d_interp_1d, interp_1d, interp_bytes, hipMemcpyHostToDevice));
2190d0321e0SJeremy L Thompson 
2202b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMalloc((void **)&data->d_grad_1d, interp_bytes));
2212b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMemcpy(data->d_grad_1d, grad_1d, interp_bytes, hipMemcpyHostToDevice));
2220d0321e0SJeremy L Thompson 
223ecc88aebSJeremy L Thompson   // Compile basis kernels
2240d0321e0SJeremy L Thompson   CeedInt ncomp;
2252b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetNumComponents(basis, &ncomp));
226437930d1SJeremy L Thompson   char *basis_kernel_path, *basis_kernel_source;
2272b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetJitAbsolutePath(ceed, "ceed/jit-source/hip/hip-ref-basis-tensor.h", &basis_kernel_path));
22846dc0734SJeremy L Thompson   CeedDebug256(ceed, 2, "----- Loading Basis Kernel Source -----\n");
2292b730f8bSJeremy L Thompson   CeedCallBackend(CeedLoadSourceToBuffer(ceed, basis_kernel_path, &basis_kernel_source));
23046dc0734SJeremy L Thompson   CeedDebug256(ceed, 2, "----- Loading Basis Kernel Source Complete! -----\n");
2312b730f8bSJeremy L Thompson   CeedCallBackend(CeedCompileHip(ceed, basis_kernel_source, &data->module, 7, "BASIS_Q_1D", Q_1d, "BASIS_P_1D", P_1d, "BASIS_BUF_LEN",
2322b730f8bSJeremy L Thompson                                  ncomp * CeedIntPow(Q_1d > P_1d ? Q_1d : P_1d, dim), "BASIS_DIM", dim, "BASIS_NUM_COMP", ncomp, "BASIS_NUM_NODES",
2332b730f8bSJeremy L Thompson                                  CeedIntPow(P_1d, dim), "BASIS_NUM_QPTS", CeedIntPow(Q_1d, dim)));
2342b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetKernelHip(ceed, data->module, "Interp", &data->Interp));
2352b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetKernelHip(ceed, data->module, "Grad", &data->Grad));
2362b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetKernelHip(ceed, data->module, "Weight", &data->Weight));
2372b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&basis_kernel_path));
2382b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&basis_kernel_source));
239437930d1SJeremy L Thompson 
2402b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisSetData(basis, data));
2410d0321e0SJeremy L Thompson 
2422b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApply_Hip));
2432b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroy_Hip));
2440d0321e0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
2450d0321e0SJeremy L Thompson }
2460d0321e0SJeremy L Thompson 
2470d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
2480d0321e0SJeremy L Thompson // Create non-tensor
2490d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
2502b730f8bSJeremy L Thompson int CeedBasisCreateH1_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, const CeedScalar *grad,
2512b730f8bSJeremy L Thompson                           const CeedScalar *qref, const CeedScalar *q_weight, CeedBasis basis) {
2520d0321e0SJeremy L Thompson   Ceed ceed;
2532b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetCeed(basis, &ceed));
2540d0321e0SJeremy L Thompson   CeedBasisNonTensor_Hip *data;
2552b730f8bSJeremy L Thompson   CeedCallBackend(CeedCalloc(1, &data));
2560d0321e0SJeremy L Thompson 
2570d0321e0SJeremy L Thompson   // Copy basis data to GPU
258437930d1SJeremy L Thompson   const CeedInt q_bytes = num_qpts * sizeof(CeedScalar);
2592b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMalloc((void **)&data->d_q_weight, q_bytes));
2602b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMemcpy(data->d_q_weight, q_weight, q_bytes, hipMemcpyHostToDevice));
2610d0321e0SJeremy L Thompson 
262437930d1SJeremy L Thompson   const CeedInt interp_bytes = q_bytes * num_nodes;
2632b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMalloc((void **)&data->d_interp, interp_bytes));
2642b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMemcpy(data->d_interp, interp, interp_bytes, hipMemcpyHostToDevice));
2650d0321e0SJeremy L Thompson 
266437930d1SJeremy L Thompson   const CeedInt grad_bytes = q_bytes * num_nodes * dim;
2672b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMalloc((void **)&data->d_grad, grad_bytes));
2682b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMemcpy(data->d_grad, grad, grad_bytes, hipMemcpyHostToDevice));
2690d0321e0SJeremy L Thompson 
2700d0321e0SJeremy L Thompson   // Compile basis kernels
2710d0321e0SJeremy L Thompson   CeedInt ncomp;
2722b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisGetNumComponents(basis, &ncomp));
273437930d1SJeremy L Thompson   char *basis_kernel_path, *basis_kernel_source;
2742b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetJitAbsolutePath(ceed, "ceed/jit-source/hip/hip-ref-basis-nontensor.h", &basis_kernel_path));
27546dc0734SJeremy L Thompson   CeedDebug256(ceed, 2, "----- Loading Basis Kernel Source -----\n");
2762b730f8bSJeremy L Thompson   CeedCallBackend(CeedLoadSourceToBuffer(ceed, basis_kernel_path, &basis_kernel_source));
27746dc0734SJeremy L Thompson   CeedDebug256(ceed, 2, "----- Loading Basis Kernel Source Complete! -----\n");
2782b730f8bSJeremy L Thompson   CeedCallBackend(CeedCompileHip(ceed, basis_kernel_source, &data->module, 4, "BASIS_Q", num_qpts, "BASIS_P", num_nodes, "BASIS_DIM", dim,
2792b730f8bSJeremy L Thompson                                  "BASIS_NUM_COMP", ncomp));
2802b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetKernelHip(ceed, data->module, "Interp", &data->Interp));
2812b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetKernelHip(ceed, data->module, "Grad", &data->Grad));
2822b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetKernelHip(ceed, data->module, "Weight", &data->Weight));
2832b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&basis_kernel_path));
2842b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&basis_kernel_source));
2852b730f8bSJeremy L Thompson   CeedCallBackend(CeedBasisSetData(basis, data));
2860d0321e0SJeremy L Thompson 
2870d0321e0SJeremy L Thompson   // Register backend functions
2882b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApplyNonTensor_Hip));
2892b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroyNonTensor_Hip));
2900d0321e0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
2910d0321e0SJeremy L Thompson }
292*2a86cc9dSSebastian Grimberg 
2930d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
294