Skip to content

Commit 0d6e554

Browse files
authored
SWDEV-524188 - Check for VRam and system RAM properly (#122)
Currently, we check if there's enough system RAM even if we don't allocate on host device. This is incorrect logic. We should not check for this size on windows because PAL checks for memory allocation. See SWDEV-467263. Co-authored-by: Jimbo Xie <[email protected]>
1 parent 5c03084 commit 0d6e554

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

hipamd/src/hip_memory.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,11 @@ hipError_t ihipMalloc(void** ptr, size_t sizeBytes, unsigned int flags)
344344
const auto& dev_info = amdContext->devices()[0]->info();
345345
hip::getCurrentDevice()->SetActiveStatus();
346346

347-
if (dev_info.maxPhysicalMemAllocSize_ < sizeBytes) {
348-
return hipErrorOutOfMemory;
349-
}
350-
// PAL allocates from system memory if needed
351-
if (IS_LINUX && !useHostDevice && (dev_info.maxMemAllocSize_ < sizeBytes)) {
347+
size_t max_device_size = IS_LINUX ? dev_info.maxMemAllocSize_ :
348+
(dev_info.maxMemAllocSize_ + dev_info.maxPhysicalMemAllocSize_);
349+
350+
if ((useHostDevice && dev_info.maxPhysicalMemAllocSize_ < sizeBytes) ||
351+
(!useHostDevice && max_device_size < sizeBytes)) {
352352
return hipErrorOutOfMemory;
353353
}
354354

0 commit comments

Comments
 (0)