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 30111870feSJeremy 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 //------------------------------------------------------------------------------ 320*43e13feeSJeremy L Thompson // Restrict Operator Inputs 3210d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 322*43e13feeSJeremy L Thompson static inline int CeedOperatorInputRestrict_Cuda(CeedOperatorField op_input_field, CeedQFunctionField qf_input_field, CeedInt input_field, 323*43e13feeSJeremy L Thompson CeedVector in_vec, const bool skip_active, CeedScalar **e_data, CeedOperator_Cuda *impl, 324*43e13feeSJeremy L Thompson CeedRequest *request) { 325004e4986SSebastian Grimberg CeedEvalMode eval_mode; 3260d0321e0SJeremy L Thompson CeedVector vec; 327edb2538eSJeremy L Thompson CeedElemRestriction elem_rstr; 3280d0321e0SJeremy L Thompson 3290d0321e0SJeremy L Thompson // Get input vector 330*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_field, &vec)); 3310d0321e0SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 332*43e13feeSJeremy L Thompson if (skip_active) return CEED_ERROR_SUCCESS; 333ca735530SJeremy L Thompson else vec = in_vec; 3340d0321e0SJeremy L Thompson } 3350d0321e0SJeremy L Thompson 336*43e13feeSJeremy L Thompson // Restriction action 337*43e13feeSJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_field, &eval_mode)); 338004e4986SSebastian Grimberg if (eval_mode == CEED_EVAL_WEIGHT) { // Skip 3390d0321e0SJeremy L Thompson } else { 340004e4986SSebastian Grimberg // Get input vector 341*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_field, &vec)); 3420d0321e0SJeremy L Thompson // Get input element restriction 343*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_input_field, &elem_rstr)); 344ca735530SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) vec = in_vec; 3450d0321e0SJeremy L Thompson // Restrict, if necessary 346*43e13feeSJeremy L Thompson if (!impl->e_vecs[input_field]) { 3470d0321e0SJeremy L Thompson // No restriction for this field; read data directly from vec. 348*43e13feeSJeremy L Thompson CeedCallBackend(CeedVectorGetArrayRead(vec, CEED_MEM_DEVICE, (const CeedScalar **)e_data)); 3490d0321e0SJeremy L Thompson } else { 350c1222711SJeremy L Thompson uint64_t state; 351c1222711SJeremy L Thompson 352c1222711SJeremy L Thompson CeedCallBackend(CeedVectorGetState(vec, &state)); 353*43e13feeSJeremy L Thompson if ((state != impl->input_states[input_field] || vec == in_vec) && !impl->skip_rstr_in[input_field]) { 354*43e13feeSJeremy L Thompson CeedCallBackend(CeedElemRestrictionApply(elem_rstr, CEED_NOTRANSPOSE, vec, impl->e_vecs[input_field], request)); 355c1222711SJeremy L Thompson } 356*43e13feeSJeremy L Thompson impl->input_states[input_field] = state; 3570d0321e0SJeremy L Thompson // Get evec 358*43e13feeSJeremy L Thompson CeedCallBackend(CeedVectorGetArrayRead(impl->e_vecs[input_field], CEED_MEM_DEVICE, (const CeedScalar **)e_data)); 3590d0321e0SJeremy L Thompson } 3600d0321e0SJeremy L Thompson } 3610d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 3620d0321e0SJeremy L Thompson } 3630d0321e0SJeremy L Thompson 3640d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 3650d0321e0SJeremy L Thompson // Input Basis Action 3660d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 367*43e13feeSJeremy L Thompson static inline int CeedOperatorInputBasis_Cuda(CeedOperatorField op_input_field, CeedQFunctionField qf_input_field, CeedInt input_field, 368*43e13feeSJeremy L Thompson CeedInt num_elem, const bool skip_active, CeedScalar *e_data, CeedOperator_Cuda *impl) { 369004e4986SSebastian Grimberg CeedEvalMode eval_mode; 3700d0321e0SJeremy L Thompson 3710d0321e0SJeremy L Thompson // Skip active input 372004e4986SSebastian Grimberg if (skip_active) { 3730d0321e0SJeremy L Thompson CeedVector vec; 374ca735530SJeremy L Thompson 375*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_field, &vec)); 376*43e13feeSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) return CEED_ERROR_SUCCESS; 3770d0321e0SJeremy L Thompson } 378*43e13feeSJeremy L Thompson 3790d0321e0SJeremy L Thompson // Basis action 380*43e13feeSJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_field, &eval_mode)); 381004e4986SSebastian Grimberg switch (eval_mode) { 3820d0321e0SJeremy L Thompson case CEED_EVAL_NONE: 383*43e13feeSJeremy L Thompson CeedCallBackend(CeedVectorSetArray(impl->q_vecs_in[input_field], CEED_MEM_DEVICE, CEED_USE_POINTER, e_data)); 3840d0321e0SJeremy L Thompson break; 3850d0321e0SJeremy L Thompson case CEED_EVAL_INTERP: 3860d0321e0SJeremy L Thompson case CEED_EVAL_GRAD: 387004e4986SSebastian Grimberg case CEED_EVAL_DIV: 388*43e13feeSJeremy L Thompson case CEED_EVAL_CURL: { 389*43e13feeSJeremy L Thompson CeedBasis basis; 390*43e13feeSJeremy L Thompson 391*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetBasis(op_input_field, &basis)); 392*43e13feeSJeremy L Thompson CeedCallBackend(CeedBasisApply(basis, num_elem, CEED_NOTRANSPOSE, eval_mode, impl->e_vecs[input_field], impl->q_vecs_in[input_field])); 3930d0321e0SJeremy L Thompson break; 394*43e13feeSJeremy L Thompson } 3950d0321e0SJeremy L Thompson case CEED_EVAL_WEIGHT: 3960d0321e0SJeremy L Thompson break; // No action 3970d0321e0SJeremy L Thompson } 3980d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 3990d0321e0SJeremy L Thompson } 4000d0321e0SJeremy L Thompson 4010d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 4020d0321e0SJeremy L Thompson // Restore Input Vectors 4030d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 404*43e13feeSJeremy L Thompson static inline int CeedOperatorInputRestore_Cuda(CeedOperatorField op_input_field, CeedQFunctionField qf_input_field, CeedInt input_field, 405*43e13feeSJeremy L Thompson const bool skip_active, CeedScalar **e_data, CeedOperator_Cuda *impl) { 406004e4986SSebastian Grimberg CeedEvalMode eval_mode; 4070d0321e0SJeremy L Thompson CeedVector vec; 4080d0321e0SJeremy L Thompson 4090d0321e0SJeremy L Thompson // Skip active input 410004e4986SSebastian Grimberg if (skip_active) { 411*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_field, &vec)); 412*43e13feeSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) return CEED_ERROR_SUCCESS; 4130d0321e0SJeremy L Thompson } 414*43e13feeSJeremy L Thompson 415*43e13feeSJeremy L Thompson // Restore e-vec 416*43e13feeSJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_field, &eval_mode)); 417004e4986SSebastian Grimberg if (eval_mode == CEED_EVAL_WEIGHT) { // Skip 4180d0321e0SJeremy L Thompson } else { 419*43e13feeSJeremy L Thompson if (!impl->e_vecs[input_field]) { // This was a skip_restriction case 420*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_field, &vec)); 421*43e13feeSJeremy L Thompson CeedCallBackend(CeedVectorRestoreArrayRead(vec, (const CeedScalar **)e_data)); 4220d0321e0SJeremy L Thompson } else { 423*43e13feeSJeremy L Thompson CeedCallBackend(CeedVectorRestoreArrayRead(impl->e_vecs[input_field], (const CeedScalar **)e_data)); 4240d0321e0SJeremy L Thompson } 4250d0321e0SJeremy L Thompson } 4260d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 4270d0321e0SJeremy L Thompson } 4280d0321e0SJeremy L Thompson 4290d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 4300d0321e0SJeremy L Thompson // Apply and add to output 4310d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 432ca735530SJeremy L Thompson static int CeedOperatorApplyAdd_Cuda(CeedOperator op, CeedVector in_vec, CeedVector out_vec, CeedRequest *request) { 433ca735530SJeremy L Thompson CeedInt Q, num_elem, elem_size, num_input_fields, num_output_fields, size; 434ca735530SJeremy L Thompson CeedScalar *e_data[2 * CEED_FIELD_MAX] = {NULL}; 435ca735530SJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 4360d0321e0SJeremy L Thompson CeedQFunction qf; 437004e4986SSebastian Grimberg CeedOperatorField *op_input_fields, *op_output_fields; 438004e4986SSebastian Grimberg CeedOperator_Cuda *impl; 439ca735530SJeremy L Thompson 440ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 4412b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); 4422b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetNumQuadraturePoints(op, &Q)); 443ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem)); 444ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 445ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields)); 4460d0321e0SJeremy L Thompson 4470d0321e0SJeremy L Thompson // Setup 4482b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorSetup_Cuda(op)); 4490d0321e0SJeremy L Thompson 450*43e13feeSJeremy L Thompson // Process inputs 451*43e13feeSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 452*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorInputRestrict_Cuda(op_input_fields[i], qf_input_fields[i], i, in_vec, false, &e_data[i], impl, request)); 453*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorInputBasis_Cuda(op_input_fields[i], qf_input_fields[i], i, num_elem, false, e_data[i], impl)); 454*43e13feeSJeremy L Thompson } 4550d0321e0SJeremy L Thompson 4560d0321e0SJeremy L Thompson // Output pointers, as necessary 457ca735530SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 458004e4986SSebastian Grimberg CeedEvalMode eval_mode; 459004e4986SSebastian Grimberg 460004e4986SSebastian Grimberg CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 461004e4986SSebastian Grimberg if (eval_mode == CEED_EVAL_NONE) { 4620d0321e0SJeremy L Thompson // Set the output Q-Vector to use the E-Vector data directly. 463ca735530SJeremy L Thompson CeedCallBackend(CeedVectorGetArrayWrite(impl->e_vecs[i + impl->num_inputs], CEED_MEM_DEVICE, &e_data[i + num_input_fields])); 464ca735530SJeremy L Thompson CeedCallBackend(CeedVectorSetArray(impl->q_vecs_out[i], CEED_MEM_DEVICE, CEED_USE_POINTER, e_data[i + num_input_fields])); 4650d0321e0SJeremy L Thompson } 4660d0321e0SJeremy L Thompson } 4670d0321e0SJeremy L Thompson 4680d0321e0SJeremy L Thompson // Q function 469ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionApply(qf, num_elem * Q, impl->q_vecs_in, impl->q_vecs_out)); 4700d0321e0SJeremy L Thompson 47141655a23SJeremy L Thompson // Restore input arrays 472*43e13feeSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 473*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorInputRestore_Cuda(op_input_fields[i], qf_input_fields[i], i, false, &e_data[i], impl)); 474*43e13feeSJeremy L Thompson } 47541655a23SJeremy L Thompson 4760d0321e0SJeremy L Thompson // Output basis apply if needed 477ca735530SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 478004e4986SSebastian Grimberg CeedEvalMode eval_mode; 479edb2538eSJeremy L Thompson CeedElemRestriction elem_rstr; 480ca735530SJeremy L Thompson CeedBasis basis; 481ca735530SJeremy L Thompson 482004e4986SSebastian Grimberg // Get elem_size, eval_mode, size 483edb2538eSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &elem_rstr)); 484edb2538eSJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetElementSize(elem_rstr, &elem_size)); 485004e4986SSebastian Grimberg CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 486ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetSize(qf_output_fields[i], &size)); 4870d0321e0SJeremy L Thompson // Basis action 488004e4986SSebastian Grimberg switch (eval_mode) { 4890d0321e0SJeremy L Thompson case CEED_EVAL_NONE: 490004e4986SSebastian Grimberg break; // No action 4910d0321e0SJeremy L Thompson case CEED_EVAL_INTERP: 4920d0321e0SJeremy L Thompson case CEED_EVAL_GRAD: 493004e4986SSebastian Grimberg case CEED_EVAL_DIV: 494004e4986SSebastian Grimberg case CEED_EVAL_CURL: 495ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetBasis(op_output_fields[i], &basis)); 496f8a0df59SJeremy L Thompson if (impl->apply_add_basis_out[i]) { 497f8a0df59SJeremy L Thompson CeedCallBackend(CeedBasisApplyAdd(basis, num_elem, CEED_TRANSPOSE, eval_mode, impl->q_vecs_out[i], impl->e_vecs[i + impl->num_inputs])); 498f8a0df59SJeremy L Thompson } else { 499004e4986SSebastian Grimberg CeedCallBackend(CeedBasisApply(basis, num_elem, CEED_TRANSPOSE, eval_mode, impl->q_vecs_out[i], impl->e_vecs[i + impl->num_inputs])); 500f8a0df59SJeremy L Thompson } 5010d0321e0SJeremy L Thompson break; 5020d0321e0SJeremy L Thompson // LCOV_EXCL_START 5030d0321e0SJeremy L Thompson case CEED_EVAL_WEIGHT: { 5046e536b99SJeremy L Thompson return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_BACKEND, "CEED_EVAL_WEIGHT cannot be an output evaluation mode"); 5050d0321e0SJeremy L Thompson // LCOV_EXCL_STOP 5060d0321e0SJeremy L Thompson } 5070d0321e0SJeremy L Thompson } 508004e4986SSebastian Grimberg } 5090d0321e0SJeremy L Thompson 5100d0321e0SJeremy L Thompson // Output restriction 511ca735530SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 512004e4986SSebastian Grimberg CeedEvalMode eval_mode; 513ca735530SJeremy L Thompson CeedVector vec; 514edb2538eSJeremy L Thompson CeedElemRestriction elem_rstr; 515ca735530SJeremy L Thompson 5160d0321e0SJeremy L Thompson // Restore evec 517004e4986SSebastian Grimberg CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 518004e4986SSebastian Grimberg if (eval_mode == CEED_EVAL_NONE) { 519ca735530SJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(impl->e_vecs[i + impl->num_inputs], &e_data[i + num_input_fields])); 5200d0321e0SJeremy L Thompson } 521f8a0df59SJeremy L Thompson if (impl->skip_rstr_out[i]) continue; 5220d0321e0SJeremy L Thompson // Get output vector 523ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_output_fields[i], &vec)); 5240d0321e0SJeremy L Thompson // Restrict 525edb2538eSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &elem_rstr)); 5260d0321e0SJeremy L Thompson // Active 527ca735530SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) vec = out_vec; 5280d0321e0SJeremy L Thompson 529edb2538eSJeremy L Thompson CeedCallBackend(CeedElemRestrictionApply(elem_rstr, CEED_TRANSPOSE, impl->e_vecs[i + impl->num_inputs], vec, request)); 5300d0321e0SJeremy L Thompson } 5310d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 5320d0321e0SJeremy L Thompson } 5330d0321e0SJeremy L Thompson 5340d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 535756ca9e9SJeremy L Thompson // CeedOperator needs to connect all the named fields (be they active or passive) to the named inputs and outputs of its CeedQFunction. 536756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 537756ca9e9SJeremy L Thompson static int CeedOperatorSetupAtPoints_Cuda(CeedOperator op) { 538756ca9e9SJeremy L Thompson Ceed ceed; 539756ca9e9SJeremy L Thompson bool is_setup_done; 540756ca9e9SJeremy L Thompson CeedInt max_num_points = -1, num_elem, num_input_fields, num_output_fields; 541756ca9e9SJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 542756ca9e9SJeremy L Thompson CeedQFunction qf; 543756ca9e9SJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 544756ca9e9SJeremy L Thompson CeedOperator_Cuda *impl; 545756ca9e9SJeremy L Thompson 546756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorIsSetupDone(op, &is_setup_done)); 547756ca9e9SJeremy L Thompson if (is_setup_done) return CEED_ERROR_SUCCESS; 548756ca9e9SJeremy L Thompson 549756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 550756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 551756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); 552756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem)); 553756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 554756ca9e9SJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields)); 555756ca9e9SJeremy L Thompson { 556111870feSJeremy L Thompson CeedElemRestriction rstr_points = NULL; 557756ca9e9SJeremy L Thompson 558111870feSJeremy L Thompson CeedCallBackend(CeedOperatorAtPointsGetPoints(op, &rstr_points, NULL)); 559111870feSJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetMaxPointsInElement(rstr_points, &max_num_points)); 560111870feSJeremy L Thompson CeedCallBackend(CeedCalloc(num_elem, &impl->num_points)); 561111870feSJeremy L Thompson for (CeedInt e = 0; e < num_elem; e++) { 562111870feSJeremy L Thompson CeedInt num_points_elem; 563111870feSJeremy L Thompson 564111870feSJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetNumPointsInElement(rstr_points, e, &num_points_elem)); 565111870feSJeremy L Thompson impl->num_points[e] = num_points_elem; 566111870feSJeremy L Thompson } 567756ca9e9SJeremy L Thompson } 568756ca9e9SJeremy L Thompson impl->max_num_points = max_num_points; 569756ca9e9SJeremy L Thompson 570756ca9e9SJeremy L Thompson // Allocate 571756ca9e9SJeremy L Thompson CeedCallBackend(CeedCalloc(num_input_fields + num_output_fields, &impl->e_vecs)); 5723aab95c0SJeremy L Thompson CeedCallBackend(CeedCalloc(CEED_FIELD_MAX, &impl->skip_rstr_in)); 573f8a0df59SJeremy L Thompson CeedCallBackend(CeedCalloc(CEED_FIELD_MAX, &impl->skip_rstr_out)); 574f8a0df59SJeremy L Thompson CeedCallBackend(CeedCalloc(CEED_FIELD_MAX, &impl->apply_add_basis_out)); 575756ca9e9SJeremy L Thompson CeedCallBackend(CeedCalloc(CEED_FIELD_MAX, &impl->input_states)); 576756ca9e9SJeremy L Thompson CeedCallBackend(CeedCalloc(CEED_FIELD_MAX, &impl->q_vecs_in)); 577756ca9e9SJeremy L Thompson CeedCallBackend(CeedCalloc(CEED_FIELD_MAX, &impl->q_vecs_out)); 578756ca9e9SJeremy L Thompson impl->num_inputs = num_input_fields; 579756ca9e9SJeremy L Thompson impl->num_outputs = num_output_fields; 580756ca9e9SJeremy L Thompson 5818a213570SJeremy L Thompson // Set up infield and outfield e-vecs and q-vecs 582756ca9e9SJeremy L Thompson // Infields 583f8a0df59SJeremy 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, 5843aab95c0SJeremy L Thompson max_num_points, num_elem)); 585756ca9e9SJeremy L Thompson // Outfields 586f8a0df59SJeremy 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, 587f8a0df59SJeremy L Thompson num_input_fields, num_output_fields, max_num_points, num_elem)); 588756ca9e9SJeremy L Thompson 5898a213570SJeremy L Thompson // Reuse active e-vecs where able 5908a213570SJeremy L Thompson { 5918a213570SJeremy L Thompson CeedInt num_used = 0; 5928a213570SJeremy L Thompson CeedElemRestriction *rstr_used = NULL; 5938a213570SJeremy L Thompson 5948a213570SJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 5958a213570SJeremy L Thompson bool is_used = false; 5968a213570SJeremy L Thompson CeedVector vec_i; 5978a213570SJeremy L Thompson CeedElemRestriction rstr_i; 5988a213570SJeremy L Thompson 5998a213570SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec_i)); 6008a213570SJeremy L Thompson if (vec_i != CEED_VECTOR_ACTIVE) continue; 6018a213570SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &rstr_i)); 6028a213570SJeremy L Thompson for (CeedInt j = 0; j < num_used; j++) { 6038a213570SJeremy L Thompson if (rstr_i == rstr_used[i]) is_used = true; 6048a213570SJeremy L Thompson } 6058a213570SJeremy L Thompson if (is_used) continue; 6068a213570SJeremy L Thompson num_used++; 6078a213570SJeremy L Thompson if (num_used == 1) CeedCallBackend(CeedCalloc(num_used, &rstr_used)); 6088a213570SJeremy L Thompson else CeedCallBackend(CeedRealloc(num_used, &rstr_used)); 6098a213570SJeremy L Thompson rstr_used[num_used - 1] = rstr_i; 6108a213570SJeremy L Thompson for (CeedInt j = num_output_fields - 1; j >= 0; j--) { 6118a213570SJeremy L Thompson CeedEvalMode eval_mode; 6128a213570SJeremy L Thompson CeedVector vec_j; 6138a213570SJeremy L Thompson CeedElemRestriction rstr_j; 6148a213570SJeremy L Thompson 6158a213570SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_output_fields[j], &vec_j)); 6168a213570SJeremy L Thompson if (vec_j != CEED_VECTOR_ACTIVE) continue; 6178a213570SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[j], &eval_mode)); 6188a213570SJeremy L Thompson if (eval_mode == CEED_EVAL_NONE) continue; 6198a213570SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_output_fields[j], &rstr_j)); 6208a213570SJeremy L Thompson if (rstr_i == rstr_j) { 6218a213570SJeremy L Thompson CeedCallBackend(CeedVectorReferenceCopy(impl->e_vecs[i], &impl->e_vecs[j + impl->num_inputs])); 6228a213570SJeremy L Thompson } 6238a213570SJeremy L Thompson } 6248a213570SJeremy L Thompson } 6258a213570SJeremy L Thompson CeedCallBackend(CeedFree(&rstr_used)); 6268a213570SJeremy L Thompson } 6278a213570SJeremy L Thompson impl->has_shared_e_vecs = true; 628756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorSetSetupDone(op)); 629756ca9e9SJeremy L Thompson return CEED_ERROR_SUCCESS; 630756ca9e9SJeremy L Thompson } 631756ca9e9SJeremy L Thompson 632756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 63367d9480aSJeremy L Thompson // Input Basis Action AtPoints 634756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 635*43e13feeSJeremy L Thompson static inline int CeedOperatorInputBasisAtPoints_Cuda(CeedOperatorField op_input_field, CeedQFunctionField qf_input_field, CeedInt input_field, 636*43e13feeSJeremy L Thompson CeedInt num_elem, const CeedInt *num_points, const bool skip_active, CeedScalar *e_data, 637*43e13feeSJeremy L Thompson CeedOperator_Cuda *impl) { 638756ca9e9SJeremy L Thompson CeedEvalMode eval_mode; 639756ca9e9SJeremy L Thompson 640756ca9e9SJeremy L Thompson // Skip active input 641756ca9e9SJeremy L Thompson if (skip_active) { 642756ca9e9SJeremy L Thompson CeedVector vec; 643756ca9e9SJeremy L Thompson 644*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_field, &vec)); 645*43e13feeSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) return CEED_ERROR_SUCCESS; 646756ca9e9SJeremy L Thompson } 647*43e13feeSJeremy L Thompson 648756ca9e9SJeremy L Thompson // Basis action 649*43e13feeSJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_field, &eval_mode)); 650756ca9e9SJeremy L Thompson switch (eval_mode) { 651756ca9e9SJeremy L Thompson case CEED_EVAL_NONE: 652*43e13feeSJeremy L Thompson CeedCallBackend(CeedVectorSetArray(impl->q_vecs_in[input_field], CEED_MEM_DEVICE, CEED_USE_POINTER, e_data)); 653756ca9e9SJeremy L Thompson break; 654756ca9e9SJeremy L Thompson case CEED_EVAL_INTERP: 655756ca9e9SJeremy L Thompson case CEED_EVAL_GRAD: 656756ca9e9SJeremy L Thompson case CEED_EVAL_DIV: 657*43e13feeSJeremy L Thompson case CEED_EVAL_CURL: { 658*43e13feeSJeremy L Thompson CeedBasis basis; 659*43e13feeSJeremy L Thompson 660*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetBasis(op_input_field, &basis)); 661*43e13feeSJeremy L Thompson CeedCallBackend(CeedBasisApplyAtPoints(basis, num_elem, num_points, CEED_NOTRANSPOSE, eval_mode, impl->point_coords_elem, 662*43e13feeSJeremy L Thompson impl->e_vecs[input_field], impl->q_vecs_in[input_field])); 663756ca9e9SJeremy L Thompson break; 664*43e13feeSJeremy L Thompson } 665756ca9e9SJeremy L Thompson case CEED_EVAL_WEIGHT: 666756ca9e9SJeremy L Thompson break; // No action 667756ca9e9SJeremy L Thompson } 668756ca9e9SJeremy L Thompson return CEED_ERROR_SUCCESS; 669756ca9e9SJeremy L Thompson } 670756ca9e9SJeremy L Thompson 671756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 67267d9480aSJeremy L Thompson // Apply and add to output AtPoints 673756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 674756ca9e9SJeremy L Thompson static int CeedOperatorApplyAddAtPoints_Cuda(CeedOperator op, CeedVector in_vec, CeedVector out_vec, CeedRequest *request) { 675111870feSJeremy L Thompson CeedInt max_num_points, *num_points, num_elem, elem_size, num_input_fields, num_output_fields, size; 676756ca9e9SJeremy L Thompson CeedScalar *e_data[2 * CEED_FIELD_MAX] = {NULL}; 677756ca9e9SJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 678756ca9e9SJeremy L Thompson CeedQFunction qf; 679756ca9e9SJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 680756ca9e9SJeremy L Thompson CeedOperator_Cuda *impl; 681756ca9e9SJeremy L Thompson 682756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 683756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); 684756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem)); 685756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 686756ca9e9SJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields)); 687756ca9e9SJeremy L Thompson 688756ca9e9SJeremy L Thompson // Setup 689756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorSetupAtPoints_Cuda(op)); 690111870feSJeremy L Thompson num_points = impl->num_points; 691756ca9e9SJeremy L Thompson max_num_points = impl->max_num_points; 692756ca9e9SJeremy L Thompson 693756ca9e9SJeremy L Thompson // Get point coordinates 694756ca9e9SJeremy L Thompson if (!impl->point_coords_elem) { 695756ca9e9SJeremy L Thompson CeedVector point_coords = NULL; 696756ca9e9SJeremy L Thompson CeedElemRestriction rstr_points = NULL; 697756ca9e9SJeremy L Thompson 698756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorAtPointsGetPoints(op, &rstr_points, &point_coords)); 699756ca9e9SJeremy L Thompson CeedCallBackend(CeedElemRestrictionCreateVector(rstr_points, NULL, &impl->point_coords_elem)); 700756ca9e9SJeremy L Thompson CeedCallBackend(CeedElemRestrictionApply(rstr_points, CEED_NOTRANSPOSE, point_coords, impl->point_coords_elem, request)); 701756ca9e9SJeremy L Thompson } 702756ca9e9SJeremy L Thompson 703*43e13feeSJeremy L Thompson // Process inputs 704*43e13feeSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 705*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorInputRestrict_Cuda(op_input_fields[i], qf_input_fields[i], i, in_vec, false, &e_data[i], impl, request)); 706*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorInputBasisAtPoints_Cuda(op_input_fields[i], qf_input_fields[i], i, num_elem, num_points, false, e_data[i], impl)); 707*43e13feeSJeremy L Thompson } 708756ca9e9SJeremy L Thompson 709756ca9e9SJeremy L Thompson // Output pointers, as necessary 710756ca9e9SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 711756ca9e9SJeremy L Thompson CeedEvalMode eval_mode; 712756ca9e9SJeremy L Thompson 713756ca9e9SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 714756ca9e9SJeremy L Thompson if (eval_mode == CEED_EVAL_NONE) { 715756ca9e9SJeremy L Thompson // Set the output Q-Vector to use the E-Vector data directly. 716756ca9e9SJeremy L Thompson CeedCallBackend(CeedVectorGetArrayWrite(impl->e_vecs[i + impl->num_inputs], CEED_MEM_DEVICE, &e_data[i + num_input_fields])); 717756ca9e9SJeremy L Thompson CeedCallBackend(CeedVectorSetArray(impl->q_vecs_out[i], CEED_MEM_DEVICE, CEED_USE_POINTER, e_data[i + num_input_fields])); 718756ca9e9SJeremy L Thompson } 719756ca9e9SJeremy L Thompson } 720756ca9e9SJeremy L Thompson 721756ca9e9SJeremy L Thompson // Q function 722756ca9e9SJeremy L Thompson CeedCallBackend(CeedQFunctionApply(qf, num_elem * max_num_points, impl->q_vecs_in, impl->q_vecs_out)); 723756ca9e9SJeremy L Thompson 7248a213570SJeremy L Thompson // Restore input arrays 725*43e13feeSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 726*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorInputRestore_Cuda(op_input_fields[i], qf_input_fields[i], i, false, &e_data[i], impl)); 727*43e13feeSJeremy L Thompson } 7288a213570SJeremy L Thompson 729756ca9e9SJeremy L Thompson // Output basis apply if needed 730756ca9e9SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 731756ca9e9SJeremy L Thompson CeedEvalMode eval_mode; 732756ca9e9SJeremy L Thompson CeedElemRestriction elem_rstr; 733756ca9e9SJeremy L Thompson CeedBasis basis; 734756ca9e9SJeremy L Thompson 735756ca9e9SJeremy L Thompson // Get elem_size, eval_mode, size 736756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &elem_rstr)); 737756ca9e9SJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetElementSize(elem_rstr, &elem_size)); 738756ca9e9SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 739756ca9e9SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetSize(qf_output_fields[i], &size)); 740756ca9e9SJeremy L Thompson // Basis action 741756ca9e9SJeremy L Thompson switch (eval_mode) { 742756ca9e9SJeremy L Thompson case CEED_EVAL_NONE: 743756ca9e9SJeremy L Thompson break; // No action 744756ca9e9SJeremy L Thompson case CEED_EVAL_INTERP: 745756ca9e9SJeremy L Thompson case CEED_EVAL_GRAD: 746756ca9e9SJeremy L Thompson case CEED_EVAL_DIV: 747756ca9e9SJeremy L Thompson case CEED_EVAL_CURL: 748756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetBasis(op_output_fields[i], &basis)); 749f8a0df59SJeremy L Thompson if (impl->apply_add_basis_out[i]) { 750f8a0df59SJeremy L Thompson CeedCallBackend(CeedBasisApplyAddAtPoints(basis, num_elem, num_points, CEED_TRANSPOSE, eval_mode, impl->point_coords_elem, 751f8a0df59SJeremy L Thompson impl->q_vecs_out[i], impl->e_vecs[i + impl->num_inputs])); 752f8a0df59SJeremy L Thompson } else { 753756ca9e9SJeremy L Thompson CeedCallBackend(CeedBasisApplyAtPoints(basis, num_elem, num_points, CEED_TRANSPOSE, eval_mode, impl->point_coords_elem, impl->q_vecs_out[i], 754756ca9e9SJeremy L Thompson impl->e_vecs[i + impl->num_inputs])); 755f8a0df59SJeremy L Thompson } 756756ca9e9SJeremy L Thompson break; 757756ca9e9SJeremy L Thompson // LCOV_EXCL_START 758756ca9e9SJeremy L Thompson case CEED_EVAL_WEIGHT: { 759756ca9e9SJeremy L Thompson return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_BACKEND, "CEED_EVAL_WEIGHT cannot be an output evaluation mode"); 760756ca9e9SJeremy L Thompson // LCOV_EXCL_STOP 761756ca9e9SJeremy L Thompson } 762756ca9e9SJeremy L Thompson } 763756ca9e9SJeremy L Thompson } 764756ca9e9SJeremy L Thompson 765756ca9e9SJeremy L Thompson // Output restriction 766756ca9e9SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 767756ca9e9SJeremy L Thompson CeedEvalMode eval_mode; 768756ca9e9SJeremy L Thompson CeedVector vec; 769756ca9e9SJeremy L Thompson CeedElemRestriction elem_rstr; 770756ca9e9SJeremy L Thompson 771756ca9e9SJeremy L Thompson // Restore evec 772756ca9e9SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 773756ca9e9SJeremy L Thompson if (eval_mode == CEED_EVAL_NONE) { 774756ca9e9SJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(impl->e_vecs[i + impl->num_inputs], &e_data[i + num_input_fields])); 775756ca9e9SJeremy L Thompson } 776f8a0df59SJeremy L Thompson if (impl->skip_rstr_out[i]) continue; 777756ca9e9SJeremy L Thompson // Get output vector 778756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_output_fields[i], &vec)); 779756ca9e9SJeremy L Thompson // Restrict 780756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &elem_rstr)); 781756ca9e9SJeremy L Thompson // Active 782756ca9e9SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) vec = out_vec; 783756ca9e9SJeremy L Thompson 784756ca9e9SJeremy L Thompson CeedCallBackend(CeedElemRestrictionApply(elem_rstr, CEED_TRANSPOSE, impl->e_vecs[i + impl->num_inputs], vec, request)); 785756ca9e9SJeremy L Thompson } 786756ca9e9SJeremy L Thompson return CEED_ERROR_SUCCESS; 787756ca9e9SJeremy L Thompson } 788756ca9e9SJeremy L Thompson 789756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 790004e4986SSebastian Grimberg // Linear QFunction Assembly Core 7910d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 7922b730f8bSJeremy L Thompson static inline int CeedOperatorLinearAssembleQFunctionCore_Cuda(CeedOperator op, bool build_objects, CeedVector *assembled, CeedElemRestriction *rstr, 7930d0321e0SJeremy L Thompson CeedRequest *request) { 794ca735530SJeremy L Thompson Ceed ceed, ceed_parent; 795ca735530SJeremy L Thompson CeedInt num_active_in, num_active_out, Q, num_elem, num_input_fields, num_output_fields, size; 796ca735530SJeremy L Thompson CeedScalar *assembled_array, *e_data[2 * CEED_FIELD_MAX] = {NULL}; 797ca735530SJeremy L Thompson CeedVector *active_inputs; 798ca735530SJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 799ca735530SJeremy L Thompson CeedQFunction qf; 800ca735530SJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 801ca735530SJeremy L Thompson CeedOperator_Cuda *impl; 802ca735530SJeremy L Thompson 8032b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 804ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetFallbackParentCeed(op, &ceed_parent)); 805e984cf9aSJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 806e984cf9aSJeremy L Thompson CeedCallBackend(CeedOperatorGetNumQuadraturePoints(op, &Q)); 807ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem)); 808e984cf9aSJeremy L Thompson CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); 809ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields)); 810ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 811ca735530SJeremy L Thompson active_inputs = impl->qf_active_in; 812ca735530SJeremy L Thompson num_active_in = impl->num_active_in, num_active_out = impl->num_active_out; 8130d0321e0SJeremy L Thompson 8140d0321e0SJeremy L Thompson // Setup 8152b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorSetup_Cuda(op)); 8160d0321e0SJeremy L Thompson 817004e4986SSebastian Grimberg // Input Evecs and Restriction 818*43e13feeSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 819*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorInputRestrict_Cuda(op_input_fields[i], qf_input_fields[i], i, NULL, true, &e_data[i], impl, request)); 820*43e13feeSJeremy L Thompson } 8210d0321e0SJeremy L Thompson 8220d0321e0SJeremy L Thompson // Count number of active input fields 823ca735530SJeremy L Thompson if (!num_active_in) { 824ca735530SJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 825ca735530SJeremy L Thompson CeedScalar *q_vec_array; 826ca735530SJeremy L Thompson CeedVector vec; 827ca735530SJeremy L Thompson 8280d0321e0SJeremy L Thompson // Get input vector 829ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 8300d0321e0SJeremy L Thompson // Check if active input 8310d0321e0SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 832ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetSize(qf_input_fields[i], &size)); 833ca735530SJeremy L Thompson CeedCallBackend(CeedVectorSetValue(impl->q_vecs_in[i], 0.0)); 834ca735530SJeremy L Thompson CeedCallBackend(CeedVectorGetArray(impl->q_vecs_in[i], CEED_MEM_DEVICE, &q_vec_array)); 835ca735530SJeremy L Thompson CeedCallBackend(CeedRealloc(num_active_in + size, &active_inputs)); 8360d0321e0SJeremy L Thompson for (CeedInt field = 0; field < size; field++) { 837004e4986SSebastian Grimberg CeedSize q_size = (CeedSize)Q * num_elem; 838004e4986SSebastian Grimberg 839ca735530SJeremy L Thompson CeedCallBackend(CeedVectorCreate(ceed, q_size, &active_inputs[num_active_in + field])); 840ca735530SJeremy L Thompson CeedCallBackend( 841ca735530SJeremy L Thompson CeedVectorSetArray(active_inputs[num_active_in + field], CEED_MEM_DEVICE, CEED_USE_POINTER, &q_vec_array[field * Q * num_elem])); 8420d0321e0SJeremy L Thompson } 843ca735530SJeremy L Thompson num_active_in += size; 844ca735530SJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(impl->q_vecs_in[i], &q_vec_array)); 8450d0321e0SJeremy L Thompson } 8460d0321e0SJeremy L Thompson } 847ca735530SJeremy L Thompson impl->num_active_in = num_active_in; 848ca735530SJeremy L Thompson impl->qf_active_in = active_inputs; 8490d0321e0SJeremy L Thompson } 8500d0321e0SJeremy L Thompson 8510d0321e0SJeremy L Thompson // Count number of active output fields 852ca735530SJeremy L Thompson if (!num_active_out) { 853ca735530SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 854ca735530SJeremy L Thompson CeedVector vec; 855ca735530SJeremy L Thompson 8560d0321e0SJeremy L Thompson // Get output vector 857ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_output_fields[i], &vec)); 8580d0321e0SJeremy L Thompson // Check if active output 8590d0321e0SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 860ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetSize(qf_output_fields[i], &size)); 861ca735530SJeremy L Thompson num_active_out += size; 8620d0321e0SJeremy L Thompson } 8630d0321e0SJeremy L Thompson } 864ca735530SJeremy L Thompson impl->num_active_out = num_active_out; 8650d0321e0SJeremy L Thompson } 8660d0321e0SJeremy L Thompson 8670d0321e0SJeremy L Thompson // Check sizes 868ca735530SJeremy L Thompson CeedCheck(num_active_in > 0 && num_active_out > 0, ceed, CEED_ERROR_BACKEND, "Cannot assemble QFunction without active inputs and outputs"); 8690d0321e0SJeremy L Thompson 8700d0321e0SJeremy L Thompson // Build objects if needed 8710d0321e0SJeremy L Thompson if (build_objects) { 872004e4986SSebastian Grimberg CeedSize l_size = (CeedSize)num_elem * Q * num_active_in * num_active_out; 873ca735530SJeremy L Thompson CeedInt strides[3] = {1, num_elem * Q, Q}; /* *NOPAD* */ 874004e4986SSebastian Grimberg 875004e4986SSebastian Grimberg // Create output restriction 876ca735530SJeremy L Thompson CeedCallBackend(CeedElemRestrictionCreateStrided(ceed_parent, num_elem, Q, num_active_in * num_active_out, 8770a5597ceSJeremy L Thompson (CeedSize)num_active_in * (CeedSize)num_active_out * (CeedSize)num_elem * (CeedSize)Q, strides, 8780a5597ceSJeremy L Thompson rstr)); 8790d0321e0SJeremy L Thompson // Create assembled vector 880ca735530SJeremy L Thompson CeedCallBackend(CeedVectorCreate(ceed_parent, l_size, assembled)); 8810d0321e0SJeremy L Thompson } 8822b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorSetValue(*assembled, 0.0)); 883ca735530SJeremy L Thompson CeedCallBackend(CeedVectorGetArray(*assembled, CEED_MEM_DEVICE, &assembled_array)); 8840d0321e0SJeremy L Thompson 8850d0321e0SJeremy L Thompson // Input basis apply 886*43e13feeSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 887*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorInputBasis_Cuda(op_input_fields[i], qf_input_fields[i], i, num_elem, true, e_data[i], impl)); 888*43e13feeSJeremy L Thompson } 8890d0321e0SJeremy L Thompson 8900d0321e0SJeremy L Thompson // Assemble QFunction 891ca735530SJeremy L Thompson for (CeedInt in = 0; in < num_active_in; in++) { 8920d0321e0SJeremy L Thompson // Set Inputs 893ca735530SJeremy L Thompson CeedCallBackend(CeedVectorSetValue(active_inputs[in], 1.0)); 894ca735530SJeremy L Thompson if (num_active_in > 1) { 895ca735530SJeremy L Thompson CeedCallBackend(CeedVectorSetValue(active_inputs[(in + num_active_in - 1) % num_active_in], 0.0)); 8960d0321e0SJeremy L Thompson } 8970d0321e0SJeremy L Thompson // Set Outputs 898ca735530SJeremy L Thompson for (CeedInt out = 0; out < num_output_fields; out++) { 899ca735530SJeremy L Thompson CeedVector vec; 900ca735530SJeremy L Thompson 9010d0321e0SJeremy L Thompson // Get output vector 902ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_output_fields[out], &vec)); 9030d0321e0SJeremy L Thompson // Check if active output 9040d0321e0SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 905ca735530SJeremy L Thompson CeedCallBackend(CeedVectorSetArray(impl->q_vecs_out[out], CEED_MEM_DEVICE, CEED_USE_POINTER, assembled_array)); 906ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetSize(qf_output_fields[out], &size)); 907ca735530SJeremy L Thompson assembled_array += size * Q * num_elem; // Advance the pointer by the size of the output 9080d0321e0SJeremy L Thompson } 9090d0321e0SJeremy L Thompson } 9100d0321e0SJeremy L Thompson // Apply QFunction 911ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionApply(qf, Q * num_elem, impl->q_vecs_in, impl->q_vecs_out)); 9120d0321e0SJeremy L Thompson } 9130d0321e0SJeremy L Thompson 9148a213570SJeremy L Thompson // Un-set output q-vecs to prevent accidental overwrite of Assembled 915ca735530SJeremy L Thompson for (CeedInt out = 0; out < num_output_fields; out++) { 916ca735530SJeremy L Thompson CeedVector vec; 917ca735530SJeremy L Thompson 9180d0321e0SJeremy L Thompson // Get output vector 919ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_output_fields[out], &vec)); 9200d0321e0SJeremy L Thompson // Check if active output 9210d0321e0SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 922ca735530SJeremy L Thompson CeedCallBackend(CeedVectorTakeArray(impl->q_vecs_out[out], CEED_MEM_DEVICE, NULL)); 9230d0321e0SJeremy L Thompson } 9240d0321e0SJeremy L Thompson } 9250d0321e0SJeremy L Thompson 9260d0321e0SJeremy L Thompson // Restore input arrays 927*43e13feeSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 928*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorInputRestore_Cuda(op_input_fields[i], qf_input_fields[i], i, true, &e_data[i], impl)); 929*43e13feeSJeremy L Thompson } 9300d0321e0SJeremy L Thompson 9310d0321e0SJeremy L Thompson // Restore output 932ca735530SJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(*assembled, &assembled_array)); 9330d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 9340d0321e0SJeremy L Thompson } 9350d0321e0SJeremy L Thompson 9360d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 9370d0321e0SJeremy L Thompson // Assemble Linear QFunction 9380d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 9392b730f8bSJeremy L Thompson static int CeedOperatorLinearAssembleQFunction_Cuda(CeedOperator op, CeedVector *assembled, CeedElemRestriction *rstr, CeedRequest *request) { 9402b730f8bSJeremy L Thompson return CeedOperatorLinearAssembleQFunctionCore_Cuda(op, true, assembled, rstr, request); 9410d0321e0SJeremy L Thompson } 9420d0321e0SJeremy L Thompson 9430d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 9440d0321e0SJeremy L Thompson // Update Assembled Linear QFunction 9450d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 9462b730f8bSJeremy L Thompson static int CeedOperatorLinearAssembleQFunctionUpdate_Cuda(CeedOperator op, CeedVector assembled, CeedElemRestriction rstr, CeedRequest *request) { 9472b730f8bSJeremy L Thompson return CeedOperatorLinearAssembleQFunctionCore_Cuda(op, false, &assembled, &rstr, request); 9480d0321e0SJeremy L Thompson } 9490d0321e0SJeremy L Thompson 9500d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 951004e4986SSebastian Grimberg // Assemble Diagonal Setup 9520d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 953cbfe683aSSebastian Grimberg static inline int CeedOperatorAssembleDiagonalSetup_Cuda(CeedOperator op) { 9540d0321e0SJeremy L Thompson Ceed ceed; 955004e4986SSebastian Grimberg CeedInt num_input_fields, num_output_fields, num_eval_modes_in = 0, num_eval_modes_out = 0; 956cbfe683aSSebastian Grimberg CeedInt q_comp, num_nodes, num_qpts; 957004e4986SSebastian Grimberg CeedEvalMode *eval_modes_in = NULL, *eval_modes_out = NULL; 958ca735530SJeremy L Thompson CeedBasis basis_in = NULL, basis_out = NULL; 959ca735530SJeremy L Thompson CeedQFunctionField *qf_fields; 9600d0321e0SJeremy L Thompson CeedQFunction qf; 961ca735530SJeremy L Thompson CeedOperatorField *op_fields; 962ca735530SJeremy L Thompson CeedOperator_Cuda *impl; 963ca735530SJeremy L Thompson 964ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 9652b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); 966ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionGetNumArgs(qf, &num_input_fields, &num_output_fields)); 9670d0321e0SJeremy L Thompson 9680d0321e0SJeremy L Thompson // Determine active input basis 969ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, NULL, &op_fields, NULL, NULL)); 970ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_fields, NULL, NULL)); 971ca735530SJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 9720d0321e0SJeremy L Thompson CeedVector vec; 973ca735530SJeremy L Thompson 974ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_fields[i], &vec)); 9750d0321e0SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 976004e4986SSebastian Grimberg CeedBasis basis; 977004e4986SSebastian Grimberg CeedEvalMode eval_mode; 978ca735530SJeremy L Thompson 979004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorFieldGetBasis(op_fields[i], &basis)); 980004e4986SSebastian Grimberg CeedCheck(!basis_in || basis_in == basis, ceed, CEED_ERROR_BACKEND, 981004e4986SSebastian Grimberg "Backend does not implement operator diagonal assembly with multiple active bases"); 982004e4986SSebastian Grimberg basis_in = basis; 983004e4986SSebastian Grimberg CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_fields[i], &eval_mode)); 984004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis_in, eval_mode, &q_comp)); 985004e4986SSebastian Grimberg if (eval_mode != CEED_EVAL_WEIGHT) { 986004e4986SSebastian Grimberg // q_comp = 1 if CEED_EVAL_NONE, CEED_EVAL_WEIGHT caught by QF assembly 987004e4986SSebastian Grimberg CeedCallBackend(CeedRealloc(num_eval_modes_in + q_comp, &eval_modes_in)); 988004e4986SSebastian Grimberg for (CeedInt d = 0; d < q_comp; d++) eval_modes_in[num_eval_modes_in + d] = eval_mode; 989004e4986SSebastian Grimberg num_eval_modes_in += q_comp; 9900d0321e0SJeremy L Thompson } 9910d0321e0SJeremy L Thompson } 9920d0321e0SJeremy L Thompson } 9930d0321e0SJeremy L Thompson 9940d0321e0SJeremy L Thompson // Determine active output basis 995ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, NULL, NULL, NULL, &op_fields)); 996ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, NULL, NULL, &qf_fields)); 997ca735530SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 9980d0321e0SJeremy L Thompson CeedVector vec; 999ca735530SJeremy L Thompson 1000ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_fields[i], &vec)); 10010d0321e0SJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 1002004e4986SSebastian Grimberg CeedBasis basis; 1003004e4986SSebastian Grimberg CeedEvalMode eval_mode; 1004ca735530SJeremy L Thompson 1005004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorFieldGetBasis(op_fields[i], &basis)); 1006004e4986SSebastian Grimberg CeedCheck(!basis_out || basis_out == basis, ceed, CEED_ERROR_BACKEND, 1007004e4986SSebastian Grimberg "Backend does not implement operator diagonal assembly with multiple active bases"); 1008004e4986SSebastian Grimberg basis_out = basis; 1009004e4986SSebastian Grimberg CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_fields[i], &eval_mode)); 1010004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis_out, eval_mode, &q_comp)); 1011004e4986SSebastian Grimberg if (eval_mode != CEED_EVAL_WEIGHT) { 1012004e4986SSebastian Grimberg // q_comp = 1 if CEED_EVAL_NONE, CEED_EVAL_WEIGHT caught by QF assembly 1013004e4986SSebastian Grimberg CeedCallBackend(CeedRealloc(num_eval_modes_out + q_comp, &eval_modes_out)); 1014004e4986SSebastian Grimberg for (CeedInt d = 0; d < q_comp; d++) eval_modes_out[num_eval_modes_out + d] = eval_mode; 1015004e4986SSebastian Grimberg num_eval_modes_out += q_comp; 10160d0321e0SJeremy L Thompson } 10170d0321e0SJeremy L Thompson } 10180d0321e0SJeremy L Thompson } 10190d0321e0SJeremy L Thompson 10200d0321e0SJeremy L Thompson // Operator data struct 10212b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 10222b730f8bSJeremy L Thompson CeedCallBackend(CeedCalloc(1, &impl->diag)); 10230d0321e0SJeremy L Thompson CeedOperatorDiag_Cuda *diag = impl->diag; 1024ca735530SJeremy L Thompson 1025cbfe683aSSebastian Grimberg // Basis matrices 1026004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumNodes(basis_in, &num_nodes)); 1027004e4986SSebastian Grimberg if (basis_in == CEED_BASIS_NONE) num_qpts = num_nodes; 1028004e4986SSebastian Grimberg else CeedCallBackend(CeedBasisGetNumQuadraturePoints(basis_in, &num_qpts)); 1029004e4986SSebastian Grimberg const CeedInt interp_bytes = num_nodes * num_qpts * sizeof(CeedScalar); 1030004e4986SSebastian Grimberg const CeedInt eval_modes_bytes = sizeof(CeedEvalMode); 1031004e4986SSebastian Grimberg bool has_eval_none = false; 10320d0321e0SJeremy L Thompson 10330d0321e0SJeremy L Thompson // CEED_EVAL_NONE 1034004e4986SSebastian Grimberg for (CeedInt i = 0; i < num_eval_modes_in; i++) has_eval_none = has_eval_none || (eval_modes_in[i] == CEED_EVAL_NONE); 1035004e4986SSebastian Grimberg for (CeedInt i = 0; i < num_eval_modes_out; i++) has_eval_none = has_eval_none || (eval_modes_out[i] == CEED_EVAL_NONE); 1036004e4986SSebastian Grimberg if (has_eval_none) { 10370d0321e0SJeremy L Thompson CeedScalar *identity = NULL; 1038ca735530SJeremy L Thompson 1039004e4986SSebastian Grimberg CeedCallBackend(CeedCalloc(num_nodes * num_qpts, &identity)); 1040ca735530SJeremy L Thompson for (CeedInt i = 0; i < (num_nodes < num_qpts ? num_nodes : num_qpts); i++) identity[i * num_nodes + i] = 1.0; 1041ca735530SJeremy L Thompson CeedCallCuda(ceed, cudaMalloc((void **)&diag->d_identity, interp_bytes)); 1042ca735530SJeremy L Thompson CeedCallCuda(ceed, cudaMemcpy(diag->d_identity, identity, interp_bytes, cudaMemcpyHostToDevice)); 1043004e4986SSebastian Grimberg CeedCallBackend(CeedFree(&identity)); 10440d0321e0SJeremy L Thompson } 10450d0321e0SJeremy L Thompson 1046004e4986SSebastian Grimberg // CEED_EVAL_INTERP, CEED_EVAL_GRAD, CEED_EVAL_DIV, and CEED_EVAL_CURL 1047004e4986SSebastian Grimberg for (CeedInt in = 0; in < 2; in++) { 1048004e4986SSebastian Grimberg CeedFESpace fespace; 1049004e4986SSebastian Grimberg CeedBasis basis = in ? basis_in : basis_out; 10500d0321e0SJeremy L Thompson 1051004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetFESpace(basis, &fespace)); 1052004e4986SSebastian Grimberg switch (fespace) { 1053004e4986SSebastian Grimberg case CEED_FE_SPACE_H1: { 1054004e4986SSebastian Grimberg CeedInt q_comp_interp, q_comp_grad; 1055004e4986SSebastian Grimberg const CeedScalar *interp, *grad; 1056004e4986SSebastian Grimberg CeedScalar *d_interp, *d_grad; 10570d0321e0SJeremy L Thompson 1058004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, CEED_EVAL_INTERP, &q_comp_interp)); 1059004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, CEED_EVAL_GRAD, &q_comp_grad)); 10600d0321e0SJeremy L Thompson 1061004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetInterp(basis, &interp)); 1062004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&d_interp, interp_bytes * q_comp_interp)); 1063004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMemcpy(d_interp, interp, interp_bytes * q_comp_interp, cudaMemcpyHostToDevice)); 1064004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetGrad(basis, &grad)); 1065004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&d_grad, interp_bytes * q_comp_grad)); 1066004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMemcpy(d_grad, grad, interp_bytes * q_comp_grad, cudaMemcpyHostToDevice)); 1067004e4986SSebastian Grimberg if (in) { 1068004e4986SSebastian Grimberg diag->d_interp_in = d_interp; 1069004e4986SSebastian Grimberg diag->d_grad_in = d_grad; 1070004e4986SSebastian Grimberg } else { 1071004e4986SSebastian Grimberg diag->d_interp_out = d_interp; 1072004e4986SSebastian Grimberg diag->d_grad_out = d_grad; 1073004e4986SSebastian Grimberg } 1074004e4986SSebastian Grimberg } break; 1075004e4986SSebastian Grimberg case CEED_FE_SPACE_HDIV: { 1076004e4986SSebastian Grimberg CeedInt q_comp_interp, q_comp_div; 1077004e4986SSebastian Grimberg const CeedScalar *interp, *div; 1078004e4986SSebastian Grimberg CeedScalar *d_interp, *d_div; 1079004e4986SSebastian Grimberg 1080004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, CEED_EVAL_INTERP, &q_comp_interp)); 1081004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, CEED_EVAL_DIV, &q_comp_div)); 1082004e4986SSebastian Grimberg 1083004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetInterp(basis, &interp)); 1084004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&d_interp, interp_bytes * q_comp_interp)); 1085004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMemcpy(d_interp, interp, interp_bytes * q_comp_interp, cudaMemcpyHostToDevice)); 1086004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetDiv(basis, &div)); 1087004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&d_div, interp_bytes * q_comp_div)); 1088004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMemcpy(d_div, div, interp_bytes * q_comp_div, cudaMemcpyHostToDevice)); 1089004e4986SSebastian Grimberg if (in) { 1090004e4986SSebastian Grimberg diag->d_interp_in = d_interp; 1091004e4986SSebastian Grimberg diag->d_div_in = d_div; 1092004e4986SSebastian Grimberg } else { 1093004e4986SSebastian Grimberg diag->d_interp_out = d_interp; 1094004e4986SSebastian Grimberg diag->d_div_out = d_div; 1095004e4986SSebastian Grimberg } 1096004e4986SSebastian Grimberg } break; 1097004e4986SSebastian Grimberg case CEED_FE_SPACE_HCURL: { 1098004e4986SSebastian Grimberg CeedInt q_comp_interp, q_comp_curl; 1099004e4986SSebastian Grimberg const CeedScalar *interp, *curl; 1100004e4986SSebastian Grimberg CeedScalar *d_interp, *d_curl; 1101004e4986SSebastian Grimberg 1102004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, CEED_EVAL_INTERP, &q_comp_interp)); 1103004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, CEED_EVAL_CURL, &q_comp_curl)); 1104004e4986SSebastian Grimberg 1105004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetInterp(basis, &interp)); 1106004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&d_interp, interp_bytes * q_comp_interp)); 1107004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMemcpy(d_interp, interp, interp_bytes * q_comp_interp, cudaMemcpyHostToDevice)); 1108004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetCurl(basis, &curl)); 1109004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&d_curl, interp_bytes * q_comp_curl)); 1110004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMemcpy(d_curl, curl, interp_bytes * q_comp_curl, cudaMemcpyHostToDevice)); 1111004e4986SSebastian Grimberg if (in) { 1112004e4986SSebastian Grimberg diag->d_interp_in = d_interp; 1113004e4986SSebastian Grimberg diag->d_curl_in = d_curl; 1114004e4986SSebastian Grimberg } else { 1115004e4986SSebastian Grimberg diag->d_interp_out = d_interp; 1116004e4986SSebastian Grimberg diag->d_curl_out = d_curl; 1117004e4986SSebastian Grimberg } 1118004e4986SSebastian Grimberg } break; 1119004e4986SSebastian Grimberg } 1120004e4986SSebastian Grimberg } 1121004e4986SSebastian Grimberg 1122004e4986SSebastian Grimberg // Arrays of eval_modes 1123004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&diag->d_eval_modes_in, num_eval_modes_in * eval_modes_bytes)); 1124004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMemcpy(diag->d_eval_modes_in, eval_modes_in, num_eval_modes_in * eval_modes_bytes, cudaMemcpyHostToDevice)); 1125004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&diag->d_eval_modes_out, num_eval_modes_out * eval_modes_bytes)); 1126004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMemcpy(diag->d_eval_modes_out, eval_modes_out, num_eval_modes_out * eval_modes_bytes, cudaMemcpyHostToDevice)); 1127004e4986SSebastian Grimberg CeedCallBackend(CeedFree(&eval_modes_in)); 1128004e4986SSebastian Grimberg CeedCallBackend(CeedFree(&eval_modes_out)); 11290d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 11300d0321e0SJeremy L Thompson } 11310d0321e0SJeremy L Thompson 11320d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 1133cbfe683aSSebastian Grimberg // Assemble Diagonal Setup (Compilation) 1134cbfe683aSSebastian Grimberg //------------------------------------------------------------------------------ 1135cbfe683aSSebastian Grimberg static inline int CeedOperatorAssembleDiagonalSetupCompile_Cuda(CeedOperator op, CeedInt use_ceedsize_idx, const bool is_point_block) { 1136cbfe683aSSebastian Grimberg Ceed ceed; 113722070f95SJeremy L Thompson char *diagonal_kernel_source; 113822070f95SJeremy L Thompson const char *diagonal_kernel_path; 1139cbfe683aSSebastian Grimberg CeedInt num_input_fields, num_output_fields, num_eval_modes_in = 0, num_eval_modes_out = 0; 1140cbfe683aSSebastian Grimberg CeedInt num_comp, q_comp, num_nodes, num_qpts; 1141cbfe683aSSebastian Grimberg CeedBasis basis_in = NULL, basis_out = NULL; 1142cbfe683aSSebastian Grimberg CeedQFunctionField *qf_fields; 1143cbfe683aSSebastian Grimberg CeedQFunction qf; 1144cbfe683aSSebastian Grimberg CeedOperatorField *op_fields; 1145cbfe683aSSebastian Grimberg CeedOperator_Cuda *impl; 1146cbfe683aSSebastian Grimberg 1147cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 1148cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); 1149cbfe683aSSebastian Grimberg CeedCallBackend(CeedQFunctionGetNumArgs(qf, &num_input_fields, &num_output_fields)); 1150cbfe683aSSebastian Grimberg 1151cbfe683aSSebastian Grimberg // Determine active input basis 1152cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorGetFields(op, NULL, &op_fields, NULL, NULL)); 1153cbfe683aSSebastian Grimberg CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_fields, NULL, NULL)); 1154cbfe683aSSebastian Grimberg for (CeedInt i = 0; i < num_input_fields; i++) { 1155cbfe683aSSebastian Grimberg CeedVector vec; 1156cbfe683aSSebastian Grimberg 1157cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorFieldGetVector(op_fields[i], &vec)); 1158cbfe683aSSebastian Grimberg if (vec == CEED_VECTOR_ACTIVE) { 1159cbfe683aSSebastian Grimberg CeedEvalMode eval_mode; 1160cbfe683aSSebastian Grimberg 1161cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorFieldGetBasis(op_fields[i], &basis_in)); 1162cbfe683aSSebastian Grimberg CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_fields[i], &eval_mode)); 1163cbfe683aSSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis_in, eval_mode, &q_comp)); 1164cbfe683aSSebastian Grimberg if (eval_mode != CEED_EVAL_WEIGHT) { 1165cbfe683aSSebastian Grimberg num_eval_modes_in += q_comp; 1166cbfe683aSSebastian Grimberg } 1167cbfe683aSSebastian Grimberg } 1168cbfe683aSSebastian Grimberg } 1169cbfe683aSSebastian Grimberg 1170cbfe683aSSebastian Grimberg // Determine active output basis 1171cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorGetFields(op, NULL, NULL, NULL, &op_fields)); 1172cbfe683aSSebastian Grimberg CeedCallBackend(CeedQFunctionGetFields(qf, NULL, NULL, NULL, &qf_fields)); 1173cbfe683aSSebastian Grimberg for (CeedInt i = 0; i < num_output_fields; i++) { 1174cbfe683aSSebastian Grimberg CeedVector vec; 1175cbfe683aSSebastian Grimberg 1176cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorFieldGetVector(op_fields[i], &vec)); 1177cbfe683aSSebastian Grimberg if (vec == CEED_VECTOR_ACTIVE) { 1178cbfe683aSSebastian Grimberg CeedEvalMode eval_mode; 1179cbfe683aSSebastian Grimberg 1180cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorFieldGetBasis(op_fields[i], &basis_out)); 1181cbfe683aSSebastian Grimberg CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_fields[i], &eval_mode)); 1182cbfe683aSSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis_out, eval_mode, &q_comp)); 1183cbfe683aSSebastian Grimberg if (eval_mode != CEED_EVAL_WEIGHT) { 1184cbfe683aSSebastian Grimberg num_eval_modes_out += q_comp; 1185cbfe683aSSebastian Grimberg } 1186cbfe683aSSebastian Grimberg } 1187cbfe683aSSebastian Grimberg } 1188cbfe683aSSebastian Grimberg 1189cbfe683aSSebastian Grimberg // Operator data struct 1190cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorGetData(op, &impl)); 1191cbfe683aSSebastian Grimberg CeedOperatorDiag_Cuda *diag = impl->diag; 1192cbfe683aSSebastian Grimberg 1193cbfe683aSSebastian Grimberg // Assemble kernel 1194cbfe683aSSebastian Grimberg CUmodule *module = is_point_block ? &diag->module_point_block : &diag->module; 1195cbfe683aSSebastian Grimberg CeedInt elems_per_block = 1; 1196cbfe683aSSebastian Grimberg CeedCallBackend(CeedBasisGetNumNodes(basis_in, &num_nodes)); 1197cbfe683aSSebastian Grimberg CeedCallBackend(CeedBasisGetNumComponents(basis_in, &num_comp)); 1198cbfe683aSSebastian Grimberg if (basis_in == CEED_BASIS_NONE) num_qpts = num_nodes; 1199cbfe683aSSebastian Grimberg else CeedCallBackend(CeedBasisGetNumQuadraturePoints(basis_in, &num_qpts)); 1200cbfe683aSSebastian Grimberg CeedCallBackend(CeedGetJitAbsolutePath(ceed, "ceed/jit-source/cuda/cuda-ref-operator-assemble-diagonal.h", &diagonal_kernel_path)); 1201cbfe683aSSebastian Grimberg CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading Diagonal Assembly Kernel Source -----\n"); 1202cbfe683aSSebastian Grimberg CeedCallBackend(CeedLoadSourceToBuffer(ceed, diagonal_kernel_path, &diagonal_kernel_source)); 1203cbfe683aSSebastian Grimberg CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading Diagonal Assembly Source Complete! -----\n"); 1204cbfe683aSSebastian Grimberg CeedCallCuda(ceed, CeedCompile_Cuda(ceed, diagonal_kernel_source, module, 8, "NUM_EVAL_MODES_IN", num_eval_modes_in, "NUM_EVAL_MODES_OUT", 1205cbfe683aSSebastian Grimberg num_eval_modes_out, "NUM_COMP", num_comp, "NUM_NODES", num_nodes, "NUM_QPTS", num_qpts, "USE_CEEDSIZE", 1206cbfe683aSSebastian Grimberg use_ceedsize_idx, "USE_POINT_BLOCK", is_point_block ? 1 : 0, "BLOCK_SIZE", num_nodes * elems_per_block)); 1207cbfe683aSSebastian Grimberg CeedCallCuda(ceed, CeedGetKernel_Cuda(ceed, *module, "LinearDiagonal", is_point_block ? &diag->LinearPointBlock : &diag->LinearDiagonal)); 1208cbfe683aSSebastian Grimberg CeedCallBackend(CeedFree(&diagonal_kernel_path)); 1209cbfe683aSSebastian Grimberg CeedCallBackend(CeedFree(&diagonal_kernel_source)); 1210cbfe683aSSebastian Grimberg return CEED_ERROR_SUCCESS; 1211cbfe683aSSebastian Grimberg } 1212cbfe683aSSebastian Grimberg 1213cbfe683aSSebastian Grimberg //------------------------------------------------------------------------------ 1214004e4986SSebastian Grimberg // Assemble Diagonal Core 12150d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 1216ca735530SJeremy L Thompson static inline int CeedOperatorAssembleDiagonalCore_Cuda(CeedOperator op, CeedVector assembled, CeedRequest *request, const bool is_point_block) { 12170d0321e0SJeremy L Thompson Ceed ceed; 1218cbfe683aSSebastian Grimberg CeedInt num_elem, num_nodes; 1219ca735530SJeremy L Thompson CeedScalar *elem_diag_array; 1220ca735530SJeremy L Thompson const CeedScalar *assembled_qf_array; 1221004e4986SSebastian Grimberg CeedVector assembled_qf = NULL, elem_diag; 1222004e4986SSebastian Grimberg CeedElemRestriction assembled_rstr = NULL, rstr_in, rstr_out, diag_rstr; 12230d0321e0SJeremy L Thompson CeedOperator_Cuda *impl; 1224ca735530SJeremy L Thompson 1225ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 12262b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 12270d0321e0SJeremy L Thompson 12280d0321e0SJeremy L Thompson // Assemble QFunction 1229004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorLinearAssembleQFunctionBuildOrUpdate(op, &assembled_qf, &assembled_rstr, request)); 1230004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionDestroy(&assembled_rstr)); 1231004e4986SSebastian Grimberg CeedCallBackend(CeedVectorGetArrayRead(assembled_qf, CEED_MEM_DEVICE, &assembled_qf_array)); 12320d0321e0SJeremy L Thompson 1233cbfe683aSSebastian Grimberg // Setup 1234cbfe683aSSebastian Grimberg if (!impl->diag) CeedCallBackend(CeedOperatorAssembleDiagonalSetup_Cuda(op)); 1235cbfe683aSSebastian Grimberg CeedOperatorDiag_Cuda *diag = impl->diag; 1236cbfe683aSSebastian Grimberg 1237cbfe683aSSebastian Grimberg assert(diag != NULL); 1238cbfe683aSSebastian Grimberg 1239cbfe683aSSebastian Grimberg // Assemble kernel if needed 1240cbfe683aSSebastian Grimberg if ((!is_point_block && !diag->LinearDiagonal) || (is_point_block && !diag->LinearPointBlock)) { 1241cbfe683aSSebastian Grimberg CeedSize assembled_length, assembled_qf_length; 1242cbfe683aSSebastian Grimberg CeedInt use_ceedsize_idx = 0; 1243f7c1b517Snbeams CeedCallBackend(CeedVectorGetLength(assembled, &assembled_length)); 1244ca735530SJeremy L Thompson CeedCallBackend(CeedVectorGetLength(assembled_qf, &assembled_qf_length)); 1245ca735530SJeremy L Thompson if ((assembled_length > INT_MAX) || (assembled_qf_length > INT_MAX)) use_ceedsize_idx = 1; 1246f7c1b517Snbeams 1247cbfe683aSSebastian Grimberg CeedCallBackend(CeedOperatorAssembleDiagonalSetupCompile_Cuda(op, use_ceedsize_idx, is_point_block)); 1248cbfe683aSSebastian Grimberg } 12490d0321e0SJeremy L Thompson 1250004e4986SSebastian Grimberg // Restriction and diagonal vector 1251004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorGetActiveElemRestrictions(op, &rstr_in, &rstr_out)); 1252004e4986SSebastian Grimberg CeedCheck(rstr_in == rstr_out, ceed, CEED_ERROR_BACKEND, 1253004e4986SSebastian Grimberg "Cannot assemble operator diagonal with different input and output active element restrictions"); 1254004e4986SSebastian Grimberg if (!is_point_block && !diag->diag_rstr) { 1255004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionCreateUnsignedCopy(rstr_out, &diag->diag_rstr)); 1256004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionCreateVector(diag->diag_rstr, NULL, &diag->elem_diag)); 1257004e4986SSebastian Grimberg } else if (is_point_block && !diag->point_block_diag_rstr) { 1258004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorCreateActivePointBlockRestriction(rstr_out, &diag->point_block_diag_rstr)); 1259004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionCreateVector(diag->point_block_diag_rstr, NULL, &diag->point_block_elem_diag)); 12600d0321e0SJeremy L Thompson } 1261004e4986SSebastian Grimberg diag_rstr = is_point_block ? diag->point_block_diag_rstr : diag->diag_rstr; 1262004e4986SSebastian Grimberg elem_diag = is_point_block ? diag->point_block_elem_diag : diag->elem_diag; 1263ca735530SJeremy L Thompson CeedCallBackend(CeedVectorSetValue(elem_diag, 0.0)); 12640d0321e0SJeremy L Thompson 126591db28b6SZach Atkins // Only assemble diagonal if the basis has nodes, otherwise inputs are null pointers 1266004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetElementSize(diag_rstr, &num_nodes)); 1267004e4986SSebastian Grimberg if (num_nodes > 0) { 12680d0321e0SJeremy L Thompson // Assemble element operator diagonals 1269ca735530SJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetNumElements(diag_rstr, &num_elem)); 1270004e4986SSebastian Grimberg CeedCallBackend(CeedVectorGetArray(elem_diag, CEED_MEM_DEVICE, &elem_diag_array)); 12710d0321e0SJeremy L Thompson 12720d0321e0SJeremy L Thompson // Compute the diagonal of B^T D B 1273004e4986SSebastian Grimberg CeedInt elems_per_block = 1; 1274004e4986SSebastian Grimberg CeedInt grid = CeedDivUpInt(num_elem, elems_per_block); 1275004e4986SSebastian Grimberg void *args[] = {(void *)&num_elem, &diag->d_identity, &diag->d_interp_in, &diag->d_grad_in, &diag->d_div_in, 1276004e4986SSebastian Grimberg &diag->d_curl_in, &diag->d_interp_out, &diag->d_grad_out, &diag->d_div_out, &diag->d_curl_out, 1277004e4986SSebastian Grimberg &diag->d_eval_modes_in, &diag->d_eval_modes_out, &assembled_qf_array, &elem_diag_array}; 1278004e4986SSebastian Grimberg 1279ca735530SJeremy L Thompson if (is_point_block) { 1280004e4986SSebastian Grimberg CeedCallBackend(CeedRunKernelDim_Cuda(ceed, diag->LinearPointBlock, grid, num_nodes, 1, elems_per_block, args)); 12810d0321e0SJeremy L Thompson } else { 1282004e4986SSebastian Grimberg CeedCallBackend(CeedRunKernelDim_Cuda(ceed, diag->LinearDiagonal, grid, num_nodes, 1, elems_per_block, args)); 12830d0321e0SJeremy L Thompson } 12840d0321e0SJeremy L Thompson 12850d0321e0SJeremy L Thompson // Restore arrays 1286ca735530SJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(elem_diag, &elem_diag_array)); 1287ca735530SJeremy L Thompson CeedCallBackend(CeedVectorRestoreArrayRead(assembled_qf, &assembled_qf_array)); 128891db28b6SZach Atkins } 12890d0321e0SJeremy L Thompson 12900d0321e0SJeremy L Thompson // Assemble local operator diagonal 1291ca735530SJeremy L Thompson CeedCallBackend(CeedElemRestrictionApply(diag_rstr, CEED_TRANSPOSE, elem_diag, assembled, request)); 12920d0321e0SJeremy L Thompson 12930d0321e0SJeremy L Thompson // Cleanup 1294ca735530SJeremy L Thompson CeedCallBackend(CeedVectorDestroy(&assembled_qf)); 12950d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 12960d0321e0SJeremy L Thompson } 12970d0321e0SJeremy L Thompson 12980d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 12990d0321e0SJeremy L Thompson // Assemble Linear Diagonal 13000d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 13012b730f8bSJeremy L Thompson static int CeedOperatorLinearAssembleAddDiagonal_Cuda(CeedOperator op, CeedVector assembled, CeedRequest *request) { 13022b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorAssembleDiagonalCore_Cuda(op, assembled, request, false)); 13036aa95790SJeremy L Thompson return CEED_ERROR_SUCCESS; 13040d0321e0SJeremy L Thompson } 13050d0321e0SJeremy L Thompson 13060d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 13070d0321e0SJeremy L Thompson // Assemble Linear Point Block Diagonal 13080d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 13092b730f8bSJeremy L Thompson static int CeedOperatorLinearAssembleAddPointBlockDiagonal_Cuda(CeedOperator op, CeedVector assembled, CeedRequest *request) { 13102b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorAssembleDiagonalCore_Cuda(op, assembled, request, true)); 13116aa95790SJeremy L Thompson return CEED_ERROR_SUCCESS; 13120d0321e0SJeremy L Thompson } 13130d0321e0SJeremy L Thompson 13140d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 1315004e4986SSebastian Grimberg // Single Operator Assembly Setup 1316cc132f9aSnbeams //------------------------------------------------------------------------------ 1317f7c1b517Snbeams static int CeedSingleOperatorAssembleSetup_Cuda(CeedOperator op, CeedInt use_ceedsize_idx) { 1318cc132f9aSnbeams Ceed ceed; 1319004e4986SSebastian Grimberg Ceed_Cuda *cuda_data; 132022070f95SJeremy L Thompson char *assembly_kernel_source; 132122070f95SJeremy L Thompson const char *assembly_kernel_path; 1322004e4986SSebastian Grimberg CeedInt num_input_fields, num_output_fields, num_eval_modes_in = 0, num_eval_modes_out = 0; 13233b38d1dfSJeremy L Thompson CeedInt elem_size_in, num_qpts_in = 0, num_comp_in, elem_size_out, num_qpts_out, num_comp_out, q_comp; 1324004e4986SSebastian Grimberg CeedEvalMode *eval_modes_in = NULL, *eval_modes_out = NULL; 1325ca735530SJeremy L Thompson CeedElemRestriction rstr_in = NULL, rstr_out = NULL; 1326ca735530SJeremy L Thompson CeedBasis basis_in = NULL, basis_out = NULL; 1327ca735530SJeremy L Thompson CeedQFunctionField *qf_fields; 1328ca735530SJeremy L Thompson CeedQFunction qf; 1329ca735530SJeremy L Thompson CeedOperatorField *input_fields, *output_fields; 1330cc132f9aSnbeams CeedOperator_Cuda *impl; 1331ca735530SJeremy L Thompson 1332ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 13332b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 1334cc132f9aSnbeams 1335cc132f9aSnbeams // Get intput and output fields 13362b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &input_fields, &num_output_fields, &output_fields)); 1337cc132f9aSnbeams 1338cc132f9aSnbeams // Determine active input basis eval mode 13392b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); 13402b730f8bSJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_fields, NULL, NULL)); 1341cc132f9aSnbeams for (CeedInt i = 0; i < num_input_fields; i++) { 1342cc132f9aSnbeams CeedVector vec; 1343ca735530SJeremy L Thompson 13442b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(input_fields[i], &vec)); 1345cc132f9aSnbeams if (vec == CEED_VECTOR_ACTIVE) { 1346004e4986SSebastian Grimberg CeedBasis basis; 1347ca735530SJeremy L Thompson CeedEvalMode eval_mode; 1348ca735530SJeremy L Thompson 1349004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorFieldGetBasis(input_fields[i], &basis)); 1350004e4986SSebastian Grimberg CeedCheck(!basis_in || basis_in == basis, ceed, CEED_ERROR_BACKEND, "Backend does not implement operator assembly with multiple active bases"); 1351004e4986SSebastian Grimberg basis_in = basis; 13522b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(input_fields[i], &rstr_in)); 1353004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetElementSize(rstr_in, &elem_size_in)); 1354004e4986SSebastian Grimberg if (basis_in == CEED_BASIS_NONE) num_qpts_in = elem_size_in; 1355004e4986SSebastian Grimberg else CeedCallBackend(CeedBasisGetNumQuadraturePoints(basis_in, &num_qpts_in)); 13562b730f8bSJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_fields[i], &eval_mode)); 1357004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis_in, eval_mode, &q_comp)); 1358004e4986SSebastian Grimberg if (eval_mode != CEED_EVAL_WEIGHT) { 1359004e4986SSebastian Grimberg // q_comp = 1 if CEED_EVAL_NONE, CEED_EVAL_WEIGHT caught by QF Assembly 1360004e4986SSebastian Grimberg CeedCallBackend(CeedRealloc(num_eval_modes_in + q_comp, &eval_modes_in)); 1361004e4986SSebastian Grimberg for (CeedInt d = 0; d < q_comp; d++) { 1362004e4986SSebastian Grimberg eval_modes_in[num_eval_modes_in + d] = eval_mode; 1363cc132f9aSnbeams } 1364004e4986SSebastian Grimberg num_eval_modes_in += q_comp; 1365cc132f9aSnbeams } 1366cc132f9aSnbeams } 1367cc132f9aSnbeams } 1368cc132f9aSnbeams 1369cc132f9aSnbeams // Determine active output basis; basis_out and rstr_out only used if same as input, TODO 13702b730f8bSJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, NULL, NULL, &qf_fields)); 1371cc132f9aSnbeams for (CeedInt i = 0; i < num_output_fields; i++) { 1372cc132f9aSnbeams CeedVector vec; 1373ca735530SJeremy L Thompson 13742b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(output_fields[i], &vec)); 1375cc132f9aSnbeams if (vec == CEED_VECTOR_ACTIVE) { 1376004e4986SSebastian Grimberg CeedBasis basis; 1377ca735530SJeremy L Thompson CeedEvalMode eval_mode; 1378ca735530SJeremy L Thompson 1379004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorFieldGetBasis(output_fields[i], &basis)); 1380004e4986SSebastian Grimberg CeedCheck(!basis_out || basis_out == basis, ceed, CEED_ERROR_BACKEND, 1381004e4986SSebastian Grimberg "Backend does not implement operator assembly with multiple active bases"); 1382004e4986SSebastian Grimberg basis_out = basis; 13832b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(output_fields[i], &rstr_out)); 1384004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetElementSize(rstr_out, &elem_size_out)); 1385004e4986SSebastian Grimberg if (basis_out == CEED_BASIS_NONE) num_qpts_out = elem_size_out; 1386004e4986SSebastian Grimberg else CeedCallBackend(CeedBasisGetNumQuadraturePoints(basis_out, &num_qpts_out)); 1387004e4986SSebastian Grimberg CeedCheck(num_qpts_in == num_qpts_out, ceed, CEED_ERROR_UNSUPPORTED, 1388004e4986SSebastian Grimberg "Active input and output bases must have the same number of quadrature points"); 13892b730f8bSJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_fields[i], &eval_mode)); 1390004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis_out, eval_mode, &q_comp)); 1391004e4986SSebastian Grimberg if (eval_mode != CEED_EVAL_WEIGHT) { 1392004e4986SSebastian Grimberg // q_comp = 1 if CEED_EVAL_NONE, CEED_EVAL_WEIGHT caught by QF Assembly 1393004e4986SSebastian Grimberg CeedCallBackend(CeedRealloc(num_eval_modes_out + q_comp, &eval_modes_out)); 1394004e4986SSebastian Grimberg for (CeedInt d = 0; d < q_comp; d++) { 1395004e4986SSebastian Grimberg eval_modes_out[num_eval_modes_out + d] = eval_mode; 1396004e4986SSebastian Grimberg } 1397004e4986SSebastian Grimberg num_eval_modes_out += q_comp; 1398cc132f9aSnbeams } 1399cc132f9aSnbeams } 1400cc132f9aSnbeams } 1401004e4986SSebastian Grimberg CeedCheck(num_eval_modes_in > 0 && num_eval_modes_out > 0, ceed, CEED_ERROR_UNSUPPORTED, "Cannot assemble operator without inputs/outputs"); 1402cc132f9aSnbeams 14032b730f8bSJeremy L Thompson CeedCallBackend(CeedCalloc(1, &impl->asmb)); 1404cc132f9aSnbeams CeedOperatorAssemble_Cuda *asmb = impl->asmb; 1405004e4986SSebastian Grimberg asmb->elems_per_block = 1; 1406004e4986SSebastian Grimberg asmb->block_size_x = elem_size_in; 1407004e4986SSebastian Grimberg asmb->block_size_y = elem_size_out; 1408ca735530SJeremy L Thompson 14092b730f8bSJeremy L Thompson CeedCallBackend(CeedGetData(ceed, &cuda_data)); 1410004e4986SSebastian Grimberg bool fallback = asmb->block_size_x * asmb->block_size_y * asmb->elems_per_block > cuda_data->device_prop.maxThreadsPerBlock; 1411004e4986SSebastian Grimberg 1412004e4986SSebastian Grimberg if (fallback) { 1413004e4986SSebastian Grimberg // Use fallback kernel with 1D threadblock 1414004e4986SSebastian Grimberg asmb->block_size_y = 1; 1415004e4986SSebastian Grimberg } 1416004e4986SSebastian Grimberg 1417004e4986SSebastian Grimberg // Compile kernels 1418004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetNumComponents(rstr_in, &num_comp_in)); 1419004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetNumComponents(rstr_out, &num_comp_out)); 14202b730f8bSJeremy L Thompson CeedCallBackend(CeedGetJitAbsolutePath(ceed, "ceed/jit-source/cuda/cuda-ref-operator-assemble.h", &assembly_kernel_path)); 142123d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading Assembly Kernel Source -----\n"); 14222b730f8bSJeremy L Thompson CeedCallBackend(CeedLoadSourceToBuffer(ceed, assembly_kernel_path, &assembly_kernel_source)); 142323d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading Assembly Source Complete! -----\n"); 1424004e4986SSebastian Grimberg CeedCallBackend(CeedCompile_Cuda(ceed, assembly_kernel_source, &asmb->module, 10, "NUM_EVAL_MODES_IN", num_eval_modes_in, "NUM_EVAL_MODES_OUT", 1425004e4986SSebastian Grimberg num_eval_modes_out, "NUM_COMP_IN", num_comp_in, "NUM_COMP_OUT", num_comp_out, "NUM_NODES_IN", elem_size_in, 1426004e4986SSebastian Grimberg "NUM_NODES_OUT", elem_size_out, "NUM_QPTS", num_qpts_in, "BLOCK_SIZE", 1427cbfe683aSSebastian Grimberg asmb->block_size_x * asmb->block_size_y * asmb->elems_per_block, "BLOCK_SIZE_Y", asmb->block_size_y, 1428cbfe683aSSebastian Grimberg "USE_CEEDSIZE", use_ceedsize_idx)); 1429004e4986SSebastian Grimberg CeedCallBackend(CeedGetKernel_Cuda(ceed, asmb->module, "LinearAssemble", &asmb->LinearAssemble)); 14302b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&assembly_kernel_path)); 14312b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&assembly_kernel_source)); 1432cc132f9aSnbeams 1433004e4986SSebastian Grimberg // Load into B_in, in order that they will be used in eval_modes_in 1434004e4986SSebastian Grimberg { 1435004e4986SSebastian Grimberg const CeedInt in_bytes = elem_size_in * num_qpts_in * num_eval_modes_in * sizeof(CeedScalar); 1436004e4986SSebastian Grimberg CeedInt d_in = 0; 1437004e4986SSebastian Grimberg CeedEvalMode eval_modes_in_prev = CEED_EVAL_NONE; 1438004e4986SSebastian Grimberg bool has_eval_none = false; 1439004e4986SSebastian Grimberg CeedScalar *identity = NULL; 1440ca735530SJeremy L Thompson 1441004e4986SSebastian Grimberg for (CeedInt i = 0; i < num_eval_modes_in; i++) { 1442004e4986SSebastian Grimberg has_eval_none = has_eval_none || (eval_modes_in[i] == CEED_EVAL_NONE); 1443004e4986SSebastian Grimberg } 1444004e4986SSebastian Grimberg if (has_eval_none) { 1445004e4986SSebastian Grimberg CeedCallBackend(CeedCalloc(elem_size_in * num_qpts_in, &identity)); 1446004e4986SSebastian 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; 1447004e4986SSebastian Grimberg } 1448cc132f9aSnbeams 1449004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&asmb->d_B_in, in_bytes)); 1450004e4986SSebastian Grimberg for (CeedInt i = 0; i < num_eval_modes_in; i++) { 1451004e4986SSebastian Grimberg const CeedScalar *h_B_in; 1452ca735530SJeremy L Thompson 1453004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorGetBasisPointer(basis_in, eval_modes_in[i], identity, &h_B_in)); 1454004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis_in, eval_modes_in[i], &q_comp)); 1455004e4986SSebastian Grimberg if (q_comp > 1) { 1456004e4986SSebastian Grimberg if (i == 0 || eval_modes_in[i] != eval_modes_in_prev) d_in = 0; 1457004e4986SSebastian Grimberg else h_B_in = &h_B_in[(++d_in) * elem_size_in * num_qpts_in]; 1458004e4986SSebastian Grimberg } 1459004e4986SSebastian Grimberg eval_modes_in_prev = eval_modes_in[i]; 1460ca735530SJeremy L Thompson 1461004e4986SSebastian 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), 1462004e4986SSebastian Grimberg cudaMemcpyHostToDevice)); 1463004e4986SSebastian Grimberg } 1464004e4986SSebastian Grimberg 1465004e4986SSebastian Grimberg if (identity) { 1466004e4986SSebastian Grimberg CeedCallBackend(CeedFree(&identity)); 1467cc132f9aSnbeams } 1468cc132f9aSnbeams } 1469cc132f9aSnbeams 1470004e4986SSebastian Grimberg // Load into B_out, in order that they will be used in eval_modes_out 1471004e4986SSebastian Grimberg { 1472004e4986SSebastian Grimberg const CeedInt out_bytes = elem_size_out * num_qpts_out * num_eval_modes_out * sizeof(CeedScalar); 1473004e4986SSebastian Grimberg CeedInt d_out = 0; 1474004e4986SSebastian Grimberg CeedEvalMode eval_modes_out_prev = CEED_EVAL_NONE; 1475004e4986SSebastian Grimberg bool has_eval_none = false; 1476004e4986SSebastian Grimberg CeedScalar *identity = NULL; 1477ca735530SJeremy L Thompson 1478004e4986SSebastian Grimberg for (CeedInt i = 0; i < num_eval_modes_out; i++) { 1479004e4986SSebastian Grimberg has_eval_none = has_eval_none || (eval_modes_out[i] == CEED_EVAL_NONE); 1480004e4986SSebastian Grimberg } 1481004e4986SSebastian Grimberg if (has_eval_none) { 1482004e4986SSebastian Grimberg CeedCallBackend(CeedCalloc(elem_size_out * num_qpts_out, &identity)); 1483004e4986SSebastian 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; 1484cc132f9aSnbeams } 1485cc132f9aSnbeams 1486004e4986SSebastian Grimberg CeedCallCuda(ceed, cudaMalloc((void **)&asmb->d_B_out, out_bytes)); 1487004e4986SSebastian Grimberg for (CeedInt i = 0; i < num_eval_modes_out; i++) { 1488004e4986SSebastian Grimberg const CeedScalar *h_B_out; 1489ca735530SJeremy L Thompson 1490004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorGetBasisPointer(basis_out, eval_modes_out[i], identity, &h_B_out)); 1491004e4986SSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis_out, eval_modes_out[i], &q_comp)); 1492004e4986SSebastian Grimberg if (q_comp > 1) { 1493004e4986SSebastian Grimberg if (i == 0 || eval_modes_out[i] != eval_modes_out_prev) d_out = 0; 1494004e4986SSebastian Grimberg else h_B_out = &h_B_out[(++d_out) * elem_size_out * num_qpts_out]; 1495004e4986SSebastian Grimberg } 1496004e4986SSebastian Grimberg eval_modes_out_prev = eval_modes_out[i]; 1497ca735530SJeremy L Thompson 1498004e4986SSebastian 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), 1499004e4986SSebastian Grimberg cudaMemcpyHostToDevice)); 1500004e4986SSebastian Grimberg } 1501004e4986SSebastian Grimberg 1502004e4986SSebastian Grimberg if (identity) { 1503004e4986SSebastian Grimberg CeedCallBackend(CeedFree(&identity)); 1504cc132f9aSnbeams } 1505cc132f9aSnbeams } 1506cc132f9aSnbeams return CEED_ERROR_SUCCESS; 1507cc132f9aSnbeams } 1508cc132f9aSnbeams 1509cc132f9aSnbeams //------------------------------------------------------------------------------ 1510cefa2673SJeremy L Thompson // Assemble matrix data for COO matrix of assembled operator. 1511cefa2673SJeremy L Thompson // The sparsity pattern is set by CeedOperatorLinearAssembleSymbolic. 1512cefa2673SJeremy L Thompson // 1513ea61e9acSJeremy L Thompson // Note that this (and other assembly routines) currently assume only one active input restriction/basis per operator (could have multiple basis eval 1514cefa2673SJeremy L Thompson // modes). 1515cefa2673SJeremy L Thompson // TODO: allow multiple active input restrictions/basis objects 1516cc132f9aSnbeams //------------------------------------------------------------------------------ 15172b730f8bSJeremy L Thompson static int CeedSingleOperatorAssemble_Cuda(CeedOperator op, CeedInt offset, CeedVector values) { 1518cc132f9aSnbeams Ceed ceed; 1519ca735530SJeremy L Thompson CeedSize values_length = 0, assembled_qf_length = 0; 1520004e4986SSebastian Grimberg CeedInt use_ceedsize_idx = 0, num_elem_in, num_elem_out, elem_size_in, elem_size_out; 1521ca735530SJeremy L Thompson CeedScalar *values_array; 1522004e4986SSebastian Grimberg const CeedScalar *assembled_qf_array; 1523ca735530SJeremy L Thompson CeedVector assembled_qf = NULL; 1524004e4986SSebastian Grimberg CeedElemRestriction assembled_rstr = NULL, rstr_in, rstr_out; 1525004e4986SSebastian Grimberg CeedRestrictionType rstr_type_in, rstr_type_out; 1526004e4986SSebastian Grimberg const bool *orients_in = NULL, *orients_out = NULL; 1527004e4986SSebastian Grimberg const CeedInt8 *curl_orients_in = NULL, *curl_orients_out = NULL; 1528cc132f9aSnbeams CeedOperator_Cuda *impl; 1529ca735530SJeremy L Thompson 1530ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 15312b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 1532cc132f9aSnbeams 1533cc132f9aSnbeams // Assemble QFunction 1534004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorLinearAssembleQFunctionBuildOrUpdate(op, &assembled_qf, &assembled_rstr, CEED_REQUEST_IMMEDIATE)); 1535004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionDestroy(&assembled_rstr)); 1536004e4986SSebastian Grimberg CeedCallBackend(CeedVectorGetArrayRead(assembled_qf, CEED_MEM_DEVICE, &assembled_qf_array)); 1537cc132f9aSnbeams 1538f7c1b517Snbeams CeedCallBackend(CeedVectorGetLength(values, &values_length)); 1539f7c1b517Snbeams CeedCallBackend(CeedVectorGetLength(assembled_qf, &assembled_qf_length)); 1540f7c1b517Snbeams if ((values_length > INT_MAX) || (assembled_qf_length > INT_MAX)) use_ceedsize_idx = 1; 1541004e4986SSebastian Grimberg 1542f7c1b517Snbeams // Setup 1543004e4986SSebastian Grimberg if (!impl->asmb) CeedCallBackend(CeedSingleOperatorAssembleSetup_Cuda(op, use_ceedsize_idx)); 1544004e4986SSebastian Grimberg CeedOperatorAssemble_Cuda *asmb = impl->asmb; 1545004e4986SSebastian Grimberg 1546004e4986SSebastian Grimberg assert(asmb != NULL); 1547004e4986SSebastian Grimberg 1548004e4986SSebastian Grimberg // Assemble element operator 1549004e4986SSebastian Grimberg CeedCallBackend(CeedVectorGetArray(values, CEED_MEM_DEVICE, &values_array)); 1550004e4986SSebastian Grimberg values_array += offset; 1551004e4986SSebastian Grimberg 1552004e4986SSebastian Grimberg CeedCallBackend(CeedOperatorGetActiveElemRestrictions(op, &rstr_in, &rstr_out)); 1553004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetNumElements(rstr_in, &num_elem_in)); 1554004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetElementSize(rstr_in, &elem_size_in)); 1555004e4986SSebastian Grimberg 1556004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetType(rstr_in, &rstr_type_in)); 1557004e4986SSebastian Grimberg if (rstr_type_in == CEED_RESTRICTION_ORIENTED) { 1558004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetOrientations(rstr_in, CEED_MEM_DEVICE, &orients_in)); 1559004e4986SSebastian Grimberg } else if (rstr_type_in == CEED_RESTRICTION_CURL_ORIENTED) { 1560004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetCurlOrientations(rstr_in, CEED_MEM_DEVICE, &curl_orients_in)); 1561004e4986SSebastian Grimberg } 1562004e4986SSebastian Grimberg 1563004e4986SSebastian Grimberg if (rstr_in != rstr_out) { 1564004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetNumElements(rstr_out, &num_elem_out)); 1565004e4986SSebastian Grimberg CeedCheck(num_elem_in == num_elem_out, ceed, CEED_ERROR_UNSUPPORTED, 1566004e4986SSebastian Grimberg "Active input and output operator restrictions must have the same number of elements"); 1567004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetElementSize(rstr_out, &elem_size_out)); 1568004e4986SSebastian Grimberg 1569004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetType(rstr_out, &rstr_type_out)); 1570004e4986SSebastian Grimberg if (rstr_type_out == CEED_RESTRICTION_ORIENTED) { 1571004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetOrientations(rstr_out, CEED_MEM_DEVICE, &orients_out)); 1572004e4986SSebastian Grimberg } else if (rstr_type_out == CEED_RESTRICTION_CURL_ORIENTED) { 1573004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionGetCurlOrientations(rstr_out, CEED_MEM_DEVICE, &curl_orients_out)); 1574004e4986SSebastian Grimberg } 1575004e4986SSebastian Grimberg } else { 1576004e4986SSebastian Grimberg elem_size_out = elem_size_in; 1577004e4986SSebastian Grimberg orients_out = orients_in; 1578004e4986SSebastian Grimberg curl_orients_out = curl_orients_in; 1579f7c1b517Snbeams } 1580f7c1b517Snbeams 1581cc132f9aSnbeams // Compute B^T D B 1582004e4986SSebastian Grimberg CeedInt shared_mem = 1583004e4986SSebastian 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)) * 1584004e4986SSebastian Grimberg sizeof(CeedScalar); 1585004e4986SSebastian Grimberg CeedInt grid = CeedDivUpInt(num_elem_in, asmb->elems_per_block); 1586004e4986SSebastian Grimberg void *args[] = {(void *)&num_elem_in, &asmb->d_B_in, &asmb->d_B_out, &orients_in, &curl_orients_in, 1587004e4986SSebastian Grimberg &orients_out, &curl_orients_out, &assembled_qf_array, &values_array}; 1588ca735530SJeremy L Thompson 15892b730f8bSJeremy L Thompson CeedCallBackend( 1590004e4986SSebastian Grimberg CeedRunKernelDimShared_Cuda(ceed, asmb->LinearAssemble, grid, asmb->block_size_x, asmb->block_size_y, asmb->elems_per_block, shared_mem, args)); 1591cc132f9aSnbeams 1592cc132f9aSnbeams // Restore arrays 15932b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(values, &values_array)); 1594004e4986SSebastian Grimberg CeedCallBackend(CeedVectorRestoreArrayRead(assembled_qf, &assembled_qf_array)); 1595cc132f9aSnbeams 1596cc132f9aSnbeams // Cleanup 15972b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorDestroy(&assembled_qf)); 1598004e4986SSebastian Grimberg if (rstr_type_in == CEED_RESTRICTION_ORIENTED) { 1599004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionRestoreOrientations(rstr_in, &orients_in)); 1600004e4986SSebastian Grimberg } else if (rstr_type_in == CEED_RESTRICTION_CURL_ORIENTED) { 1601004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionRestoreCurlOrientations(rstr_in, &curl_orients_in)); 1602004e4986SSebastian Grimberg } 1603004e4986SSebastian Grimberg if (rstr_in != rstr_out) { 1604004e4986SSebastian Grimberg if (rstr_type_out == CEED_RESTRICTION_ORIENTED) { 1605004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionRestoreOrientations(rstr_out, &orients_out)); 1606004e4986SSebastian Grimberg } else if (rstr_type_out == CEED_RESTRICTION_CURL_ORIENTED) { 1607004e4986SSebastian Grimberg CeedCallBackend(CeedElemRestrictionRestoreCurlOrientations(rstr_out, &curl_orients_out)); 1608004e4986SSebastian Grimberg } 1609004e4986SSebastian Grimberg } 1610cc132f9aSnbeams return CEED_ERROR_SUCCESS; 1611cc132f9aSnbeams } 1612cc132f9aSnbeams 1613cc132f9aSnbeams //------------------------------------------------------------------------------ 1614756ca9e9SJeremy L Thompson // Assemble Linear QFunction AtPoints 1615756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 1616756ca9e9SJeremy L Thompson static int CeedOperatorLinearAssembleQFunctionAtPoints_Cuda(CeedOperator op, CeedVector *assembled, CeedElemRestriction *rstr, CeedRequest *request) { 1617756ca9e9SJeremy L Thompson return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_BACKEND, "Backend does not implement CeedOperatorLinearAssembleQFunction"); 1618756ca9e9SJeremy L Thompson } 1619756ca9e9SJeremy L Thompson 1620756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 1621756ca9e9SJeremy L Thompson // Assemble Linear Diagonal AtPoints 1622756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 1623756ca9e9SJeremy L Thompson static int CeedOperatorLinearAssembleAddDiagonalAtPoints_Cuda(CeedOperator op, CeedVector assembled, CeedRequest *request) { 1624111870feSJeremy L Thompson CeedInt max_num_points, *num_points, num_elem, num_input_fields, num_output_fields; 1625349fb27dSJeremy L Thompson CeedScalar *e_data[2 * CEED_FIELD_MAX] = {NULL}; 1626349fb27dSJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 1627349fb27dSJeremy L Thompson CeedQFunction qf; 1628349fb27dSJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 1629349fb27dSJeremy L Thompson CeedOperator_Cuda *impl; 1630349fb27dSJeremy L Thompson 1631349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorGetData(op, &impl)); 1632349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); 1633349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem)); 1634349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 1635349fb27dSJeremy L Thompson CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields)); 1636349fb27dSJeremy L Thompson 1637349fb27dSJeremy L Thompson // Setup 1638349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorSetupAtPoints_Cuda(op)); 1639111870feSJeremy L Thompson num_points = impl->num_points; 1640349fb27dSJeremy L Thompson max_num_points = impl->max_num_points; 1641349fb27dSJeremy L Thompson 16428a213570SJeremy L Thompson // Create separate output e-vecs 16438a213570SJeremy L Thompson if (impl->has_shared_e_vecs) { 16448a213570SJeremy L Thompson for (CeedInt i = 0; i < impl->num_outputs; i++) { 16458a213570SJeremy L Thompson CeedCallBackend(CeedVectorDestroy(&impl->q_vecs_out[i])); 16468a213570SJeremy L Thompson CeedCallBackend(CeedVectorDestroy(&impl->e_vecs[impl->num_inputs + i])); 16478a213570SJeremy L Thompson } 16488a213570SJeremy 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, 16498a213570SJeremy L Thompson num_input_fields, num_output_fields, max_num_points, num_elem)); 16508a213570SJeremy L Thompson } 16518a213570SJeremy L Thompson impl->has_shared_e_vecs = false; 16528a213570SJeremy L Thompson 1653349fb27dSJeremy L Thompson // Get point coordinates 1654349fb27dSJeremy L Thompson if (!impl->point_coords_elem) { 1655349fb27dSJeremy L Thompson CeedVector point_coords = NULL; 1656349fb27dSJeremy L Thompson CeedElemRestriction rstr_points = NULL; 1657349fb27dSJeremy L Thompson 1658349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorAtPointsGetPoints(op, &rstr_points, &point_coords)); 1659349fb27dSJeremy L Thompson CeedCallBackend(CeedElemRestrictionCreateVector(rstr_points, NULL, &impl->point_coords_elem)); 1660349fb27dSJeremy L Thompson CeedCallBackend(CeedElemRestrictionApply(rstr_points, CEED_NOTRANSPOSE, point_coords, impl->point_coords_elem, request)); 1661349fb27dSJeremy L Thompson } 1662349fb27dSJeremy L Thompson 1663*43e13feeSJeremy L Thompson // Input Evecs and Restriction 1664*43e13feeSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 1665*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorInputRestrict_Cuda(op_input_fields[i], qf_input_fields[i], i, NULL, true, &e_data[i], impl, request)); 1666*43e13feeSJeremy L Thompson } 1667*43e13feeSJeremy 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 1678*43e13feeSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 1679*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorInputBasisAtPoints_Cuda(op_input_fields[i], qf_input_fields[i], i, num_elem, num_points, true, e_data[i], impl)); 1680*43e13feeSJeremy L Thompson } 1681349fb27dSJeremy L Thompson 1682349fb27dSJeremy L Thompson // Output pointers, as necessary 1683349fb27dSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 1684349fb27dSJeremy L Thompson CeedEvalMode eval_mode; 1685349fb27dSJeremy L Thompson 1686349fb27dSJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 1687349fb27dSJeremy L Thompson if (eval_mode == CEED_EVAL_NONE) { 1688349fb27dSJeremy L Thompson // Set the output Q-Vector to use the E-Vector data directly. 1689349fb27dSJeremy L Thompson CeedCallBackend(CeedVectorGetArrayWrite(impl->e_vecs[i + impl->num_inputs], CEED_MEM_DEVICE, &e_data[i + num_input_fields])); 1690349fb27dSJeremy L Thompson CeedCallBackend(CeedVectorSetArray(impl->q_vecs_out[i], CEED_MEM_DEVICE, CEED_USE_POINTER, e_data[i + num_input_fields])); 1691349fb27dSJeremy L Thompson } 1692349fb27dSJeremy L Thompson } 1693349fb27dSJeremy L Thompson 1694349fb27dSJeremy L Thompson // Loop over active fields 1695349fb27dSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 1696382e9c83SJeremy L Thompson bool is_active_at_points = true; 1697382e9c83SJeremy L Thompson CeedInt elem_size = 1, num_comp_active = 1, e_vec_size = 0; 1698382e9c83SJeremy L Thompson CeedRestrictionType rstr_type; 1699382e9c83SJeremy L Thompson CeedVector vec; 1700382e9c83SJeremy L Thompson CeedElemRestriction elem_rstr; 1701382e9c83SJeremy L Thompson 1702382e9c83SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 1703382e9c83SJeremy L Thompson // -- Skip non-active input 1704382e9c83SJeremy L Thompson if (vec != CEED_VECTOR_ACTIVE) continue; 1705382e9c83SJeremy L Thompson 1706382e9c83SJeremy L Thompson // -- Get active restriction type 1707382e9c83SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &elem_rstr)); 1708382e9c83SJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetType(elem_rstr, &rstr_type)); 1709382e9c83SJeremy L Thompson is_active_at_points = rstr_type == CEED_RESTRICTION_POINTS; 1710382e9c83SJeremy L Thompson if (!is_active_at_points) CeedCallBackend(CeedElemRestrictionGetElementSize(elem_rstr, &elem_size)); 1711382e9c83SJeremy L Thompson else elem_size = max_num_points; 1712382e9c83SJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetNumComponents(elem_rstr, &num_comp_active)); 1713382e9c83SJeremy L Thompson 1714382e9c83SJeremy L Thompson e_vec_size = elem_size * num_comp_active; 1715382e9c83SJeremy L Thompson for (CeedInt s = 0; s < e_vec_size; s++) { 1716349fb27dSJeremy L Thompson bool is_active_input = false; 1717349fb27dSJeremy L Thompson CeedEvalMode eval_mode; 1718349fb27dSJeremy L Thompson CeedVector vec; 1719349fb27dSJeremy L Thompson CeedBasis basis; 1720349fb27dSJeremy L Thompson 1721349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 1722349fb27dSJeremy L Thompson // Skip non-active input 1723349fb27dSJeremy L Thompson is_active_input = vec == CEED_VECTOR_ACTIVE; 1724349fb27dSJeremy L Thompson if (!is_active_input) continue; 1725349fb27dSJeremy L Thompson 1726349fb27dSJeremy L Thompson // Update unit vector 172713062808SJeremy L Thompson if (s == 0) CeedCallBackend(CeedVectorSetValue(impl->e_vecs[i], 0.0)); 1728349fb27dSJeremy L Thompson else CeedCallBackend(CeedVectorSetValueStrided(impl->e_vecs[i], s - 1, e_vec_size, 0.0)); 1729349fb27dSJeremy L Thompson CeedCallBackend(CeedVectorSetValueStrided(impl->e_vecs[i], s, e_vec_size, 1.0)); 1730349fb27dSJeremy L Thompson 1731349fb27dSJeremy L Thompson // Basis action 1732349fb27dSJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode)); 1733349fb27dSJeremy L Thompson switch (eval_mode) { 1734349fb27dSJeremy L Thompson case CEED_EVAL_NONE: 1735349fb27dSJeremy L Thompson CeedCallBackend(CeedVectorSetArray(impl->q_vecs_in[i], CEED_MEM_DEVICE, CEED_USE_POINTER, e_data[i])); 1736349fb27dSJeremy L Thompson break; 1737349fb27dSJeremy L Thompson case CEED_EVAL_INTERP: 1738349fb27dSJeremy L Thompson case CEED_EVAL_GRAD: 1739349fb27dSJeremy L Thompson case CEED_EVAL_DIV: 1740349fb27dSJeremy L Thompson case CEED_EVAL_CURL: 1741349fb27dSJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetBasis(op_input_fields[i], &basis)); 1742349fb27dSJeremy L Thompson CeedCallBackend(CeedBasisApplyAtPoints(basis, num_elem, num_points, CEED_NOTRANSPOSE, eval_mode, impl->point_coords_elem, impl->e_vecs[i], 1743349fb27dSJeremy L Thompson impl->q_vecs_in[i])); 1744349fb27dSJeremy L Thompson break; 1745349fb27dSJeremy L Thompson case CEED_EVAL_WEIGHT: 1746349fb27dSJeremy L Thompson break; // No action 1747349fb27dSJeremy L Thompson } 1748349fb27dSJeremy L Thompson 1749349fb27dSJeremy L Thompson // Q function 1750349fb27dSJeremy L Thompson CeedCallBackend(CeedQFunctionApply(qf, num_elem * max_num_points, impl->q_vecs_in, impl->q_vecs_out)); 1751349fb27dSJeremy L Thompson 1752349fb27dSJeremy L Thompson // Output basis apply if needed 1753382e9c83SJeremy L Thompson for (CeedInt j = 0; j < num_output_fields; j++) { 1754349fb27dSJeremy L Thompson bool is_active_output = false; 1755382e9c83SJeremy L Thompson CeedInt elem_size = 0; 1756382e9c83SJeremy L Thompson CeedRestrictionType rstr_type; 1757349fb27dSJeremy L Thompson CeedEvalMode eval_mode; 1758349fb27dSJeremy L Thompson CeedVector vec; 1759349fb27dSJeremy L Thompson CeedElemRestriction elem_rstr; 1760349fb27dSJeremy L Thompson CeedBasis basis; 1761349fb27dSJeremy L Thompson 1762382e9c83SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetVector(op_output_fields[j], &vec)); 1763382e9c83SJeremy L Thompson // ---- Skip non-active output 1764349fb27dSJeremy L Thompson is_active_output = vec == CEED_VECTOR_ACTIVE; 1765349fb27dSJeremy L Thompson if (!is_active_output) continue; 1766349fb27dSJeremy L Thompson 1767382e9c83SJeremy L Thompson // ---- Check if elem size matches 1768382e9c83SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_output_fields[j], &elem_rstr)); 1769382e9c83SJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetType(elem_rstr, &rstr_type)); 1770382e9c83SJeremy L Thompson if (is_active_at_points && rstr_type != CEED_RESTRICTION_POINTS) continue; 1771382e9c83SJeremy L Thompson if (rstr_type == CEED_RESTRICTION_POINTS) { 1772382e9c83SJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetMaxPointsInElement(elem_rstr, &elem_size)); 1773382e9c83SJeremy L Thompson } else { 1774382e9c83SJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetElementSize(elem_rstr, &elem_size)); 1775382e9c83SJeremy L Thompson } 1776382e9c83SJeremy L Thompson { 1777382e9c83SJeremy L Thompson CeedInt num_comp = 0; 1778382e9c83SJeremy L Thompson 1779382e9c83SJeremy L Thompson CeedCallBackend(CeedElemRestrictionGetNumComponents(elem_rstr, &num_comp)); 1780382e9c83SJeremy L Thompson if (e_vec_size != num_comp * elem_size) continue; 1781382e9c83SJeremy L Thompson } 1782382e9c83SJeremy L Thompson 1783349fb27dSJeremy L Thompson // Basis action 1784382e9c83SJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[j], &eval_mode)); 1785349fb27dSJeremy L Thompson switch (eval_mode) { 1786349fb27dSJeremy L Thompson case CEED_EVAL_NONE: 1787382e9c83SJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(impl->e_vecs[j + impl->num_inputs], &e_data[j + num_input_fields])); 1788349fb27dSJeremy L Thompson break; 1789349fb27dSJeremy L Thompson case CEED_EVAL_INTERP: 1790349fb27dSJeremy L Thompson case CEED_EVAL_GRAD: 1791349fb27dSJeremy L Thompson case CEED_EVAL_DIV: 1792349fb27dSJeremy L Thompson case CEED_EVAL_CURL: 1793382e9c83SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetBasis(op_output_fields[j], &basis)); 1794382e9c83SJeremy L Thompson CeedCallBackend(CeedBasisApplyAtPoints(basis, num_elem, num_points, CEED_TRANSPOSE, eval_mode, impl->point_coords_elem, 1795382e9c83SJeremy L Thompson impl->q_vecs_out[j], impl->e_vecs[j + impl->num_inputs])); 1796349fb27dSJeremy L Thompson break; 1797349fb27dSJeremy L Thompson // LCOV_EXCL_START 1798349fb27dSJeremy L Thompson case CEED_EVAL_WEIGHT: { 1799349fb27dSJeremy L Thompson return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_BACKEND, "CEED_EVAL_WEIGHT cannot be an output evaluation mode"); 1800349fb27dSJeremy L Thompson // LCOV_EXCL_STOP 1801349fb27dSJeremy L Thompson } 1802349fb27dSJeremy L Thompson } 1803349fb27dSJeremy L Thompson 1804349fb27dSJeremy L Thompson // Mask output e-vec 1805382e9c83SJeremy L Thompson CeedCallBackend(CeedVectorPointwiseMult(impl->e_vecs[j + impl->num_inputs], impl->e_vecs[i], impl->e_vecs[j + impl->num_inputs])); 1806349fb27dSJeremy L Thompson 1807349fb27dSJeremy L Thompson // Restrict 1808382e9c83SJeremy L Thompson CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_output_fields[j], &elem_rstr)); 1809382e9c83SJeremy L Thompson CeedCallBackend(CeedElemRestrictionApply(elem_rstr, CEED_TRANSPOSE, impl->e_vecs[j + impl->num_inputs], assembled, request)); 1810349fb27dSJeremy L Thompson 1811349fb27dSJeremy L Thompson // Reset q_vec for 1812349fb27dSJeremy L Thompson if (eval_mode == CEED_EVAL_NONE) { 1813382e9c83SJeremy L Thompson CeedCallBackend(CeedVectorGetArrayWrite(impl->e_vecs[j + impl->num_inputs], CEED_MEM_DEVICE, &e_data[j + num_input_fields])); 1814382e9c83SJeremy L Thompson CeedCallBackend(CeedVectorSetArray(impl->q_vecs_out[j], CEED_MEM_DEVICE, CEED_USE_POINTER, e_data[j + num_input_fields])); 1815349fb27dSJeremy L Thompson } 1816349fb27dSJeremy L Thompson } 1817382e9c83SJeremy L Thompson 1818382e9c83SJeremy L Thompson // Reset vec 181913062808SJeremy L Thompson if (s == e_vec_size - 1 && i != num_input_fields - 1) CeedCallBackend(CeedVectorSetValue(impl->q_vecs_in[i], 0.0)); 182086e10729SJeremy L Thompson } 1821349fb27dSJeremy L Thompson } 1822349fb27dSJeremy L Thompson 1823349fb27dSJeremy L Thompson // Restore CEED_EVAL_NONE 1824349fb27dSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 1825349fb27dSJeremy L Thompson CeedEvalMode eval_mode; 1826349fb27dSJeremy L Thompson 1827349fb27dSJeremy L Thompson // Get eval_mode 1828349fb27dSJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 1829349fb27dSJeremy L Thompson 1830349fb27dSJeremy L Thompson // Restore evec 1831349fb27dSJeremy L Thompson CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 1832349fb27dSJeremy L Thompson if (eval_mode == CEED_EVAL_NONE) { 1833349fb27dSJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(impl->e_vecs[i + impl->num_inputs], &e_data[i + num_input_fields])); 1834349fb27dSJeremy L Thompson } 1835349fb27dSJeremy L Thompson } 1836349fb27dSJeremy L Thompson 1837349fb27dSJeremy L Thompson // Restore input arrays 1838*43e13feeSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 1839*43e13feeSJeremy L Thompson CeedCallBackend(CeedOperatorInputRestore_Cuda(op_input_fields[i], qf_input_fields[i], i, true, &e_data[i], impl)); 1840*43e13feeSJeremy L Thompson } 1841349fb27dSJeremy L Thompson return CEED_ERROR_SUCCESS; 1842756ca9e9SJeremy L Thompson } 1843756ca9e9SJeremy L Thompson 1844756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 18450d0321e0SJeremy L Thompson // Create operator 18460d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 18470d0321e0SJeremy L Thompson int CeedOperatorCreate_Cuda(CeedOperator op) { 18480d0321e0SJeremy L Thompson Ceed ceed; 18490d0321e0SJeremy L Thompson CeedOperator_Cuda *impl; 18500d0321e0SJeremy L Thompson 1851ca735530SJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 18522b730f8bSJeremy L Thompson CeedCallBackend(CeedCalloc(1, &impl)); 18532b730f8bSJeremy L Thompson CeedCallBackend(CeedOperatorSetData(op, impl)); 18540d0321e0SJeremy L Thompson 18552b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleQFunction", CeedOperatorLinearAssembleQFunction_Cuda)); 18562b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleQFunctionUpdate", CeedOperatorLinearAssembleQFunctionUpdate_Cuda)); 18572b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleAddDiagonal", CeedOperatorLinearAssembleAddDiagonal_Cuda)); 18582b730f8bSJeremy L Thompson CeedCallBackend( 18592b730f8bSJeremy L Thompson CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleAddPointBlockDiagonal", CeedOperatorLinearAssembleAddPointBlockDiagonal_Cuda)); 18602b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleSingle", CeedSingleOperatorAssemble_Cuda)); 18612b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "ApplyAdd", CeedOperatorApplyAdd_Cuda)); 18622b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "Destroy", CeedOperatorDestroy_Cuda)); 18630d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 18640d0321e0SJeremy L Thompson } 18650d0321e0SJeremy L Thompson 18660d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 186767d9480aSJeremy L Thompson // Create operator AtPoints 1868756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 1869756ca9e9SJeremy L Thompson int CeedOperatorCreateAtPoints_Cuda(CeedOperator op) { 1870756ca9e9SJeremy L Thompson Ceed ceed; 1871756ca9e9SJeremy L Thompson CeedOperator_Cuda *impl; 1872756ca9e9SJeremy L Thompson 1873756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); 1874756ca9e9SJeremy L Thompson CeedCallBackend(CeedCalloc(1, &impl)); 1875756ca9e9SJeremy L Thompson CeedCallBackend(CeedOperatorSetData(op, impl)); 1876756ca9e9SJeremy L Thompson 1877756ca9e9SJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleQFunction", CeedOperatorLinearAssembleQFunctionAtPoints_Cuda)); 1878756ca9e9SJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleAddDiagonal", CeedOperatorLinearAssembleAddDiagonalAtPoints_Cuda)); 1879756ca9e9SJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "ApplyAdd", CeedOperatorApplyAddAtPoints_Cuda)); 1880756ca9e9SJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "Destroy", CeedOperatorDestroy_Cuda)); 1881756ca9e9SJeremy L Thompson return CEED_ERROR_SUCCESS; 1882756ca9e9SJeremy L Thompson } 1883756ca9e9SJeremy L Thompson 1884756ca9e9SJeremy L Thompson //------------------------------------------------------------------------------ 1885