Skip to content

Commit

Permalink
qf - require CeedOpGetQF to be Destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylt committed Oct 23, 2024
1 parent 12cb84f commit 6a77f11
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 61 deletions.
21 changes: 12 additions & 9 deletions backends/blocked/ceed-blocked-operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ static int CeedOperatorSetup_Blocked(CeedOperator op) {
}

CeedCallBackend(CeedOperatorSetSetupDone(op));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -438,23 +439,23 @@ static int CeedOperatorApplyAdd_Blocked(CeedOperator op, CeedVector in_vec, Ceed
CeedOperatorField *op_input_fields, *op_output_fields;
CeedOperator_Blocked *impl;

CeedCallBackend(CeedOperatorGetData(op, &impl));
CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem));
CeedCallBackend(CeedOperatorGetNumQuadraturePoints(op, &Q));
CeedCallBackend(CeedOperatorGetQFunction(op, &qf));
CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields));
CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields));
const CeedInt num_blocks = (num_elem / block_size) + !!(num_elem % block_size);

// Setup
CeedCallBackend(CeedOperatorSetup_Blocked(op));

CeedCallBackend(CeedOperatorGetData(op, &impl));

// Restriction only operator
if (impl->is_identity_rstr_op) {
CeedCallBackend(CeedElemRestrictionApply(impl->block_rstr[0], CEED_NOTRANSPOSE, in_vec, impl->e_vecs_full[0], request));
CeedCallBackend(CeedElemRestrictionApply(impl->block_rstr[1], CEED_TRANSPOSE, impl->e_vecs_full[0], out_vec, request));
return CEED_ERROR_SUCCESS;
}
CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem));
CeedCallBackend(CeedOperatorGetNumQuadraturePoints(op, &Q));
CeedCallBackend(CeedOperatorGetQFunction(op, &qf));
CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields));
CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields));
const CeedInt num_blocks = (num_elem / block_size) + !!(num_elem % block_size);

// Input Evecs and Restriction
CeedCallBackend(CeedOperatorSetupInputs_Blocked(num_input_fields, qf_input_fields, op_input_fields, in_vec, false, e_data_full, impl, request));
Expand Down Expand Up @@ -514,6 +515,7 @@ static int CeedOperatorApplyAdd_Blocked(CeedOperator op, CeedVector in_vec, Ceed

// Restore input arrays
CeedCallBackend(CeedOperatorRestoreInputs_Blocked(num_input_fields, qf_input_fields, op_input_fields, false, e_data_full, impl));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -708,10 +710,11 @@ 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));
CeedCallBackend(CeedDestroy(&ceed));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down
1 change: 1 addition & 0 deletions backends/cuda-gen/ceed-cuda-gen-operator-build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ extern "C" int CeedOperatorBuildKernel_Cuda_gen(CeedOperator op) {
CeedCallBackend(CeedGetKernel_Cuda(ceed, data->module, operator_name.c_str(), &data->op));
CeedCallBackend(CeedOperatorSetSetupDone(op));
CeedCallBackend(CeedDestroy(&ceed));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down
22 changes: 11 additions & 11 deletions backends/cuda-gen/ceed-cuda-gen-operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,6 @@ static int CeedOperatorApplyAdd_Cuda_gen(CeedOperator op, CeedVector input_vec,
CeedOperatorField *op_input_fields, *op_output_fields;
CeedOperator_Cuda_gen *data;

CeedCallBackend(CeedOperatorGetCeed(op, &ceed));
CeedCallBackend(CeedGetData(ceed, &cuda_data));
CeedCallBackend(CeedOperatorGetData(op, &data));
CeedCallBackend(CeedOperatorGetQFunction(op, &qf));
CeedCallBackend(CeedQFunctionGetData(qf, &qf_data));
CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem));
CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields));
CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields));

// Check for tensor-product bases
{
bool has_tensor_bases;
Expand All @@ -121,14 +112,22 @@ static int CeedOperatorApplyAdd_Cuda_gen(CeedOperator op, CeedVector input_vec,
if (!has_tensor_bases) {
CeedOperator op_fallback;

CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "Falling back to /gpu/cuda/ref CeedOperator due to non-tensor bases");
CeedCallBackend(CeedDestroy(&ceed));
CeedDebug256(CeedOperatorReturnCeed(op), CEED_DEBUG_COLOR_SUCCESS, "Falling back to /gpu/cuda/ref CeedOperator due to non-tensor bases");
CeedCallBackend(CeedOperatorGetFallback(op, &op_fallback));
CeedCallBackend(CeedOperatorApplyAdd(op_fallback, input_vec, output_vec, request));
return CEED_ERROR_SUCCESS;
}
}

CeedCallBackend(CeedOperatorGetCeed(op, &ceed));
CeedCallBackend(CeedGetData(ceed, &cuda_data));
CeedCallBackend(CeedOperatorGetData(op, &data));
CeedCallBackend(CeedOperatorGetQFunction(op, &qf));
CeedCallBackend(CeedQFunctionGetData(qf, &qf_data));
CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem));
CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields));
CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields));

// Creation of the operator
CeedCallBackend(CeedOperatorBuildKernel_Cuda_gen(op));

Expand Down Expand Up @@ -253,6 +252,7 @@ static int CeedOperatorApplyAdd_Cuda_gen(CeedOperator op, CeedVector input_vec,
// Restore context data
CeedCallBackend(CeedQFunctionRestoreInnerContextData(qf, &qf_data->d_c));
CeedCallBackend(CeedDestroy(&ceed));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down
11 changes: 10 additions & 1 deletion backends/cuda-ref/ceed-cuda-ref-operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ static int CeedOperatorSetup_Cuda(CeedOperator op) {
}
}
CeedCallBackend(CeedOperatorSetSetupDone(op));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -601,6 +602,7 @@ static int CeedOperatorApplyAdd_Cuda(CeedOperator op, CeedVector in_vec, CeedVec
// Return work vector
CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec));
CeedCallBackend(CeedDestroy(&ceed));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -739,6 +741,7 @@ static int CeedOperatorSetupAtPoints_Cuda(CeedOperator op) {
}
}
CeedCallBackend(CeedOperatorSetSetupDone(op));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -927,6 +930,7 @@ static int CeedOperatorApplyAddAtPoints_Cuda(CeedOperator op, CeedVector in_vec,
// Restore work vector
CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec));
CeedCallBackend(CeedDestroy(&ceed));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -1068,9 +1072,10 @@ static inline int CeedOperatorLinearAssembleQFunctionCore_Cuda(CeedOperator op,
}

// Restore output
CeedCallBackend(CeedVectorRestoreArray(*assembled, &assembled_array));
CeedCallBackend(CeedDestroy(&ceed));
CeedCallBackend(CeedDestroy(&ceed_parent));
CeedCallBackend(CeedVectorRestoreArray(*assembled, &assembled_array));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -1274,6 +1279,7 @@ static inline int CeedOperatorAssembleDiagonalSetup_Cuda(CeedOperator op) {
CeedCallBackend(CeedDestroy(&ceed));
CeedCallBackend(CeedBasisDestroy(&basis_in));
CeedCallBackend(CeedBasisDestroy(&basis_out));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -1360,6 +1366,7 @@ static inline int CeedOperatorAssembleDiagonalSetupCompile_Cuda(CeedOperator op,
CeedCallBackend(CeedDestroy(&ceed));
CeedCallBackend(CeedBasisDestroy(&basis_in));
CeedCallBackend(CeedBasisDestroy(&basis_out));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -1664,6 +1671,7 @@ static int CeedSingleOperatorAssembleSetup_Cuda(CeedOperator op, CeedInt use_cee
CeedCallBackend(CeedElemRestrictionDestroy(&rstr_out));
CeedCallBackend(CeedBasisDestroy(&basis_in));
CeedCallBackend(CeedBasisDestroy(&basis_out));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -2041,6 +2049,7 @@ static int CeedOperatorLinearAssembleAddDiagonalAtPoints_Cuda(CeedOperator op, C
CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec_in));
CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec_out));
CeedCallBackend(CeedDestroy(&ceed));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down
1 change: 1 addition & 0 deletions backends/hip-gen/ceed-hip-gen-operator-build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ extern "C" int CeedOperatorBuildKernel_Hip_gen(CeedOperator op) {
CeedCallBackend(CeedGetKernel_Hip(ceed, data->module, operator_name.c_str(), &data->op));
CeedCallBackend(CeedOperatorSetSetupDone(op));
CeedCallBackend(CeedDestroy(&ceed));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down
20 changes: 10 additions & 10 deletions backends/hip-gen/ceed-hip-gen-operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ static int CeedOperatorApplyAdd_Hip_gen(CeedOperator op, CeedVector input_vec, C
CeedOperatorField *op_input_fields, *op_output_fields;
CeedOperator_Hip_gen *data;

CeedCallBackend(CeedOperatorGetCeed(op, &ceed));
CeedCallBackend(CeedOperatorGetData(op, &data));
CeedCallBackend(CeedOperatorGetQFunction(op, &qf));
CeedCallBackend(CeedQFunctionGetData(qf, &qf_data));
CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem));
CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields));
CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields));

// Check for tensor-product bases
{
bool has_tensor_bases;
Expand All @@ -57,14 +49,21 @@ static int CeedOperatorApplyAdd_Hip_gen(CeedOperator op, CeedVector input_vec, C
if (!has_tensor_bases) {
CeedOperator op_fallback;

CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "Falling back to /gpu/hip/ref CeedOperator due to non-tensor bases");
CeedCallBackend(CeedDestroy(&ceed));
CeedDebug256(CeedOperatorReturnCeed(op), CEED_DEBUG_COLOR_SUCCESS, "Falling back to /gpu/hip/ref CeedOperator due to non-tensor bases");
CeedCallBackend(CeedOperatorGetFallback(op, &op_fallback));
CeedCallBackend(CeedOperatorApplyAdd(op_fallback, input_vec, output_vec, request));
return CEED_ERROR_SUCCESS;
}
}

CeedCallBackend(CeedOperatorGetCeed(op, &ceed));
CeedCallBackend(CeedOperatorGetData(op, &data));
CeedCallBackend(CeedOperatorGetQFunction(op, &qf));
CeedCallBackend(CeedQFunctionGetData(qf, &qf_data));
CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem));
CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields));
CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields));

// Creation of the operator
CeedCallBackend(CeedOperatorBuildKernel_Hip_gen(op));

Expand Down Expand Up @@ -179,6 +178,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));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down
11 changes: 10 additions & 1 deletion backends/hip-ref/ceed-hip-ref-operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ static int CeedOperatorSetup_Hip(CeedOperator op) {
}
}
CeedCallBackend(CeedOperatorSetSetupDone(op));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -599,6 +600,7 @@ static int CeedOperatorApplyAdd_Hip(CeedOperator op, CeedVector in_vec, CeedVect
// Return work vector
CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec));
CeedCallBackend(CeedDestroy(&ceed));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -737,6 +739,7 @@ static int CeedOperatorSetupAtPoints_Hip(CeedOperator op) {
}
}
CeedCallBackend(CeedOperatorSetSetupDone(op));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -924,6 +927,7 @@ static int CeedOperatorApplyAddAtPoints_Hip(CeedOperator op, CeedVector in_vec,
// Restore work vector
CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec));
CeedCallBackend(CeedDestroy(&ceed));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -1065,9 +1069,10 @@ static inline int CeedOperatorLinearAssembleQFunctionCore_Hip(CeedOperator op, b
}

// Restore output
CeedCallBackend(CeedVectorRestoreArray(*assembled, &assembled_array));
CeedCallBackend(CeedDestroy(&ceed));
CeedCallBackend(CeedDestroy(&ceed_parent));
CeedCallBackend(CeedVectorRestoreArray(*assembled, &assembled_array));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -1271,6 +1276,7 @@ static inline int CeedOperatorAssembleDiagonalSetup_Hip(CeedOperator op) {
CeedCallBackend(CeedDestroy(&ceed));
CeedCallBackend(CeedBasisDestroy(&basis_in));
CeedCallBackend(CeedBasisDestroy(&basis_out));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -1357,6 +1363,7 @@ static inline int CeedOperatorAssembleDiagonalSetupCompile_Hip(CeedOperator op,
CeedCallBackend(CeedDestroy(&ceed));
CeedCallBackend(CeedBasisDestroy(&basis_in));
CeedCallBackend(CeedBasisDestroy(&basis_out));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -1661,6 +1668,7 @@ static int CeedSingleOperatorAssembleSetup_Hip(CeedOperator op, CeedInt use_ceed
CeedCallBackend(CeedElemRestrictionDestroy(&rstr_out));
CeedCallBackend(CeedBasisDestroy(&basis_in));
CeedCallBackend(CeedBasisDestroy(&basis_out));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -2038,6 +2046,7 @@ static int CeedOperatorLinearAssembleAddDiagonalAtPoints_Hip(CeedOperator op, Ce
CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec_in));
CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec_out));
CeedCallBackend(CeedDestroy(&ceed));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down
18 changes: 11 additions & 7 deletions backends/opt/ceed-opt-operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ static int CeedOperatorSetup_Opt(CeedOperator op) {
}

CeedCallBackend(CeedOperatorSetSetupDone(op));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -449,21 +450,17 @@ static int CeedOperatorApplyAdd_Opt(CeedOperator op, CeedVector in_vec, CeedVect
CeedOperatorField *op_input_fields, *op_output_fields;
CeedOperator_Opt *impl;

// Setup
CeedCallBackend(CeedOperatorSetup_Opt(op));

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));
CeedCallBackend(CeedOperatorGetQFunction(op, &qf));
CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields));
CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields));
const CeedInt block_size = ceed_impl->block_size;
const CeedInt num_blocks = (num_elem / block_size) + !!(num_elem % block_size);

// Setup
CeedCallBackend(CeedOperatorSetup_Opt(op));

// Restriction only operator
if (impl->is_identity_rstr_op) {
for (CeedInt b = 0; b < num_blocks; b++) {
Expand All @@ -473,6 +470,11 @@ static int CeedOperatorApplyAdd_Opt(CeedOperator op, CeedVector in_vec, CeedVect
return CEED_ERROR_SUCCESS;
}

CeedCallBackend(CeedOperatorGetNumQuadraturePoints(op, &Q));
CeedCallBackend(CeedOperatorGetQFunction(op, &qf));
CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields));
CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields));

// Input Evecs and Restriction
CeedCallBackend(CeedOperatorSetupInputs_Opt(num_input_fields, qf_input_fields, op_input_fields, in_vec, e_data, impl, request));

Expand Down Expand Up @@ -506,6 +508,7 @@ static int CeedOperatorApplyAdd_Opt(CeedOperator op, CeedVector in_vec, CeedVect

// Restore input arrays
CeedCallBackend(CeedOperatorRestoreInputs_Opt(num_input_fields, qf_input_fields, op_input_fields, e_data, impl));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -718,6 +721,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));
CeedCallBackend(CeedQFunctionDestroy(&qf));
return CEED_ERROR_SUCCESS;
}

Expand Down
Loading

0 comments on commit 6a77f11

Please sign in to comment.