fix: limit usm device reuse based on used memory

Calculate available memory for usm device reuse based as (total device
memory - used memory) * fraction for reuse.

Use sys mem allocs for devices without local memory.

Related-To: NEO-12902

Signed-off-by: Dominik Dabek <dominik.dabek@intel.com>
This commit is contained in:
Dominik Dabek
2024-12-04 07:07:13 +00:00
committed by Compute-Runtime-Automation
parent d4bfa0f758
commit 1252b10ba9
6 changed files with 132 additions and 12 deletions

View File

@@ -181,7 +181,7 @@ class Device : public ReferenceTrackedObject<Device> {
void initializeRayTracing(uint32_t maxBvhLevels);
void allocateRTDispatchGlobals(uint32_t maxBvhLevels);
uint64_t getGlobalMemorySize(uint32_t deviceBitfield) const;
MOCKABLE_VIRTUAL uint64_t getGlobalMemorySize(uint32_t deviceBitfield) const;
const std::vector<SubDevice *> &getSubDevices() const { return subdevices; }
bool getUuid(std::array<uint8_t, ProductHelper::uuidSize> &uuid);
void generateUuid(std::array<uint8_t, ProductHelper::uuidSize> &uuid);

View File

@@ -62,7 +62,13 @@ bool SVMAllocsManager::SvmAllocationCache::insert(size_t size, void *ptr, SvmAll
if (auto device = svmData->device) {
auto lock = device->obtainAllocationsReuseLock();
const auto usedSize = device->getAllocationsSavedForReuseSize();
if (size + usedSize > this->maxSize) {
uint64_t availableMemory = device->getGlobalMemorySize(static_cast<uint32_t>(device->getDeviceBitfield().to_ulong()));
availableMemory -= memoryManager->getUsedLocalMemorySize(device->getRootDeviceIndex());
if (!localMemorySupported) {
availableMemory -= memoryManager->getUsedSystemMemorySize();
}
const auto availableMemoryForReuse = static_cast<uint64_t>(availableMemory * fractionOfAvailableMemoryForRecycling);
if (size + usedSize > availableMemoryForReuse) {
return false;
}
device->recordAllocationSaveForReuse(size);
@@ -756,6 +762,8 @@ void SVMAllocsManager::initUsmDeviceAllocationsCache(Device &device) {
if (this->usmDeviceAllocationsCache.maxSize > 0u) {
this->usmDeviceAllocationsCache.allocations.reserve(128u);
}
this->usmDeviceAllocationsCache.fractionOfAvailableMemoryForRecycling = fractionOfTotalMemoryForRecycling;
this->usmDeviceAllocationsCache.localMemorySupported = memoryManager->isLocalMemorySupported(device.getRootDeviceIndex());
}
void SVMAllocsManager::initUsmHostAllocationsCache() {

View File

@@ -172,6 +172,8 @@ class SVMAllocsManager {
std::vector<SvmCacheAllocationInfo> allocations;
std::mutex mtx;
bool localMemorySupported = true;
double fractionOfAvailableMemoryForRecycling = 0.0;
size_t maxSize = 0;
};