From 4b3a5b615127ad145e9de5b65f56c2bcbc0118b2 Mon Sep 17 00:00:00 2001 From: Sean Keely Date: Wed, 29 Apr 2020 14:52:24 -0500 Subject: [PATCH] Fix pointer info block base address fetch. Thunk may report nullptr for host base if the host does not have access. Use agent base in this case. Change-Id: I44883d35a3fff0941b1e3037d16b059591a6c511 [ROCm/ROCR-Runtime commit: 397608e2c02a822da8f1ebb5f3703630d5fcde10] --- .../runtime/hsa-runtime/core/runtime/runtime.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp index dd6a15ca28..2debd164ac 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -790,11 +790,14 @@ hsa_status_t Runtime::PtrInfo(void* ptr, hsa_amd_pointer_info_t* info, void* (*a retInfo.sizeInBytes = thunkInfo.SizeInBytes; retInfo.userData = thunkInfo.UserData; if (block_info != nullptr) { - // The only time host and agent ptr may be different is when the memory is lock memory (malloc - // memory pinned for GPU access). In this case there can not be any suballocation so - // block_info is redundant and unused. Host address is returned since host address is used to - // manipulate lock memory. This protects future use of block_info with lock memory. - block_info->base = retInfo.hostBaseAddress; + // Block_info reports the thunk allocation from which we may have suballocated. + // For locked memory we want to return the host address since hostBaseAddress is used to + // manipulate locked memory and it is possible that hostBaseAddress is different from + // agentBaseAddress. + // For device memory, hostBaseAddress is either equal to agentBaseAddress or is NULL when the + // CPU does not have access. + assert((retInfo.hostBaseAddress || retInfo.agentBaseAddress) && "Thunk pointer info returned no base address."); + block_info->base = (retInfo.hostBaseAddress ? retInfo.hostBaseAddress : retInfo.agentBaseAddress); block_info->length = retInfo.sizeInBytes; } if (retInfo.type == HSA_EXT_POINTER_TYPE_HSA) {