From 0418c16f3ac3944a7f206dc81294c09b511d5dac Mon Sep 17 00:00:00 2001 From: Jeremy L Thompson Date: Tue, 22 Oct 2024 16:55:55 -0600 Subject: [PATCH] wip --- backends/blocked/ceed-blocked-operator.c | 8 +- .../cuda-gen/ceed-cuda-gen-operator-build.cpp | 2 +- backends/cuda-gen/ceed-cuda-gen-operator.c | 2 + backends/cuda-gen/ceed-cuda-gen-qfunction.c | 2 +- backends/cuda-ref/ceed-cuda-ref-basis.c | 9 + backends/cuda-ref/ceed-cuda-ref-operator.c | 22 ++- .../cuda-ref/ceed-cuda-ref-qfunction-load.cpp | 1 + backends/cuda-ref/ceed-cuda-ref-qfunction.c | 3 +- .../cuda-ref/ceed-cuda-ref-qfunctioncontext.c | 4 + backends/cuda-ref/ceed-cuda-ref-restriction.c | 5 + backends/cuda-ref/ceed-cuda-ref-vector.c | 17 +- backends/cuda-shared/ceed-cuda-shared-basis.c | 4 + .../hip-gen/ceed-hip-gen-operator-build.cpp | 2 +- backends/hip-gen/ceed-hip-gen-operator.c | 2 + backends/hip-gen/ceed-hip-gen-qfunction.c | 2 +- backends/hip-ref/ceed-hip-ref-basis.c | 9 + backends/hip-ref/ceed-hip-ref-operator.c | 22 ++- .../hip-ref/ceed-hip-ref-qfunction-load.cpp | 1 + backends/hip-ref/ceed-hip-ref-qfunction.c | 3 +- .../hip-ref/ceed-hip-ref-qfunctioncontext.c | 4 + backends/hip-ref/ceed-hip-ref-restriction.c | 5 + backends/hip-ref/ceed-hip-ref-vector.c | 17 +- backends/hip-shared/ceed-hip-shared-basis.c | 2 + backends/magma/ceed-magma-basis.c | 8 + backends/memcheck/ceed-memcheck-qfunction.c | 5 +- .../memcheck/ceed-memcheck-qfunctioncontext.c | 10 +- backends/memcheck/ceed-memcheck-restriction.c | 1 + backends/memcheck/ceed-memcheck-vector.c | 15 +- backends/opt/ceed-opt-operator.c | 8 +- backends/ref/ceed-ref-basis.c | 18 +- backends/ref/ceed-ref-operator.c | 19 +- backends/ref/ceed-ref-qfunction.c | 1 + backends/ref/ceed-ref-qfunctioncontext.c | 1 + backends/ref/ceed-ref-restriction.c | 1 + backends/ref/ceed-ref-vector.c | 1 + .../ceed-sycl-gen-operator-build.sycl.cpp | 2 +- .../sycl-gen/ceed-sycl-gen-operator.sycl.cpp | 2 + .../sycl-gen/ceed-sycl-gen-qfunction.sycl.cpp | 2 + .../sycl-ref/ceed-sycl-ref-basis.sycl.cpp | 21 ++- .../sycl-ref/ceed-sycl-ref-operator.sycl.cpp | 39 ++-- .../ceed-sycl-ref-qfunction-load.sycl.cpp | 1 + .../sycl-ref/ceed-sycl-ref-qfunction.sycl.cpp | 3 + .../ceed-sycl-ref-qfunctioncontext.sycl.cpp | 15 +- .../sycl-ref/ceed-sycl-restriction.sycl.cpp | 6 +- backends/sycl-ref/ceed-sycl-vector.sycl.cpp | 32 +++- .../ceed-sycl-shared-basis.sycl.cpp | 4 +- examples/fluids/include/petsc-ceed-utils.h | 1 + examples/fluids/src/mat-ceed.c | 1 - examples/fluids/src/petsc_ops.c | 1 + examples/fluids/src/turb_spanstats.c | 2 + interface/ceed-basis.c | 34 ++-- interface/ceed-cuda.c | 5 +- interface/ceed-elemrestriction.c | 55 +++--- interface/ceed-hip.c | 5 +- interface/ceed-operator.c | 124 ++++++------- interface/ceed-preconditioning.c | 89 ++++----- interface/ceed-qfunction.c | 36 ++-- interface/ceed-qfunctioncontext.c | 49 +++-- interface/ceed-vector.c | 175 ++++++++++-------- 59 files changed, 520 insertions(+), 420 deletions(-) diff --git a/backends/blocked/ceed-blocked-operator.c b/backends/blocked/ceed-blocked-operator.c index c9f5ccfd46..46b61ab7fa 100644 --- a/backends/blocked/ceed-blocked-operator.c +++ b/backends/blocked/ceed-blocked-operator.c @@ -30,7 +30,7 @@ static int CeedOperatorSetupFields_Blocked(CeedQFunction qf, CeedOperator op, bo CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); CeedCallBackend(CeedGetParent(ceed, &ceed_parent)); - if (ceed_parent) ceed = ceed_parent; + if (ceed_parent) CeedCall(CeedReferenceCopy(ceed_parent, &ceed)); } if (is_input) { CeedCallBackend(CeedOperatorGetFields(op, NULL, &op_fields, NULL, NULL)); @@ -105,6 +105,7 @@ static int CeedOperatorSetupFields_Blocked(CeedQFunction qf, CeedOperator op, bo // Empty case - won't occur break; } + CeedCallBackend(CeedDestroy(&ceed_rstr)); CeedCallBackend(CeedElemRestrictionDestroy(&rstr)); CeedCallBackend(CeedElemRestrictionCreateVector(block_rstr[i + start_e], NULL, &e_vecs_full[i + start_e])); } @@ -190,6 +191,7 @@ static int CeedOperatorSetupFields_Blocked(CeedQFunction qf, CeedOperator op, bo CeedCallBackend(CeedElemRestrictionDestroy(&rstr_i)); } } + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -198,7 +200,6 @@ static int CeedOperatorSetupFields_Blocked(CeedQFunction qf, CeedOperator op, bo //------------------------------------------------------------------------------ static int CeedOperatorSetup_Blocked(CeedOperator op) { bool is_setup_done; - Ceed ceed; CeedInt Q, num_input_fields, num_output_fields; const CeedInt block_size = 8; CeedQFunctionField *qf_input_fields, *qf_output_fields; @@ -209,7 +210,6 @@ static int CeedOperatorSetup_Blocked(CeedOperator op) { CeedCallBackend(CeedOperatorIsSetupDone(op, &is_setup_done)); if (is_setup_done) return CEED_ERROR_SUCCESS; - CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); CeedCallBackend(CeedOperatorGetData(op, &impl)); CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); CeedCallBackend(CeedOperatorGetNumQuadraturePoints(op, &Q)); @@ -707,6 +707,7 @@ static inline int CeedOperatorLinearAssembleQFunctionCore_Blocked(CeedOperator o CeedCallBackend(CeedOperatorRestoreInputs_Blocked(num_input_fields, qf_input_fields, op_input_fields, true, e_data_full, impl)); // Output blocked restriction + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedVectorRestoreArray(l_vec, &l_vec_array)); CeedCallBackend(CeedVectorSetValue(*assembled, 0.0)); CeedCallBackend(CeedElemRestrictionApply(block_rstr, CEED_TRANSPOSE, l_vec, *assembled, request)); @@ -783,6 +784,7 @@ int CeedOperatorCreate_Blocked(CeedOperator op) { CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleQFunctionUpdate", CeedOperatorLinearAssembleQFunctionUpdate_Blocked)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "ApplyAdd", CeedOperatorApplyAdd_Blocked)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "Destroy", CeedOperatorDestroy_Blocked)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/cuda-gen/ceed-cuda-gen-operator-build.cpp b/backends/cuda-gen/ceed-cuda-gen-operator-build.cpp index 315db3844f..3103bcbfb7 100644 --- a/backends/cuda-gen/ceed-cuda-gen-operator-build.cpp +++ b/backends/cuda-gen/ceed-cuda-gen-operator-build.cpp @@ -901,8 +901,8 @@ extern "C" int CeedOperatorBuildKernel_Cuda_gen(CeedOperator op) { CeedCallBackend(CeedCompile_Cuda(ceed, code.str().c_str(), &data->module, 1, "T_1D", CeedIntMax(Q_1d, data->max_P_1d))); CeedCallBackend(CeedGetKernel_Cuda(ceed, data->module, operator_name.c_str(), &data->op)); - CeedCallBackend(CeedOperatorSetSetupDone(op)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/cuda-gen/ceed-cuda-gen-operator.c b/backends/cuda-gen/ceed-cuda-gen-operator.c index 4c235984fd..f08de183b6 100644 --- a/backends/cuda-gen/ceed-cuda-gen-operator.c +++ b/backends/cuda-gen/ceed-cuda-gen-operator.c @@ -251,6 +251,7 @@ static int CeedOperatorApplyAdd_Cuda_gen(CeedOperator op, CeedVector input_vec, // Restore context data CeedCallBackend(CeedQFunctionRestoreInnerContextData(qf, &qf_data->d_c)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -266,6 +267,7 @@ int CeedOperatorCreate_Cuda_gen(CeedOperator op) { CeedCallBackend(CeedOperatorSetData(op, impl)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "ApplyAdd", CeedOperatorApplyAdd_Cuda_gen)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "Destroy", CeedOperatorDestroy_Cuda_gen)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/cuda-gen/ceed-cuda-gen-qfunction.c b/backends/cuda-gen/ceed-cuda-gen-qfunction.c index aec5294a8d..483b520503 100644 --- a/backends/cuda-gen/ceed-cuda-gen-qfunction.c +++ b/backends/cuda-gen/ceed-cuda-gen-qfunction.c @@ -42,11 +42,11 @@ int CeedQFunctionCreate_Cuda_gen(CeedQFunction qf) { CeedCallBackend(CeedCalloc(1, &data)); CeedCallBackend(CeedQFunctionSetData(qf, data)); - // Read QFunction source CeedCallBackend(CeedQFunctionGetKernelName(qf, &data->qfunction_name)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Cuda_gen)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Cuda_gen)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/cuda-ref/ceed-cuda-ref-basis.c b/backends/cuda-ref/ceed-cuda-ref-basis.c index 3eca8134c3..a9ad5ebbf7 100644 --- a/backends/cuda-ref/ceed-cuda-ref-basis.c +++ b/backends/cuda-ref/ceed-cuda-ref-basis.c @@ -88,6 +88,7 @@ static int CeedBasisApplyCore_Cuda(CeedBasis basis, bool apply_add, const CeedIn CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); if (eval_mode == CEED_EVAL_NONE) CeedCallBackend(CeedVectorSetArray(v, CEED_MEM_DEVICE, CEED_COPY_VALUES, (CeedScalar *)d_u)); if (eval_mode != CEED_EVAL_WEIGHT) CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -244,6 +245,7 @@ static int CeedBasisApplyAtPointsCore_Cuda(CeedBasis basis, bool apply_add, cons CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); if (eval_mode == CEED_EVAL_NONE) CeedCallBackend(CeedVectorSetArray(v, CEED_MEM_DEVICE, CEED_COPY_VALUES, (CeedScalar *)d_u)); if (eval_mode != CEED_EVAL_WEIGHT) CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -351,6 +353,7 @@ static int CeedBasisApplyNonTensorCore_Cuda(CeedBasis basis, bool apply_add, con CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); if (eval_mode == CEED_EVAL_NONE) CeedCallBackend(CeedVectorSetArray(v, CEED_MEM_DEVICE, CEED_COPY_VALUES, (CeedScalar *)d_u)); if (eval_mode != CEED_EVAL_WEIGHT) CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -384,6 +387,7 @@ static int CeedBasisDestroy_Cuda(CeedBasis basis) { CeedCallCuda(ceed, cudaFree(data->d_grad_1d)); CeedCallCuda(ceed, cudaFree(data->d_chebyshev_interp_1d)); CeedCallBackend(CeedFree(&data)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -403,6 +407,7 @@ static int CeedBasisDestroyNonTensor_Cuda(CeedBasis basis) { CeedCallCuda(ceed, cudaFree(data->d_div)); CeedCallCuda(ceed, cudaFree(data->d_curl)); CeedCallBackend(CeedFree(&data)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -449,6 +454,7 @@ int CeedBasisCreateTensorH1_Cuda(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAtPoints", CeedBasisApplyAtPoints_Cuda)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAddAtPoints", CeedBasisApplyAddAtPoints_Cuda)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroy_Cuda)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -503,6 +509,7 @@ int CeedBasisCreateH1_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApplyNonTensor_Cuda)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAdd", CeedBasisApplyAddNonTensor_Cuda)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroyNonTensor_Cuda)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -557,6 +564,7 @@ int CeedBasisCreateHdiv_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nod CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApplyNonTensor_Cuda)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAdd", CeedBasisApplyAddNonTensor_Cuda)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroyNonTensor_Cuda)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -611,6 +619,7 @@ int CeedBasisCreateHcurl_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_no CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApplyNonTensor_Cuda)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAdd", CeedBasisApplyAddNonTensor_Cuda)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroyNonTensor_Cuda)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/cuda-ref/ceed-cuda-ref-operator.c b/backends/cuda-ref/ceed-cuda-ref-operator.c index 8cb8855ba7..602719e4fa 100644 --- a/backends/cuda-ref/ceed-cuda-ref-operator.c +++ b/backends/cuda-ref/ceed-cuda-ref-operator.c @@ -78,10 +78,11 @@ static int CeedOperatorDestroy_Cuda(CeedOperator op) { CeedCallCuda(ceed, cudaFree(impl->diag->d_div_out)); CeedCallCuda(ceed, cudaFree(impl->diag->d_curl_in)); CeedCallCuda(ceed, cudaFree(impl->diag->d_curl_out)); - CeedCallBackend(CeedElemRestrictionDestroy(&impl->diag->diag_rstr)); - CeedCallBackend(CeedElemRestrictionDestroy(&impl->diag->point_block_diag_rstr)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedVectorDestroy(&impl->diag->elem_diag)); CeedCallBackend(CeedVectorDestroy(&impl->diag->point_block_elem_diag)); + CeedCallBackend(CeedElemRestrictionDestroy(&impl->diag->diag_rstr)); + CeedCallBackend(CeedElemRestrictionDestroy(&impl->diag->point_block_diag_rstr)); } CeedCallBackend(CeedFree(&impl->diag)); @@ -92,6 +93,7 @@ static int CeedOperatorDestroy_Cuda(CeedOperator op) { CeedCallCuda(ceed, cuModuleUnload(impl->asmb->module)); CeedCallCuda(ceed, cudaFree(impl->asmb->d_B_in)); CeedCallCuda(ceed, cudaFree(impl->asmb->d_B_out)); + CeedCallBackend(CeedDestroy(&ceed)); } CeedCallBackend(CeedFree(&impl->asmb)); @@ -227,6 +229,7 @@ static int CeedOperatorSetupFields_Cuda(CeedQFunction qf, CeedOperator op, bool CeedCallBackend(CeedElemRestrictionDestroy(&rstr_i)); } } + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -234,7 +237,6 @@ static int CeedOperatorSetupFields_Cuda(CeedQFunction qf, CeedOperator op, bool // CeedOperator needs to connect all the named fields (be they active or passive) to the named inputs and outputs of its CeedQFunction. //------------------------------------------------------------------------------ static int CeedOperatorSetup_Cuda(CeedOperator op) { - Ceed ceed; bool is_setup_done; CeedInt Q, num_elem, num_input_fields, num_output_fields; CeedQFunctionField *qf_input_fields, *qf_output_fields; @@ -245,7 +247,6 @@ static int CeedOperatorSetup_Cuda(CeedOperator op) { CeedCallBackend(CeedOperatorIsSetupDone(op, &is_setup_done)); if (is_setup_done) return CEED_ERROR_SUCCESS; - CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); CeedCallBackend(CeedOperatorGetData(op, &impl)); CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); CeedCallBackend(CeedOperatorGetNumQuadraturePoints(op, &Q)); @@ -603,6 +604,7 @@ static int CeedOperatorApplyAdd_Cuda(CeedOperator op, CeedVector in_vec, CeedVec // Return work vector CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -610,7 +612,6 @@ static int CeedOperatorApplyAdd_Cuda(CeedOperator op, CeedVector in_vec, CeedVec // CeedOperator needs to connect all the named fields (be they active or passive) to the named inputs and outputs of its CeedQFunction. //------------------------------------------------------------------------------ static int CeedOperatorSetupAtPoints_Cuda(CeedOperator op) { - Ceed ceed; bool is_setup_done; CeedInt max_num_points = -1, num_elem, num_input_fields, num_output_fields; CeedQFunctionField *qf_input_fields, *qf_output_fields; @@ -621,7 +622,6 @@ static int CeedOperatorSetupAtPoints_Cuda(CeedOperator op) { CeedCallBackend(CeedOperatorIsSetupDone(op, &is_setup_done)); if (is_setup_done) return CEED_ERROR_SUCCESS; - CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); CeedCallBackend(CeedOperatorGetData(op, &impl)); CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem)); @@ -934,6 +934,7 @@ static int CeedOperatorApplyAddAtPoints_Cuda(CeedOperator op, CeedVector in_vec, // Restore work vector CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -1075,6 +1076,7 @@ static inline int CeedOperatorLinearAssembleQFunctionCore_Cuda(CeedOperator op, } // Restore output + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedVectorRestoreArray(*assembled, &assembled_array)); return CEED_ERROR_SUCCESS; } @@ -1276,6 +1278,7 @@ static inline int CeedOperatorAssembleDiagonalSetup_Cuda(CeedOperator op) { CeedCallCuda(ceed, cudaMemcpy(diag->d_eval_modes_out, eval_modes_out, num_eval_modes_out * eval_modes_bytes, cudaMemcpyHostToDevice)); CeedCallBackend(CeedFree(&eval_modes_in)); CeedCallBackend(CeedFree(&eval_modes_out)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedBasisDestroy(&basis_in)); CeedCallBackend(CeedBasisDestroy(&basis_out)); return CEED_ERROR_SUCCESS; @@ -1361,6 +1364,7 @@ static inline int CeedOperatorAssembleDiagonalSetupCompile_Cuda(CeedOperator op, num_eval_modes_out, "NUM_COMP", num_comp, "NUM_NODES", num_nodes, "NUM_QPTS", num_qpts, "USE_CEEDSIZE", use_ceedsize_idx, "USE_POINT_BLOCK", is_point_block ? 1 : 0, "BLOCK_SIZE", num_nodes * elems_per_block)); CeedCallCuda(ceed, CeedGetKernel_Cuda(ceed, *module, "LinearDiagonal", is_point_block ? &diag->LinearPointBlock : &diag->LinearDiagonal)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedBasisDestroy(&basis_in)); CeedCallBackend(CeedBasisDestroy(&basis_out)); return CEED_ERROR_SUCCESS; @@ -1449,6 +1453,7 @@ static inline int CeedOperatorAssembleDiagonalCore_Cuda(CeedOperator op, CeedVec CeedCallBackend(CeedElemRestrictionApply(diag_rstr, CEED_TRANSPOSE, elem_diag, assembled, request)); // Cleanup + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedVectorDestroy(&assembled_qf)); return CEED_ERROR_SUCCESS; } @@ -1661,6 +1666,7 @@ static int CeedSingleOperatorAssembleSetup_Cuda(CeedOperator op, CeedInt use_cee CeedCallBackend(CeedFree(&identity)); } CeedCallBackend(CeedFree(&eval_modes_out)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedElemRestrictionDestroy(&rstr_in)); CeedCallBackend(CeedElemRestrictionDestroy(&rstr_out)); CeedCallBackend(CeedBasisDestroy(&basis_in)); @@ -1769,6 +1775,7 @@ static int CeedSingleOperatorAssemble_Cuda(CeedOperator op, CeedInt offset, Ceed CeedCallBackend(CeedElemRestrictionRestoreCurlOrientations(rstr_out, &curl_orients_out)); } } + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedElemRestrictionDestroy(&rstr_in)); CeedCallBackend(CeedElemRestrictionDestroy(&rstr_out)); return CEED_ERROR_SUCCESS; @@ -2040,6 +2047,7 @@ static int CeedOperatorLinearAssembleAddDiagonalAtPoints_Cuda(CeedOperator op, C // Restore work vector CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec_in)); CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec_out)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -2062,6 +2070,7 @@ int CeedOperatorCreate_Cuda(CeedOperator op) { CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleSingle", CeedSingleOperatorAssemble_Cuda)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "ApplyAdd", CeedOperatorApplyAdd_Cuda)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "Destroy", CeedOperatorDestroy_Cuda)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -2080,6 +2089,7 @@ int CeedOperatorCreateAtPoints_Cuda(CeedOperator op) { CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleAddDiagonal", CeedOperatorLinearAssembleAddDiagonalAtPoints_Cuda)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "ApplyAdd", CeedOperatorApplyAddAtPoints_Cuda)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "Destroy", CeedOperatorDestroy_Cuda)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/cuda-ref/ceed-cuda-ref-qfunction-load.cpp b/backends/cuda-ref/ceed-cuda-ref-qfunction-load.cpp index 2d5540ead8..be5b1e9e83 100644 --- a/backends/cuda-ref/ceed-cuda-ref-qfunction-load.cpp +++ b/backends/cuda-ref/ceed-cuda-ref-qfunction-load.cpp @@ -112,6 +112,7 @@ extern "C" int CeedQFunctionBuildKernel_Cuda_ref(CeedQFunction qf) { // Compile kernel CeedCallBackend(CeedCompile_Cuda(ceed, code.str().c_str(), &data->module, 0)); CeedCallBackend(CeedGetKernel_Cuda(ceed, data->module, kernel_name.c_str(), &data->QFunction)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/cuda-ref/ceed-cuda-ref-qfunction.c b/backends/cuda-ref/ceed-cuda-ref-qfunction.c index eec4aea26c..32a02b43dd 100644 --- a/backends/cuda-ref/ceed-cuda-ref-qfunction.c +++ b/backends/cuda-ref/ceed-cuda-ref-qfunction.c @@ -58,6 +58,7 @@ static int CeedQFunctionApply_Cuda(CeedQFunction qf, CeedInt Q, CeedVector *U, C // Restore context CeedCallBackend(CeedQFunctionRestoreInnerContextData(qf, &data->d_c)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -95,13 +96,13 @@ int CeedQFunctionCreate_Cuda(CeedQFunction qf) { CeedCallBackend(CeedCalloc(1, &data)); CeedCallBackend(CeedQFunctionSetData(qf, data)); - // Read QFunction name CeedCallBackend(CeedQFunctionGetKernelName(qf, &data->qfunction_name)); // Register backend functions CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Cuda)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Cuda)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "SetCUDAUserFunction", CeedQFunctionSetCUDAUserFunction_Cuda)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/cuda-ref/ceed-cuda-ref-qfunctioncontext.c b/backends/cuda-ref/ceed-cuda-ref-qfunctioncontext.c index 4257265987..5afbb7aa02 100644 --- a/backends/cuda-ref/ceed-cuda-ref-qfunctioncontext.c +++ b/backends/cuda-ref/ceed-cuda-ref-qfunctioncontext.c @@ -37,6 +37,7 @@ static inline int CeedQFunctionContextSyncH2D_Cuda(const CeedQFunctionContext ct impl->d_data = impl->d_data_owned; } CeedCallCuda(ceed, cudaMemcpy(impl->d_data, impl->h_data, ctx_size, cudaMemcpyHostToDevice)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -64,6 +65,7 @@ static inline int CeedQFunctionContextSyncD2H_Cuda(const CeedQFunctionContext ct impl->h_data = impl->h_data_owned; } CeedCallCuda(ceed, cudaMemcpy(impl->h_data, impl->d_data, ctx_size, cudaMemcpyDeviceToHost)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -205,6 +207,7 @@ static int CeedQFunctionContextSetDataDevice_Cuda(const CeedQFunctionContext ctx impl->d_data = data; break; } + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -335,6 +338,7 @@ int CeedQFunctionContextCreate_Cuda(CeedQFunctionContext ctx) { CeedCallBackend(CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "GetData", CeedQFunctionContextGetData_Cuda)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "GetDataRead", CeedQFunctionContextGetDataRead_Cuda)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "Destroy", CeedQFunctionContextDestroy_Cuda)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedCalloc(1, &impl)); CeedCallBackend(CeedQFunctionContextSetBackendData(ctx, impl)); return CEED_ERROR_SUCCESS; diff --git a/backends/cuda-ref/ceed-cuda-ref-restriction.c b/backends/cuda-ref/ceed-cuda-ref-restriction.c index c4a5c22dda..be1c3d8b5d 100644 --- a/backends/cuda-ref/ceed-cuda-ref-restriction.c +++ b/backends/cuda-ref/ceed-cuda-ref-restriction.c @@ -106,6 +106,7 @@ static inline int CeedElemRestrictionSetupCompile_Cuda(CeedElemRestriction rstr) CeedCallBackend(CeedGetKernel_Cuda(ceed, impl->module, "OffsetTranspose", &impl->ApplyUnorientedTranspose)); } break; } + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -285,6 +286,7 @@ static inline int CeedElemRestrictionApply_Cuda_Core(CeedElemRestriction rstr, C // Restore arrays CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -404,6 +406,7 @@ static int CeedElemRestrictionDestroy_Cuda(CeedElemRestriction rstr) { CeedCallBackend(CeedFree(&impl->h_points_per_elem_owned)); CeedCallCuda(ceed, cudaFree((CeedInt *)impl->d_points_per_elem_owned)); CeedCallBackend(CeedFree(&impl)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -485,6 +488,7 @@ static int CeedElemRestrictionOffset_Cuda(const CeedElemRestriction rstr, const CeedCallBackend(CeedFree(&l_vec_indices)); CeedCallBackend(CeedFree(&t_offsets)); CeedCallBackend(CeedFree(&t_indices)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -649,6 +653,7 @@ int CeedElemRestrictionCreate_Cuda(CeedMemType mem_type, CeedCopyMode copy_mode, CeedSetBackendFunction(ceed, "ElemRestriction", rstr, "GetAtPointsElementOffset", CeedElemRestrictionGetAtPointsElementOffset_Cuda)); } CeedCallBackend(CeedSetBackendFunction(ceed, "ElemRestriction", rstr, "Destroy", CeedElemRestrictionDestroy_Cuda)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/cuda-ref/ceed-cuda-ref-vector.c b/backends/cuda-ref/ceed-cuda-ref-vector.c index 9deb6dec82..7365327229 100644 --- a/backends/cuda-ref/ceed-cuda-ref-vector.c +++ b/backends/cuda-ref/ceed-cuda-ref-vector.c @@ -41,10 +41,8 @@ static inline int CeedVectorNeedSync_Cuda(const CeedVector vec, CeedMemType mem_ static inline int CeedVectorSyncH2D_Cuda(const CeedVector vec) { CeedSize length; size_t bytes; - Ceed ceed; CeedVector_Cuda *impl; - CeedCallBackend(CeedVectorGetCeed(vec, &ceed)); CeedCallBackend(CeedVectorGetData(vec, &impl)); CeedCheck(impl->h_array, CeedVectorReturnCeed(vec), CEED_ERROR_BACKEND, "No valid host data to sync to device"); @@ -56,10 +54,10 @@ static inline int CeedVectorSyncH2D_Cuda(const CeedVector vec) { } else if (impl->d_array_owned) { impl->d_array = impl->d_array_owned; } else { - CeedCallCuda(ceed, cudaMalloc((void **)&impl->d_array_owned, bytes)); + CeedCallCuda(CeedVectorReturnCeed(vec), cudaMalloc((void **)&impl->d_array_owned, bytes)); impl->d_array = impl->d_array_owned; } - CeedCallCuda(ceed, cudaMemcpy(impl->d_array, impl->h_array, bytes, cudaMemcpyHostToDevice)); + CeedCallCuda(CeedVectorReturnCeed(vec), cudaMemcpy(impl->d_array, impl->h_array, bytes, cudaMemcpyHostToDevice)); return CEED_ERROR_SUCCESS; } @@ -68,13 +66,11 @@ static inline int CeedVectorSyncH2D_Cuda(const CeedVector vec) { //------------------------------------------------------------------------------ static inline int CeedVectorSyncD2H_Cuda(const CeedVector vec) { CeedSize length; - Ceed ceed; CeedVector_Cuda *impl; - CeedCallBackend(CeedVectorGetCeed(vec, &ceed)); CeedCallBackend(CeedVectorGetData(vec, &impl)); - CeedCheck(impl->d_array, ceed, CEED_ERROR_BACKEND, "No valid device data to sync to host"); + CeedCheck(impl->d_array, CeedVectorReturnCeed(vec), CEED_ERROR_BACKEND, "No valid device data to sync to host"); if (impl->h_array_borrowed) { impl->h_array = impl->h_array_borrowed; @@ -91,7 +87,7 @@ static inline int CeedVectorSyncD2H_Cuda(const CeedVector vec) { CeedCallBackend(CeedVectorGetLength(vec, &length)); size_t bytes = length * sizeof(CeedScalar); - CeedCallCuda(ceed, cudaMemcpy(impl->h_array, impl->d_array, bytes, cudaMemcpyDeviceToHost)); + CeedCallCuda(CeedVectorReturnCeed(vec), cudaMemcpy(impl->h_array, impl->d_array, bytes, cudaMemcpyDeviceToHost)); return CEED_ERROR_SUCCESS; } @@ -202,6 +198,7 @@ static int CeedVectorSetArrayDevice_Cuda(const CeedVector vec, const CeedCopyMod CeedCallBackend(CeedSetDeviceCeedScalarArray_Cuda(ceed, array, copy_mode, length, (const CeedScalar **)&impl->d_array_owned, (const CeedScalar **)&impl->d_array_borrowed, (const CeedScalar **)&impl->d_array)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -611,6 +608,7 @@ static int CeedVectorNorm_Cuda(CeedVector vec, CeedNormType type, CeedScalar *no } } CeedCallBackend(CeedVectorRestoreArrayRead(vec, &d_array)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -689,11 +687,9 @@ int CeedDeviceAXPY_Cuda(CeedScalar *y_array, CeedScalar alpha, CeedScalar *x_arr // Compute y = alpha x + y //------------------------------------------------------------------------------ static int CeedVectorAXPY_Cuda(CeedVector y, CeedScalar alpha, CeedVector x) { - Ceed ceed; CeedSize length; CeedVector_Cuda *y_impl, *x_impl; - CeedCallBackend(CeedVectorGetCeed(y, &ceed)); CeedCallBackend(CeedVectorGetData(y, &y_impl)); CeedCallBackend(CeedVectorGetData(x, &x_impl)); CeedCallBackend(CeedVectorGetLength(y, &length)); @@ -824,6 +820,7 @@ int CeedVectorCreate_Cuda(CeedSize n, CeedVector vec) { CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "AXPBY", CeedVectorAXPBY_Cuda)); CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "PointwiseMult", CeedVectorPointwiseMult_Cuda)); CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "Destroy", CeedVectorDestroy_Cuda)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedCalloc(1, &impl)); CeedCallBackend(CeedVectorSetData(vec, impl)); return CEED_ERROR_SUCCESS; diff --git a/backends/cuda-shared/ceed-cuda-shared-basis.c b/backends/cuda-shared/ceed-cuda-shared-basis.c index b1709787ec..2308fe0f63 100644 --- a/backends/cuda-shared/ceed-cuda-shared-basis.c +++ b/backends/cuda-shared/ceed-cuda-shared-basis.c @@ -189,6 +189,7 @@ static int CeedBasisApplyTensorCore_Cuda_shared(CeedBasis basis, bool apply_add, CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); if (eval_mode == CEED_EVAL_NONE) CeedCallBackend(CeedVectorSetArray(v, CEED_MEM_DEVICE, CEED_COPY_VALUES, (CeedScalar *)d_u)); if (eval_mode != CEED_EVAL_WEIGHT) CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -345,6 +346,7 @@ static int CeedBasisApplyAtPointsCore_Cuda_shared(CeedBasis basis, bool apply_ad CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); if (eval_mode == CEED_EVAL_NONE) CeedCallBackend(CeedVectorSetArray(v, CEED_MEM_DEVICE, CEED_COPY_VALUES, (CeedScalar *)d_u)); if (eval_mode != CEED_EVAL_WEIGHT) CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -379,6 +381,7 @@ static int CeedBasisDestroy_Cuda_shared(CeedBasis basis) { CeedCallCuda(ceed, cudaFree(data->d_collo_grad_1d)); CeedCallCuda(ceed, cudaFree(data->d_chebyshev_interp_1d)); CeedCallBackend(CeedFree(&data)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -443,6 +446,7 @@ int CeedBasisCreateTensorH1_Cuda_shared(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAtPoints", CeedBasisApplyAtPoints_Cuda_shared)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAddAtPoints", CeedBasisApplyAddAtPoints_Cuda_shared)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroy_Cuda_shared)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/hip-gen/ceed-hip-gen-operator-build.cpp b/backends/hip-gen/ceed-hip-gen-operator-build.cpp index f1a876ce26..6a13cd5600 100644 --- a/backends/hip-gen/ceed-hip-gen-operator-build.cpp +++ b/backends/hip-gen/ceed-hip-gen-operator-build.cpp @@ -908,8 +908,8 @@ extern "C" int CeedOperatorBuildKernel_Hip_gen(CeedOperator op) { CeedCallBackend(CeedCompile_Hip(ceed, code.str().c_str(), &data->module, 2, "T_1D", block_sizes[0], "BLOCK_SIZE", block_sizes[0] * block_sizes[1] * block_sizes[2])); CeedCallBackend(CeedGetKernel_Hip(ceed, data->module, operator_name.c_str(), &data->op)); - CeedCallBackend(CeedOperatorSetSetupDone(op)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/hip-gen/ceed-hip-gen-operator.c b/backends/hip-gen/ceed-hip-gen-operator.c index fcd58ed76d..f01730b5b6 100644 --- a/backends/hip-gen/ceed-hip-gen-operator.c +++ b/backends/hip-gen/ceed-hip-gen-operator.c @@ -177,6 +177,7 @@ static int CeedOperatorApplyAdd_Hip_gen(CeedOperator op, CeedVector input_vec, C // Restore context data CeedCallBackend(CeedQFunctionRestoreInnerContextData(qf, &qf_data->d_c)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -192,6 +193,7 @@ int CeedOperatorCreate_Hip_gen(CeedOperator op) { CeedCallBackend(CeedOperatorSetData(op, impl)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "ApplyAdd", CeedOperatorApplyAdd_Hip_gen)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "Destroy", CeedOperatorDestroy_Hip_gen)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/hip-gen/ceed-hip-gen-qfunction.c b/backends/hip-gen/ceed-hip-gen-qfunction.c index 32d5653b98..6da2c1d10e 100644 --- a/backends/hip-gen/ceed-hip-gen-qfunction.c +++ b/backends/hip-gen/ceed-hip-gen-qfunction.c @@ -42,11 +42,11 @@ int CeedQFunctionCreate_Hip_gen(CeedQFunction qf) { CeedCallBackend(CeedCalloc(1, &data)); CeedCallBackend(CeedQFunctionSetData(qf, data)); - // Read QFunction source CeedCallBackend(CeedQFunctionGetKernelName(qf, &data->qfunction_name)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Hip_gen)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Hip_gen)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/hip-ref/ceed-hip-ref-basis.c b/backends/hip-ref/ceed-hip-ref-basis.c index 7e7f0e97e4..cf547b93be 100644 --- a/backends/hip-ref/ceed-hip-ref-basis.c +++ b/backends/hip-ref/ceed-hip-ref-basis.c @@ -87,6 +87,7 @@ static int CeedBasisApplyCore_Hip(CeedBasis basis, bool apply_add, const CeedInt CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); if (eval_mode == CEED_EVAL_NONE) CeedCallBackend(CeedVectorSetArray(v, CEED_MEM_DEVICE, CEED_COPY_VALUES, (CeedScalar *)d_u)); if (eval_mode != CEED_EVAL_WEIGHT) CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -242,6 +243,7 @@ static int CeedBasisApplyAtPointsCore_Hip(CeedBasis basis, bool apply_add, const CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); if (eval_mode == CEED_EVAL_NONE) CeedCallBackend(CeedVectorSetArray(v, CEED_MEM_DEVICE, CEED_COPY_VALUES, (CeedScalar *)d_u)); if (eval_mode != CEED_EVAL_WEIGHT) CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -346,6 +348,7 @@ static int CeedBasisApplyNonTensorCore_Hip(CeedBasis basis, bool apply_add, cons CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); if (eval_mode == CEED_EVAL_NONE) CeedCallBackend(CeedVectorSetArray(v, CEED_MEM_DEVICE, CEED_COPY_VALUES, (CeedScalar *)d_u)); if (eval_mode != CEED_EVAL_WEIGHT) CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -379,6 +382,7 @@ static int CeedBasisDestroy_Hip(CeedBasis basis) { CeedCallHip(ceed, hipFree(data->d_grad_1d)); CeedCallHip(ceed, hipFree(data->d_chebyshev_interp_1d)); CeedCallBackend(CeedFree(&data)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -398,6 +402,7 @@ static int CeedBasisDestroyNonTensor_Hip(CeedBasis basis) { CeedCallHip(ceed, hipFree(data->d_div)); CeedCallHip(ceed, hipFree(data->d_curl)); CeedCallBackend(CeedFree(&data)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -444,6 +449,7 @@ int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const C CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAtPoints", CeedBasisApplyAtPoints_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAddAtPoints", CeedBasisApplyAddAtPoints_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroy_Hip)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -498,6 +504,7 @@ int CeedBasisCreateH1_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApplyNonTensor_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAdd", CeedBasisApplyAddNonTensor_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroyNonTensor_Hip)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -552,6 +559,7 @@ int CeedBasisCreateHdiv_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_node CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApplyNonTensor_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAdd", CeedBasisApplyAddNonTensor_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroyNonTensor_Hip)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -606,6 +614,7 @@ int CeedBasisCreateHcurl_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nod CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApplyNonTensor_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAdd", CeedBasisApplyAddNonTensor_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroyNonTensor_Hip)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/hip-ref/ceed-hip-ref-operator.c b/backends/hip-ref/ceed-hip-ref-operator.c index c2e58a1e7f..aeb5ce21a9 100644 --- a/backends/hip-ref/ceed-hip-ref-operator.c +++ b/backends/hip-ref/ceed-hip-ref-operator.c @@ -77,10 +77,11 @@ static int CeedOperatorDestroy_Hip(CeedOperator op) { CeedCallHip(ceed, hipFree(impl->diag->d_div_out)); CeedCallHip(ceed, hipFree(impl->diag->d_curl_in)); CeedCallHip(ceed, hipFree(impl->diag->d_curl_out)); - CeedCallBackend(CeedElemRestrictionDestroy(&impl->diag->diag_rstr)); - CeedCallBackend(CeedElemRestrictionDestroy(&impl->diag->point_block_diag_rstr)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedVectorDestroy(&impl->diag->elem_diag)); CeedCallBackend(CeedVectorDestroy(&impl->diag->point_block_elem_diag)); + CeedCallBackend(CeedElemRestrictionDestroy(&impl->diag->diag_rstr)); + CeedCallBackend(CeedElemRestrictionDestroy(&impl->diag->point_block_diag_rstr)); } CeedCallBackend(CeedFree(&impl->diag)); @@ -91,6 +92,7 @@ static int CeedOperatorDestroy_Hip(CeedOperator op) { CeedCallHip(ceed, hipModuleUnload(impl->asmb->module)); CeedCallHip(ceed, hipFree(impl->asmb->d_B_in)); CeedCallHip(ceed, hipFree(impl->asmb->d_B_out)); + CeedCallBackend(CeedDestroy(&ceed)); } CeedCallBackend(CeedFree(&impl->asmb)); @@ -226,6 +228,7 @@ static int CeedOperatorSetupFields_Hip(CeedQFunction qf, CeedOperator op, bool i CeedCallBackend(CeedElemRestrictionDestroy(&rstr_i)); } } + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -233,7 +236,6 @@ static int CeedOperatorSetupFields_Hip(CeedQFunction qf, CeedOperator op, bool i // CeedOperator needs to connect all the named fields (be they active or passive) to the named inputs and outputs of its CeedQFunction. //------------------------------------------------------------------------------ static int CeedOperatorSetup_Hip(CeedOperator op) { - Ceed ceed; bool is_setup_done; CeedInt Q, num_elem, num_input_fields, num_output_fields; CeedQFunctionField *qf_input_fields, *qf_output_fields; @@ -244,7 +246,6 @@ static int CeedOperatorSetup_Hip(CeedOperator op) { CeedCallBackend(CeedOperatorIsSetupDone(op, &is_setup_done)); if (is_setup_done) return CEED_ERROR_SUCCESS; - CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); CeedCallBackend(CeedOperatorGetData(op, &impl)); CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); CeedCallBackend(CeedOperatorGetNumQuadraturePoints(op, &Q)); @@ -601,6 +602,7 @@ static int CeedOperatorApplyAdd_Hip(CeedOperator op, CeedVector in_vec, CeedVect // Return work vector CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -608,7 +610,6 @@ static int CeedOperatorApplyAdd_Hip(CeedOperator op, CeedVector in_vec, CeedVect // CeedOperator needs to connect all the named fields (be they active or passive) to the named inputs and outputs of its CeedQFunction. //------------------------------------------------------------------------------ static int CeedOperatorSetupAtPoints_Hip(CeedOperator op) { - Ceed ceed; bool is_setup_done; CeedInt max_num_points = -1, num_elem, num_input_fields, num_output_fields; CeedQFunctionField *qf_input_fields, *qf_output_fields; @@ -619,7 +620,6 @@ static int CeedOperatorSetupAtPoints_Hip(CeedOperator op) { CeedCallBackend(CeedOperatorIsSetupDone(op, &is_setup_done)); if (is_setup_done) return CEED_ERROR_SUCCESS; - CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); CeedCallBackend(CeedOperatorGetData(op, &impl)); CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem)); @@ -931,6 +931,7 @@ static int CeedOperatorApplyAddAtPoints_Hip(CeedOperator op, CeedVector in_vec, // Restore work vector CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -1072,6 +1073,7 @@ static inline int CeedOperatorLinearAssembleQFunctionCore_Hip(CeedOperator op, b } // Restore output + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedVectorRestoreArray(*assembled, &assembled_array)); return CEED_ERROR_SUCCESS; } @@ -1273,6 +1275,7 @@ static inline int CeedOperatorAssembleDiagonalSetup_Hip(CeedOperator op) { CeedCallHip(ceed, hipMemcpy(diag->d_eval_modes_out, eval_modes_out, num_eval_modes_out * eval_modes_bytes, hipMemcpyHostToDevice)); CeedCallBackend(CeedFree(&eval_modes_in)); CeedCallBackend(CeedFree(&eval_modes_out)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedBasisDestroy(&basis_in)); CeedCallBackend(CeedBasisDestroy(&basis_out)); return CEED_ERROR_SUCCESS; @@ -1358,6 +1361,7 @@ static inline int CeedOperatorAssembleDiagonalSetupCompile_Hip(CeedOperator op, num_eval_modes_out, "NUM_COMP", num_comp, "NUM_NODES", num_nodes, "NUM_QPTS", num_qpts, "USE_CEEDSIZE", use_ceedsize_idx, "USE_POINT_BLOCK", is_point_block ? 1 : 0, "BLOCK_SIZE", num_nodes * elems_per_block)); CeedCallHip(ceed, CeedGetKernel_Hip(ceed, *module, "LinearDiagonal", is_point_block ? &diag->LinearPointBlock : &diag->LinearDiagonal)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedBasisDestroy(&basis_in)); CeedCallBackend(CeedBasisDestroy(&basis_out)); return CEED_ERROR_SUCCESS; @@ -1446,6 +1450,7 @@ static inline int CeedOperatorAssembleDiagonalCore_Hip(CeedOperator op, CeedVect CeedCallBackend(CeedElemRestrictionApply(diag_rstr, CEED_TRANSPOSE, elem_diag, assembled, request)); // Cleanup + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedVectorDestroy(&assembled_qf)); return CEED_ERROR_SUCCESS; } @@ -1658,6 +1663,7 @@ static int CeedSingleOperatorAssembleSetup_Hip(CeedOperator op, CeedInt use_ceed CeedCallBackend(CeedFree(&identity)); } CeedCallBackend(CeedFree(&eval_modes_out)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedElemRestrictionDestroy(&rstr_in)); CeedCallBackend(CeedElemRestrictionDestroy(&rstr_out)); CeedCallBackend(CeedBasisDestroy(&basis_in)); @@ -1766,6 +1772,7 @@ static int CeedSingleOperatorAssemble_Hip(CeedOperator op, CeedInt offset, CeedV CeedCallBackend(CeedElemRestrictionRestoreCurlOrientations(rstr_out, &curl_orients_out)); } } + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedElemRestrictionDestroy(&rstr_in)); CeedCallBackend(CeedElemRestrictionDestroy(&rstr_out)); return CEED_ERROR_SUCCESS; @@ -2037,6 +2044,7 @@ static int CeedOperatorLinearAssembleAddDiagonalAtPoints_Hip(CeedOperator op, Ce // Restore work vector CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec_in)); CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec_out)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -2059,6 +2067,7 @@ int CeedOperatorCreate_Hip(CeedOperator op) { CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleSingle", CeedSingleOperatorAssemble_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "ApplyAdd", CeedOperatorApplyAdd_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "Destroy", CeedOperatorDestroy_Hip)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -2077,6 +2086,7 @@ int CeedOperatorCreateAtPoints_Hip(CeedOperator op) { CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleAddDiagonal", CeedOperatorLinearAssembleAddDiagonalAtPoints_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "ApplyAdd", CeedOperatorApplyAddAtPoints_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "Destroy", CeedOperatorDestroy_Hip)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/hip-ref/ceed-hip-ref-qfunction-load.cpp b/backends/hip-ref/ceed-hip-ref-qfunction-load.cpp index 2311f8a332..3f9d0e9472 100644 --- a/backends/hip-ref/ceed-hip-ref-qfunction-load.cpp +++ b/backends/hip-ref/ceed-hip-ref-qfunction-load.cpp @@ -116,6 +116,7 @@ extern "C" int CeedQFunctionBuildKernel_Hip_ref(CeedQFunction qf) { // Compile kernel CeedCallBackend(CeedCompile_Hip(ceed, code.str().c_str(), &data->module, 1, "BLOCK_SIZE", ceed_Hip->opt_block_size)); CeedCallBackend(CeedGetKernel_Hip(ceed, data->module, kernel_name.c_str(), &data->QFunction)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/hip-ref/ceed-hip-ref-qfunction.c b/backends/hip-ref/ceed-hip-ref-qfunction.c index 18d531ac11..92835b897e 100644 --- a/backends/hip-ref/ceed-hip-ref-qfunction.c +++ b/backends/hip-ref/ceed-hip-ref-qfunction.c @@ -60,6 +60,7 @@ static int CeedQFunctionApply_Hip(CeedQFunction qf, CeedInt Q, CeedVector *U, Ce // Restore context CeedCallBackend(CeedQFunctionRestoreInnerContextData(qf, &data->d_c)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -88,12 +89,12 @@ int CeedQFunctionCreate_Hip(CeedQFunction qf) { CeedCallBackend(CeedQFunctionSetData(qf, data)); CeedCallBackend(CeedQFunctionGetNumArgs(qf, &num_input_fields, &num_output_fields)); - // Read QFunction name CeedCallBackend(CeedQFunctionGetKernelName(qf, &data->qfunction_name)); // Register backend functions CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Hip)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/hip-ref/ceed-hip-ref-qfunctioncontext.c b/backends/hip-ref/ceed-hip-ref-qfunctioncontext.c index 52bf13370b..0d09a2087d 100644 --- a/backends/hip-ref/ceed-hip-ref-qfunctioncontext.c +++ b/backends/hip-ref/ceed-hip-ref-qfunctioncontext.c @@ -37,6 +37,7 @@ static inline int CeedQFunctionContextSyncH2D_Hip(const CeedQFunctionContext ctx impl->d_data = impl->d_data_owned; } CeedCallHip(ceed, hipMemcpy(impl->d_data, impl->h_data, ctx_size, hipMemcpyHostToDevice)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -63,6 +64,7 @@ static inline int CeedQFunctionContextSyncD2H_Hip(const CeedQFunctionContext ctx impl->h_data = impl->h_data_owned; } CeedCallHip(ceed, hipMemcpy(impl->h_data, impl->d_data, ctx_size, hipMemcpyDeviceToHost)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -204,6 +206,7 @@ static int CeedQFunctionContextSetDataDevice_Hip(const CeedQFunctionContext ctx, impl->d_data = data; break; } + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -334,6 +337,7 @@ int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx) { CeedCallBackend(CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "GetData", CeedQFunctionContextGetData_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "GetDataRead", CeedQFunctionContextGetDataRead_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "Destroy", CeedQFunctionContextDestroy_Hip)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedCalloc(1, &impl)); CeedCallBackend(CeedQFunctionContextSetBackendData(ctx, impl)); return CEED_ERROR_SUCCESS; diff --git a/backends/hip-ref/ceed-hip-ref-restriction.c b/backends/hip-ref/ceed-hip-ref-restriction.c index ca1d19d7a6..326061456b 100644 --- a/backends/hip-ref/ceed-hip-ref-restriction.c +++ b/backends/hip-ref/ceed-hip-ref-restriction.c @@ -108,6 +108,7 @@ static inline int CeedElemRestrictionSetupCompile_Hip(CeedElemRestriction rstr) } break; } + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -287,6 +288,7 @@ static inline int CeedElemRestrictionApply_Hip_Core(CeedElemRestriction rstr, Ce // Restore arrays CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -406,6 +408,7 @@ static int CeedElemRestrictionDestroy_Hip(CeedElemRestriction rstr) { CeedCallBackend(CeedFree(&impl->h_points_per_elem_owned)); CeedCallHip(ceed, hipFree((CeedInt *)impl->d_points_per_elem_owned)); CeedCallBackend(CeedFree(&impl)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -487,6 +490,7 @@ static int CeedElemRestrictionOffset_Hip(const CeedElemRestriction rstr, const C CeedCallBackend(CeedFree(&l_vec_indices)); CeedCallBackend(CeedFree(&t_offsets)); CeedCallBackend(CeedFree(&t_indices)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -651,6 +655,7 @@ int CeedElemRestrictionCreate_Hip(CeedMemType mem_type, CeedCopyMode copy_mode, CeedSetBackendFunction(ceed, "ElemRestriction", rstr, "GetAtPointsElementOffset", CeedElemRestrictionGetAtPointsElementOffset_Hip)); } CeedCallBackend(CeedSetBackendFunction(ceed, "ElemRestriction", rstr, "Destroy", CeedElemRestrictionDestroy_Hip)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/hip-ref/ceed-hip-ref-vector.c b/backends/hip-ref/ceed-hip-ref-vector.c index 164eb822d6..0a3a3fe3d0 100644 --- a/backends/hip-ref/ceed-hip-ref-vector.c +++ b/backends/hip-ref/ceed-hip-ref-vector.c @@ -39,15 +39,13 @@ static inline int CeedVectorNeedSync_Hip(const CeedVector vec, CeedMemType mem_t // Sync host to device //------------------------------------------------------------------------------ static inline int CeedVectorSyncH2D_Hip(const CeedVector vec) { - Ceed ceed; CeedSize length; size_t bytes; CeedVector_Hip *impl; - CeedCallBackend(CeedVectorGetCeed(vec, &ceed)); CeedCallBackend(CeedVectorGetData(vec, &impl)); - CeedCheck(impl->h_array, ceed, CEED_ERROR_BACKEND, "No valid host data to sync to device"); + CeedCheck(impl->h_array, CeedVectorReturnCeed(vec), CEED_ERROR_BACKEND, "No valid host data to sync to device"); CeedCallBackend(CeedVectorGetLength(vec, &length)); bytes = length * sizeof(CeedScalar); @@ -56,10 +54,10 @@ static inline int CeedVectorSyncH2D_Hip(const CeedVector vec) { } else if (impl->d_array_owned) { impl->d_array = impl->d_array_owned; } else { - CeedCallHip(ceed, hipMalloc((void **)&impl->d_array_owned, bytes)); + CeedCallHip(CeedVectorReturnCeed(vec), hipMalloc((void **)&impl->d_array_owned, bytes)); impl->d_array = impl->d_array_owned; } - CeedCallHip(ceed, hipMemcpy(impl->d_array, impl->h_array, bytes, hipMemcpyHostToDevice)); + CeedCallHip(CeedVectorReturnCeed(vec), hipMemcpy(impl->d_array, impl->h_array, bytes, hipMemcpyHostToDevice)); return CEED_ERROR_SUCCESS; } @@ -67,15 +65,13 @@ static inline int CeedVectorSyncH2D_Hip(const CeedVector vec) { // Sync device to host //------------------------------------------------------------------------------ static inline int CeedVectorSyncD2H_Hip(const CeedVector vec) { - Ceed ceed; CeedSize length; size_t bytes; CeedVector_Hip *impl; - CeedCallBackend(CeedVectorGetCeed(vec, &ceed)); CeedCallBackend(CeedVectorGetData(vec, &impl)); - CeedCheck(impl->d_array, ceed, CEED_ERROR_BACKEND, "No valid device data to sync to host"); + CeedCheck(impl->d_array, CeedVectorReturnCeed(vec), CEED_ERROR_BACKEND, "No valid device data to sync to host"); if (impl->h_array_borrowed) { impl->h_array = impl->h_array_borrowed; @@ -91,7 +87,7 @@ static inline int CeedVectorSyncD2H_Hip(const CeedVector vec) { CeedCallBackend(CeedVectorGetLength(vec, &length)); bytes = length * sizeof(CeedScalar); - CeedCallHip(ceed, hipMemcpy(impl->h_array, impl->d_array, bytes, hipMemcpyDeviceToHost)); + CeedCallHip(CeedVectorReturnCeed(vec), hipMemcpy(impl->h_array, impl->d_array, bytes, hipMemcpyDeviceToHost)); return CEED_ERROR_SUCCESS; } @@ -202,6 +198,7 @@ static int CeedVectorSetArrayDevice_Hip(const CeedVector vec, const CeedCopyMode CeedCallBackend(CeedSetDeviceCeedScalarArray_Hip(ceed, array, copy_mode, length, (const CeedScalar **)&impl->d_array_owned, (const CeedScalar **)&impl->d_array_borrowed, (const CeedScalar **)&impl->d_array)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -574,6 +571,7 @@ static int CeedVectorNorm_Hip(CeedVector vec, CeedNormType type, CeedScalar *nor } } CeedCallBackend(CeedVectorRestoreArrayRead(vec, &d_array)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -786,6 +784,7 @@ int CeedVectorCreate_Hip(CeedSize n, CeedVector vec) { CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "AXPBY", CeedVectorAXPBY_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "PointwiseMult", CeedVectorPointwiseMult_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "Destroy", CeedVectorDestroy_Hip)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedCalloc(1, &impl)); CeedCallBackend(CeedVectorSetData(vec, impl)); return CEED_ERROR_SUCCESS; diff --git a/backends/hip-shared/ceed-hip-shared-basis.c b/backends/hip-shared/ceed-hip-shared-basis.c index cdcc28ce07..68aaa0b3a1 100644 --- a/backends/hip-shared/ceed-hip-shared-basis.c +++ b/backends/hip-shared/ceed-hip-shared-basis.c @@ -248,6 +248,7 @@ static int CeedBasisApplyTensorCore_Hip_shared(CeedBasis basis, bool apply_add, CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); if (eval_mode == CEED_EVAL_NONE) CeedCallBackend(CeedVectorSetArray(v, CEED_MEM_DEVICE, CEED_COPY_VALUES, (CeedScalar *)d_u)); if (eval_mode != CEED_EVAL_WEIGHT) CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -507,6 +508,7 @@ int CeedBasisCreateTensorH1_Hip_shared(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAtPoints", CeedBasisApplyAtPoints_Hip_shared)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAddAtPoints", CeedBasisApplyAddAtPoints_Hip_shared)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroy_Hip_shared)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/magma/ceed-magma-basis.c b/backends/magma/ceed-magma-basis.c index 6f5fa0a2ca..e25efe84fe 100644 --- a/backends/magma/ceed-magma-basis.c +++ b/backends/magma/ceed-magma-basis.c @@ -249,6 +249,7 @@ static int CeedBasisApplyCore_Magma(CeedBasis basis, bool apply_add, CeedInt num CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); } CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -457,6 +458,7 @@ static int CeedBasisApplyNonTensorCore_Magma(CeedBasis basis, bool apply_add, Ce CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); } CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -490,6 +492,7 @@ static int CeedBasisDestroy_Magma(CeedBasis basis) { CeedCallBackend(magma_free(impl->d_grad_1d)); if (impl->d_q_weight_1d) CeedCallBackend(magma_free(impl->d_q_weight_1d)); CeedCallBackend(CeedFree(&impl)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -517,6 +520,7 @@ static int CeedBasisDestroyNonTensor_Magma(CeedBasis basis) { CeedCallBackend(magma_free(impl->d_curl)); if (impl->d_q_weight) CeedCallBackend(magma_free(impl->d_q_weight)); CeedCallBackend(CeedFree(&impl)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -626,6 +630,7 @@ int CeedBasisCreateTensorH1_Magma(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAdd", CeedBasisApplyAdd_Magma)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAtPoints", CeedBasisApplyAtPoints_Magma)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroy_Magma)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -688,6 +693,7 @@ int CeedBasisCreateH1_Magma(CeedElemTopology topo, CeedInt dim, CeedInt num_node CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApplyNonTensor_Magma)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAdd", CeedBasisApplyAddNonTensor_Magma)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroyNonTensor_Magma)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -750,6 +756,7 @@ int CeedBasisCreateHdiv_Magma(CeedElemTopology topo, CeedInt dim, CeedInt num_no CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApplyNonTensor_Magma)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAdd", CeedBasisApplyAddNonTensor_Magma)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroyNonTensor_Magma)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -812,6 +819,7 @@ int CeedBasisCreateHcurl_Magma(CeedElemTopology topo, CeedInt dim, CeedInt num_n CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApplyNonTensor_Magma)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAdd", CeedBasisApplyAddNonTensor_Magma)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroyNonTensor_Magma)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/memcheck/ceed-memcheck-qfunction.c b/backends/memcheck/ceed-memcheck-qfunction.c index 1bb8158584..b73e3c5e90 100644 --- a/backends/memcheck/ceed-memcheck-qfunction.c +++ b/backends/memcheck/ceed-memcheck-qfunction.c @@ -17,7 +17,6 @@ // QFunction Apply //------------------------------------------------------------------------------ static int CeedQFunctionApply_Memcheck(CeedQFunction qf, CeedInt Q, CeedVector *U, CeedVector *V) { - Ceed ceed; void *ctx_data = NULL; int input_block_ids[CEED_FIELD_MAX], output_block_ids[CEED_FIELD_MAX]; CeedInt num_in, num_out; @@ -25,7 +24,6 @@ static int CeedQFunctionApply_Memcheck(CeedQFunction qf, CeedInt Q, CeedVector * CeedQFunctionField *output_fields; CeedQFunction_Memcheck *impl; - CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed)); CeedCallBackend(CeedQFunctionGetData(qf, &impl)); CeedCallBackend(CeedQFunctionGetContextData(qf, CEED_MEM_HOST, &ctx_data)); CeedCallBackend(CeedQFunctionGetUserFunction(qf, &f)); @@ -82,7 +80,7 @@ static int CeedQFunctionApply_Memcheck(CeedQFunction qf, CeedInt Q, CeedVector * CeedCallBackend(CeedQFunctionFieldGetSize(output_fields[i], &field_size)); CeedCallBackend(CeedQFunctionFieldGetName(output_fields[i], &field_name)); for (CeedSize j = 0; j < field_size * (CeedSize)Q; j++) { - CeedCheck(!isnan(impl->outputs[i][j]), ceed, CEED_ERROR_BACKEND, + CeedCheck(!isnan(impl->outputs[i][j]), CeedQFunctionReturnCeed(qf), CEED_ERROR_BACKEND, "QFunction output %" CeedInt_FMT " '%s' entry %" CeedSize_FMT " is NaN after restoring write-only access: %s:%s ", i, field_name, j, kernel_path, kernel_name); } @@ -121,6 +119,7 @@ int CeedQFunctionCreate_Memcheck(CeedQFunction qf) { CeedCallBackend(CeedQFunctionSetData(qf, impl)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Memcheck)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Memcheck)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/memcheck/ceed-memcheck-qfunctioncontext.c b/backends/memcheck/ceed-memcheck-qfunctioncontext.c index 57afe981af..6149a5a3ac 100644 --- a/backends/memcheck/ceed-memcheck-qfunctioncontext.c +++ b/backends/memcheck/ceed-memcheck-qfunctioncontext.c @@ -206,18 +206,16 @@ static int CeedQFunctionContextRestoreData_Memcheck(CeedQFunctionContext ctx) { // QFunctionContext Restore Data Read-Only //------------------------------------------------------------------------------ static int CeedQFunctionContextRestoreDataRead_Memcheck(CeedQFunctionContext ctx) { - Ceed ceed; size_t ctx_size; CeedQFunctionContext_Memcheck *impl; - CeedCallBackend(CeedQFunctionContextGetCeed(ctx, &ceed)); CeedCallBackend(CeedQFunctionContextGetContextSize(ctx, &ctx_size)); CeedCallBackend(CeedQFunctionContextGetBackendData(ctx, &impl)); // Verify no changes made during read-only access bool is_changed = memcmp(impl->data_allocated, impl->data_read_only_copy, ctx_size); - CeedCheck(!is_changed, ceed, CEED_ERROR_BACKEND, "Context data changed while accessed in read-only mode"); + CeedCheck(!is_changed, CeedQFunctionContextReturnCeed(ctx), CEED_ERROR_BACKEND, "Context data changed while accessed in read-only mode"); // Invalidate read-only buffer memset(impl->data_read_only_copy, -42, ctx_size); @@ -230,16 +228,15 @@ static int CeedQFunctionContextRestoreDataRead_Memcheck(CeedQFunctionContext ctx // QFunctionContext destroy user data //------------------------------------------------------------------------------ static int CeedQFunctionContextDataDestroy_Memcheck(CeedQFunctionContext ctx) { - Ceed ceed; CeedMemType data_destroy_mem_type; CeedQFunctionContextDataDestroyUser data_destroy_function; CeedQFunctionContext_Memcheck *impl; - CeedCallBackend(CeedQFunctionContextGetCeed(ctx, &ceed)); CeedCallBackend(CeedQFunctionContextGetBackendData(ctx, &impl)); CeedCallBackend(CeedQFunctionContextGetDataDestroy(ctx, &data_destroy_mem_type, &data_destroy_function)); - CeedCheck(data_destroy_mem_type == CEED_MEM_HOST, ceed, CEED_ERROR_BACKEND, "Can only destroy HOST memory for this backend"); + CeedCheck(data_destroy_mem_type == CEED_MEM_HOST, CeedQFunctionContextReturnCeed(ctx), CEED_ERROR_BACKEND, + "Can only destroy HOST memory for this backend"); // Run user destroy routine if (data_destroy_function) { @@ -305,6 +302,7 @@ int CeedQFunctionContextCreate_Memcheck(CeedQFunctionContext ctx) { CeedCallBackend(CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "RestoreDataRead", CeedQFunctionContextRestoreDataRead_Memcheck)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "DataDestroy", CeedQFunctionContextDataDestroy_Memcheck)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "Destroy", CeedQFunctionContextDestroy_Memcheck)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedCalloc(1, &impl)); CeedCallBackend(CeedQFunctionContextSetBackendData(ctx, impl)); return CEED_ERROR_SUCCESS; diff --git a/backends/memcheck/ceed-memcheck-restriction.c b/backends/memcheck/ceed-memcheck-restriction.c index 35d3016726..57faf28116 100644 --- a/backends/memcheck/ceed-memcheck-restriction.c +++ b/backends/memcheck/ceed-memcheck-restriction.c @@ -768,6 +768,7 @@ int CeedElemRestrictionCreate_Memcheck(CeedMemType mem_type, CeedCopyMode copy_m CeedCallBackend(CeedSetBackendFunction(ceed, "ElemRestriction", rstr, "GetOrientations", CeedElemRestrictionGetOrientations_Memcheck)); CeedCallBackend(CeedSetBackendFunction(ceed, "ElemRestriction", rstr, "GetCurlOrientations", CeedElemRestrictionGetCurlOrientations_Memcheck)); CeedCallBackend(CeedSetBackendFunction(ceed, "ElemRestriction", rstr, "Destroy", CeedElemRestrictionDestroy_Memcheck)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/memcheck/ceed-memcheck-vector.c b/backends/memcheck/ceed-memcheck-vector.c index 325fd52c34..52716d5c70 100644 --- a/backends/memcheck/ceed-memcheck-vector.c +++ b/backends/memcheck/ceed-memcheck-vector.c @@ -248,11 +248,9 @@ static int CeedVectorGetArrayWrite_Memcheck(CeedVector vec, CeedMemType mem_type // Vector Restore Array //------------------------------------------------------------------------------ static int CeedVectorRestoreArray_Memcheck(CeedVector vec) { - Ceed ceed; CeedSize length; CeedVector_Memcheck *impl; - CeedCallBackend(CeedVectorGetCeed(vec, &ceed)); CeedCallBackend(CeedVectorGetData(vec, &impl)); CeedCallBackend(CeedVectorGetLength(vec, &length)); @@ -260,7 +258,8 @@ static int CeedVectorRestoreArray_Memcheck(CeedVector vec) { if (impl->is_write_only_access) { for (CeedSize i = 0; i < length; i++) { if (isnan(impl->array_writable_copy[i])) { - CeedDebug256(ceed, CEED_DEBUG_COLOR_WARNING, "WARNING: Vec entry %" CeedSize_FMT " is NaN after restoring write-only access", i); + CeedDebug256(CeedVectorReturnCeed(vec), CEED_DEBUG_COLOR_WARNING, + "WARNING: Vec entry %" CeedSize_FMT " is NaN after restoring write-only access", i); } } impl->is_write_only_access = false; @@ -281,18 +280,16 @@ static int CeedVectorRestoreArray_Memcheck(CeedVector vec) { // Vector Restore Array Read-Only //------------------------------------------------------------------------------ static int CeedVectorRestoreArrayRead_Memcheck(CeedVector vec) { - Ceed ceed; CeedSize length; CeedVector_Memcheck *impl; - CeedCallBackend(CeedVectorGetCeed(vec, &ceed)); CeedCallBackend(CeedVectorGetData(vec, &impl)); CeedCallBackend(CeedVectorGetLength(vec, &length)); // Verify no changes made during read-only access bool is_changed = memcmp(impl->array_allocated, impl->array_read_only_copy, length * sizeof(CeedScalar)); - CeedCheck(!is_changed, ceed, CEED_ERROR_BACKEND, "Array data changed while accessed in read-only mode"); + CeedCheck(!is_changed, CeedVectorReturnCeed(vec), CEED_ERROR_BACKEND, "Array data changed while accessed in read-only mode"); // Invalidate read-only buffer for (CeedSize i = 0; i < length; i++) impl->array_read_only_copy[i] = NAN; @@ -409,9 +406,6 @@ int CeedVectorCreate_Memcheck(CeedSize n, CeedVector vec) { Ceed ceed; CeedVector_Memcheck *impl; - CeedCallBackend(CeedCalloc(1, &impl)); - CeedCallBackend(CeedVectorSetData(vec, impl)); - CeedCallBackend(CeedVectorGetCeed(vec, &ceed)); CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "HasValidArray", CeedVectorHasValidArray_Memcheck)); CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "HasBorrowedArrayOfType", CeedVectorHasBorrowedArrayOfType_Memcheck)); @@ -431,6 +425,9 @@ int CeedVectorCreate_Memcheck(CeedSize n, CeedVector vec) { CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "AXPBY", CeedVectorAXPBY_Memcheck)); CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "PointwiseMult", CeedVectorPointwiseMult_Memcheck)); CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "Destroy", CeedVectorDestroy_Memcheck)); + CeedCallBackend(CeedDestroy(&ceed)); + CeedCallBackend(CeedCalloc(1, &impl)); + CeedCallBackend(CeedVectorSetData(vec, impl)); return CEED_ERROR_SUCCESS; } diff --git a/backends/opt/ceed-opt-operator.c b/backends/opt/ceed-opt-operator.c index 8057741208..3dee660278 100644 --- a/backends/opt/ceed-opt-operator.c +++ b/backends/opt/ceed-opt-operator.c @@ -30,7 +30,7 @@ static int CeedOperatorSetupFields_Opt(CeedQFunction qf, CeedOperator op, bool i CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); CeedCallBackend(CeedGetParent(ceed, &ceed_parent)); - if (ceed_parent) ceed = ceed_parent; + if (ceed_parent) CeedCallBackend(CeedReferenceCopy(ceed_parent, &ceed)); } if (is_input) { CeedCallBackend(CeedOperatorGetFields(op, NULL, &op_fields, NULL, NULL)); @@ -105,6 +105,7 @@ static int CeedOperatorSetupFields_Opt(CeedQFunction qf, CeedOperator op, bool i // Empty case - won't occur break; } + CeedCallBackend(CeedDestroy(&ceed_rstr)); CeedCallBackend(CeedElemRestrictionDestroy(&rstr)); CeedCallBackend(CeedElemRestrictionCreateVector(block_rstr[i + start_e], NULL, &e_vecs_full[i + start_e])); } @@ -193,6 +194,7 @@ static int CeedOperatorSetupFields_Opt(CeedQFunction qf, CeedOperator op, bool i CeedCallBackend(CeedElemRestrictionDestroy(&rstr_i)); } } + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -214,6 +216,7 @@ static int CeedOperatorSetup_Opt(CeedOperator op) { CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); CeedCallBackend(CeedGetData(ceed, &ceed_impl)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedOperatorGetData(op, &impl)); CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); CeedCallBackend(CeedOperatorGetNumQuadraturePoints(op, &Q)); @@ -447,6 +450,7 @@ static int CeedOperatorApplyAdd_Opt(CeedOperator op, CeedVector in_vec, CeedVect CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); CeedCallBackend(CeedGetData(ceed, &ceed_impl)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedOperatorGetData(op, &impl)); CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem)); CeedCallBackend(CeedOperatorGetNumQuadraturePoints(op, &Q)); @@ -712,6 +716,7 @@ static inline int CeedOperatorLinearAssembleQFunctionCore_Opt(CeedOperator op, b // Restore input arrays CeedCallBackend(CeedOperatorRestoreInputs_Opt(num_input_fields, qf_input_fields, op_input_fields, e_data, impl)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -790,6 +795,7 @@ int CeedOperatorCreate_Opt(CeedOperator op) { CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleQFunctionUpdate", CeedOperatorLinearAssembleQFunctionUpdate_Opt)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "ApplyAdd", CeedOperatorApplyAdd_Opt)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "Destroy", CeedOperatorDestroy_Opt)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/ref/ceed-ref-basis.c b/backends/ref/ceed-ref-basis.c index 121669012a..322d13d721 100644 --- a/backends/ref/ceed-ref-basis.c +++ b/backends/ref/ceed-ref-basis.c @@ -18,7 +18,6 @@ //------------------------------------------------------------------------------ static int CeedBasisApplyCore_Ref(CeedBasis basis, bool apply_add, CeedInt num_elem, CeedTransposeMode t_mode, CeedEvalMode eval_mode, CeedVector U, CeedVector V) { - Ceed ceed; bool is_tensor_basis, add = apply_add || (t_mode == CEED_TRANSPOSE); CeedInt dim, num_comp, q_comp, num_nodes, num_qpts; const CeedScalar *u; @@ -26,7 +25,6 @@ static int CeedBasisApplyCore_Ref(CeedBasis basis, bool apply_add, CeedInt num_e CeedTensorContract contract; CeedBasis_Ref *impl; - CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); CeedCallBackend(CeedBasisGetData(basis, &impl)); CeedCallBackend(CeedBasisGetDimension(basis, &dim)); CeedCallBackend(CeedBasisGetNumComponents(basis, &num_comp)); @@ -35,7 +33,7 @@ static int CeedBasisApplyCore_Ref(CeedBasis basis, bool apply_add, CeedInt num_e CeedCallBackend(CeedBasisGetNumQuadraturePoints(basis, &num_qpts)); CeedCallBackend(CeedBasisGetTensorContract(basis, &contract)); if (U != CEED_VECTOR_NONE) CeedCallBackend(CeedVectorGetArrayRead(U, CEED_MEM_HOST, &u)); - else CeedCheck(eval_mode == CEED_EVAL_WEIGHT, ceed, CEED_ERROR_BACKEND, "An input vector is required for this CeedEvalMode"); + else CeedCheck(eval_mode == CEED_EVAL_WEIGHT, CeedBasisReturnCeed(basis), CEED_ERROR_BACKEND, "An input vector is required for this CeedEvalMode"); // Clear v if operating in transpose if (apply_add) CeedCallBackend(CeedVectorGetArray(V, CEED_MEM_HOST, &v)); else CeedCallBackend(CeedVectorGetArrayWrite(V, CEED_MEM_HOST, &v)); @@ -172,7 +170,7 @@ static int CeedBasisApplyCore_Ref(CeedBasis basis, bool apply_add, CeedInt num_e CeedInt Q = Q_1d; const CeedScalar *q_weight_1d; - CeedCheck(t_mode == CEED_NOTRANSPOSE, ceed, CEED_ERROR_BACKEND, "CEED_EVAL_WEIGHT incompatible with CEED_TRANSPOSE"); + CeedCheck(t_mode == CEED_NOTRANSPOSE, CeedBasisReturnCeed(basis), CEED_ERROR_BACKEND, "CEED_EVAL_WEIGHT incompatible with CEED_TRANSPOSE"); CeedCallBackend(CeedBasisGetQWeights(basis, &q_weight_1d)); for (CeedInt d = 0; d < dim; d++) { CeedInt pre = CeedIntPow(Q, dim - d - 1), post = CeedIntPow(Q, d); @@ -191,9 +189,9 @@ static int CeedBasisApplyCore_Ref(CeedBasis basis, bool apply_add, CeedInt num_e // LCOV_EXCL_START case CEED_EVAL_DIV: case CEED_EVAL_CURL: - return CeedError(ceed, CEED_ERROR_BACKEND, "%s not supported", CeedEvalModes[eval_mode]); + return CeedError(CeedBasisReturnCeed(basis), CEED_ERROR_BACKEND, "%s not supported", CeedEvalModes[eval_mode]); case CEED_EVAL_NONE: - return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_NONE does not make sense in this context"); + return CeedError(CeedBasisReturnCeed(basis), CEED_ERROR_BACKEND, "CEED_EVAL_NONE does not make sense in this context"); // LCOV_EXCL_STOP } } else { @@ -233,7 +231,7 @@ static int CeedBasisApplyCore_Ref(CeedBasis basis, bool apply_add, CeedInt num_e case CEED_EVAL_WEIGHT: { const CeedScalar *q_weight; - CeedCheck(t_mode == CEED_NOTRANSPOSE, ceed, CEED_ERROR_BACKEND, "CEED_EVAL_WEIGHT incompatible with CEED_TRANSPOSE"); + CeedCheck(t_mode == CEED_NOTRANSPOSE, CeedBasisReturnCeed(basis), CEED_ERROR_BACKEND, "CEED_EVAL_WEIGHT incompatible with CEED_TRANSPOSE"); CeedCallBackend(CeedBasisGetQWeights(basis, &q_weight)); for (CeedInt i = 0; i < num_qpts; i++) { for (CeedInt e = 0; e < num_elem; e++) v[i * num_elem + e] = q_weight[i]; @@ -241,7 +239,7 @@ static int CeedBasisApplyCore_Ref(CeedBasis basis, bool apply_add, CeedInt num_e } break; // LCOV_EXCL_START case CEED_EVAL_NONE: - return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_NONE does not make sense in this context"); + return CeedError(CeedBasisReturnCeed(basis), CEED_ERROR_BACKEND, "CEED_EVAL_NONE does not make sense in this context"); // LCOV_EXCL_STOP } } @@ -312,6 +310,7 @@ int CeedBasisCreateTensorH1_Ref(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const C CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApply_Ref)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAdd", CeedBasisApplyAdd_Ref)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroyTensor_Ref)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -331,6 +330,7 @@ int CeedBasisCreateH1_Ref(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApply_Ref)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAdd", CeedBasisApplyAdd_Ref)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -350,6 +350,7 @@ int CeedBasisCreateHdiv_Ref(CeedElemTopology topo, CeedInt dim, CeedInt num_node CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApply_Ref)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAdd", CeedBasisApplyAdd_Ref)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -369,6 +370,7 @@ int CeedBasisCreateHcurl_Ref(CeedElemTopology topo, CeedInt dim, CeedInt num_nod CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApply_Ref)); CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "ApplyAdd", CeedBasisApplyAdd_Ref)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/ref/ceed-ref-operator.c b/backends/ref/ceed-ref-operator.c index 4c62608d49..d4b179a7a9 100644 --- a/backends/ref/ceed-ref-operator.c +++ b/backends/ref/ceed-ref-operator.c @@ -30,7 +30,7 @@ static int CeedOperatorSetupFields_Ref(CeedQFunction qf, CeedOperator op, bool i CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); CeedCallBackend(CeedGetParent(ceed, &ceed_parent)); - if (ceed_parent) ceed = ceed_parent; + if (ceed_parent) CeedCallBackend(CeedReferenceCopy(ceed_parent, &ceed)); } if (is_input) { CeedCallBackend(CeedOperatorGetFields(op, NULL, &op_fields, NULL, NULL)); @@ -134,6 +134,7 @@ static int CeedOperatorSetupFields_Ref(CeedQFunction qf, CeedOperator op, bool i CeedCallBackend(CeedElemRestrictionDestroy(&rstr_i)); } } + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -472,7 +473,7 @@ static int CeedOperatorApplyAdd_Ref(CeedOperator op, CeedVector in_vec, CeedVect //------------------------------------------------------------------------------ static inline int CeedOperatorLinearAssembleQFunctionCore_Ref(CeedOperator op, bool build_objects, CeedVector *assembled, CeedElemRestriction *rstr, CeedRequest *request) { - Ceed ceed, ceed_parent; + Ceed ceed_parent; CeedInt qf_size_in, qf_size_out, Q, num_elem, num_input_fields, num_output_fields; CeedScalar *assembled_array, *e_data_full[2 * CEED_FIELD_MAX] = {NULL}; CeedQFunctionField *qf_input_fields, *qf_output_fields; @@ -480,7 +481,6 @@ static inline int CeedOperatorLinearAssembleQFunctionCore_Ref(CeedOperator op, b CeedOperatorField *op_input_fields, *op_output_fields; CeedOperator_Ref *impl; - CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); CeedCallBackend(CeedOperatorGetFallbackParentCeed(op, &ceed_parent)); CeedCallBackend(CeedOperatorGetData(op, &impl)); qf_size_in = impl->qf_size_in; @@ -495,7 +495,7 @@ static inline int CeedOperatorLinearAssembleQFunctionCore_Ref(CeedOperator op, b CeedCallBackend(CeedOperatorSetup_Ref(op)); // Check for restriction only operator - CeedCheck(!impl->is_identity_rstr_op, ceed, CEED_ERROR_BACKEND, "Assembling restriction only operators is not supported"); + CeedCheck(!impl->is_identity_rstr_op, CeedOperatorReturnCeed(op), CEED_ERROR_BACKEND, "Assembling restriction only operators is not supported"); // Input Evecs and Restriction CeedCallBackend(CeedOperatorSetupInputs_Ref(num_input_fields, qf_input_fields, op_input_fields, NULL, true, e_data_full, impl, request)); @@ -516,7 +516,7 @@ static inline int CeedOperatorLinearAssembleQFunctionCore_Ref(CeedOperator op, b } CeedCallBackend(CeedVectorDestroy(&vec)); } - CeedCheck(qf_size_in > 0, ceed, CEED_ERROR_BACKEND, "Cannot assemble QFunction without active inputs and outputs"); + CeedCheck(qf_size_in > 0, CeedOperatorReturnCeed(op), CEED_ERROR_BACKEND, "Cannot assemble QFunction without active inputs and outputs"); impl->qf_size_in = qf_size_in; } @@ -535,7 +535,7 @@ static inline int CeedOperatorLinearAssembleQFunctionCore_Ref(CeedOperator op, b } CeedCallBackend(CeedVectorDestroy(&vec)); } - CeedCheck(qf_size_out > 0, ceed, CEED_ERROR_BACKEND, "Cannot assemble QFunction without active inputs and outputs"); + CeedCheck(qf_size_out > 0, CeedOperatorReturnCeed(op), CEED_ERROR_BACKEND, "Cannot assemble QFunction without active inputs and outputs"); impl->qf_size_out = qf_size_out; } @@ -678,7 +678,7 @@ static int CeedOperatorSetupFieldsAtPoints_Ref(CeedQFunction qf, CeedOperator op CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); CeedCallBackend(CeedGetParent(ceed, &ceed_parent)); - if (ceed_parent) ceed = ceed_parent; + if (ceed_parent) CeedCallBackend(CeedReferenceCopy(ceed_parent, &ceed)); } if (is_input) { CeedCallBackend(CeedOperatorGetFields(op, NULL, &op_fields, NULL, NULL)); @@ -1282,6 +1282,7 @@ static inline int CeedOperatorLinearAssembleQFunctionAtPointsCore_Ref(CeedOperat CeedCallBackend(CeedVectorRestoreArray(*assembled, &assembled_array)); // Cleanup + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedVectorDestroy(&point_coords)); CeedCallBackend(CeedElemRestrictionDestroy(&rstr_points)); return CEED_ERROR_SUCCESS; @@ -1331,7 +1332,7 @@ static int CeedOperatorLinearAssembleAddDiagonalAtPoints_Ref(CeedOperator op, Ce CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); CeedCallBackend(CeedGetParent(ceed, &ceed_parent)); - if (ceed_parent) ceed = ceed_parent; + if (ceed_parent) CeedCallBackend(CeedReferenceCopy(ceed_parent, &ceed)); } // Point coordinates @@ -1587,6 +1588,7 @@ int CeedOperatorCreate_Ref(CeedOperator op) { CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleQFunctionUpdate", CeedOperatorLinearAssembleQFunctionUpdate_Ref)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "ApplyAdd", CeedOperatorApplyAdd_Ref)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "Destroy", CeedOperatorDestroy_Ref)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -1606,6 +1608,7 @@ int CeedOperatorCreateAtPoints_Ref(CeedOperator op) { CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "LinearAssembleAddDiagonal", CeedOperatorLinearAssembleAddDiagonalAtPoints_Ref)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "ApplyAdd", CeedOperatorApplyAddAtPoints_Ref)); CeedCallBackend(CeedSetBackendFunction(ceed, "Operator", op, "Destroy", CeedOperatorDestroy_Ref)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/ref/ceed-ref-qfunction.c b/backends/ref/ceed-ref-qfunction.c index d2bbd07ad1..efddda2dcc 100644 --- a/backends/ref/ceed-ref-qfunction.c +++ b/backends/ref/ceed-ref-qfunction.c @@ -71,6 +71,7 @@ int CeedQFunctionCreate_Ref(CeedQFunction qf) { CeedCallBackend(CeedQFunctionSetData(qf, impl)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Ref)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Ref)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/ref/ceed-ref-qfunctioncontext.c b/backends/ref/ceed-ref-qfunctioncontext.c index 9fd2d013db..0d3c8bba36 100644 --- a/backends/ref/ceed-ref-qfunctioncontext.c +++ b/backends/ref/ceed-ref-qfunctioncontext.c @@ -131,6 +131,7 @@ int CeedQFunctionContextCreate_Ref(CeedQFunctionContext ctx) { CeedCallBackend(CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "RestoreData", CeedQFunctionContextRestoreData_Ref)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "RestoreDataRead", CeedQFunctionContextRestoreData_Ref)); CeedCallBackend(CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "Destroy", CeedQFunctionContextDestroy_Ref)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedCalloc(1, &impl)); CeedCallBackend(CeedQFunctionContextSetBackendData(ctx, impl)); return CEED_ERROR_SUCCESS; diff --git a/backends/ref/ceed-ref-restriction.c b/backends/ref/ceed-ref-restriction.c index 068b9906f8..b655b8a7fa 100644 --- a/backends/ref/ceed-ref-restriction.c +++ b/backends/ref/ceed-ref-restriction.c @@ -871,6 +871,7 @@ int CeedElemRestrictionCreate_Ref(CeedMemType mem_type, CeedCopyMode copy_mode, CeedCallBackend(CeedSetBackendFunction(ceed, "ElemRestriction", rstr, "GetOrientations", CeedElemRestrictionGetOrientations_Ref)); CeedCallBackend(CeedSetBackendFunction(ceed, "ElemRestriction", rstr, "GetCurlOrientations", CeedElemRestrictionGetCurlOrientations_Ref)); CeedCallBackend(CeedSetBackendFunction(ceed, "ElemRestriction", rstr, "Destroy", CeedElemRestrictionDestroy_Ref)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/ref/ceed-ref-vector.c b/backends/ref/ceed-ref-vector.c index f907d232c8..2af3a8770c 100644 --- a/backends/ref/ceed-ref-vector.c +++ b/backends/ref/ceed-ref-vector.c @@ -149,6 +149,7 @@ int CeedVectorCreate_Ref(CeedSize n, CeedVector vec) { CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "RestoreArray", CeedVectorRestoreArray_Ref)); CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "RestoreArrayRead", CeedVectorRestoreArrayRead_Ref)); CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "Destroy", CeedVectorDestroy_Ref)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedCalloc(1, &impl)); CeedCallBackend(CeedVectorSetData(vec, impl)); return CEED_ERROR_SUCCESS; diff --git a/backends/sycl-gen/ceed-sycl-gen-operator-build.sycl.cpp b/backends/sycl-gen/ceed-sycl-gen-operator-build.sycl.cpp index ee7aab812c..f1fb58e42f 100644 --- a/backends/sycl-gen/ceed-sycl-gen-operator-build.sycl.cpp +++ b/backends/sycl-gen/ceed-sycl-gen-operator-build.sycl.cpp @@ -780,8 +780,8 @@ extern "C" int CeedOperatorBuildKernel_Sycl_gen(CeedOperator op) { // Load kernel function CeedCallBackend(CeedGetKernel_Sycl(ceed, impl->sycl_module, operator_name, &impl->op)); - CeedCallBackend(CeedOperatorSetSetupDone(op)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/sycl-gen/ceed-sycl-gen-operator.sycl.cpp b/backends/sycl-gen/ceed-sycl-gen-operator.sycl.cpp index 0736446f4c..52fe43bcf1 100644 --- a/backends/sycl-gen/ceed-sycl-gen-operator.sycl.cpp +++ b/backends/sycl-gen/ceed-sycl-gen-operator.sycl.cpp @@ -198,6 +198,7 @@ static int CeedOperatorApplyAdd_Sycl_gen(CeedOperator op, CeedVector input_vec, // Restore context data CeedCallBackend(CeedQFunctionRestoreInnerContextData(qf, &qf_impl->d_c)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -223,6 +224,7 @@ int CeedOperatorCreate_Sycl_gen(CeedOperator op) { CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Operator", op, "ApplyAdd", CeedOperatorApplyAdd_Sycl_gen)); CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Operator", op, "Destroy", CeedOperatorDestroy_Sycl_gen)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/sycl-gen/ceed-sycl-gen-qfunction.sycl.cpp b/backends/sycl-gen/ceed-sycl-gen-qfunction.sycl.cpp index 05774e6237..e810bfbf7a 100644 --- a/backends/sycl-gen/ceed-sycl-gen-qfunction.sycl.cpp +++ b/backends/sycl-gen/ceed-sycl-gen-qfunction.sycl.cpp @@ -38,6 +38,7 @@ static int CeedQFunctionDestroy_Sycl_gen(CeedQFunction qf) { CeedCallBackend(CeedFree(&impl->qfunction_source)); CeedCallBackend(CeedFree(&impl)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -61,6 +62,7 @@ int CeedQFunctionCreate_Sycl_gen(CeedQFunction qf) { CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Sycl_gen)); CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Sycl_gen)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/sycl-ref/ceed-sycl-ref-basis.sycl.cpp b/backends/sycl-ref/ceed-sycl-ref-basis.sycl.cpp index e5495fe83f..1330d61a6a 100644 --- a/backends/sycl-ref/ceed-sycl-ref-basis.sycl.cpp +++ b/backends/sycl-ref/ceed-sycl-ref-basis.sycl.cpp @@ -328,6 +328,7 @@ static int CeedBasisApply_Sycl(CeedBasis basis, const CeedInt num_elem, CeedTran CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); if (eval_mode == CEED_EVAL_NONE) CeedCallBackend(CeedVectorSetArray(v, CEED_MEM_DEVICE, CEED_COPY_VALUES, (CeedScalar *)d_u)); if (eval_mode != CEED_EVAL_WEIGHT) CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -504,7 +505,7 @@ static int CeedBasisApplyNonTensor_Sycl(CeedBasis basis, const CeedInt num_elem, CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); if (eval_mode == CEED_EVAL_NONE) CeedCallBackend(CeedVectorSetArray(v, CEED_MEM_DEVICE, CEED_COPY_VALUES, (CeedScalar *)d_u)); if (eval_mode != CEED_EVAL_WEIGHT) CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); - + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -527,6 +528,7 @@ static int CeedBasisDestroy_Sycl(CeedBasis basis) { CeedCallSycl(ceed, sycl::free(impl->d_grad_1d, data->sycl_context)); CeedCallBackend(CeedFree(&impl)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -549,6 +551,7 @@ static int CeedBasisDestroyNonTensor_Sycl(CeedBasis basis) { CeedCallSycl(ceed, sycl::free(impl->d_grad, data->sycl_context)); CeedCallBackend(CeedFree(&impl)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -557,11 +560,12 @@ static int CeedBasisDestroyNonTensor_Sycl(CeedBasis basis) { //------------------------------------------------------------------------------ int CeedBasisCreateTensorH1_Sycl(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d, const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis) { - Ceed ceed; - CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); + Ceed ceed; CeedBasis_Sycl *impl; + Ceed_Sycl *data; + + CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); CeedCallBackend(CeedCalloc(1, &impl)); - Ceed_Sycl *data; CeedCallBackend(CeedGetData(ceed, &data)); CeedInt num_comp; @@ -617,6 +621,7 @@ int CeedBasisCreateTensorH1_Sycl(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const // Register backend functions CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Basis", basis, "Apply", CeedBasisApply_Sycl)); CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Basis", basis, "Destroy", CeedBasisDestroy_Sycl)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -625,11 +630,12 @@ int CeedBasisCreateTensorH1_Sycl(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const //------------------------------------------------------------------------------ int CeedBasisCreateH1_Sycl(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis) { - Ceed ceed; - CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); + Ceed ceed; CeedBasisNonTensor_Sycl *impl; + Ceed_Sycl *data; + + CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); CeedCallBackend(CeedCalloc(1, &impl)); - Ceed_Sycl *data; CeedCallBackend(CeedGetData(ceed, &data)); CeedInt num_comp; @@ -668,6 +674,7 @@ int CeedBasisCreateH1_Sycl(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes // Register backend functions CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Basis", basis, "Apply", CeedBasisApplyNonTensor_Sycl)); CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Basis", basis, "Destroy", CeedBasisDestroyNonTensor_Sycl)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/sycl-ref/ceed-sycl-ref-operator.sycl.cpp b/backends/sycl-ref/ceed-sycl-ref-operator.sycl.cpp index e43981c217..a936e31ef4 100644 --- a/backends/sycl-ref/ceed-sycl-ref-operator.sycl.cpp +++ b/backends/sycl-ref/ceed-sycl-ref-operator.sycl.cpp @@ -107,6 +107,7 @@ static int CeedOperatorDestroy_Sycl(CeedOperator op) { CeedCallBackend(CeedFree(&impl->asmb)); CeedCallBackend(CeedFree(&impl)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -206,6 +207,7 @@ static int CeedOperatorSetupFields_Sycl(CeedQFunction qf, CeedOperator op, bool break; // TODO: Not implemented } } + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -214,7 +216,6 @@ static int CeedOperatorSetupFields_Sycl(CeedQFunction qf, CeedOperator op, bool // passive) to the named inputs and outputs of its CeedQFunction. //------------------------------------------------------------------------------ static int CeedOperatorSetup_Sycl(CeedOperator op) { - Ceed ceed; bool is_setup_done; CeedInt Q, num_elem, num_input_fields, num_output_fields; CeedQFunctionField *qf_input_fields, *qf_output_fields; @@ -225,7 +226,6 @@ static int CeedOperatorSetup_Sycl(CeedOperator op) { CeedCallBackend(CeedOperatorIsSetupDone(op, &is_setup_done)); if (is_setup_done) return CEED_ERROR_SUCCESS; - CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); CeedCallBackend(CeedOperatorGetData(op, &impl)); CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); CeedCallBackend(CeedOperatorGetNumQuadraturePoints(op, &Q)); @@ -432,22 +432,14 @@ static int CeedOperatorApplyAdd_Sycl(CeedOperator op, CeedVector in_vec, CeedVec break; } // LCOV_EXCL_START - case CEED_EVAL_WEIGHT: { - Ceed ceed; - - CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); - return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_WEIGHT cannot be an output evaluation mode"); + case CEED_EVAL_WEIGHT: + return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_BACKEND, "CEED_EVAL_WEIGHT cannot be an output evaluation mode"); break; // Should not occur - } case CEED_EVAL_DIV: - case CEED_EVAL_CURL: { - Ceed ceed; - - CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); - return CeedError(ceed, CEED_ERROR_BACKEND, "%s not supported", CeedEvalModes[eval_mode]); + case CEED_EVAL_CURL: + return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_BACKEND, "%s not supported", CeedEvalModes[eval_mode]); break; // Should not occur - } - // LCOV_EXCL_STOP + // LCOV_EXCL_STOP } } @@ -483,7 +475,7 @@ static int CeedOperatorApplyAdd_Sycl(CeedOperator op, CeedVector in_vec, CeedVec //------------------------------------------------------------------------------ static inline int CeedOperatorLinearAssembleQFunctionCore_Sycl(CeedOperator op, bool build_objects, CeedVector *assembled, CeedElemRestriction *elem_rstr, CeedRequest *request) { - Ceed ceed, ceed_parent; + Ceed ceed_parent; CeedSize q_size; CeedInt num_active_in, num_active_out, Q, num_elem, num_input_fields, num_output_fields, size; CeedScalar *assembled_array, *e_data[2 * CEED_FIELD_MAX] = {NULL}; @@ -493,7 +485,6 @@ static inline int CeedOperatorLinearAssembleQFunctionCore_Sycl(CeedOperator op, CeedOperatorField *op_input_fields, *op_output_fields; CeedOperator_Sycl *impl; - CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); CeedCallBackend(CeedOperatorGetFallbackParentCeed(op, &ceed_parent)); CeedCallBackend(CeedOperatorGetData(op, &impl)); CeedCallBackend(CeedOperatorGetQFunction(op, &qf)); @@ -525,7 +516,7 @@ static inline int CeedOperatorLinearAssembleQFunctionCore_Sycl(CeedOperator op, CeedCallBackend(CeedRealloc(num_active_in + size, &active_in)); for (CeedInt field = 0; field < size; field++) { q_size = (CeedSize)Q * num_elem; - CeedCallBackend(CeedVectorCreate(ceed, q_size, &active_in[num_active_in + field])); + CeedCallBackend(CeedVectorCreate(ceed_parent, q_size, &active_in[num_active_in + field])); CeedCallBackend( CeedVectorSetArray(active_in[num_active_in + field], CEED_MEM_DEVICE, CEED_USE_POINTER, &q_vec_array[field * Q * num_elem])); } @@ -555,7 +546,8 @@ static inline int CeedOperatorLinearAssembleQFunctionCore_Sycl(CeedOperator op, } // Check sizes - CeedCheck(num_active_in > 0 && num_active_out > 0, ceed, CEED_ERROR_BACKEND, "Cannot assemble QFunction without active inputs and outputs"); + CeedCheck(num_active_in > 0 && num_active_out > 0, CeedOperatorReturnCeed(op), CEED_ERROR_BACKEND, + "Cannot assemble QFunction without active inputs and outputs"); // Build objects if needed if (build_objects) { @@ -820,6 +812,7 @@ static inline int CeedOperatorAssembleDiagonalSetup_Sycl(CeedOperator op) { CeedCallBackend(CeedElemRestrictionDestroy(&rstr_out)); // Cleanup + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedBasisDestroy(&basis_in)); CeedCallBackend(CeedBasisDestroy(&basis_out)); @@ -921,8 +914,9 @@ static inline int CeedOperatorAssembleDiagonalCore_Sycl(CeedOperator op, CeedVec CeedOperator_Sycl *impl; CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); - CeedCallBackend(CeedOperatorGetData(op, &impl)); CeedCallBackend(CeedGetData(ceed, &sycl_data)); + CeedCallBackend(CeedDestroy(&ceed)); + CeedCallBackend(CeedOperatorGetData(op, &impl)); // Assemble QFunction { @@ -1175,6 +1169,7 @@ static int CeedSingleOperatorAssembleSetup_Sycl(CeedOperator op) { mat_start += dim * elem_size * num_qpts; } } + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedElemRestrictionDestroy(&rstr_in)); CeedCallBackend(CeedElemRestrictionDestroy(&rstr_out)); CeedCallBackend(CeedBasisDestroy(&basis_in)); @@ -1346,8 +1341,9 @@ static int CeedSingleOperatorAssemble_Sycl(CeedOperator op, CeedInt offset, Ceed CeedOperator_Sycl *impl; CeedCallBackend(CeedOperatorGetCeed(op, &ceed)); - CeedCallBackend(CeedOperatorGetData(op, &impl)); CeedCallBackend(CeedGetData(ceed, &sycl_data)); + CeedCallBackend(CeedDestroy(&ceed)); + CeedCallBackend(CeedOperatorGetData(op, &impl)); // Setup if (!impl->asmb) { @@ -1398,6 +1394,7 @@ int CeedOperatorCreate_Sycl(CeedOperator op) { CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Operator", op, "LinearAssembleSingle", CeedSingleOperatorAssemble_Sycl)); CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Operator", op, "ApplyAdd", CeedOperatorApplyAdd_Sycl)); CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Operator", op, "Destroy", CeedOperatorDestroy_Sycl)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/sycl-ref/ceed-sycl-ref-qfunction-load.sycl.cpp b/backends/sycl-ref/ceed-sycl-ref-qfunction-load.sycl.cpp index 1d3cf330ad..4b6efcd4ce 100644 --- a/backends/sycl-ref/ceed-sycl-ref-qfunction-load.sycl.cpp +++ b/backends/sycl-ref/ceed-sycl-ref-qfunction-load.sycl.cpp @@ -175,6 +175,7 @@ extern "C" int CeedQFunctionBuildKernel_Sycl(CeedQFunction qf) { CeedCallBackend(CeedFree(&qfunction_source)); CeedCallBackend(CeedFree(&read_write_kernel_path)); CeedCallBackend(CeedFree(&read_write_kernel_source)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/sycl-ref/ceed-sycl-ref-qfunction.sycl.cpp b/backends/sycl-ref/ceed-sycl-ref-qfunction.sycl.cpp index 4de8fcf379..6a2c7f060b 100644 --- a/backends/sycl-ref/ceed-sycl-ref-qfunction.sycl.cpp +++ b/backends/sycl-ref/ceed-sycl-ref-qfunction.sycl.cpp @@ -37,6 +37,7 @@ static int CeedQFunctionApply_Sycl(CeedQFunction qf, CeedInt Q, CeedVector *U, C CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed)); CeedCallBackend(CeedGetData(ceed, &ceed_Sycl)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedQFunctionGetNumArgs(qf, &num_input_fields, &num_output_fields)); @@ -118,6 +119,7 @@ static int CeedQFunctionDestroy_Sycl(CeedQFunction qf) { delete impl->QFunction; delete impl->sycl_module; CeedCallBackend(CeedFree(&impl)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -134,6 +136,7 @@ int CeedQFunctionCreate_Sycl(CeedQFunction qf) { // Register backend functions CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Sycl)); CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Sycl)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/sycl-ref/ceed-sycl-ref-qfunctioncontext.sycl.cpp b/backends/sycl-ref/ceed-sycl-ref-qfunctioncontext.sycl.cpp index 1c942a645b..7130a0dead 100644 --- a/backends/sycl-ref/ceed-sycl-ref-qfunctioncontext.sycl.cpp +++ b/backends/sycl-ref/ceed-sycl-ref-qfunctioncontext.sycl.cpp @@ -42,6 +42,7 @@ static inline int CeedQFunctionContextSyncH2D_Sycl(const CeedQFunctionContext ct if (!sycl_data->sycl_queue.is_in_order()) e = {sycl_data->sycl_queue.ext_oneapi_submit_barrier()}; sycl::event copy_event = sycl_data->sycl_queue.memcpy(impl->d_data, impl->h_data, ctx_size, e); CeedCallSycl(ceed, copy_event.wait_and_throw()); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -75,6 +76,7 @@ static inline int CeedQFunctionContextSyncD2H_Sycl(const CeedQFunctionContext ct if (!sycl_data->sycl_queue.is_in_order()) e = {sycl_data->sycl_queue.ext_oneapi_submit_barrier()}; sycl::event copy_event = sycl_data->sycl_queue.memcpy(impl->h_data, impl->d_data, ctx_size, e); CeedCallSycl(ceed, copy_event.wait_and_throw()); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -229,6 +231,7 @@ static int CeedQFunctionContextSetDataDevice_Sycl(const CeedQFunctionContext ctx impl->d_data = data; } break; } + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -237,9 +240,6 @@ static int CeedQFunctionContextSetDataDevice_Sycl(const CeedQFunctionContext ctx // freeing any previously allocated data if applicable //------------------------------------------------------------------------------ static int CeedQFunctionContextSetData_Sycl(const CeedQFunctionContext ctx, const CeedMemType mem_type, const CeedCopyMode copy_mode, void *data) { - Ceed ceed; - - CeedCallBackend(CeedQFunctionContextGetCeed(ctx, &ceed)); CeedCallBackend(CeedQFunctionContextSetAllInvalid_Sycl(ctx)); switch (mem_type) { case CEED_MEM_HOST: @@ -260,8 +260,9 @@ static int CeedQFunctionContextTakeData_Sycl(const CeedQFunctionContext ctx, con CeedQFunctionContext_Sycl *impl; CeedCallBackend(CeedQFunctionContextGetCeed(ctx, &ceed)); - CeedCallBackend(CeedQFunctionContextGetBackendData(ctx, &impl)); CeedCallBackend(CeedGetData(ceed, &ceedSycl)); + CeedCallBackend(CeedDestroy(&ceed)); + CeedCallBackend(CeedQFunctionContextGetBackendData(ctx, &impl)); // Order queue if needed if (!ceedSycl->sycl_queue.is_in_order()) ceedSycl->sycl_queue.ext_oneapi_submit_barrier(); @@ -291,11 +292,9 @@ static int CeedQFunctionContextTakeData_Sycl(const CeedQFunctionContext ctx, con // If a different memory type is most up to date, this will perform a copy //------------------------------------------------------------------------------ static int CeedQFunctionContextGetDataCore_Sycl(const CeedQFunctionContext ctx, const CeedMemType mem_type, void *data) { - Ceed ceed; bool need_sync = false; CeedQFunctionContext_Sycl *impl; - CeedCallBackend(CeedQFunctionContextGetCeed(ctx, &ceed)); CeedCallBackend(CeedQFunctionContextGetBackendData(ctx, &impl)); // Sync data to requested mem_type @@ -325,11 +324,9 @@ static int CeedQFunctionContextGetDataRead_Sycl(const CeedQFunctionContext ctx, // Get read/write access to the data //------------------------------------------------------------------------------ static int CeedQFunctionContextGetData_Sycl(const CeedQFunctionContext ctx, const CeedMemType mem_type, void *data) { - Ceed ceed; CeedQFunctionContext_Sycl *impl; CeedCallBackend(CeedQFunctionContextGetBackendData(ctx, &impl)); - CeedCallBackend(CeedQFunctionContextGetCeed(ctx, &ceed)); CeedCallBackend(CeedQFunctionContextGetDataCore_Sycl(ctx, mem_type, data)); // Mark only pointer for requested memory as valid @@ -360,6 +357,7 @@ static int CeedQFunctionContextDestroy_Sycl(const CeedQFunctionContext ctx) { // Wait for all work to finish before freeing memory CeedCallSycl(ceed, sycl_data->sycl_queue.wait_and_throw()); CeedCallSycl(ceed, sycl::free(impl->d_data_owned, sycl_data->sycl_context)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedFree(&impl->h_data_owned)); CeedCallBackend(CeedFree(&impl)); return CEED_ERROR_SUCCESS; @@ -380,6 +378,7 @@ int CeedQFunctionContextCreate_Sycl(CeedQFunctionContext ctx) { CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "QFunctionContext", ctx, "GetData", CeedQFunctionContextGetData_Sycl)); CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "QFunctionContext", ctx, "GetDataRead", CeedQFunctionContextGetDataRead_Sycl)); CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "QFunctionContext", ctx, "Destroy", CeedQFunctionContextDestroy_Sycl)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedCalloc(1, &impl)); CeedCallBackend(CeedQFunctionContextSetBackendData(ctx, impl)); return CEED_ERROR_SUCCESS; diff --git a/backends/sycl-ref/ceed-sycl-restriction.sycl.cpp b/backends/sycl-ref/ceed-sycl-restriction.sycl.cpp index d85d036587..07a451213b 100644 --- a/backends/sycl-ref/ceed-sycl-restriction.sycl.cpp +++ b/backends/sycl-ref/ceed-sycl-restriction.sycl.cpp @@ -195,6 +195,7 @@ static int CeedElemRestrictionApply_Sycl(CeedElemRestriction rstr, CeedTranspose // Restore arrays CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -202,10 +203,8 @@ static int CeedElemRestrictionApply_Sycl(CeedElemRestriction rstr, CeedTranspose // Get offsets //------------------------------------------------------------------------------ static int CeedElemRestrictionGetOffsets_Sycl(CeedElemRestriction rstr, CeedMemType m_type, const CeedInt **offsets) { - Ceed ceed; CeedElemRestriction_Sycl *impl; - CeedCallBackend(CeedElemRestrictionGetCeed(rstr, &ceed)); CeedCallBackend(CeedElemRestrictionGetData(rstr, &impl)); switch (m_type) { @@ -240,6 +239,7 @@ static int CeedElemRestrictionDestroy_Sycl(CeedElemRestriction rstr) { CeedCallSycl(ceed, sycl::free(impl->d_t_indices, data->sycl_context)); CeedCallSycl(ceed, sycl::free(impl->d_l_vec_indices, data->sycl_context)); CeedCallBackend(CeedFree(&impl)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -328,6 +328,7 @@ static int CeedElemRestrictionOffset_Sycl(const CeedElemRestriction rstr, const CeedCallBackend(CeedFree(&l_vec_indices)); CeedCallBackend(CeedFree(&t_offsets)); CeedCallBackend(CeedFree(&t_indices)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -472,5 +473,6 @@ int CeedElemRestrictionCreate_Sycl(CeedMemType mem_type, CeedCopyMode copy_mode, CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "ElemRestriction", rstr, "ApplyUnoriented", CeedElemRestrictionApply_Sycl)); CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "ElemRestriction", rstr, "GetOffsets", CeedElemRestrictionGetOffsets_Sycl)); CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "ElemRestriction", rstr, "Destroy", CeedElemRestrictionDestroy_Sycl)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/backends/sycl-ref/ceed-sycl-vector.sycl.cpp b/backends/sycl-ref/ceed-sycl-vector.sycl.cpp index 427f51f727..32dda419f0 100644 --- a/backends/sycl-ref/ceed-sycl-vector.sycl.cpp +++ b/backends/sycl-ref/ceed-sycl-vector.sycl.cpp @@ -44,8 +44,9 @@ static inline int CeedVectorSyncH2D_Sycl(const CeedVector vec) { CeedVector_Sycl *impl; CeedCallBackend(CeedVectorGetCeed(vec, &ceed)); - CeedCallBackend(CeedVectorGetData(vec, &impl)); CeedCallBackend(CeedGetData(ceed, &data)); + CeedCallBackend(CeedVectorGetData(vec, &impl)); + CeedCheck(impl->h_array, ceed, CEED_ERROR_BACKEND, "No valid host data to sync to device"); CeedCallBackend(CeedVectorGetLength(vec, &length)); @@ -63,6 +64,7 @@ static inline int CeedVectorSyncH2D_Sycl(const CeedVector vec) { if (!data->sycl_queue.is_in_order()) e = {data->sycl_queue.ext_oneapi_submit_barrier()}; CeedCallSycl(ceed, data->sycl_queue.copy(impl->h_array, impl->d_array, length, e).wait_and_throw()); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -76,8 +78,8 @@ static inline int CeedVectorSyncD2H_Sycl(const CeedVector vec) { CeedVector_Sycl *impl; CeedCallBackend(CeedVectorGetCeed(vec, &ceed)); - CeedCallBackend(CeedVectorGetData(vec, &impl)); CeedCallBackend(CeedGetData(ceed, &data)); + CeedCallBackend(CeedVectorGetData(vec, &impl)); CeedCheck(impl->d_array, ceed, CEED_ERROR_BACKEND, "No valid device data to sync to host"); @@ -96,6 +98,7 @@ static inline int CeedVectorSyncD2H_Sycl(const CeedVector vec) { if (!data->sycl_queue.is_in_order()) e = {data->sycl_queue.ext_oneapi_submit_barrier()}; CeedCallSycl(ceed, data->sycl_queue.copy(impl->d_array, impl->h_array, length, e).wait_and_throw()); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -244,6 +247,7 @@ static int CeedVectorSetArrayDevice_Sycl(const CeedVector vec, const CeedCopyMod impl->d_array = impl->d_array_borrowed; break; } + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -295,9 +299,10 @@ static int CeedVectorSetValue_Sycl(CeedVector vec, CeedScalar val) { CeedVector_Sycl *impl; CeedCallBackend(CeedVectorGetCeed(vec, &ceed)); + CeedCallBackend(CeedGetData(ceed, &data)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedVectorGetData(vec, &impl)); CeedCallBackend(CeedVectorGetLength(vec, &length)); - CeedCallBackend(CeedGetData(ceed, &data)); // Set value for synced device/host array if (!impl->d_array && !impl->h_array) { @@ -333,8 +338,10 @@ static int CeedVectorTakeArray_Sycl(CeedVector vec, CeedMemType mem_type, CeedSc CeedVector_Sycl *impl; CeedCallBackend(CeedVectorGetCeed(vec, &ceed)); - CeedCallBackend(CeedVectorGetData(vec, &impl)); CeedCallBackend(CeedGetData(ceed, &data)); + CeedCallBackend(CeedVectorGetData(vec, &impl)); + CeedCallBackend(CeedDestroy(&ceed)); + CeedCallBackend(CeedVectorGetData(vec, &impl)); // Order queue if needed if (!data->sycl_queue.is_in_order()) data->sycl_queue.ext_oneapi_submit_barrier(); @@ -447,9 +454,10 @@ static int CeedVectorNorm_Sycl(CeedVector vec, CeedNormType type, CeedScalar *no CeedVector_Sycl *impl; CeedCallBackend(CeedVectorGetCeed(vec, &ceed)); + CeedCallBackend(CeedGetData(ceed, &data)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedVectorGetData(vec, &impl)); CeedCallBackend(CeedVectorGetLength(vec, &length)); - CeedCallBackend(CeedGetData(ceed, &data)); // Compute norm CeedCallBackend(CeedVectorGetArrayRead(vec, CEED_MEM_DEVICE, &d_array)); @@ -515,9 +523,10 @@ static int CeedVectorReciprocal_Sycl(CeedVector vec) { CeedVector_Sycl *impl; CeedCallBackend(CeedVectorGetCeed(vec, &ceed)); + CeedCallBackend(CeedGetData(ceed, &data)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedVectorGetData(vec, &impl)); CeedCallBackend(CeedVectorGetLength(vec, &length)); - CeedCallBackend(CeedGetData(ceed, &data)); // Set value for synced device/host array if (impl->d_array) CeedCallBackend(CeedDeviceReciprocal_Sycl(data->sycl_queue, impl->d_array, length)); @@ -554,9 +563,10 @@ static int CeedVectorScale_Sycl(CeedVector x, CeedScalar alpha) { CeedVector_Sycl *x_impl; CeedCallBackend(CeedVectorGetCeed(x, &ceed)); + CeedCallBackend(CeedGetData(ceed, &data)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedVectorGetData(x, &x_impl)); CeedCallBackend(CeedVectorGetLength(x, &length)); - CeedCallBackend(CeedGetData(ceed, &data)); // Set value for synced device/host array if (x_impl->d_array) CeedCallBackend(CeedDeviceScale_Sycl(data->sycl_queue, x_impl->d_array, alpha, length)); @@ -593,10 +603,11 @@ static int CeedVectorAXPY_Sycl(CeedVector y, CeedScalar alpha, CeedVector x) { CeedVector_Sycl *y_impl, *x_impl; CeedCallBackend(CeedVectorGetCeed(y, &ceed)); + CeedCallBackend(CeedGetData(ceed, &data)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedVectorGetData(y, &y_impl)); CeedCallBackend(CeedVectorGetData(x, &x_impl)); CeedCallBackend(CeedVectorGetLength(y, &length)); - CeedCallBackend(CeedGetData(ceed, &data)); // Set value for synced device/host array if (y_impl->d_array) { @@ -639,11 +650,12 @@ static int CeedVectorPointwiseMult_Sycl(CeedVector w, CeedVector x, CeedVector y CeedVector_Sycl *w_impl, *x_impl, *y_impl; CeedCallBackend(CeedVectorGetCeed(w, &ceed)); + CeedCallBackend(CeedGetData(ceed, &data)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedVectorGetData(w, &w_impl)); CeedCallBackend(CeedVectorGetData(x, &x_impl)); CeedCallBackend(CeedVectorGetData(y, &y_impl)); CeedCallBackend(CeedVectorGetLength(w, &length)); - CeedCallBackend(CeedGetData(ceed, &data)); // Set value for synced device/host array if (!w_impl->d_array && !w_impl->h_array) { @@ -681,6 +693,7 @@ static int CeedVectorDestroy_Sycl(const CeedVector vec) { CeedCallBackend(CeedFree(&impl->h_array_owned)); CeedCallBackend(CeedFree(&impl)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -711,6 +724,7 @@ int CeedVectorCreate_Sycl(CeedSize n, CeedVector vec) { CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Vector", vec, "Scale", CeedVectorScale_Sycl)); CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Vector", vec, "PointwiseMult", CeedVectorPointwiseMult_Sycl)); CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Vector", vec, "Destroy", CeedVectorDestroy_Sycl)); + CeedCallBackend(CeedDestroy(&ceed)); CeedCallBackend(CeedVectorSetData(vec, impl)); return CEED_ERROR_SUCCESS; } diff --git a/backends/sycl-shared/ceed-sycl-shared-basis.sycl.cpp b/backends/sycl-shared/ceed-sycl-shared-basis.sycl.cpp index d549f6cd4f..7d8302599f 100644 --- a/backends/sycl-shared/ceed-sycl-shared-basis.sycl.cpp +++ b/backends/sycl-shared/ceed-sycl-shared-basis.sycl.cpp @@ -128,7 +128,7 @@ int CeedBasisApplyTensor_Sycl_shared(CeedBasis basis, const CeedInt num_elem, Ce CeedCallBackend(CeedVectorRestoreArray(v, &d_v)); if (eval_mode == CEED_EVAL_NONE) CeedCallBackend(CeedVectorSetArray(v, CEED_MEM_DEVICE, CEED_COPY_VALUES, (CeedScalar *)d_u)); if (eval_mode != CEED_EVAL_WEIGHT) CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u)); - + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -157,6 +157,7 @@ static int CeedBasisDestroy_Sycl_shared(CeedBasis basis) { delete impl->sycl_module; CeedCallBackend(CeedFree(&impl)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -277,6 +278,7 @@ int CeedBasisCreateTensorH1_Sycl_shared(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, // Register backend functions CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Basis", basis, "Apply", CeedBasisApplyTensor_Sycl_shared)); CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Basis", basis, "Destroy", CeedBasisDestroy_Sycl_shared)); + CeedCallBackend(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } diff --git a/examples/fluids/include/petsc-ceed-utils.h b/examples/fluids/include/petsc-ceed-utils.h index 936f278ee3..d085ad670f 100644 --- a/examples/fluids/include/petsc-ceed-utils.h +++ b/examples/fluids/include/petsc-ceed-utils.h @@ -220,6 +220,7 @@ static inline PetscErrorCode VecCopyPetscToCeed(Vec X_petsc, CeedVector x_ceed) PetscCall(VecGetArrayReadAndMemType(X_petsc, (const PetscScalar **)&x, &mem_type)); PetscCallCeed(ceed, CeedVectorSetArray(x_ceed, MemTypePetscToCeed(mem_type), CEED_COPY_VALUES, x)); PetscCall(VecRestoreArrayReadAndMemType(X_petsc, (const PetscScalar **)&x)); + PetscCheck(CeedDestroy(&ceed) == CEED_ERROR_SUCCESS, PetscObjectComm((PetscObject)X_petsc), PETSC_ERR_LIB, "Destroying Ceed object failed"); PetscFunctionReturn(PETSC_SUCCESS); } diff --git a/examples/fluids/src/mat-ceed.c b/examples/fluids/src/mat-ceed.c index cd164598ed..358160f678 100644 --- a/examples/fluids/src/mat-ceed.c +++ b/examples/fluids/src/mat-ceed.c @@ -1229,7 +1229,6 @@ PetscErrorCode MatCeedContextCreate(DM dm_x, DM dm_y, Vec X_loc, Vec Y_loc_trans // libCEED objects PetscCheck(CeedOperatorGetCeed(op_mult, &(*ctx)->ceed) == CEED_ERROR_SUCCESS, PETSC_COMM_SELF, PETSC_ERR_LIB, "retrieving Ceed context object failed"); - PetscCallCeed((*ctx)->ceed, CeedReference((*ctx)->ceed)); PetscCallCeed((*ctx)->ceed, CeedOperatorGetActiveVectorLengths(op_mult, &x_loc_len, &y_loc_len)); PetscCallCeed((*ctx)->ceed, CeedOperatorReferenceCopy(op_mult, &(*ctx)->op_mult)); if (op_mult_transpose) PetscCallCeed((*ctx)->ceed, CeedOperatorReferenceCopy(op_mult_transpose, &(*ctx)->op_mult_transpose)); diff --git a/examples/fluids/src/petsc_ops.c b/examples/fluids/src/petsc_ops.c index f40e156af2..b9b51209a3 100644 --- a/examples/fluids/src/petsc_ops.c +++ b/examples/fluids/src/petsc_ops.c @@ -197,6 +197,7 @@ PetscErrorCode CeedOperatorCreateLocalVecs(CeedOperator op, VecType vec_type, MP PetscCall(VecSetType(*output, vec_type)); PetscCall(VecSetSizes(*output, output_size, output_size)); } + PetscCheck(CeedDestroy(&ceed) == CEED_ERROR_SUCCESS, comm, PETSC_ERR_LIB, "Destroying Ceed object failed"); PetscFunctionReturn(PETSC_SUCCESS); } diff --git a/examples/fluids/src/turb_spanstats.c b/examples/fluids/src/turb_spanstats.c index 08f9ef36b9..db0532fdce 100644 --- a/examples/fluids/src/turb_spanstats.c +++ b/examples/fluids/src/turb_spanstats.c @@ -238,6 +238,8 @@ PetscErrorCode SpanStatsSetupDataDestroy(SpanStatsSetupData data) { PetscCallCeed(ceed, CeedVectorDestroy(&data->x_coord)); + PetscCheck(CeedDestroy(&ceed) == CEED_ERROR_SUCCESS, PETSC_COMM_WORLD, PETSC_ERR_LIB, "Destroying Ceed object failed"); + PetscCall(PetscFree(data)); PetscFunctionReturn(PETSC_SUCCESS); } diff --git a/interface/ceed-basis.c b/interface/ceed-basis.c index c6869f2f3b..147a173c2a 100644 --- a/interface/ceed-basis.c +++ b/interface/ceed-basis.c @@ -194,16 +194,13 @@ static int CeedScalarView(const char *name, const char *fp_fmt, CeedInt m, CeedI @ref Developer **/ static int CeedBasisCreateProjectionMatrices(CeedBasis basis_from, CeedBasis basis_to, CeedScalar **interp_project, CeedScalar **grad_project) { - Ceed ceed; bool are_both_tensor; CeedInt Q, Q_to, Q_from, P_to, P_from; - CeedCall(CeedBasisGetCeed(basis_to, &ceed)); - // Check for compatible quadrature spaces CeedCall(CeedBasisGetNumQuadraturePoints(basis_to, &Q_to)); CeedCall(CeedBasisGetNumQuadraturePoints(basis_from, &Q_from)); - CeedCheck(Q_to == Q_from, ceed, CEED_ERROR_DIMENSION, + CeedCheck(Q_to == Q_from, CeedBasisReturnCeed(basis_to), CEED_ERROR_DIMENSION, "Bases must have compatible quadrature spaces." " 'basis_from' has %" CeedInt_FMT " points and 'basis_to' has %" CeedInt_FMT, Q_from, Q_to); @@ -231,7 +228,7 @@ static int CeedBasisCreateProjectionMatrices(CeedBasis basis_from, CeedBasis bas CeedCall(CeedBasisGetFESpace(basis_to, &fe_space_to)); CeedCall(CeedBasisGetFESpace(basis_from, &fe_space_from)); - CeedCheck(fe_space_to == fe_space_from, ceed, CEED_ERROR_MINOR, + CeedCheck(fe_space_to == fe_space_from, CeedBasisReturnCeed(basis_to), CEED_ERROR_MINOR, "Bases must both be the same FE space type." " 'basis_from' is a %s and 'basis_to' is a %s", CeedFESpaces[fe_space_from], CeedFESpaces[fe_space_to]); @@ -267,7 +264,7 @@ static int CeedBasisCreateProjectionMatrices(CeedBasis basis_from, CeedBasis bas // Compute interp_to^+, pseudoinverse of interp_to CeedCall(CeedCalloc(Q * q_comp * P_to, &interp_to_inv)); - CeedCall(CeedMatrixPseudoinverse(ceed, interp_to_source, Q * q_comp, P_to, interp_to_inv)); + CeedCall(CeedMatrixPseudoinverse(CeedBasisReturnCeed(basis_to), interp_to_source, Q * q_comp, P_to, interp_to_inv)); // Build matrices CeedInt num_matrices = 1 + (fe_space_to == CEED_FE_SPACE_H1) * (are_both_tensor ? 1 : dim); CeedScalar *input_from[num_matrices], *output_project[num_matrices]; @@ -281,7 +278,7 @@ static int CeedBasisCreateProjectionMatrices(CeedBasis basis_from, CeedBasis bas for (CeedInt m = 0; m < num_matrices; m++) { // output_project = interp_to^+ * interp_from memcpy(interp_from, input_from[m], Q * P_from * q_comp * sizeof(input_from[m][0])); - CeedCall(CeedMatrixMatrixMultiply(ceed, interp_to_inv, input_from[m], output_project[m], P_to, P_from, Q * q_comp)); + CeedCall(CeedMatrixMatrixMultiply(CeedBasisReturnCeed(basis_to), interp_to_inv, input_from[m], output_project[m], P_to, P_from, Q * q_comp)); // Round zero to machine precision for (CeedInt i = 0; i < P_to * P_from; i++) { if (fabs(output_project[m][i]) < 10 * CEED_EPSILON) output_project[m][i] = 0.0; @@ -318,9 +315,7 @@ static int CeedBasisApplyAtPointsCheckDims(CeedBasis basis, CeedInt num_elem, co CeedEvalMode eval_mode, CeedVector x_ref, CeedVector u, CeedVector v) { CeedInt dim, num_comp, num_q_comp, num_nodes, P_1d = 1, Q_1d = 1, total_num_points = 0; CeedSize x_length = 0, u_length = 0, v_length; - Ceed ceed; - CeedCall(CeedBasisGetCeed(basis, &ceed)); CeedCall(CeedBasisGetDimension(basis, &dim)); CeedCall(CeedBasisGetNumNodes1D(basis, &P_1d)); CeedCall(CeedBasisGetNumQuadraturePoints1D(basis, &Q_1d)); @@ -333,13 +328,14 @@ static int CeedBasisApplyAtPointsCheckDims(CeedBasis basis, CeedInt num_elem, co // Check compatibility coordinates vector for (CeedInt i = 0; i < num_elem; i++) total_num_points += num_points[i]; - CeedCheck((x_length >= (CeedSize)total_num_points * (CeedSize)dim) || (eval_mode == CEED_EVAL_WEIGHT), ceed, CEED_ERROR_DIMENSION, + CeedCheck((x_length >= (CeedSize)total_num_points * (CeedSize)dim) || (eval_mode == CEED_EVAL_WEIGHT), CeedBasisReturnCeed(basis), + CEED_ERROR_DIMENSION, "Length of reference coordinate vector incompatible with basis dimension and number of points." " Found reference coordinate vector of length %" CeedSize_FMT ", not of length %" CeedSize_FMT ".", x_length, (CeedSize)total_num_points * (CeedSize)dim); // Check CEED_EVAL_WEIGHT only on CEED_NOTRANSPOSE - CeedCheck(eval_mode != CEED_EVAL_WEIGHT || t_mode == CEED_NOTRANSPOSE, ceed, CEED_ERROR_UNSUPPORTED, + CeedCheck(eval_mode != CEED_EVAL_WEIGHT || t_mode == CEED_NOTRANSPOSE, CeedBasisReturnCeed(basis), CEED_ERROR_UNSUPPORTED, "CEED_EVAL_WEIGHT only supported with CEED_NOTRANSPOSE"); // Check vector lengths to prevent out of bounds issues @@ -364,10 +360,11 @@ static int CeedBasisApplyAtPointsCheckDims(CeedBasis basis, CeedInt num_elem, co case CEED_EVAL_NONE: case CEED_EVAL_DIV: case CEED_EVAL_CURL: - return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "Evaluation at arbitrary points not supported for %s", CeedEvalModes[eval_mode]); + return CeedError(CeedBasisReturnCeed(basis), CEED_ERROR_UNSUPPORTED, "Evaluation at arbitrary points not supported for %s", + CeedEvalModes[eval_mode]); // LCOV_EXCL_STOP } - CeedCheck(has_good_dims, ceed, CEED_ERROR_DIMENSION, "Input/output vectors too short for basis and evaluation mode"); + CeedCheck(has_good_dims, CeedBasisReturnCeed(basis), CEED_ERROR_DIMENSION, "Input/output vectors too short for basis and evaluation mode"); return CEED_ERROR_SUCCESS; } @@ -588,6 +585,7 @@ static int CeedBasisApplyAtPoints_Core(CeedBasis basis, bool apply_add, CeedInt break; } } + CeedCall(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -628,6 +626,7 @@ int CeedBasisGetCollocatedGrad(CeedBasis basis, CeedScalar *collo_grad_1d) { CeedCall(CeedMatrixMatrixMultiply(ceed, grad_1d, (const CeedScalar *)interp_1d_pinv, collo_grad_1d, Q_1d, Q_1d, P_1d)); CeedCall(CeedFree(&interp_1d_pinv)); + CeedCall(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -669,6 +668,7 @@ int CeedBasisGetChebyshevInterp1D(CeedBasis basis, CeedScalar *chebyshev_interp_ // Cleanup CeedCall(CeedFree(&C)); CeedCall(CeedFree(&chebyshev_coeffs_1d_inv)); + CeedCall(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -1681,6 +1681,7 @@ int CeedBasisCreateProjection(CeedBasis basis_from, CeedBasis basis_to, CeedBasi // Cleanup CeedCall(CeedFree(&interp_project)); CeedCall(CeedFree(&grad_project)); + CeedCall(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -1806,9 +1807,7 @@ int CeedBasisView(CeedBasis basis, FILE *stream) { static int CeedBasisApplyCheckDims(CeedBasis basis, CeedInt num_elem, CeedTransposeMode t_mode, CeedEvalMode eval_mode, CeedVector u, CeedVector v) { CeedInt dim, num_comp, q_comp, num_nodes, num_qpts; CeedSize u_length = 0, v_length; - Ceed ceed; - CeedCall(CeedBasisGetCeed(basis, &ceed)); CeedCall(CeedBasisGetDimension(basis, &dim)); CeedCall(CeedBasisGetNumComponents(basis, &num_comp)); CeedCall(CeedBasisGetNumQuadratureComponents(basis, eval_mode, &q_comp)); @@ -1834,7 +1833,7 @@ static int CeedBasisApplyCheckDims(CeedBasis basis, CeedInt num_elem, CeedTransp has_good_dims = v_length >= (CeedSize)num_elem * (CeedSize)num_qpts; break; } - CeedCheck(has_good_dims, ceed, CEED_ERROR_DIMENSION, "Input/output vectors too short for basis and evaluation mode"); + CeedCheck(has_good_dims, CeedBasisReturnCeed(basis), CEED_ERROR_DIMENSION, "Input/output vectors too short for basis and evaluation mode"); return CEED_ERROR_SUCCESS; } @@ -1969,7 +1968,8 @@ int CeedBasisApplyAddAtPoints(CeedBasis basis, CeedInt num_elem, const CeedInt * @ref Advanced **/ int CeedBasisGetCeed(CeedBasis basis, Ceed *ceed) { - *ceed = CeedBasisReturnCeed(basis); + *ceed = NULL; + CeedCall(CeedReferenceCopy(CeedBasisReturnCeed(basis), ceed)); return CEED_ERROR_SUCCESS; } diff --git a/interface/ceed-cuda.c b/interface/ceed-cuda.c index c4463b738d..ff28d10d14 100644 --- a/interface/ceed-cuda.c +++ b/interface/ceed-cuda.c @@ -23,10 +23,7 @@ **/ int CeedQFunctionSetCUDAUserFunction(CeedQFunction qf, CUfunction f) { if (!qf->SetCUDAUserFunction) { - Ceed ceed; - - CeedCall(CeedQFunctionGetCeed(qf, &ceed)); - CeedDebug(ceed, "Backend does not support CUfunction pointers for QFunctions."); + CeedDebug(CeedQFunctionReturnCeed(qf), "Backend does not support CUfunction pointers for QFunctions."); } else { CeedCall(qf->SetCUDAUserFunction(qf, f)); } diff --git a/interface/ceed-elemrestriction.c b/interface/ceed-elemrestriction.c index 7d832f1a97..5d2650abdb 100644 --- a/interface/ceed-elemrestriction.c +++ b/interface/ceed-elemrestriction.c @@ -164,13 +164,12 @@ int CeedElemRestrictionIsAtPoints(CeedElemRestriction rstr, bool *is_points) { **/ int CeedElemRestrictionAtPointsAreCompatible(CeedElemRestriction rstr_a, CeedElemRestriction rstr_b, bool *are_compatible) { CeedInt num_elem_a, num_elem_b, num_points_a, num_points_b; - Ceed ceed; - - CeedCall(CeedElemRestrictionGetCeed(rstr_a, &ceed)); // Cannot compare non-points restrictions - CeedCheck(rstr_a->rstr_type == CEED_RESTRICTION_POINTS, ceed, CEED_ERROR_UNSUPPORTED, "First CeedElemRestriction must be AtPoints"); - CeedCheck(rstr_b->rstr_type == CEED_RESTRICTION_POINTS, ceed, CEED_ERROR_UNSUPPORTED, "Second CeedElemRestriction must be AtPoints"); + CeedCheck(rstr_a->rstr_type == CEED_RESTRICTION_POINTS, CeedElemRestrictionReturnCeed(rstr_a), CEED_ERROR_UNSUPPORTED, + "First CeedElemRestriction must be AtPoints"); + CeedCheck(rstr_b->rstr_type == CEED_RESTRICTION_POINTS, CeedElemRestrictionReturnCeed(rstr_a), CEED_ERROR_UNSUPPORTED, + "Second CeedElemRestriction must be AtPoints"); CeedCall(CeedElemRestrictionGetNumElements(rstr_a, &num_elem_a)); CeedCall(CeedElemRestrictionGetNumElements(rstr_b, &num_elem_b)); @@ -357,14 +356,13 @@ int CeedElemRestrictionRestoreCurlOrientations(CeedElemRestriction rstr, const C int CeedElemRestrictionGetLLayout(CeedElemRestriction rstr, CeedInt layout[3]) { bool has_backend_strides; CeedRestrictionType rstr_type; - Ceed ceed; - CeedCall(CeedElemRestrictionGetCeed(rstr, &ceed)); CeedCall(CeedElemRestrictionGetType(rstr, &rstr_type)); - CeedCheck(rstr_type == CEED_RESTRICTION_STRIDED, ceed, CEED_ERROR_MINOR, "Only strided CeedElemRestriction have strided L-vector layout"); + CeedCheck(rstr_type == CEED_RESTRICTION_STRIDED, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_MINOR, + "Only strided CeedElemRestriction have strided L-vector layout"); CeedCall(CeedElemRestrictionHasBackendStrides(rstr, &has_backend_strides)); if (has_backend_strides) { - CeedCheck(rstr->l_layout[0], ceed, CEED_ERROR_MINOR, "CeedElemRestriction has no L-vector layout data"); + CeedCheck(rstr->l_layout[0], CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_MINOR, "CeedElemRestriction has no L-vector layout data"); for (CeedInt i = 0; i < 3; i++) layout[i] = rstr->l_layout[i]; } else { CeedCall(CeedElemRestrictionGetStrides(rstr, layout)); @@ -481,12 +479,11 @@ int CeedElemRestrictionGetAtPointsElementOffset(CeedElemRestriction rstr, CeedIn **/ int CeedElemRestrictionSetAtPointsEVectorSize(CeedElemRestriction rstr, CeedSize e_size) { CeedRestrictionType rstr_type; - Ceed ceed; - CeedCall(CeedElemRestrictionGetCeed(rstr, &ceed)); CeedCall(CeedElemRestrictionGetType(rstr, &rstr_type)); - CeedCheck(rstr_type == CEED_RESTRICTION_POINTS, ceed, CEED_ERROR_INCOMPATIBLE, "Can only compute offset for a points CeedElemRestriction"); - CeedCheck(e_size >= rstr->e_size, ceed, CEED_ERROR_INCOMPATIBLE, + CeedCheck(rstr_type == CEED_RESTRICTION_POINTS, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_INCOMPATIBLE, + "Can only compute offset for a points CeedElemRestriction"); + CeedCheck(e_size >= rstr->e_size, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_INCOMPATIBLE, "Can only increase the size of the E-vector for the CeedElemRestriction." " Current size: %" CeedSize_FMT " New size: %" CeedSize_FMT, rstr->e_size, e_size); @@ -1269,6 +1266,7 @@ int CeedElemRestrictionCreateVector(CeedElemRestriction rstr, CeedVector *l_vec, CeedCall(CeedElemRestrictionGetEVectorSize(rstr, &e_size)); if (l_vec) CeedCall(CeedVectorCreate(ceed, l_size, l_vec)); if (e_vec) CeedCall(CeedVectorCreate(ceed, e_size, e_vec)); + CeedCall(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -1289,9 +1287,7 @@ int CeedElemRestrictionCreateVector(CeedElemRestriction rstr, CeedVector *l_vec, int CeedElemRestrictionApply(CeedElemRestriction rstr, CeedTransposeMode t_mode, CeedVector u, CeedVector ru, CeedRequest *request) { CeedSize min_u_len, min_ru_len, len; CeedInt num_elem; - Ceed ceed; - CeedCall(CeedElemRestrictionGetCeed(rstr, &ceed)); if (t_mode == CEED_NOTRANSPOSE) { CeedCall(CeedElemRestrictionGetEVectorSize(rstr, &min_ru_len)); CeedCall(CeedElemRestrictionGetLVectorSize(rstr, &min_u_len)); @@ -1300,11 +1296,11 @@ int CeedElemRestrictionApply(CeedElemRestriction rstr, CeedTransposeMode t_mode, CeedCall(CeedElemRestrictionGetLVectorSize(rstr, &min_ru_len)); } CeedCall(CeedVectorGetLength(u, &len)); - CeedCheck(min_u_len <= len, ceed, CEED_ERROR_DIMENSION, + CeedCheck(min_u_len <= len, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_DIMENSION, "Input vector size %" CeedInt_FMT " not compatible with element restriction (%" CeedInt_FMT ", %" CeedInt_FMT ")", len, min_ru_len, min_u_len); CeedCall(CeedVectorGetLength(ru, &len)); - CeedCheck(min_ru_len <= len, ceed, CEED_ERROR_DIMENSION, + CeedCheck(min_ru_len <= len, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_DIMENSION, "Output vector size %" CeedInt_FMT " not compatible with element restriction (%" CeedInt_FMT ", %" CeedInt_FMT ")", len, min_u_len, min_ru_len); CeedCall(CeedElemRestrictionGetNumElements(rstr, &num_elem)); @@ -1331,10 +1327,9 @@ int CeedElemRestrictionApplyAtPointsInElement(CeedElemRestriction rstr, CeedInt CeedRequest *request) { CeedSize min_u_len, min_ru_len, len; CeedInt num_elem; - Ceed ceed; - CeedCall(CeedElemRestrictionGetCeed(rstr, &ceed)); - CeedCheck(rstr->ApplyAtPointsInElement, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedElemRestrictionApplyAtPointsInElement"); + CeedCheck(rstr->ApplyAtPointsInElement, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_UNSUPPORTED, + "Backend does not implement CeedElemRestrictionApplyAtPointsInElement"); if (t_mode == CEED_NOTRANSPOSE) { CeedInt num_points, num_comp; @@ -1352,17 +1347,17 @@ int CeedElemRestrictionApplyAtPointsInElement(CeedElemRestriction rstr, CeedInt CeedCall(CeedElemRestrictionGetLVectorSize(rstr, &min_ru_len)); } CeedCall(CeedVectorGetLength(u, &len)); - CeedCheck(min_u_len <= len, ceed, CEED_ERROR_DIMENSION, + CeedCheck(min_u_len <= len, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_DIMENSION, "Input vector size %" CeedInt_FMT " not compatible with element restriction (%" CeedInt_FMT ", %" CeedInt_FMT ") for element %" CeedInt_FMT, len, min_ru_len, min_u_len, elem); CeedCall(CeedVectorGetLength(ru, &len)); - CeedCheck(min_ru_len <= len, ceed, CEED_ERROR_DIMENSION, + CeedCheck(min_ru_len <= len, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_DIMENSION, "Output vector size %" CeedInt_FMT " not compatible with element restriction (%" CeedInt_FMT ", %" CeedInt_FMT ") for element %" CeedInt_FMT, len, min_ru_len, min_u_len, elem); CeedCall(CeedElemRestrictionGetNumElements(rstr, &num_elem)); - CeedCheck(elem < num_elem, ceed, CEED_ERROR_DIMENSION, + CeedCheck(elem < num_elem, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_DIMENSION, "Cannot retrieve element %" CeedInt_FMT ", element %" CeedInt_FMT " > total elements %" CeedInt_FMT "", elem, elem, num_elem); if (num_elem > 0) CeedCall(rstr->ApplyAtPointsInElement(rstr, elem, t_mode, u, ru, request)); return CEED_ERROR_SUCCESS; @@ -1387,10 +1382,9 @@ int CeedElemRestrictionApplyBlock(CeedElemRestriction rstr, CeedInt block, CeedT CeedRequest *request) { CeedSize min_u_len, min_ru_len, len; CeedInt block_size, num_elem; - Ceed ceed; - CeedCall(CeedElemRestrictionGetCeed(rstr, &ceed)); - CeedCheck(rstr->ApplyBlock, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedElemRestrictionApplyBlock"); + CeedCheck(rstr->ApplyBlock, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_UNSUPPORTED, + "Backend does not implement CeedElemRestrictionApplyBlock"); CeedCall(CeedElemRestrictionGetBlockSize(rstr, &block_size)); if (t_mode == CEED_NOTRANSPOSE) { @@ -1409,15 +1403,15 @@ int CeedElemRestrictionApplyBlock(CeedElemRestriction rstr, CeedInt block, CeedT min_u_len = (CeedSize)block_size * (CeedSize)elem_size * (CeedSize)num_comp; } CeedCall(CeedVectorGetLength(u, &len)); - CeedCheck(min_u_len == len, ceed, CEED_ERROR_DIMENSION, + CeedCheck(min_u_len == len, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_DIMENSION, "Input vector size %" CeedInt_FMT " not compatible with element restriction (%" CeedInt_FMT ", %" CeedInt_FMT ")", len, min_u_len, min_ru_len); CeedCall(CeedVectorGetLength(ru, &len)); - CeedCheck(min_ru_len == len, ceed, CEED_ERROR_DIMENSION, + CeedCheck(min_ru_len == len, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_DIMENSION, "Output vector size %" CeedInt_FMT " not compatible with element restriction (%" CeedInt_FMT ", %" CeedInt_FMT ")", len, min_ru_len, min_u_len); CeedCall(CeedElemRestrictionGetNumElements(rstr, &num_elem)); - CeedCheck(block_size * block <= num_elem, ceed, CEED_ERROR_DIMENSION, + CeedCheck(block_size * block <= num_elem, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_DIMENSION, "Cannot retrieve block %" CeedInt_FMT ", element %" CeedInt_FMT " > total elements %" CeedInt_FMT "", block, block_size * block, num_elem); CeedCall(rstr->ApplyBlock(rstr, block, t_mode, u, ru, request)); @@ -1435,7 +1429,8 @@ int CeedElemRestrictionApplyBlock(CeedElemRestriction rstr, CeedInt block, CeedT @ref Advanced **/ int CeedElemRestrictionGetCeed(CeedElemRestriction rstr, Ceed *ceed) { - *ceed = CeedElemRestrictionReturnCeed(rstr); + *ceed = NULL; + CeedCall(CeedReferenceCopy(CeedElemRestrictionReturnCeed(rstr), ceed)); return CEED_ERROR_SUCCESS; } diff --git a/interface/ceed-hip.c b/interface/ceed-hip.c index cc4a625853..f14df51eb5 100644 --- a/interface/ceed-hip.c +++ b/interface/ceed-hip.c @@ -23,10 +23,7 @@ **/ int CeedQFunctionSetHIPUserFunction(CeedQFunction qf, hipFunction_t f) { if (!qf->SetHIPUserFunction) { - Ceed ceed; - - CeedCall(CeedQFunctionGetCeed(qf, &ceed)); - CeedDebug(ceed, "Backend does not support hipFunction_t pointers for QFunctions."); + CeedDebug(CeedQFunctionReturnCeed(qf), "Backend does not support hipFunction_t pointers for QFunctions."); } else { CeedCall(qf->SetHIPUserFunction(qf, f)); } diff --git a/interface/ceed-operator.c b/interface/ceed-operator.c index 301d5584fa..0543100dca 100644 --- a/interface/ceed-operator.c +++ b/interface/ceed-operator.c @@ -195,10 +195,8 @@ int CeedOperatorGetActiveBasis(CeedOperator op, CeedBasis *active_basis) { int CeedOperatorGetActiveBases(CeedOperator op, CeedBasis *active_input_basis, CeedBasis *active_output_basis) { bool is_composite; CeedInt num_input_fields, num_output_fields; - Ceed ceed; CeedOperatorField *op_input_fields, *op_output_fields; - CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedOperatorIsComposite(op, &is_composite)); CeedCall(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); @@ -213,13 +211,14 @@ int CeedOperatorGetActiveBases(CeedOperator op, CeedBasis *active_input_basis, C CeedBasis basis; CeedCall(CeedOperatorFieldGetBasis(op_input_fields[i], &basis)); - CeedCheck(!*active_input_basis || *active_input_basis == basis, ceed, CEED_ERROR_MINOR, "Multiple active input CeedBases found"); + CeedCheck(!*active_input_basis || *active_input_basis == basis, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, + "Multiple active input CeedBases found"); if (!*active_input_basis) CeedCall(CeedBasisReferenceCopy(basis, active_input_basis)); CeedCall(CeedBasisDestroy(&basis)); } CeedCall(CeedVectorDestroy(&vec)); } - CeedCheck(*active_input_basis, ceed, CEED_ERROR_INCOMPLETE, "No active input CeedBasis found"); + CeedCheck(*active_input_basis, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, "No active input CeedBasis found"); } } if (active_output_basis) { @@ -233,13 +232,14 @@ int CeedOperatorGetActiveBases(CeedOperator op, CeedBasis *active_input_basis, C CeedBasis basis; CeedCall(CeedOperatorFieldGetBasis(op_output_fields[i], &basis)); - CeedCheck(!*active_output_basis || *active_output_basis == basis, ceed, CEED_ERROR_MINOR, "Multiple active output CeedBases found"); + CeedCheck(!*active_output_basis || *active_output_basis == basis, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, + "Multiple active output CeedBases found"); if (!*active_output_basis) CeedCall(CeedBasisReferenceCopy(basis, active_output_basis)); CeedCall(CeedBasisDestroy(&basis)); } CeedCall(CeedVectorDestroy(&vec)); } - CeedCheck(*active_output_basis, ceed, CEED_ERROR_INCOMPLETE, "No active output CeedBasis found"); + CeedCheck(*active_output_basis, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, "No active output CeedBasis found"); } } return CEED_ERROR_SUCCESS; @@ -278,10 +278,8 @@ int CeedOperatorGetActiveElemRestriction(CeedOperator op, CeedElemRestriction *a int CeedOperatorGetActiveElemRestrictions(CeedOperator op, CeedElemRestriction *active_input_rstr, CeedElemRestriction *active_output_rstr) { bool is_composite; CeedInt num_input_fields, num_output_fields; - Ceed ceed; CeedOperatorField *op_input_fields, *op_output_fields; - CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedOperatorIsComposite(op, &is_composite)); CeedCall(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); @@ -296,13 +294,14 @@ int CeedOperatorGetActiveElemRestrictions(CeedOperator op, CeedElemRestriction * CeedElemRestriction rstr; CeedCall(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &rstr)); - CeedCheck(!*active_input_rstr || *active_input_rstr == rstr, ceed, CEED_ERROR_MINOR, "Multiple active input CeedElemRestrictions found"); + CeedCheck(!*active_input_rstr || *active_input_rstr == rstr, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, + "Multiple active input CeedElemRestrictions found"); if (!*active_input_rstr) CeedCall(CeedElemRestrictionReferenceCopy(rstr, active_input_rstr)); CeedCall(CeedElemRestrictionDestroy(&rstr)); } CeedCall(CeedVectorDestroy(&vec)); } - CeedCheck(*active_input_rstr, ceed, CEED_ERROR_INCOMPLETE, "No active input CeedElemRestriction found"); + CeedCheck(*active_input_rstr, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, "No active input CeedElemRestriction found"); } } if (active_output_rstr) { @@ -316,13 +315,14 @@ int CeedOperatorGetActiveElemRestrictions(CeedOperator op, CeedElemRestriction * CeedElemRestriction rstr; CeedCall(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &rstr)); - CeedCheck(!*active_output_rstr || *active_output_rstr == rstr, ceed, CEED_ERROR_MINOR, "Multiple active output CeedElemRestrictions found"); + CeedCheck(!*active_output_rstr || *active_output_rstr == rstr, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, + "Multiple active output CeedElemRestrictions found"); if (!*active_output_rstr) CeedCall(CeedElemRestrictionReferenceCopy(rstr, active_output_rstr)); CeedCall(CeedElemRestrictionDestroy(&rstr)); } CeedCall(CeedVectorDestroy(&vec)); } - CeedCheck(*active_output_rstr, ceed, CEED_ERROR_INCOMPLETE, "No active output CeedElemRestriction found"); + CeedCheck(*active_output_rstr, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, "No active output CeedElemRestriction found"); } } return CEED_ERROR_SUCCESS; @@ -345,10 +345,8 @@ int CeedOperatorGetActiveElemRestrictions(CeedOperator op, CeedElemRestriction * **/ static int CeedOperatorContextSetGeneric(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, void *values) { bool is_composite = false; - Ceed ceed; - CeedCall(CeedOperatorGetCeed(op, &ceed)); - CeedCheck(field_label, ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); + CeedCheck(field_label, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "Invalid field label"); // Check if field_label and op correspond if (field_label->from_op) { @@ -357,7 +355,7 @@ static int CeedOperatorContextSetGeneric(CeedOperator op, CeedContextFieldLabel for (CeedInt i = 0; i < op->num_context_labels; i++) { if (op->context_labels[i] == field_label) index = i; } - CeedCheck(index != -1, ceed, CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); + CeedCheck(index != -1, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); } CeedCall(CeedOperatorIsComposite(op, &is_composite)); @@ -367,7 +365,8 @@ static int CeedOperatorContextSetGeneric(CeedOperator op, CeedContextFieldLabel CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); - CeedCheck(num_sub == field_label->num_sub_labels, ceed, CEED_ERROR_UNSUPPORTED, "Composite operator modified after ContextFieldLabel created"); + CeedCheck(num_sub == field_label->num_sub_labels, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, + "Composite operator modified after ContextFieldLabel created"); for (CeedInt i = 0; i < num_sub; i++) { CeedQFunction qf; @@ -386,7 +385,7 @@ static int CeedOperatorContextSetGeneric(CeedOperator op, CeedContextFieldLabel CeedCall(CeedOperatorGetQFunction(op, &qf)); CeedCall(CeedQFunctionGetContext(qf, &ctx)); - CeedCheck(ctx, ceed, CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); + CeedCheck(ctx, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label, field_type, values)); } CeedCall(CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(op, true)); @@ -412,10 +411,8 @@ static int CeedOperatorContextSetGeneric(CeedOperator op, CeedContextFieldLabel static int CeedOperatorContextGetGenericRead(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, size_t *num_values, void *values) { bool is_composite = false; - Ceed ceed; - CeedCall(CeedOperatorGetCeed(op, &ceed)); - CeedCheck(field_label, ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); + CeedCheck(field_label, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "Invalid field label"); *(void **)values = NULL; *num_values = 0; @@ -427,7 +424,7 @@ static int CeedOperatorContextGetGenericRead(CeedOperator op, CeedContextFieldLa for (CeedInt i = 0; i < op->num_context_labels; i++) { if (op->context_labels[i] == field_label) index = i; } - CeedCheck(index != -1, ceed, CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); + CeedCheck(index != -1, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); } CeedCall(CeedOperatorIsComposite(op, &is_composite)); @@ -437,7 +434,8 @@ static int CeedOperatorContextGetGenericRead(CeedOperator op, CeedContextFieldLa CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); - CeedCheck(num_sub == field_label->num_sub_labels, ceed, CEED_ERROR_UNSUPPORTED, "Composite operator modified after ContextFieldLabel created"); + CeedCheck(num_sub == field_label->num_sub_labels, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, + "Composite operator modified after ContextFieldLabel created"); for (CeedInt i = 0; i < num_sub; i++) { CeedQFunction qf; @@ -457,7 +455,7 @@ static int CeedOperatorContextGetGenericRead(CeedOperator op, CeedContextFieldLa CeedCall(CeedOperatorGetQFunction(op, &qf)); CeedCall(CeedQFunctionGetContext(qf, &ctx)); - CeedCheck(ctx, ceed, CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); + CeedCheck(ctx, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label, field_type, num_values, values)); } return CEED_ERROR_SUCCESS; @@ -480,10 +478,8 @@ static int CeedOperatorContextGetGenericRead(CeedOperator op, CeedContextFieldLa **/ static int CeedOperatorContextRestoreGenericRead(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, void *values) { bool is_composite = false; - Ceed ceed; - CeedCall(CeedOperatorGetCeed(op, &ceed)); - CeedCheck(field_label, ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); + CeedCheck(field_label, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "Invalid field label"); // Check if field_label and op correspond if (field_label->from_op) { @@ -492,7 +488,7 @@ static int CeedOperatorContextRestoreGenericRead(CeedOperator op, CeedContextFie for (CeedInt i = 0; i < op->num_context_labels; i++) { if (op->context_labels[i] == field_label) index = i; } - CeedCheck(index != -1, ceed, CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); + CeedCheck(index != -1, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); } CeedCall(CeedOperatorIsComposite(op, &is_composite)); @@ -502,7 +498,8 @@ static int CeedOperatorContextRestoreGenericRead(CeedOperator op, CeedContextFie CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); - CeedCheck(num_sub == field_label->num_sub_labels, ceed, CEED_ERROR_UNSUPPORTED, "Composite operator modified after ContextFieldLabel created"); + CeedCheck(num_sub == field_label->num_sub_labels, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, + "Composite operator modified after ContextFieldLabel created"); for (CeedInt i = 0; i < num_sub; i++) { CeedQFunction qf; @@ -522,7 +519,7 @@ static int CeedOperatorContextRestoreGenericRead(CeedOperator op, CeedContextFie CeedCall(CeedOperatorGetQFunction(op, &qf)); CeedCall(CeedQFunctionGetContext(qf, &ctx)); - CeedCheck(ctx, ceed, CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); + CeedCheck(ctx, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label, field_type, values)); } return CEED_ERROR_SUCCESS; @@ -893,38 +890,38 @@ int CeedOperatorReferenceCopy(CeedOperator op, CeedOperator *op_copy) { int CeedOperatorSetField(CeedOperator op, const char *field_name, CeedElemRestriction rstr, CeedBasis basis, CeedVector vec) { bool is_input = true, is_at_points, is_composite, is_immutable; CeedInt num_elem = 0, num_qpts = 0, num_input_fields, num_output_fields; - Ceed ceed; CeedQFunction qf; CeedQFunctionField qf_field, *qf_input_fields, *qf_output_fields; CeedOperatorField *op_field; - CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); CeedCall(CeedOperatorIsComposite(op, &is_composite)); CeedCall(CeedOperatorIsImmutable(op, &is_immutable)); - CeedCheck(!is_composite, ceed, CEED_ERROR_INCOMPATIBLE, "Cannot add field to composite operator."); - CeedCheck(!is_immutable, ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); - CeedCheck(rstr, ceed, CEED_ERROR_INCOMPATIBLE, "CeedElemRestriction rstr for field \"%s\" must be non-NULL.", field_name); - CeedCheck(basis, ceed, CEED_ERROR_INCOMPATIBLE, "CeedBasis basis for field \"%s\" must be non-NULL.", field_name); - CeedCheck(vec, ceed, CEED_ERROR_INCOMPATIBLE, "CeedVector vec for field \"%s\" must be non-NULL.", field_name); + CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "Cannot add field to composite operator."); + CeedCheck(!is_immutable, CeedOperatorReturnCeed(op), CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); + CeedCheck(rstr, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "CeedElemRestriction rstr for field \"%s\" must be non-NULL.", field_name); + CeedCheck(basis, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "CeedBasis basis for field \"%s\" must be non-NULL.", field_name); + CeedCheck(vec, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "CeedVector vec for field \"%s\" must be non-NULL.", field_name); CeedCall(CeedElemRestrictionGetNumElements(rstr, &num_elem)); - CeedCheck(rstr == CEED_ELEMRESTRICTION_NONE || !op->has_restriction || num_elem == op->num_elem, ceed, CEED_ERROR_DIMENSION, + CeedCheck(rstr == CEED_ELEMRESTRICTION_NONE || !op->has_restriction || num_elem == op->num_elem, CeedOperatorReturnCeed(op), CEED_ERROR_DIMENSION, "CeedElemRestriction with %" CeedInt_FMT " elements incompatible with prior %" CeedInt_FMT " elements", num_elem, op->num_elem); { CeedRestrictionType rstr_type; CeedCall(CeedElemRestrictionGetType(rstr, &rstr_type)); if (rstr_type == CEED_RESTRICTION_POINTS) { - CeedCheck(is_at_points, ceed, CEED_ERROR_UNSUPPORTED, "CeedElemRestriction AtPoints not supported for standard operator fields"); - CeedCheck(basis == CEED_BASIS_NONE, ceed, CEED_ERROR_UNSUPPORTED, "CeedElemRestriction AtPoints must be used with CEED_BASIS_NONE"); + CeedCheck(is_at_points, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, + "CeedElemRestriction AtPoints not supported for standard operator fields"); + CeedCheck(basis == CEED_BASIS_NONE, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, + "CeedElemRestriction AtPoints must be used with CEED_BASIS_NONE"); if (!op->first_points_rstr) { CeedCall(CeedElemRestrictionReferenceCopy(rstr, &op->first_points_rstr)); } else { bool are_compatible; CeedCall(CeedElemRestrictionAtPointsAreCompatible(op->first_points_rstr, rstr, &are_compatible)); - CeedCheck(are_compatible, ceed, CEED_ERROR_INCOMPATIBLE, + CeedCheck(are_compatible, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "CeedElemRestriction must have compatible offsets with previously set CeedElemRestriction"); } } @@ -932,7 +929,7 @@ int CeedOperatorSetField(CeedOperator op, const char *field_name, CeedElemRestri if (basis == CEED_BASIS_NONE) CeedCall(CeedElemRestrictionGetElementSize(rstr, &num_qpts)); else CeedCall(CeedBasisGetNumQuadraturePoints(basis, &num_qpts)); - CeedCheck(op->num_qpts == 0 || num_qpts == op->num_qpts, ceed, CEED_ERROR_DIMENSION, + CeedCheck(op->num_qpts == 0 || num_qpts == op->num_qpts, CeedOperatorReturnCeed(op), CEED_ERROR_DIMENSION, "%s must correspond to the same number of quadrature points as previously added CeedBases. Found %" CeedInt_FMT " quadrature points but expected %" CeedInt_FMT " quadrature points.", basis == CEED_BASIS_NONE ? "CeedElemRestriction" : "CeedBasis", num_qpts, op->num_qpts); @@ -961,10 +958,10 @@ int CeedOperatorSetField(CeedOperator op, const char *field_name, CeedElemRestri } } // LCOV_EXCL_START - return CeedError(ceed, CEED_ERROR_INCOMPLETE, "CeedQFunction has no knowledge of field '%s'", field_name); + return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, "CeedQFunction has no knowledge of field '%s'", field_name); // LCOV_EXCL_STOP found: - CeedCall(CeedOperatorCheckField(ceed, qf_field, rstr, basis)); + CeedCall(CeedOperatorCheckField(CeedOperatorReturnCeed(op), qf_field, rstr, basis)); CeedCall(CeedCalloc(1, op_field)); if (vec == CEED_VECTOR_ACTIVE) { @@ -973,11 +970,11 @@ int CeedOperatorSetField(CeedOperator op, const char *field_name, CeedElemRestri CeedCall(CeedElemRestrictionGetLVectorSize(rstr, &l_size)); if (is_input) { if (op->input_size == -1) op->input_size = l_size; - CeedCheck(l_size == op->input_size, ceed, CEED_ERROR_INCOMPATIBLE, + CeedCheck(l_size == op->input_size, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "LVector size %" CeedSize_FMT " does not match previous size %" CeedSize_FMT "", l_size, op->input_size); } else { if (op->output_size == -1) op->output_size = l_size; - CeedCheck(l_size == op->output_size, ceed, CEED_ERROR_INCOMPATIBLE, + CeedCheck(l_size == op->output_size, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "LVector size %" CeedSize_FMT " does not match previous size %" CeedSize_FMT "", l_size, op->output_size); } } @@ -1041,13 +1038,11 @@ int CeedOperatorGetFields(CeedOperator op, CeedInt *num_input_fields, CeedOperat **/ int CeedOperatorAtPointsSetPoints(CeedOperator op, CeedElemRestriction rstr_points, CeedVector point_coords) { bool is_at_points, is_immutable; - Ceed ceed; - CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); CeedCall(CeedOperatorIsImmutable(op, &is_immutable)); - CeedCheck(is_at_points, ceed, CEED_ERROR_MINOR, "Only defined for operator at points"); - CeedCheck(!is_immutable, ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); + CeedCheck(is_at_points, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Only defined for operator at points"); + CeedCheck(!is_immutable, CeedOperatorReturnCeed(op), CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); if (!op->first_points_rstr) { CeedCall(CeedElemRestrictionReferenceCopy(rstr_points, &op->first_points_rstr)); @@ -1055,7 +1050,7 @@ int CeedOperatorAtPointsSetPoints(CeedOperator op, CeedElemRestriction rstr_poin bool are_compatible; CeedCall(CeedElemRestrictionAtPointsAreCompatible(op->first_points_rstr, rstr_points, &are_compatible)); - CeedCheck(are_compatible, ceed, CEED_ERROR_INCOMPATIBLE, + CeedCheck(are_compatible, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "CeedElemRestriction must have compatible offsets with previously set field CeedElemRestriction"); } @@ -1249,13 +1244,12 @@ int CeedOperatorFieldGetData(CeedOperatorField op_field, const char **field_name */ int CeedCompositeOperatorAddSub(CeedOperator composite_op, CeedOperator sub_op) { bool is_immutable; - Ceed ceed; - CeedCall(CeedOperatorGetCeed(composite_op, &ceed)); - CeedCheck(composite_op->is_composite, ceed, CEED_ERROR_MINOR, "CeedOperator is not a composite operator"); - CeedCheck(composite_op->num_suboperators < CEED_COMPOSITE_MAX, ceed, CEED_ERROR_UNSUPPORTED, "Cannot add additional sub-operators"); + CeedCheck(composite_op->is_composite, CeedOperatorReturnCeed(composite_op), CEED_ERROR_MINOR, "CeedOperator is not a composite operator"); + CeedCheck(composite_op->num_suboperators < CEED_COMPOSITE_MAX, CeedOperatorReturnCeed(composite_op), CEED_ERROR_UNSUPPORTED, + "Cannot add additional sub-operators"); CeedCall(CeedOperatorIsImmutable(composite_op, &is_immutable)); - CeedCheck(!is_immutable, ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); + CeedCheck(!is_immutable, CeedOperatorReturnCeed(composite_op), CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); { CeedSize input_size, output_size; @@ -1264,8 +1258,8 @@ int CeedCompositeOperatorAddSub(CeedOperator composite_op, CeedOperator sub_op) if (composite_op->input_size == -1) composite_op->input_size = input_size; if (composite_op->output_size == -1) composite_op->output_size = output_size; // Note, a size of -1 means no active vector restriction set, so no incompatibility - CeedCheck((input_size == -1 || input_size == composite_op->input_size) && (output_size == -1 || output_size == composite_op->output_size), ceed, - CEED_ERROR_MAJOR, + CeedCheck((input_size == -1 || input_size == composite_op->input_size) && (output_size == -1 || output_size == composite_op->output_size), + CeedOperatorReturnCeed(composite_op), CEED_ERROR_MAJOR, "Sub-operators must have compatible dimensions; composite operator of shape (%" CeedSize_FMT ", %" CeedSize_FMT ") not compatible with sub-operator of " "shape (%" CeedSize_FMT ", %" CeedSize_FMT ")", @@ -1361,12 +1355,10 @@ int CeedCompositeOperatorGetSubByName(CeedOperator op, const char *op_name, Ceed **/ int CeedOperatorCheckReady(CeedOperator op) { bool is_at_points, is_composite; - Ceed ceed; CeedQFunction qf = NULL; if (op->is_interface_setup) return CEED_ERROR_SUCCESS; - CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); CeedCall(CeedOperatorIsComposite(op, &is_composite)); if (!is_composite) CeedCall(CeedOperatorGetQFunction(op, &qf)); @@ -1393,11 +1385,12 @@ int CeedOperatorCheckReady(CeedOperator op) { } else { CeedInt num_input_fields, num_output_fields; - CeedCheck(op->num_fields > 0, ceed, CEED_ERROR_INCOMPLETE, "No operator fields set"); + CeedCheck(op->num_fields > 0, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, "No operator fields set"); CeedCall(CeedQFunctionGetFields(qf, &num_input_fields, NULL, &num_output_fields, NULL)); - CeedCheck(op->num_fields == num_input_fields + num_output_fields, ceed, CEED_ERROR_INCOMPLETE, "Not all operator fields set"); - CeedCheck(op->has_restriction, ceed, CEED_ERROR_INCOMPLETE, "At least one restriction required"); - CeedCheck(op->num_qpts > 0 || is_at_points, ceed, CEED_ERROR_INCOMPLETE, + CeedCheck(op->num_fields == num_input_fields + num_output_fields, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, + "Not all operator fields set"); + CeedCheck(op->has_restriction, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, "At least one restriction required"); + CeedCheck(op->num_qpts > 0 || is_at_points, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, "At least one non-collocated CeedBasis is required or the number of quadrature points must be set"); } @@ -1612,7 +1605,8 @@ int CeedOperatorViewTerse(CeedOperator op, FILE *stream) { @ref Advanced **/ int CeedOperatorGetCeed(CeedOperator op, Ceed *ceed) { - *ceed = CeedOperatorReturnCeed(op); + *ceed = NULL; + CeedCall(CeedReferenceCopy(CeedOperatorReturnCeed(op), ceed)); return CEED_ERROR_SUCCESS; } diff --git a/interface/ceed-preconditioning.c b/interface/ceed-preconditioning.c index 3e82b38493..d89b4b5766 100644 --- a/interface/ceed-preconditioning.c +++ b/interface/ceed-preconditioning.c @@ -37,15 +37,13 @@ static int CeedQFunctionCreateFallback(Ceed fallback_ceed, CeedQFunction qf, CeedQFunction *qf_fallback) { char *source_path_with_name = NULL; CeedInt num_input_fields, num_output_fields; - Ceed ceed; CeedQFunctionField *input_fields, *output_fields; // Check if NULL qf passed in if (!qf) return CEED_ERROR_SUCCESS; - CeedCall(CeedQFunctionGetCeed(qf, &ceed)); - CeedDebug256(ceed, 1, "---------- CeedOperator Fallback ----------\n"); - CeedDebug(ceed, "Creating fallback CeedQFunction\n"); + CeedDebug256(CeedQFunctionReturnCeed(qf), 1, "---------- CeedOperator Fallback ----------\n"); + CeedDebug(CeedQFunctionReturnCeed(qf), "Creating fallback CeedQFunction\n"); if (qf->source_path) { size_t path_len = strlen(qf->source_path), name_len = strlen(qf->kernel_name); @@ -115,10 +113,11 @@ static int CeedOperatorCreateFallback(CeedOperator op) { // Fallback Ceed CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedGetOperatorFallbackCeed(ceed, &ceed_fallback)); + CeedCall(CeedDestroy(&ceed)); if (!ceed_fallback) return CEED_ERROR_SUCCESS; - CeedDebug256(ceed, 1, "---------- CeedOperator Fallback ----------\n"); - CeedDebug(ceed, "Creating fallback CeedOperator\n"); + CeedDebug256(CeedOperatorReturnCeed(op), 1, "---------- CeedOperator Fallback ----------\n"); + CeedDebug(CeedOperatorReturnCeed(op), "Creating fallback CeedOperator\n"); // Clone Op CeedCall(CeedOperatorIsComposite(op, &is_composite)); @@ -203,12 +202,10 @@ static int CeedOperatorCreateFallback(CeedOperator op) { **/ static inline int CeedSingleOperatorLinearAssembleAddDiagonal_Mesh(CeedOperator op, CeedRequest *request, const bool is_point_block, CeedVector assembled) { - Ceed ceed; bool is_composite; - CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedOperatorIsComposite(op, &is_composite)); - CeedCheck(!is_composite, ceed, CEED_ERROR_UNSUPPORTED, "Composite operator not supported"); + CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "Composite operator not supported"); // Assemble QFunction CeedInt layout_qf[3]; @@ -265,7 +262,7 @@ static inline int CeedSingleOperatorLinearAssembleAddDiagonal_Mesh(CeedOperator continue; } // No matching output basis found } - CeedCheck(active_elem_rstrs_in[b_in] == active_elem_rstrs_out[b_out], ceed, CEED_ERROR_UNSUPPORTED, + CeedCheck(active_elem_rstrs_in[b_in] == active_elem_rstrs_out[b_out], CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "Cannot assemble operator diagonal with different input and output active element restrictions"); // Assemble point block diagonal restriction, if needed @@ -390,12 +387,10 @@ static inline int CeedSingleOperatorLinearAssembleAddDiagonal_Mesh(CeedOperator **/ static inline int CeedSingleOperatorLinearAssembleAddDiagonal(CeedOperator op, CeedRequest *request, const bool is_point_block, CeedVector assembled) { - Ceed ceed; bool is_at_points; - CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); - CeedCheck(!is_at_points, ceed, CEED_ERROR_UNSUPPORTED, "AtPoints operator not supported"); + CeedCheck(!is_at_points, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "AtPoints operator not supported"); CeedCall(CeedSingleOperatorLinearAssembleAddDiagonal_Mesh(op, request, is_point_block, assembled)); return CEED_ERROR_SUCCESS; } @@ -539,6 +534,7 @@ static int CeedSingleOperatorAssembleSymbolic(CeedOperator op, CeedInt offset, C } CeedCall(CeedElemRestrictionDestroy(&elem_rstr_in)); CeedCall(CeedElemRestrictionDestroy(&elem_rstr_out)); + CeedCall(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -556,12 +552,10 @@ static int CeedSingleOperatorAssembleSymbolic(CeedOperator op, CeedInt offset, C @ref Developer **/ static int CeedSingleOperatorAssemble(CeedOperator op, CeedInt offset, CeedVector values) { - Ceed ceed; bool is_composite; - CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedOperatorIsComposite(op, &is_composite)); - CeedCheck(!is_composite, ceed, CEED_ERROR_UNSUPPORTED, "Composite operator not supported"); + CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "Composite operator not supported"); // Early exit for empty operator { @@ -615,9 +609,10 @@ static int CeedSingleOperatorAssemble(CeedOperator op, CeedInt offset, CeedVecto CeedCall(CeedOperatorAssemblyDataGetEvalModes(data, &num_active_bases_in, &num_eval_modes_in, &eval_modes_in, NULL, &num_active_bases_out, &num_eval_modes_out, &eval_modes_out, NULL, NULL)); - CeedCheck(num_active_bases_in == 1 && num_active_bases_out == 1, ceed, CEED_ERROR_UNSUPPORTED, + CeedCheck(num_active_bases_in == 1 && num_active_bases_out == 1, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "Cannot assemble operator with multiple active bases"); - CeedCheck(num_eval_modes_in[0] > 0 && num_eval_modes_out[0] > 0, ceed, CEED_ERROR_UNSUPPORTED, "Cannot assemble operator without inputs/outputs"); + CeedCheck(num_eval_modes_in[0] > 0 && num_eval_modes_out[0] > 0, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, + "Cannot assemble operator without inputs/outputs"); CeedCall(CeedOperatorAssemblyDataGetBases(data, NULL, &active_bases_in, &B_mats_in, NULL, &active_bases_out, &B_mats_out)); CeedCall(CeedOperatorGetActiveElemRestrictions(op, &elem_rstr_in, &elem_rstr_out)); @@ -641,7 +636,7 @@ static int CeedSingleOperatorAssemble(CeedOperator op, CeedInt offset, CeedVecto if (elem_rstr_in != elem_rstr_out) { CeedCall(CeedElemRestrictionGetNumElements(elem_rstr_out, &num_elem_out)); - CeedCheck(num_elem_in == num_elem_out, ceed, CEED_ERROR_UNSUPPORTED, + CeedCheck(num_elem_in == num_elem_out, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "Active input and output operator restrictions must have the same number of elements." " Input has %" CeedInt_FMT " elements; output has %" CeedInt_FMT "elements.", num_elem_in, num_elem_out); @@ -649,7 +644,7 @@ static int CeedSingleOperatorAssemble(CeedOperator op, CeedInt offset, CeedVecto CeedCall(CeedElemRestrictionGetNumComponents(elem_rstr_out, &num_comp_out)); if (basis_out == CEED_BASIS_NONE) num_qpts_out = elem_size_out; else CeedCall(CeedBasisGetNumQuadraturePoints(basis_out, &num_qpts_out)); - CeedCheck(num_qpts_in == num_qpts_out, ceed, CEED_ERROR_UNSUPPORTED, + CeedCheck(num_qpts_in == num_qpts_out, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "Active input and output bases must have the same number of quadrature points." " Input has %" CeedInt_FMT " points; output has %" CeedInt_FMT "points.", num_qpts_in, num_qpts_out); @@ -709,7 +704,11 @@ static int CeedSingleOperatorAssemble(CeedOperator op, CeedInt offset, CeedVecto CeedCall(CeedTensorContractApply(contract, 1, num_qpts_in * num_eval_modes_in[0], elem_size_in, elem_size_out, BTD_mat, CEED_NOTRANSPOSE, false, B_mat_in, elem_mat)); } else { + Ceed ceed; + + CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedMatrixMatrixMultiply(ceed, BTD_mat, B_mat_in, elem_mat, elem_size_out, elem_size_in, num_qpts_in * num_eval_modes_in[0])); + CeedCall(CeedDestroy(&ceed)); } // Transform the element matrix if required @@ -768,7 +767,7 @@ static int CeedSingleOperatorAssemble(CeedOperator op, CeedInt offset, CeedVecto } } } - CeedCheck(count == local_num_entries, ceed, CEED_ERROR_MAJOR, "Error computing entries"); + CeedCheck(count == local_num_entries, CeedOperatorReturnCeed(op), CEED_ERROR_MAJOR, "Error computing entries"); CeedCall(CeedVectorRestoreArray(values, &vals)); // Cleanup @@ -807,12 +806,10 @@ static int CeedSingleOperatorAssemble(CeedOperator op, CeedInt offset, CeedVecto static int CeedSingleOperatorAssemblyCountEntries(CeedOperator op, CeedSize *num_entries) { bool is_composite; CeedInt num_elem_in, elem_size_in, num_comp_in, num_elem_out, elem_size_out, num_comp_out; - Ceed ceed; CeedElemRestriction rstr_in, rstr_out; - CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedOperatorIsComposite(op, &is_composite)); - CeedCheck(!is_composite, ceed, CEED_ERROR_UNSUPPORTED, "Composite operator not supported"); + CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "Composite operator not supported"); CeedCall(CeedOperatorGetActiveElemRestrictions(op, &rstr_in, &rstr_out)); CeedCall(CeedElemRestrictionGetNumElements(rstr_in, &num_elem_in)); @@ -820,7 +817,7 @@ static int CeedSingleOperatorAssemblyCountEntries(CeedOperator op, CeedSize *num CeedCall(CeedElemRestrictionGetNumComponents(rstr_in, &num_comp_in)); if (rstr_in != rstr_out) { CeedCall(CeedElemRestrictionGetNumElements(rstr_out, &num_elem_out)); - CeedCheck(num_elem_in == num_elem_out, ceed, CEED_ERROR_UNSUPPORTED, + CeedCheck(num_elem_in == num_elem_out, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "Active input and output operator restrictions must have the same number of elements." " Input has %" CeedInt_FMT " elements; output has %" CeedInt_FMT "elements.", num_elem_in, num_elem_out); @@ -1034,6 +1031,7 @@ static int CeedSingleOperatorMultigridLevel(CeedOperator op_fine, CeedVector p_m CeedCall(CeedOperatorCheckReady(*op_coarse)); // Cleanup + CeedCall(CeedDestroy(&ceed)); CeedCall(CeedVectorDestroy(&mult_vec)); CeedCall(CeedElemRestrictionDestroy(&rstr_fine)); CeedCall(CeedElemRestrictionDestroy(&rstr_p_mult_fine)); @@ -1162,6 +1160,7 @@ int CeedOperatorCreateActivePointBlockRestriction(CeedElemRestriction rstr, Ceed // Cleanup CeedCall(CeedElemRestrictionRestoreOffsets(rstr, &offsets)); + CeedCall(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -1812,6 +1811,7 @@ int CeedOperatorGetFallback(CeedOperator op, CeedOperator *op_fallback) { CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "---------- CeedOperator Fallback ----------\n"); CeedDebug(ceed, "Falling back from %s operator at address %p to %s operator at address %p\n", resource, op, resource_fallback, op->op_fallback); } + CeedCall(CeedDestroy(&ceed)); } *op_fallback = op->op_fallback; return CEED_ERROR_SUCCESS; @@ -1883,13 +1883,11 @@ int CeedOperatorLinearAssembleQFunction(CeedOperator op, CeedVector *assembled, CeedCall(op->LinearAssembleQFunction(op, assembled, rstr, request)); } else { // Operator fallback - Ceed ceed; CeedOperator op_fallback; - CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedOperatorGetFallback(op, &op_fallback)); if (op_fallback) CeedCall(CeedOperatorLinearAssembleQFunction(op_fallback, assembled, rstr, request)); - else return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support CeedOperatorLinearAssembleQFunction"); + else return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "Backend does not support CeedOperatorLinearAssembleQFunction"); } return CEED_ERROR_SUCCESS; } @@ -1961,13 +1959,11 @@ int CeedOperatorLinearAssembleQFunctionBuildOrUpdate(CeedOperator op, CeedVector CeedCall(CeedElemRestrictionDestroy(&assembled_rstr)); } else { // Operator fallback - Ceed ceed; CeedOperator op_fallback; - CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedOperatorGetFallback(op, &op_fallback)); if (op_fallback) CeedCall(CeedOperatorLinearAssembleQFunctionBuildOrUpdate(op_fallback, assembled, rstr, request)); - else return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support CeedOperatorLinearAssembleQFunctionUpdate"); + else return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "Backend does not support CeedOperatorLinearAssembleQFunctionUpdate"); } return CEED_ERROR_SUCCESS; } @@ -1992,14 +1988,12 @@ int CeedOperatorLinearAssembleQFunctionBuildOrUpdate(CeedOperator op, CeedVector int CeedOperatorLinearAssembleDiagonal(CeedOperator op, CeedVector assembled, CeedRequest *request) { bool is_composite; CeedSize input_size = 0, output_size = 0; - Ceed ceed; - CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedOperatorCheckReady(op)); CeedCall(CeedOperatorIsComposite(op, &is_composite)); CeedCall(CeedOperatorGetActiveVectorLengths(op, &input_size, &output_size)); - CeedCheck(input_size == output_size, ceed, CEED_ERROR_DIMENSION, "Operator must be square"); + CeedCheck(input_size == output_size, CeedOperatorReturnCeed(op), CEED_ERROR_DIMENSION, "Operator must be square"); // Early exit for empty operator if (!is_composite) { @@ -2054,14 +2048,12 @@ int CeedOperatorLinearAssembleDiagonal(CeedOperator op, CeedVector assembled, Ce int CeedOperatorLinearAssembleAddDiagonal(CeedOperator op, CeedVector assembled, CeedRequest *request) { bool is_composite; CeedSize input_size = 0, output_size = 0; - Ceed ceed; - CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedOperatorCheckReady(op)); CeedCall(CeedOperatorIsComposite(op, &is_composite)); CeedCall(CeedOperatorGetActiveVectorLengths(op, &input_size, &output_size)); - CeedCheck(input_size == output_size, ceed, CEED_ERROR_DIMENSION, "Operator must be square"); + CeedCheck(input_size == output_size, CeedOperatorReturnCeed(op), CEED_ERROR_DIMENSION, "Operator must be square"); // Early exit for empty operator if (!is_composite) { @@ -2115,17 +2107,15 @@ int CeedOperatorLinearAssembleAddDiagonal(CeedOperator op, CeedVector assembled, @ref User **/ int CeedOperatorLinearAssemblePointBlockDiagonalSymbolic(CeedOperator op, CeedSize *num_entries, CeedInt **rows, CeedInt **cols) { - Ceed ceed; bool is_composite; CeedInt num_active_components, num_sub_operators; CeedOperator *sub_operators; - CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedOperatorIsComposite(op, &is_composite)); CeedSize input_size = 0, output_size = 0; CeedCall(CeedOperatorGetActiveVectorLengths(op, &input_size, &output_size)); - CeedCheck(input_size == output_size, ceed, CEED_ERROR_DIMENSION, "Operator must be square"); + CeedCheck(input_size == output_size, CeedOperatorReturnCeed(op), CEED_ERROR_DIMENSION, "Operator must be square"); if (is_composite) { CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub_operators)); @@ -2155,10 +2145,10 @@ int CeedOperatorLinearAssemblePointBlockDiagonalSymbolic(CeedOperator op, CeedSi CeedInt comp_stride_sub, num_active_components_sub; CeedCall(CeedElemRestrictionGetCompStride(active_elem_rstrs[i], &comp_stride_sub)); - CeedCheck(comp_stride == comp_stride_sub, ceed, CEED_ERROR_DIMENSION, + CeedCheck(comp_stride == comp_stride_sub, CeedOperatorReturnCeed(op), CEED_ERROR_DIMENSION, "Active element restrictions must have the same component stride: %d vs %d", comp_stride, comp_stride_sub); CeedCall(CeedElemRestrictionGetNumComponents(active_elem_rstrs[i], &num_active_components_sub)); - CeedCheck(num_active_components == num_active_components_sub, ceed, CEED_ERROR_INCOMPATIBLE, + CeedCheck(num_active_components == num_active_components_sub, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "All suboperators must have the same number of output components." " Previous: %" CeedInt_FMT " Current: %" CeedInt_FMT, num_active_components, num_active_components_sub); @@ -2222,14 +2212,12 @@ int CeedOperatorLinearAssemblePointBlockDiagonalSymbolic(CeedOperator op, CeedSi int CeedOperatorLinearAssemblePointBlockDiagonal(CeedOperator op, CeedVector assembled, CeedRequest *request) { bool is_composite; CeedSize input_size = 0, output_size = 0; - Ceed ceed; - CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedOperatorCheckReady(op)); CeedCall(CeedOperatorIsComposite(op, &is_composite)); CeedCall(CeedOperatorGetActiveVectorLengths(op, &input_size, &output_size)); - CeedCheck(input_size == output_size, ceed, CEED_ERROR_DIMENSION, "Operator must be square"); + CeedCheck(input_size == output_size, CeedOperatorReturnCeed(op), CEED_ERROR_DIMENSION, "Operator must be square"); // Early exit for empty operator if (!is_composite) { @@ -2286,14 +2274,12 @@ int CeedOperatorLinearAssemblePointBlockDiagonal(CeedOperator op, CeedVector ass int CeedOperatorLinearAssembleAddPointBlockDiagonal(CeedOperator op, CeedVector assembled, CeedRequest *request) { bool is_composite; CeedSize input_size = 0, output_size = 0; - Ceed ceed; - CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedOperatorCheckReady(op)); CeedCall(CeedOperatorIsComposite(op, &is_composite)); CeedCall(CeedOperatorGetActiveVectorLengths(op, &input_size, &output_size)); - CeedCheck(input_size == output_size, ceed, CEED_ERROR_DIMENSION, "Operator must be square"); + CeedCheck(input_size == output_size, CeedOperatorReturnCeed(op), CEED_ERROR_DIMENSION, "Operator must be square"); // Early exit for empty operator if (!is_composite) { @@ -2494,8 +2480,6 @@ int CeedCompositeOperatorGetMultiplicity(CeedOperator op, CeedInt num_skip_indic CeedCall(CeedOperatorCheckReady(op)); - CeedCall(CeedOperatorGetCeed(op, &ceed)); - // Zero mult vector CeedCall(CeedVectorSetValue(mult, 0.0)); @@ -2506,7 +2490,9 @@ int CeedCompositeOperatorGetMultiplicity(CeedOperator op, CeedInt num_skip_indic // Work vector CeedCall(CeedVectorGetLength(mult, &l_vec_len)); + CeedCall(CeedOperatorGetCeed(op, &ceed)); CeedCall(CeedVectorCreate(ceed, l_vec_len, &ones_l_vec)); + CeedCall(CeedDestroy(&ceed)); CeedCall(CeedVectorSetValue(ones_l_vec, 1.0)); CeedCall(CeedVectorGetArray(mult, CEED_MEM_HOST, &mult_array)); @@ -2642,6 +2628,7 @@ int CeedOperatorMultigridLevelCreateTensorH1(CeedOperator op_fine, CeedVector p_ // Core code CeedCall(CeedSingleOperatorMultigridLevel(op_fine, p_mult_fine, rstr_coarse, basis_coarse, basis_c_to_f, op_coarse, op_prolong, op_restrict)); + CeedCall(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -2705,6 +2692,7 @@ int CeedOperatorMultigridLevelCreateH1(CeedOperator op_fine, CeedVector p_mult_f // Core code CeedCall(CeedSingleOperatorMultigridLevel(op_fine, p_mult_fine, rstr_coarse, basis_coarse, basis_c_to_f, op_coarse, op_prolong, op_restrict)); + CeedCall(CeedDestroy(&ceed)); return CEED_ERROR_SUCCESS; } @@ -2939,6 +2927,7 @@ int CeedOperatorCreateFDMElementInverse(CeedOperator op, CeedOperator *fdm_inv, CeedCall(CeedOperatorSetField(*fdm_inv, "output", rstr, fdm_basis, CEED_VECTOR_ACTIVE)); // Cleanup + CeedCall(CeedDestroy(&ceed)); CeedCall(CeedVectorDestroy(&q_data)); CeedCall(CeedElemRestrictionDestroy(&rstr)); CeedCall(CeedElemRestrictionDestroy(&rstr_qd_i)); diff --git a/interface/ceed-qfunction.c b/interface/ceed-qfunction.c index 7c0cf3a285..377247ff07 100644 --- a/interface/ceed-qfunction.c +++ b/interface/ceed-qfunction.c @@ -252,6 +252,7 @@ int CeedQFunctionGetSourcePath(CeedQFunction qf, const char **source_path) { } else { CeedCall(CeedGetJitAbsolutePath(ceed, qf->user_source, &absolute_path)); } + CeedCall(CeedDestroy(&ceed)); size_t source_len = strlen(absolute_path) - kernel_name_len - 1; @@ -295,6 +296,7 @@ int CeedQFunctionLoadSourceToBuffer(CeedQFunction qf, const char **source_buffer CeedCall(CeedQFunctionGetCeed(qf, &ceed)); CeedCall(CeedLoadSourceToBuffer(ceed, source_path, &buffer)); + CeedCall(CeedDestroy(&ceed)); *source_buffer = buffer; } return CEED_ERROR_SUCCESS; @@ -770,18 +772,16 @@ int CeedQFunctionReferenceCopy(CeedQFunction qf, CeedQFunction *qf_copy) { **/ int CeedQFunctionAddInput(CeedQFunction qf, const char *field_name, CeedInt size, CeedEvalMode eval_mode) { bool is_immutable; - Ceed ceed; - CeedCall(CeedQFunctionGetCeed(qf, &ceed)); CeedCall(CeedQFunctionIsImmutable(qf, &is_immutable)); - CeedCheck(!is_immutable, ceed, CEED_ERROR_MAJOR, "QFunction cannot be changed after set as immutable"); - CeedCheck(eval_mode != CEED_EVAL_WEIGHT || size == 1, ceed, CEED_ERROR_DIMENSION, "CEED_EVAL_WEIGHT should have size 1"); + CeedCheck(!is_immutable, CeedQFunctionReturnCeed(qf), CEED_ERROR_MAJOR, "QFunction cannot be changed after set as immutable"); + CeedCheck(eval_mode != CEED_EVAL_WEIGHT || size == 1, CeedQFunctionReturnCeed(qf), CEED_ERROR_DIMENSION, "CEED_EVAL_WEIGHT should have size 1"); for (CeedInt i = 0; i < qf->num_input_fields; i++) { - CeedCheck(strcmp(field_name, qf->input_fields[i]->field_name), ceed, CEED_ERROR_MINOR, + CeedCheck(strcmp(field_name, qf->input_fields[i]->field_name), CeedQFunctionReturnCeed(qf), CEED_ERROR_MINOR, "CeedQFunction field names must be unique. Duplicate name: %s", field_name); } for (CeedInt i = 0; i < qf->num_output_fields; i++) { - CeedCheck(strcmp(field_name, qf->output_fields[i]->field_name), ceed, CEED_ERROR_MINOR, + CeedCheck(strcmp(field_name, qf->output_fields[i]->field_name), CeedQFunctionReturnCeed(qf), CEED_ERROR_MINOR, "CeedQFunction field names must be unique. Duplicate name: %s", field_name); } CeedCall(CeedQFunctionFieldSet(&qf->input_fields[qf->num_input_fields], field_name, size, eval_mode)); @@ -807,17 +807,18 @@ int CeedQFunctionAddInput(CeedQFunction qf, const char *field_name, CeedInt size **/ int CeedQFunctionAddOutput(CeedQFunction qf, const char *field_name, CeedInt size, CeedEvalMode eval_mode) { bool is_immutable; - Ceed ceed; - CeedCall(CeedQFunctionGetCeed(qf, &ceed)); CeedCall(CeedQFunctionIsImmutable(qf, &is_immutable)); - CeedCheck(!is_immutable, ceed, CEED_ERROR_MAJOR, "CeedQFunction cannot be changed after set as immutable"); - CeedCheck(eval_mode != CEED_EVAL_WEIGHT, ceed, CEED_ERROR_DIMENSION, "Cannot create CeedQFunction output with CEED_EVAL_WEIGHT"); + CeedCheck(!is_immutable, CeedQFunctionReturnCeed(qf), CEED_ERROR_MAJOR, "CeedQFunction cannot be changed after set as immutable"); + CeedCheck(eval_mode != CEED_EVAL_WEIGHT, CeedQFunctionReturnCeed(qf), CEED_ERROR_DIMENSION, + "Cannot create CeedQFunction output with CEED_EVAL_WEIGHT"); for (CeedInt i = 0; i < qf->num_input_fields; i++) { - CeedCheck(strcmp(field_name, qf->input_fields[i]->field_name), ceed, CEED_ERROR_MINOR, "CeedQFunction field names must be unique"); + CeedCheck(strcmp(field_name, qf->input_fields[i]->field_name), CeedQFunctionReturnCeed(qf), CEED_ERROR_MINOR, + "CeedQFunction field names must be unique"); } for (CeedInt i = 0; i < qf->num_output_fields; i++) { - CeedCheck(strcmp(field_name, qf->output_fields[i]->field_name), ceed, CEED_ERROR_MINOR, "CeedQFunction field names must be unique"); + CeedCheck(strcmp(field_name, qf->output_fields[i]->field_name), CeedQFunctionReturnCeed(qf), CEED_ERROR_MINOR, + "CeedQFunction field names must be unique"); } CeedCall(CeedQFunctionFieldSet(&qf->output_fields[qf->num_output_fields], field_name, size, eval_mode)); qf->num_output_fields++; @@ -1009,7 +1010,8 @@ int CeedQFunctionView(CeedQFunction qf, FILE *stream) { @ref Advanced **/ int CeedQFunctionGetCeed(CeedQFunction qf, Ceed *ceed) { - *ceed = CeedQFunctionReturnCeed(qf); + *ceed = NULL; + CeedCall(CeedReferenceCopy(CeedQFunctionReturnCeed(qf), ceed)); return CEED_ERROR_SUCCESS; } @@ -1040,13 +1042,11 @@ Ceed CeedQFunctionReturnCeed(CeedQFunction qf) { return qf->ceed; } **/ int CeedQFunctionApply(CeedQFunction qf, CeedInt Q, CeedVector *u, CeedVector *v) { CeedInt vec_length; - Ceed ceed; - CeedCall(CeedQFunctionGetCeed(qf, &ceed)); - CeedCheck(qf->Apply, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support CeedQFunctionApply"); + CeedCheck(qf->Apply, CeedQFunctionReturnCeed(qf), CEED_ERROR_UNSUPPORTED, "Backend does not support CeedQFunctionApply"); CeedCall(CeedQFunctionGetVectorLength(qf, &vec_length)); - CeedCheck(Q % vec_length == 0, ceed, CEED_ERROR_DIMENSION, "Number of quadrature points %" CeedInt_FMT " must be a multiple of %" CeedInt_FMT, Q, - qf->vec_length); + CeedCheck(Q % vec_length == 0, CeedQFunctionReturnCeed(qf), CEED_ERROR_DIMENSION, + "Number of quadrature points %" CeedInt_FMT " must be a multiple of %" CeedInt_FMT, Q, qf->vec_length); CeedCall(CeedQFunctionSetImmutable(qf)); CeedCall(qf->Apply(qf, Q, u, v)); return CEED_ERROR_SUCCESS; diff --git a/interface/ceed-qfunctioncontext.c b/interface/ceed-qfunctioncontext.c index 16cc22cebe..037756f71a 100644 --- a/interface/ceed-qfunctioncontext.c +++ b/interface/ceed-qfunctioncontext.c @@ -59,12 +59,11 @@ int CeedQFunctionContextRegisterGeneric(CeedQFunctionContext ctx, const char *fi CeedContextFieldType field_type, size_t num_values) { size_t field_size = 0; CeedInt field_index = -1; - Ceed ceed; // Check for duplicate - CeedCall(CeedQFunctionContextGetCeed(ctx, &ceed)); CeedCall(CeedQFunctionContextGetFieldIndex(ctx, field_name, &field_index)); - CeedCheck(field_index == -1, ceed, CEED_ERROR_UNSUPPORTED, "QFunctionContext field with name \"%s\" already registered", field_name); + CeedCheck(field_index == -1, CeedQFunctionContextReturnCeed(ctx), CEED_ERROR_UNSUPPORTED, + "QFunctionContext field with name \"%s\" already registered", field_name); // Allocate space for field data if (ctx->num_fields == 0) { @@ -147,7 +146,8 @@ static int CeedQFunctionContextDestroyData(CeedQFunctionContext ctx) { @ref Backend **/ int CeedQFunctionContextGetCeed(CeedQFunctionContext ctx, Ceed *ceed) { - *ceed = CeedQFunctionContextReturnCeed(ctx); + *ceed = NULL; + CeedCall(CeedReferenceCopy(CeedQFunctionContextReturnCeed(ctx), ceed)); return CEED_ERROR_SUCCESS; } @@ -620,11 +620,9 @@ int CeedQFunctionContextReferenceCopy(CeedQFunctionContext ctx, CeedQFunctionCon @ref User **/ int CeedQFunctionContextSetData(CeedQFunctionContext ctx, CeedMemType mem_type, CeedCopyMode copy_mode, size_t size, void *data) { - Ceed ceed; - - CeedCall(CeedQFunctionContextGetCeed(ctx, &ceed)); - CeedCheck(ctx->SetData, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support CeedQFunctionContextSetData"); - CeedCheck(ctx->state % 2 == 0, ceed, 1, "Cannot grant CeedQFunctionContext data access, the access lock is already in use"); + CeedCheck(ctx->SetData, CeedQFunctionContextReturnCeed(ctx), CEED_ERROR_UNSUPPORTED, "Backend does not support CeedQFunctionContextSetData"); + CeedCheck(ctx->state % 2 == 0, CeedQFunctionContextReturnCeed(ctx), 1, + "Cannot grant CeedQFunctionContext data access, the access lock is already in use"); CeedCall(CeedQFunctionContextDestroyData(ctx)); ctx->ctx_size = size; @@ -650,17 +648,16 @@ int CeedQFunctionContextSetData(CeedQFunctionContext ctx, CeedMemType mem_type, int CeedQFunctionContextTakeData(CeedQFunctionContext ctx, CeedMemType mem_type, void *data) { void *temp_data = NULL; bool has_valid_data = true, has_borrowed_data_of_type = true; - Ceed ceed; - CeedCall(CeedQFunctionContextGetCeed(ctx, &ceed)); CeedCall(CeedQFunctionContextHasValidData(ctx, &has_valid_data)); - CeedCheck(has_valid_data, ceed, CEED_ERROR_BACKEND, "CeedQFunctionContext has no valid data to take, must set data"); + CeedCheck(has_valid_data, CeedQFunctionContextReturnCeed(ctx), CEED_ERROR_BACKEND, "CeedQFunctionContext has no valid data to take, must set data"); - CeedCheck(ctx->TakeData, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support CeedQFunctionContextTakeData"); - CeedCheck(ctx->state % 2 == 0, ceed, 1, "Cannot grant CeedQFunctionContext data access, the access lock is already in use"); + CeedCheck(ctx->TakeData, CeedQFunctionContextReturnCeed(ctx), CEED_ERROR_UNSUPPORTED, "Backend does not support CeedQFunctionContextTakeData"); + CeedCheck(ctx->state % 2 == 0, CeedQFunctionContextReturnCeed(ctx), 1, + "Cannot grant CeedQFunctionContext data access, the access lock is already in use"); CeedCall(CeedQFunctionContextHasBorrowedDataOfType(ctx, mem_type, &has_borrowed_data_of_type)); - CeedCheck(has_borrowed_data_of_type, ceed, CEED_ERROR_BACKEND, + CeedCheck(has_borrowed_data_of_type, CeedQFunctionContextReturnCeed(ctx), CEED_ERROR_BACKEND, "CeedQFunctionContext has no borrowed %s data, must set data with CeedQFunctionContextSetData", CeedMemTypes[mem_type]); CeedCall(ctx->TakeData(ctx, mem_type, &temp_data)); @@ -687,15 +684,15 @@ int CeedQFunctionContextTakeData(CeedQFunctionContext ctx, CeedMemType mem_type, **/ int CeedQFunctionContextGetData(CeedQFunctionContext ctx, CeedMemType mem_type, void *data) { bool has_valid_data = true; - Ceed ceed; - CeedCall(CeedQFunctionContextGetCeed(ctx, &ceed)); - CeedCheck(ctx->GetData, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support CeedQFunctionContextGetData"); - CeedCheck(ctx->state % 2 == 0, ceed, 1, "Cannot grant CeedQFunctionContext data access, the access lock is already in use"); - CeedCheck(ctx->num_readers == 0, ceed, 1, "Cannot grant CeedQFunctionContext data access, a process has read access"); + CeedCheck(ctx->GetData, CeedQFunctionContextReturnCeed(ctx), CEED_ERROR_UNSUPPORTED, "Backend does not support CeedQFunctionContextGetData"); + CeedCheck(ctx->state % 2 == 0, CeedQFunctionContextReturnCeed(ctx), 1, + "Cannot grant CeedQFunctionContext data access, the access lock is already in use"); + CeedCheck(ctx->num_readers == 0, CeedQFunctionContextReturnCeed(ctx), 1, + "Cannot grant CeedQFunctionContext data access, a process has read access"); CeedCall(CeedQFunctionContextHasValidData(ctx, &has_valid_data)); - CeedCheck(has_valid_data, ceed, CEED_ERROR_BACKEND, "CeedQFunctionContext has no valid data to get, must set data"); + CeedCheck(has_valid_data, CeedQFunctionContextReturnCeed(ctx), CEED_ERROR_BACKEND, "CeedQFunctionContext has no valid data to get, must set data"); CeedCall(ctx->GetData(ctx, mem_type, data)); ctx->state++; @@ -721,14 +718,14 @@ int CeedQFunctionContextGetData(CeedQFunctionContext ctx, CeedMemType mem_type, **/ int CeedQFunctionContextGetDataRead(CeedQFunctionContext ctx, CeedMemType mem_type, void *data) { bool has_valid_data = true; - Ceed ceed; - CeedCall(CeedQFunctionContextGetCeed(ctx, &ceed)); - CeedCheck(ctx->GetDataRead, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support CeedQFunctionContextGetDataRead"); - CeedCheck(ctx->state % 2 == 0, ceed, 1, "Cannot grant CeedQFunctionContext data access, the access lock is already in use"); + CeedCheck(ctx->GetDataRead, CeedQFunctionContextReturnCeed(ctx), CEED_ERROR_UNSUPPORTED, + "Backend does not support CeedQFunctionContextGetDataRead"); + CeedCheck(ctx->state % 2 == 0, CeedQFunctionContextReturnCeed(ctx), 1, + "Cannot grant CeedQFunctionContext data access, the access lock is already in use"); CeedCall(CeedQFunctionContextHasValidData(ctx, &has_valid_data)); - CeedCheck(has_valid_data, ceed, CEED_ERROR_BACKEND, "CeedQFunctionContext has no valid data to get, must set data"); + CeedCheck(has_valid_data, CeedQFunctionContextReturnCeed(ctx), CEED_ERROR_BACKEND, "CeedQFunctionContext has no valid data to get, must set data"); CeedCall(ctx->GetDataRead(ctx, mem_type, data)); ctx->num_readers++; diff --git a/interface/ceed-vector.c b/interface/ceed-vector.c index b0e277e9d2..d98a037afb 100644 --- a/interface/ceed-vector.c +++ b/interface/ceed-vector.c @@ -210,17 +210,21 @@ int CeedVectorReferenceCopy(CeedVector vec, CeedVector *vec_copy) { @ref User **/ int CeedVectorCopy(CeedVector vec, CeedVector vec_copy) { - Ceed ceed; CeedMemType mem_type, mem_type_copy; CeedScalar *array; - // Get the preferred memory type - CeedCall(CeedVectorGetCeed(vec, &ceed)); - CeedCall(CeedGetPreferredMemType(ceed, &mem_type)); + // Get the preferred memory types + { + Ceed ceed; + + CeedCall(CeedVectorGetCeed(vec, &ceed)); + CeedCall(CeedGetPreferredMemType(ceed, &mem_type)); + CeedCall(CeedDestroy(&ceed)); - // Get the preferred memory type - CeedCall(CeedVectorGetCeed(vec_copy, &ceed)); - CeedCall(CeedGetPreferredMemType(ceed, &mem_type_copy)); + CeedCall(CeedVectorGetCeed(vec_copy, &ceed)); + CeedCall(CeedGetPreferredMemType(ceed, &mem_type_copy)); + CeedCall(CeedDestroy(&ceed)); + } // Check that both have same memory type if (mem_type != mem_type_copy) mem_type = CEED_MEM_HOST; @@ -231,7 +235,7 @@ int CeedVectorCopy(CeedVector vec, CeedVector vec_copy) { CeedCall(CeedVectorGetLength(vec, &length_vec)); CeedCall(CeedVectorGetLength(vec_copy, &length_copy)); - CeedCheck(length_vec == length_copy, ceed, CEED_ERROR_INCOMPATIBLE, "CeedVectors must have the same length to copy"); + CeedCheck(length_vec == length_copy, CeedVectorReturnCeed(vec), CEED_ERROR_INCOMPATIBLE, "CeedVectors must have the same length to copy"); } // Copy the values from vec to vec_copy @@ -304,13 +308,11 @@ int CeedVectorCopyStrided(CeedVector vec, CeedSize start, CeedInt step, CeedVect **/ int CeedVectorSetArray(CeedVector vec, CeedMemType mem_type, CeedCopyMode copy_mode, CeedScalar *array) { CeedSize length; - Ceed ceed; - - CeedCall(CeedVectorGetCeed(vec, &ceed)); - CeedCheck(vec->SetArray, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support VectorSetArray"); - CeedCheck(vec->state % 2 == 0, ceed, CEED_ERROR_ACCESS, "Cannot grant CeedVector array access, the access lock is already in use"); - CeedCheck(vec->num_readers == 0, ceed, CEED_ERROR_ACCESS, "Cannot grant CeedVector array access, a process has read access"); + CeedCheck(vec->SetArray, CeedVectorReturnCeed(vec), CEED_ERROR_UNSUPPORTED, "Backend does not support VectorSetArray"); + CeedCheck(vec->state % 2 == 0, CeedVectorReturnCeed(vec), CEED_ERROR_ACCESS, + "Cannot grant CeedVector array access, the access lock is already in use"); + CeedCheck(vec->num_readers == 0, CeedVectorReturnCeed(vec), CEED_ERROR_ACCESS, "Cannot grant CeedVector array access, a process has read access"); CeedCall(CeedVectorGetLength(vec, &length)); if (length > 0) CeedCall(vec->SetArray(vec, mem_type, copy_mode, array)); @@ -329,11 +331,9 @@ int CeedVectorSetArray(CeedVector vec, CeedMemType mem_type, CeedCopyMode copy_m @ref User **/ int CeedVectorSetValue(CeedVector vec, CeedScalar value) { - Ceed ceed; - - CeedCall(CeedVectorGetCeed(vec, &ceed)); - CeedCheck(vec->state % 2 == 0, ceed, CEED_ERROR_ACCESS, "Cannot grant CeedVector array access, the access lock is already in use"); - CeedCheck(vec->num_readers == 0, ceed, CEED_ERROR_ACCESS, "Cannot grant CeedVector array access, a process has read access"); + CeedCheck(vec->state % 2 == 0, CeedVectorReturnCeed(vec), CEED_ERROR_ACCESS, + "Cannot grant CeedVector array access, the access lock is already in use"); + CeedCheck(vec->num_readers == 0, CeedVectorReturnCeed(vec), CEED_ERROR_ACCESS, "Cannot grant CeedVector array access, a process has read access"); if (vec->SetValue) { CeedCall(vec->SetValue(vec, value)); @@ -365,11 +365,9 @@ int CeedVectorSetValue(CeedVector vec, CeedScalar value) { @ref User **/ int CeedVectorSetValueStrided(CeedVector vec, CeedSize start, CeedInt step, CeedScalar value) { - Ceed ceed; - - CeedCall(CeedVectorGetCeed(vec, &ceed)); - CeedCheck(vec->state % 2 == 0, ceed, CEED_ERROR_ACCESS, "Cannot grant CeedVector array access, the access lock is already in use"); - CeedCheck(vec->num_readers == 0, ceed, CEED_ERROR_ACCESS, "Cannot grant CeedVector array access, a process has read access"); + CeedCheck(vec->state % 2 == 0, CeedVectorReturnCeed(vec), CEED_ERROR_ACCESS, + "Cannot grant CeedVector array access, the access lock is already in use"); + CeedCheck(vec->num_readers == 0, CeedVectorReturnCeed(vec), CEED_ERROR_ACCESS, "Cannot grant CeedVector array access, a process has read access"); if (vec->SetValueStrided) { CeedCall(vec->SetValueStrided(vec, start, step, value)); @@ -438,22 +436,20 @@ int CeedVectorSyncArray(CeedVector vec, CeedMemType mem_type) { int CeedVectorTakeArray(CeedVector vec, CeedMemType mem_type, CeedScalar **array) { CeedSize length; CeedScalar *temp_array = NULL; - Ceed ceed; - CeedCall(CeedVectorGetCeed(vec, &ceed)); - CeedCheck(vec->state % 2 == 0, ceed, CEED_ERROR_ACCESS, "Cannot take CeedVector array, the access lock is already in use"); - CeedCheck(vec->num_readers == 0, ceed, CEED_ERROR_ACCESS, "Cannot take CeedVector array, a process has read access"); + CeedCheck(vec->state % 2 == 0, CeedVectorReturnCeed(vec), CEED_ERROR_ACCESS, "Cannot take CeedVector array, the access lock is already in use"); + CeedCheck(vec->num_readers == 0, CeedVectorReturnCeed(vec), CEED_ERROR_ACCESS, "Cannot take CeedVector array, a process has read access"); CeedCall(CeedVectorGetLength(vec, &length)); if (length > 0) { bool has_borrowed_array_of_type = true, has_valid_array = true; CeedCall(CeedVectorHasBorrowedArrayOfType(vec, mem_type, &has_borrowed_array_of_type)); - CeedCheck(has_borrowed_array_of_type, ceed, CEED_ERROR_BACKEND, "CeedVector has no borrowed %s array, must set array with CeedVectorSetArray", - CeedMemTypes[mem_type]); + CeedCheck(has_borrowed_array_of_type, CeedVectorReturnCeed(vec), CEED_ERROR_BACKEND, + "CeedVector has no borrowed %s array, must set array with CeedVectorSetArray", CeedMemTypes[mem_type]); CeedCall(CeedVectorHasValidArray(vec, &has_valid_array)); - CeedCheck(has_valid_array, ceed, CEED_ERROR_BACKEND, + CeedCheck(has_valid_array, CeedVectorReturnCeed(vec), CEED_ERROR_BACKEND, "CeedVector has no valid data to take, must set data with CeedVectorSetValue or CeedVectorSetArray"); CeedCall(vec->TakeArray(vec, mem_type, &temp_array)); @@ -481,19 +477,18 @@ int CeedVectorTakeArray(CeedVector vec, CeedMemType mem_type, CeedScalar **array **/ int CeedVectorGetArray(CeedVector vec, CeedMemType mem_type, CeedScalar **array) { CeedSize length; - Ceed ceed; - CeedCall(CeedVectorGetCeed(vec, &ceed)); - CeedCheck(vec->GetArray, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support GetArray"); - CeedCheck(vec->state % 2 == 0, ceed, CEED_ERROR_ACCESS, "Cannot grant CeedVector array access, the access lock is already in use"); - CeedCheck(vec->num_readers == 0, ceed, CEED_ERROR_ACCESS, "Cannot grant CeedVector array access, a process has read access"); + CeedCheck(vec->GetArray, CeedVectorReturnCeed(vec), CEED_ERROR_UNSUPPORTED, "Backend does not support GetArray"); + CeedCheck(vec->state % 2 == 0, CeedVectorReturnCeed(vec), CEED_ERROR_ACCESS, + "Cannot grant CeedVector array access, the access lock is already in use"); + CeedCheck(vec->num_readers == 0, CeedVectorReturnCeed(vec), CEED_ERROR_ACCESS, "Cannot grant CeedVector array access, a process has read access"); CeedCall(CeedVectorGetLength(vec, &length)); if (length > 0) { bool has_valid_array = true; CeedCall(CeedVectorHasValidArray(vec, &has_valid_array)); - CeedCheck(has_valid_array, ceed, CEED_ERROR_BACKEND, + CeedCheck(has_valid_array, CeedVectorReturnCeed(vec), CEED_ERROR_BACKEND, "CeedVector has no valid data to read, must set data with CeedVectorSetValue or CeedVectorSetArray"); CeedCall(vec->GetArray(vec, mem_type, array)); @@ -520,18 +515,17 @@ int CeedVectorGetArray(CeedVector vec, CeedMemType mem_type, CeedScalar **array) **/ int CeedVectorGetArrayRead(CeedVector vec, CeedMemType mem_type, const CeedScalar **array) { CeedSize length; - Ceed ceed; - CeedCall(CeedVectorGetCeed(vec, &ceed)); - CeedCheck(vec->GetArrayRead, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support GetArrayRead"); - CeedCheck(vec->state % 2 == 0, ceed, CEED_ERROR_ACCESS, "Cannot grant CeedVector read-only array access, the access lock is already in use"); + CeedCheck(vec->GetArrayRead, CeedVectorReturnCeed(vec), CEED_ERROR_UNSUPPORTED, "Backend does not support GetArrayRead"); + CeedCheck(vec->state % 2 == 0, CeedVectorReturnCeed(vec), CEED_ERROR_ACCESS, + "Cannot grant CeedVector read-only array access, the access lock is already in use"); CeedCall(CeedVectorGetLength(vec, &length)); if (length > 0) { bool has_valid_array = true; CeedCall(CeedVectorHasValidArray(vec, &has_valid_array)); - CeedCheck(has_valid_array, ceed, CEED_ERROR_BACKEND, + CeedCheck(has_valid_array, CeedVectorReturnCeed(vec), CEED_ERROR_BACKEND, "CeedVector has no valid data to read, must set data with CeedVectorSetValue or CeedVectorSetArray"); CeedCall(vec->GetArrayRead(vec, mem_type, array)); @@ -558,12 +552,11 @@ int CeedVectorGetArrayRead(CeedVector vec, CeedMemType mem_type, const CeedScala **/ int CeedVectorGetArrayWrite(CeedVector vec, CeedMemType mem_type, CeedScalar **array) { CeedSize length; - Ceed ceed; - CeedCall(CeedVectorGetCeed(vec, &ceed)); - CeedCheck(vec->GetArrayWrite, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support CeedVectorGetArrayWrite"); - CeedCheck(vec->state % 2 == 0, ceed, CEED_ERROR_ACCESS, "Cannot grant CeedVector array access, the access lock is already in use"); - CeedCheck(vec->num_readers == 0, ceed, CEED_ERROR_ACCESS, "Cannot grant CeedVector array access, a process has read access"); + CeedCheck(vec->GetArrayWrite, CeedVectorReturnCeed(vec), CEED_ERROR_UNSUPPORTED, "Backend does not support CeedVectorGetArrayWrite"); + CeedCheck(vec->state % 2 == 0, CeedVectorReturnCeed(vec), CEED_ERROR_ACCESS, + "Cannot grant CeedVector array access, the access lock is already in use"); + CeedCheck(vec->num_readers == 0, CeedVectorReturnCeed(vec), CEED_ERROR_ACCESS, "Cannot grant CeedVector array access, a process has read access"); CeedCall(CeedVectorGetLength(vec, &length)); if (length > 0) { @@ -730,27 +723,34 @@ int CeedVectorAXPY(CeedVector y, CeedScalar alpha, CeedVector x) { CeedSize length_x, length_y; CeedScalar *y_array = NULL; CeedScalar const *x_array = NULL; - Ceed ceed, ceed_parent_x, ceed_parent_y; - CeedCall(CeedVectorGetCeed(y, &ceed)); CeedCall(CeedVectorGetLength(y, &length_y)); CeedCall(CeedVectorGetLength(x, &length_x)); - CeedCheck(length_x == length_y, ceed, CEED_ERROR_UNSUPPORTED, + CeedCheck(length_x == length_y, CeedVectorReturnCeed(y), CEED_ERROR_UNSUPPORTED, "Cannot add vector of different lengths." " x length: %" CeedSize_FMT " y length: %" CeedSize_FMT, length_x, length_y); - CeedCheck(x != y, ceed, CEED_ERROR_UNSUPPORTED, "Cannot use same vector for x and y in CeedVectorAXPY"); + CeedCheck(x != y, CeedVectorReturnCeed(y), CEED_ERROR_UNSUPPORTED, "Cannot use same vector for x and y in CeedVectorAXPY"); CeedCall(CeedVectorHasValidArray(x, &has_valid_array_x)); - CeedCheck(has_valid_array_x, ceed, CEED_ERROR_BACKEND, + CeedCheck(has_valid_array_x, CeedVectorReturnCeed(y), CEED_ERROR_BACKEND, "CeedVector x has no valid data, must set data with CeedVectorSetValue or CeedVectorSetArray"); CeedCall(CeedVectorHasValidArray(y, &has_valid_array_y)); - CeedCheck(has_valid_array_y, ceed, CEED_ERROR_BACKEND, + CeedCheck(has_valid_array_y, CeedVectorReturnCeed(y), CEED_ERROR_BACKEND, "CeedVector y has no valid data, must set data with CeedVectorSetValue or CeedVectorSetArray"); - CeedCall(CeedGetParent(x->ceed, &ceed_parent_x)); - CeedCall(CeedGetParent(y->ceed, &ceed_parent_y)); - CeedCheck(ceed_parent_x == ceed_parent_y, ceed, CEED_ERROR_INCOMPATIBLE, "Vectors x and y must be created by the same Ceed context"); + { + Ceed ceed_x, ceed_y, ceed_parent_x, ceed_parent_y; + + CeedCall(CeedVectorGetCeed(y, &ceed_y)); + CeedCall(CeedVectorGetCeed(x, &ceed_x)); + CeedCall(CeedGetParent(ceed_x, &ceed_parent_x)); + CeedCall(CeedGetParent(ceed_y, &ceed_parent_y)); + CeedCall(CeedDestroy(&ceed_x)); + CeedCall(CeedDestroy(&ceed_y)); + CeedCheck(ceed_parent_x == ceed_parent_y, CeedVectorReturnCeed(y), CEED_ERROR_INCOMPATIBLE, + "Vectors x and y must be created by the same Ceed context"); + } // Return early for empty vectors if (length_y == 0) return CEED_ERROR_SUCCESS; @@ -792,28 +792,34 @@ int CeedVectorAXPBY(CeedVector y, CeedScalar alpha, CeedScalar beta, CeedVector CeedSize length_x, length_y; CeedScalar *y_array = NULL; CeedScalar const *x_array = NULL; - Ceed ceed, ceed_parent_x, ceed_parent_y; - - CeedCall(CeedVectorGetCeed(y, &ceed)); CeedCall(CeedVectorGetLength(y, &length_y)); CeedCall(CeedVectorGetLength(x, &length_x)); - CeedCheck(length_x == length_y, ceed, CEED_ERROR_UNSUPPORTED, + CeedCheck(length_x == length_y, CeedVectorReturnCeed(y), CEED_ERROR_UNSUPPORTED, "Cannot add vector of different lengths." " x length: %" CeedSize_FMT " y length: %" CeedSize_FMT, length_x, length_y); - CeedCheck(x != y, ceed, CEED_ERROR_UNSUPPORTED, "Cannot use same vector for x and y in CeedVectorAXPBY"); + CeedCheck(x != y, CeedVectorReturnCeed(y), CEED_ERROR_UNSUPPORTED, "Cannot use same vector for x and y in CeedVectorAXPBY"); CeedCall(CeedVectorHasValidArray(x, &has_valid_array_x)); - CeedCheck(has_valid_array_x, ceed, CEED_ERROR_BACKEND, + CeedCheck(has_valid_array_x, CeedVectorReturnCeed(y), CEED_ERROR_BACKEND, "CeedVector x has no valid data, must set data with CeedVectorSetValue or CeedVectorSetArray"); CeedCall(CeedVectorHasValidArray(y, &has_valid_array_y)); - CeedCheck(has_valid_array_y, ceed, CEED_ERROR_BACKEND, + CeedCheck(has_valid_array_y, CeedVectorReturnCeed(y), CEED_ERROR_BACKEND, "CeedVector y has no valid data, must set data with CeedVectorSetValue or CeedVectorSetArray"); - CeedCall(CeedGetParent(x->ceed, &ceed_parent_x)); - CeedCall(CeedGetParent(y->ceed, &ceed_parent_y)); - CeedCheck(ceed_parent_x == ceed_parent_y, ceed, CEED_ERROR_INCOMPATIBLE, "Vectors x and y must be created by the same Ceed context"); + { + Ceed ceed_x, ceed_y, ceed_parent_x, ceed_parent_y; + + CeedCall(CeedVectorGetCeed(y, &ceed_y)); + CeedCall(CeedVectorGetCeed(x, &ceed_x)); + CeedCall(CeedGetParent(ceed_x, &ceed_parent_x)); + CeedCall(CeedGetParent(ceed_y, &ceed_parent_y)); + CeedCall(CeedDestroy(&ceed_x)); + CeedCall(CeedDestroy(&ceed_y)); + CeedCheck(ceed_parent_x == ceed_parent_y, CeedVectorReturnCeed(y), CEED_ERROR_INCOMPATIBLE, + "Vectors x and y must be created by the same Ceed context"); + } // Return early for empty vectors if (length_y == 0) return CEED_ERROR_SUCCESS; @@ -856,28 +862,36 @@ int CeedVectorPointwiseMult(CeedVector w, CeedVector x, CeedVector y) { CeedScalar *w_array = NULL; CeedScalar const *x_array = NULL, *y_array = NULL; CeedSize length_w, length_x, length_y; - Ceed ceed, ceed_parent_w, ceed_parent_x, ceed_parent_y; - CeedCall(CeedVectorGetCeed(w, &ceed)); CeedCall(CeedVectorGetLength(w, &length_w)); CeedCall(CeedVectorGetLength(x, &length_x)); CeedCall(CeedVectorGetLength(y, &length_y)); - CeedCheck(length_x >= length_w && length_y >= length_w, ceed, CEED_ERROR_UNSUPPORTED, + CeedCheck(length_x >= length_w && length_y >= length_w, CeedVectorReturnCeed(w), CEED_ERROR_UNSUPPORTED, "Cannot pointwise multiply vectors of incompatible lengths." " w length: %" CeedSize_FMT " x length: %" CeedSize_FMT " y length: %" CeedSize_FMT, length_w, length_x, length_y); - CeedCall(CeedGetParent(w->ceed, &ceed_parent_w)); - CeedCall(CeedGetParent(x->ceed, &ceed_parent_x)); - CeedCall(CeedGetParent(y->ceed, &ceed_parent_y)); - CeedCheck(ceed_parent_w == ceed_parent_x && ceed_parent_w == ceed_parent_y, ceed, CEED_ERROR_INCOMPATIBLE, - "Vectors w, x, and y must be created by the same Ceed context"); + { + Ceed ceed_w, ceed_x, ceed_y, ceed_parent_w, ceed_parent_x, ceed_parent_y; + + CeedCall(CeedVectorGetCeed(w, &ceed_w)); + CeedCall(CeedVectorGetCeed(x, &ceed_x)); + CeedCall(CeedVectorGetCeed(y, &ceed_y)); + CeedCall(CeedGetParent(ceed_w, &ceed_parent_w)); + CeedCall(CeedGetParent(ceed_x, &ceed_parent_x)); + CeedCall(CeedGetParent(ceed_y, &ceed_parent_y)); + CeedCall(CeedDestroy(&ceed_w)); + CeedCall(CeedDestroy(&ceed_x)); + CeedCall(CeedDestroy(&ceed_y)); + CeedCheck(ceed_parent_w == ceed_parent_x && ceed_parent_w == ceed_parent_y, CeedVectorReturnCeed(w), CEED_ERROR_INCOMPATIBLE, + "Vectors w, x, and y must be created by the same Ceed context"); + } CeedCall(CeedVectorHasValidArray(x, &has_valid_array_x)); - CeedCheck(has_valid_array_x, ceed, CEED_ERROR_BACKEND, + CeedCheck(has_valid_array_x, CeedVectorReturnCeed(w), CEED_ERROR_BACKEND, "CeedVector x has no valid data, must set data with CeedVectorSetValue or CeedVectorSetArray"); CeedCall(CeedVectorHasValidArray(y, &has_valid_array_y)); - CeedCheck(has_valid_array_y, ceed, CEED_ERROR_BACKEND, + CeedCheck(has_valid_array_y, CeedVectorReturnCeed(w), CEED_ERROR_BACKEND, "CeedVector y has no valid data, must set data with CeedVectorSetValue or CeedVectorSetArray"); // Return early for empty vectors @@ -933,15 +947,13 @@ int CeedVectorReciprocal(CeedVector vec) { bool has_valid_array = true; CeedSize length; CeedScalar *array; - Ceed ceed; - CeedCall(CeedVectorGetCeed(vec, &ceed)); CeedCall(CeedVectorHasValidArray(vec, &has_valid_array)); - CeedCheck(has_valid_array, ceed, CEED_ERROR_BACKEND, + CeedCheck(has_valid_array, CeedVectorReturnCeed(vec), CEED_ERROR_BACKEND, "CeedVector has no valid data to compute reciprocal, must set data with CeedVectorSetValue or CeedVectorSetArray"); // Check if vector data set - CeedCheck(vec->state > 0, ceed, CEED_ERROR_INCOMPLETE, "CeedVector must have data set to take reciprocal"); + CeedCheck(vec->state > 0, CeedVectorReturnCeed(vec), CEED_ERROR_INCOMPLETE, "CeedVector must have data set to take reciprocal"); // Return early for empty vector CeedCall(CeedVectorGetLength(vec, &length)); @@ -1032,7 +1044,8 @@ int CeedVectorView(CeedVector vec, const char *fp_fmt, FILE *stream) { @ref Advanced **/ int CeedVectorGetCeed(CeedVector vec, Ceed *ceed) { - *ceed = CeedVectorReturnCeed(vec); + *ceed = NULL; + CeedCall(CeedReferenceCopy(CeedVectorReturnCeed(vec), ceed)); return CEED_ERROR_SUCCESS; }