diff --git a/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp b/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp index 0961dcb6bb..013bb0a331 100644 --- a/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp @@ -600,7 +600,7 @@ hsa_status_t MemoryRegion::AssignAgent(void* ptr, size_t size, } void* MemoryRegion::BlockAllocator::alloc(size_t request_size, size_t& allocated_size) const { - assert(request_size < block_size() && "BlockAllocator alloc request exceeds block size."); + assert(request_size <= block_size() && "BlockAllocator alloc request exceeds block size."); void* ret; hsa_status_t err = region_.Allocate( diff --git a/runtime/hsa-runtime/core/runtime/runtime.cpp b/runtime/hsa-runtime/core/runtime/runtime.cpp index 9f3bebca37..9be9a67efe 100644 --- a/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -722,6 +722,10 @@ 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->length = retInfo.sizeInBytes; } @@ -731,8 +735,11 @@ hsa_status_t Runtime::PtrInfo(void* ptr, hsa_amd_pointer_info_t* info, void* (*a fragment--; if ((fragment->first <= ptr) && (ptr < reinterpret_cast(fragment->first) + fragment->second.size)) { - retInfo.hostBaseAddress = const_cast(fragment->first); - retInfo.agentBaseAddress = retInfo.hostBaseAddress; + // agent and host address must match here. Only lock memory is allowed to have differing + // addresses but lock memory has type HSA_EXT_POINTER_TYPE_LOCKED and cannot be + // suballocated. + retInfo.agentBaseAddress = const_cast(fragment->first); + retInfo.hostBaseAddress = retInfo.agentBaseAddress; retInfo.sizeInBytes = fragment->second.size; retInfo.userData = fragment->second.user_ptr; } diff --git a/runtime/hsa-runtime/core/util/simple_heap.h b/runtime/hsa-runtime/core/util/simple_heap.h index 76df7ad73d..361f71389a 100644 --- a/runtime/hsa-runtime/core/util/simple_heap.h +++ b/runtime/hsa-runtime/core/util/simple_heap.h @@ -239,6 +239,7 @@ template class SimpleHeap { for (const auto& block : block_cache_) block_allocator_.free(reinterpret_cast(block.base_ptr_), block.length_); block_cache_.clear(); + cache_size_ = 0; } size_t max_alloc() const { return block_allocator_.block_size(); }