From 6811fd90b88eb3a7ff5fba77191bfb94249e57e3 Mon Sep 17 00:00:00 2001 From: "Jayaprakash, Karthik" Date: Tue, 29 Apr 2025 01:49:16 -0400 Subject: [PATCH] SWDEV-522707 - Set phys_mem_handle type to sizeof(size_t) to avoid blocking address range. (#105) --- rocclr/device/rocm/rocmemory.cpp | 4 ++++ rocclr/platform/memory.hpp | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/rocclr/device/rocm/rocmemory.cpp b/rocclr/device/rocm/rocmemory.cpp index bee2110c43..a886446042 100644 --- a/rocclr/device/rocm/rocmemory.cpp +++ b/rocclr/device/rocm/rocmemory.cpp @@ -788,6 +788,10 @@ bool Buffer::create(bool alloc_local) { return false; } + // Update the size of memory object to size of handle, since the setting the size to the actual + // physical memory allocated would block the address range during amd::MemObjMap::FindMemObj() + // lookup. This might cause address range issue in virtual address space. + owner()->UpdatePhysMemSize(); owner()->setSvmPtr(reinterpret_cast(owner()->getUserData().hsa_handle)); return true; diff --git a/rocclr/platform/memory.hpp b/rocclr/platform/memory.hpp index a19e2660c6..cdd3f4ff3a 100644 --- a/rocclr/platform/memory.hpp +++ b/rocclr/platform/memory.hpp @@ -254,7 +254,6 @@ class Memory : public amd::RuntimeObject { //! Initializes the device memory array virtual void initDeviceMemory(); - void setSize(size_t size) { size_ = size; } void setInteropObj(InteropObject* obj) { interopObj_ = obj; } @@ -339,6 +338,13 @@ class Memory : public amd::RuntimeObject { Flags getMemFlags() const { return flags_; } Type getType() const { return type_; } + //! Update phys mem size to the handle, only when the ROCCLR_MEM_PHYSMEM flag is set. + void UpdatePhysMemSize() { + if (flags_ & ROCCLR_MEM_PHYMEM) { + size_ = sizeof(getUserData().hsa_handle); + } + } + const Device* getLastWriter() { return lastWriter_; } const HostMemoryReference* getHostMemRef() const { return &hostMemRef_; } void* getHostMem() const { return hostMemRef_.hostMem(); }