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 };