SWDEV-355281 - Add offset calculation

Calculate memory location offset for requested memory

Change-Id: I7919523df1790d9eaad5827ee5bd98e4263a7554


[ROCm/clr commit: 5d83345c20]
This commit is contained in:
German Andryeyev
2023-01-13 17:46:06 -05:00
parent 19c80916fa
commit 8ad3120e25
2 changed files with 6 additions and 2 deletions
+4 -1
View File
@@ -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<uintptr_t>(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 {
+2 -1
View File
@@ -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