Support ray tracing memory allocation extension in L0.

Related-To: NEO-5579

Signed-off-by: Jim Snow <jim.m.snow@intel.com>
This commit is contained in:
Jim Snow
2022-07-27 06:51:10 +00:00
committed by Compute-Runtime-Automation
parent 8a6cf4fd4e
commit 8e9242dc92
3 changed files with 67 additions and 1 deletions

View File

@ -177,6 +177,10 @@ ze_result_t ContextImp::allocDeviceMem(ze_device_handle_t hDevice,
unifiedMemoryProperties.allocationFlags.flags.locallyUncachedResource = 1;
}
if (lookupTable.rayTracingMemory == true) {
unifiedMemoryProperties.allocationFlags.flags.resource48Bit = 1;
}
void *usmPtr =
this->driverHandle->svmAllocsManager->createUnifiedMemoryAllocation(size, unifiedMemoryProperties);
if (usmPtr == nullptr) {
@ -204,6 +208,8 @@ ze_result_t ContextImp::allocSharedMem(ze_device_handle_t hDevice,
auto neoDevice = device->getNEODevice();
bool relaxedSizeAllowed = NEO::DebugManager.flags.AllowUnrestrictedSize.get();
bool rayTracingAllocation = false;
if (deviceDesc->pNext) {
const ze_base_desc_t *extendedDesc = reinterpret_cast<const ze_base_desc_t *>(deviceDesc->pNext);
if (extendedDesc->stype == ZE_STRUCTURE_TYPE_RELAXED_ALLOCATION_LIMITS_EXP_DESC) {
@ -213,6 +219,8 @@ ze_result_t ContextImp::allocSharedMem(ze_device_handle_t hDevice,
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
relaxedSizeAllowed = true;
} else if (extendedDesc->stype == ZE_STRUCTURE_TYPE_RAYTRACING_MEM_ALLOC_EXT_DESC) {
rayTracingAllocation = true;
}
}
@ -265,6 +273,10 @@ ze_result_t ContextImp::allocSharedMem(ze_device_handle_t hDevice,
unifiedMemoryProperties.allocationFlags.allocFlags.usmInitialPlacementCpu = 1;
}
if (rayTracingAllocation) {
unifiedMemoryProperties.allocationFlags.flags.resource48Bit = 1;
}
void *usmPtr = nullptr;
if (hostDesc->flags & ZEX_HOST_MEM_ALLOC_FLAG_USE_HOST_PTR) {
unifiedMemoryProperties.allocationFlags.hostptr = reinterpret_cast<uintptr_t>(*ptr);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Intel Corporation
* Copyright (C) 2021-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -71,6 +71,7 @@ struct StructuresLookupTable {
bool relaxedSizeAllowed;
bool compressedHint;
bool uncompressedHint;
bool rayTracingMemory;
};
inline ze_result_t prepareL0StructuresLookupTable(StructuresLookupTable &lookupTable, const void *desc) {
@ -132,6 +133,8 @@ inline ze_result_t prepareL0StructuresLookupTable(StructuresLookupTable &lookupT
} else {
return ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
} else if (extendedDesc->stype == ZE_STRUCTURE_TYPE_RAYTRACING_MEM_ALLOC_EXT_DESC) {
lookupTable.rayTracingMemory = true;
} else {
return ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}

View File

@ -754,6 +754,57 @@ TEST_F(MemoryTest, whenAllocatingHostMemoryWithUseHostPtrFlagThenExternalHostPtr
ASSERT_EQ(result, ZE_RESULT_SUCCESS);
}
TEST_F(MemoryTest, whenAllocatingSharedMemoryAsRayTracingAllocationAddressIsIn48Bits) {
size_t size = 10;
size_t alignment = 1u;
void *ptr = reinterpret_cast<void *>(0x1234);
ze_device_mem_alloc_desc_t deviceDesc = {};
ze_host_mem_alloc_desc_t hostDesc = {};
ze_raytracing_mem_alloc_ext_desc_t rtDesc = {};
rtDesc.stype = ZE_STRUCTURE_TYPE_RAYTRACING_MEM_ALLOC_EXT_DESC;
deviceDesc.pNext = &rtDesc;
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_EQ(allocData->allocationFlagsProperty.hostptr & 0xffff000000000000, 0u);
result = context->freeMem(ptr);
ASSERT_EQ(result, ZE_RESULT_SUCCESS);
}
TEST_F(MemoryTest, whenAllocatingDeviceMemoryAsRayTracingAllocationAddressIsIn48Bits) {
size_t size = 10;
size_t alignment = 1u;
void *ptr = reinterpret_cast<void *>(0x1234);
ze_device_mem_alloc_desc_t deviceDesc = {};
ze_raytracing_mem_alloc_ext_desc_t rtDesc = {};
rtDesc.stype = ZE_STRUCTURE_TYPE_RAYTRACING_MEM_ALLOC_EXT_DESC;
deviceDesc.pNext = &rtDesc;
ze_result_t result = context->allocDeviceMem(device->toHandle(),
&deviceDesc,
size, alignment, &ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_NE(nullptr, ptr);
auto allocData = driverHandle->getSvmAllocsManager()->getSVMAlloc(ptr);
EXPECT_EQ(allocData->allocationFlagsProperty.hostptr & 0xffff000000000000, 0u);
result = context->freeMem(ptr);
ASSERT_EQ(result, ZE_RESULT_SUCCESS);
}
struct SVMAllocsManagerSharedAllocZexPointerMock : public NEO::SVMAllocsManager {
SVMAllocsManagerSharedAllocZexPointerMock(MemoryManager *memoryManager) : NEO::SVMAllocsManager(memoryManager, false) {}
void *createHostUnifiedMemoryAllocation(size_t size,