diff --git a/projects/rocr-runtime/src/fmm.c b/projects/rocr-runtime/src/fmm.c index af4840268d..cf1be8ac45 100644 --- a/projects/rocr-runtime/src/fmm.c +++ b/projects/rocr-runtime/src/fmm.c @@ -139,6 +139,7 @@ static void __fmm_release(void *address, static int _fmm_unmap_from_gpu_scratch(uint32_t gpu_id, manageble_aperture_t *aperture, void *address); +void __attribute__ ((destructor)) fmm_release_global_resources(void); static vm_area_t *vm_create_and_init_area(void *start, void *end) { @@ -1544,3 +1545,16 @@ bool fmm_get_handle(void *address, uint64_t *handle) return found; } + +void fmm_release_global_resources(void) +{ + uint64_t len; + + if (dgpu_shared_aperture_base) { + len = (uint64_t)dgpu_shared_aperture_limit + - (uint64_t)dgpu_shared_aperture_base + 1; + munmap(dgpu_shared_aperture_base, len); + } + dgpu_shared_aperture_base = NULL; + dgpu_shared_aperture_limit = NULL; +} diff --git a/projects/rocr-runtime/src/perfctr.c b/projects/rocr-runtime/src/perfctr.c index 64ab168fda..403ff4ad3e 100644 --- a/projects/rocr-runtime/src/perfctr.c +++ b/projects/rocr-runtime/src/perfctr.c @@ -48,6 +48,8 @@ extern int amd_hsa_thunk_lock_fd; static HsaCounterProperties *counter_props[MAX_NODES] = {NULL}; +void __attribute__ ((destructor)) perfctr_release_global_resources(void); + static int blockid2uuid(enum perf_block_id block_id, HSA_UUID *uuid) { int rc = 0; @@ -368,3 +370,14 @@ hsaKmtPmcStopTrace( return HSAKMT_STATUS_SUCCESS; } + +void perfctr_release_global_resources(void) +{ + int i; + + for (i=0; i