From 7f7eebab6de93b7a359723346b34793a0f18325e Mon Sep 17 00:00:00 2001 From: Harish Kasiviswanathan Date: Fri, 18 Aug 2017 16:50:54 -0400 Subject: [PATCH] Fix hsaKmtQueryPointerInfo for scratch memory Change-Id: I35a0f1a81f8b0ac6e99c2e1572829eb32d3bc95b Signed-off-by: Harish Kasiviswanathan [ROCm/ROCR-Runtime commit: 00250f7686373b12e21acc77ee452a57e4178e76] --- projects/rocr-runtime/src/fmm.c | 46 ++++++++++++++++----------------- projects/rocr-runtime/src/fmm.h | 1 - 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/projects/rocr-runtime/src/fmm.c b/projects/rocr-runtime/src/fmm.c index 381898d35f..11963b66ec 100644 --- a/projects/rocr-runtime/src/fmm.c +++ b/projects/rocr-runtime/src/fmm.c @@ -656,6 +656,23 @@ static manageable_aperture_t *fmm_get_aperture(HsaApertureInfo info) return NULL; } } + +static manageable_aperture_t *fmm_is_scratch_aperture(const void *address) +{ + uint32_t i; + + for (i = 0; i < gpu_mem_count; i++) { + if (gpu_mem[i].gpu_id == NON_VALID_GPU_ID) + continue; + + if ((address >= gpu_mem[i].scratch_physical.base) && + (address <= gpu_mem[i].scratch_physical.limit)) + return &gpu_mem[i].scratch_physical; + + } + return NULL; +} + static manageable_aperture_t *fmm_find_aperture(const void *address, HsaApertureInfo *info) { @@ -666,8 +683,12 @@ static manageable_aperture_t *fmm_find_aperture(const void *address, if (is_dgpu) { if (address >= svm.dgpu_aperture.base && address <= svm.dgpu_aperture.limit) { - aperture = &svm.dgpu_aperture; - _info.type = HSA_APERTURE_DGPU; + + aperture = fmm_is_scratch_aperture(address); + if (!aperture) { + aperture = &svm.dgpu_aperture; + _info.type = HSA_APERTURE_DGPU; + } } else if (address >= svm.dgpu_alt_aperture.base && address <= svm.dgpu_alt_aperture.limit) { aperture = &svm.dgpu_alt_aperture; @@ -753,27 +774,6 @@ err_object_allocation_failed: return NULL; } -bool fmm_is_inside_some_aperture(void *address) -{ - uint32_t i; - - for (i = 0; i < gpu_mem_count; i++) { - if (gpu_mem[i].gpu_id == NON_VALID_GPU_ID) - continue; - if ((address >= gpu_mem[i].lds_aperture.base) && - (address <= gpu_mem[i].lds_aperture.limit)) - return true; - if ((address >= gpu_mem[i].gpuvm_aperture.base) && - (address <= gpu_mem[i].gpuvm_aperture.limit)) - return true; - if ((address >= gpu_mem[i].scratch_aperture.base) && - (address <= gpu_mem[i].scratch_aperture.limit)) - return true; - } - - return false; -} - #ifdef DEBUG_PRINT_APERTURE static void aperture_print(aperture_t *app) { diff --git a/projects/rocr-runtime/src/fmm.h b/projects/rocr-runtime/src/fmm.h index 3bc0fb2040..c874f6fe01 100644 --- a/projects/rocr-runtime/src/fmm.h +++ b/projects/rocr-runtime/src/fmm.h @@ -54,7 +54,6 @@ void *fmm_allocate_doorbell(uint32_t gpu_id, uint64_t MemorySizeInBytes, uint64_ void *fmm_allocate_host(uint32_t node_id, uint64_t MemorySizeInBytes, HsaMemFlags flags); void fmm_print(uint32_t node); -bool fmm_is_inside_some_aperture(void *address); void fmm_release(void *address); int fmm_map_to_gpu(void *address, uint64_t size, uint64_t *gpuvm_address); int fmm_unmap_from_gpu(void *address);