From 8ad3120e254c3fa98a422ac2e17acbbfc742403f Mon Sep 17 00:00:00 2001 From: German Andryeyev Date: Fri, 13 Jan 2023 17:46:06 -0500 Subject: [PATCH] SWDEV-355281 - Add offset calculation Calculate memory location offset for requested memory Change-Id: I7919523df1790d9eaad5827ee5bd98e4263a7554 [ROCm/clr commit: 5d83345c20a0cb19523864fe513f70eccde622bd] --- projects/clr/rocclr/device/device.cpp | 5 ++++- projects/clr/rocclr/device/device.hpp | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/projects/clr/rocclr/device/device.cpp b/projects/clr/rocclr/device/device.cpp index 3ca1014b60..2709febd8b 100644 --- a/projects/clr/rocclr/device/device.cpp +++ b/projects/clr/rocclr/device/device.cpp @@ -296,7 +296,7 @@ void MemObjMap::RemoveMemObj(const void* k) { } } -amd::Memory* MemObjMap::FindMemObj(const void* k) { +amd::Memory* MemObjMap::FindMemObj(const void* k, size_t* offset) { amd::ScopedLock lock(AllocatedLock_); uintptr_t key = reinterpret_cast(k); auto it = MemObjMap_.upper_bound(key); @@ -307,6 +307,9 @@ amd::Memory* MemObjMap::FindMemObj(const void* k) { --it; amd::Memory* mem = it->second; if (key >= it->first && key < (it->first + mem->getSize())) { + if (offset != nullptr) { + *offset = key - it->first; + } // the k is in the range return mem; } else { diff --git a/projects/clr/rocclr/device/device.hpp b/projects/clr/rocclr/device/device.hpp index 129a237720..fe276be2f4 100644 --- a/projects/clr/rocclr/device/device.hpp +++ b/projects/clr/rocclr/device/device.hpp @@ -1294,7 +1294,8 @@ class MemObjMap : public AllStatic { amd::Memory* v); //!< add the host mem pointer and buffer in the container static void RemoveMemObj(const void* k); //!< Remove an entry of mem object from the container static amd::Memory* FindMemObj( - const void* k); //!< find the mem object based on the input pointer + const void* k, //!< find the mem object based on the input pointer + size_t* offset = nullptr); //!< Offset in the memory location static void UpdateAccess(amd::Device *peerDev); static void Purge(amd::Device* dev); //!< Purge all user allocated memories on the given device