From 88841d1dee4cd9364c26e7debfe4bc189e681959 Mon Sep 17 00:00:00 2001 From: "Xie, Jiabao(Jimbo)" Date: Thu, 10 Apr 2025 12:20:48 -0400 Subject: [PATCH] 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 [ROCm/clr commit: 0d6e554d92e8e3adbcf1ebb51e91f527e0651c03] --- projects/clr/hipamd/src/hip_memory.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/projects/clr/hipamd/src/hip_memory.cpp b/projects/clr/hipamd/src/hip_memory.cpp index 6721b86d81..6ff0939b2c 100644 --- a/projects/clr/hipamd/src/hip_memory.cpp +++ b/projects/clr/hipamd/src/hip_memory.cpp @@ -344,11 +344,11 @@ hipError_t ihipMalloc(void** ptr, size_t sizeBytes, unsigned int flags) const auto& dev_info = amdContext->devices()[0]->info(); hip::getCurrentDevice()->SetActiveStatus(); - if (dev_info.maxPhysicalMemAllocSize_ < sizeBytes) { - return hipErrorOutOfMemory; - } - // PAL allocates from system memory if needed - if (IS_LINUX && !useHostDevice && (dev_info.maxMemAllocSize_ < sizeBytes)) { + size_t max_device_size = IS_LINUX ? dev_info.maxMemAllocSize_ : + (dev_info.maxMemAllocSize_ + dev_info.maxPhysicalMemAllocSize_); + + if ((useHostDevice && dev_info.maxPhysicalMemAllocSize_ < sizeBytes) || + (!useHostDevice && max_device_size < sizeBytes)) { return hipErrorOutOfMemory; }