Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit ad79386

Browse files
committed
set free mem to zero avoding underflow
Change-Id: I964b41695fb41712624146c5959a35b37eacf52d
1 parent 3af67a3 commit ad79386

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

device/rocm/rocdevice.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,16 @@ void Device::updateFreeMemory(size_t size, bool free) {
18181818
freeMem_ += size;
18191819
}
18201820
else {
1821+
if (size > freeMem_) {
1822+
// To avoid underflow of the freeMem_
1823+
// This can happen if the free mem tracked is inaccurate, as some allocations can happen
1824+
// directly via ROCr
1825+
ClPrint(amd::LOG_ERROR, amd::LOG_ALWAYS,
1826+
"Free memory set to zero on device 0x%lx, requested size = 0x%x, freeMem_ = 0x%x",
1827+
this, size, freeMem_.load());
1828+
freeMem_ = 0;
1829+
return;
1830+
}
18211831
freeMem_ -= size;
18221832
}
18231833
ClPrint(amd::LOG_INFO, amd::LOG_MEM, "device=0x%lx, freeMem_ = 0x%x", this, freeMem_.load());

0 commit comments

Comments
 (0)