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; 220d0321e0SJeremy L Thompson Ceed_Hip *ceed_Hip; 23*b7453713SJeremy L Thompson CeedInt Q_1d, dim; 24437930d1SJeremy L Thompson const CeedInt transpose = t_mode == CEED_TRANSPOSE; 25437930d1SJeremy L Thompson const int max_block_size = 64; 260d0321e0SJeremy L Thompson const CeedScalar *d_u; 270d0321e0SJeremy L Thompson CeedScalar *d_v; 28*b7453713SJeremy L Thompson CeedBasis_Hip *data; 29*b7453713SJeremy L Thompson 30*b7453713SJeremy L Thompson CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 31*b7453713SJeremy L Thompson CeedCallBackend(CeedGetData(ceed, &ceed_Hip)); 32*b7453713SJeremy L Thompson CeedCallBackend(CeedBasisGetData(basis, &data)); 33*b7453713SJeremy L Thompson 34*b7453713SJeremy L Thompson // Read vectors 356574a04fSJeremy L Thompson if (u != CEED_VECTOR_NONE) CeedCallBackend(CeedVectorGetArrayRead(u, CEED_MEM_DEVICE, &d_u)); 366574a04fSJeremy L Thompson else CeedCheck(eval_mode == CEED_EVAL_WEIGHT, ceed, CEED_ERROR_BACKEND, "An input vector is required for this CeedEvalMode"); 372b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorGetArrayWrite(v, CEED_MEM_DEVICE, &d_v)); 380d0321e0SJeremy L Thompson 390d0321e0SJeremy L Thompson // Clear v for transpose operation 40437930d1SJeremy L Thompson if (t_mode == CEED_TRANSPOSE) { 411f9221feSJeremy L Thompson CeedSize length; 42*b7453713SJeremy L Thompson 432b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorGetLength(v, &length)); 442b730f8bSJeremy L Thompson CeedCallHip(ceed, hipMemset(d_v, 0, length * sizeof(CeedScalar))); 450d0321e0SJeremy L Thompson } 46b2165e7aSSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadraturePoints1D(basis, &Q_1d)); 47b2165e7aSSebastian Grimberg CeedCallBackend(CeedBasisGetDimension(basis, &dim)); 480d0321e0SJeremy L Thompson 490d0321e0SJeremy L Thompson // Basis action 50437930d1SJeremy L Thompson switch (eval_mode) { 510d0321e0SJeremy L Thompson case CEED_EVAL_INTERP: { 522b730f8bSJeremy L Thompson void *interp_args[] = {(void *)&num_elem, (void *)&transpose, &data->d_interp_1d, &d_u, &d_v}; 53b2165e7aSSebastian Grimberg const CeedInt block_size = CeedIntMin(CeedIntPow(Q_1d, dim), max_block_size); 540d0321e0SJeremy L Thompson 55eb7e6cafSJeremy L Thompson CeedCallBackend(CeedRunKernel_Hip(ceed, data->Interp, num_elem, block_size, interp_args)); 560d0321e0SJeremy L Thompson } break; 570d0321e0SJeremy L Thompson case CEED_EVAL_GRAD: { 582b730f8bSJeremy L Thompson void *grad_args[] = {(void *)&num_elem, (void *)&transpose, &data->d_interp_1d, &data->d_grad_1d, &d_u, &d_v}; 59b2165e7aSSebastian Grimberg const CeedInt block_size = max_block_size; 600d0321e0SJeremy L Thompson 61eb7e6cafSJeremy L Thompson CeedCallBackend(CeedRunKernel_Hip(ceed, data->Grad, num_elem, block_size, grad_args)); 620d0321e0SJeremy L Thompson } break; 630d0321e0SJeremy L Thompson case CEED_EVAL_WEIGHT: { 64437930d1SJeremy L Thompson void *weight_args[] = {(void *)&num_elem, (void *)&data->d_q_weight_1d, &d_v}; 65b2165e7aSSebastian Grimberg const int block_size_x = Q_1d; 66b2165e7aSSebastian Grimberg const int block_size_y = dim >= 2 ? Q_1d : 1; 670d0321e0SJeremy L Thompson 68b2165e7aSSebastian Grimberg CeedCallBackend(CeedRunKernelDim_Hip(ceed, data->Weight, num_elem, block_size_x, block_size_y, 1, 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; 970d0321e0SJeremy L Thompson Ceed_Hip *ceed_Hip; 98437930d1SJeremy L Thompson CeedInt num_nodes, num_qpts; 99437930d1SJeremy L Thompson const CeedInt transpose = t_mode == CEED_TRANSPOSE; 100b2165e7aSSebastian Grimberg int elems_per_block = 1; 101b2165e7aSSebastian Grimberg int grid = num_elem / elems_per_block + ((num_elem / elems_per_block * elems_per_block < num_elem) ? 1 : 0); 1020d0321e0SJeremy L Thompson const CeedScalar *d_u; 1030d0321e0SJeremy L Thompson CeedScalar *d_v; 104*b7453713SJeremy L Thompson CeedBasisNonTensor_Hip *data; 105*b7453713SJeremy L Thompson 106*b7453713SJeremy L Thompson CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 107*b7453713SJeremy L Thompson CeedCallBackend(CeedGetData(ceed, &ceed_Hip)); 108*b7453713SJeremy L Thompson CeedCallBackend(CeedBasisGetData(basis, &data)); 109*b7453713SJeremy L Thompson CeedCallBackend(CeedBasisGetNumQuadraturePoints(basis, &num_qpts)); 110*b7453713SJeremy L Thompson CeedCallBackend(CeedBasisGetNumNodes(basis, &num_nodes)); 111*b7453713SJeremy L Thompson 112*b7453713SJeremy L Thompson // Read vectors 113437930d1SJeremy L Thompson if (eval_mode != CEED_EVAL_WEIGHT) { 1142b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorGetArrayRead(u, CEED_MEM_DEVICE, &d_u)); 1150d0321e0SJeremy L Thompson } 1162b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorGetArrayWrite(v, CEED_MEM_DEVICE, &d_v)); 1170d0321e0SJeremy L Thompson 1180d0321e0SJeremy L Thompson // Clear v for transpose operation 119437930d1SJeremy L Thompson if (t_mode == CEED_TRANSPOSE) { 1201f9221feSJeremy L Thompson CeedSize length; 121*b7453713SJeremy L Thompson 1222b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorGetLength(v, &length)); 1232b730f8bSJeremy L Thompson CeedCallHip(ceed, hipMemset(d_v, 0, length * sizeof(CeedScalar))); 1240d0321e0SJeremy L Thompson } 1250d0321e0SJeremy L Thompson 1260d0321e0SJeremy L Thompson // Apply basis operation 127437930d1SJeremy L Thompson switch (eval_mode) { 1280d0321e0SJeremy L Thompson case CEED_EVAL_INTERP: { 1292b730f8bSJeremy L Thompson void *interp_args[] = {(void *)&num_elem, (void *)&transpose, &data->d_interp, &d_u, &d_v}; 1302b730f8bSJeremy L Thompson const int block_size_x = transpose ? num_nodes : num_qpts; 131b2165e7aSSebastian Grimberg 132b2165e7aSSebastian Grimberg CeedCallBackend(CeedRunKernelDim_Hip(ceed, data->Interp, grid, block_size_x, 1, elems_per_block, interp_args)); 1330d0321e0SJeremy L Thompson } break; 1340d0321e0SJeremy L Thompson case CEED_EVAL_GRAD: { 1352b730f8bSJeremy L Thompson void *grad_args[] = {(void *)&num_elem, (void *)&transpose, &data->d_grad, &d_u, &d_v}; 1362b730f8bSJeremy L Thompson const int block_size_x = transpose ? num_nodes : num_qpts; 137b2165e7aSSebastian Grimberg 138b2165e7aSSebastian Grimberg CeedCallBackend(CeedRunKernelDim_Hip(ceed, data->Grad, grid, block_size_x, 1, elems_per_block, grad_args)); 1390d0321e0SJeremy L Thompson } break; 1400d0321e0SJeremy L Thompson case CEED_EVAL_WEIGHT: { 141437930d1SJeremy L Thompson void *weight_args[] = {(void *)&num_elem, (void *)&data->d_q_weight, &d_v}; 142b2165e7aSSebastian Grimberg 143b2165e7aSSebastian Grimberg CeedCallBackend(CeedRunKernelDim_Hip(ceed, data->Weight, grid, num_qpts, 1, elems_per_block, weight_args)); 1440d0321e0SJeremy L Thompson } break; 1450d0321e0SJeremy L Thompson // LCOV_EXCL_START 1460d0321e0SJeremy L Thompson // Evaluate the divergence to/from the quadrature points 1470d0321e0SJeremy L Thompson case CEED_EVAL_DIV: 1480d0321e0SJeremy L Thompson return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_DIV not supported"); 1490d0321e0SJeremy L Thompson // Evaluate the curl to/from the quadrature points 1500d0321e0SJeremy L Thompson case CEED_EVAL_CURL: 1510d0321e0SJeremy L Thompson return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_CURL not supported"); 1520d0321e0SJeremy L Thompson // Take no action, BasisApply should not have been called 1530d0321e0SJeremy L Thompson case CEED_EVAL_NONE: 1542b730f8bSJeremy L Thompson return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_NONE does not make sense in this context"); 1550d0321e0SJeremy L Thompson // LCOV_EXCL_STOP 1560d0321e0SJeremy L Thompson } 1570d0321e0SJeremy L Thompson 1580d0321e0SJeremy L Thompson // Restore vectors 159437930d1SJeremy L Thompson if (eval_mode != CEED_EVAL_WEIGHT) { 1602b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); 1610d0321e0SJeremy L Thompson } 1622b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); 1630d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1640d0321e0SJeremy L Thompson } 1650d0321e0SJeremy L Thompson 1660d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 1670d0321e0SJeremy L Thompson // Destroy tensor basis 1680d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 1690d0321e0SJeremy L Thompson static int CeedBasisDestroy_Hip(CeedBasis basis) { 1700d0321e0SJeremy L Thompson Ceed ceed; 1710d0321e0SJeremy L Thompson CeedBasis_Hip *data; 172*b7453713SJeremy L Thompson 173*b7453713SJeremy L Thompson CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 1742b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetData(basis, &data)); 1752b730f8bSJeremy L Thompson CeedCallHip(ceed, hipModuleUnload(data->module)); 1762b730f8bSJeremy L Thompson CeedCallHip(ceed, hipFree(data->d_q_weight_1d)); 1772b730f8bSJeremy L Thompson CeedCallHip(ceed, hipFree(data->d_interp_1d)); 1782b730f8bSJeremy L Thompson CeedCallHip(ceed, hipFree(data->d_grad_1d)); 1792b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&data)); 1800d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1810d0321e0SJeremy L Thompson } 1820d0321e0SJeremy L Thompson 1830d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 1840d0321e0SJeremy L Thompson // Destroy non-tensor basis 1850d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 1860d0321e0SJeremy L Thompson static int CeedBasisDestroyNonTensor_Hip(CeedBasis basis) { 1870d0321e0SJeremy L Thompson Ceed ceed; 1880d0321e0SJeremy L Thompson CeedBasisNonTensor_Hip *data; 189*b7453713SJeremy L Thompson 190*b7453713SJeremy L Thompson CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 1912b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetData(basis, &data)); 1922b730f8bSJeremy L Thompson CeedCallHip(ceed, hipModuleUnload(data->module)); 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)); 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, 2046574a04fSJeremy L Thompson const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis) { 2050d0321e0SJeremy L Thompson Ceed ceed; 206*b7453713SJeremy L Thompson char *basis_kernel_path, *basis_kernel_source; 207*b7453713SJeremy L Thompson CeedInt num_comp; 208*b7453713SJeremy L Thompson const CeedInt q_bytes = Q_1d * sizeof(CeedScalar); 209*b7453713SJeremy L Thompson const CeedInt interp_bytes = q_bytes * P_1d; 2100d0321e0SJeremy L Thompson CeedBasis_Hip *data; 211*b7453713SJeremy L Thompson 212*b7453713SJeremy L Thompson CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 2132b730f8bSJeremy L Thompson CeedCallBackend(CeedCalloc(1, &data)); 2140d0321e0SJeremy L Thompson 2150d0321e0SJeremy L Thompson // Copy data to GPU 2162b730f8bSJeremy L Thompson CeedCallHip(ceed, hipMalloc((void **)&data->d_q_weight_1d, q_bytes)); 2172b730f8bSJeremy L Thompson CeedCallHip(ceed, hipMemcpy(data->d_q_weight_1d, q_weight_1d, q_bytes, hipMemcpyHostToDevice)); 2182b730f8bSJeremy L Thompson CeedCallHip(ceed, hipMalloc((void **)&data->d_interp_1d, interp_bytes)); 2192b730f8bSJeremy L Thompson CeedCallHip(ceed, hipMemcpy(data->d_interp_1d, interp_1d, interp_bytes, hipMemcpyHostToDevice)); 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 224*b7453713SJeremy L Thompson CeedCallBackend(CeedBasisGetNumComponents(basis, &num_comp)); 2252b730f8bSJeremy L Thompson CeedCallBackend(CeedGetJitAbsolutePath(ceed, "ceed/jit-source/hip/hip-ref-basis-tensor.h", &basis_kernel_path)); 22623d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading Basis Kernel Source -----\n"); 2272b730f8bSJeremy L Thompson CeedCallBackend(CeedLoadSourceToBuffer(ceed, basis_kernel_path, &basis_kernel_source)); 22823d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading Basis Kernel Source Complete! -----\n"); 229eb7e6cafSJeremy L Thompson CeedCallBackend(CeedCompile_Hip(ceed, basis_kernel_source, &data->module, 7, "BASIS_Q_1D", Q_1d, "BASIS_P_1D", P_1d, "BASIS_BUF_LEN", 230*b7453713SJeremy L Thompson num_comp * CeedIntPow(Q_1d > P_1d ? Q_1d : P_1d, dim), "BASIS_DIM", dim, "BASIS_NUM_COMP", num_comp, 231*b7453713SJeremy L Thompson "BASIS_NUM_NODES", CeedIntPow(P_1d, dim), "BASIS_NUM_QPTS", CeedIntPow(Q_1d, dim))); 232eb7e6cafSJeremy L Thompson CeedCallBackend(CeedGetKernel_Hip(ceed, data->module, "Interp", &data->Interp)); 233eb7e6cafSJeremy L Thompson CeedCallBackend(CeedGetKernel_Hip(ceed, data->module, "Grad", &data->Grad)); 234eb7e6cafSJeremy L Thompson CeedCallBackend(CeedGetKernel_Hip(ceed, data->module, "Weight", &data->Weight)); 2352b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&basis_kernel_path)); 2362b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&basis_kernel_source)); 237437930d1SJeremy L Thompson 2382b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisSetData(basis, data)); 2390d0321e0SJeremy L Thompson 2402b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApply_Hip)); 2412b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroy_Hip)); 2420d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2430d0321e0SJeremy L Thompson } 2440d0321e0SJeremy L Thompson 2450d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 2460d0321e0SJeremy L Thompson // Create non-tensor 2470d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 2482b730f8bSJeremy L Thompson int CeedBasisCreateH1_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, const CeedScalar *grad, 24951475c7cSJeremy L Thompson const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis) { 2500d0321e0SJeremy L Thompson Ceed ceed; 251*b7453713SJeremy L Thompson char *basis_kernel_path, *basis_kernel_source; 252*b7453713SJeremy L Thompson CeedInt num_comp; 253*b7453713SJeremy L Thompson const CeedInt q_bytes = num_qpts * sizeof(CeedScalar); 254*b7453713SJeremy L Thompson const CeedInt interp_bytes = q_bytes * num_nodes; 255*b7453713SJeremy L Thompson const CeedInt grad_bytes = q_bytes * num_nodes * dim; 2560d0321e0SJeremy L Thompson CeedBasisNonTensor_Hip *data; 257*b7453713SJeremy L Thompson 258*b7453713SJeremy L Thompson CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 2592b730f8bSJeremy L Thompson CeedCallBackend(CeedCalloc(1, &data)); 2600d0321e0SJeremy L Thompson 2610d0321e0SJeremy L Thompson // Copy basis data to GPU 2622b730f8bSJeremy L Thompson CeedCallHip(ceed, hipMalloc((void **)&data->d_q_weight, q_bytes)); 2632b730f8bSJeremy L Thompson CeedCallHip(ceed, hipMemcpy(data->d_q_weight, q_weight, q_bytes, hipMemcpyHostToDevice)); 2642b730f8bSJeremy L Thompson CeedCallHip(ceed, hipMalloc((void **)&data->d_interp, interp_bytes)); 2652b730f8bSJeremy L Thompson CeedCallHip(ceed, hipMemcpy(data->d_interp, interp, interp_bytes, hipMemcpyHostToDevice)); 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 270*b7453713SJeremy L Thompson CeedCallBackend(CeedBasisGetNumComponents(basis, &num_comp)); 2712b730f8bSJeremy L Thompson CeedCallBackend(CeedGetJitAbsolutePath(ceed, "ceed/jit-source/hip/hip-ref-basis-nontensor.h", &basis_kernel_path)); 27223d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading Basis Kernel Source -----\n"); 2732b730f8bSJeremy L Thompson CeedCallBackend(CeedLoadSourceToBuffer(ceed, basis_kernel_path, &basis_kernel_source)); 27423d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading Basis Kernel Source Complete! -----\n"); 275eb7e6cafSJeremy L Thompson CeedCallBackend(CeedCompile_Hip(ceed, basis_kernel_source, &data->module, 4, "BASIS_Q", num_qpts, "BASIS_P", num_nodes, "BASIS_DIM", dim, 276*b7453713SJeremy L Thompson "BASIS_NUM_COMP", num_comp)); 277eb7e6cafSJeremy L Thompson CeedCallBackend(CeedGetKernel_Hip(ceed, data->module, "Interp", &data->Interp)); 278eb7e6cafSJeremy L Thompson CeedCallBackend(CeedGetKernel_Hip(ceed, data->module, "Grad", &data->Grad)); 279eb7e6cafSJeremy L Thompson CeedCallBackend(CeedGetKernel_Hip(ceed, data->module, "Weight", &data->Weight)); 2802b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&basis_kernel_path)); 2812b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&basis_kernel_source)); 2822b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisSetData(basis, data)); 2830d0321e0SJeremy L Thompson 2840d0321e0SJeremy L Thompson // Register backend functions 2852b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApplyNonTensor_Hip)); 2862b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroyNonTensor_Hip)); 2870d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2880d0321e0SJeremy L Thompson } 2892a86cc9dSSebastian Grimberg 2900d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 291