From 639d67866c5e302f6ea8cecda54d80043c8da3f7 Mon Sep 17 00:00:00 2001 From: Alex Xie Date: Mon, 22 Feb 2021 17:33:05 -0500 Subject: [PATCH] SWDEV-272382 - [OCL][LNX] OCLMemoryInfo[1] subtest of oclruntime is failing 1. Fix the size of the memory when releasing. 2. Make sure we only count the device memory Change-Id: Ib4dcda79f313c4ee9cc1c7bab53f8076bce5f583 --- rocclr/device/rocm/rocmemory.cpp | 17 ++++++++++++++--- rocclr/device/rocm/rocmemory.hpp | 7 +++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/rocclr/device/rocm/rocmemory.cpp b/rocclr/device/rocm/rocmemory.cpp index 2f7c74dcc6..4500c16036 100644 --- a/rocclr/device/rocm/rocmemory.cpp +++ b/rocclr/device/rocm/rocmemory.cpp @@ -1133,13 +1133,18 @@ bool Image::create() { if (originalDeviceMemory_ == nullptr) { originalDeviceMemory_ = dev().hostAlloc(alloc_size, 1, Device::MemorySegment::kNoAtomics); - if ((originalDeviceMemory_ != nullptr) && dev().settings().apuSystem_) { - const_cast(dev()).updateFreeMemory(alloc_size, false); + if (originalDeviceMemory_ != nullptr) { + kind_ = MEMORY_KIND_HOST; + if (dev().settings().apuSystem_) { + const_cast(dev()).updateFreeMemory(alloc_size, false); + } } } else { const_cast(dev()).updateFreeMemory(alloc_size, false); } + //record real size of the buffer so we will release and count it correctly. + deviceImageInfo_.size = alloc_size; deviceMemory_ = reinterpret_cast( amd::alignUp(reinterpret_cast(originalDeviceMemory_), deviceImageInfo_.alignment)); @@ -1316,7 +1321,13 @@ void Image::destroy() { if (originalDeviceMemory_ != nullptr) { dev().memFree(originalDeviceMemory_, deviceImageInfo_.size); - const_cast(dev()).updateFreeMemory(size(), true); + if (kind_ == MEMORY_KIND_HOST) { + if (dev().settings().apuSystem_) { + const_cast(dev()).updateFreeMemory(deviceImageInfo_.size, true); + } + } else { + const_cast(dev()).updateFreeMemory(deviceImageInfo_.size, true); + } } } diff --git a/rocclr/device/rocm/rocmemory.hpp b/rocclr/device/rocm/rocmemory.hpp index 1bb5a1f52a..b1f5345f74 100644 --- a/rocclr/device/rocm/rocmemory.hpp +++ b/rocclr/device/rocm/rocmemory.hpp @@ -33,8 +33,11 @@ class Memory : public device::Memory { public: enum MEMORY_KIND { MEMORY_KIND_NORMAL = 0, - MEMORY_KIND_LOCK, - MEMORY_KIND_GART, + + // The memory is allocated by ROCclr in host memory. This flag is used by + // image class now. It may find more use in buffer class in future + MEMORY_KIND_HOST, + MEMORY_KIND_INTEROP, MEMORY_KIND_PTRGIVEN };