diff --git a/level_zero/core/source/context/context_imp.cpp b/level_zero/core/source/context/context_imp.cpp index a8fff83fd3..be67707eed 100644 --- a/level_zero/core/source/context/context_imp.cpp +++ b/level_zero/core/source/context/context_imp.cpp @@ -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(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(*ptr); diff --git a/level_zero/core/source/helpers/properties_parser.h b/level_zero/core/source/helpers/properties_parser.h index 0425d9d9dc..9e1c1e2e01 100644 --- a/level_zero/core/source/helpers/properties_parser.h +++ b/level_zero/core/source/helpers/properties_parser.h @@ -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; } diff --git a/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp b/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp index 9c4b337156..4094d7c1c3 100644 --- a/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp +++ b/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp @@ -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(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(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,