Skip to content

Commit c2f5fcc

Browse files
downorCompute-Runtime-Automation
authored andcommitted
DrmAllocation with correct pair of cpu address and gpu address
correct mapping of cpu and gpu address in memory allocation in case of NonSVM. Also, used only aligned address since offset is already calculated and written to "allocationOffset". gpuBaseAddress is programmed with 0 instead of base address of heap because it represents GPU's address space. v2: add allocationOffset to the aligned address in allocation data to point to exact starting address of buffer in two NonSVM allocation unit tests Change-Id: I32ef512de64a13459b7c132672f837c5cb210ada Signed-off-by: dongwonk <dongwon.kim@intel.com>
1 parent 0240f23 commit c2f5fcc

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

runtime/os_interface/linux/drm_memory_manager.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,12 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(size_t s
269269
bo->isAllocated = false;
270270
bo->setUnmapSize(alignedSize);
271271
bo->address = reinterpret_cast<void *>(gpuVirtualAddress);
272-
uintptr_t offset = (uintptr_t)bo->address;
273-
bo->softPin((uint64_t)offset);
272+
bo->softPin((uint64_t)bo->address);
274273
bo->setAllocationType(allocType);
275274

276-
auto allocation = new DrmAllocation(bo, cpuPtr, reinterpret_cast<uint64_t>(alignedPtr), size, MemoryPool::System4KBPages, false);
275+
auto allocation = new DrmAllocation(bo, alignedPtr, gpuVirtualAddress, size, MemoryPool::System4KBPages, false);
277276
allocation->allocationOffset = offsetInPage;
278-
allocation->gpuBaseAddress = limitedGpuAddressRangeAllocator->getBase();
277+
allocation->gpuBaseAddress = 0;
279278

280279
return allocation;
281280
}

unit_tests/os_interface/linux/drm_memory_manager_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,7 +2801,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenAllocateGraphicsMemoryForN
28012801
auto allocation = memoryManager->allocateGraphicsMemoryForNonSvmHostPtr(13, hostPtr);
28022802

28032803
EXPECT_NE(nullptr, allocation);
2804-
EXPECT_EQ(reinterpret_cast<void *>(0x5001), allocation->getUnderlyingBuffer());
2804+
EXPECT_EQ(0x5001u, reinterpret_cast<uint64_t>(allocation->getUnderlyingBuffer()) + allocation->allocationOffset);
28052805
EXPECT_EQ(13u, allocation->getUnderlyingBufferSize());
28062806
EXPECT_EQ(1u, allocation->allocationOffset);
28072807

@@ -3069,7 +3069,7 @@ TEST_F(DrmMemoryManagerTest, givenDisabledHostPtrTrackingWhenAllocateGraphicsMem
30693069
auto allocation = memoryManager->allocateGraphicsMemoryForNonSvmHostPtr(13, hostPtr);
30703070

30713071
EXPECT_NE(nullptr, allocation);
3072-
EXPECT_EQ(reinterpret_cast<void *>(0x5001), allocation->getUnderlyingBuffer());
3072+
EXPECT_EQ(0x5001u, reinterpret_cast<uint64_t>(allocation->getUnderlyingBuffer()) + allocation->allocationOffset);
30733073
EXPECT_EQ(13u, allocation->getUnderlyingBufferSize());
30743074
EXPECT_EQ(1u, allocation->allocationOffset);
30753075

0 commit comments

Comments
 (0)