Skip to content

Commit

Permalink
gpu - clean up small leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylt committed Oct 10, 2024
1 parent 1a930f3 commit c16760b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions backends/cuda-ref/ceed-cuda-ref-operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ static int CeedOperatorSetupAtPoints_Cuda(CeedOperator op) {
CeedCallBackend(CeedElemRestrictionGetNumPointsInElement(rstr_points, e, &num_points_elem));
impl->num_points[e] = num_points_elem;
}
CeedCallBackend(CeedElemRestrictionDestroy(&rstr_points));
}
impl->max_num_points = max_num_points;

Expand Down Expand Up @@ -779,6 +780,8 @@ static int CeedOperatorApplyAddAtPoints_Cuda(CeedOperator op, CeedVector in_vec,
CeedCallBackend(CeedOperatorAtPointsGetPoints(op, &rstr_points, &point_coords));
CeedCallBackend(CeedElemRestrictionCreateVector(rstr_points, NULL, &impl->point_coords_elem));
CeedCallBackend(CeedElemRestrictionApply(rstr_points, CEED_NOTRANSPOSE, point_coords, impl->point_coords_elem, request));
CeedCallBackend(CeedVectorDestroy(&point_coords));
CeedCallBackend(CeedElemRestrictionDestroy(&rstr_points));
}

// Process inputs
Expand Down Expand Up @@ -1543,6 +1546,7 @@ static int CeedSingleOperatorAssembleSetup_Cuda(CeedOperator op, CeedInt use_cee
CeedCallBackend(CeedFree(&identity));
}
}
CeedCallBackend(CeedFree(&eval_modes_in));

// Load into B_out, in order that they will be used in eval_modes_out
{
Expand Down Expand Up @@ -1580,6 +1584,7 @@ static int CeedSingleOperatorAssembleSetup_Cuda(CeedOperator op, CeedInt use_cee
CeedCallBackend(CeedFree(&identity));
}
}
CeedCallBackend(CeedFree(&eval_modes_out));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -1743,6 +1748,8 @@ static int CeedOperatorLinearAssembleAddDiagonalAtPoints_Cuda(CeedOperator op, C
CeedCallBackend(CeedOperatorAtPointsGetPoints(op, &rstr_points, &point_coords));
CeedCallBackend(CeedElemRestrictionCreateVector(rstr_points, NULL, &impl->point_coords_elem));
CeedCallBackend(CeedElemRestrictionApply(rstr_points, CEED_NOTRANSPOSE, point_coords, impl->point_coords_elem, request));
CeedCallBackend(CeedVectorDestroy(&point_coords));
CeedCallBackend(CeedElemRestrictionDestroy(&rstr_points));
}

// Process inputs
Expand Down Expand Up @@ -1933,6 +1940,10 @@ static int CeedOperatorLinearAssembleAddDiagonalAtPoints_Cuda(CeedOperator op, C
for (CeedInt i = 0; i < num_input_fields; i++) {
CeedCallBackend(CeedOperatorInputRestore_Cuda(op_input_fields[i], qf_input_fields[i], i, NULL, NULL, true, impl));
}

// Restore work vector
CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec_in));
CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec_out));
return CEED_ERROR_SUCCESS;
}

Expand Down
1 change: 1 addition & 0 deletions backends/cuda-ref/ceed-cuda-ref-qfunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static int CeedQFunctionDestroy_Cuda(CeedQFunction qf) {
CeedQFunction_Cuda *data;

CeedCallBackend(CeedQFunctionGetData(qf, &data));
CeedCallBackend(CeedFree(&data->qfunction_source));
if (data->module) CeedCallCuda(CeedQFunctionReturnCeed(qf), cuModuleUnload(data->module));
CeedCallBackend(CeedFree(&data));
return CEED_ERROR_SUCCESS;
Expand Down
4 changes: 4 additions & 0 deletions backends/cuda-ref/ceed-cuda-ref-restriction.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ static inline int CeedElemRestrictionSetupCompile_Cuda(CeedElemRestriction rstr)
"USE_DETERMINISTIC", is_deterministic ? 1 : 0));
CeedCallBackend(CeedGetKernel_Cuda(ceed, impl->module, "OffsetNoTranspose", &impl->ApplyNoTranspose));
CeedCallBackend(CeedGetKernel_Cuda(ceed, impl->module, "AtPointsTranspose", &impl->ApplyTranspose));
// Cleanup
CeedCallBackend(CeedFree(&offset_kernel_path));
for (CeedInt i = 0; i < num_file_paths; i++) CeedCallBackend(CeedFree(&file_paths[i]));
CeedCallBackend(CeedFree(&file_paths));
} break;
case CEED_RESTRICTION_STANDARD: {
CeedCallBackend(CeedGetJitAbsolutePath(ceed, "ceed/jit-source/cuda/cuda-ref-restriction-offset.h", &restriction_kernel_path));
Expand Down
11 changes: 11 additions & 0 deletions backends/hip-ref/ceed-hip-ref-operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ static int CeedOperatorSetupAtPoints_Hip(CeedOperator op) {
CeedCallBackend(CeedElemRestrictionGetNumPointsInElement(rstr_points, e, &num_points_elem));
impl->num_points[e] = num_points_elem;
}
CeedCallBackend(CeedElemRestrictionDestroy(&rstr_points));
}
impl->max_num_points = max_num_points;

Expand Down Expand Up @@ -777,6 +778,8 @@ static int CeedOperatorApplyAddAtPoints_Hip(CeedOperator op, CeedVector in_vec,
CeedCallBackend(CeedOperatorAtPointsGetPoints(op, &rstr_points, &point_coords));
CeedCallBackend(CeedElemRestrictionCreateVector(rstr_points, NULL, &impl->point_coords_elem));
CeedCallBackend(CeedElemRestrictionApply(rstr_points, CEED_NOTRANSPOSE, point_coords, impl->point_coords_elem, request));
CeedCallBackend(CeedVectorDestroy(&point_coords));
CeedCallBackend(CeedElemRestrictionDestroy(&rstr_points));
}

// Process inputs
Expand Down Expand Up @@ -1540,6 +1543,7 @@ static int CeedSingleOperatorAssembleSetup_Hip(CeedOperator op, CeedInt use_ceed
CeedCallBackend(CeedFree(&identity));
}
}
CeedCallBackend(CeedFree(&eval_modes_in));

// Load into B_out, in order that they will be used in eval_modes_out
{
Expand Down Expand Up @@ -1577,6 +1581,7 @@ static int CeedSingleOperatorAssembleSetup_Hip(CeedOperator op, CeedInt use_ceed
CeedCallBackend(CeedFree(&identity));
}
}
CeedCallBackend(CeedFree(&eval_modes_out));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -1740,6 +1745,8 @@ static int CeedOperatorLinearAssembleAddDiagonalAtPoints_Hip(CeedOperator op, Ce
CeedCallBackend(CeedOperatorAtPointsGetPoints(op, &rstr_points, &point_coords));
CeedCallBackend(CeedElemRestrictionCreateVector(rstr_points, NULL, &impl->point_coords_elem));
CeedCallBackend(CeedElemRestrictionApply(rstr_points, CEED_NOTRANSPOSE, point_coords, impl->point_coords_elem, request));
CeedCallBackend(CeedVectorDestroy(&point_coords));
CeedCallBackend(CeedElemRestrictionDestroy(&rstr_points));
}

// Process inputs
Expand Down Expand Up @@ -1930,6 +1937,10 @@ static int CeedOperatorLinearAssembleAddDiagonalAtPoints_Hip(CeedOperator op, Ce
for (CeedInt i = 0; i < num_input_fields; i++) {
CeedCallBackend(CeedOperatorInputRestore_Hip(op_input_fields[i], qf_input_fields[i], i, NULL, NULL, true, impl));
}

// Restore work vector
CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec_in));
CeedCallBackend(CeedRestoreWorkVector(ceed, &active_e_vec_out));
return CEED_ERROR_SUCCESS;
}

Expand Down
1 change: 1 addition & 0 deletions backends/hip-ref/ceed-hip-ref-qfunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static int CeedQFunctionDestroy_Hip(CeedQFunction qf) {
CeedQFunction_Hip *data;

CeedCallBackend(CeedQFunctionGetData(qf, &data));
CeedCallBackend(CeedFree(&data->qfunction_source));
if (data->module) CeedCallHip(CeedQFunctionReturnCeed(qf), hipModuleUnload(data->module));
CeedCallBackend(CeedFree(&data));
return CEED_ERROR_SUCCESS;
Expand Down
4 changes: 4 additions & 0 deletions backends/hip-ref/ceed-hip-ref-restriction.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ static inline int CeedElemRestrictionSetupCompile_Hip(CeedElemRestriction rstr)
"USE_DETERMINISTIC", is_deterministic ? 1 : 0));
CeedCallBackend(CeedGetKernel_Hip(ceed, impl->module, "OffsetNoTranspose", &impl->ApplyNoTranspose));
CeedCallBackend(CeedGetKernel_Hip(ceed, impl->module, "AtPointsTranspose", &impl->ApplyTranspose));
// Cleanup
CeedCallBackend(CeedFree(&offset_kernel_path));
for (CeedInt i = 0; i < num_file_paths; i++) CeedCallBackend(CeedFree(&file_paths[i]));
CeedCallBackend(CeedFree(&file_paths));
} break;
case CEED_RESTRICTION_STANDARD: {
CeedCallBackend(CeedGetJitAbsolutePath(ceed, "ceed/jit-source/hip/hip-ref-restriction-offset.h", &restriction_kernel_path));
Expand Down

0 comments on commit c16760b

Please sign in to comment.