fix: support alignments in device and shared memory allocation on WSL2

Related-To: LOCI-4334

Signed-off-by: Lu, Wenbin <wenbin.lu@intel.com>
This commit is contained in:
Lu, Wenbin
2023-09-06 23:46:05 +00:00
committed by Compute-Runtime-Automation
parent ac7cd9c4c5
commit dd46bf1e90
2 changed files with 53 additions and 7 deletions

View File

@@ -368,6 +368,28 @@ TEST_F(WddmMemoryManagerTests, givenAllocateGraphicsMemoryUsingKmdAndMapItToCpuV
EXPECT_GT(reinterpret_cast<MockGmmClientContextBase *>(gmmHelper->getClientContext())->freeGpuVirtualAddressCalled, 0u);
}
TEST_F(WddmMemoryManagerTests, givenAllocateGraphicsMemoryUsingKmdAndMapItToCpuVAWhenCreatingHostAllocationThenCpuAddressIsAligned) {
NEO::AllocationData allocData{};
allocData.type = NEO::AllocationType::BUFFER_HOST_MEMORY;
allocData.size = 1;
allocData.makeGPUVaDifferentThanCPUPtr = true;
allocData.allocationMethod = GfxMemoryAllocationMethod::AllocateByKmd;
memoryManager->callBaseAllocateGraphicsMemoryUsingKmdAndMapItToCpuVA = true;
size_t alignment = 8 * MemoryConstants::megaByte;
do {
alignment >>= 1;
allocData.alignment = alignment;
auto graphicsAllocation = memoryManager->allocateGraphicsMemoryUsingKmdAndMapItToCpuVA(allocData, true);
void *ptr = graphicsAllocation->getUnderlyingBuffer();
EXPECT_NE(nullptr, ptr);
if (alignment != 0) {
EXPECT_EQ(reinterpret_cast<uintptr_t>(ptr) & (~(alignment - 1)), reinterpret_cast<uintptr_t>(ptr));
}
memoryManager->freeGraphicsMemory(graphicsAllocation);
} while (alignment != 0);
}
TEST_F(WddmMemoryManagerAllocPathTests, givenAllocateGraphicsMemoryUsingKmdAndMapItToCpuVAWhen32bitThenProperAddressSet) {
if constexpr (is64bit) {
GTEST_SKIP();
@@ -1489,6 +1511,30 @@ TEST_F(WddmMemoryManagerSimpleTest, whenAlignmentRequirementExceedsPageSizeThenA
}
}
TEST_F(WddmMemoryManagerSimpleTest, givenAlignmentWhenAllocatingGraphicsAllocationInDevicePoolThenAllocationIsAligned) {
const bool enable64kbPages = false;
const bool localMemoryEnabled = true;
memoryManager = std::make_unique<MockWddmMemoryManager>(enable64kbPages, localMemoryEnabled, executionEnvironment);
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Error;
AllocationData allocData{};
allocData.allFlags = 0;
allocData.size = 1;
allocData.flags.allocateMemory = true;
size_t alignment = 8 * MemoryConstants::megaByte;
do {
alignment >>= 1;
allocData.alignment = alignment;
auto allocation = memoryManager->allocateGraphicsMemoryInDevicePool(allocData, status);
EXPECT_EQ(MemoryManager::AllocationStatus::Success, status);
EXPECT_NE(nullptr, allocation);
EXPECT_EQ(MemoryPool::LocalMemory, allocation->getMemoryPool());
EXPECT_LE(alignment, allocation->getUnderlyingBufferSize());
memoryManager->freeGraphicsMemory(allocation);
} while (alignment != 0);
}
TEST_F(WddmMemoryManagerSimpleTest, givenUseSystemMemorySetToTrueWhenAllocateInDevicePoolIsCalledThenNullptrIsReturned) {
memoryManager.reset(new MockWddmMemoryManager(false, false, executionEnvironment));
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;