From 7346f3bd29c0133a3fee323904abdc79872cc8cb Mon Sep 17 00:00:00 2001 From: Ajay Date: Tue, 8 Oct 2024 16:29:10 -0700 Subject: [PATCH] SWDEV-498474 - APU: when total allocated is greater than 75% of invisible Only when memory type is Local and the invisible memory is +ve Should also fix SWDEV-490991 Change-Id: I78a4925a234ba90c63909bde5b7dc217568b4de3 [ROCm/clr commit: 7d763fb803c89944434c60d318a1b86e0891bda1] --- projects/clr/rocclr/device/pal/paldevice.hpp | 7 +++++++ projects/clr/rocclr/device/pal/palmemory.cpp | 15 +++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/projects/clr/rocclr/device/pal/paldevice.hpp b/projects/clr/rocclr/device/pal/paldevice.hpp index 21909d540a..c1b1ab1d86 100644 --- a/projects/clr/rocclr/device/pal/paldevice.hpp +++ b/projects/clr/rocclr/device/pal/paldevice.hpp @@ -680,6 +680,13 @@ class Device : public NullDevice { return heaps_[Pal::GpuHeapInvisible]; } + Pal::gpusize TotalAlloc() const { + Pal::gpusize local = allocedMem[Pal::GpuHeapLocal] - resourceCache().persistentCacheSize(); + Pal::gpusize invisible = allocedMem[Pal::GpuHeapInvisible] - resourceCache().lclCacheSize(); + Pal::gpusize total_alloced = local + invisible; + return total_alloced; + } + private: static void PAL_STDCALL PalDeveloperCallback(void* pPrivateData, const Pal::uint32 deviceIndex, Pal::Developer::CallbackType type, void* pCbData); diff --git a/projects/clr/rocclr/device/pal/palmemory.cpp b/projects/clr/rocclr/device/pal/palmemory.cpp index 8cabf58bf1..550f235688 100644 --- a/projects/clr/rocclr/device/pal/palmemory.cpp +++ b/projects/clr/rocclr/device/pal/palmemory.cpp @@ -113,18 +113,21 @@ bool Memory::create(Resource::MemoryType memType, Resource::CreateParams* params dev().info().largeBar_) { memType = Persistent; } + + if (dev().settings().apuSystem_) { + const Pal::GpuMemoryHeapProperties& invisibleHeap = dev().GetGpuHeapInvisible(); + Pal::gpusize totalAlloc = dev().TotalAlloc(); + if (invisibleHeap.logicalSize > 0 && memType == Local && + (totalAlloc > (invisibleHeap.logicalSize * 0.75))) { + memType = RemoteUSWC; + } + } // Create a resource in PAL result = Resource::create(memType, params, forceLinear); if (!result) { size_t freeMemory[2]; // if requested memory is greater than available then exit the loop dev().globalFreeMemory(freeMemory); - - const Pal::GpuMemoryHeapProperties& invisibleHeap = dev().GetGpuHeapInvisible(); - if (dev().settings().apuSystem_ && (size() > (invisibleHeap.logicalSize * 2))) { - memType = RemoteUSWC; - break; - } // Local to Persistent if (memoryType() == Local) { // For dgpu freeMemory[0] reports a sum of visible+invisible fb