mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-21 09:14:47 +08:00
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:
committed by
Compute-Runtime-Automation
parent
ffec97acc5
commit
484210d656
@@ -181,7 +181,7 @@ class Device : public ReferenceTrackedObject<Device> {
|
||||
void initializeRayTracing(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; }
|
||||
bool getUuid(std::array<uint8_t, ProductHelper::uuidSize> &uuid);
|
||||
void generateUuid(std::array<uint8_t, ProductHelper::uuidSize> &uuid);
|
||||
|
||||
@@ -62,13 +62,7 @@ bool SVMAllocsManager::SvmAllocationCache::insert(size_t size, void *ptr, SvmAll
|
||||
if (auto device = svmData->device) {
|
||||
auto lock = device->obtainAllocationsReuseLock();
|
||||
const auto usedSize = device->getAllocationsSavedForReuseSize();
|
||||
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) {
|
||||
if (size + usedSize > this->maxSize) {
|
||||
return false;
|
||||
}
|
||||
device->recordAllocationSaveForReuse(size);
|
||||
@@ -762,8 +756,6 @@ 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() {
|
||||
|
||||
@@ -172,8 +172,6 @@ class SVMAllocsManager {
|
||||
|
||||
std::vector<SvmCacheAllocationInfo> allocations;
|
||||
std::mutex mtx;
|
||||
bool localMemorySupported = true;
|
||||
double fractionOfAvailableMemoryForRecycling = 0.0;
|
||||
size_t maxSize = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ class MockDevice : public RootDevice {
|
||||
using Device::deviceInfo;
|
||||
using Device::executionEnvironment;
|
||||
using Device::generateUuidFromPciBusInfo;
|
||||
using Device::getGlobalMemorySize;
|
||||
using Device::initializeCaps;
|
||||
using Device::preemptionMode;
|
||||
using Device::regularEngineGroups;
|
||||
@@ -98,13 +99,6 @@ class MockDevice : public RootDevice {
|
||||
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 {
|
||||
if (callBaseGetMaxParameterSizeFromIGC) {
|
||||
return Device::getMaxParameterSizeFromIGC();
|
||||
@@ -179,8 +173,6 @@ class MockDevice : public RootDevice {
|
||||
|
||||
bool callBaseGetMaxParameterSizeFromIGC = false;
|
||||
bool callBaseVerifyAdapterLuid = true;
|
||||
bool callBaseGetGlobalMemorySize = true;
|
||||
uint64_t getGlobalMemorySizeReturn = 0u;
|
||||
bool verifyAdapterLuidReturnValue = true;
|
||||
size_t maxParameterSizeFromIGC = 0u;
|
||||
bool rtDispatchGlobalsForceAllocation = true;
|
||||
|
||||
@@ -64,7 +64,6 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
|
||||
using MemoryManager::localMemorySupported;
|
||||
using MemoryManager::reservedMemory;
|
||||
using MemoryManager::secondaryEngines;
|
||||
using MemoryManager::sysMemAllocsSize;
|
||||
|
||||
static constexpr osHandle invalidSharedHandle = -1;
|
||||
static const unsigned int moduleId;
|
||||
|
||||
@@ -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);
|
||||
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));
|
||||
RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex};
|
||||
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, mockDeviceBitfield}};
|
||||
DebugManagerStateRestore restore;
|
||||
debugManager.flags.ExperimentalEnableDeviceAllocationCache.set(2);
|
||||
debugManager.flags.ExperimentalEnableDeviceAllocationCache.set(1);
|
||||
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);
|
||||
svmManager->initUsmAllocationsCaches(*device);
|
||||
ASSERT_TRUE(svmManager->usmDeviceAllocationsCacheEnabled);
|
||||
|
||||
constexpr auto allocationSize = MemoryConstants::pageSize64k;
|
||||
svmManager->usmDeviceAllocationsCache.maxSize = allocationSize;
|
||||
|
||||
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::deviceUnifiedMemory, 1, rootDeviceIndices, deviceBitfields);
|
||||
unifiedMemoryProperties.device = device;
|
||||
{
|
||||
mockMemoryManager->sysMemAllocsSize = allocationSize * 50;
|
||||
mockMemoryManager->localMemAllocsSize[device->getRootDeviceIndex()] = 0u;
|
||||
auto allocation = svmManager->createUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties);
|
||||
ASSERT_NE(allocation, nullptr);
|
||||
auto allocation2 = svmManager->createUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties);
|
||||
@@ -270,8 +261,6 @@ TEST_F(SvmDeviceAllocationCacheTest, givenAllocationCacheEnabledAndLocalMemorySu
|
||||
EXPECT_EQ(1u, svmManager->usmDeviceAllocationsCache.allocations.size());
|
||||
EXPECT_EQ(allocationSize, device->getAllocationsSavedForReuseSize());
|
||||
|
||||
mockMemoryManager->localMemAllocsSize[device->getRootDeviceIndex()] = allocationSize * 50;
|
||||
|
||||
svmManager->freeSVMAlloc(allocation2);
|
||||
EXPECT_EQ(1u, svmManager->usmDeviceAllocationsCache.allocations.size());
|
||||
EXPECT_EQ(allocationSize, device->getAllocationsSavedForReuseSize());
|
||||
@@ -288,8 +277,6 @@ TEST_F(SvmDeviceAllocationCacheTest, givenAllocationCacheEnabledAndLocalMemorySu
|
||||
EXPECT_EQ(0u, device->getAllocationsSavedForReuseSize());
|
||||
}
|
||||
{
|
||||
mockMemoryManager->sysMemAllocsSize = allocationSize * 50;
|
||||
mockMemoryManager->localMemAllocsSize[device->getRootDeviceIndex()] = 0u;
|
||||
auto allocation = svmManager->createUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties);
|
||||
ASSERT_NE(allocation, nullptr);
|
||||
auto allocation2 = svmManager->createUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties);
|
||||
@@ -301,94 +288,6 @@ TEST_F(SvmDeviceAllocationCacheTest, givenAllocationCacheEnabledAndLocalMemorySu
|
||||
EXPECT_EQ(1u, svmManager->usmDeviceAllocationsCache.allocations.size());
|
||||
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);
|
||||
EXPECT_EQ(1u, svmManager->usmDeviceAllocationsCache.allocations.size());
|
||||
EXPECT_EQ(allocationSize, device->getAllocationsSavedForReuseSize());
|
||||
@@ -413,10 +312,6 @@ TEST_F(SvmDeviceAllocationCacheTest, givenAllocationCacheEnabledAndMultipleSVMMa
|
||||
DebugManagerStateRestore restore;
|
||||
debugManager.flags.ExperimentalEnableDeviceAllocationCache.set(1);
|
||||
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 secondSvmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
|
||||
svmManager->initUsmAllocationsCaches(*device);
|
||||
@@ -424,6 +319,10 @@ TEST_F(SvmDeviceAllocationCacheTest, givenAllocationCacheEnabledAndMultipleSVMMa
|
||||
ASSERT_TRUE(svmManager->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);
|
||||
unifiedMemoryProperties.device = device;
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user