Skip to content

Commit c8e79b7

Browse files
Change shared allocations required alignment to 64KB.
Signed-off-by: Michal Mrozek <[email protected]>
1 parent c225923 commit c8e79b7

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

opencl/test/unit_test/memory_manager/unified_memory_manager_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ TEST_F(SVMLocalMemoryAllocatorTest, whenSharedAllocationIsCreatedWithDebugFlagSe
355355
EXPECT_EQ(allocationSize, allocation->size);
356356
EXPECT_EQ(mockContext.getDevice(0u), allocation->device->getSpecializedDevice<ClDevice>());
357357

358-
EXPECT_EQ(alignUp(allocationSize, 2u * MB), gpuAllocation->getUnderlyingBufferSize());
359-
EXPECT_EQ(alignUp(allocationSize, 2u * MB), allocation->cpuAllocation->getUnderlyingBufferSize());
358+
EXPECT_EQ(alignUp(allocationSize, 64 * KB), gpuAllocation->getUnderlyingBufferSize());
359+
EXPECT_EQ(alignUp(allocationSize, 64 * KB), allocation->cpuAllocation->getUnderlyingBufferSize());
360360

361361
EXPECT_EQ(GraphicsAllocation::AllocationType::SVM_GPU, gpuAllocation->getAllocationType());
362362
EXPECT_EQ(GraphicsAllocation::AllocationType::SVM_CPU, allocation->cpuAllocation->getAllocationType());
@@ -384,8 +384,8 @@ TEST_F(SVMLocalMemoryAllocatorTest, whenSharedAllocationIsCreatedWithLocalMemory
384384
EXPECT_EQ(InternalMemoryType::SHARED_UNIFIED_MEMORY, allocation->memoryType);
385385
EXPECT_EQ(allocationSize, allocation->size);
386386

387-
EXPECT_EQ(alignUp(allocationSize, 2u * MB), gpuAllocation->getUnderlyingBufferSize());
388-
EXPECT_EQ(alignUp(allocationSize, 2u * MB), allocation->cpuAllocation->getUnderlyingBufferSize());
387+
EXPECT_EQ(alignUp(allocationSize, 64 * KB), gpuAllocation->getUnderlyingBufferSize());
388+
EXPECT_EQ(alignUp(allocationSize, 64 * KB), allocation->cpuAllocation->getUnderlyingBufferSize());
389389

390390
EXPECT_EQ(GraphicsAllocation::AllocationType::SVM_GPU, gpuAllocation->getAllocationType());
391391
EXPECT_EQ(GraphicsAllocation::AllocationType::SVM_CPU, allocation->cpuAllocation->getAllocationType());

shared/source/memory_manager/os_agnostic_memory_manager.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,32 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment
7070
return memoryAllocation;
7171
}
7272

73+
auto alignment = allocationData.alignment;
74+
if (allocationData.type == GraphicsAllocation::AllocationType::SVM_CPU) {
75+
alignment = MemoryConstants::pageSize2Mb;
76+
sizeAligned = alignUp(allocationData.size, MemoryConstants::pageSize2Mb);
77+
}
78+
7379
if (allocationData.type == GraphicsAllocation::AllocationType::DEBUG_CONTEXT_SAVE_AREA) {
7480
sizeAligned *= allocationData.storageInfo.getNumBanks();
7581
}
7682

77-
auto ptr = allocateSystemMemory(sizeAligned, allocationData.alignment ? alignUp(allocationData.alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize);
83+
auto ptr = allocateSystemMemory(sizeAligned, alignment ? alignUp(alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize);
7884
if (ptr != nullptr) {
7985
memoryAllocation = createMemoryAllocation(allocationData.type, ptr, ptr, reinterpret_cast<uint64_t>(ptr), allocationData.size,
8086
counter, MemoryPool::System4KBPages, allocationData.rootDeviceIndex, allocationData.flags.uncacheable, allocationData.flags.flushL3, false);
8187

8288
if (allocationData.type == GraphicsAllocation::AllocationType::SVM_CPU) {
83-
//add 2MB padding in case mapPtr is not 2MB aligned
84-
size_t reserveSize = sizeAligned + allocationData.alignment;
89+
//add padding in case mapPtr is not aligned
90+
size_t reserveSize = sizeAligned + alignment;
8591
void *gpuPtr = reserveCpuAddressRange(reserveSize, allocationData.rootDeviceIndex);
8692
if (!gpuPtr) {
8793
delete memoryAllocation;
8894
alignedFreeWrapper(ptr);
8995
return nullptr;
9096
}
9197
memoryAllocation->setReservedAddressRange(gpuPtr, reserveSize);
92-
gpuPtr = alignUp(gpuPtr, allocationData.alignment);
98+
gpuPtr = alignUp(gpuPtr, alignment);
9399
memoryAllocation->setCpuPtrAndGpuAddress(ptr, reinterpret_cast<uint64_t>(gpuPtr));
94100
}
95101

@@ -436,7 +442,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryInDevicePool(
436442
adjustedAllocationData.alignment = MemoryConstants::pageSize64k;
437443
allocation = static_cast<MemoryAllocation *>(allocate32BitGraphicsMemoryImpl(adjustedAllocationData, true));
438444
} else if (allocationData.type == GraphicsAllocation::AllocationType::SVM_GPU) {
439-
auto storage = allocateSystemMemory(allocationData.size, allocationData.alignment);
445+
auto storage = allocateSystemMemory(allocationData.size, MemoryConstants::pageSize2Mb);
440446
allocation = new MemoryAllocation(allocationData.rootDeviceIndex, numHandles, allocationData.type, storage, storage, reinterpret_cast<uint64_t>(allocationData.hostPtr),
441447
allocationData.size, counter, MemoryPool::LocalMemory, false, allocationData.flags.flushL3, maxOsContextCount);
442448
counter++;

shared/source/memory_manager/unified_memory_manager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,14 @@ void *SVMAllocsManager::createUnifiedAllocationWithDeviceStorage(size_t size, co
396396
auto rootDeviceIndex = unifiedMemoryProperties.device
397397
? unifiedMemoryProperties.device->getRootDeviceIndex()
398398
: *unifiedMemoryProperties.rootDeviceIndices.begin();
399-
size_t alignedSize = alignUp<size_t>(size, 2 * MemoryConstants::megaByte);
399+
size_t alignedSize = alignUp<size_t>(size, MemoryConstants::pageSize64k);
400400
DeviceBitfield subDevices = unifiedMemoryProperties.subdeviceBitfields.at(rootDeviceIndex);
401401
AllocationProperties cpuProperties{rootDeviceIndex,
402402
true, // allocateMemory
403403
alignedSize, GraphicsAllocation::AllocationType::SVM_CPU,
404404
false, // isMultiStorageAllocation
405405
subDevices};
406-
cpuProperties.alignment = 2 * MemoryConstants::megaByte;
406+
cpuProperties.alignment = MemoryConstants::pageSize64k;
407407
auto cacheRegion = MemoryPropertiesHelper::getCacheRegion(unifiedMemoryProperties.allocationFlags);
408408
MemoryPropertiesHelper::fillCachePolicyInProperties(cpuProperties, false, svmProperties.readOnly, false, cacheRegion);
409409
GraphicsAllocation *allocationCpu = memoryManager->allocateGraphicsMemoryWithProperties(cpuProperties);
@@ -432,7 +432,7 @@ void *SVMAllocsManager::createUnifiedAllocationWithDeviceStorage(size_t size, co
432432
multiStorageAllocation,
433433
subDevices};
434434

435-
gpuProperties.alignment = 2 * MemoryConstants::megaByte;
435+
gpuProperties.alignment = MemoryConstants::pageSize64k;
436436
MemoryPropertiesHelper::fillCachePolicyInProperties(gpuProperties, false, svmProperties.readOnly, false, cacheRegion);
437437
GraphicsAllocation *allocationGpu = memoryManager->allocateGraphicsMemoryWithProperties(gpuProperties, svmPtr);
438438
if (!allocationGpu) {

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryWithAlignmentImpl(const A
268268
size_t alignedVirtualAdressRangeSize = cSize;
269269
auto svmCpuAllocation = allocationData.type == GraphicsAllocation::AllocationType::SVM_CPU;
270270
if (svmCpuAllocation) {
271-
//add 2MB padding in case reserved addr is not 2MB aligned
271+
//add padding in case reserved addr is not aligned
272272
alignedStorageSize = alignUp(cSize, cAlignment);
273273
alignedVirtualAdressRangeSize = alignedStorageSize + cAlignment;
274274
}

shared/source/os_interface/windows/wddm_memory_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ GraphicsAllocation *WddmMemoryManager::allocateSystemMemoryAndCreateGraphicsAllo
241241
wddmAllocation->setDefaultGmm(gmm);
242242
void *mapPtr = wddmAllocation->getAlignedCpuPtr();
243243
if (allocationData.type == GraphicsAllocation::AllocationType::SVM_CPU) {
244-
//add 2MB padding in case mapPtr is not 2MB aligned
244+
//add padding in case mapPtr is not aligned
245245
size_t reserveSizeAligned = sizeAligned + allocationData.alignment;
246246
bool ret = getWddm(wddmAllocation->getRootDeviceIndex()).reserveValidAddressRange(reserveSizeAligned, mapPtr);
247247
if (!ret) {

0 commit comments

Comments
 (0)