Revert "fix: limit usm device reuse based on used memory"

This reverts commit 1252b10ba9.

Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
Compute-Runtime-Validation
2024-12-05 22:46:55 +01:00
committed by Compute-Runtime-Automation
parent ffec97acc5
commit 484210d656
6 changed files with 12 additions and 132 deletions

View File

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

View File

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

View File

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

View File

@@ -63,6 +63,7 @@ class MockDevice : public RootDevice {
using Device::deviceInfo; using Device::deviceInfo;
using Device::executionEnvironment; using Device::executionEnvironment;
using Device::generateUuidFromPciBusInfo; using Device::generateUuidFromPciBusInfo;
using Device::getGlobalMemorySize;
using Device::initializeCaps; using Device::initializeCaps;
using Device::preemptionMode; using Device::preemptionMode;
using Device::regularEngineGroups; using Device::regularEngineGroups;
@@ -98,13 +99,6 @@ class MockDevice : public RootDevice {
performanceCounters = std::move(perfCounters); performanceCounters = std::move(perfCounters);
} }
uint64_t getGlobalMemorySize(uint32_t deviceBitfield) const override {
if (callBaseGetGlobalMemorySize) {
return Device::getGlobalMemorySize(deviceBitfield);
}
return getGlobalMemorySizeReturn;
}
size_t getMaxParameterSizeFromIGC() const override { size_t getMaxParameterSizeFromIGC() const override {
if (callBaseGetMaxParameterSizeFromIGC) { if (callBaseGetMaxParameterSizeFromIGC) {
return Device::getMaxParameterSizeFromIGC(); return Device::getMaxParameterSizeFromIGC();
@@ -179,8 +173,6 @@ class MockDevice : public RootDevice {
bool callBaseGetMaxParameterSizeFromIGC = false; bool callBaseGetMaxParameterSizeFromIGC = false;
bool callBaseVerifyAdapterLuid = true; bool callBaseVerifyAdapterLuid = true;
bool callBaseGetGlobalMemorySize = true;
uint64_t getGlobalMemorySizeReturn = 0u;
bool verifyAdapterLuidReturnValue = true; bool verifyAdapterLuidReturnValue = true;
size_t maxParameterSizeFromIGC = 0u; size_t maxParameterSizeFromIGC = 0u;
bool rtDispatchGlobalsForceAllocation = true; bool rtDispatchGlobalsForceAllocation = true;

View File

@@ -64,7 +64,6 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
using MemoryManager::localMemorySupported; using MemoryManager::localMemorySupported;
using MemoryManager::reservedMemory; using MemoryManager::reservedMemory;
using MemoryManager::secondaryEngines; using MemoryManager::secondaryEngines;
using MemoryManager::sysMemAllocsSize;
static constexpr osHandle invalidSharedHandle = -1; static constexpr osHandle invalidSharedHandle = -1;
static const unsigned int moduleId; static const unsigned int moduleId;

View File

@@ -231,34 +231,25 @@ TEST_F(SvmDeviceAllocationCacheTest, givenAllocationCacheEnabledWhenInitializedT
auto expectedMaxSize = static_cast<size_t>(device->getGlobalMemorySize(static_cast<uint32_t>(mockDeviceBitfield.to_ulong())) * 0.02); auto expectedMaxSize = static_cast<size_t>(device->getGlobalMemorySize(static_cast<uint32_t>(mockDeviceBitfield.to_ulong())) * 0.02);
EXPECT_EQ(expectedMaxSize, svmManager->usmDeviceAllocationsCache.maxSize); EXPECT_EQ(expectedMaxSize, svmManager->usmDeviceAllocationsCache.maxSize);
EXPECT_EQ(0.02, svmManager->usmDeviceAllocationsCache.fractionOfAvailableMemoryForRecycling);
EXPECT_EQ(device->getMemoryManager()->isLocalMemorySupported(device->getRootDeviceIndex()), svmManager->usmDeviceAllocationsCache.localMemorySupported);
} }
TEST_F(SvmDeviceAllocationCacheTest, givenAllocationCacheEnabledAndLocalMemorySupportedWhenFreeingDeviceAllocationThenItIsPutIntoCacheOnlyIfMaxSizeWillNotBeExceeded) { TEST_F(SvmDeviceAllocationCacheTest, givenAllocationCacheEnabledWhenFreeingDeviceAllocationThenItIsPutIntoCacheOnlyIfMaxSizeWillNotBeExceeded) {
std::unique_ptr<UltDeviceFactory> deviceFactory(new UltDeviceFactory(1, 1)); std::unique_ptr<UltDeviceFactory> deviceFactory(new UltDeviceFactory(1, 1));
RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex}; RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, mockDeviceBitfield}}; std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, mockDeviceBitfield}};
DebugManagerStateRestore restore; DebugManagerStateRestore restore;
debugManager.flags.ExperimentalEnableDeviceAllocationCache.set(2); debugManager.flags.ExperimentalEnableDeviceAllocationCache.set(1);
auto device = deviceFactory->rootDevices[0]; auto device = deviceFactory->rootDevices[0];
auto mockMemoryManager = reinterpret_cast<MockMemoryManager *>(device->getMemoryManager());
mockMemoryManager->localMemorySupported[device->getRootDeviceIndex()] = true;
constexpr auto allocationSize = MemoryConstants::pageSize64k;
device->callBaseGetGlobalMemorySize = false;
device->getGlobalMemorySizeReturn = allocationSize * 100;
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false); auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
svmManager->initUsmAllocationsCaches(*device); svmManager->initUsmAllocationsCaches(*device);
ASSERT_TRUE(svmManager->usmDeviceAllocationsCacheEnabled); ASSERT_TRUE(svmManager->usmDeviceAllocationsCacheEnabled);
constexpr auto allocationSize = MemoryConstants::pageSize64k;
svmManager->usmDeviceAllocationsCache.maxSize = allocationSize;
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::deviceUnifiedMemory, 1, rootDeviceIndices, deviceBitfields); SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::deviceUnifiedMemory, 1, rootDeviceIndices, deviceBitfields);
unifiedMemoryProperties.device = device; unifiedMemoryProperties.device = device;
{ {
mockMemoryManager->sysMemAllocsSize = allocationSize * 50;
mockMemoryManager->localMemAllocsSize[device->getRootDeviceIndex()] = 0u;
auto allocation = svmManager->createUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties); auto allocation = svmManager->createUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties);
ASSERT_NE(allocation, nullptr); ASSERT_NE(allocation, nullptr);
auto allocation2 = svmManager->createUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties); auto allocation2 = svmManager->createUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties);
@@ -270,8 +261,6 @@ TEST_F(SvmDeviceAllocationCacheTest, givenAllocationCacheEnabledAndLocalMemorySu
EXPECT_EQ(1u, svmManager->usmDeviceAllocationsCache.allocations.size()); EXPECT_EQ(1u, svmManager->usmDeviceAllocationsCache.allocations.size());
EXPECT_EQ(allocationSize, device->getAllocationsSavedForReuseSize()); EXPECT_EQ(allocationSize, device->getAllocationsSavedForReuseSize());
mockMemoryManager->localMemAllocsSize[device->getRootDeviceIndex()] = allocationSize * 50;
svmManager->freeSVMAlloc(allocation2); svmManager->freeSVMAlloc(allocation2);
EXPECT_EQ(1u, svmManager->usmDeviceAllocationsCache.allocations.size()); EXPECT_EQ(1u, svmManager->usmDeviceAllocationsCache.allocations.size());
EXPECT_EQ(allocationSize, device->getAllocationsSavedForReuseSize()); EXPECT_EQ(allocationSize, device->getAllocationsSavedForReuseSize());
@@ -288,8 +277,6 @@ TEST_F(SvmDeviceAllocationCacheTest, givenAllocationCacheEnabledAndLocalMemorySu
EXPECT_EQ(0u, device->getAllocationsSavedForReuseSize()); EXPECT_EQ(0u, device->getAllocationsSavedForReuseSize());
} }
{ {
mockMemoryManager->sysMemAllocsSize = allocationSize * 50;
mockMemoryManager->localMemAllocsSize[device->getRootDeviceIndex()] = 0u;
auto allocation = svmManager->createUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties); auto allocation = svmManager->createUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties);
ASSERT_NE(allocation, nullptr); ASSERT_NE(allocation, nullptr);
auto allocation2 = svmManager->createUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties); auto allocation2 = svmManager->createUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties);
@@ -301,94 +288,6 @@ TEST_F(SvmDeviceAllocationCacheTest, givenAllocationCacheEnabledAndLocalMemorySu
EXPECT_EQ(1u, svmManager->usmDeviceAllocationsCache.allocations.size()); EXPECT_EQ(1u, svmManager->usmDeviceAllocationsCache.allocations.size());
EXPECT_EQ(allocationSize, device->getAllocationsSavedForReuseSize()); EXPECT_EQ(allocationSize, device->getAllocationsSavedForReuseSize());
mockMemoryManager->localMemAllocsSize[device->getRootDeviceIndex()] = allocationSize * 50;
svmManager->freeSVMAllocDefer(allocation2);
EXPECT_EQ(1u, svmManager->usmDeviceAllocationsCache.allocations.size());
EXPECT_EQ(allocationSize, device->getAllocationsSavedForReuseSize());
auto recycledAllocation = svmManager->createUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties);
EXPECT_EQ(recycledAllocation, allocation);
EXPECT_EQ(svmManager->usmDeviceAllocationsCache.allocations.size(), 0u);
EXPECT_EQ(0u, device->getAllocationsSavedForReuseSize());
svmManager->freeSVMAllocDefer(recycledAllocation);
svmManager->trimUSMDeviceAllocCache();
EXPECT_EQ(svmManager->usmDeviceAllocationsCache.allocations.size(), 0u);
EXPECT_EQ(0u, device->getAllocationsSavedForReuseSize());
}
}
TEST_F(SvmDeviceAllocationCacheTest, givenAllocationCacheEnabledAndLocalMemoryNotSupportedWhenFreeingDeviceAllocationThenItIsPutIntoCacheOnlyIfMaxSizeWillNotBeExceeded) {
std::unique_ptr<UltDeviceFactory> deviceFactory(new UltDeviceFactory(1, 1));
RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, mockDeviceBitfield}};
DebugManagerStateRestore restore;
debugManager.flags.ExperimentalEnableDeviceAllocationCache.set(2);
auto device = deviceFactory->rootDevices[0];
auto mockMemoryManager = reinterpret_cast<MockMemoryManager *>(device->getMemoryManager());
mockMemoryManager->localMemorySupported[device->getRootDeviceIndex()] = false;
constexpr auto allocationSize = MemoryConstants::pageSize64k;
device->callBaseGetGlobalMemorySize = false;
device->getGlobalMemorySizeReturn = allocationSize * 100;
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
svmManager->initUsmAllocationsCaches(*device);
ASSERT_TRUE(svmManager->usmDeviceAllocationsCacheEnabled);
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::deviceUnifiedMemory, 1, rootDeviceIndices, deviceBitfields);
unifiedMemoryProperties.device = device;
{
mockMemoryManager->sysMemAllocsSize = 0u;
mockMemoryManager->localMemAllocsSize[device->getRootDeviceIndex()] = 0u;
auto allocation = svmManager->createUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties);
ASSERT_NE(allocation, nullptr);
auto allocation2 = svmManager->createUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties);
ASSERT_NE(allocation2, nullptr);
EXPECT_EQ(0u, svmManager->usmDeviceAllocationsCache.allocations.size());
EXPECT_EQ(0u, device->getAllocationsSavedForReuseSize());
svmManager->freeSVMAlloc(allocation);
EXPECT_EQ(1u, svmManager->usmDeviceAllocationsCache.allocations.size());
EXPECT_EQ(allocationSize, device->getAllocationsSavedForReuseSize());
mockMemoryManager->sysMemAllocsSize = allocationSize * 25;
mockMemoryManager->localMemAllocsSize[device->getRootDeviceIndex()] = allocationSize * 25;
svmManager->freeSVMAlloc(allocation2);
EXPECT_EQ(1u, svmManager->usmDeviceAllocationsCache.allocations.size());
EXPECT_EQ(allocationSize, device->getAllocationsSavedForReuseSize());
auto recycledAllocation = svmManager->createUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties);
EXPECT_EQ(recycledAllocation, allocation);
EXPECT_EQ(svmManager->usmDeviceAllocationsCache.allocations.size(), 0u);
EXPECT_EQ(0u, device->getAllocationsSavedForReuseSize());
svmManager->freeSVMAlloc(recycledAllocation);
svmManager->trimUSMDeviceAllocCache();
EXPECT_EQ(svmManager->usmDeviceAllocationsCache.allocations.size(), 0u);
EXPECT_EQ(0u, device->getAllocationsSavedForReuseSize());
}
{
mockMemoryManager->sysMemAllocsSize = 0u;
mockMemoryManager->localMemAllocsSize[device->getRootDeviceIndex()] = 0u;
auto allocation = svmManager->createUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties);
ASSERT_NE(allocation, nullptr);
auto allocation2 = svmManager->createUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties);
ASSERT_NE(allocation2, nullptr);
EXPECT_EQ(0u, svmManager->usmDeviceAllocationsCache.allocations.size());
EXPECT_EQ(0u, device->getAllocationsSavedForReuseSize());
svmManager->freeSVMAllocDefer(allocation);
EXPECT_EQ(1u, svmManager->usmDeviceAllocationsCache.allocations.size());
EXPECT_EQ(allocationSize, device->getAllocationsSavedForReuseSize());
mockMemoryManager->sysMemAllocsSize = allocationSize * 25;
mockMemoryManager->localMemAllocsSize[device->getRootDeviceIndex()] = allocationSize * 25;
svmManager->freeSVMAllocDefer(allocation2); svmManager->freeSVMAllocDefer(allocation2);
EXPECT_EQ(1u, svmManager->usmDeviceAllocationsCache.allocations.size()); EXPECT_EQ(1u, svmManager->usmDeviceAllocationsCache.allocations.size());
EXPECT_EQ(allocationSize, device->getAllocationsSavedForReuseSize()); EXPECT_EQ(allocationSize, device->getAllocationsSavedForReuseSize());
@@ -413,10 +312,6 @@ TEST_F(SvmDeviceAllocationCacheTest, givenAllocationCacheEnabledAndMultipleSVMMa
DebugManagerStateRestore restore; DebugManagerStateRestore restore;
debugManager.flags.ExperimentalEnableDeviceAllocationCache.set(1); debugManager.flags.ExperimentalEnableDeviceAllocationCache.set(1);
auto device = deviceFactory->rootDevices[0]; auto device = deviceFactory->rootDevices[0];
constexpr auto allocationSize = MemoryConstants::pageSize64k;
device->callBaseGetGlobalMemorySize = false;
device->getGlobalMemorySizeReturn = allocationSize * 100;
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false); auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
auto secondSvmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false); auto secondSvmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
svmManager->initUsmAllocationsCaches(*device); svmManager->initUsmAllocationsCaches(*device);
@@ -424,6 +319,10 @@ TEST_F(SvmDeviceAllocationCacheTest, givenAllocationCacheEnabledAndMultipleSVMMa
ASSERT_TRUE(svmManager->usmDeviceAllocationsCacheEnabled); ASSERT_TRUE(svmManager->usmDeviceAllocationsCacheEnabled);
ASSERT_TRUE(secondSvmManager->usmDeviceAllocationsCacheEnabled); ASSERT_TRUE(secondSvmManager->usmDeviceAllocationsCacheEnabled);
constexpr auto allocationSize = MemoryConstants::pageSize64k;
svmManager->usmDeviceAllocationsCache.maxSize = allocationSize;
secondSvmManager->usmDeviceAllocationsCache.maxSize = allocationSize;
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::deviceUnifiedMemory, 1, rootDeviceIndices, deviceBitfields); SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::deviceUnifiedMemory, 1, rootDeviceIndices, deviceBitfields);
unifiedMemoryProperties.device = device; unifiedMemoryProperties.device = device;
{ {