From 142e347aac692563a82eb8f50f3ff337ac788f53 Mon Sep 17 00:00:00 2001 From: "Xie, AlexBin" Date: Fri, 9 May 2025 20:08:23 -0400 Subject: [PATCH] SWDEV-528860 - reserve some memory in visible frame buffer (#251) [ROCm/clr commit: faac50c77abfc361e770c2e55ad40216d651a4b5] --- projects/clr/rocclr/device/pal/paldevice.cpp | 17 +++++++++++++++++ projects/clr/rocclr/device/pal/paldevice.hpp | 5 +++-- projects/clr/rocclr/device/pal/palmemory.cpp | 3 +-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/projects/clr/rocclr/device/pal/paldevice.cpp b/projects/clr/rocclr/device/pal/paldevice.cpp index 6530ce37d6..23a11b14e3 100644 --- a/projects/clr/rocclr/device/pal/paldevice.cpp +++ b/projects/clr/rocclr/device/pal/paldevice.cpp @@ -998,6 +998,23 @@ bool Device::create(Pal::IDevice* device) { // Fill the device info structure fillDeviceInfo(properties(), heaps_, 16 * Ki, numComputeEngines(), numExclusiveComputeEngines(), iDev()); + // Reserve percentage memory for large frame buffer. + // Reserve a threshold size for small frame buffer, used by page table for remote memory mapping + Pal::gpusize invisibleSize = heaps_[Pal::GpuHeapInvisible].logicalSize; + Pal::gpusize visibleSize = heaps_[Pal::GpuHeapLocal].logicalSize; + + Pal::gpusize maxInvisibleAllocation = std::min((invisibleSize / 100) * 98, + invisibleSize < 128 * Mi? 0: invisibleSize - 128 * Mi); + Pal::gpusize maxVisibleAllocation = std::min((visibleSize / 100) * 98, + visibleSize < 128 * Mi? 0: visibleSize - 128 * Mi); + + if (invisibleSize < visibleSize && invisibleSize > 0) { + // Page table is in invisible and its size is smaller. Invisible is the only deciding factor + maxFrameBufferAllocation_ = maxInvisibleAllocation; + } else { + maxFrameBufferAllocation_ = std::max(maxInvisibleAllocation, maxVisibleAllocation); + } + if (!ValidateComgr()) { LogError("Code object manager initialization failed!"); return false; diff --git a/projects/clr/rocclr/device/pal/paldevice.hpp b/projects/clr/rocclr/device/pal/paldevice.hpp index 3c99abc0e9..4e4e0522bf 100644 --- a/projects/clr/rocclr/device/pal/paldevice.hpp +++ b/projects/clr/rocclr/device/pal/paldevice.hpp @@ -675,8 +675,8 @@ class Device : public NullDevice { //! Allocates hidden heap for device memory allocations void HiddenHeapAlloc(const VirtualGPU& gpu); - const Pal::GpuMemoryHeapProperties& GetGpuHeapInvisible() const { - return heaps_[Pal::GpuHeapInvisible]; + Pal::gpusize GetMaxFrameBuffer() const { + return maxFrameBufferAllocation_; } Pal::gpusize TotalAlloc() const { @@ -760,6 +760,7 @@ class Device : public NullDevice { ICaptureMgr* captureMgr_; //!< RGP/UberTrace capture manager Pal::GpuMemoryHeapProperties heaps_[Pal::GpuHeapCount]; //!< Information about heaps, returned from PAL + Pal::gpusize maxFrameBufferAllocation_; //!< To reserve some memory in frame buffer std::map queue_pool_; //!< Pool of PAL queues for recycling amd::Program* trap_handler_ = nullptr; //!< Trap handler program for debugger setup }; diff --git a/projects/clr/rocclr/device/pal/palmemory.cpp b/projects/clr/rocclr/device/pal/palmemory.cpp index b9dffe9146..3c9177f3a2 100644 --- a/projects/clr/rocclr/device/pal/palmemory.cpp +++ b/projects/clr/rocclr/device/pal/palmemory.cpp @@ -116,9 +116,8 @@ bool Memory::create(Resource::MemoryType memType, Resource::CreateParams* params } if (amd::IS_HIP && dev().settings().apuSystem_) { - const Pal::GpuMemoryHeapProperties& invisibleHeap = dev().GetGpuHeapInvisible(); Pal::gpusize totalAlloc = dev().TotalAlloc(); - if (memType == Local && (totalAlloc > invisibleHeap.logicalSize)) { + if (memType == Local && totalAlloc > dev().GetMaxFrameBuffer()) { memType = RemoteUSWC; } }