Skip to content

Commit 7728123

Browse files
fix: Do not use 2mb alignment for host ptr allocs
Signed-off-by: Maciej Plewka <[email protected]> Related-To: NEO-9945
1 parent 4704cd4 commit 7728123

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ BufferObject *DrmMemoryManager::createRootDeviceBufferObject(uint32_t rootDevice
121121
if (bo) {
122122
if (isLimitedRange(rootDeviceIndex)) {
123123
auto boSize = bo->peekSize();
124-
bo->setAddress(acquireGpuRange(boSize, rootDeviceIndex, HeapIndex::heapStandard));
124+
bo->setAddress(DrmMemoryManager::acquireGpuRange(boSize, rootDeviceIndex, HeapIndex::heapStandard));
125125
UNRECOVERABLE_IF(boSize < bo->peekSize());
126126
}
127127
} else {
@@ -518,8 +518,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(con
518518
auto offsetInPage = ptrDiff(allocationData.hostPtr, alignedPtr);
519519
auto rootDeviceIndex = allocationData.rootDeviceIndex;
520520

521-
alignedSize = alignUp(alignedSize, MemoryConstants::pageSize2M);
522-
auto gpuVirtualAddress = acquireGpuRangeWithCustomAlignment(alignedSize, rootDeviceIndex, HeapIndex::heapStandard, MemoryConstants::pageSize2M);
521+
auto gpuVirtualAddress = acquireGpuRange(alignedSize, rootDeviceIndex, HeapIndex::heapStandard);
523522
if (!gpuVirtualAddress) {
524523
return nullptr;
525524
}

shared/source/os_interface/linux/drm_memory_manager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ class DrmMemoryManager : public MemoryManager {
108108
void pushSharedBufferObject(BufferObject *bo);
109109
BufferObject *allocUserptr(uintptr_t address, size_t size, uint32_t rootDeviceIndex);
110110
bool setDomainCpu(GraphicsAllocation &graphicsAllocation, bool writeEnable);
111-
uint64_t acquireGpuRange(size_t &size, uint32_t rootDeviceIndex, HeapIndex heapIndex);
112-
uint64_t acquireGpuRangeWithCustomAlignment(size_t &size, uint32_t rootDeviceIndex, HeapIndex heapIndex, size_t alignment);
111+
MOCKABLE_VIRTUAL uint64_t acquireGpuRange(size_t &size, uint32_t rootDeviceIndex, HeapIndex heapIndex);
112+
MOCKABLE_VIRTUAL uint64_t acquireGpuRangeWithCustomAlignment(size_t &size, uint32_t rootDeviceIndex, HeapIndex heapIndex, size_t alignment);
113113
MOCKABLE_VIRTUAL void releaseGpuRange(void *address, size_t size, uint32_t rootDeviceIndex);
114114
void emitPinningRequest(BufferObject *bo, const AllocationData &allocationData) const;
115115
uint32_t getDefaultDrmContextId(uint32_t rootDeviceIndex) const;

shared/test/common/mocks/linux/mock_drm_memory_manager.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,18 @@ class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> {
147147
}
148148
return DrmMemoryManager::obtainFdFromHandle(boHandle, rootDeviceIndex);
149149
}
150+
uint64_t acquireGpuRange(size_t &size, uint32_t rootDeviceIndex, HeapIndex heapIndex) override {
151+
acquireGpuRangeCalledTimes++;
152+
return DrmMemoryManager::acquireGpuRange(size, rootDeviceIndex, heapIndex);
153+
}
154+
155+
uint64_t acquireGpuRangeWithCustomAlignment(size_t &size, uint32_t rootDeviceIndex, HeapIndex heapIndex, size_t alignment) override {
156+
acquireGpuRangeWithCustomAlignmenCalledTimes++;
157+
return DrmMemoryManager::acquireGpuRangeWithCustomAlignment(size, rootDeviceIndex, heapIndex, alignment);
158+
}
150159

160+
uint32_t acquireGpuRangeCalledTimes = 0u;
161+
uint32_t acquireGpuRangeWithCustomAlignmenCalledTimes = 0u;
151162
ExecutionEnvironment *executionEnvironment = nullptr;
152163

153164
protected:

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,7 +3226,7 @@ TEST_F(DrmMemoryManagerBasic, givenDrmMemoryManagerWhenAllocateGraphicsMemoryFor
32263226
memoryManager->freeGraphicsMemory(allocation1);
32273227
}
32283228

3229-
TEST_F(DrmMemoryManagerBasic, givenDrmMemoryManagerWhenAllocateGraphicsMemoryForNonSvmHostPtrThenGpuVaIsAlignedTo2Mb) {
3229+
TEST_F(DrmMemoryManagerBasic, givenDrmMemoryManagerWhenAllocateGraphicsMemoryForNonSvmHostPtrThenAcquireGpuRangeCalled) {
32303230
AllocationData allocationData;
32313231
allocationData.rootDeviceIndex = rootDeviceIndex;
32323232
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(false, false, false, executionEnvironment));
@@ -3237,10 +3237,8 @@ TEST_F(DrmMemoryManagerBasic, givenDrmMemoryManagerWhenAllocateGraphicsMemoryFor
32373237
allocationData.hostPtr = reinterpret_cast<const void *>(0x1234);
32383238
auto allocation = static_cast<DrmAllocation *>(memoryManager->allocateGraphicsMemoryForNonSvmHostPtr(allocationData));
32393239

3240-
EXPECT_EQ(static_cast<DrmAllocation *>(allocation)->getBO()->peekAddress(), castToUint64(allocation->getReservedAddressPtr()));
3241-
EXPECT_TRUE(isAligned<MemoryConstants::pageSize2M>(static_cast<DrmAllocation *>(allocation)->getBO()->peekAddress()));
3242-
EXPECT_TRUE(isAligned<MemoryConstants::pageSize2M>(allocation->getReservedAddressSize()));
3243-
3240+
EXPECT_EQ(memoryManager->acquireGpuRangeCalledTimes, 1u);
3241+
EXPECT_EQ(memoryManager->acquireGpuRangeWithCustomAlignmenCalledTimes, 0u);
32443242
memoryManager->freeGraphicsMemory(allocation);
32453243
}
32463244

0 commit comments

Comments
 (0)