Implement initial placement for shared allocations in L0

The following flags are now respected:
- ZE_DEVICE_MEM_ALLOC_FLAG_BIAS_INITIAL_PLACEMENT
- ZE_HOST_MEM_ALLOC_FLAG_BIAS_INITIAL_PLACEMENT

Related-To: NEO-5059
Signed-off-by: Maciej Dziuban <maciej.dziuban@intel.com>
This commit is contained in:
Maciej Dziuban
2021-06-29 13:12:29 +00:00
committed by Compute-Runtime-Automation
parent 18b06eb345
commit 95dd2828f5
2 changed files with 58 additions and 0 deletions

View File

@@ -227,6 +227,14 @@ ze_result_t ContextImp::allocSharedMem(ze_device_handle_t hDevice,
unifiedMemoryProperties.allocationFlags.flags.locallyUncachedResource = 1;
}
if (deviceDesc->flags & ZE_DEVICE_MEM_ALLOC_FLAG_BIAS_INITIAL_PLACEMENT) {
unifiedMemoryProperties.allocationFlags.allocFlags.usmInitialPlacementGpu = 1;
}
if (hostDesc->flags & ZE_HOST_MEM_ALLOC_FLAG_BIAS_INITIAL_PLACEMENT) {
unifiedMemoryProperties.allocationFlags.allocFlags.usmInitialPlacementCpu = 1;
}
auto usmPtr =
this->driverHandle->svmAllocsManager->createSharedUnifiedMemoryAllocation(size,
unifiedMemoryProperties,

View File

@@ -100,6 +100,56 @@ TEST_F(MemoryTest, whenAllocatingSharedMemoryWithUncachedFlagThenLocallyUncached
ASSERT_EQ(result, ZE_RESULT_SUCCESS);
}
TEST_F(MemoryTest, whenAllocatingSharedMemoryWithDeviceInitialPlacementBiasFlagThenFlagsAreSetupCorrectly) {
size_t size = 10;
size_t alignment = 1u;
void *ptr = nullptr;
ze_device_mem_alloc_desc_t deviceDesc = {};
deviceDesc.flags = ZE_DEVICE_MEM_ALLOC_FLAG_BIAS_INITIAL_PLACEMENT;
ze_host_mem_alloc_desc_t hostDesc = {};
ze_result_t result = context->allocSharedMem(device->toHandle(),
&deviceDesc,
&hostDesc,
size, alignment, &ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_NE(nullptr, ptr);
auto allocData = driverHandle->getSvmAllocsManager()->getSVMAlloc(ptr);
EXPECT_NE(nullptr, allocData);
EXPECT_EQ(0u, allocData->allocationFlagsProperty.allocFlags.usmInitialPlacementCpu);
EXPECT_EQ(1u, allocData->allocationFlagsProperty.allocFlags.usmInitialPlacementGpu);
result = context->freeMem(ptr);
ASSERT_EQ(result, ZE_RESULT_SUCCESS);
}
TEST_F(MemoryTest, whenAllocatingSharedMemoryWithHostInitialPlacementBiasFlagThenFlagsAreSetupCorrectly) {
size_t size = 10;
size_t alignment = 1u;
void *ptr = nullptr;
ze_device_mem_alloc_desc_t deviceDesc = {};
ze_host_mem_alloc_desc_t hostDesc = {};
hostDesc.flags = ZE_HOST_MEM_ALLOC_FLAG_BIAS_INITIAL_PLACEMENT;
ze_result_t result = context->allocSharedMem(device->toHandle(),
&deviceDesc,
&hostDesc,
size, alignment, &ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_NE(nullptr, ptr);
auto allocData = driverHandle->getSvmAllocsManager()->getSVMAlloc(ptr);
EXPECT_NE(nullptr, allocData);
EXPECT_EQ(1u, allocData->allocationFlagsProperty.allocFlags.usmInitialPlacementCpu);
EXPECT_EQ(0u, allocData->allocationFlagsProperty.allocFlags.usmInitialPlacementGpu);
result = context->freeMem(ptr);
ASSERT_EQ(result, ZE_RESULT_SUCCESS);
}
struct SVMAllocsManagerOutOFMemoryMock : public NEO::SVMAllocsManager {
SVMAllocsManagerOutOFMemoryMock(MemoryManager *memoryManager) : NEO::SVMAllocsManager(memoryManager, false) {}
void *createUnifiedMemoryAllocation(size_t size,