Skip to content

Commit 2a77576

Browse files
Change percent of global memory returned
Related-To: NEO-5796 Signed-off-by: Dominik Dabek <dominik.dabek@intel.com>
1 parent 8268154 commit 2a77576

File tree

13 files changed

+51
-12
lines changed

13 files changed

+51
-12
lines changed

level_zero/core/test/unit_tests/sources/event/test_event.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ class MemoryManagerEventPoolFailMock : public NEO::MemoryManager {
3838
AllocationStatus populateOsHandles(NEO::OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override { return AllocationStatus::Success; };
3939
void cleanOsHandles(NEO::OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override{};
4040
void freeGraphicsMemoryImpl(NEO::GraphicsAllocation *gfxAllocation) override{};
41-
uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override {
42-
return 0;
43-
};
41+
uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override { return 0; };
4442
uint64_t getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t deviceBitfield) override { return 0; };
43+
double getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) override { return 0; }
4544
AddressRange reserveGpuAddress(size_t size, uint32_t rootDeviceIndex) override {
4645
return {};
4746
}

level_zero/core/test/unit_tests/sources/memory/test_memory.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,10 +1304,9 @@ class MemoryManagerIpcMock : public NEO::MemoryManager {
13041304
AllocationStatus populateOsHandles(NEO::OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override { return AllocationStatus::Success; };
13051305
void cleanOsHandles(NEO::OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override{};
13061306
void freeGraphicsMemoryImpl(NEO::GraphicsAllocation *gfxAllocation) override{};
1307-
uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override {
1308-
return 0;
1309-
};
1307+
uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override { return 0; };
13101308
uint64_t getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t deviceBitfield) override { return 0; };
1309+
double getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) override { return 0; }
13111310
AddressRange reserveGpuAddress(size_t size, uint32_t rootDeviceIndex) override {
13121311
return {};
13131312
}

opencl/test/unit_test/device/device_caps_tests.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,13 @@ TEST_F(DeviceGetCapsTest, givenForce32bitAddressingWhenCapsAreCreatedThenDeviceR
437437
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
438438
const auto &caps = device->getDeviceInfo();
439439
const auto &sharedCaps = device->getSharedDeviceInfo();
440+
const auto memSizePercent = device->getMemoryManager()->getPercentOfGlobalMemoryAvailable(device->getRootDeviceIndex());
440441
if constexpr (is64bit) {
441442
EXPECT_TRUE(sharedCaps.force32BitAddressess);
442443
} else {
443444
EXPECT_FALSE(sharedCaps.force32BitAddressess);
444445
}
445-
auto expectedSize = (cl_ulong)(4 * 0.8 * GB);
446+
auto expectedSize = (cl_ulong)(4 * memSizePercent * GB);
446447
EXPECT_LE(sharedCaps.globalMemSize, expectedSize);
447448
EXPECT_LE(sharedCaps.maxMemAllocSize, expectedSize);
448449
EXPECT_LE(caps.maxConstantBufferSize, expectedSize);
@@ -465,13 +466,14 @@ TEST_F(DeviceGetCapsTest, Given32bitAddressingWhenDeviceIsCreatedThenGlobalMemSi
465466
auto pMemManager = device->getMemoryManager();
466467
auto enabledOcl21Features = device->areOcl21FeaturesEnabled();
467468
bool addressing32Bit = is32bit || (is64bit && (enabledOcl21Features == false)) || DebugManager.flags.Force32bitAddressing.get();
469+
const auto memSizePercent = pMemManager->getPercentOfGlobalMemoryAvailable(device->getRootDeviceIndex());
468470

469471
cl_ulong sharedMem = (cl_ulong)pMemManager->getSystemSharedMemory(0u);
470472
cl_ulong maxAppAddrSpace = (cl_ulong)pMemManager->getMaxApplicationAddress() + 1ULL;
471473
cl_ulong memSize = std::min(sharedMem, maxAppAddrSpace);
472-
memSize = (cl_ulong)((double)memSize * 0.8);
474+
memSize = (cl_ulong)((double)memSize * memSizePercent);
473475
if (addressing32Bit) {
474-
memSize = std::min(memSize, (uint64_t)(4 * GB * 0.8));
476+
memSize = std::min(memSize, (uint64_t)(4 * GB * memSizePercent));
475477
}
476478
cl_ulong expectedSize = alignDown(memSize, MemoryConstants::pageSize);
477479

@@ -487,13 +489,14 @@ TEST_F(DeviceGetCapsTest, givenDeviceCapsWhenLocalMemoryIsEnabledThenCalculateGl
487489
auto pMemManager = device->getMemoryManager();
488490
auto enabledOcl21Features = device->areOcl21FeaturesEnabled();
489491
bool addressing32Bit = is32bit || (is64bit && (enabledOcl21Features == false)) || DebugManager.flags.Force32bitAddressing.get();
492+
const auto memSizePercent = pMemManager->getPercentOfGlobalMemoryAvailable(device->getRootDeviceIndex());
490493

491494
auto localMem = pMemManager->getLocalMemorySize(0u, static_cast<uint32_t>(device->getDeviceBitfield().to_ulong()));
492495
auto maxAppAddrSpace = pMemManager->getMaxApplicationAddress() + 1;
493496
auto memSize = std::min(localMem, maxAppAddrSpace);
494-
memSize = static_cast<cl_ulong>(memSize * 0.8);
497+
memSize = static_cast<cl_ulong>(memSize * memSizePercent);
495498
if (addressing32Bit) {
496-
memSize = std::min(memSize, static_cast<cl_ulong>(4 * GB * 0.8));
499+
memSize = std::min(memSize, static_cast<cl_ulong>(4 * GB * memSizePercent));
497500
}
498501
cl_ulong expectedSize = alignDown(memSize, MemoryConstants::pageSize);
499502

@@ -1370,6 +1373,7 @@ TEST_F(DeviceGetCapsTest, givenFlagEnabled64kbPagesWhenCallConstructorMemoryMana
13701373
return 0;
13711374
};
13721375
uint64_t getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t deviceBitfield) override { return 0; };
1376+
double getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) override { return 0; }
13731377
AddressRange reserveGpuAddress(size_t size, uint32_t rootDeviceIndex) override {
13741378
return {};
13751379
}

opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4516,4 +4516,16 @@ TEST_F(DrmMemoryManagerTest, givenCustomAlignmentWhenWddmMemoryManagerIsCreatedT
45164516
}
45174517
}
45184518

4519+
TEST_F(DrmMemoryManagerTest, givenDrmManagerWithLocalMemoryWhenGettingGlobalMemoryPercentThenCorrectValueIsReturned) {
4520+
TestedDrmMemoryManager memoryManager(true, false, false, *executionEnvironment);
4521+
uint32_t rootDeviceIndex = 0u;
4522+
EXPECT_EQ(memoryManager.getPercentOfGlobalMemoryAvailable(rootDeviceIndex), 0.95);
4523+
}
4524+
4525+
TEST_F(DrmMemoryManagerTest, givenDrmManagerWithoutLocalMemoryWhenGettingGlobalMemoryPercentThenCorrectValueIsReturned) {
4526+
TestedDrmMemoryManager memoryManager(false, false, false, *executionEnvironment);
4527+
uint32_t rootDeviceIndex = 0u;
4528+
EXPECT_EQ(memoryManager.getPercentOfGlobalMemoryAvailable(rootDeviceIndex), 0.8);
4529+
}
4530+
45194531
} // namespace NEO

opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,3 +2284,9 @@ TEST_F(WddmMemoryManagerSimpleTest, givenCustomAlignmentWhenWddmMemoryManagerIsC
22842284
EXPECT_EQ(expectedAlignments, memoryManager.alignmentSelector.peekCandidateAlignments());
22852285
}
22862286
}
2287+
2288+
TEST_F(WddmMemoryManagerSimpleTest, givenWddmMemoryManagerWhenGettingGlobalMemoryPercentThenCorrectValueIsReturned) {
2289+
MockWddmMemoryManager memoryManager(true, true, *executionEnvironment);
2290+
uint32_t rootDeviceIndex = 0u;
2291+
EXPECT_EQ(memoryManager.getPercentOfGlobalMemoryAvailable(rootDeviceIndex), 0.8);
2292+
}

shared/source/device/device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ double Device::getPercentOfGlobalMemoryAvailable() const {
528528
if (DebugManager.flags.ClDeviceGlobalMemSizeAvailablePercent.get() != -1) {
529529
return 0.01 * static_cast<double>(DebugManager.flags.ClDeviceGlobalMemSizeAvailablePercent.get());
530530
}
531-
return 0.8;
531+
return getMemoryManager()->getPercentOfGlobalMemoryAvailable(this->getRootDeviceIndex());
532532
}
533533

534534
NEO::SourceLevelDebugger *Device::getSourceLevelDebugger() {

shared/source/memory_manager/memory_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class MemoryManager {
128128

129129
virtual uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) = 0;
130130
virtual uint64_t getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t deviceBitfield) = 0;
131+
virtual double getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) = 0;
131132

132133
uint64_t getMaxApplicationAddress() { return is64bit ? MemoryConstants::max64BitAppAddress : MemoryConstants::max32BitAppAddress; };
133134
MOCKABLE_VIRTUAL uint64_t getInternalHeapBaseAddress(uint32_t rootDeviceIndex, bool useLocalMemory) { return getGfxPartition(rootDeviceIndex)->getHeapBase(selectInternalHeap(useLocalMemory)); }

shared/source/memory_manager/os_agnostic_memory_manager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,10 @@ uint64_t OsAgnosticMemoryManager::getLocalMemorySize(uint32_t rootDeviceIndex, u
499499
return AubHelper::getMemBankSize(executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo());
500500
}
501501

502+
double OsAgnosticMemoryManager::getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) {
503+
return 0.8;
504+
}
505+
502506
void MemoryAllocation::overrideMemoryPool(MemoryPool::Type pool) {
503507
if (DebugManager.flags.AUBDumpForceAllToLocalMemory.get()) {
504508
this->memoryPool = MemoryPool::LocalMemory;

shared/source/memory_manager/os_agnostic_memory_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class OsAgnosticMemoryManager : public MemoryManager {
8181

8282
uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override;
8383
uint64_t getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t deviceBitfield) override;
84+
double getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) override;
8485

8586
void turnOnFakingBigAllocations();
8687

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,13 @@ uint64_t DrmMemoryManager::getSystemSharedMemory(uint32_t rootDeviceIndex) {
799799
return std::min(hostMemorySize, gpuMemorySize);
800800
}
801801

802+
double DrmMemoryManager::getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) {
803+
if (isLocalMemorySupported(rootDeviceIndex)) {
804+
return 0.95;
805+
}
806+
return 0.8;
807+
}
808+
802809
MemoryManager::AllocationStatus DrmMemoryManager::populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) {
803810
BufferObject *allocatedBos[maxFragmentsCount];
804811
uint32_t numberOfBosAllocated = 0;

0 commit comments

Comments
 (0)