15aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, 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> 92b730f8bSJeremy L Thompson #include <ceed/backend.h> 102b730f8bSJeremy L Thompson #include <ceed/jit-tools.h> 11c85e8640SSebastian Grimberg #include <assert.h> 120d0321e0SJeremy L Thompson #include <cuda.h> 130d0321e0SJeremy L Thompson #include <cuda_runtime.h> 140d0321e0SJeremy L Thompson #include <stdbool.h> 150d0321e0SJeremy L Thompson #include <string.h> 162b730f8bSJeremy L Thompson 1749aac155SJeremy L Thompson #include "../cuda/ceed-cuda-common.h" 180d0321e0SJeremy L Thompson #include "../cuda/ceed-cuda-compile.h" 192b730f8bSJeremy L Thompson #include "ceed-cuda-ref.h" 200d0321e0SJeremy L Thompson 210d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 220d0321e0SJeremy L Thompson // Destroy operator 230d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 240d0321e0SJeremy L Thompson static int CeedOperatorDestroy_Cuda(CeedOperator op) { 250d0321e0SJeremy L Thompson CeedOperator_Cuda *impl; 26ca735530SJeremy L Thompson 272b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 280d0321e0SJeremy L Thompson 290d0321e0SJeremy L Thompson // Apply data 30*111870feSJeremy L Thompson CeedCallBackend(CeedFree(&impl->num_points)); 313aab95c0SJeremy L Thompson CeedCallBackend(CeedFree(&impl->skip_rstr_in)); 32f8a0df59SJeremy L Thompson CeedCallBackend(CeedFree(&impl->skip_rstr_out)); 33f8a0df59SJeremy L Thompson CeedCallBackend(CeedFree(&impl->apply_add_basis_out)); 34ca735530SJeremy L Thompson for (CeedInt i = 0; i < impl->num_inputs + impl->num_outputs; i++) { 35ca735530SJeremy L Thompson CeedCallBackend(CeedVectorDestroy(&impl->e_vecs[i])); 360d0321e0SJeremy L Thompson } 37ca735530SJeremy L Thompson CeedCallBackend(CeedFree(&impl->e_vecs)); 38c1222711SJeremy L Thompson CeedCallBackend(CeedFree(&impl->input_states)); 390d0321e0SJeremy L Thompson 40ca735530SJeremy L Thompson for (CeedInt i = 0; i < impl->num_inputs; i++) { 41ca735530SJeremy L Thompson CeedCallBackend(CeedVectorDestroy(&impl->q_vecs_in[i])); 420d0321e0SJeremy L Thompson } 43ca735530SJeremy L Thompson CeedCallBackend(CeedFree(&impl->q_vecs_in)); 440d0321e0SJeremy L Thompson 45ca735530SJeremy L Thompson for (CeedInt i = 0; i < impl->num_outputs; i++) { 46ca735530SJeremy L Thompson CeedCallBackend(CeedVectorDestroy(&impl->q_vecs_out[i])); 470d0321e0SJeremy L Thompson } 48ca735530SJeremy L Thompson CeedCallBackend(CeedFree(&impl->q_vecs_out)); 49756ca9e9SJeremy L Thompson CeedCallBackend(CeedVectorDestroy(&impl->point_coords_elem)); 500d0321e0SJeremy L Thompson 510d0321e0SJeremy L Thompson // QFunction assembly data 52ca735530SJeremy L Thompson for (CeedInt i = 0; i < impl->num_active_in; i++) { 53ca735530SJeremy L Thompson CeedCallBackend(CeedVectorDestroy(&impl->qf_active_in[i])); 540d0321e0SJeremy L Thompson } 55ca735530SJeremy L Thompson CeedCallBackend(CeedFree(&impl->qf_active_in)); 560d0321e0SJeremy L Thompson 570d0321e0SJeremy L Thompson // Diag data 580d0321e0SJeremy L Thompson if (impl->diag) { 590d0321e0SJeremy L Thompson Ceed ceed; 60ca735530SJeremy L Thompson 612b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 62cbfe683aSSebastian Grimberg if (impl->diag->module) { 632b730f8bSJeremy L Thompson CeedCallCuda(ceed, cuModuleUnload(impl->diag->module)); 64cbfe683aSSebastian Grimberg } 65cbfe683aSSebastian Grimberg if (impl->diag->module_point_block) { 66cbfe683aSSebastian Grimberg CeedCallCuda(ceed, cuModuleUnload(impl->diag->module_point_block)); 67cbfe683aSSebastian Grimberg } 68004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaFree(impl->diag->d_eval_modes_in)); 69004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaFree(impl->diag->d_eval_modes_out)); 702b730f8bSJeremy L Thompson CeedCallCuda(ceed, cudaFree(impl->diag->d_identity)); 71ca735530SJeremy L Thompson CeedCallCuda(ceed, cudaFree(impl->diag->d_interp_in)); 72ca735530SJeremy L Thompson CeedCallCuda(ceed, cudaFree(impl->diag->d_interp_out)); 73ca735530SJeremy L Thompson CeedCallCuda(ceed, cudaFree(impl->diag->d_grad_in)); 74ca735530SJeremy L Thompson CeedCallCuda(ceed, cudaFree(impl->diag->d_grad_out)); 75004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaFree(impl->diag->d_div_in)); 76004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaFree(impl->diag->d_div_out)); 77004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaFree(impl->diag->d_curl_in)); 78004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaFree(impl->diag->d_curl_out)); 79004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionDestroy(&impl->diag->diag_rstr)); 80506b1a0cSSebastian Grimberg CeedCallBackend(CeedElemRestrictionDestroy(&impl->diag->point_block_diag_rstr)); 81ca735530SJeremy L Thompson CeedCallBackend(CeedVectorDestroy(&impl->diag->elem_diag)); 82ca735530SJeremy L Thompson CeedCallBackend(CeedVectorDestroy(&impl->diag->point_block_elem_diag)); 830d0321e0SJeremy L Thompson } 842b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&impl->diag)); 850d0321e0SJeremy L Thompson 86cc132f9aSnbeams if (impl->asmb) { 87cc132f9aSnbeams Ceed ceed; 88ca735530SJeremy L Thompson 892b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 902b730f8bSJeremy L Thompson CeedCallCuda(ceed, cuModuleUnload(impl->asmb->module)); 912b730f8bSJeremy L Thompson CeedCallCuda(ceed, cudaFree(impl->asmb->d_B_in)); 922b730f8bSJeremy L Thompson CeedCallCuda(ceed, cudaFree(impl->asmb->d_B_out)); 93cc132f9aSnbeams } 942b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&impl->asmb)); 95cc132f9aSnbeams 962b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&impl)); 970d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 980d0321e0SJeremy L Thompson } 990d0321e0SJeremy L Thompson 1000d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 1010d0321e0SJeremy L Thompson // Setup infields or outfields 1020d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 103f8a0df59SJeremy L Thompson static int CeedOperatorSetupFields_Cuda(CeedQFunction qf, CeedOperator op, bool is_input, bool is_at_points, bool *skip_rstr, bool *apply_add_basis, 104f8a0df59SJeremy L Thompson CeedVector *e_vecs, CeedVector *q_vecs, CeedInt start_e, CeedInt num_fields, CeedInt Q, CeedInt num_elem) { 1050d0321e0SJeremy L Thompson Ceed ceed; 106ca735530SJeremy L Thompson CeedQFunctionField *qf_fields; 107ca735530SJeremy L Thompson CeedOperatorField *op_fields; 1080d0321e0SJeremy L Thompson 109ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 110ca735530SJeremy L Thompson if (is_input) { 111ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, NULL, &op_fields, NULL, NULL)); 112ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_fields, NULL, NULL)); 1130d0321e0SJeremy L Thompson } else { 114ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, NULL, NULL, NULL, &op_fields)); 115ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, NULL, NULL, &qf_fields)); 1160d0321e0SJeremy L Thompson } 1170d0321e0SJeremy L Thompson 1180d0321e0SJeremy L Thompson // Loop over fields 119ca735530SJeremy L Thompson for (CeedInt i = 0; i < num_fields; i++) { 120004e4986SSebastian Grimberg bool is_strided = false, skip_restriction = false; 121004e4986SSebastian Grimberg CeedSize q_size; 122004e4986SSebastian Grimberg CeedInt size; 123004e4986SSebastian Grimberg CeedEvalMode eval_mode; 124ca735530SJeremy L Thompson CeedBasis basis; 1250d0321e0SJeremy L Thompson 126004e4986SSebastian Grimberg CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_fields[i], &eval_mode)); 127004e4986SSebastian Grimberg if (eval_mode != CEED_EVAL_WEIGHT) { 128edb2538eSJeremy L Thompson CeedElemRestriction elem_rstr; 129ca735530SJeremy L Thompson 1300d0321e0SJeremy L Thompson // Check whether this field can skip the element restriction: 131004e4986SSebastian Grimberg // Must be passive input, with eval_mode NONE, and have a strided restriction with CEED_STRIDES_BACKEND. 132004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_fields[i], &elem_rstr)); 1330d0321e0SJeremy L Thompson 1340d0321e0SJeremy L Thompson // First, check whether the field is input or output: 135ca735530SJeremy L Thompson if (is_input) { 136ca735530SJeremy L Thompson CeedVector vec; 137ca735530SJeremy L Thompson 138004e4986SSebastian Grimberg // Check for passive input 139ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_fields[i], &vec)); 140ca735530SJeremy L Thompson if (vec != CEED_VECTOR_ACTIVE) { 141004e4986SSebastian Grimberg // Check eval_mode 142004e4986SSebastian Grimberg if (eval_mode == CEED_EVAL_NONE) { 1430d0321e0SJeremy L Thompson // Check for strided restriction 144edb2538eSJeremy L Thompson CeedCallBackend(CeedElemRestrictionIsStrided(elem_rstr, &is_strided)); 145ca735530SJeremy L Thompson if (is_strided) { 1460d0321e0SJeremy L Thompson // Check if vector is already in preferred backend ordering 147edb2538eSJeremy L Thompson CeedCallBackend(CeedElemRestrictionHasBackendStrides(elem_rstr, &skip_restriction)); 1480d0321e0SJeremy L Thompson } 1490d0321e0SJeremy L Thompson } 1500d0321e0SJeremy L Thompson } 1510d0321e0SJeremy L Thompson } 152ca735530SJeremy L Thompson if (skip_restriction) { 153ea61e9acSJeremy L Thompson // We do not need an E-Vector, but will use the input field vector's data directly in the operator application. 154004e4986SSebastian Grimberg e_vecs[i + start_e] = NULL; 1550d0321e0SJeremy L Thompson } else { 156004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionCreateVector(elem_rstr, NULL, &e_vecs[i + start_e])); 1570d0321e0SJeremy L Thompson } 1580d0321e0SJeremy L Thompson } 1590d0321e0SJeremy L Thompson 160004e4986SSebastian Grimberg switch (eval_mode) { 1610d0321e0SJeremy L Thompson case CEED_EVAL_NONE: 162ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetSize(qf_fields[i], &size)); 163ca735530SJeremy L Thompson q_size = (CeedSize)num_elem * Q * size; 164ca735530SJeremy L Thompson CeedCallBackend(CeedVectorCreate(ceed, q_size, &q_vecs[i])); 1650d0321e0SJeremy L Thompson break; 1660d0321e0SJeremy L Thompson case CEED_EVAL_INTERP: 1670d0321e0SJeremy L Thompson case CEED_EVAL_GRAD: 168004e4986SSebastian Grimberg case CEED_EVAL_DIV: 169004e4986SSebastian Grimberg case CEED_EVAL_CURL: 170ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetSize(qf_fields[i], &size)); 171ca735530SJeremy L Thompson q_size = (CeedSize)num_elem * Q * size; 172ca735530SJeremy L Thompson CeedCallBackend(CeedVectorCreate(ceed, q_size, &q_vecs[i])); 1730d0321e0SJeremy L Thompson break; 1740d0321e0SJeremy L Thompson case CEED_EVAL_WEIGHT: // Only on input fields 175ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetBasis(op_fields[i], &basis)); 176ca735530SJeremy L Thompson q_size = (CeedSize)num_elem * Q; 177ca735530SJeremy L Thompson CeedCallBackend(CeedVectorCreate(ceed, q_size, &q_vecs[i])); 178756ca9e9SJeremy L Thompson if (is_at_points) { 179756ca9e9SJeremy L Thompson CeedInt num_points[num_elem]; 180756ca9e9SJeremy L Thompson 181756ca9e9SJeremy L Thompson for (CeedInt i = 0; i < num_elem; i++) num_points[i] = Q; 182756ca9e9SJeremy L Thompson CeedCallBackend( 183756ca9e9SJeremy L Thompson CeedBasisApplyAtPoints(basis, num_elem, num_points, CEED_NOTRANSPOSE, CEED_EVAL_WEIGHT, CEED_VECTOR_NONE, CEED_VECTOR_NONE, q_vecs[i])); 184756ca9e9SJeremy L Thompson } else { 185ca735530SJeremy L Thompson CeedCallBackend(CeedBasisApply(basis, num_elem, CEED_NOTRANSPOSE, CEED_EVAL_WEIGHT, CEED_VECTOR_NONE, q_vecs[i])); 186756ca9e9SJeremy L Thompson } 1870d0321e0SJeremy L Thompson break; 1880d0321e0SJeremy L Thompson } 1890d0321e0SJeremy L Thompson } 190f8a0df59SJeremy L Thompson // Drop duplicate restrictions 1913aab95c0SJeremy L Thompson if (is_input) { 1923aab95c0SJeremy L Thompson for (CeedInt i = 0; i < num_fields; i++) { 1933aab95c0SJeremy L Thompson CeedVector vec_i; 1943aab95c0SJeremy L Thompson CeedElemRestriction rstr_i; 1953aab95c0SJeremy L Thompson 1963aab95c0SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_fields[i], &vec_i)); 1973aab95c0SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_fields[i], &rstr_i)); 1983aab95c0SJeremy L Thompson for (CeedInt j = i + 1; j < num_fields; j++) { 1993aab95c0SJeremy L Thompson CeedVector vec_j; 2003aab95c0SJeremy L Thompson CeedElemRestriction rstr_j; 2013aab95c0SJeremy L Thompson 2023aab95c0SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_fields[j], &vec_j)); 2033aab95c0SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_fields[j], &rstr_j)); 2043aab95c0SJeremy L Thompson if (vec_i == vec_j && rstr_i == rstr_j) { 205f8a0df59SJeremy L Thompson CeedCallBackend(CeedVectorReferenceCopy(e_vecs[i + start_e], &e_vecs[j + start_e])); 2063aab95c0SJeremy L Thompson skip_rstr[j] = true; 2073aab95c0SJeremy L Thompson } 2083aab95c0SJeremy L Thompson } 2093aab95c0SJeremy L Thompson } 210f8a0df59SJeremy L Thompson } else { 211f8a0df59SJeremy L Thompson for (CeedInt i = num_fields - 1; i >= 0; i--) { 212f8a0df59SJeremy L Thompson CeedVector vec_i; 213f8a0df59SJeremy L Thompson CeedElemRestriction rstr_i; 214f8a0df59SJeremy L Thompson 215f8a0df59SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_fields[i], &vec_i)); 216f8a0df59SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_fields[i], &rstr_i)); 217f8a0df59SJeremy L Thompson for (CeedInt j = i - 1; j >= 0; j--) { 218f8a0df59SJeremy L Thompson CeedVector vec_j; 219f8a0df59SJeremy L Thompson CeedElemRestriction rstr_j; 220f8a0df59SJeremy L Thompson 221f8a0df59SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_fields[j], &vec_j)); 222f8a0df59SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_fields[j], &rstr_j)); 223f8a0df59SJeremy L Thompson if (vec_i == vec_j && rstr_i == rstr_j) { 224f8a0df59SJeremy L Thompson CeedCallBackend(CeedVectorReferenceCopy(e_vecs[i + start_e], &e_vecs[j + start_e])); 225f8a0df59SJeremy L Thompson skip_rstr[j] = true; 226f8a0df59SJeremy L Thompson apply_add_basis[i] = true; 227f8a0df59SJeremy L Thompson } 228f8a0df59SJeremy L Thompson } 229f8a0df59SJeremy L Thompson } 2303aab95c0SJeremy L Thompson } 2310d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2320d0321e0SJeremy L Thompson } 2330d0321e0SJeremy L Thompson 2340d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 235ea61e9acSJeremy L Thompson // CeedOperator needs to connect all the named fields (be they active or passive) to the named inputs and outputs of its CeedQFunction. 2360d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 2370d0321e0SJeremy L Thompson static int CeedOperatorSetup_Cuda(CeedOperator op) { 2380d0321e0SJeremy L Thompson Ceed ceed; 239ca735530SJeremy L Thompson bool is_setup_done; 240ca735530SJeremy L Thompson CeedInt Q, num_elem, num_input_fields, num_output_fields; 241ca735530SJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 2420d0321e0SJeremy L Thompson CeedQFunction qf; 243ca735530SJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 244ca735530SJeremy L Thompson CeedOperator_Cuda *impl; 245ca735530SJeremy L Thompson 246ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorIsSetupDone(op, &is_setup_done)); 247ca735530SJeremy L Thompson if (is_setup_done) return CEED_ERROR_SUCCESS; 248ca735530SJeremy L Thompson 249ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 250ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 2512b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); 2522b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetNumQuadraturePoints(op, &Q)); 253ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem)); 254ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 255ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields)); 2560d0321e0SJeremy L Thompson 2570d0321e0SJeremy L Thompson // Allocate 258ca735530SJeremy L Thompson CeedCallBackend(CeedCalloc(num_input_fields + num_output_fields, &impl->e_vecs)); 2593aab95c0SJeremy L Thompson CeedCallBackend(CeedCalloc(CEED_FIELD_MAX, &impl->skip_rstr_in)); 260f8a0df59SJeremy L Thompson CeedCallBackend(CeedCalloc(CEED_FIELD_MAX, &impl->skip_rstr_out)); 261f8a0df59SJeremy L Thompson CeedCallBackend(CeedCalloc(CEED_FIELD_MAX, &impl->apply_add_basis_out)); 262c1222711SJeremy L Thompson CeedCallBackend(CeedCalloc(CEED_FIELD_MAX, &impl->input_states)); 263ca735530SJeremy L Thompson CeedCallBackend(CeedCalloc(CEED_FIELD_MAX, &impl->q_vecs_in)); 264ca735530SJeremy L Thompson CeedCallBackend(CeedCalloc(CEED_FIELD_MAX, &impl->q_vecs_out)); 265ca735530SJeremy L Thompson impl->num_inputs = num_input_fields; 266ca735530SJeremy L Thompson impl->num_outputs = num_output_fields; 2670d0321e0SJeremy L Thompson 26841655a23SJeremy L Thompson // Set up infield and outfield e-vecs and q-vecs 2690d0321e0SJeremy L Thompson // Infields 2703aab95c0SJeremy L Thompson CeedCallBackend( 271f8a0df59SJeremy L Thompson CeedOperatorSetupFields_Cuda(qf, op, true, false, impl->skip_rstr_in, NULL, impl->e_vecs, impl->q_vecs_in, 0, num_input_fields, Q, num_elem)); 2720d0321e0SJeremy L Thompson // Outfields 273f8a0df59SJeremy L Thompson CeedCallBackend(CeedOperatorSetupFields_Cuda(qf, op, false, false, impl->skip_rstr_out, impl->apply_add_basis_out, impl->e_vecs, impl->q_vecs_out, 274f8a0df59SJeremy L Thompson num_input_fields, num_output_fields, Q, num_elem)); 2750d0321e0SJeremy L Thompson 27641655a23SJeremy L Thompson // Reuse active e-vecs where able 27741655a23SJeremy L Thompson { 27841655a23SJeremy L Thompson CeedInt num_used = 0; 27941655a23SJeremy L Thompson CeedElemRestriction *rstr_used = NULL; 28041655a23SJeremy L Thompson 28141655a23SJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 28241655a23SJeremy L Thompson bool is_used = false; 28341655a23SJeremy L Thompson CeedVector vec_i; 28441655a23SJeremy L Thompson CeedElemRestriction rstr_i; 28541655a23SJeremy L Thompson 28641655a23SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec_i)); 28741655a23SJeremy L Thompson if (vec_i != CEED_VECTOR_ACTIVE) continue; 28841655a23SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &rstr_i)); 28941655a23SJeremy L Thompson for (CeedInt j = 0; j < num_used; j++) { 29041655a23SJeremy L Thompson if (rstr_i == rstr_used[i]) is_used = true; 29141655a23SJeremy L Thompson } 29241655a23SJeremy L Thompson if (is_used) continue; 29341655a23SJeremy L Thompson num_used++; 29441655a23SJeremy L Thompson if (num_used == 1) CeedCallBackend(CeedCalloc(num_used, &rstr_used)); 29541655a23SJeremy L Thompson else CeedCallBackend(CeedRealloc(num_used, &rstr_used)); 29641655a23SJeremy L Thompson rstr_used[num_used - 1] = rstr_i; 29741655a23SJeremy L Thompson for (CeedInt j = num_output_fields - 1; j >= 0; j--) { 29841655a23SJeremy L Thompson CeedEvalMode eval_mode; 29941655a23SJeremy L Thompson CeedVector vec_j; 30041655a23SJeremy L Thompson CeedElemRestriction rstr_j; 30141655a23SJeremy L Thompson 30241655a23SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_output_fields[j], &vec_j)); 30341655a23SJeremy L Thompson if (vec_j != CEED_VECTOR_ACTIVE) continue; 30441655a23SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[j], &eval_mode)); 30541655a23SJeremy L Thompson if (eval_mode == CEED_EVAL_NONE) continue; 30641655a23SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_output_fields[j], &rstr_j)); 30741655a23SJeremy L Thompson if (rstr_i == rstr_j) { 30841655a23SJeremy L Thompson CeedCallBackend(CeedVectorReferenceCopy(impl->e_vecs[i], &impl->e_vecs[j + impl->num_inputs])); 30941655a23SJeremy L Thompson } 31041655a23SJeremy L Thompson } 31141655a23SJeremy L Thompson } 31241655a23SJeremy L Thompson CeedCallBackend(CeedFree(&rstr_used)); 31341655a23SJeremy L Thompson } 3148a213570SJeremy L Thompson impl->has_shared_e_vecs = true; 3152b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorSetSetupDone(op)); 3160d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 3170d0321e0SJeremy L Thompson } 3180d0321e0SJeremy L Thompson 3190d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 3200d0321e0SJeremy L Thompson // Setup Operator Inputs 3210d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 322ca735530SJeremy L Thompson static inline int CeedOperatorSetupInputs_Cuda(CeedInt num_input_fields, CeedQFunctionField *qf_input_fields, CeedOperatorField *op_input_fields, 323004e4986SSebastian Grimberg CeedVector in_vec, const bool skip_active, CeedScalar *e_data[2 * CEED_FIELD_MAX], 3240d0321e0SJeremy L Thompson CeedOperator_Cuda *impl, CeedRequest *request) { 325ca735530SJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 326004e4986SSebastian Grimberg CeedEvalMode eval_mode; 3270d0321e0SJeremy L Thompson CeedVector vec; 328edb2538eSJeremy L Thompson CeedElemRestriction elem_rstr; 3290d0321e0SJeremy L Thompson 3300d0321e0SJeremy L Thompson // Get input vector 331ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 3320d0321e0SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 333004e4986SSebastian Grimberg if (skip_active) continue; 334ca735530SJeremy L Thompson else vec = in_vec; 3350d0321e0SJeremy L Thompson } 3360d0321e0SJeremy L Thompson 337004e4986SSebastian Grimberg CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode)); 338004e4986SSebastian Grimberg if (eval_mode == CEED_EVAL_WEIGHT) { // Skip 3390d0321e0SJeremy L Thompson } else { 340004e4986SSebastian Grimberg // Get input vector 341004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 3420d0321e0SJeremy L Thompson // Get input element restriction 343edb2538eSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &elem_rstr)); 344ca735530SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) vec = in_vec; 3450d0321e0SJeremy L Thompson // Restrict, if necessary 346ca735530SJeremy L Thompson if (!impl->e_vecs[i]) { 3470d0321e0SJeremy L Thompson // No restriction for this field; read data directly from vec. 348ca735530SJeremy L Thompson CeedCallBackend(CeedVectorGetArrayRead(vec, CEED_MEM_DEVICE, (const CeedScalar **)&e_data[i])); 3490d0321e0SJeremy L Thompson } else { 350c1222711SJeremy L Thompson uint64_t state; 351c1222711SJeremy L Thompson 352c1222711SJeremy L Thompson CeedCallBackend(CeedVectorGetState(vec, &state)); 35341655a23SJeremy L Thompson if ((state != impl->input_states[i] || vec == in_vec) && !impl->skip_rstr_in[i]) { 354edb2538eSJeremy L Thompson CeedCallBackend(CeedElemRestrictionApply(elem_rstr, CEED_NOTRANSPOSE, vec, impl->e_vecs[i], request)); 355c1222711SJeremy L Thompson } 3563aab95c0SJeremy L Thompson impl->input_states[i] = state; 3570d0321e0SJeremy L Thompson // Get evec 358ca735530SJeremy L Thompson CeedCallBackend(CeedVectorGetArrayRead(impl->e_vecs[i], CEED_MEM_DEVICE, (const CeedScalar **)&e_data[i])); 3590d0321e0SJeremy L Thompson } 3600d0321e0SJeremy L Thompson } 3610d0321e0SJeremy L Thompson } 3620d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 3630d0321e0SJeremy L Thompson } 3640d0321e0SJeremy L Thompson 3650d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 3660d0321e0SJeremy L Thompson // Input Basis Action 3670d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 368ca735530SJeremy L Thompson static inline int CeedOperatorInputBasis_Cuda(CeedInt num_elem, CeedQFunctionField *qf_input_fields, CeedOperatorField *op_input_fields, 369004e4986SSebastian Grimberg CeedInt num_input_fields, const bool skip_active, CeedScalar *e_data[2 * CEED_FIELD_MAX], 3702b730f8bSJeremy L Thompson CeedOperator_Cuda *impl) { 371ca735530SJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 372ca735530SJeremy L Thompson CeedInt elem_size, size; 373004e4986SSebastian Grimberg CeedEvalMode eval_mode; 374edb2538eSJeremy L Thompson CeedElemRestriction elem_rstr; 3750d0321e0SJeremy L Thompson CeedBasis basis; 3760d0321e0SJeremy L Thompson 3770d0321e0SJeremy L Thompson // Skip active input 378004e4986SSebastian Grimberg if (skip_active) { 3790d0321e0SJeremy L Thompson CeedVector vec; 380ca735530SJeremy L Thompson 381ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 3822b730f8bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) continue; 3830d0321e0SJeremy L Thompson } 384004e4986SSebastian Grimberg // Get elem_size, eval_mode, size 385edb2538eSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &elem_rstr)); 386edb2538eSJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetElementSize(elem_rstr, &elem_size)); 387004e4986SSebastian Grimberg CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode)); 388ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetSize(qf_input_fields[i], &size)); 3890d0321e0SJeremy L Thompson // Basis action 390004e4986SSebastian Grimberg switch (eval_mode) { 3910d0321e0SJeremy L Thompson case CEED_EVAL_NONE: 392ca735530SJeremy L Thompson CeedCallBackend(CeedVectorSetArray(impl->q_vecs_in[i], CEED_MEM_DEVICE, CEED_USE_POINTER, e_data[i])); 3930d0321e0SJeremy L Thompson break; 3940d0321e0SJeremy L Thompson case CEED_EVAL_INTERP: 3950d0321e0SJeremy L Thompson case CEED_EVAL_GRAD: 396004e4986SSebastian Grimberg case CEED_EVAL_DIV: 397004e4986SSebastian Grimberg case CEED_EVAL_CURL: 398ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetBasis(op_input_fields[i], &basis)); 399004e4986SSebastian Grimberg CeedCallBackend(CeedBasisApply(basis, num_elem, CEED_NOTRANSPOSE, eval_mode, impl->e_vecs[i], impl->q_vecs_in[i])); 4000d0321e0SJeremy L Thompson break; 4010d0321e0SJeremy L Thompson case CEED_EVAL_WEIGHT: 4020d0321e0SJeremy L Thompson break; // No action 4030d0321e0SJeremy L Thompson } 4040d0321e0SJeremy L Thompson } 4050d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 4060d0321e0SJeremy L Thompson } 4070d0321e0SJeremy L Thompson 4080d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 4090d0321e0SJeremy L Thompson // Restore Input Vectors 4100d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 411ca735530SJeremy L Thompson static inline int CeedOperatorRestoreInputs_Cuda(CeedInt num_input_fields, CeedQFunctionField *qf_input_fields, CeedOperatorField *op_input_fields, 412004e4986SSebastian Grimberg const bool skip_active, CeedScalar *e_data[2 * CEED_FIELD_MAX], CeedOperator_Cuda *impl) { 413ca735530SJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 414004e4986SSebastian Grimberg CeedEvalMode eval_mode; 4150d0321e0SJeremy L Thompson CeedVector vec; 4160d0321e0SJeremy L Thompson 4170d0321e0SJeremy L Thompson // Skip active input 418004e4986SSebastian Grimberg if (skip_active) { 419ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 4202b730f8bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) continue; 4210d0321e0SJeremy L Thompson } 422004e4986SSebastian Grimberg CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode)); 423004e4986SSebastian Grimberg if (eval_mode == CEED_EVAL_WEIGHT) { // Skip 4240d0321e0SJeremy L Thompson } else { 425ca735530SJeremy L Thompson if (!impl->e_vecs[i]) { // This was a skip_restriction case 426ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 427ca735530SJeremy L Thompson CeedCallBackend(CeedVectorRestoreArrayRead(vec, (const CeedScalar **)&e_data[i])); 4280d0321e0SJeremy L Thompson } else { 429ca735530SJeremy L Thompson CeedCallBackend(CeedVectorRestoreArrayRead(impl->e_vecs[i], (const CeedScalar **)&e_data[i])); 4300d0321e0SJeremy L Thompson } 4310d0321e0SJeremy L Thompson } 4320d0321e0SJeremy L Thompson } 4330d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 4340d0321e0SJeremy L Thompson } 4350d0321e0SJeremy L Thompson 4360d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 4370d0321e0SJeremy L Thompson // Apply and add to output 4380d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 439ca735530SJeremy L Thompson static int CeedOperatorApplyAdd_Cuda(CeedOperator op, CeedVector in_vec, CeedVector out_vec, CeedRequest *request) { 440ca735530SJeremy L Thompson CeedInt Q, num_elem, elem_size, num_input_fields, num_output_fields, size; 441ca735530SJeremy L Thompson CeedScalar *e_data[2 * CEED_FIELD_MAX] = {NULL}; 442ca735530SJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 4430d0321e0SJeremy L Thompson CeedQFunction qf; 444004e4986SSebastian Grimberg CeedOperatorField *op_input_fields, *op_output_fields; 445004e4986SSebastian Grimberg CeedOperator_Cuda *impl; 446ca735530SJeremy L Thompson 447ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 4482b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); 4492b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetNumQuadraturePoints(op, &Q)); 450ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem)); 451ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 452ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields)); 4530d0321e0SJeremy L Thompson 4540d0321e0SJeremy L Thompson // Setup 4552b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorSetup_Cuda(op)); 4560d0321e0SJeremy L Thompson 457004e4986SSebastian Grimberg // Input Evecs and Restriction 458ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorSetupInputs_Cuda(num_input_fields, qf_input_fields, op_input_fields, in_vec, false, e_data, impl, request)); 4590d0321e0SJeremy L Thompson 4600d0321e0SJeremy L Thompson // Input basis apply if needed 461ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorInputBasis_Cuda(num_elem, qf_input_fields, op_input_fields, num_input_fields, false, e_data, impl)); 4620d0321e0SJeremy L Thompson 4630d0321e0SJeremy L Thompson // Output pointers, as necessary 464ca735530SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 465004e4986SSebastian Grimberg CeedEvalMode eval_mode; 466004e4986SSebastian Grimberg 467004e4986SSebastian Grimberg CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 468004e4986SSebastian Grimberg if (eval_mode == CEED_EVAL_NONE) { 4690d0321e0SJeremy L Thompson // Set the output Q-Vector to use the E-Vector data directly. 470ca735530SJeremy L Thompson CeedCallBackend(CeedVectorGetArrayWrite(impl->e_vecs[i + impl->num_inputs], CEED_MEM_DEVICE, &e_data[i + num_input_fields])); 471ca735530SJeremy L Thompson CeedCallBackend(CeedVectorSetArray(impl->q_vecs_out[i], CEED_MEM_DEVICE, CEED_USE_POINTER, e_data[i + num_input_fields])); 4720d0321e0SJeremy L Thompson } 4730d0321e0SJeremy L Thompson } 4740d0321e0SJeremy L Thompson 4750d0321e0SJeremy L Thompson // Q function 476ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionApply(qf, num_elem * Q, impl->q_vecs_in, impl->q_vecs_out)); 4770d0321e0SJeremy L Thompson 47841655a23SJeremy L Thompson // Restore input arrays 47941655a23SJeremy L Thompson CeedCallBackend(CeedOperatorRestoreInputs_Cuda(num_input_fields, qf_input_fields, op_input_fields, false, e_data, impl)); 48041655a23SJeremy L Thompson 4810d0321e0SJeremy L Thompson // Output basis apply if needed 482ca735530SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 483004e4986SSebastian Grimberg CeedEvalMode eval_mode; 484edb2538eSJeremy L Thompson CeedElemRestriction elem_rstr; 485ca735530SJeremy L Thompson CeedBasis basis; 486ca735530SJeremy L Thompson 487004e4986SSebastian Grimberg // Get elem_size, eval_mode, size 488edb2538eSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &elem_rstr)); 489edb2538eSJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetElementSize(elem_rstr, &elem_size)); 490004e4986SSebastian Grimberg CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 491ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetSize(qf_output_fields[i], &size)); 4920d0321e0SJeremy L Thompson // Basis action 493004e4986SSebastian Grimberg switch (eval_mode) { 4940d0321e0SJeremy L Thompson case CEED_EVAL_NONE: 495004e4986SSebastian Grimberg break; // No action 4960d0321e0SJeremy L Thompson case CEED_EVAL_INTERP: 4970d0321e0SJeremy L Thompson case CEED_EVAL_GRAD: 498004e4986SSebastian Grimberg case CEED_EVAL_DIV: 499004e4986SSebastian Grimberg case CEED_EVAL_CURL: 500ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetBasis(op_output_fields[i], &basis)); 501f8a0df59SJeremy L Thompson if (impl->apply_add_basis_out[i]) { 502f8a0df59SJeremy L Thompson CeedCallBackend(CeedBasisApplyAdd(basis, num_elem, CEED_TRANSPOSE, eval_mode, impl->q_vecs_out[i], impl->e_vecs[i + impl->num_inputs])); 503f8a0df59SJeremy L Thompson } else { 504004e4986SSebastian Grimberg CeedCallBackend(CeedBasisApply(basis, num_elem, CEED_TRANSPOSE, eval_mode, impl->q_vecs_out[i], impl->e_vecs[i + impl->num_inputs])); 505f8a0df59SJeremy L Thompson } 5060d0321e0SJeremy L Thompson break; 5070d0321e0SJeremy L Thompson // LCOV_EXCL_START 5080d0321e0SJeremy L Thompson case CEED_EVAL_WEIGHT: { 5096e536b99SJeremy L Thompson return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_BACKEND, "CEED_EVAL_WEIGHT cannot be an output evaluation mode"); 5100d0321e0SJeremy L Thompson // LCOV_EXCL_STOP 5110d0321e0SJeremy L Thompson } 5120d0321e0SJeremy L Thompson } 513004e4986SSebastian Grimberg } 5140d0321e0SJeremy L Thompson 5150d0321e0SJeremy L Thompson // Output restriction 516ca735530SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 517004e4986SSebastian Grimberg CeedEvalMode eval_mode; 518ca735530SJeremy L Thompson CeedVector vec; 519edb2538eSJeremy L Thompson CeedElemRestriction elem_rstr; 520ca735530SJeremy L Thompson 5210d0321e0SJeremy L Thompson // Restore evec 522004e4986SSebastian Grimberg CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 523004e4986SSebastian Grimberg if (eval_mode == CEED_EVAL_NONE) { 524ca735530SJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(impl->e_vecs[i + impl->num_inputs], &e_data[i + num_input_fields])); 5250d0321e0SJeremy L Thompson } 526f8a0df59SJeremy L Thompson if (impl->skip_rstr_out[i]) continue; 5270d0321e0SJeremy L Thompson // Get output vector 528ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_output_fields[i], &vec)); 5290d0321e0SJeremy L Thompson // Restrict 530edb2538eSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &elem_rstr)); 5310d0321e0SJeremy L Thompson // Active 532ca735530SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) vec = out_vec; 5330d0321e0SJeremy L Thompson 534edb2538eSJeremy L Thompson CeedCallBackend(CeedElemRestrictionApply(elem_rstr, CEED_TRANSPOSE, impl->e_vecs[i + impl->num_inputs], vec, request)); 5350d0321e0SJeremy L Thompson } 5360d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 5370d0321e0SJeremy L Thompson } 5380d0321e0SJeremy L Thompson 5390d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 540756ca9e9SJeremy L Thompson // CeedOperator needs to connect all the named fields (be they active or passive) to the named inputs and outputs of its CeedQFunction. 541756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 542756ca9e9SJeremy L Thompson static int CeedOperatorSetupAtPoints_Cuda(CeedOperator op) { 543756ca9e9SJeremy L Thompson Ceed ceed; 544756ca9e9SJeremy L Thompson bool is_setup_done; 545756ca9e9SJeremy L Thompson CeedInt max_num_points = -1, num_elem, num_input_fields, num_output_fields; 546756ca9e9SJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 547756ca9e9SJeremy L Thompson CeedQFunction qf; 548756ca9e9SJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 549756ca9e9SJeremy L Thompson CeedOperator_Cuda *impl; 550756ca9e9SJeremy L Thompson 551756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorIsSetupDone(op, &is_setup_done)); 552756ca9e9SJeremy L Thompson if (is_setup_done) return CEED_ERROR_SUCCESS; 553756ca9e9SJeremy L Thompson 554756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 555756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 556756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); 557756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem)); 558756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 559756ca9e9SJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields)); 560756ca9e9SJeremy L Thompson { 561*111870feSJeremy L Thompson CeedElemRestriction rstr_points = NULL; 562756ca9e9SJeremy L Thompson 563*111870feSJeremy L Thompson CeedCallBackend(CeedOperatorAtPointsGetPoints(op, &rstr_points, NULL)); 564*111870feSJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetMaxPointsInElement(rstr_points, &max_num_points)); 565*111870feSJeremy L Thompson CeedCallBackend(CeedCalloc(num_elem, &impl->num_points)); 566*111870feSJeremy L Thompson for (CeedInt e = 0; e < num_elem; e++) { 567*111870feSJeremy L Thompson CeedInt num_points_elem; 568*111870feSJeremy L Thompson 569*111870feSJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetNumPointsInElement(rstr_points, e, &num_points_elem)); 570*111870feSJeremy L Thompson impl->num_points[e] = num_points_elem; 571*111870feSJeremy L Thompson } 572756ca9e9SJeremy L Thompson } 573756ca9e9SJeremy L Thompson impl->max_num_points = max_num_points; 574756ca9e9SJeremy L Thompson 575756ca9e9SJeremy L Thompson // Allocate 576756ca9e9SJeremy L Thompson CeedCallBackend(CeedCalloc(num_input_fields + num_output_fields, &impl->e_vecs)); 5773aab95c0SJeremy L Thompson CeedCallBackend(CeedCalloc(CEED_FIELD_MAX, &impl->skip_rstr_in)); 578f8a0df59SJeremy L Thompson CeedCallBackend(CeedCalloc(CEED_FIELD_MAX, &impl->skip_rstr_out)); 579f8a0df59SJeremy L Thompson CeedCallBackend(CeedCalloc(CEED_FIELD_MAX, &impl->apply_add_basis_out)); 580756ca9e9SJeremy L Thompson CeedCallBackend(CeedCalloc(CEED_FIELD_MAX, &impl->input_states)); 581756ca9e9SJeremy L Thompson CeedCallBackend(CeedCalloc(CEED_FIELD_MAX, &impl->q_vecs_in)); 582756ca9e9SJeremy L Thompson CeedCallBackend(CeedCalloc(CEED_FIELD_MAX, &impl->q_vecs_out)); 583756ca9e9SJeremy L Thompson impl->num_inputs = num_input_fields; 584756ca9e9SJeremy L Thompson impl->num_outputs = num_output_fields; 585756ca9e9SJeremy L Thompson 5868a213570SJeremy L Thompson // Set up infield and outfield e-vecs and q-vecs 587756ca9e9SJeremy L Thompson // Infields 588f8a0df59SJeremy L Thompson CeedCallBackend(CeedOperatorSetupFields_Cuda(qf, op, true, true, impl->skip_rstr_in, NULL, impl->e_vecs, impl->q_vecs_in, 0, num_input_fields, 5893aab95c0SJeremy L Thompson max_num_points, num_elem)); 590756ca9e9SJeremy L Thompson // Outfields 591f8a0df59SJeremy L Thompson CeedCallBackend(CeedOperatorSetupFields_Cuda(qf, op, false, true, impl->skip_rstr_out, impl->apply_add_basis_out, impl->e_vecs, impl->q_vecs_out, 592f8a0df59SJeremy L Thompson num_input_fields, num_output_fields, max_num_points, num_elem)); 593756ca9e9SJeremy L Thompson 5948a213570SJeremy L Thompson // Reuse active e-vecs where able 5958a213570SJeremy L Thompson { 5968a213570SJeremy L Thompson CeedInt num_used = 0; 5978a213570SJeremy L Thompson CeedElemRestriction *rstr_used = NULL; 5988a213570SJeremy L Thompson 5998a213570SJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 6008a213570SJeremy L Thompson bool is_used = false; 6018a213570SJeremy L Thompson CeedVector vec_i; 6028a213570SJeremy L Thompson CeedElemRestriction rstr_i; 6038a213570SJeremy L Thompson 6048a213570SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec_i)); 6058a213570SJeremy L Thompson if (vec_i != CEED_VECTOR_ACTIVE) continue; 6068a213570SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &rstr_i)); 6078a213570SJeremy L Thompson for (CeedInt j = 0; j < num_used; j++) { 6088a213570SJeremy L Thompson if (rstr_i == rstr_used[i]) is_used = true; 6098a213570SJeremy L Thompson } 6108a213570SJeremy L Thompson if (is_used) continue; 6118a213570SJeremy L Thompson num_used++; 6128a213570SJeremy L Thompson if (num_used == 1) CeedCallBackend(CeedCalloc(num_used, &rstr_used)); 6138a213570SJeremy L Thompson else CeedCallBackend(CeedRealloc(num_used, &rstr_used)); 6148a213570SJeremy L Thompson rstr_used[num_used - 1] = rstr_i; 6158a213570SJeremy L Thompson for (CeedInt j = num_output_fields - 1; j >= 0; j--) { 6168a213570SJeremy L Thompson CeedEvalMode eval_mode; 6178a213570SJeremy L Thompson CeedVector vec_j; 6188a213570SJeremy L Thompson CeedElemRestriction rstr_j; 6198a213570SJeremy L Thompson 6208a213570SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_output_fields[j], &vec_j)); 6218a213570SJeremy L Thompson if (vec_j != CEED_VECTOR_ACTIVE) continue; 6228a213570SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[j], &eval_mode)); 6238a213570SJeremy L Thompson if (eval_mode == CEED_EVAL_NONE) continue; 6248a213570SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_output_fields[j], &rstr_j)); 6258a213570SJeremy L Thompson if (rstr_i == rstr_j) { 6268a213570SJeremy L Thompson CeedCallBackend(CeedVectorReferenceCopy(impl->e_vecs[i], &impl->e_vecs[j + impl->num_inputs])); 6278a213570SJeremy L Thompson } 6288a213570SJeremy L Thompson } 6298a213570SJeremy L Thompson } 6308a213570SJeremy L Thompson CeedCallBackend(CeedFree(&rstr_used)); 6318a213570SJeremy L Thompson } 6328a213570SJeremy L Thompson impl->has_shared_e_vecs = true; 633756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorSetSetupDone(op)); 634756ca9e9SJeremy L Thompson return CEED_ERROR_SUCCESS; 635756ca9e9SJeremy L Thompson } 636756ca9e9SJeremy L Thompson 637756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 63867d9480aSJeremy L Thompson // Input Basis Action AtPoints 639756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 640756ca9e9SJeremy L Thompson static inline int CeedOperatorInputBasisAtPoints_Cuda(CeedInt num_elem, const CeedInt *num_points, CeedQFunctionField *qf_input_fields, 641756ca9e9SJeremy L Thompson CeedOperatorField *op_input_fields, CeedInt num_input_fields, const bool skip_active, 642756ca9e9SJeremy L Thompson CeedScalar *e_data[2 * CEED_FIELD_MAX], CeedOperator_Cuda *impl) { 643756ca9e9SJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 644756ca9e9SJeremy L Thompson CeedInt elem_size, size; 645756ca9e9SJeremy L Thompson CeedEvalMode eval_mode; 646756ca9e9SJeremy L Thompson CeedElemRestriction elem_rstr; 647756ca9e9SJeremy L Thompson CeedBasis basis; 648756ca9e9SJeremy L Thompson 649756ca9e9SJeremy L Thompson // Skip active input 650756ca9e9SJeremy L Thompson if (skip_active) { 651756ca9e9SJeremy L Thompson CeedVector vec; 652756ca9e9SJeremy L Thompson 653756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 654756ca9e9SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) continue; 655756ca9e9SJeremy L Thompson } 656756ca9e9SJeremy L Thompson // Get elem_size, eval_mode, size 657756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &elem_rstr)); 658756ca9e9SJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetElementSize(elem_rstr, &elem_size)); 659756ca9e9SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode)); 660756ca9e9SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetSize(qf_input_fields[i], &size)); 661756ca9e9SJeremy L Thompson // Basis action 662756ca9e9SJeremy L Thompson switch (eval_mode) { 663756ca9e9SJeremy L Thompson case CEED_EVAL_NONE: 664756ca9e9SJeremy L Thompson CeedCallBackend(CeedVectorSetArray(impl->q_vecs_in[i], CEED_MEM_DEVICE, CEED_USE_POINTER, e_data[i])); 665756ca9e9SJeremy L Thompson break; 666756ca9e9SJeremy L Thompson case CEED_EVAL_INTERP: 667756ca9e9SJeremy L Thompson case CEED_EVAL_GRAD: 668756ca9e9SJeremy L Thompson case CEED_EVAL_DIV: 669756ca9e9SJeremy L Thompson case CEED_EVAL_CURL: 670756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetBasis(op_input_fields[i], &basis)); 671756ca9e9SJeremy L Thompson CeedCallBackend(CeedBasisApplyAtPoints(basis, num_elem, num_points, CEED_NOTRANSPOSE, eval_mode, impl->point_coords_elem, impl->e_vecs[i], 672756ca9e9SJeremy L Thompson impl->q_vecs_in[i])); 673756ca9e9SJeremy L Thompson break; 674756ca9e9SJeremy L Thompson case CEED_EVAL_WEIGHT: 675756ca9e9SJeremy L Thompson break; // No action 676756ca9e9SJeremy L Thompson } 677756ca9e9SJeremy L Thompson } 678756ca9e9SJeremy L Thompson return CEED_ERROR_SUCCESS; 679756ca9e9SJeremy L Thompson } 680756ca9e9SJeremy L Thompson 681756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 68267d9480aSJeremy L Thompson // Apply and add to output AtPoints 683756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 684756ca9e9SJeremy L Thompson static int CeedOperatorApplyAddAtPoints_Cuda(CeedOperator op, CeedVector in_vec, CeedVector out_vec, CeedRequest *request) { 685*111870feSJeremy L Thompson CeedInt max_num_points, *num_points, num_elem, elem_size, num_input_fields, num_output_fields, size; 686756ca9e9SJeremy L Thompson CeedScalar *e_data[2 * CEED_FIELD_MAX] = {NULL}; 687756ca9e9SJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 688756ca9e9SJeremy L Thompson CeedQFunction qf; 689756ca9e9SJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 690756ca9e9SJeremy L Thompson CeedOperator_Cuda *impl; 691756ca9e9SJeremy L Thompson 692756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 693756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); 694756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem)); 695756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 696756ca9e9SJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields)); 697756ca9e9SJeremy L Thompson 698756ca9e9SJeremy L Thompson // Setup 699756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorSetupAtPoints_Cuda(op)); 700*111870feSJeremy L Thompson num_points = impl->num_points; 701756ca9e9SJeremy L Thompson max_num_points = impl->max_num_points; 702756ca9e9SJeremy L Thompson 703756ca9e9SJeremy L Thompson // Input Evecs and Restriction 704756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorSetupInputs_Cuda(num_input_fields, qf_input_fields, op_input_fields, in_vec, false, e_data, impl, request)); 705756ca9e9SJeremy L Thompson 706756ca9e9SJeremy L Thompson // Get point coordinates 707756ca9e9SJeremy L Thompson if (!impl->point_coords_elem) { 708756ca9e9SJeremy L Thompson CeedVector point_coords = NULL; 709756ca9e9SJeremy L Thompson CeedElemRestriction rstr_points = NULL; 710756ca9e9SJeremy L Thompson 711756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorAtPointsGetPoints(op, &rstr_points, &point_coords)); 712756ca9e9SJeremy L Thompson CeedCallBackend(CeedElemRestrictionCreateVector(rstr_points, NULL, &impl->point_coords_elem)); 713756ca9e9SJeremy L Thompson CeedCallBackend(CeedElemRestrictionApply(rstr_points, CEED_NOTRANSPOSE, point_coords, impl->point_coords_elem, request)); 714756ca9e9SJeremy L Thompson } 715756ca9e9SJeremy L Thompson 716756ca9e9SJeremy L Thompson // Input basis apply if needed 717756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorInputBasisAtPoints_Cuda(num_elem, num_points, qf_input_fields, op_input_fields, num_input_fields, false, e_data, impl)); 718756ca9e9SJeremy L Thompson 719756ca9e9SJeremy L Thompson // Output pointers, as necessary 720756ca9e9SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 721756ca9e9SJeremy L Thompson CeedEvalMode eval_mode; 722756ca9e9SJeremy L Thompson 723756ca9e9SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 724756ca9e9SJeremy L Thompson if (eval_mode == CEED_EVAL_NONE) { 725756ca9e9SJeremy L Thompson // Set the output Q-Vector to use the E-Vector data directly. 726756ca9e9SJeremy L Thompson CeedCallBackend(CeedVectorGetArrayWrite(impl->e_vecs[i + impl->num_inputs], CEED_MEM_DEVICE, &e_data[i + num_input_fields])); 727756ca9e9SJeremy L Thompson CeedCallBackend(CeedVectorSetArray(impl->q_vecs_out[i], CEED_MEM_DEVICE, CEED_USE_POINTER, e_data[i + num_input_fields])); 728756ca9e9SJeremy L Thompson } 729756ca9e9SJeremy L Thompson } 730756ca9e9SJeremy L Thompson 731756ca9e9SJeremy L Thompson // Q function 732756ca9e9SJeremy L Thompson CeedCallBackend(CeedQFunctionApply(qf, num_elem * max_num_points, impl->q_vecs_in, impl->q_vecs_out)); 733756ca9e9SJeremy L Thompson 7348a213570SJeremy L Thompson // Restore input arrays 7358a213570SJeremy L Thompson CeedCallBackend(CeedOperatorRestoreInputs_Cuda(num_input_fields, qf_input_fields, op_input_fields, false, e_data, impl)); 7368a213570SJeremy L Thompson 737756ca9e9SJeremy L Thompson // Output basis apply if needed 738756ca9e9SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 739756ca9e9SJeremy L Thompson CeedEvalMode eval_mode; 740756ca9e9SJeremy L Thompson CeedElemRestriction elem_rstr; 741756ca9e9SJeremy L Thompson CeedBasis basis; 742756ca9e9SJeremy L Thompson 743756ca9e9SJeremy L Thompson // Get elem_size, eval_mode, size 744756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &elem_rstr)); 745756ca9e9SJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetElementSize(elem_rstr, &elem_size)); 746756ca9e9SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 747756ca9e9SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetSize(qf_output_fields[i], &size)); 748756ca9e9SJeremy L Thompson // Basis action 749756ca9e9SJeremy L Thompson switch (eval_mode) { 750756ca9e9SJeremy L Thompson case CEED_EVAL_NONE: 751756ca9e9SJeremy L Thompson break; // No action 752756ca9e9SJeremy L Thompson case CEED_EVAL_INTERP: 753756ca9e9SJeremy L Thompson case CEED_EVAL_GRAD: 754756ca9e9SJeremy L Thompson case CEED_EVAL_DIV: 755756ca9e9SJeremy L Thompson case CEED_EVAL_CURL: 756756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetBasis(op_output_fields[i], &basis)); 757f8a0df59SJeremy L Thompson if (impl->apply_add_basis_out[i]) { 758f8a0df59SJeremy L Thompson CeedCallBackend(CeedBasisApplyAddAtPoints(basis, num_elem, num_points, CEED_TRANSPOSE, eval_mode, impl->point_coords_elem, 759f8a0df59SJeremy L Thompson impl->q_vecs_out[i], impl->e_vecs[i + impl->num_inputs])); 760f8a0df59SJeremy L Thompson } else { 761756ca9e9SJeremy L Thompson CeedCallBackend(CeedBasisApplyAtPoints(basis, num_elem, num_points, CEED_TRANSPOSE, eval_mode, impl->point_coords_elem, impl->q_vecs_out[i], 762756ca9e9SJeremy L Thompson impl->e_vecs[i + impl->num_inputs])); 763f8a0df59SJeremy L Thompson } 764756ca9e9SJeremy L Thompson break; 765756ca9e9SJeremy L Thompson // LCOV_EXCL_START 766756ca9e9SJeremy L Thompson case CEED_EVAL_WEIGHT: { 767756ca9e9SJeremy L Thompson return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_BACKEND, "CEED_EVAL_WEIGHT cannot be an output evaluation mode"); 768756ca9e9SJeremy L Thompson // LCOV_EXCL_STOP 769756ca9e9SJeremy L Thompson } 770756ca9e9SJeremy L Thompson } 771756ca9e9SJeremy L Thompson } 772756ca9e9SJeremy L Thompson 773756ca9e9SJeremy L Thompson // Output restriction 774756ca9e9SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 775756ca9e9SJeremy L Thompson CeedEvalMode eval_mode; 776756ca9e9SJeremy L Thompson CeedVector vec; 777756ca9e9SJeremy L Thompson CeedElemRestriction elem_rstr; 778756ca9e9SJeremy L Thompson 779756ca9e9SJeremy L Thompson // Restore evec 780756ca9e9SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 781756ca9e9SJeremy L Thompson if (eval_mode == CEED_EVAL_NONE) { 782756ca9e9SJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(impl->e_vecs[i + impl->num_inputs], &e_data[i + num_input_fields])); 783756ca9e9SJeremy L Thompson } 784f8a0df59SJeremy L Thompson if (impl->skip_rstr_out[i]) continue; 785756ca9e9SJeremy L Thompson // Get output vector 786756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_output_fields[i], &vec)); 787756ca9e9SJeremy L Thompson // Restrict 788756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &elem_rstr)); 789756ca9e9SJeremy L Thompson // Active 790756ca9e9SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) vec = out_vec; 791756ca9e9SJeremy L Thompson 792756ca9e9SJeremy L Thompson CeedCallBackend(CeedElemRestrictionApply(elem_rstr, CEED_TRANSPOSE, impl->e_vecs[i + impl->num_inputs], vec, request)); 793756ca9e9SJeremy L Thompson } 794756ca9e9SJeremy L Thompson return CEED_ERROR_SUCCESS; 795756ca9e9SJeremy L Thompson } 796756ca9e9SJeremy L Thompson 797756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 798004e4986SSebastian Grimberg // Linear QFunction Assembly Core 7990d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 8002b730f8bSJeremy L Thompson static inline int CeedOperatorLinearAssembleQFunctionCore_Cuda(CeedOperator op, bool build_objects, CeedVector *assembled, CeedElemRestriction *rstr, 8010d0321e0SJeremy L Thompson CeedRequest *request) { 802ca735530SJeremy L Thompson Ceed ceed, ceed_parent; 803ca735530SJeremy L Thompson CeedInt num_active_in, num_active_out, Q, num_elem, num_input_fields, num_output_fields, size; 804ca735530SJeremy L Thompson CeedScalar *assembled_array, *e_data[2 * CEED_FIELD_MAX] = {NULL}; 805ca735530SJeremy L Thompson CeedVector *active_inputs; 806ca735530SJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 807ca735530SJeremy L Thompson CeedQFunction qf; 808ca735530SJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 809ca735530SJeremy L Thompson CeedOperator_Cuda *impl; 810ca735530SJeremy L Thompson 8112b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 812ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetFallbackParentCeed(op, &ceed_parent)); 813e984cf9aSJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 814e984cf9aSJeremy L Thompson CeedCallBackend(CeedOperatorGetNumQuadraturePoints(op, &Q)); 815ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem)); 816e984cf9aSJeremy L Thompson CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); 817ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields)); 818ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 819ca735530SJeremy L Thompson active_inputs = impl->qf_active_in; 820ca735530SJeremy L Thompson num_active_in = impl->num_active_in, num_active_out = impl->num_active_out; 8210d0321e0SJeremy L Thompson 8220d0321e0SJeremy L Thompson // Setup 8232b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorSetup_Cuda(op)); 8240d0321e0SJeremy L Thompson 825004e4986SSebastian Grimberg // Input Evecs and Restriction 826ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorSetupInputs_Cuda(num_input_fields, qf_input_fields, op_input_fields, NULL, true, e_data, impl, request)); 8270d0321e0SJeremy L Thompson 8280d0321e0SJeremy L Thompson // Count number of active input fields 829ca735530SJeremy L Thompson if (!num_active_in) { 830ca735530SJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 831ca735530SJeremy L Thompson CeedScalar *q_vec_array; 832ca735530SJeremy L Thompson CeedVector vec; 833ca735530SJeremy L Thompson 8340d0321e0SJeremy L Thompson // Get input vector 835ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 8360d0321e0SJeremy L Thompson // Check if active input 8370d0321e0SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 838ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetSize(qf_input_fields[i], &size)); 839ca735530SJeremy L Thompson CeedCallBackend(CeedVectorSetValue(impl->q_vecs_in[i], 0.0)); 840ca735530SJeremy L Thompson CeedCallBackend(CeedVectorGetArray(impl->q_vecs_in[i], CEED_MEM_DEVICE, &q_vec_array)); 841ca735530SJeremy L Thompson CeedCallBackend(CeedRealloc(num_active_in + size, &active_inputs)); 8420d0321e0SJeremy L Thompson for (CeedInt field = 0; field < size; field++) { 843004e4986SSebastian Grimberg CeedSize q_size = (CeedSize)Q * num_elem; 844004e4986SSebastian Grimberg 845ca735530SJeremy L Thompson CeedCallBackend(CeedVectorCreate(ceed, q_size, &active_inputs[num_active_in + field])); 846ca735530SJeremy L Thompson CeedCallBackend( 847ca735530SJeremy L Thompson CeedVectorSetArray(active_inputs[num_active_in + field], CEED_MEM_DEVICE, CEED_USE_POINTER, &q_vec_array[field * Q * num_elem])); 8480d0321e0SJeremy L Thompson } 849ca735530SJeremy L Thompson num_active_in += size; 850ca735530SJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(impl->q_vecs_in[i], &q_vec_array)); 8510d0321e0SJeremy L Thompson } 8520d0321e0SJeremy L Thompson } 853ca735530SJeremy L Thompson impl->num_active_in = num_active_in; 854ca735530SJeremy L Thompson impl->qf_active_in = active_inputs; 8550d0321e0SJeremy L Thompson } 8560d0321e0SJeremy L Thompson 8570d0321e0SJeremy L Thompson // Count number of active output fields 858ca735530SJeremy L Thompson if (!num_active_out) { 859ca735530SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 860ca735530SJeremy L Thompson CeedVector vec; 861ca735530SJeremy L Thompson 8620d0321e0SJeremy L Thompson // Get output vector 863ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_output_fields[i], &vec)); 8640d0321e0SJeremy L Thompson // Check if active output 8650d0321e0SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 866ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetSize(qf_output_fields[i], &size)); 867ca735530SJeremy L Thompson num_active_out += size; 8680d0321e0SJeremy L Thompson } 8690d0321e0SJeremy L Thompson } 870ca735530SJeremy L Thompson impl->num_active_out = num_active_out; 8710d0321e0SJeremy L Thompson } 8720d0321e0SJeremy L Thompson 8730d0321e0SJeremy L Thompson // Check sizes 874ca735530SJeremy L Thompson CeedCheck(num_active_in > 0 && num_active_out > 0, ceed, CEED_ERROR_BACKEND, "Cannot assemble QFunction without active inputs and outputs"); 8750d0321e0SJeremy L Thompson 8760d0321e0SJeremy L Thompson // Build objects if needed 8770d0321e0SJeremy L Thompson if (build_objects) { 878004e4986SSebastian Grimberg CeedSize l_size = (CeedSize)num_elem * Q * num_active_in * num_active_out; 879ca735530SJeremy L Thompson CeedInt strides[3] = {1, num_elem * Q, Q}; /* *NOPAD* */ 880004e4986SSebastian Grimberg 881004e4986SSebastian Grimberg // Create output restriction 882ca735530SJeremy L Thompson CeedCallBackend(CeedElemRestrictionCreateStrided(ceed_parent, num_elem, Q, num_active_in * num_active_out, 8830a5597ceSJeremy L Thompson (CeedSize)num_active_in * (CeedSize)num_active_out * (CeedSize)num_elem * (CeedSize)Q, strides, 8840a5597ceSJeremy L Thompson rstr)); 8850d0321e0SJeremy L Thompson // Create assembled vector 886ca735530SJeremy L Thompson CeedCallBackend(CeedVectorCreate(ceed_parent, l_size, assembled)); 8870d0321e0SJeremy L Thompson } 8882b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorSetValue(*assembled, 0.0)); 889ca735530SJeremy L Thompson CeedCallBackend(CeedVectorGetArray(*assembled, CEED_MEM_DEVICE, &assembled_array)); 8900d0321e0SJeremy L Thompson 8910d0321e0SJeremy L Thompson // Input basis apply 892ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorInputBasis_Cuda(num_elem, qf_input_fields, op_input_fields, num_input_fields, true, e_data, impl)); 8930d0321e0SJeremy L Thompson 8940d0321e0SJeremy L Thompson // Assemble QFunction 895ca735530SJeremy L Thompson for (CeedInt in = 0; in < num_active_in; in++) { 8960d0321e0SJeremy L Thompson // Set Inputs 897ca735530SJeremy L Thompson CeedCallBackend(CeedVectorSetValue(active_inputs[in], 1.0)); 898ca735530SJeremy L Thompson if (num_active_in > 1) { 899ca735530SJeremy L Thompson CeedCallBackend(CeedVectorSetValue(active_inputs[(in + num_active_in - 1) % num_active_in], 0.0)); 9000d0321e0SJeremy L Thompson } 9010d0321e0SJeremy L Thompson // Set Outputs 902ca735530SJeremy L Thompson for (CeedInt out = 0; out < num_output_fields; out++) { 903ca735530SJeremy L Thompson CeedVector vec; 904ca735530SJeremy L Thompson 9050d0321e0SJeremy L Thompson // Get output vector 906ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_output_fields[out], &vec)); 9070d0321e0SJeremy L Thompson // Check if active output 9080d0321e0SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 909ca735530SJeremy L Thompson CeedCallBackend(CeedVectorSetArray(impl->q_vecs_out[out], CEED_MEM_DEVICE, CEED_USE_POINTER, assembled_array)); 910ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetSize(qf_output_fields[out], &size)); 911ca735530SJeremy L Thompson assembled_array += size * Q * num_elem; // Advance the pointer by the size of the output 9120d0321e0SJeremy L Thompson } 9130d0321e0SJeremy L Thompson } 9140d0321e0SJeremy L Thompson // Apply QFunction 915ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionApply(qf, Q * num_elem, impl->q_vecs_in, impl->q_vecs_out)); 9160d0321e0SJeremy L Thompson } 9170d0321e0SJeremy L Thompson 9188a213570SJeremy L Thompson // Un-set output q-vecs to prevent accidental overwrite of Assembled 919ca735530SJeremy L Thompson for (CeedInt out = 0; out < num_output_fields; out++) { 920ca735530SJeremy L Thompson CeedVector vec; 921ca735530SJeremy L Thompson 9220d0321e0SJeremy L Thompson // Get output vector 923ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_output_fields[out], &vec)); 9240d0321e0SJeremy L Thompson // Check if active output 9250d0321e0SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 926ca735530SJeremy L Thompson CeedCallBackend(CeedVectorTakeArray(impl->q_vecs_out[out], CEED_MEM_DEVICE, NULL)); 9270d0321e0SJeremy L Thompson } 9280d0321e0SJeremy L Thompson } 9290d0321e0SJeremy L Thompson 9300d0321e0SJeremy L Thompson // Restore input arrays 931ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorRestoreInputs_Cuda(num_input_fields, qf_input_fields, op_input_fields, true, e_data, impl)); 9320d0321e0SJeremy L Thompson 9330d0321e0SJeremy L Thompson // Restore output 934ca735530SJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(*assembled, &assembled_array)); 9350d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 9360d0321e0SJeremy L Thompson } 9370d0321e0SJeremy L Thompson 9380d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 9390d0321e0SJeremy L Thompson // Assemble Linear QFunction 9400d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 9412b730f8bSJeremy L Thompson static int CeedOperatorLinearAssembleQFunction_Cuda(CeedOperator op, CeedVector *assembled, CeedElemRestriction *rstr, CeedRequest *request) { 9422b730f8bSJeremy L Thompson return CeedOperatorLinearAssembleQFunctionCore_Cuda(op, true, assembled, rstr, request); 9430d0321e0SJeremy L Thompson } 9440d0321e0SJeremy L Thompson 9450d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 9460d0321e0SJeremy L Thompson // Update Assembled Linear QFunction 9470d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 9482b730f8bSJeremy L Thompson static int CeedOperatorLinearAssembleQFunctionUpdate_Cuda(CeedOperator op, CeedVector assembled, CeedElemRestriction rstr, CeedRequest *request) { 9492b730f8bSJeremy L Thompson return CeedOperatorLinearAssembleQFunctionCore_Cuda(op, false, &assembled, &rstr, request); 9500d0321e0SJeremy L Thompson } 9510d0321e0SJeremy L Thompson 9520d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 953004e4986SSebastian Grimberg // Assemble Diagonal Setup 9540d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 955cbfe683aSSebastian Grimberg static inline int CeedOperatorAssembleDiagonalSetup_Cuda(CeedOperator op) { 9560d0321e0SJeremy L Thompson Ceed ceed; 957004e4986SSebastian Grimberg CeedInt num_input_fields, num_output_fields, num_eval_modes_in = 0, num_eval_modes_out = 0; 958cbfe683aSSebastian Grimberg CeedInt q_comp, num_nodes, num_qpts; 959004e4986SSebastian Grimberg CeedEvalMode *eval_modes_in = NULL, *eval_modes_out = NULL; 960ca735530SJeremy L Thompson CeedBasis basis_in = NULL, basis_out = NULL; 961ca735530SJeremy L Thompson CeedQFunctionField *qf_fields; 9620d0321e0SJeremy L Thompson CeedQFunction qf; 963ca735530SJeremy L Thompson CeedOperatorField *op_fields; 964ca735530SJeremy L Thompson CeedOperator_Cuda *impl; 965ca735530SJeremy L Thompson 966ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 9672b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); 968ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionGetNumArgs(qf, &num_input_fields, &num_output_fields)); 9690d0321e0SJeremy L Thompson 9700d0321e0SJeremy L Thompson // Determine active input basis 971ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, NULL, &op_fields, NULL, NULL)); 972ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_fields, NULL, NULL)); 973ca735530SJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 9740d0321e0SJeremy L Thompson CeedVector vec; 975ca735530SJeremy L Thompson 976ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_fields[i], &vec)); 9770d0321e0SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 978004e4986SSebastian Grimberg CeedBasis basis; 979004e4986SSebastian Grimberg CeedEvalMode eval_mode; 980ca735530SJeremy L Thompson 981004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorFieldGetBasis(op_fields[i], &basis)); 982004e4986SSebastian Grimberg CeedCheck(!basis_in || basis_in == basis, ceed, CEED_ERROR_BACKEND, 983004e4986SSebastian Grimberg "Backend does not implement operator diagonal assembly with multiple active bases"); 984004e4986SSebastian Grimberg basis_in = basis; 985004e4986SSebastian Grimberg CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_fields[i], &eval_mode)); 986004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis_in, eval_mode, &q_comp)); 987004e4986SSebastian Grimberg if (eval_mode != CEED_EVAL_WEIGHT) { 988004e4986SSebastian Grimberg // q_comp = 1 if CEED_EVAL_NONE, CEED_EVAL_WEIGHT caught by QF assembly 989004e4986SSebastian Grimberg CeedCallBackend(CeedRealloc(num_eval_modes_in + q_comp, &eval_modes_in)); 990004e4986SSebastian Grimberg for (CeedInt d = 0; d < q_comp; d++) eval_modes_in[num_eval_modes_in + d] = eval_mode; 991004e4986SSebastian Grimberg num_eval_modes_in += q_comp; 9920d0321e0SJeremy L Thompson } 9930d0321e0SJeremy L Thompson } 9940d0321e0SJeremy L Thompson } 9950d0321e0SJeremy L Thompson 9960d0321e0SJeremy L Thompson // Determine active output basis 997ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, NULL, NULL, NULL, &op_fields)); 998ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, NULL, NULL, &qf_fields)); 999ca735530SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 10000d0321e0SJeremy L Thompson CeedVector vec; 1001ca735530SJeremy L Thompson 1002ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_fields[i], &vec)); 10030d0321e0SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 1004004e4986SSebastian Grimberg CeedBasis basis; 1005004e4986SSebastian Grimberg CeedEvalMode eval_mode; 1006ca735530SJeremy L Thompson 1007004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorFieldGetBasis(op_fields[i], &basis)); 1008004e4986SSebastian Grimberg CeedCheck(!basis_out || basis_out == basis, ceed, CEED_ERROR_BACKEND, 1009004e4986SSebastian Grimberg "Backend does not implement operator diagonal assembly with multiple active bases"); 1010004e4986SSebastian Grimberg basis_out = basis; 1011004e4986SSebastian Grimberg CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_fields[i], &eval_mode)); 1012004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis_out, eval_mode, &q_comp)); 1013004e4986SSebastian Grimberg if (eval_mode != CEED_EVAL_WEIGHT) { 1014004e4986SSebastian Grimberg // q_comp = 1 if CEED_EVAL_NONE, CEED_EVAL_WEIGHT caught by QF assembly 1015004e4986SSebastian Grimberg CeedCallBackend(CeedRealloc(num_eval_modes_out + q_comp, &eval_modes_out)); 1016004e4986SSebastian Grimberg for (CeedInt d = 0; d < q_comp; d++) eval_modes_out[num_eval_modes_out + d] = eval_mode; 1017004e4986SSebastian Grimberg num_eval_modes_out += q_comp; 10180d0321e0SJeremy L Thompson } 10190d0321e0SJeremy L Thompson } 10200d0321e0SJeremy L Thompson } 10210d0321e0SJeremy L Thompson 10220d0321e0SJeremy L Thompson // Operator data struct 10232b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 10242b730f8bSJeremy L Thompson CeedCallBackend(CeedCalloc(1, &impl->diag)); 10250d0321e0SJeremy L Thompson CeedOperatorDiag_Cuda *diag = impl->diag; 1026ca735530SJeremy L Thompson 1027cbfe683aSSebastian Grimberg // Basis matrices 1028004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumNodes(basis_in, &num_nodes)); 1029004e4986SSebastian Grimberg if (basis_in == CEED_BASIS_NONE) num_qpts = num_nodes; 1030004e4986SSebastian Grimberg else CeedCallBackend(CeedBasisGetNumQuadraturePoints(basis_in, &num_qpts)); 1031004e4986SSebastian Grimberg const CeedInt interp_bytes = num_nodes * num_qpts * sizeof(CeedScalar); 1032004e4986SSebastian Grimberg const CeedInt eval_modes_bytes = sizeof(CeedEvalMode); 1033004e4986SSebastian Grimberg bool has_eval_none = false; 10340d0321e0SJeremy L Thompson 10350d0321e0SJeremy L Thompson // CEED_EVAL_NONE 1036004e4986SSebastian Grimberg for (CeedInt i = 0; i < num_eval_modes_in; i++) has_eval_none = has_eval_none || (eval_modes_in[i] == CEED_EVAL_NONE); 1037004e4986SSebastian Grimberg for (CeedInt i = 0; i < num_eval_modes_out; i++) has_eval_none = has_eval_none || (eval_modes_out[i] == CEED_EVAL_NONE); 1038004e4986SSebastian Grimberg if (has_eval_none) { 10390d0321e0SJeremy L Thompson CeedScalar *identity = NULL; 1040ca735530SJeremy L Thompson 1041004e4986SSebastian Grimberg CeedCallBackend(CeedCalloc(num_nodes * num_qpts, &identity)); 1042ca735530SJeremy L Thompson for (CeedInt i = 0; i < (num_nodes < num_qpts ? num_nodes : num_qpts); i++) identity[i * num_nodes + i] = 1.0; 1043ca735530SJeremy L Thompson CeedCallCuda(ceed, cudaMalloc((void **)&diag->d_identity, interp_bytes)); 1044ca735530SJeremy L Thompson CeedCallCuda(ceed, cudaMemcpy(diag->d_identity, identity, interp_bytes, cudaMemcpyHostToDevice)); 1045004e4986SSebastian Grimberg CeedCallBackend(CeedFree(&identity)); 10460d0321e0SJeremy L Thompson } 10470d0321e0SJeremy L Thompson 1048004e4986SSebastian Grimberg // CEED_EVAL_INTERP, CEED_EVAL_GRAD, CEED_EVAL_DIV, and CEED_EVAL_CURL 1049004e4986SSebastian Grimberg for (CeedInt in = 0; in < 2; in++) { 1050004e4986SSebastian Grimberg CeedFESpace fespace; 1051004e4986SSebastian Grimberg CeedBasis basis = in ? basis_in : basis_out; 10520d0321e0SJeremy L Thompson 1053004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetFESpace(basis, &fespace)); 1054004e4986SSebastian Grimberg switch (fespace) { 1055004e4986SSebastian Grimberg case CEED_FE_SPACE_H1: { 1056004e4986SSebastian Grimberg CeedInt q_comp_interp, q_comp_grad; 1057004e4986SSebastian Grimberg const CeedScalar *interp, *grad; 1058004e4986SSebastian Grimberg CeedScalar *d_interp, *d_grad; 10590d0321e0SJeremy L Thompson 1060004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, CEED_EVAL_INTERP, &q_comp_interp)); 1061004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, CEED_EVAL_GRAD, &q_comp_grad)); 10620d0321e0SJeremy L Thompson 1063004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetInterp(basis, &interp)); 1064004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&d_interp, interp_bytes * q_comp_interp)); 1065004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMemcpy(d_interp, interp, interp_bytes * q_comp_interp, cudaMemcpyHostToDevice)); 1066004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetGrad(basis, &grad)); 1067004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&d_grad, interp_bytes * q_comp_grad)); 1068004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMemcpy(d_grad, grad, interp_bytes * q_comp_grad, cudaMemcpyHostToDevice)); 1069004e4986SSebastian Grimberg if (in) { 1070004e4986SSebastian Grimberg diag->d_interp_in = d_interp; 1071004e4986SSebastian Grimberg diag->d_grad_in = d_grad; 1072004e4986SSebastian Grimberg } else { 1073004e4986SSebastian Grimberg diag->d_interp_out = d_interp; 1074004e4986SSebastian Grimberg diag->d_grad_out = d_grad; 1075004e4986SSebastian Grimberg } 1076004e4986SSebastian Grimberg } break; 1077004e4986SSebastian Grimberg case CEED_FE_SPACE_HDIV: { 1078004e4986SSebastian Grimberg CeedInt q_comp_interp, q_comp_div; 1079004e4986SSebastian Grimberg const CeedScalar *interp, *div; 1080004e4986SSebastian Grimberg CeedScalar *d_interp, *d_div; 1081004e4986SSebastian Grimberg 1082004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, CEED_EVAL_INTERP, &q_comp_interp)); 1083004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, CEED_EVAL_DIV, &q_comp_div)); 1084004e4986SSebastian Grimberg 1085004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetInterp(basis, &interp)); 1086004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&d_interp, interp_bytes * q_comp_interp)); 1087004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMemcpy(d_interp, interp, interp_bytes * q_comp_interp, cudaMemcpyHostToDevice)); 1088004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetDiv(basis, &div)); 1089004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&d_div, interp_bytes * q_comp_div)); 1090004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMemcpy(d_div, div, interp_bytes * q_comp_div, cudaMemcpyHostToDevice)); 1091004e4986SSebastian Grimberg if (in) { 1092004e4986SSebastian Grimberg diag->d_interp_in = d_interp; 1093004e4986SSebastian Grimberg diag->d_div_in = d_div; 1094004e4986SSebastian Grimberg } else { 1095004e4986SSebastian Grimberg diag->d_interp_out = d_interp; 1096004e4986SSebastian Grimberg diag->d_div_out = d_div; 1097004e4986SSebastian Grimberg } 1098004e4986SSebastian Grimberg } break; 1099004e4986SSebastian Grimberg case CEED_FE_SPACE_HCURL: { 1100004e4986SSebastian Grimberg CeedInt q_comp_interp, q_comp_curl; 1101004e4986SSebastian Grimberg const CeedScalar *interp, *curl; 1102004e4986SSebastian Grimberg CeedScalar *d_interp, *d_curl; 1103004e4986SSebastian Grimberg 1104004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, CEED_EVAL_INTERP, &q_comp_interp)); 1105004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, CEED_EVAL_CURL, &q_comp_curl)); 1106004e4986SSebastian Grimberg 1107004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetInterp(basis, &interp)); 1108004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&d_interp, interp_bytes * q_comp_interp)); 1109004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMemcpy(d_interp, interp, interp_bytes * q_comp_interp, cudaMemcpyHostToDevice)); 1110004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetCurl(basis, &curl)); 1111004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&d_curl, interp_bytes * q_comp_curl)); 1112004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMemcpy(d_curl, curl, interp_bytes * q_comp_curl, cudaMemcpyHostToDevice)); 1113004e4986SSebastian Grimberg if (in) { 1114004e4986SSebastian Grimberg diag->d_interp_in = d_interp; 1115004e4986SSebastian Grimberg diag->d_curl_in = d_curl; 1116004e4986SSebastian Grimberg } else { 1117004e4986SSebastian Grimberg diag->d_interp_out = d_interp; 1118004e4986SSebastian Grimberg diag->d_curl_out = d_curl; 1119004e4986SSebastian Grimberg } 1120004e4986SSebastian Grimberg } break; 1121004e4986SSebastian Grimberg } 1122004e4986SSebastian Grimberg } 1123004e4986SSebastian Grimberg 1124004e4986SSebastian Grimberg // Arrays of eval_modes 1125004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&diag->d_eval_modes_in, num_eval_modes_in * eval_modes_bytes)); 1126004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMemcpy(diag->d_eval_modes_in, eval_modes_in, num_eval_modes_in * eval_modes_bytes, cudaMemcpyHostToDevice)); 1127004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&diag->d_eval_modes_out, num_eval_modes_out * eval_modes_bytes)); 1128004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMemcpy(diag->d_eval_modes_out, eval_modes_out, num_eval_modes_out * eval_modes_bytes, cudaMemcpyHostToDevice)); 1129004e4986SSebastian Grimberg CeedCallBackend(CeedFree(&eval_modes_in)); 1130004e4986SSebastian Grimberg CeedCallBackend(CeedFree(&eval_modes_out)); 11310d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 11320d0321e0SJeremy L Thompson } 11330d0321e0SJeremy L Thompson 11340d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 1135cbfe683aSSebastian Grimberg // Assemble Diagonal Setup (Compilation) 1136cbfe683aSSebastian Grimberg //------------------------------------------------------------------------------ 1137cbfe683aSSebastian Grimberg static inline int CeedOperatorAssembleDiagonalSetupCompile_Cuda(CeedOperator op, CeedInt use_ceedsize_idx, const bool is_point_block) { 1138cbfe683aSSebastian Grimberg Ceed ceed; 113922070f95SJeremy L Thompson char *diagonal_kernel_source; 114022070f95SJeremy L Thompson const char *diagonal_kernel_path; 1141cbfe683aSSebastian Grimberg CeedInt num_input_fields, num_output_fields, num_eval_modes_in = 0, num_eval_modes_out = 0; 1142cbfe683aSSebastian Grimberg CeedInt num_comp, q_comp, num_nodes, num_qpts; 1143cbfe683aSSebastian Grimberg CeedBasis basis_in = NULL, basis_out = NULL; 1144cbfe683aSSebastian Grimberg CeedQFunctionField *qf_fields; 1145cbfe683aSSebastian Grimberg CeedQFunction qf; 1146cbfe683aSSebastian Grimberg CeedOperatorField *op_fields; 1147cbfe683aSSebastian Grimberg CeedOperator_Cuda *impl; 1148cbfe683aSSebastian Grimberg 1149cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 1150cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); 1151cbfe683aSSebastian Grimberg CeedCallBackend(CeedQFunctionGetNumArgs(qf, &num_input_fields, &num_output_fields)); 1152cbfe683aSSebastian Grimberg 1153cbfe683aSSebastian Grimberg // Determine active input basis 1154cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorGetFields(op, NULL, &op_fields, NULL, NULL)); 1155cbfe683aSSebastian Grimberg CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_fields, NULL, NULL)); 1156cbfe683aSSebastian Grimberg for (CeedInt i = 0; i < num_input_fields; i++) { 1157cbfe683aSSebastian Grimberg CeedVector vec; 1158cbfe683aSSebastian Grimberg 1159cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorFieldGetVector(op_fields[i], &vec)); 1160cbfe683aSSebastian Grimberg if (vec == CEED_VECTOR_ACTIVE) { 1161cbfe683aSSebastian Grimberg CeedEvalMode eval_mode; 1162cbfe683aSSebastian Grimberg 1163cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorFieldGetBasis(op_fields[i], &basis_in)); 1164cbfe683aSSebastian Grimberg CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_fields[i], &eval_mode)); 1165cbfe683aSSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis_in, eval_mode, &q_comp)); 1166cbfe683aSSebastian Grimberg if (eval_mode != CEED_EVAL_WEIGHT) { 1167cbfe683aSSebastian Grimberg num_eval_modes_in += q_comp; 1168cbfe683aSSebastian Grimberg } 1169cbfe683aSSebastian Grimberg } 1170cbfe683aSSebastian Grimberg } 1171cbfe683aSSebastian Grimberg 1172cbfe683aSSebastian Grimberg // Determine active output basis 1173cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorGetFields(op, NULL, NULL, NULL, &op_fields)); 1174cbfe683aSSebastian Grimberg CeedCallBackend(CeedQFunctionGetFields(qf, NULL, NULL, NULL, &qf_fields)); 1175cbfe683aSSebastian Grimberg for (CeedInt i = 0; i < num_output_fields; i++) { 1176cbfe683aSSebastian Grimberg CeedVector vec; 1177cbfe683aSSebastian Grimberg 1178cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorFieldGetVector(op_fields[i], &vec)); 1179cbfe683aSSebastian Grimberg if (vec == CEED_VECTOR_ACTIVE) { 1180cbfe683aSSebastian Grimberg CeedEvalMode eval_mode; 1181cbfe683aSSebastian Grimberg 1182cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorFieldGetBasis(op_fields[i], &basis_out)); 1183cbfe683aSSebastian Grimberg CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_fields[i], &eval_mode)); 1184cbfe683aSSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis_out, eval_mode, &q_comp)); 1185cbfe683aSSebastian Grimberg if (eval_mode != CEED_EVAL_WEIGHT) { 1186cbfe683aSSebastian Grimberg num_eval_modes_out += q_comp; 1187cbfe683aSSebastian Grimberg } 1188cbfe683aSSebastian Grimberg } 1189cbfe683aSSebastian Grimberg } 1190cbfe683aSSebastian Grimberg 1191cbfe683aSSebastian Grimberg // Operator data struct 1192cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorGetData(op, &impl)); 1193cbfe683aSSebastian Grimberg CeedOperatorDiag_Cuda *diag = impl->diag; 1194cbfe683aSSebastian Grimberg 1195cbfe683aSSebastian Grimberg // Assemble kernel 1196cbfe683aSSebastian Grimberg CUmodule *module = is_point_block ? &diag->module_point_block : &diag->module; 1197cbfe683aSSebastian Grimberg CeedInt elems_per_block = 1; 1198cbfe683aSSebastian Grimberg CeedCallBackend(CeedBasisGetNumNodes(basis_in, &num_nodes)); 1199cbfe683aSSebastian Grimberg CeedCallBackend(CeedBasisGetNumComponents(basis_in, &num_comp)); 1200cbfe683aSSebastian Grimberg if (basis_in == CEED_BASIS_NONE) num_qpts = num_nodes; 1201cbfe683aSSebastian Grimberg else CeedCallBackend(CeedBasisGetNumQuadraturePoints(basis_in, &num_qpts)); 1202cbfe683aSSebastian Grimberg CeedCallBackend(CeedGetJitAbsolutePath(ceed, "ceed/jit-source/cuda/cuda-ref-operator-assemble-diagonal.h", &diagonal_kernel_path)); 1203cbfe683aSSebastian Grimberg CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading Diagonal Assembly Kernel Source -----\n"); 1204cbfe683aSSebastian Grimberg CeedCallBackend(CeedLoadSourceToBuffer(ceed, diagonal_kernel_path, &diagonal_kernel_source)); 1205cbfe683aSSebastian Grimberg CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading Diagonal Assembly Source Complete! -----\n"); 1206cbfe683aSSebastian Grimberg CeedCallCuda(ceed, CeedCompile_Cuda(ceed, diagonal_kernel_source, module, 8, "NUM_EVAL_MODES_IN", num_eval_modes_in, "NUM_EVAL_MODES_OUT", 1207cbfe683aSSebastian Grimberg num_eval_modes_out, "NUM_COMP", num_comp, "NUM_NODES", num_nodes, "NUM_QPTS", num_qpts, "USE_CEEDSIZE", 1208cbfe683aSSebastian Grimberg use_ceedsize_idx, "USE_POINT_BLOCK", is_point_block ? 1 : 0, "BLOCK_SIZE", num_nodes * elems_per_block)); 1209cbfe683aSSebastian Grimberg CeedCallCuda(ceed, CeedGetKernel_Cuda(ceed, *module, "LinearDiagonal", is_point_block ? &diag->LinearPointBlock : &diag->LinearDiagonal)); 1210cbfe683aSSebastian Grimberg CeedCallBackend(CeedFree(&diagonal_kernel_path)); 1211cbfe683aSSebastian Grimberg CeedCallBackend(CeedFree(&diagonal_kernel_source)); 1212cbfe683aSSebastian Grimberg return CEED_ERROR_SUCCESS; 1213cbfe683aSSebastian Grimberg } 1214cbfe683aSSebastian Grimberg 1215cbfe683aSSebastian Grimberg //------------------------------------------------------------------------------ 1216004e4986SSebastian Grimberg // Assemble Diagonal Core 12170d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 1218ca735530SJeremy L Thompson static inline int CeedOperatorAssembleDiagonalCore_Cuda(CeedOperator op, CeedVector assembled, CeedRequest *request, const bool is_point_block) { 12190d0321e0SJeremy L Thompson Ceed ceed; 1220cbfe683aSSebastian Grimberg CeedInt num_elem, num_nodes; 1221ca735530SJeremy L Thompson CeedScalar *elem_diag_array; 1222ca735530SJeremy L Thompson const CeedScalar *assembled_qf_array; 1223004e4986SSebastian Grimberg CeedVector assembled_qf = NULL, elem_diag; 1224004e4986SSebastian Grimberg CeedElemRestriction assembled_rstr = NULL, rstr_in, rstr_out, diag_rstr; 12250d0321e0SJeremy L Thompson CeedOperator_Cuda *impl; 1226ca735530SJeremy L Thompson 1227ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 12282b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 12290d0321e0SJeremy L Thompson 12300d0321e0SJeremy L Thompson // Assemble QFunction 1231004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorLinearAssembleQFunctionBuildOrUpdate(op, &assembled_qf, &assembled_rstr, request)); 1232004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionDestroy(&assembled_rstr)); 1233004e4986SSebastian Grimberg CeedCallBackend(CeedVectorGetArrayRead(assembled_qf, CEED_MEM_DEVICE, &assembled_qf_array)); 12340d0321e0SJeremy L Thompson 1235cbfe683aSSebastian Grimberg // Setup 1236cbfe683aSSebastian Grimberg if (!impl->diag) CeedCallBackend(CeedOperatorAssembleDiagonalSetup_Cuda(op)); 1237cbfe683aSSebastian Grimberg CeedOperatorDiag_Cuda *diag = impl->diag; 1238cbfe683aSSebastian Grimberg 1239cbfe683aSSebastian Grimberg assert(diag != NULL); 1240cbfe683aSSebastian Grimberg 1241cbfe683aSSebastian Grimberg // Assemble kernel if needed 1242cbfe683aSSebastian Grimberg if ((!is_point_block && !diag->LinearDiagonal) || (is_point_block && !diag->LinearPointBlock)) { 1243cbfe683aSSebastian Grimberg CeedSize assembled_length, assembled_qf_length; 1244cbfe683aSSebastian Grimberg CeedInt use_ceedsize_idx = 0; 1245f7c1b517Snbeams CeedCallBackend(CeedVectorGetLength(assembled, &assembled_length)); 1246ca735530SJeremy L Thompson CeedCallBackend(CeedVectorGetLength(assembled_qf, &assembled_qf_length)); 1247ca735530SJeremy L Thompson if ((assembled_length > INT_MAX) || (assembled_qf_length > INT_MAX)) use_ceedsize_idx = 1; 1248f7c1b517Snbeams 1249cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorAssembleDiagonalSetupCompile_Cuda(op, use_ceedsize_idx, is_point_block)); 1250cbfe683aSSebastian Grimberg } 12510d0321e0SJeremy L Thompson 1252004e4986SSebastian Grimberg // Restriction and diagonal vector 1253004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorGetActiveElemRestrictions(op, &rstr_in, &rstr_out)); 1254004e4986SSebastian Grimberg CeedCheck(rstr_in == rstr_out, ceed, CEED_ERROR_BACKEND, 1255004e4986SSebastian Grimberg "Cannot assemble operator diagonal with different input and output active element restrictions"); 1256004e4986SSebastian Grimberg if (!is_point_block && !diag->diag_rstr) { 1257004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionCreateUnsignedCopy(rstr_out, &diag->diag_rstr)); 1258004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionCreateVector(diag->diag_rstr, NULL, &diag->elem_diag)); 1259004e4986SSebastian Grimberg } else if (is_point_block && !diag->point_block_diag_rstr) { 1260004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorCreateActivePointBlockRestriction(rstr_out, &diag->point_block_diag_rstr)); 1261004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionCreateVector(diag->point_block_diag_rstr, NULL, &diag->point_block_elem_diag)); 12620d0321e0SJeremy L Thompson } 1263004e4986SSebastian Grimberg diag_rstr = is_point_block ? diag->point_block_diag_rstr : diag->diag_rstr; 1264004e4986SSebastian Grimberg elem_diag = is_point_block ? diag->point_block_elem_diag : diag->elem_diag; 1265ca735530SJeremy L Thompson CeedCallBackend(CeedVectorSetValue(elem_diag, 0.0)); 12660d0321e0SJeremy L Thompson 126791db28b6SZach Atkins // Only assemble diagonal if the basis has nodes, otherwise inputs are null pointers 1268004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetElementSize(diag_rstr, &num_nodes)); 1269004e4986SSebastian Grimberg if (num_nodes > 0) { 12700d0321e0SJeremy L Thompson // Assemble element operator diagonals 1271ca735530SJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetNumElements(diag_rstr, &num_elem)); 1272004e4986SSebastian Grimberg CeedCallBackend(CeedVectorGetArray(elem_diag, CEED_MEM_DEVICE, &elem_diag_array)); 12730d0321e0SJeremy L Thompson 12740d0321e0SJeremy L Thompson // Compute the diagonal of B^T D B 1275004e4986SSebastian Grimberg CeedInt elems_per_block = 1; 1276004e4986SSebastian Grimberg CeedInt grid = CeedDivUpInt(num_elem, elems_per_block); 1277004e4986SSebastian Grimberg void *args[] = {(void *)&num_elem, &diag->d_identity, &diag->d_interp_in, &diag->d_grad_in, &diag->d_div_in, 1278004e4986SSebastian Grimberg &diag->d_curl_in, &diag->d_interp_out, &diag->d_grad_out, &diag->d_div_out, &diag->d_curl_out, 1279004e4986SSebastian Grimberg &diag->d_eval_modes_in, &diag->d_eval_modes_out, &assembled_qf_array, &elem_diag_array}; 1280004e4986SSebastian Grimberg 1281ca735530SJeremy L Thompson if (is_point_block) { 1282004e4986SSebastian Grimberg CeedCallBackend(CeedRunKernelDim_Cuda(ceed, diag->LinearPointBlock, grid, num_nodes, 1, elems_per_block, args)); 12830d0321e0SJeremy L Thompson } else { 1284004e4986SSebastian Grimberg CeedCallBackend(CeedRunKernelDim_Cuda(ceed, diag->LinearDiagonal, grid, num_nodes, 1, elems_per_block, args)); 12850d0321e0SJeremy L Thompson } 12860d0321e0SJeremy L Thompson 12870d0321e0SJeremy L Thompson // Restore arrays 1288ca735530SJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(elem_diag, &elem_diag_array)); 1289ca735530SJeremy L Thompson CeedCallBackend(CeedVectorRestoreArrayRead(assembled_qf, &assembled_qf_array)); 129091db28b6SZach Atkins } 12910d0321e0SJeremy L Thompson 12920d0321e0SJeremy L Thompson // Assemble local operator diagonal 1293ca735530SJeremy L Thompson CeedCallBackend(CeedElemRestrictionApply(diag_rstr, CEED_TRANSPOSE, elem_diag, assembled, request)); 12940d0321e0SJeremy L Thompson 12950d0321e0SJeremy L Thompson // Cleanup 1296ca735530SJeremy L Thompson CeedCallBackend(CeedVectorDestroy(&assembled_qf)); 12970d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 12980d0321e0SJeremy L Thompson } 12990d0321e0SJeremy L Thompson 13000d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 13010d0321e0SJeremy L Thompson // Assemble Linear Diagonal 13020d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 13032b730f8bSJeremy L Thompson static int CeedOperatorLinearAssembleAddDiagonal_Cuda(CeedOperator op, CeedVector assembled, CeedRequest *request) { 13042b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorAssembleDiagonalCore_Cuda(op, assembled, request, false)); 13056aa95790SJeremy L Thompson return CEED_ERROR_SUCCESS; 13060d0321e0SJeremy L Thompson } 13070d0321e0SJeremy L Thompson 13080d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 13090d0321e0SJeremy L Thompson // Assemble Linear Point Block Diagonal 13100d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 13112b730f8bSJeremy L Thompson static int CeedOperatorLinearAssembleAddPointBlockDiagonal_Cuda(CeedOperator op, CeedVector assembled, CeedRequest *request) { 13122b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorAssembleDiagonalCore_Cuda(op, assembled, request, true)); 13136aa95790SJeremy L Thompson return CEED_ERROR_SUCCESS; 13140d0321e0SJeremy L Thompson } 13150d0321e0SJeremy L Thompson 13160d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 1317004e4986SSebastian Grimberg // Single Operator Assembly Setup 1318cc132f9aSnbeams //------------------------------------------------------------------------------ 1319f7c1b517Snbeams static int CeedSingleOperatorAssembleSetup_Cuda(CeedOperator op, CeedInt use_ceedsize_idx) { 1320cc132f9aSnbeams Ceed ceed; 1321004e4986SSebastian Grimberg Ceed_Cuda *cuda_data; 132222070f95SJeremy L Thompson char *assembly_kernel_source; 132322070f95SJeremy L Thompson const char *assembly_kernel_path; 1324004e4986SSebastian Grimberg CeedInt num_input_fields, num_output_fields, num_eval_modes_in = 0, num_eval_modes_out = 0; 13253b38d1dfSJeremy L Thompson CeedInt elem_size_in, num_qpts_in = 0, num_comp_in, elem_size_out, num_qpts_out, num_comp_out, q_comp; 1326004e4986SSebastian Grimberg CeedEvalMode *eval_modes_in = NULL, *eval_modes_out = NULL; 1327ca735530SJeremy L Thompson CeedElemRestriction rstr_in = NULL, rstr_out = NULL; 1328ca735530SJeremy L Thompson CeedBasis basis_in = NULL, basis_out = NULL; 1329ca735530SJeremy L Thompson CeedQFunctionField *qf_fields; 1330ca735530SJeremy L Thompson CeedQFunction qf; 1331ca735530SJeremy L Thompson CeedOperatorField *input_fields, *output_fields; 1332cc132f9aSnbeams CeedOperator_Cuda *impl; 1333ca735530SJeremy L Thompson 1334ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 13352b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 1336cc132f9aSnbeams 1337cc132f9aSnbeams // Get intput and output fields 13382b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &input_fields, &num_output_fields, &output_fields)); 1339cc132f9aSnbeams 1340cc132f9aSnbeams // Determine active input basis eval mode 13412b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); 13422b730f8bSJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_fields, NULL, NULL)); 1343cc132f9aSnbeams for (CeedInt i = 0; i < num_input_fields; i++) { 1344cc132f9aSnbeams CeedVector vec; 1345ca735530SJeremy L Thompson 13462b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(input_fields[i], &vec)); 1347cc132f9aSnbeams if (vec == CEED_VECTOR_ACTIVE) { 1348004e4986SSebastian Grimberg CeedBasis basis; 1349ca735530SJeremy L Thompson CeedEvalMode eval_mode; 1350ca735530SJeremy L Thompson 1351004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorFieldGetBasis(input_fields[i], &basis)); 1352004e4986SSebastian Grimberg CeedCheck(!basis_in || basis_in == basis, ceed, CEED_ERROR_BACKEND, "Backend does not implement operator assembly with multiple active bases"); 1353004e4986SSebastian Grimberg basis_in = basis; 13542b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(input_fields[i], &rstr_in)); 1355004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetElementSize(rstr_in, &elem_size_in)); 1356004e4986SSebastian Grimberg if (basis_in == CEED_BASIS_NONE) num_qpts_in = elem_size_in; 1357004e4986SSebastian Grimberg else CeedCallBackend(CeedBasisGetNumQuadraturePoints(basis_in, &num_qpts_in)); 13582b730f8bSJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_fields[i], &eval_mode)); 1359004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis_in, eval_mode, &q_comp)); 1360004e4986SSebastian Grimberg if (eval_mode != CEED_EVAL_WEIGHT) { 1361004e4986SSebastian Grimberg // q_comp = 1 if CEED_EVAL_NONE, CEED_EVAL_WEIGHT caught by QF Assembly 1362004e4986SSebastian Grimberg CeedCallBackend(CeedRealloc(num_eval_modes_in + q_comp, &eval_modes_in)); 1363004e4986SSebastian Grimberg for (CeedInt d = 0; d < q_comp; d++) { 1364004e4986SSebastian Grimberg eval_modes_in[num_eval_modes_in + d] = eval_mode; 1365cc132f9aSnbeams } 1366004e4986SSebastian Grimberg num_eval_modes_in += q_comp; 1367cc132f9aSnbeams } 1368cc132f9aSnbeams } 1369cc132f9aSnbeams } 1370cc132f9aSnbeams 1371cc132f9aSnbeams // Determine active output basis; basis_out and rstr_out only used if same as input, TODO 13722b730f8bSJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, NULL, NULL, &qf_fields)); 1373cc132f9aSnbeams for (CeedInt i = 0; i < num_output_fields; i++) { 1374cc132f9aSnbeams CeedVector vec; 1375ca735530SJeremy L Thompson 13762b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(output_fields[i], &vec)); 1377cc132f9aSnbeams if (vec == CEED_VECTOR_ACTIVE) { 1378004e4986SSebastian Grimberg CeedBasis basis; 1379ca735530SJeremy L Thompson CeedEvalMode eval_mode; 1380ca735530SJeremy L Thompson 1381004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorFieldGetBasis(output_fields[i], &basis)); 1382004e4986SSebastian Grimberg CeedCheck(!basis_out || basis_out == basis, ceed, CEED_ERROR_BACKEND, 1383004e4986SSebastian Grimberg "Backend does not implement operator assembly with multiple active bases"); 1384004e4986SSebastian Grimberg basis_out = basis; 13852b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(output_fields[i], &rstr_out)); 1386004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetElementSize(rstr_out, &elem_size_out)); 1387004e4986SSebastian Grimberg if (basis_out == CEED_BASIS_NONE) num_qpts_out = elem_size_out; 1388004e4986SSebastian Grimberg else CeedCallBackend(CeedBasisGetNumQuadraturePoints(basis_out, &num_qpts_out)); 1389004e4986SSebastian Grimberg CeedCheck(num_qpts_in == num_qpts_out, ceed, CEED_ERROR_UNSUPPORTED, 1390004e4986SSebastian Grimberg "Active input and output bases must have the same number of quadrature points"); 13912b730f8bSJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_fields[i], &eval_mode)); 1392004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis_out, eval_mode, &q_comp)); 1393004e4986SSebastian Grimberg if (eval_mode != CEED_EVAL_WEIGHT) { 1394004e4986SSebastian Grimberg // q_comp = 1 if CEED_EVAL_NONE, CEED_EVAL_WEIGHT caught by QF Assembly 1395004e4986SSebastian Grimberg CeedCallBackend(CeedRealloc(num_eval_modes_out + q_comp, &eval_modes_out)); 1396004e4986SSebastian Grimberg for (CeedInt d = 0; d < q_comp; d++) { 1397004e4986SSebastian Grimberg eval_modes_out[num_eval_modes_out + d] = eval_mode; 1398004e4986SSebastian Grimberg } 1399004e4986SSebastian Grimberg num_eval_modes_out += q_comp; 1400cc132f9aSnbeams } 1401cc132f9aSnbeams } 1402cc132f9aSnbeams } 1403004e4986SSebastian Grimberg CeedCheck(num_eval_modes_in > 0 && num_eval_modes_out > 0, ceed, CEED_ERROR_UNSUPPORTED, "Cannot assemble operator without inputs/outputs"); 1404cc132f9aSnbeams 14052b730f8bSJeremy L Thompson CeedCallBackend(CeedCalloc(1, &impl->asmb)); 1406cc132f9aSnbeams CeedOperatorAssemble_Cuda *asmb = impl->asmb; 1407004e4986SSebastian Grimberg asmb->elems_per_block = 1; 1408004e4986SSebastian Grimberg asmb->block_size_x = elem_size_in; 1409004e4986SSebastian Grimberg asmb->block_size_y = elem_size_out; 1410ca735530SJeremy L Thompson 14112b730f8bSJeremy L Thompson CeedCallBackend(CeedGetData(ceed, &cuda_data)); 1412004e4986SSebastian Grimberg bool fallback = asmb->block_size_x * asmb->block_size_y * asmb->elems_per_block > cuda_data->device_prop.maxThreadsPerBlock; 1413004e4986SSebastian Grimberg 1414004e4986SSebastian Grimberg if (fallback) { 1415004e4986SSebastian Grimberg // Use fallback kernel with 1D threadblock 1416004e4986SSebastian Grimberg asmb->block_size_y = 1; 1417004e4986SSebastian Grimberg } 1418004e4986SSebastian Grimberg 1419004e4986SSebastian Grimberg // Compile kernels 1420004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetNumComponents(rstr_in, &num_comp_in)); 1421004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetNumComponents(rstr_out, &num_comp_out)); 14222b730f8bSJeremy L Thompson CeedCallBackend(CeedGetJitAbsolutePath(ceed, "ceed/jit-source/cuda/cuda-ref-operator-assemble.h", &assembly_kernel_path)); 142323d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading Assembly Kernel Source -----\n"); 14242b730f8bSJeremy L Thompson CeedCallBackend(CeedLoadSourceToBuffer(ceed, assembly_kernel_path, &assembly_kernel_source)); 142523d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading Assembly Source Complete! -----\n"); 1426004e4986SSebastian Grimberg CeedCallBackend(CeedCompile_Cuda(ceed, assembly_kernel_source, &asmb->module, 10, "NUM_EVAL_MODES_IN", num_eval_modes_in, "NUM_EVAL_MODES_OUT", 1427004e4986SSebastian Grimberg num_eval_modes_out, "NUM_COMP_IN", num_comp_in, "NUM_COMP_OUT", num_comp_out, "NUM_NODES_IN", elem_size_in, 1428004e4986SSebastian Grimberg "NUM_NODES_OUT", elem_size_out, "NUM_QPTS", num_qpts_in, "BLOCK_SIZE", 1429cbfe683aSSebastian Grimberg asmb->block_size_x * asmb->block_size_y * asmb->elems_per_block, "BLOCK_SIZE_Y", asmb->block_size_y, 1430cbfe683aSSebastian Grimberg "USE_CEEDSIZE", use_ceedsize_idx)); 1431004e4986SSebastian Grimberg CeedCallBackend(CeedGetKernel_Cuda(ceed, asmb->module, "LinearAssemble", &asmb->LinearAssemble)); 14322b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&assembly_kernel_path)); 14332b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&assembly_kernel_source)); 1434cc132f9aSnbeams 1435004e4986SSebastian Grimberg // Load into B_in, in order that they will be used in eval_modes_in 1436004e4986SSebastian Grimberg { 1437004e4986SSebastian Grimberg const CeedInt in_bytes = elem_size_in * num_qpts_in * num_eval_modes_in * sizeof(CeedScalar); 1438004e4986SSebastian Grimberg CeedInt d_in = 0; 1439004e4986SSebastian Grimberg CeedEvalMode eval_modes_in_prev = CEED_EVAL_NONE; 1440004e4986SSebastian Grimberg bool has_eval_none = false; 1441004e4986SSebastian Grimberg CeedScalar *identity = NULL; 1442ca735530SJeremy L Thompson 1443004e4986SSebastian Grimberg for (CeedInt i = 0; i < num_eval_modes_in; i++) { 1444004e4986SSebastian Grimberg has_eval_none = has_eval_none || (eval_modes_in[i] == CEED_EVAL_NONE); 1445004e4986SSebastian Grimberg } 1446004e4986SSebastian Grimberg if (has_eval_none) { 1447004e4986SSebastian Grimberg CeedCallBackend(CeedCalloc(elem_size_in * num_qpts_in, &identity)); 1448004e4986SSebastian Grimberg for (CeedInt i = 0; i < (elem_size_in < num_qpts_in ? elem_size_in : num_qpts_in); i++) identity[i * elem_size_in + i] = 1.0; 1449004e4986SSebastian Grimberg } 1450cc132f9aSnbeams 1451004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&asmb->d_B_in, in_bytes)); 1452004e4986SSebastian Grimberg for (CeedInt i = 0; i < num_eval_modes_in; i++) { 1453004e4986SSebastian Grimberg const CeedScalar *h_B_in; 1454ca735530SJeremy L Thompson 1455004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorGetBasisPointer(basis_in, eval_modes_in[i], identity, &h_B_in)); 1456004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis_in, eval_modes_in[i], &q_comp)); 1457004e4986SSebastian Grimberg if (q_comp > 1) { 1458004e4986SSebastian Grimberg if (i == 0 || eval_modes_in[i] != eval_modes_in_prev) d_in = 0; 1459004e4986SSebastian Grimberg else h_B_in = &h_B_in[(++d_in) * elem_size_in * num_qpts_in]; 1460004e4986SSebastian Grimberg } 1461004e4986SSebastian Grimberg eval_modes_in_prev = eval_modes_in[i]; 1462ca735530SJeremy L Thompson 1463004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMemcpy(&asmb->d_B_in[i * elem_size_in * num_qpts_in], h_B_in, elem_size_in * num_qpts_in * sizeof(CeedScalar), 1464004e4986SSebastian Grimberg cudaMemcpyHostToDevice)); 1465004e4986SSebastian Grimberg } 1466004e4986SSebastian Grimberg 1467004e4986SSebastian Grimberg if (identity) { 1468004e4986SSebastian Grimberg CeedCallBackend(CeedFree(&identity)); 1469cc132f9aSnbeams } 1470cc132f9aSnbeams } 1471cc132f9aSnbeams 1472004e4986SSebastian Grimberg // Load into B_out, in order that they will be used in eval_modes_out 1473004e4986SSebastian Grimberg { 1474004e4986SSebastian Grimberg const CeedInt out_bytes = elem_size_out * num_qpts_out * num_eval_modes_out * sizeof(CeedScalar); 1475004e4986SSebastian Grimberg CeedInt d_out = 0; 1476004e4986SSebastian Grimberg CeedEvalMode eval_modes_out_prev = CEED_EVAL_NONE; 1477004e4986SSebastian Grimberg bool has_eval_none = false; 1478004e4986SSebastian Grimberg CeedScalar *identity = NULL; 1479ca735530SJeremy L Thompson 1480004e4986SSebastian Grimberg for (CeedInt i = 0; i < num_eval_modes_out; i++) { 1481004e4986SSebastian Grimberg has_eval_none = has_eval_none || (eval_modes_out[i] == CEED_EVAL_NONE); 1482004e4986SSebastian Grimberg } 1483004e4986SSebastian Grimberg if (has_eval_none) { 1484004e4986SSebastian Grimberg CeedCallBackend(CeedCalloc(elem_size_out * num_qpts_out, &identity)); 1485004e4986SSebastian Grimberg for (CeedInt i = 0; i < (elem_size_out < num_qpts_out ? elem_size_out : num_qpts_out); i++) identity[i * elem_size_out + i] = 1.0; 1486cc132f9aSnbeams } 1487cc132f9aSnbeams 1488004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&asmb->d_B_out, out_bytes)); 1489004e4986SSebastian Grimberg for (CeedInt i = 0; i < num_eval_modes_out; i++) { 1490004e4986SSebastian Grimberg const CeedScalar *h_B_out; 1491ca735530SJeremy L Thompson 1492004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorGetBasisPointer(basis_out, eval_modes_out[i], identity, &h_B_out)); 1493004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis_out, eval_modes_out[i], &q_comp)); 1494004e4986SSebastian Grimberg if (q_comp > 1) { 1495004e4986SSebastian Grimberg if (i == 0 || eval_modes_out[i] != eval_modes_out_prev) d_out = 0; 1496004e4986SSebastian Grimberg else h_B_out = &h_B_out[(++d_out) * elem_size_out * num_qpts_out]; 1497004e4986SSebastian Grimberg } 1498004e4986SSebastian Grimberg eval_modes_out_prev = eval_modes_out[i]; 1499ca735530SJeremy L Thompson 1500004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMemcpy(&asmb->d_B_out[i * elem_size_out * num_qpts_out], h_B_out, elem_size_out * num_qpts_out * sizeof(CeedScalar), 1501004e4986SSebastian Grimberg cudaMemcpyHostToDevice)); 1502004e4986SSebastian Grimberg } 1503004e4986SSebastian Grimberg 1504004e4986SSebastian Grimberg if (identity) { 1505004e4986SSebastian Grimberg CeedCallBackend(CeedFree(&identity)); 1506cc132f9aSnbeams } 1507cc132f9aSnbeams } 1508cc132f9aSnbeams return CEED_ERROR_SUCCESS; 1509cc132f9aSnbeams } 1510cc132f9aSnbeams 1511cc132f9aSnbeams //------------------------------------------------------------------------------ 1512cefa2673SJeremy L Thompson // Assemble matrix data for COO matrix of assembled operator. 1513cefa2673SJeremy L Thompson // The sparsity pattern is set by CeedOperatorLinearAssembleSymbolic. 1514cefa2673SJeremy L Thompson // 1515ea61e9acSJeremy L Thompson // Note that this (and other assembly routines) currently assume only one active input restriction/basis per operator (could have multiple basis eval 1516cefa2673SJeremy L Thompson // modes). 1517cefa2673SJeremy L Thompson // TODO: allow multiple active input restrictions/basis objects 1518cc132f9aSnbeams //------------------------------------------------------------------------------ 15192b730f8bSJeremy L Thompson static int CeedSingleOperatorAssemble_Cuda(CeedOperator op, CeedInt offset, CeedVector values) { 1520cc132f9aSnbeams Ceed ceed; 1521ca735530SJeremy L Thompson CeedSize values_length = 0, assembled_qf_length = 0; 1522004e4986SSebastian Grimberg CeedInt use_ceedsize_idx = 0, num_elem_in, num_elem_out, elem_size_in, elem_size_out; 1523ca735530SJeremy L Thompson CeedScalar *values_array; 1524004e4986SSebastian Grimberg const CeedScalar *assembled_qf_array; 1525ca735530SJeremy L Thompson CeedVector assembled_qf = NULL; 1526004e4986SSebastian Grimberg CeedElemRestriction assembled_rstr = NULL, rstr_in, rstr_out; 1527004e4986SSebastian Grimberg CeedRestrictionType rstr_type_in, rstr_type_out; 1528004e4986SSebastian Grimberg const bool *orients_in = NULL, *orients_out = NULL; 1529004e4986SSebastian Grimberg const CeedInt8 *curl_orients_in = NULL, *curl_orients_out = NULL; 1530cc132f9aSnbeams CeedOperator_Cuda *impl; 1531ca735530SJeremy L Thompson 1532ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 15332b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 1534cc132f9aSnbeams 1535cc132f9aSnbeams // Assemble QFunction 1536004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorLinearAssembleQFunctionBuildOrUpdate(op, &assembled_qf, &assembled_rstr, CEED_REQUEST_IMMEDIATE)); 1537004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionDestroy(&assembled_rstr)); 1538004e4986SSebastian Grimberg CeedCallBackend(CeedVectorGetArrayRead(assembled_qf, CEED_MEM_DEVICE, &assembled_qf_array)); 1539cc132f9aSnbeams 1540f7c1b517Snbeams CeedCallBackend(CeedVectorGetLength(values, &values_length)); 1541f7c1b517Snbeams CeedCallBackend(CeedVectorGetLength(assembled_qf, &assembled_qf_length)); 1542f7c1b517Snbeams if ((values_length > INT_MAX) || (assembled_qf_length > INT_MAX)) use_ceedsize_idx = 1; 1543004e4986SSebastian Grimberg 1544f7c1b517Snbeams // Setup 1545004e4986SSebastian Grimberg if (!impl->asmb) CeedCallBackend(CeedSingleOperatorAssembleSetup_Cuda(op, use_ceedsize_idx)); 1546004e4986SSebastian Grimberg CeedOperatorAssemble_Cuda *asmb = impl->asmb; 1547004e4986SSebastian Grimberg 1548004e4986SSebastian Grimberg assert(asmb != NULL); 1549004e4986SSebastian Grimberg 1550004e4986SSebastian Grimberg // Assemble element operator 1551004e4986SSebastian Grimberg CeedCallBackend(CeedVectorGetArray(values, CEED_MEM_DEVICE, &values_array)); 1552004e4986SSebastian Grimberg values_array += offset; 1553004e4986SSebastian Grimberg 1554004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorGetActiveElemRestrictions(op, &rstr_in, &rstr_out)); 1555004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetNumElements(rstr_in, &num_elem_in)); 1556004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetElementSize(rstr_in, &elem_size_in)); 1557004e4986SSebastian Grimberg 1558004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetType(rstr_in, &rstr_type_in)); 1559004e4986SSebastian Grimberg if (rstr_type_in == CEED_RESTRICTION_ORIENTED) { 1560004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetOrientations(rstr_in, CEED_MEM_DEVICE, &orients_in)); 1561004e4986SSebastian Grimberg } else if (rstr_type_in == CEED_RESTRICTION_CURL_ORIENTED) { 1562004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetCurlOrientations(rstr_in, CEED_MEM_DEVICE, &curl_orients_in)); 1563004e4986SSebastian Grimberg } 1564004e4986SSebastian Grimberg 1565004e4986SSebastian Grimberg if (rstr_in != rstr_out) { 1566004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetNumElements(rstr_out, &num_elem_out)); 1567004e4986SSebastian Grimberg CeedCheck(num_elem_in == num_elem_out, ceed, CEED_ERROR_UNSUPPORTED, 1568004e4986SSebastian Grimberg "Active input and output operator restrictions must have the same number of elements"); 1569004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetElementSize(rstr_out, &elem_size_out)); 1570004e4986SSebastian Grimberg 1571004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetType(rstr_out, &rstr_type_out)); 1572004e4986SSebastian Grimberg if (rstr_type_out == CEED_RESTRICTION_ORIENTED) { 1573004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetOrientations(rstr_out, CEED_MEM_DEVICE, &orients_out)); 1574004e4986SSebastian Grimberg } else if (rstr_type_out == CEED_RESTRICTION_CURL_ORIENTED) { 1575004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetCurlOrientations(rstr_out, CEED_MEM_DEVICE, &curl_orients_out)); 1576004e4986SSebastian Grimberg } 1577004e4986SSebastian Grimberg } else { 1578004e4986SSebastian Grimberg elem_size_out = elem_size_in; 1579004e4986SSebastian Grimberg orients_out = orients_in; 1580004e4986SSebastian Grimberg curl_orients_out = curl_orients_in; 1581f7c1b517Snbeams } 1582f7c1b517Snbeams 1583cc132f9aSnbeams // Compute B^T D B 1584004e4986SSebastian Grimberg CeedInt shared_mem = 1585004e4986SSebastian Grimberg ((curl_orients_in || curl_orients_out ? elem_size_in * elem_size_out : 0) + (curl_orients_in ? elem_size_in * asmb->block_size_y : 0)) * 1586004e4986SSebastian Grimberg sizeof(CeedScalar); 1587004e4986SSebastian Grimberg CeedInt grid = CeedDivUpInt(num_elem_in, asmb->elems_per_block); 1588004e4986SSebastian Grimberg void *args[] = {(void *)&num_elem_in, &asmb->d_B_in, &asmb->d_B_out, &orients_in, &curl_orients_in, 1589004e4986SSebastian Grimberg &orients_out, &curl_orients_out, &assembled_qf_array, &values_array}; 1590ca735530SJeremy L Thompson 15912b730f8bSJeremy L Thompson CeedCallBackend( 1592004e4986SSebastian Grimberg CeedRunKernelDimShared_Cuda(ceed, asmb->LinearAssemble, grid, asmb->block_size_x, asmb->block_size_y, asmb->elems_per_block, shared_mem, args)); 1593cc132f9aSnbeams 1594cc132f9aSnbeams // Restore arrays 15952b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(values, &values_array)); 1596004e4986SSebastian Grimberg CeedCallBackend(CeedVectorRestoreArrayRead(assembled_qf, &assembled_qf_array)); 1597cc132f9aSnbeams 1598cc132f9aSnbeams // Cleanup 15992b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorDestroy(&assembled_qf)); 1600004e4986SSebastian Grimberg if (rstr_type_in == CEED_RESTRICTION_ORIENTED) { 1601004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionRestoreOrientations(rstr_in, &orients_in)); 1602004e4986SSebastian Grimberg } else if (rstr_type_in == CEED_RESTRICTION_CURL_ORIENTED) { 1603004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionRestoreCurlOrientations(rstr_in, &curl_orients_in)); 1604004e4986SSebastian Grimberg } 1605004e4986SSebastian Grimberg if (rstr_in != rstr_out) { 1606004e4986SSebastian Grimberg if (rstr_type_out == CEED_RESTRICTION_ORIENTED) { 1607004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionRestoreOrientations(rstr_out, &orients_out)); 1608004e4986SSebastian Grimberg } else if (rstr_type_out == CEED_RESTRICTION_CURL_ORIENTED) { 1609004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionRestoreCurlOrientations(rstr_out, &curl_orients_out)); 1610004e4986SSebastian Grimberg } 1611004e4986SSebastian Grimberg } 1612cc132f9aSnbeams return CEED_ERROR_SUCCESS; 1613cc132f9aSnbeams } 1614cc132f9aSnbeams 1615cc132f9aSnbeams //------------------------------------------------------------------------------ 1616756ca9e9SJeremy L Thompson // Assemble Linear QFunction AtPoints 1617756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 1618756ca9e9SJeremy L Thompson static int CeedOperatorLinearAssembleQFunctionAtPoints_Cuda(CeedOperator op, CeedVector *assembled, CeedElemRestriction *rstr, CeedRequest *request) { 1619756ca9e9SJeremy L Thompson return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_BACKEND, "Backend does not implement CeedOperatorLinearAssembleQFunction"); 1620756ca9e9SJeremy L Thompson } 1621756ca9e9SJeremy L Thompson 1622756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 1623756ca9e9SJeremy L Thompson // Assemble Linear Diagonal AtPoints 1624756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 1625756ca9e9SJeremy L Thompson static int CeedOperatorLinearAssembleAddDiagonalAtPoints_Cuda(CeedOperator op, CeedVector assembled, CeedRequest *request) { 1626*111870feSJeremy L Thompson CeedInt max_num_points, *num_points, num_elem, num_input_fields, num_output_fields; 1627349fb27dSJeremy L Thompson CeedScalar *e_data[2 * CEED_FIELD_MAX] = {NULL}; 1628349fb27dSJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 1629349fb27dSJeremy L Thompson CeedQFunction qf; 1630349fb27dSJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 1631349fb27dSJeremy L Thompson CeedOperator_Cuda *impl; 1632349fb27dSJeremy L Thompson 1633349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 1634349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); 1635349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem)); 1636349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 1637349fb27dSJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields)); 1638349fb27dSJeremy L Thompson 1639349fb27dSJeremy L Thompson // Setup 1640349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorSetupAtPoints_Cuda(op)); 1641*111870feSJeremy L Thompson num_points = impl->num_points; 1642349fb27dSJeremy L Thompson max_num_points = impl->max_num_points; 1643349fb27dSJeremy L Thompson 16448a213570SJeremy L Thompson // Create separate output e-vecs 16458a213570SJeremy L Thompson if (impl->has_shared_e_vecs) { 16468a213570SJeremy L Thompson for (CeedInt i = 0; i < impl->num_outputs; i++) { 16478a213570SJeremy L Thompson CeedCallBackend(CeedVectorDestroy(&impl->q_vecs_out[i])); 16488a213570SJeremy L Thompson CeedCallBackend(CeedVectorDestroy(&impl->e_vecs[impl->num_inputs + i])); 16498a213570SJeremy L Thompson } 16508a213570SJeremy L Thompson CeedCallBackend(CeedOperatorSetupFields_Cuda(qf, op, false, true, impl->skip_rstr_out, impl->apply_add_basis_out, impl->e_vecs, impl->q_vecs_out, 16518a213570SJeremy L Thompson num_input_fields, num_output_fields, max_num_points, num_elem)); 16528a213570SJeremy L Thompson } 16538a213570SJeremy L Thompson impl->has_shared_e_vecs = false; 16548a213570SJeremy L Thompson 1655349fb27dSJeremy L Thompson // Input Evecs and Restriction 1656349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorSetupInputs_Cuda(num_input_fields, qf_input_fields, op_input_fields, NULL, true, e_data, impl, request)); 1657349fb27dSJeremy L Thompson 1658349fb27dSJeremy L Thompson // Get point coordinates 1659349fb27dSJeremy L Thompson if (!impl->point_coords_elem) { 1660349fb27dSJeremy L Thompson CeedVector point_coords = NULL; 1661349fb27dSJeremy L Thompson CeedElemRestriction rstr_points = NULL; 1662349fb27dSJeremy L Thompson 1663349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorAtPointsGetPoints(op, &rstr_points, &point_coords)); 1664349fb27dSJeremy L Thompson CeedCallBackend(CeedElemRestrictionCreateVector(rstr_points, NULL, &impl->point_coords_elem)); 1665349fb27dSJeremy L Thompson CeedCallBackend(CeedElemRestrictionApply(rstr_points, CEED_NOTRANSPOSE, point_coords, impl->point_coords_elem, request)); 1666349fb27dSJeremy L Thompson } 1667349fb27dSJeremy L Thompson 1668382e9c83SJeremy L Thompson // Clear active input Qvecs 1669382e9c83SJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 1670382e9c83SJeremy L Thompson CeedVector vec; 1671382e9c83SJeremy L Thompson 1672382e9c83SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 1673382e9c83SJeremy L Thompson if (vec != CEED_VECTOR_ACTIVE) continue; 1674382e9c83SJeremy L Thompson CeedCallBackend(CeedVectorSetValue(impl->q_vecs_in[i], 0.0)); 1675382e9c83SJeremy L Thompson } 1676382e9c83SJeremy L Thompson 1677349fb27dSJeremy L Thompson // Input basis apply if needed 1678349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorInputBasisAtPoints_Cuda(num_elem, num_points, qf_input_fields, op_input_fields, num_input_fields, true, e_data, impl)); 1679349fb27dSJeremy L Thompson 1680349fb27dSJeremy L Thompson // Output pointers, as necessary 1681349fb27dSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 1682349fb27dSJeremy L Thompson CeedEvalMode eval_mode; 1683349fb27dSJeremy L Thompson 1684349fb27dSJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 1685349fb27dSJeremy L Thompson if (eval_mode == CEED_EVAL_NONE) { 1686349fb27dSJeremy L Thompson // Set the output Q-Vector to use the E-Vector data directly. 1687349fb27dSJeremy L Thompson CeedCallBackend(CeedVectorGetArrayWrite(impl->e_vecs[i + impl->num_inputs], CEED_MEM_DEVICE, &e_data[i + num_input_fields])); 1688349fb27dSJeremy L Thompson CeedCallBackend(CeedVectorSetArray(impl->q_vecs_out[i], CEED_MEM_DEVICE, CEED_USE_POINTER, e_data[i + num_input_fields])); 1689349fb27dSJeremy L Thompson } 1690349fb27dSJeremy L Thompson } 1691349fb27dSJeremy L Thompson 1692349fb27dSJeremy L Thompson // Loop over active fields 1693349fb27dSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 1694382e9c83SJeremy L Thompson bool is_active_at_points = true; 1695382e9c83SJeremy L Thompson CeedInt elem_size = 1, num_comp_active = 1, e_vec_size = 0; 1696382e9c83SJeremy L Thompson CeedRestrictionType rstr_type; 1697382e9c83SJeremy L Thompson CeedVector vec; 1698382e9c83SJeremy L Thompson CeedElemRestriction elem_rstr; 1699382e9c83SJeremy L Thompson 1700382e9c83SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 1701382e9c83SJeremy L Thompson // -- Skip non-active input 1702382e9c83SJeremy L Thompson if (vec != CEED_VECTOR_ACTIVE) continue; 1703382e9c83SJeremy L Thompson 1704382e9c83SJeremy L Thompson // -- Get active restriction type 1705382e9c83SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &elem_rstr)); 1706382e9c83SJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetType(elem_rstr, &rstr_type)); 1707382e9c83SJeremy L Thompson is_active_at_points = rstr_type == CEED_RESTRICTION_POINTS; 1708382e9c83SJeremy L Thompson if (!is_active_at_points) CeedCallBackend(CeedElemRestrictionGetElementSize(elem_rstr, &elem_size)); 1709382e9c83SJeremy L Thompson else elem_size = max_num_points; 1710382e9c83SJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetNumComponents(elem_rstr, &num_comp_active)); 1711382e9c83SJeremy L Thompson 1712382e9c83SJeremy L Thompson e_vec_size = elem_size * num_comp_active; 1713382e9c83SJeremy L Thompson for (CeedInt s = 0; s < e_vec_size; s++) { 1714349fb27dSJeremy L Thompson bool is_active_input = false; 1715349fb27dSJeremy L Thompson CeedEvalMode eval_mode; 1716349fb27dSJeremy L Thompson CeedVector vec; 1717349fb27dSJeremy L Thompson CeedBasis basis; 1718349fb27dSJeremy L Thompson 1719349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 1720349fb27dSJeremy L Thompson // Skip non-active input 1721349fb27dSJeremy L Thompson is_active_input = vec == CEED_VECTOR_ACTIVE; 1722349fb27dSJeremy L Thompson if (!is_active_input) continue; 1723349fb27dSJeremy L Thompson 1724349fb27dSJeremy L Thompson // Update unit vector 172513062808SJeremy L Thompson if (s == 0) CeedCallBackend(CeedVectorSetValue(impl->e_vecs[i], 0.0)); 1726349fb27dSJeremy L Thompson else CeedCallBackend(CeedVectorSetValueStrided(impl->e_vecs[i], s - 1, e_vec_size, 0.0)); 1727349fb27dSJeremy L Thompson CeedCallBackend(CeedVectorSetValueStrided(impl->e_vecs[i], s, e_vec_size, 1.0)); 1728349fb27dSJeremy L Thompson 1729349fb27dSJeremy L Thompson // Basis action 1730349fb27dSJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode)); 1731349fb27dSJeremy L Thompson switch (eval_mode) { 1732349fb27dSJeremy L Thompson case CEED_EVAL_NONE: 1733349fb27dSJeremy L Thompson CeedCallBackend(CeedVectorSetArray(impl->q_vecs_in[i], CEED_MEM_DEVICE, CEED_USE_POINTER, e_data[i])); 1734349fb27dSJeremy L Thompson break; 1735349fb27dSJeremy L Thompson case CEED_EVAL_INTERP: 1736349fb27dSJeremy L Thompson case CEED_EVAL_GRAD: 1737349fb27dSJeremy L Thompson case CEED_EVAL_DIV: 1738349fb27dSJeremy L Thompson case CEED_EVAL_CURL: 1739349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetBasis(op_input_fields[i], &basis)); 1740349fb27dSJeremy L Thompson CeedCallBackend(CeedBasisApplyAtPoints(basis, num_elem, num_points, CEED_NOTRANSPOSE, eval_mode, impl->point_coords_elem, impl->e_vecs[i], 1741349fb27dSJeremy L Thompson impl->q_vecs_in[i])); 1742349fb27dSJeremy L Thompson break; 1743349fb27dSJeremy L Thompson case CEED_EVAL_WEIGHT: 1744349fb27dSJeremy L Thompson break; // No action 1745349fb27dSJeremy L Thompson } 1746349fb27dSJeremy L Thompson 1747349fb27dSJeremy L Thompson // Q function 1748349fb27dSJeremy L Thompson CeedCallBackend(CeedQFunctionApply(qf, num_elem * max_num_points, impl->q_vecs_in, impl->q_vecs_out)); 1749349fb27dSJeremy L Thompson 1750349fb27dSJeremy L Thompson // Output basis apply if needed 1751382e9c83SJeremy L Thompson for (CeedInt j = 0; j < num_output_fields; j++) { 1752349fb27dSJeremy L Thompson bool is_active_output = false; 1753382e9c83SJeremy L Thompson CeedInt elem_size = 0; 1754382e9c83SJeremy L Thompson CeedRestrictionType rstr_type; 1755349fb27dSJeremy L Thompson CeedEvalMode eval_mode; 1756349fb27dSJeremy L Thompson CeedVector vec; 1757349fb27dSJeremy L Thompson CeedElemRestriction elem_rstr; 1758349fb27dSJeremy L Thompson CeedBasis basis; 1759349fb27dSJeremy L Thompson 1760382e9c83SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_output_fields[j], &vec)); 1761382e9c83SJeremy L Thompson // ---- Skip non-active output 1762349fb27dSJeremy L Thompson is_active_output = vec == CEED_VECTOR_ACTIVE; 1763349fb27dSJeremy L Thompson if (!is_active_output) continue; 1764349fb27dSJeremy L Thompson 1765382e9c83SJeremy L Thompson // ---- Check if elem size matches 1766382e9c83SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_output_fields[j], &elem_rstr)); 1767382e9c83SJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetType(elem_rstr, &rstr_type)); 1768382e9c83SJeremy L Thompson if (is_active_at_points && rstr_type != CEED_RESTRICTION_POINTS) continue; 1769382e9c83SJeremy L Thompson if (rstr_type == CEED_RESTRICTION_POINTS) { 1770382e9c83SJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetMaxPointsInElement(elem_rstr, &elem_size)); 1771382e9c83SJeremy L Thompson } else { 1772382e9c83SJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetElementSize(elem_rstr, &elem_size)); 1773382e9c83SJeremy L Thompson } 1774382e9c83SJeremy L Thompson { 1775382e9c83SJeremy L Thompson CeedInt num_comp = 0; 1776382e9c83SJeremy L Thompson 1777382e9c83SJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetNumComponents(elem_rstr, &num_comp)); 1778382e9c83SJeremy L Thompson if (e_vec_size != num_comp * elem_size) continue; 1779382e9c83SJeremy L Thompson } 1780382e9c83SJeremy L Thompson 1781349fb27dSJeremy L Thompson // Basis action 1782382e9c83SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[j], &eval_mode)); 1783349fb27dSJeremy L Thompson switch (eval_mode) { 1784349fb27dSJeremy L Thompson case CEED_EVAL_NONE: 1785382e9c83SJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(impl->e_vecs[j + impl->num_inputs], &e_data[j + num_input_fields])); 1786349fb27dSJeremy L Thompson break; 1787349fb27dSJeremy L Thompson case CEED_EVAL_INTERP: 1788349fb27dSJeremy L Thompson case CEED_EVAL_GRAD: 1789349fb27dSJeremy L Thompson case CEED_EVAL_DIV: 1790349fb27dSJeremy L Thompson case CEED_EVAL_CURL: 1791382e9c83SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetBasis(op_output_fields[j], &basis)); 1792382e9c83SJeremy L Thompson CeedCallBackend(CeedBasisApplyAtPoints(basis, num_elem, num_points, CEED_TRANSPOSE, eval_mode, impl->point_coords_elem, 1793382e9c83SJeremy L Thompson impl->q_vecs_out[j], impl->e_vecs[j + impl->num_inputs])); 1794349fb27dSJeremy L Thompson break; 1795349fb27dSJeremy L Thompson // LCOV_EXCL_START 1796349fb27dSJeremy L Thompson case CEED_EVAL_WEIGHT: { 1797349fb27dSJeremy L Thompson return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_BACKEND, "CEED_EVAL_WEIGHT cannot be an output evaluation mode"); 1798349fb27dSJeremy L Thompson // LCOV_EXCL_STOP 1799349fb27dSJeremy L Thompson } 1800349fb27dSJeremy L Thompson } 1801349fb27dSJeremy L Thompson 1802349fb27dSJeremy L Thompson // Mask output e-vec 1803382e9c83SJeremy L Thompson CeedCallBackend(CeedVectorPointwiseMult(impl->e_vecs[j + impl->num_inputs], impl->e_vecs[i], impl->e_vecs[j + impl->num_inputs])); 1804349fb27dSJeremy L Thompson 1805349fb27dSJeremy L Thompson // Restrict 1806382e9c83SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_output_fields[j], &elem_rstr)); 1807382e9c83SJeremy L Thompson CeedCallBackend(CeedElemRestrictionApply(elem_rstr, CEED_TRANSPOSE, impl->e_vecs[j + impl->num_inputs], assembled, request)); 1808349fb27dSJeremy L Thompson 1809349fb27dSJeremy L Thompson // Reset q_vec for 1810349fb27dSJeremy L Thompson if (eval_mode == CEED_EVAL_NONE) { 1811382e9c83SJeremy L Thompson CeedCallBackend(CeedVectorGetArrayWrite(impl->e_vecs[j + impl->num_inputs], CEED_MEM_DEVICE, &e_data[j + num_input_fields])); 1812382e9c83SJeremy L Thompson CeedCallBackend(CeedVectorSetArray(impl->q_vecs_out[j], CEED_MEM_DEVICE, CEED_USE_POINTER, e_data[j + num_input_fields])); 1813349fb27dSJeremy L Thompson } 1814349fb27dSJeremy L Thompson } 1815382e9c83SJeremy L Thompson 1816382e9c83SJeremy L Thompson // Reset vec 181713062808SJeremy L Thompson if (s == e_vec_size - 1 && i != num_input_fields - 1) CeedCallBackend(CeedVectorSetValue(impl->q_vecs_in[i], 0.0)); 181886e10729SJeremy L Thompson } 1819349fb27dSJeremy L Thompson } 1820349fb27dSJeremy L Thompson 1821349fb27dSJeremy L Thompson // Restore CEED_EVAL_NONE 1822349fb27dSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 1823349fb27dSJeremy L Thompson CeedEvalMode eval_mode; 1824349fb27dSJeremy L Thompson 1825349fb27dSJeremy L Thompson // Get eval_mode 1826349fb27dSJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 1827349fb27dSJeremy L Thompson 1828349fb27dSJeremy L Thompson // Restore evec 1829349fb27dSJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 1830349fb27dSJeremy L Thompson if (eval_mode == CEED_EVAL_NONE) { 1831349fb27dSJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(impl->e_vecs[i + impl->num_inputs], &e_data[i + num_input_fields])); 1832349fb27dSJeremy L Thompson } 1833349fb27dSJeremy L Thompson } 1834349fb27dSJeremy L Thompson 1835349fb27dSJeremy L Thompson // Restore input arrays 1836349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorRestoreInputs_Cuda(num_input_fields, qf_input_fields, op_input_fields, true, e_data, impl)); 1837349fb27dSJeremy L Thompson return CEED_ERROR_SUCCESS; 1838756ca9e9SJeremy L Thompson } 1839756ca9e9SJeremy L Thompson 1840756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 18410d0321e0SJeremy L Thompson // Create operator 18420d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 18430d0321e0SJeremy L Thompson int CeedOperatorCreate_Cuda(CeedOperator op) { 18440d0321e0SJeremy L Thompson Ceed ceed; 18450d0321e0SJeremy L Thompson CeedOperator_Cuda *impl; 18460d0321e0SJeremy L Thompson 1847ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 18482b730f8bSJeremy L Thompson CeedCallBackend(CeedCalloc(1, &impl)); 18492b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorSetData(op, impl)); 18500d0321e0SJeremy L Thompson 18512b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleQFunction", CeedOperatorLinearAssembleQFunction_Cuda)); 18522b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleQFunctionUpdate", CeedOperatorLinearAssembleQFunctionUpdate_Cuda)); 18532b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleAddDiagonal", CeedOperatorLinearAssembleAddDiagonal_Cuda)); 18542b730f8bSJeremy L Thompson CeedCallBackend( 18552b730f8bSJeremy L Thompson CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleAddPointBlockDiagonal", CeedOperatorLinearAssembleAddPointBlockDiagonal_Cuda)); 18562b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleSingle", CeedSingleOperatorAssemble_Cuda)); 18572b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "ApplyAdd", CeedOperatorApplyAdd_Cuda)); 18582b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "Destroy", CeedOperatorDestroy_Cuda)); 18590d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 18600d0321e0SJeremy L Thompson } 18610d0321e0SJeremy L Thompson 18620d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 186367d9480aSJeremy L Thompson // Create operator AtPoints 1864756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 1865756ca9e9SJeremy L Thompson int CeedOperatorCreateAtPoints_Cuda(CeedOperator op) { 1866756ca9e9SJeremy L Thompson Ceed ceed; 1867756ca9e9SJeremy L Thompson CeedOperator_Cuda *impl; 1868756ca9e9SJeremy L Thompson 1869756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 1870756ca9e9SJeremy L Thompson CeedCallBackend(CeedCalloc(1, &impl)); 1871756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorSetData(op, impl)); 1872756ca9e9SJeremy L Thompson 1873756ca9e9SJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleQFunction", CeedOperatorLinearAssembleQFunctionAtPoints_Cuda)); 1874756ca9e9SJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleAddDiagonal", CeedOperatorLinearAssembleAddDiagonalAtPoints_Cuda)); 1875756ca9e9SJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "ApplyAdd", CeedOperatorApplyAddAtPoints_Cuda)); 1876756ca9e9SJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "Destroy", CeedOperatorDestroy_Cuda)); 1877756ca9e9SJeremy L Thompson return CEED_ERROR_SUCCESS; 1878756ca9e9SJeremy L Thompson } 1879756ca9e9SJeremy L Thompson 1880756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 1881