1bd882c8aSJames Wright // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 2bd882c8aSJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3bd882c8aSJames Wright // 4bd882c8aSJames Wright // SPDX-License-Identifier: BSD-2-Clause 5bd882c8aSJames Wright // 6bd882c8aSJames Wright // This file is part of CEED: http://github.com/ceed 7bd882c8aSJames Wright 8bd882c8aSJames Wright #include <ceed/backend.h> 9bd882c8aSJames Wright #include <ceed/ceed.h> 10bd882c8aSJames Wright #include <ceed/jit-tools.h> 11bd882c8aSJames Wright 12bd882c8aSJames Wright #include <sycl/sycl.hpp> 13bd882c8aSJames Wright #include <vector> 14bd882c8aSJames Wright 15bd882c8aSJames Wright #include "../sycl/ceed-sycl-compile.hpp" 16bd882c8aSJames Wright #include "ceed-sycl-ref.hpp" 17bd882c8aSJames Wright 18bd882c8aSJames Wright template <int> 19bd882c8aSJames Wright class CeedBasisSyclInterp; 20bd882c8aSJames Wright template <int> 21bd882c8aSJames Wright class CeedBasisSyclGrad; 22bd882c8aSJames Wright class CeedBasisSyclWeight; 23bd882c8aSJames Wright 24bd882c8aSJames Wright class CeedBasisSyclInterpNT; 25bd882c8aSJames Wright class CeedBasisSyclGradNT; 26bd882c8aSJames Wright class CeedBasisSyclWeightNT; 27bd882c8aSJames Wright 28bd882c8aSJames Wright using SpecID = sycl::specialization_id<CeedInt>; 29bd882c8aSJames Wright 30bd882c8aSJames Wright static constexpr SpecID BASIS_DIM_ID; 31bd882c8aSJames Wright static constexpr SpecID BASIS_NUM_COMP_ID; 32bd882c8aSJames Wright static constexpr SpecID BASIS_P_1D_ID; 33bd882c8aSJames Wright static constexpr SpecID BASIS_Q_1D_ID; 34bd882c8aSJames Wright 35bd882c8aSJames Wright //------------------------------------------------------------------------------ 36bd882c8aSJames Wright // Interpolation kernel - tensor 37bd882c8aSJames Wright //------------------------------------------------------------------------------ 38bd882c8aSJames Wright template <int transpose> 39bd882c8aSJames Wright static int CeedBasisApplyInterp_Sycl(sycl::queue &sycl_queue, const SyclModule_t &sycl_module, CeedInt num_elem, const CeedBasis_Sycl *impl, 40bd882c8aSJames Wright const CeedScalar *u, CeedScalar *v) { 41bd882c8aSJames Wright const CeedInt buf_len = impl->buf_len; 42bd882c8aSJames Wright const CeedInt op_len = impl->op_len; 43bd882c8aSJames Wright const CeedScalar *interp_1d = impl->d_interp_1d; 44bd882c8aSJames Wright 45bd882c8aSJames Wright const sycl::device &sycl_device = sycl_queue.get_device(); 46bd882c8aSJames Wright const CeedInt max_work_group_size = 32; 47bd882c8aSJames Wright const CeedInt work_group_size = CeedIntMin(impl->num_qpts, max_work_group_size); 48bd882c8aSJames Wright sycl::range<1> local_range(work_group_size); 49bd882c8aSJames Wright sycl::range<1> global_range(num_elem * work_group_size); 50bd882c8aSJames Wright sycl::nd_range<1> kernel_range(global_range, local_range); 51bd882c8aSJames Wright 52bd882c8aSJames Wright // Order queue 53bd882c8aSJames Wright sycl::event e = sycl_queue.ext_oneapi_submit_barrier(); 54bd882c8aSJames Wright sycl_queue.submit([&](sycl::handler &cgh) { 55bd882c8aSJames Wright cgh.depends_on({e}); 56bd882c8aSJames Wright cgh.use_kernel_bundle(sycl_module); 57bd882c8aSJames Wright 58bd882c8aSJames Wright sycl::local_accessor<CeedScalar> s_mem(op_len + 2 * buf_len, cgh); 59bd882c8aSJames Wright 60bd882c8aSJames Wright cgh.parallel_for<CeedBasisSyclInterp<transpose>>(kernel_range, [=](sycl::nd_item<1> work_item, sycl::kernel_handler kh) { 61bd882c8aSJames Wright //--------------------------------------------------------------> 62bd882c8aSJames Wright // Retrieve spec constant values 63bd882c8aSJames Wright const CeedInt dim = kh.get_specialization_constant<BASIS_DIM_ID>(); 64bd882c8aSJames Wright const CeedInt num_comp = kh.get_specialization_constant<BASIS_NUM_COMP_ID>(); 65bd882c8aSJames Wright const CeedInt P_1d = kh.get_specialization_constant<BASIS_P_1D_ID>(); 66bd882c8aSJames Wright const CeedInt Q_1d = kh.get_specialization_constant<BASIS_Q_1D_ID>(); 67bd882c8aSJames Wright //--------------------------------------------------------------> 68bd882c8aSJames Wright const CeedInt num_nodes = CeedIntPow(P_1d, dim); 69bd882c8aSJames Wright const CeedInt num_qpts = CeedIntPow(Q_1d, dim); 70bd882c8aSJames Wright const CeedInt P = transpose ? Q_1d : P_1d; 71bd882c8aSJames Wright const CeedInt Q = transpose ? P_1d : Q_1d; 72bd882c8aSJames Wright const CeedInt stride_0 = transpose ? 1 : P_1d; 73bd882c8aSJames Wright const CeedInt stride_1 = transpose ? P_1d : 1; 74bd882c8aSJames Wright const CeedInt u_stride = transpose ? num_qpts : num_nodes; 75bd882c8aSJames Wright const CeedInt v_stride = transpose ? num_nodes : num_qpts; 76bd882c8aSJames Wright const CeedInt u_comp_stride = num_elem * u_stride; 77bd882c8aSJames Wright const CeedInt v_comp_stride = num_elem * v_stride; 78bd882c8aSJames Wright const CeedInt u_size = u_stride; 79bd882c8aSJames Wright 80bd882c8aSJames Wright sycl::group work_group = work_item.get_group(); 81bd882c8aSJames Wright const CeedInt i = work_item.get_local_linear_id(); 82bd882c8aSJames Wright const CeedInt group_size = work_group.get_local_linear_range(); 83bd882c8aSJames Wright const CeedInt elem = work_group.get_group_linear_id(); 84bd882c8aSJames Wright 85*33bb61d4SKris Rowe CeedScalar *s_interp_1d = s_mem.get_multi_ptr<sycl::access::decorated::yes>().get(); 86bd882c8aSJames Wright CeedScalar *s_buffer_1 = s_interp_1d + Q * P; 87bd882c8aSJames Wright CeedScalar *s_buffer_2 = s_buffer_1 + buf_len; 88bd882c8aSJames Wright 89bd882c8aSJames Wright for (CeedInt k = i; k < P * Q; k += group_size) { 90bd882c8aSJames Wright s_interp_1d[k] = interp_1d[k]; 91bd882c8aSJames Wright } 92bd882c8aSJames Wright 93bd882c8aSJames Wright // Apply basis element by element 94bd882c8aSJames Wright for (CeedInt comp = 0; comp < num_comp; comp++) { 95bd882c8aSJames Wright const CeedScalar *cur_u = u + elem * u_stride + comp * u_comp_stride; 96bd882c8aSJames Wright CeedScalar *cur_v = v + elem * v_stride + comp * v_comp_stride; 97bd882c8aSJames Wright 98bd882c8aSJames Wright for (CeedInt k = i; k < u_size; k += group_size) { 99bd882c8aSJames Wright s_buffer_1[k] = cur_u[k]; 100bd882c8aSJames Wright } 101bd882c8aSJames Wright 102bd882c8aSJames Wright CeedInt pre = u_size; 103bd882c8aSJames Wright CeedInt post = 1; 104bd882c8aSJames Wright 105bd882c8aSJames Wright for (CeedInt d = 0; d < dim; d++) { 106bd882c8aSJames Wright // Use older version of sycl workgroup barrier for performance reasons 107bd882c8aSJames Wright // Can be updated in future to align with SYCL2020 spec if performance bottleneck is removed 108bd882c8aSJames Wright // sycl::group_barrier(work_group); 109bd882c8aSJames Wright work_item.barrier(sycl::access::fence_space::local_space); 110bd882c8aSJames Wright 111bd882c8aSJames Wright pre /= P; 112bd882c8aSJames Wright const CeedScalar *in = d % 2 ? s_buffer_2 : s_buffer_1; 113bd882c8aSJames Wright CeedScalar *out = d == dim - 1 ? cur_v : (d % 2 ? s_buffer_1 : s_buffer_2); 114bd882c8aSJames Wright 115bd882c8aSJames Wright // Contract along middle index 116bd882c8aSJames Wright const CeedInt writeLen = pre * post * Q; 117bd882c8aSJames Wright for (CeedInt k = i; k < writeLen; k += group_size) { 118bd882c8aSJames Wright const CeedInt c = k % post; 119bd882c8aSJames Wright const CeedInt j = (k / post) % Q; 120bd882c8aSJames Wright const CeedInt a = k / (post * Q); 121bd882c8aSJames Wright 122bd882c8aSJames Wright CeedScalar vk = 0; 123bd882c8aSJames Wright for (CeedInt b = 0; b < P; b++) { 124bd882c8aSJames Wright vk += s_interp_1d[j * stride_0 + b * stride_1] * in[(a * P + b) * post + c]; 125bd882c8aSJames Wright } 126bd882c8aSJames Wright out[k] = vk; 127bd882c8aSJames Wright } 128bd882c8aSJames Wright post *= Q; 129bd882c8aSJames Wright } 130bd882c8aSJames Wright } 131bd882c8aSJames Wright }); 132bd882c8aSJames Wright }); 133bd882c8aSJames Wright return CEED_ERROR_SUCCESS; 134bd882c8aSJames Wright } 135bd882c8aSJames Wright 136bd882c8aSJames Wright //------------------------------------------------------------------------------ 137bd882c8aSJames Wright // Gradient kernel - tensor 138bd882c8aSJames Wright //------------------------------------------------------------------------------ 139bd882c8aSJames Wright template <int transpose> 140bd882c8aSJames Wright static int CeedBasisApplyGrad_Sycl(sycl::queue &sycl_queue, const SyclModule_t &sycl_module, CeedInt num_elem, const CeedBasis_Sycl *impl, 141bd882c8aSJames Wright const CeedScalar *u, CeedScalar *v) { 142bd882c8aSJames Wright const CeedInt buf_len = impl->buf_len; 143bd882c8aSJames Wright const CeedInt op_len = impl->op_len; 144bd882c8aSJames Wright const CeedScalar *interp_1d = impl->d_interp_1d; 145bd882c8aSJames Wright const CeedScalar *grad_1d = impl->d_grad_1d; 146bd882c8aSJames Wright 147bd882c8aSJames Wright const sycl::device &sycl_device = sycl_queue.get_device(); 148bd882c8aSJames Wright const CeedInt work_group_size = 32; 149bd882c8aSJames Wright sycl::range<1> local_range(work_group_size); 150bd882c8aSJames Wright sycl::range<1> global_range(num_elem * work_group_size); 151bd882c8aSJames Wright sycl::nd_range<1> kernel_range(global_range, local_range); 152bd882c8aSJames Wright 153bd882c8aSJames Wright // Order queue 154bd882c8aSJames Wright sycl::event e = sycl_queue.ext_oneapi_submit_barrier(); 155bd882c8aSJames Wright sycl_queue.submit([&](sycl::handler &cgh) { 156bd882c8aSJames Wright cgh.depends_on({e}); 157bd882c8aSJames Wright cgh.use_kernel_bundle(sycl_module); 158bd882c8aSJames Wright 159bd882c8aSJames Wright sycl::local_accessor<CeedScalar> s_mem(2 * (op_len + buf_len), cgh); 160bd882c8aSJames Wright 161bd882c8aSJames Wright cgh.parallel_for<CeedBasisSyclGrad<transpose>>(kernel_range, [=](sycl::nd_item<1> work_item, sycl::kernel_handler kh) { 162bd882c8aSJames Wright //--------------------------------------------------------------> 163bd882c8aSJames Wright // Retrieve spec constant values 164bd882c8aSJames Wright const CeedInt dim = kh.get_specialization_constant<BASIS_DIM_ID>(); 165bd882c8aSJames Wright const CeedInt num_comp = kh.get_specialization_constant<BASIS_NUM_COMP_ID>(); 166bd882c8aSJames Wright const CeedInt P_1d = kh.get_specialization_constant<BASIS_P_1D_ID>(); 167bd882c8aSJames Wright const CeedInt Q_1d = kh.get_specialization_constant<BASIS_Q_1D_ID>(); 168bd882c8aSJames Wright //--------------------------------------------------------------> 169bd882c8aSJames Wright const CeedInt num_nodes = CeedIntPow(P_1d, dim); 170bd882c8aSJames Wright const CeedInt num_qpts = CeedIntPow(Q_1d, dim); 171bd882c8aSJames Wright const CeedInt P = transpose ? Q_1d : P_1d; 172bd882c8aSJames Wright const CeedInt Q = transpose ? P_1d : Q_1d; 173bd882c8aSJames Wright const CeedInt stride_0 = transpose ? 1 : P_1d; 174bd882c8aSJames Wright const CeedInt stride_1 = transpose ? P_1d : 1; 175bd882c8aSJames Wright const CeedInt u_stride = transpose ? num_qpts : num_nodes; 176bd882c8aSJames Wright const CeedInt v_stride = transpose ? num_nodes : num_qpts; 177bd882c8aSJames Wright const CeedInt u_comp_stride = num_elem * u_stride; 178bd882c8aSJames Wright const CeedInt v_comp_stride = num_elem * v_stride; 179bd882c8aSJames Wright const CeedInt u_dim_stride = transpose ? num_elem * num_qpts * num_comp : 0; 180bd882c8aSJames Wright const CeedInt v_dim_stride = transpose ? 0 : num_elem * num_qpts * num_comp; 181bd882c8aSJames Wright sycl::group work_group = work_item.get_group(); 182bd882c8aSJames Wright const CeedInt i = work_item.get_local_linear_id(); 183bd882c8aSJames Wright const CeedInt group_size = work_group.get_local_linear_range(); 184bd882c8aSJames Wright const CeedInt elem = work_group.get_group_linear_id(); 185bd882c8aSJames Wright 186*33bb61d4SKris Rowe CeedScalar *s_interp_1d = s_mem.get_multi_ptr<sycl::access::decorated::yes>().get(); 187bd882c8aSJames Wright CeedScalar *s_grad_1d = s_interp_1d + P * Q; 188bd882c8aSJames Wright CeedScalar *s_buffer_1 = s_grad_1d + P * Q; 189bd882c8aSJames Wright CeedScalar *s_buffer_2 = s_buffer_1 + buf_len; 190bd882c8aSJames Wright 191bd882c8aSJames Wright for (CeedInt k = i; k < P * Q; k += group_size) { 192bd882c8aSJames Wright s_interp_1d[k] = interp_1d[k]; 193bd882c8aSJames Wright s_grad_1d[k] = grad_1d[k]; 194bd882c8aSJames Wright } 195bd882c8aSJames Wright 196bd882c8aSJames Wright // Apply basis element by element 197bd882c8aSJames Wright for (CeedInt comp = 0; comp < num_comp; comp++) { 198bd882c8aSJames Wright for (CeedInt dim_1 = 0; dim_1 < dim; dim_1++) { 199bd882c8aSJames Wright CeedInt pre = transpose ? num_qpts : num_nodes; 200bd882c8aSJames Wright CeedInt post = 1; 201bd882c8aSJames Wright const CeedScalar *cur_u = u + elem * u_stride + dim_1 * u_dim_stride + comp * u_comp_stride; 202bd882c8aSJames Wright CeedScalar *cur_v = v + elem * v_stride + dim_1 * v_dim_stride + comp * v_comp_stride; 203bd882c8aSJames Wright 204bd882c8aSJames Wright for (CeedInt dim_2 = 0; dim_2 < dim; dim_2++) { 205bd882c8aSJames Wright // Use older version of sycl workgroup barrier for performance reasons 206bd882c8aSJames Wright // Can be updated in future to align with SYCL2020 spec if performance bottleneck is removed 207bd882c8aSJames Wright // sycl::group_barrier(work_group); 208bd882c8aSJames Wright work_item.barrier(sycl::access::fence_space::local_space); 209bd882c8aSJames Wright 210bd882c8aSJames Wright pre /= P; 211bd882c8aSJames Wright const CeedScalar *op = dim_1 == dim_2 ? s_grad_1d : s_interp_1d; 212bd882c8aSJames Wright const CeedScalar *in = (dim_2 == 0 ? cur_u : (dim_2 % 2 ? s_buffer_2 : s_buffer_1)); 213bd882c8aSJames Wright CeedScalar *out = dim_2 == dim - 1 ? cur_v : (dim_2 % 2 ? s_buffer_1 : s_buffer_2); 214bd882c8aSJames Wright 215bd882c8aSJames Wright // Contract along middle index 216bd882c8aSJames Wright const CeedInt writeLen = pre * post * Q; 217bd882c8aSJames Wright for (CeedInt k = i; k < writeLen; k += group_size) { 218bd882c8aSJames Wright const CeedInt c = k % post; 219bd882c8aSJames Wright const CeedInt j = (k / post) % Q; 220bd882c8aSJames Wright const CeedInt a = k / (post * Q); 221bd882c8aSJames Wright 222bd882c8aSJames Wright CeedScalar v_k = 0; 223bd882c8aSJames Wright for (CeedInt b = 0; b < P; b++) v_k += op[j * stride_0 + b * stride_1] * in[(a * P + b) * post + c]; 224bd882c8aSJames Wright 225bd882c8aSJames Wright if (transpose && dim_2 == dim - 1) out[k] += v_k; 226bd882c8aSJames Wright else out[k] = v_k; 227bd882c8aSJames Wright } 228bd882c8aSJames Wright 229bd882c8aSJames Wright post *= Q; 230bd882c8aSJames Wright } 231bd882c8aSJames Wright } 232bd882c8aSJames Wright } 233bd882c8aSJames Wright }); 234bd882c8aSJames Wright }); 235bd882c8aSJames Wright return CEED_ERROR_SUCCESS; 236bd882c8aSJames Wright } 237bd882c8aSJames Wright 238bd882c8aSJames Wright //------------------------------------------------------------------------------ 239bd882c8aSJames Wright // Weight kernel - tensor 240bd882c8aSJames Wright //------------------------------------------------------------------------------ 241bd882c8aSJames Wright static int CeedBasisApplyWeight_Sycl(sycl::queue &sycl_queue, CeedInt num_elem, const CeedBasis_Sycl *impl, CeedScalar *w) { 242bd882c8aSJames Wright const CeedInt dim = impl->dim; 243bd882c8aSJames Wright const CeedInt Q_1d = impl->Q_1d; 244bd882c8aSJames Wright const CeedScalar *q_weight_1d = impl->d_q_weight_1d; 245bd882c8aSJames Wright 246bd882c8aSJames Wright const CeedInt num_quad_x = Q_1d; 247bd882c8aSJames Wright const CeedInt num_quad_y = (dim > 1) ? Q_1d : 1; 248bd882c8aSJames Wright const CeedInt num_quad_z = (dim > 2) ? Q_1d : 1; 249bd882c8aSJames Wright sycl::range<3> kernel_range(num_elem * num_quad_z, num_quad_y, num_quad_x); 250bd882c8aSJames Wright 251bd882c8aSJames Wright // Order queue 252bd882c8aSJames Wright sycl::event e = sycl_queue.ext_oneapi_submit_barrier(); 253bd882c8aSJames Wright sycl_queue.parallel_for<CeedBasisSyclWeight>(kernel_range, {e}, [=](sycl::item<3> work_item) { 254bd882c8aSJames Wright if (dim == 1) w[work_item.get_linear_id()] = q_weight_1d[work_item[2]]; 255bd882c8aSJames Wright if (dim == 2) w[work_item.get_linear_id()] = q_weight_1d[work_item[2]] * q_weight_1d[work_item[1]]; 256bd882c8aSJames Wright if (dim == 3) w[work_item.get_linear_id()] = q_weight_1d[work_item[2]] * q_weight_1d[work_item[1]] * q_weight_1d[work_item[0] % Q_1d]; 257bd882c8aSJames Wright }); 258bd882c8aSJames Wright return CEED_ERROR_SUCCESS; 259bd882c8aSJames Wright } 260bd882c8aSJames Wright 261bd882c8aSJames Wright //------------------------------------------------------------------------------ 262bd882c8aSJames Wright // Basis apply - tensor 263bd882c8aSJames Wright //------------------------------------------------------------------------------ 264bd882c8aSJames Wright static int CeedBasisApply_Sycl(CeedBasis basis, const CeedInt num_elem, CeedTransposeMode t_mode, CeedEvalMode eval_mode, CeedVector u, 265bd882c8aSJames Wright CeedVector v) { 266bd882c8aSJames Wright Ceed ceed; 267bd882c8aSJames Wright CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 268bd882c8aSJames Wright Ceed_Sycl *data; 269bd882c8aSJames Wright CeedCallBackend(CeedGetData(ceed, &data)); 270bd882c8aSJames Wright CeedBasis_Sycl *impl; 271bd882c8aSJames Wright CeedCallBackend(CeedBasisGetData(basis, &impl)); 272bd882c8aSJames Wright 273bd882c8aSJames Wright const CeedInt transpose = t_mode == CEED_TRANSPOSE; 274bd882c8aSJames Wright 275bd882c8aSJames Wright // Read vectors 276bd882c8aSJames Wright const CeedScalar *d_u; 277bd882c8aSJames Wright CeedScalar *d_v; 278bd882c8aSJames Wright if (eval_mode != CEED_EVAL_WEIGHT) { 279bd882c8aSJames Wright CeedCallBackend(CeedVectorGetArrayRead(u, CEED_MEM_DEVICE, &d_u)); 280bd882c8aSJames Wright } 281bd882c8aSJames Wright CeedCallBackend(CeedVectorGetArrayWrite(v, CEED_MEM_DEVICE, &d_v)); 282bd882c8aSJames Wright 283bd882c8aSJames Wright // Clear v for transpose operation 284bd882c8aSJames Wright if (t_mode == CEED_TRANSPOSE) { 285bd882c8aSJames Wright CeedSize length; 286bd882c8aSJames Wright CeedCallBackend(CeedVectorGetLength(v, &length)); 287bd882c8aSJames Wright // Order queue 288bd882c8aSJames Wright sycl::event e = data->sycl_queue.ext_oneapi_submit_barrier(); 289bd882c8aSJames Wright data->sycl_queue.fill<CeedScalar>(d_v, 0, length, {e}); 290bd882c8aSJames Wright } 291bd882c8aSJames Wright 292bd882c8aSJames Wright // Basis action 293bd882c8aSJames Wright switch (eval_mode) { 294bd882c8aSJames Wright case CEED_EVAL_INTERP: { 295bd882c8aSJames Wright if (transpose) { 296bd882c8aSJames Wright CeedCallBackend(CeedBasisApplyInterp_Sycl<CEED_TRANSPOSE>(data->sycl_queue, *impl->sycl_module, num_elem, impl, d_u, d_v)); 297bd882c8aSJames Wright } else { 298bd882c8aSJames Wright CeedCallBackend(CeedBasisApplyInterp_Sycl<CEED_NOTRANSPOSE>(data->sycl_queue, *impl->sycl_module, num_elem, impl, d_u, d_v)); 299bd882c8aSJames Wright } 300bd882c8aSJames Wright } break; 301bd882c8aSJames Wright case CEED_EVAL_GRAD: { 302bd882c8aSJames Wright if (transpose) { 303bd882c8aSJames Wright CeedCallBackend(CeedBasisApplyGrad_Sycl<1>(data->sycl_queue, *impl->sycl_module, num_elem, impl, d_u, d_v)); 304bd882c8aSJames Wright } else { 305bd882c8aSJames Wright CeedCallBackend(CeedBasisApplyGrad_Sycl<0>(data->sycl_queue, *impl->sycl_module, num_elem, impl, d_u, d_v)); 306bd882c8aSJames Wright } 307bd882c8aSJames Wright } break; 308bd882c8aSJames Wright case CEED_EVAL_WEIGHT: { 309bd882c8aSJames Wright CeedCallBackend(CeedBasisApplyWeight_Sycl(data->sycl_queue, num_elem, impl, d_v)); 310bd882c8aSJames Wright } break; 311bd882c8aSJames Wright // LCOV_EXCL_START 312bd882c8aSJames Wright // Evaluate the divergence to/from the quadrature points 313bd882c8aSJames Wright case CEED_EVAL_DIV: 314bd882c8aSJames Wright return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_DIV not supported"); 315bd882c8aSJames Wright // Evaluate the curl to/from the quadrature points 316bd882c8aSJames Wright case CEED_EVAL_CURL: 317bd882c8aSJames Wright return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_CURL not supported"); 318bd882c8aSJames Wright // Take no action, BasisApply should not have been called 319bd882c8aSJames Wright case CEED_EVAL_NONE: 320bd882c8aSJames Wright return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_NONE does not make sense in this context"); 321bd882c8aSJames Wright // LCOV_EXCL_STOP 322bd882c8aSJames Wright } 323bd882c8aSJames Wright 324bd882c8aSJames Wright // Restore vectors 325bd882c8aSJames Wright if (eval_mode != CEED_EVAL_WEIGHT) { 326bd882c8aSJames Wright CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); 327bd882c8aSJames Wright } 328bd882c8aSJames Wright CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); 329bd882c8aSJames Wright return CEED_ERROR_SUCCESS; 330bd882c8aSJames Wright } 331bd882c8aSJames Wright 332bd882c8aSJames Wright //------------------------------------------------------------------------------ 333bd882c8aSJames Wright // Interpolation kernel - non-tensor 334bd882c8aSJames Wright //------------------------------------------------------------------------------ 335bd882c8aSJames Wright static int CeedBasisApplyNonTensorInterp_Sycl(sycl::queue &sycl_queue, CeedInt num_elem, CeedInt transpose, const CeedBasisNonTensor_Sycl *impl, 336bd882c8aSJames Wright const CeedScalar *d_U, CeedScalar *d_V) { 337bd882c8aSJames Wright const CeedInt num_comp = impl->num_comp; 338bd882c8aSJames Wright const CeedInt P = transpose ? impl->num_qpts : impl->num_nodes; 339bd882c8aSJames Wright const CeedInt Q = transpose ? impl->num_nodes : impl->num_qpts; 340bd882c8aSJames Wright const CeedInt stride_0 = transpose ? 1 : impl->num_nodes; 341bd882c8aSJames Wright const CeedInt stride_1 = transpose ? impl->num_nodes : 1; 342bd882c8aSJames Wright const CeedInt u_stride = P; 343bd882c8aSJames Wright const CeedInt v_stride = Q; 344bd882c8aSJames Wright const CeedInt u_comp_stride = u_stride * num_elem; 345bd882c8aSJames Wright const CeedInt v_comp_stride = v_stride * num_elem; 346bd882c8aSJames Wright const CeedInt u_size = P; 347bd882c8aSJames Wright const CeedInt v_size = Q; 348bd882c8aSJames Wright const CeedScalar *d_B = impl->d_interp; 349bd882c8aSJames Wright 350bd882c8aSJames Wright sycl::range<2> kernel_range(num_elem, v_size); 351bd882c8aSJames Wright 352bd882c8aSJames Wright // Order queue 353bd882c8aSJames Wright sycl::event e = sycl_queue.ext_oneapi_submit_barrier(); 354bd882c8aSJames Wright sycl_queue.parallel_for<CeedBasisSyclInterpNT>(kernel_range, {e}, [=](sycl::id<2> indx) { 355bd882c8aSJames Wright const CeedInt i = indx[1]; 356bd882c8aSJames Wright const CeedInt elem = indx[0]; 357bd882c8aSJames Wright 358bd882c8aSJames Wright for (CeedInt comp = 0; comp < num_comp; comp++) { 359bd882c8aSJames Wright const CeedScalar *U = d_U + elem * u_stride + comp * u_comp_stride; 360bd882c8aSJames Wright CeedScalar V = 0.0; 361bd882c8aSJames Wright 362bd882c8aSJames Wright for (CeedInt j = 0; j < u_size; ++j) { 363bd882c8aSJames Wright V += d_B[i * stride_0 + j * stride_1] * U[j]; 364bd882c8aSJames Wright } 365bd882c8aSJames Wright d_V[i + elem * v_stride + comp * v_comp_stride] = V; 366bd882c8aSJames Wright } 367bd882c8aSJames Wright }); 368bd882c8aSJames Wright return CEED_ERROR_SUCCESS; 369bd882c8aSJames Wright } 370bd882c8aSJames Wright 371bd882c8aSJames Wright //------------------------------------------------------------------------------ 372bd882c8aSJames Wright // Gradient kernel - non-tensor 373bd882c8aSJames Wright //------------------------------------------------------------------------------ 374bd882c8aSJames Wright static int CeedBasisApplyNonTensorGrad_Sycl(sycl::queue &sycl_queue, CeedInt num_elem, CeedInt transpose, const CeedBasisNonTensor_Sycl *impl, 375bd882c8aSJames Wright const CeedScalar *d_U, CeedScalar *d_V) { 376bd882c8aSJames Wright const CeedInt num_comp = impl->num_comp; 377bd882c8aSJames Wright const CeedInt P = transpose ? impl->num_qpts : impl->num_nodes; 378bd882c8aSJames Wright const CeedInt Q = transpose ? impl->num_nodes : impl->num_qpts; 379bd882c8aSJames Wright const CeedInt stride_0 = transpose ? 1 : impl->num_nodes; 380bd882c8aSJames Wright const CeedInt stride_1 = transpose ? impl->num_nodes : 1; 381bd882c8aSJames Wright const CeedInt g_dim_stride = P * Q; 382bd882c8aSJames Wright const CeedInt u_stride = P; 383bd882c8aSJames Wright const CeedInt v_stride = Q; 384bd882c8aSJames Wright const CeedInt u_comp_stride = u_stride * num_elem; 385bd882c8aSJames Wright const CeedInt v_comp_stride = v_stride * num_elem; 386bd882c8aSJames Wright const CeedInt u_dim_stride = u_comp_stride * num_comp; 387bd882c8aSJames Wright const CeedInt v_dim_stride = v_comp_stride * num_comp; 388bd882c8aSJames Wright const CeedInt u_size = P; 389bd882c8aSJames Wright const CeedInt v_size = Q; 390bd882c8aSJames Wright const CeedInt in_dim = transpose ? impl->dim : 1; 391bd882c8aSJames Wright const CeedInt out_dim = transpose ? 1 : impl->dim; 392bd882c8aSJames Wright const CeedScalar *d_G = impl->d_grad; 393bd882c8aSJames Wright 394bd882c8aSJames Wright sycl::range<2> kernel_range(num_elem, v_size); 395bd882c8aSJames Wright 396bd882c8aSJames Wright // Order queue 397bd882c8aSJames Wright sycl::event e = sycl_queue.ext_oneapi_submit_barrier(); 398bd882c8aSJames Wright sycl_queue.parallel_for<CeedBasisSyclGradNT>(kernel_range, {e}, [=](sycl::id<2> indx) { 399bd882c8aSJames Wright const CeedInt i = indx[1]; 400bd882c8aSJames Wright const CeedInt elem = indx[0]; 401bd882c8aSJames Wright 402bd882c8aSJames Wright for (CeedInt comp = 0; comp < num_comp; comp++) { 403bd882c8aSJames Wright CeedScalar V[3] = {0.0, 0.0, 0.0}; 404bd882c8aSJames Wright 405bd882c8aSJames Wright for (CeedInt d1 = 0; d1 < in_dim; ++d1) { 406bd882c8aSJames Wright const CeedScalar *U = d_U + elem * u_stride + comp * u_comp_stride + d1 * u_dim_stride; 407bd882c8aSJames Wright const CeedScalar *G = d_G + i * stride_0 + d1 * g_dim_stride; 408bd882c8aSJames Wright 409bd882c8aSJames Wright for (CeedInt j = 0; j < u_size; ++j) { 410bd882c8aSJames Wright const CeedScalar Uj = U[j]; 411bd882c8aSJames Wright 412bd882c8aSJames Wright for (CeedInt d0 = 0; d0 < out_dim; ++d0) { 413bd882c8aSJames Wright V[d0] += G[j * stride_1 + d0 * g_dim_stride] * Uj; 414bd882c8aSJames Wright } 415bd882c8aSJames Wright } 416bd882c8aSJames Wright } 417bd882c8aSJames Wright for (CeedInt d0 = 0; d0 < out_dim; ++d0) { 418bd882c8aSJames Wright d_V[i + elem * v_stride + comp * v_comp_stride + d0 * v_dim_stride] = V[d0]; 419bd882c8aSJames Wright } 420bd882c8aSJames Wright } 421bd882c8aSJames Wright }); 422bd882c8aSJames Wright return CEED_ERROR_SUCCESS; 423bd882c8aSJames Wright } 424bd882c8aSJames Wright 425bd882c8aSJames Wright //------------------------------------------------------------------------------ 426bd882c8aSJames Wright // Weight kernel - non-tensor 427bd882c8aSJames Wright //------------------------------------------------------------------------------ 428bd882c8aSJames Wright static int CeedBasisApplyNonTensorWeight_Sycl(sycl::queue &sycl_queue, CeedInt num_elem, const CeedBasisNonTensor_Sycl *impl, CeedScalar *d_V) { 429bd882c8aSJames Wright const CeedInt num_qpts = impl->num_qpts; 430bd882c8aSJames Wright const CeedScalar *q_weight = impl->d_q_weight; 431bd882c8aSJames Wright 432bd882c8aSJames Wright sycl::range<2> kernel_range(num_elem, num_qpts); 433bd882c8aSJames Wright 434bd882c8aSJames Wright // Order queue 435bd882c8aSJames Wright sycl::event e = sycl_queue.ext_oneapi_submit_barrier(); 436bd882c8aSJames Wright sycl_queue.parallel_for<CeedBasisSyclWeightNT>(kernel_range, {e}, [=](sycl::id<2> indx) { 437bd882c8aSJames Wright const CeedInt i = indx[1]; 438bd882c8aSJames Wright const CeedInt elem = indx[0]; 439bd882c8aSJames Wright d_V[i + elem * num_qpts] = q_weight[i]; 440bd882c8aSJames Wright }); 441bd882c8aSJames Wright return CEED_ERROR_SUCCESS; 442bd882c8aSJames Wright } 443bd882c8aSJames Wright 444bd882c8aSJames Wright //------------------------------------------------------------------------------ 445bd882c8aSJames Wright // Basis apply - non-tensor 446bd882c8aSJames Wright //------------------------------------------------------------------------------ 447bd882c8aSJames Wright static int CeedBasisApplyNonTensor_Sycl(CeedBasis basis, const CeedInt num_elem, CeedTransposeMode t_mode, CeedEvalMode eval_mode, CeedVector u, 448bd882c8aSJames Wright CeedVector v) { 449bd882c8aSJames Wright Ceed ceed; 450bd882c8aSJames Wright CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 451bd882c8aSJames Wright CeedBasisNonTensor_Sycl *impl; 452bd882c8aSJames Wright CeedCallBackend(CeedBasisGetData(basis, &impl)); 453bd882c8aSJames Wright Ceed_Sycl *data; 454bd882c8aSJames Wright CeedCallBackend(CeedGetData(ceed, &data)); 455bd882c8aSJames Wright 456bd882c8aSJames Wright const CeedInt transpose = t_mode == CEED_TRANSPOSE; 457bd882c8aSJames Wright 458bd882c8aSJames Wright // Read vectors 459bd882c8aSJames Wright const CeedScalar *d_u; 460bd882c8aSJames Wright CeedScalar *d_v; 461bd882c8aSJames Wright if (eval_mode != CEED_EVAL_WEIGHT) { 462bd882c8aSJames Wright CeedCallBackend(CeedVectorGetArrayRead(u, CEED_MEM_DEVICE, &d_u)); 463bd882c8aSJames Wright } 464bd882c8aSJames Wright CeedCallBackend(CeedVectorGetArrayWrite(v, CEED_MEM_DEVICE, &d_v)); 465bd882c8aSJames Wright 466bd882c8aSJames Wright // Clear v for transpose operation 467bd882c8aSJames Wright if (transpose) { 468bd882c8aSJames Wright CeedSize length; 469bd882c8aSJames Wright CeedCallBackend(CeedVectorGetLength(v, &length)); 470bd882c8aSJames Wright // Order queue 471bd882c8aSJames Wright sycl::event e = data->sycl_queue.ext_oneapi_submit_barrier(); 472bd882c8aSJames Wright data->sycl_queue.fill<CeedScalar>(d_v, 0, length, {e}); 473bd882c8aSJames Wright } 474bd882c8aSJames Wright 475bd882c8aSJames Wright // Apply basis operation 476bd882c8aSJames Wright switch (eval_mode) { 477bd882c8aSJames Wright case CEED_EVAL_INTERP: { 478bd882c8aSJames Wright CeedCallBackend(CeedBasisApplyNonTensorInterp_Sycl(data->sycl_queue, num_elem, transpose, impl, d_u, d_v)); 479bd882c8aSJames Wright } break; 480bd882c8aSJames Wright case CEED_EVAL_GRAD: { 481bd882c8aSJames Wright CeedCallBackend(CeedBasisApplyNonTensorGrad_Sycl(data->sycl_queue, num_elem, transpose, impl, d_u, d_v)); 482bd882c8aSJames Wright } break; 483bd882c8aSJames Wright case CEED_EVAL_WEIGHT: { 484bd882c8aSJames Wright CeedCallBackend(CeedBasisApplyNonTensorWeight_Sycl(data->sycl_queue, num_elem, impl, d_v)); 485bd882c8aSJames Wright } break; 486bd882c8aSJames Wright // LCOV_EXCL_START 487bd882c8aSJames Wright // Evaluate the divergence to/from the quadrature points 488bd882c8aSJames Wright case CEED_EVAL_DIV: 489bd882c8aSJames Wright return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_DIV not supported"); 490bd882c8aSJames Wright // Evaluate the curl to/from the quadrature points 491bd882c8aSJames Wright case CEED_EVAL_CURL: 492bd882c8aSJames Wright return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_CURL not supported"); 493bd882c8aSJames Wright // Take no action, BasisApply should not have been called 494bd882c8aSJames Wright case CEED_EVAL_NONE: 495bd882c8aSJames Wright return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_NONE does not make sense in this context"); 496bd882c8aSJames Wright // LCOV_EXCL_STOP 497bd882c8aSJames Wright } 498bd882c8aSJames Wright 499bd882c8aSJames Wright // Restore vectors 500bd882c8aSJames Wright if (eval_mode != CEED_EVAL_WEIGHT) { 501bd882c8aSJames Wright CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); 502bd882c8aSJames Wright } 503bd882c8aSJames Wright 504bd882c8aSJames Wright CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); 505bd882c8aSJames Wright return CEED_ERROR_SUCCESS; 506bd882c8aSJames Wright } 507bd882c8aSJames Wright 508bd882c8aSJames Wright //------------------------------------------------------------------------------ 509bd882c8aSJames Wright // Destroy tensor basis 510bd882c8aSJames Wright //------------------------------------------------------------------------------ 511bd882c8aSJames Wright static int CeedBasisDestroy_Sycl(CeedBasis basis) { 512bd882c8aSJames Wright Ceed ceed; 513bd882c8aSJames Wright CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 514bd882c8aSJames Wright CeedBasis_Sycl *impl; 515bd882c8aSJames Wright CeedCallBackend(CeedBasisGetData(basis, &impl)); 516bd882c8aSJames Wright Ceed_Sycl *data; 517bd882c8aSJames Wright CeedCallBackend(CeedGetData(ceed, &data)); 518bd882c8aSJames Wright 519bd882c8aSJames Wright // Wait for all work to finish before freeing memory 520bd882c8aSJames Wright CeedCallSycl(ceed, data->sycl_queue.wait_and_throw()); 521bd882c8aSJames Wright 522bd882c8aSJames Wright CeedCallSycl(ceed, sycl::free(impl->d_q_weight_1d, data->sycl_context)); 523bd882c8aSJames Wright CeedCallSycl(ceed, sycl::free(impl->d_interp_1d, data->sycl_context)); 524bd882c8aSJames Wright CeedCallSycl(ceed, sycl::free(impl->d_grad_1d, data->sycl_context)); 525bd882c8aSJames Wright 526bd882c8aSJames Wright CeedCallBackend(CeedFree(&impl)); 527bd882c8aSJames Wright return CEED_ERROR_SUCCESS; 528bd882c8aSJames Wright } 529bd882c8aSJames Wright 530bd882c8aSJames Wright //------------------------------------------------------------------------------ 531bd882c8aSJames Wright // Destroy non-tensor basis 532bd882c8aSJames Wright //------------------------------------------------------------------------------ 533bd882c8aSJames Wright static int CeedBasisDestroyNonTensor_Sycl(CeedBasis basis) { 534bd882c8aSJames Wright Ceed ceed; 535bd882c8aSJames Wright CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 536bd882c8aSJames Wright CeedBasisNonTensor_Sycl *impl; 537bd882c8aSJames Wright CeedCallBackend(CeedBasisGetData(basis, &impl)); 538bd882c8aSJames Wright Ceed_Sycl *data; 539bd882c8aSJames Wright CeedCallBackend(CeedGetData(ceed, &data)); 540bd882c8aSJames Wright 541bd882c8aSJames Wright // Wait for all work to finish before freeing memory 542bd882c8aSJames Wright CeedCallSycl(ceed, data->sycl_queue.wait_and_throw()); 543bd882c8aSJames Wright 544bd882c8aSJames Wright CeedCallSycl(ceed, sycl::free(impl->d_q_weight, data->sycl_context)); 545bd882c8aSJames Wright CeedCallSycl(ceed, sycl::free(impl->d_interp, data->sycl_context)); 546bd882c8aSJames Wright CeedCallSycl(ceed, sycl::free(impl->d_grad, data->sycl_context)); 547bd882c8aSJames Wright 548bd882c8aSJames Wright CeedCallBackend(CeedFree(&impl)); 549bd882c8aSJames Wright return CEED_ERROR_SUCCESS; 550bd882c8aSJames Wright } 551bd882c8aSJames Wright 552bd882c8aSJames Wright //------------------------------------------------------------------------------ 553bd882c8aSJames Wright // Create tensor 554bd882c8aSJames Wright //------------------------------------------------------------------------------ 555bd882c8aSJames Wright int CeedBasisCreateTensorH1_Sycl(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d, 556bd882c8aSJames Wright const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis) { 557bd882c8aSJames Wright Ceed ceed; 558bd882c8aSJames Wright CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 559bd882c8aSJames Wright CeedBasis_Sycl *impl; 560bd882c8aSJames Wright CeedCallBackend(CeedCalloc(1, &impl)); 561bd882c8aSJames Wright Ceed_Sycl *data; 562bd882c8aSJames Wright CeedCallBackend(CeedGetData(ceed, &data)); 563bd882c8aSJames Wright 564bd882c8aSJames Wright CeedInt num_comp; 565bd882c8aSJames Wright CeedCallBackend(CeedBasisGetNumComponents(basis, &num_comp)); 566bd882c8aSJames Wright 567bd882c8aSJames Wright const CeedInt num_nodes = CeedIntPow(P_1d, dim); 568bd882c8aSJames Wright const CeedInt num_qpts = CeedIntPow(Q_1d, dim); 569bd882c8aSJames Wright 570bd882c8aSJames Wright impl->dim = dim; 571bd882c8aSJames Wright impl->P_1d = P_1d; 572bd882c8aSJames Wright impl->Q_1d = Q_1d; 573bd882c8aSJames Wright impl->num_comp = num_comp; 574bd882c8aSJames Wright impl->num_nodes = num_nodes; 575bd882c8aSJames Wright impl->num_qpts = num_qpts; 576bd882c8aSJames Wright impl->buf_len = num_comp * CeedIntMax(num_nodes, num_qpts); 577bd882c8aSJames Wright impl->op_len = Q_1d * P_1d; 578bd882c8aSJames Wright 579bd882c8aSJames Wright // Order queue 580bd882c8aSJames Wright sycl::event e = data->sycl_queue.ext_oneapi_submit_barrier(); 581bd882c8aSJames Wright 582bd882c8aSJames Wright CeedCallSycl(ceed, impl->d_q_weight_1d = sycl::malloc_device<CeedScalar>(Q_1d, data->sycl_device, data->sycl_context)); 583bd882c8aSJames Wright sycl::event copy_weight = data->sycl_queue.copy<CeedScalar>(q_weight_1d, impl->d_q_weight_1d, Q_1d, {e}); 584bd882c8aSJames Wright 585bd882c8aSJames Wright const CeedInt interp_length = Q_1d * P_1d; 586bd882c8aSJames Wright CeedCallSycl(ceed, impl->d_interp_1d = sycl::malloc_device<CeedScalar>(interp_length, data->sycl_device, data->sycl_context)); 587bd882c8aSJames Wright sycl::event copy_interp = data->sycl_queue.copy<CeedScalar>(interp_1d, impl->d_interp_1d, interp_length, {e}); 588bd882c8aSJames Wright 589bd882c8aSJames Wright CeedCallSycl(ceed, impl->d_grad_1d = sycl::malloc_device<CeedScalar>(interp_length, data->sycl_device, data->sycl_context)); 590bd882c8aSJames Wright sycl::event copy_grad = data->sycl_queue.copy<CeedScalar>(grad_1d, impl->d_grad_1d, interp_length, {e}); 591bd882c8aSJames Wright 592bd882c8aSJames Wright CeedCallSycl(ceed, sycl::event::wait_and_throw({copy_weight, copy_interp, copy_grad})); 593bd882c8aSJames Wright 594bd882c8aSJames Wright std::vector<sycl::kernel_id> kernel_ids = {sycl::get_kernel_id<CeedBasisSyclInterp<1>>(), sycl::get_kernel_id<CeedBasisSyclInterp<0>>(), 595bd882c8aSJames Wright sycl::get_kernel_id<CeedBasisSyclGrad<1>>(), sycl::get_kernel_id<CeedBasisSyclGrad<0>>()}; 596bd882c8aSJames Wright 597bd882c8aSJames Wright sycl::kernel_bundle<sycl::bundle_state::input> input_bundle = sycl::get_kernel_bundle<sycl::bundle_state::input>(data->sycl_context, kernel_ids); 598bd882c8aSJames Wright input_bundle.set_specialization_constant<BASIS_DIM_ID>(dim); 599bd882c8aSJames Wright input_bundle.set_specialization_constant<BASIS_NUM_COMP_ID>(num_comp); 600bd882c8aSJames Wright input_bundle.set_specialization_constant<BASIS_Q_1D_ID>(Q_1d); 601bd882c8aSJames Wright input_bundle.set_specialization_constant<BASIS_P_1D_ID>(P_1d); 602bd882c8aSJames Wright 603bd882c8aSJames Wright CeedCallSycl(ceed, impl->sycl_module = new SyclModule_t(sycl::build(input_bundle))); 604bd882c8aSJames Wright 605bd882c8aSJames Wright CeedCallBackend(CeedBasisSetData(basis, impl)); 606bd882c8aSJames Wright 607bd882c8aSJames Wright // Register backend functions 608bd882c8aSJames Wright CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Basis", basis, "Apply", CeedBasisApply_Sycl)); 609bd882c8aSJames Wright CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Basis", basis, "Destroy", CeedBasisDestroy_Sycl)); 610bd882c8aSJames Wright return CEED_ERROR_SUCCESS; 611bd882c8aSJames Wright } 612bd882c8aSJames Wright 613bd882c8aSJames Wright //------------------------------------------------------------------------------ 614bd882c8aSJames Wright // Create non-tensor 615bd882c8aSJames Wright //------------------------------------------------------------------------------ 616bd882c8aSJames Wright int CeedBasisCreateH1_Sycl(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, const CeedScalar *grad, 617dd64fc84SJeremy L Thompson const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis) { 618bd882c8aSJames Wright Ceed ceed; 619bd882c8aSJames Wright CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 620bd882c8aSJames Wright CeedBasisNonTensor_Sycl *impl; 621bd882c8aSJames Wright CeedCallBackend(CeedCalloc(1, &impl)); 622bd882c8aSJames Wright Ceed_Sycl *data; 623bd882c8aSJames Wright CeedCallBackend(CeedGetData(ceed, &data)); 624bd882c8aSJames Wright 625bd882c8aSJames Wright CeedInt num_comp; 626bd882c8aSJames Wright CeedCallBackend(CeedBasisGetNumComponents(basis, &num_comp)); 627bd882c8aSJames Wright 628bd882c8aSJames Wright impl->dim = dim; 629bd882c8aSJames Wright impl->num_comp = num_comp; 630bd882c8aSJames Wright impl->num_nodes = num_nodes; 631bd882c8aSJames Wright impl->num_qpts = num_qpts; 632bd882c8aSJames Wright 633bd882c8aSJames Wright // Order queue 634bd882c8aSJames Wright sycl::event e = data->sycl_queue.ext_oneapi_submit_barrier(); 635bd882c8aSJames Wright 636bd882c8aSJames Wright CeedCallSycl(ceed, impl->d_q_weight = sycl::malloc_device<CeedScalar>(num_qpts, data->sycl_device, data->sycl_context)); 637bd882c8aSJames Wright sycl::event copy_weight = data->sycl_queue.copy<CeedScalar>(q_weight, impl->d_q_weight, num_qpts, {e}); 638bd882c8aSJames Wright 639bd882c8aSJames Wright const CeedInt interp_length = num_qpts * num_nodes; 640bd882c8aSJames Wright CeedCallSycl(ceed, impl->d_interp = sycl::malloc_device<CeedScalar>(interp_length, data->sycl_device, data->sycl_context)); 641bd882c8aSJames Wright sycl::event copy_interp = data->sycl_queue.copy<CeedScalar>(interp, impl->d_interp, interp_length, {e}); 642bd882c8aSJames Wright 643bd882c8aSJames Wright const CeedInt grad_length = num_qpts * num_nodes * dim; 644bd882c8aSJames Wright CeedCallSycl(ceed, impl->d_grad = sycl::malloc_device<CeedScalar>(grad_length, data->sycl_device, data->sycl_context)); 645bd882c8aSJames Wright sycl::event copy_grad = data->sycl_queue.copy<CeedScalar>(grad, impl->d_grad, grad_length, {e}); 646bd882c8aSJames Wright 647bd882c8aSJames Wright CeedCallSycl(ceed, sycl::event::wait_and_throw({copy_weight, copy_interp, copy_grad})); 648bd882c8aSJames Wright 649bd882c8aSJames Wright CeedCallBackend(CeedBasisSetData(basis, impl)); 650bd882c8aSJames Wright 651bd882c8aSJames Wright // Register backend functions 652bd882c8aSJames Wright CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Basis", basis, "Apply", CeedBasisApplyNonTensor_Sycl)); 653bd882c8aSJames Wright CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Basis", basis, "Destroy", CeedBasisDestroyNonTensor_Sycl)); 654bd882c8aSJames Wright return CEED_ERROR_SUCCESS; 655bd882c8aSJames Wright } 656ff1e7120SSebastian Grimberg 657bd882c8aSJames Wright //------------------------------------------------------------------------------ 658