Skip to content

Commit 70322b8

Browse files
Make enableLocalMemory and enable64kbpages flags root device specific
Change-Id: I2f0c601bae83a1c4b69fb2ee04255e1d73c1ab7f Signed-off-by: Jobczyk, Lukasz <[email protected]>
1 parent ab5449a commit 70322b8

File tree

10 files changed

+38
-29
lines changed

10 files changed

+38
-29
lines changed

core/memory_manager/memory_manager.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,23 @@ uint32_t MemoryManager::maxOsContextCount = 0u;
3636
MemoryManager::MemoryManager(ExecutionEnvironment &executionEnvironment) : executionEnvironment(executionEnvironment), hostPtrManager(std::make_unique<HostPtrManager>()),
3737
multiContextResourceDestructor(std::make_unique<DeferredDeleter>()) {
3838
auto hwInfo = executionEnvironment.getHardwareInfo();
39-
this->localMemorySupported = HwHelper::get(hwInfo->platform.eRenderCoreFamily).getEnableLocalMemory(*hwInfo);
40-
this->enable64kbpages = OSInterface::osEnabled64kbPages && hwInfo->capabilityTable.ftr64KBpages;
41-
if (DebugManager.flags.Enable64kbpages.get() > -1) {
42-
this->enable64kbpages = DebugManager.flags.Enable64kbpages.get() != 0;
43-
}
4439
localMemoryUsageBankSelector.reset(new LocalMemoryUsageBankSelector(getBanksCount()));
4540

41+
bool anyLocalMemorySupported = false;
42+
4643
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < executionEnvironment.rootDeviceEnvironments.size(); ++rootDeviceIndex) {
44+
this->localMemorySupported.push_back(HwHelper::get(hwInfo->platform.eRenderCoreFamily).getEnableLocalMemory(*hwInfo));
45+
this->enable64kbpages.push_back(OSInterface::osEnabled64kbPages && hwInfo->capabilityTable.ftr64KBpages);
46+
if (DebugManager.flags.Enable64kbpages.get() > -1) {
47+
this->enable64kbpages[rootDeviceIndex] = DebugManager.flags.Enable64kbpages.get() != 0;
48+
}
49+
4750
gfxPartitions.push_back(std::make_unique<GfxPartition>());
51+
52+
anyLocalMemorySupported |= this->localMemorySupported[rootDeviceIndex];
4853
}
4954

50-
if (this->localMemorySupported) {
55+
if (anyLocalMemorySupported) {
5156
pageFaultManager = PageFaultManager::create();
5257
}
5358
}
@@ -181,8 +186,12 @@ bool MemoryManager::isAsyncDeleterEnabled() const {
181186
return asyncDeleterEnabled;
182187
}
183188

184-
bool MemoryManager::isLocalMemorySupported() const {
185-
return localMemorySupported;
189+
bool MemoryManager::isLocalMemorySupported(uint32_t rootDeviceIndex) const {
190+
return localMemorySupported[rootDeviceIndex];
191+
}
192+
193+
bool MemoryManager::peek64kbPagesEnabled(uint32_t rootDeviceIndex) const {
194+
return enable64kbpages[rootDeviceIndex];
186195
}
187196

188197
bool MemoryManager::isMemoryBudgetExhausted() const {
@@ -361,7 +370,7 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemory(const AllocationData &
361370
if (allocationData.hostPtr) {
362371
return allocateGraphicsMemoryWithHostPtr(allocationData);
363372
}
364-
if (peek64kbPagesEnabled() && allocationData.flags.allow64kbPages) {
373+
if (peek64kbPagesEnabled(allocationData.rootDeviceIndex) && allocationData.flags.allow64kbPages) {
365374
return allocateGraphicsMemory64kb(allocationData);
366375
}
367376
return allocateGraphicsMemoryWithAlignment(allocationData);

core/memory_manager/memory_manager.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class MemoryManager {
103103

104104
bool isLimitedRange(uint32_t rootDeviceIndex) { return getGfxPartition(rootDeviceIndex)->isLimitedRange(); }
105105

106-
bool peek64kbPagesEnabled() const { return enable64kbpages; }
106+
bool peek64kbPagesEnabled(uint32_t rootDeviceIndex) const;
107107
bool peekForce32BitAllocations() const { return force32bitAllocations; }
108108
void setForce32BitAllocations(bool newValue) { force32bitAllocations = newValue; }
109109

@@ -123,7 +123,7 @@ class MemoryManager {
123123
void cleanTemporaryAllocationListOnAllEngines(bool waitForCompletion);
124124

125125
bool isAsyncDeleterEnabled() const;
126-
bool isLocalMemorySupported() const;
126+
bool isLocalMemorySupported(uint32_t rootDeviceIndex) const;
127127
virtual bool isMemoryBudgetExhausted() const;
128128

129129
virtual AlignedMallocRestrictions *getAlignedMallocRestrictions() {
@@ -237,8 +237,8 @@ class MemoryManager {
237237
bool virtualPaddingAvailable = false;
238238
std::unique_ptr<DeferredDeleter> deferredDeleter;
239239
bool asyncDeleterEnabled = false;
240-
bool enable64kbpages = false;
241-
bool localMemorySupported = false;
240+
std::vector<bool> enable64kbpages;
241+
std::vector<bool> localMemorySupported;
242242
bool supportsMultiStorageResources = true;
243243
ExecutionEnvironment &executionEnvironment;
244244
EngineControlContainer registeredEngines;

core/memory_manager/unified_memory_manager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void *SVMAllocsManager::createSVMAlloc(uint32_t rootDeviceIndex, size_t size, co
8585
return nullptr;
8686

8787
std::unique_lock<SpinLock> lock(mtx);
88-
if (!memoryManager->isLocalMemorySupported()) {
88+
if (!memoryManager->isLocalMemorySupported(rootDeviceIndex)) {
8989
return createZeroCopySvmAllocation(rootDeviceIndex, size, svmProperties);
9090
} else {
9191
return createUnifiedAllocationWithDeviceStorage(rootDeviceIndex, size, svmProperties, {});
@@ -132,7 +132,7 @@ void *SVMAllocsManager::createUnifiedMemoryAllocation(uint32_t rootDeviceIndex,
132132
}
133133

134134
void *SVMAllocsManager::createSharedUnifiedMemoryAllocation(uint32_t rootDeviceIndex, size_t size, const UnifiedMemoryProperties &memoryProperties, void *cmdQ) {
135-
auto supportDualStorageSharedMemory = memoryManager->isLocalMemorySupported();
135+
auto supportDualStorageSharedMemory = memoryManager->isLocalMemorySupported(rootDeviceIndex);
136136

137137
if (DebugManager.flags.AllocateSharedAllocationsWithCpuAndGpuStorage.get() != -1) {
138138
supportDualStorageSharedMemory = !!DebugManager.flags.AllocateSharedAllocationsWithCpuAndGpuStorage.get();

runtime/device/device_caps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ void Device::initializeCaps() {
237237
deviceInfo.globalMemCacheSize = systemInfo.L3BankCount * 128 * KB;
238238
deviceInfo.grfSize = hwInfo.capabilityTable.grfSize;
239239

240-
deviceInfo.globalMemSize = getMemoryManager()->isLocalMemorySupported()
240+
deviceInfo.globalMemSize = getMemoryManager()->isLocalMemorySupported(this->getRootDeviceIndex())
241241
? getMemoryManager()->getLocalMemorySize(this->getRootDeviceIndex())
242242
: getMemoryManager()->getSystemSharedMemory(this->getRootDeviceIndex());
243243
deviceInfo.globalMemSize = std::min(deviceInfo.globalMemSize, (cl_ulong)(getMemoryManager()->getMaxApplicationAddress() + 1));

runtime/mem_obj/buffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,15 @@ Buffer *Buffer::create(Context *context,
149149
bool alignementSatisfied = true;
150150
bool allocateMemory = true;
151151
bool copyMemoryFromHostPtr = false;
152+
auto rootDeviceIndex = context->getDevice(0)->getRootDeviceIndex();
152153
MemoryManager *memoryManager = context->getMemoryManager();
153154
UNRECOVERABLE_IF(!memoryManager);
154155

155156
GraphicsAllocation::AllocationType allocationType = getGraphicsAllocationType(
156157
memoryProperties,
157158
*context,
158159
HwHelper::renderCompressedBuffersSupported(context->getDevice(0)->getHardwareInfo()),
159-
memoryManager->isLocalMemorySupported(),
160+
memoryManager->isLocalMemorySupported(rootDeviceIndex),
160161
HwHelper::get(context->getDevice(0)->getHardwareInfo().platform.eRenderCoreFamily).obtainRenderBufferCompressionPreference(context->getDevice(0)->getHardwareInfo(), size));
161162

162163
checkMemory(memoryProperties, size, hostPtr, errcodeRet, alignementSatisfied, copyMemoryFromHostPtr, memoryManager);
@@ -225,7 +226,6 @@ Buffer *Buffer::create(Context *context,
225226
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_GOOD_INTEL, CL_BUFFER_NEEDS_ALLOCATE_MEMORY);
226227
}
227228

228-
auto rootDeviceIndex = context->getDevice(0)->getRootDeviceIndex();
229229
if (!memory) {
230230
AllocationProperties allocProperties = MemoryPropertiesParser::getAllocationProperties(rootDeviceIndex, memoryProperties, allocateMemory, size, allocationType, context->areMultiStorageAllocationsPreferred());
231231
memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties, hostPtr);

unit_tests/context/driver_diagnostics_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ TEST_F(PerformanceHintTest, givenUncompressedBufferWhenItsCreatedThenProperPerfo
504504
memoryProperties, *context,
505505
HwHelper::get(hwInfo.platform.eRenderCoreFamily).obtainRenderBufferCompressionPreference(hwInfo, size)) &&
506506
!is32bit && !context->isSharedContext &&
507-
(!memoryProperties.flags.useHostPtr || context->getMemoryManager()->isLocalMemorySupported()) &&
507+
(!memoryProperties.flags.useHostPtr || context->getMemoryManager()->isLocalMemorySupported(device->getRootDeviceIndex())) &&
508508
!memoryProperties.flags.forceSharedPhysicalMemory;
509509

510510
buffer = std::unique_ptr<Buffer>(Buffer::create(context.get(), memoryProperties, CL_MEM_READ_WRITE, 0, size, static_cast<void *>(NULL), retVal));

unit_tests/device/device_caps_tests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,30 +1024,30 @@ TEST_F(DeviceGetCapsTest, GivenFlagEnabled64kbPagesWhenSetThenReturnCorrectValue
10241024
capabilityTable.ftr64KBpages = false;
10251025
OSInterface::osEnabled64kbPages = false;
10261026
memoryManager.reset(new OsAgnosticMemoryManager(executionEnvironment));
1027-
EXPECT_FALSE(memoryManager->peek64kbPagesEnabled());
1027+
EXPECT_FALSE(memoryManager->peek64kbPagesEnabled(0u));
10281028

10291029
capabilityTable.ftr64KBpages = false;
10301030
OSInterface::osEnabled64kbPages = true;
10311031
memoryManager.reset(new OsAgnosticMemoryManager(executionEnvironment));
1032-
EXPECT_FALSE(memoryManager->peek64kbPagesEnabled());
1032+
EXPECT_FALSE(memoryManager->peek64kbPagesEnabled(0u));
10331033

10341034
capabilityTable.ftr64KBpages = true;
10351035
OSInterface::osEnabled64kbPages = false;
10361036
memoryManager.reset(new OsAgnosticMemoryManager(executionEnvironment));
1037-
EXPECT_FALSE(memoryManager->peek64kbPagesEnabled());
1037+
EXPECT_FALSE(memoryManager->peek64kbPagesEnabled(0u));
10381038

10391039
capabilityTable.ftr64KBpages = true;
10401040
OSInterface::osEnabled64kbPages = true;
10411041
memoryManager.reset(new OsAgnosticMemoryManager(executionEnvironment));
1042-
EXPECT_TRUE(memoryManager->peek64kbPagesEnabled());
1042+
EXPECT_TRUE(memoryManager->peek64kbPagesEnabled(0u));
10431043

10441044
DebugManager.flags.Enable64kbpages.set(0); // force false
10451045
memoryManager.reset(new OsAgnosticMemoryManager(executionEnvironment));
1046-
EXPECT_FALSE(memoryManager->peek64kbPagesEnabled());
1046+
EXPECT_FALSE(memoryManager->peek64kbPagesEnabled(0u));
10471047

10481048
DebugManager.flags.Enable64kbpages.set(1); // force true
10491049
memoryManager.reset(new OsAgnosticMemoryManager(executionEnvironment));
1050-
EXPECT_TRUE(memoryManager->peek64kbPagesEnabled());
1050+
EXPECT_TRUE(memoryManager->peek64kbPagesEnabled(0u));
10511051
}
10521052

10531053
TEST_F(DeviceGetCapsTest, givenUnifiedMemoryShardeSystemFlagWhenDeviceIsCreatedItContainsProperSystemMemorySetting) {

unit_tests/execution_environment/execution_environment_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerI
141141
auto executionEnvironment = device->getExecutionEnvironment();
142142
auto enableLocalMemory = HwHelper::get(hwInfo->platform.eRenderCoreFamily).getEnableLocalMemory(*hwInfo);
143143
executionEnvironment->initializeMemoryManager();
144-
EXPECT_EQ(enableLocalMemory, executionEnvironment->memoryManager->isLocalMemorySupported());
144+
EXPECT_EQ(enableLocalMemory, executionEnvironment->memoryManager->isLocalMemorySupported(device->getRootDeviceIndex()));
145145
}
146146

147147
TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerIsCalledThenItIsInitalized) {

unit_tests/mocks/mock_memory_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryInDevicePool(const
8080
auto allocation = OsAgnosticMemoryManager::allocateGraphicsMemoryInDevicePool(allocationData, status);
8181
if (allocation) {
8282
allocationInDevicePoolCreated = true;
83-
if (localMemorySupported) {
83+
if (localMemorySupported[allocation->getRootDeviceIndex()]) {
8484
static_cast<MemoryAllocation *>(allocation)->overrideMemoryPool(MemoryPool::LocalMemory);
8585
}
8686
}

unit_tests/mocks/mock_memory_manager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class MemoryManagerCreate : public T {
2323

2424
template <class... U>
2525
MemoryManagerCreate(bool enable64kbPages, bool enableLocalMemory, U &&... args) : T(std::forward<U>(args)...) {
26-
this->enable64kbpages = enable64kbPages;
27-
this->localMemorySupported = enableLocalMemory;
26+
std::fill(this->enable64kbpages.begin(), this->enable64kbpages.end(), enable64kbPages);
27+
std::fill(this->localMemorySupported.begin(), this->localMemorySupported.end(), enableLocalMemory);
2828
}
2929
};
3030

0 commit comments

Comments
 (0)