Skip to content

Commit

Permalink
Merge pull request #176 from taiga-project/fix-175
Browse files Browse the repository at this point in the history
Fix memory deallocation
  • Loading branch information
matyasaradi authored Jan 14, 2024
2 parents d57854c + 9488149 commit 361f8c3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
8 changes: 7 additions & 1 deletion include/utils/free.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
#define DEVICE 2
#define FREE(where, p) { \
if (where == HOST) {free(p);} \
else {CHECK_ERROR(cudaFree(p));} \
else if (where == SHARED) {CHECK_ERROR(cudaFree(p));} \
}
#define FREE_SHARED(where, p) { \
if (where == SHARED) {CHECK_ERROR(cudaFree(p));} \
}
#define FREE_SHARED_IF(where, p) { \
if (where == SHARED & p == NULL) {CHECK_ERROR(cudaFree(p));} \
}
#define FREE_MAIN(where, p) { \
if (where == DEVICE) {CHECK_ERROR(cudaFree(p));} \
Expand Down
29 changes: 14 additions & 15 deletions src/utils/free.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ void free_taiga(TaigaGlobals *host_global, TaigaGlobals *shared_global, TaigaGlo
DetectorProp *shared_detector, DetectorProp *device_detector,
ShotProp *shot, BeamProp *beam, RunProp *run,
double *host_service_array, double *device_service_array) {
if (run->debug == 1) printf("Free global.\n");
free_global(host_global, HOST);
free_global(shared_global, SHARED);
free_global(device_global, DEVICE);
if (run->debug == 1) printf("Free common.\n");
free_common(host_common, HOST);
free_common(shared_common, SHARED);
free_common(device_common, DEVICE);
if (run->debug == 1) printf("Free detector.\n");
free_detector(shared_detector, SHARED);
free_detector(device_detector, DEVICE);
free(shot);
free(beam);
free(run);
if (run->debug == 1) printf("Free service array.\n");
free(host_service_array);
CHECK_ERROR(cudaFree(device_service_array));
}


void free_detector(DetectorProp *detector, int where){
FREE(where, detector->counter);
FREE(where, detector->xgrid);
Expand Down Expand Up @@ -53,17 +53,16 @@ void free_common(TaigaCommons *common, int where){
FREE(where, common->grid_size);
FREE(where, common->spline_rgrid);
FREE(where, common->spline_zgrid);
FREE(where, common->brad);
FREE(where, common->bz);
FREE(where, common->btor);
FREE(where, common->erad);
FREE(where, common->ez);
FREE(where, common->etor);
FREE(where, common->psi_n);
FREE_SHARED(where, common->brad);
FREE_SHARED(where, common->bz);
FREE_SHARED(where, common->btor);
FREE_SHARED_IF(where, common->erad);
FREE_SHARED_IF(where, common->ez);
FREE_SHARED_IF(where, common->etor);
FREE_SHARED_IF(where, common->psi_n);
FREE(where, common->detector_geometry);
FREE(where, common->ts_psi);
FREE(where, common->ts_density);
FREE(where, common->ts_temperature);
FREE_SHARED(where, common->ts_psi);
FREE_SHARED(where, common->ts_density);
FREE_SHARED(where, common->ts_temperature);
FREE_MAIN(where, common);
}

0 comments on commit 361f8c3

Please sign in to comment.