fix: Add alignment support to createUnifiedMemoryAllocation

Allows the user to use alignments > 64KB in `createUnifiedMemoryAllocation`

So that the restriction in `piextUSMDeviceAlloc` of the DPC++ runtime
could be lifted

Related-To: LOCI-4168

Signed-off-by: Lu, Wenbin <wenbin.lu@intel.com>
This commit is contained in:
Lu, Wenbin
2023-03-31 14:23:21 +00:00
committed by Compute-Runtime-Automation
parent 74205f3f37
commit 5d653c8536
24 changed files with 164 additions and 101 deletions

View File

@@ -116,6 +116,7 @@ ze_result_t ContextImp::allocHostMem(const ze_host_mem_alloc_desc_t *hostDesc,
}
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::HOST_UNIFIED_MEMORY,
alignment,
this->rootDeviceIndices,
this->deviceBitfields);
@@ -220,7 +221,7 @@ ze_result_t ContextImp::allocDeviceMem(ze_device_handle_t hDevice,
}
deviceBitfields[rootDeviceIndex] = neoDevice->getDeviceBitfield();
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, this->driverHandle->rootDeviceIndices, deviceBitfields);
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, alignment, this->driverHandle->rootDeviceIndices, deviceBitfields);
unifiedMemoryProperties.allocationFlags.flags.shareable = isShareableMemory(deviceDesc->pNext, static_cast<uint32_t>(lookupTable.exportMemory), neoDevice);
unifiedMemoryProperties.device = neoDevice;
unifiedMemoryProperties.allocationFlags.flags.compressedHint = isAllocationSuitableForCompression(lookupTable, *device, size);
@@ -319,6 +320,7 @@ ze_result_t ContextImp::allocSharedMem(ze_device_handle_t hDevice,
}
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::SHARED_UNIFIED_MEMORY,
alignment,
this->rootDeviceIndices,
deviceBitfields);
unifiedMemoryProperties.device = unifiedMemoryPropertiesDevice;

View File

@@ -24,6 +24,7 @@ TEST_F(AUBHelloWorldL0, whenAppendMemoryCopyIsCalledThenMemoryIsProperlyCopied)
uint8_t val = 255;
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::HOST_UNIFIED_MEMORY,
1,
context->rootDeviceIndices,
context->deviceBitfields);

View File

@@ -70,6 +70,7 @@ HWTEST_F(L0BindlessAub, DISABLED_GivenBindlessKernelWhenExecutedThenOutputIsCorr
NEO::DebugManager.flags.UpdateCrossThreadDataSize.set(true);
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::HOST_UNIFIED_MEMORY,
1,
context->rootDeviceIndices,
context->deviceBitfields);

View File

@@ -57,6 +57,7 @@ TEST_F(AUBAppendKernelIndirectL0, whenAppendKernelIndirectThenGlobalWorkSizeIsPr
uint8_t size = 3 * sizeof(uint32_t);
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::HOST_UNIFIED_MEMORY,
1,
context->rootDeviceIndices,
context->deviceBitfields);
@@ -101,6 +102,7 @@ TEST_F(AUBAppendKernelIndirectL0, whenAppendKernelIndirectThenGroupCountIsProper
uint8_t size = 3 * sizeof(uint32_t);
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::HOST_UNIFIED_MEMORY,
1,
context->rootDeviceIndices,
context->deviceBitfields);
@@ -141,6 +143,7 @@ TEST_F(AUBAppendKernelIndirectL0, whenAppendKernelIndirectThenGroupCountIsProper
TEST_F(AUBAppendKernelIndirectL0, whenAppendKernelIndirectThenWorkDimIsProperlyProgrammed) {
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::HOST_UNIFIED_MEMORY,
1,
context->rootDeviceIndices,
context->deviceBitfields);

View File

@@ -89,6 +89,7 @@ HWTEST2_F(DebuggerSingleAddressSpaceAub, GivenSingleAddressSpaceWhenCmdListIsExe
NEO::DebugManager.flags.UpdateCrossThreadDataSize.set(true);
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::HOST_UNIFIED_MEMORY,
1,
context->rootDeviceIndices,
context->deviceBitfields);

View File

@@ -45,7 +45,7 @@ ze_result_t Mock<DriverHandle>::getDevice(uint32_t *pCount, ze_device_handle_t *
ze_result_t Mock<DriverHandle>::allocDeviceMem(ze_device_handle_t hDevice, const ze_device_mem_alloc_desc_t *deviceDesc,
size_t size, size_t alignment, void **ptr) {
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, rootDeviceIndices, deviceBitfields);
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, alignment, rootDeviceIndices, deviceBitfields);
auto allocation = svmAllocsManager->createUnifiedMemoryAllocation(size, unifiedMemoryProperties);

View File

@@ -835,7 +835,7 @@ HWTEST_F(ContextMakeMemoryResidentAndMigrationTests,
RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, mockDeviceBitfield}};
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::SHARED_UNIFIED_MEMORY, rootDeviceIndices, deviceBitfields);
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::SHARED_UNIFIED_MEMORY, 1, rootDeviceIndices, deviceBitfields);
auto sharedPtr = svmManager->createSharedUnifiedMemoryAllocation(4096u, unifiedMemoryProperties, device);
EXPECT_NE(nullptr, sharedPtr);

View File

@@ -1170,6 +1170,30 @@ TEST_F(ZexHostPointerTests, whenAllocatingSharedMemoryWithUseHostPtrFlagThenCrea
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
}
TEST_F(MemoryTest, whenAllocatingDeviceMemoryThenAlignmentIsPassedCorrectly) {
const size_t size = 1;
ze_device_mem_alloc_desc_t deviceDesc = {};
deviceDesc.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC;
deviceDesc.pNext = nullptr;
auto memoryManager = static_cast<MockMemoryManager *>(neoDevice->getMemoryManager());
size_t alignment = 8 * MemoryConstants::megaByte;
do {
alignment >>= 1;
memoryManager->validateAllocateProperties = [alignment](const AllocationProperties &properties) {
EXPECT_EQ(properties.alignment, alignUp<size_t>(alignment, MemoryConstants::pageSize64k));
};
void *ptr = nullptr;
ze_result_t result = context->allocDeviceMem(device->toHandle(), &deviceDesc, size, alignment, &ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_NE(nullptr, ptr);
result = context->freeMem(ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
} while (alignment != 0);
}
TEST_F(MemoryTest, whenAllocatingSharedMemoryWithDeviceInitialPlacementBiasFlagThenFlagsAreSetupCorrectly) {
size_t size = 10;
size_t alignment = 1u;