From ba6d447b4d2d96408d5d0f10a2d148e7914e1982 Mon Sep 17 00:00:00 2001 From: Neil R Spruit Date: Wed, 24 May 2023 02:07:44 +0000 Subject: [PATCH] feature: Support for using Reserved address with multiple mappings Related-To: LOCI-4381 - Enabled support for customers to use full Virtual reservation range with multiple physical mappings with additional allocations implicitly included in residency. - Buffer Surface state size extended for first allocation to stretch to the bufferSize requested. Signed-off-by: Neil R Spruit --- level_zero/core/source/cmdlist/cmdlist_hw.inl | 11 ++ .../core/source/context/context_imp.cpp | 1 + .../core/source/driver/driver_handle_imp.cpp | 9 ++ level_zero/core/source/kernel/kernel_hw.h | 5 + level_zero/core/source/kernel/kernel_imp.cpp | 12 ++ .../sources/cmdlist/test_cmdlist_6.cpp | 90 ++++++++++++++ .../unit_tests/sources/module/test_module.cpp | 116 ++++++++++++++++++ .../memory_manager/graphics_allocation.h | 3 + shared/source/memory_manager/memory_manager.h | 1 - .../memory_manager/unified_memory_manager.h | 3 + .../memory_manager/memory_manager_tests.cpp | 15 +++ 11 files changed, 265 insertions(+), 1 deletion(-) diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.inl b/level_zero/core/source/cmdlist/cmdlist_hw.inl index 6603c9843c..cca1a6c031 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw.inl @@ -2045,6 +2045,17 @@ inline AlignedAllocationData CommandListCoreFamily::getAlignedAll allocData->memoryType == InternalMemoryType::SHARED_UNIFIED_MEMORY) { hostPointerNeedsFlush = true; } + if (allocData->virtualReservationData) { + for (const auto &mappedAllocationData : allocData->virtualReservationData->mappedAllocations) { + // Add additional allocations to the residency container if the virtual reservation spans multiple allocations. + if (buffer != mappedAllocationData.second->ptr) { + commandContainer.addToResidencyContainer(mappedAllocationData.second->mappedAllocation->allocation); + } else if (mappedAllocationData.second->mappedAllocation->allocation->getUnderlyingBufferSize() < allocData->virtualReservationData->virtualAddressRange.size) { + // If the target buffer is the same as the virtual reservation, but the allocation is less than the full reserved size, then extend the size to the full reserved size. + mappedAllocationData.second->mappedAllocation->allocation->setExtendedSize(allocData->virtualReservationData->virtualAddressRange.size); + } + } + } } return {alignedPtr, offset, alloc, hostPointerNeedsFlush}; diff --git a/level_zero/core/source/context/context_imp.cpp b/level_zero/core/source/context/context_imp.cpp index 9f6f7dabb8..8932df5f1f 100644 --- a/level_zero/core/source/context/context_imp.cpp +++ b/level_zero/core/source/context/context_imp.cpp @@ -1067,6 +1067,7 @@ ze_result_t ContextImp::mapVirtualMem(const void *ptr, allocData.pageSizeForAlignment = MemoryConstants::pageSize64k; allocData.setAllocId(this->driverHandle->svmAllocsManager->allocationsCounter++); allocData.memoryType = InternalMemoryType::RESERVED_DEVICE_MEMORY; + allocData.virtualReservationData = virtualMemoryReservation; NEO::MemoryMappedRange *mappedRange = new NEO::MemoryMappedRange; mappedRange->ptr = ptr; mappedRange->size = size; diff --git a/level_zero/core/source/driver/driver_handle_imp.cpp b/level_zero/core/source/driver/driver_handle_imp.cpp index 5efc13edf1..df35698df1 100644 --- a/level_zero/core/source/driver/driver_handle_imp.cpp +++ b/level_zero/core/source/driver/driver_handle_imp.cpp @@ -351,6 +351,15 @@ bool DriverHandleImp::findAllocationDataForRange(const void *buffer, (beginAllocData->gpuAllocations.getDefaultGraphicsAllocation() == endAllocData->gpuAllocations.getDefaultGraphicsAllocation())) { return true; } + bool allocationRangeCovered = false; + // If memory accessed is part of a virtual reservation, then return the first allocation data within the range. + auto allocDataVec = findAllocationsWithinRange(buffer, size, &allocationRangeCovered); + for (const auto &mappedAllocationData : allocDataVec) { + if (mappedAllocationData->virtualReservationData) { + *allocData = mappedAllocationData; + return true; + } + } return false; } diff --git a/level_zero/core/source/kernel/kernel_hw.h b/level_zero/core/source/kernel/kernel_hw.h index 09e02398ac..d792b1db0f 100644 --- a/level_zero/core/source/kernel/kernel_hw.h +++ b/level_zero/core/source/kernel/kernel_hw.h @@ -38,6 +38,11 @@ struct KernelHw : public KernelImp { auto misalignedSize = ptrDiff(alloc->getGpuAddressToPatch(), baseAddress); auto offset = ptrDiff(address, reinterpret_cast(baseAddress)); size_t bufferSizeForSsh = alloc->getUnderlyingBufferSize(); + // If the allocation has been set with an extended size to span other resident allocations, then program that size for the surface state & reset the extended size to 0 in the allocation structure. + if (alloc->getExtendedBufferSize() != 0) { + bufferSizeForSsh = alloc->getExtendedBufferSize(); + alloc->setExtendedSize(0); + } auto argInfo = kernelImmData->getDescriptor().payloadMappings.explicitArgs[argIndex].as(); bool offsetWasPatched = NEO::patchNonPointer(ArrayRef(this->crossThreadData.get(), this->crossThreadDataSize), argInfo.bufferOffset, static_cast(offset)); diff --git a/level_zero/core/source/kernel/kernel_imp.cpp b/level_zero/core/source/kernel/kernel_imp.cpp index 2b3ed74372..06ef415c0e 100644 --- a/level_zero/core/source/kernel/kernel_imp.cpp +++ b/level_zero/core/source/kernel/kernel_imp.cpp @@ -653,6 +653,18 @@ ze_result_t KernelImp::setArgBuffer(uint32_t argIndex, size_t argSize, const voi const uint32_t allocId = allocData ? allocData->getAllocId() : 0u; kernelArgInfos[argIndex] = KernelArgInfo{requestedAddress, allocId, allocationsCounter, false}; + if (allocData && allocData->virtualReservationData) { + for (const auto &mappedAllocationData : allocData->virtualReservationData->mappedAllocations) { + // Add additional allocations to the residency container if the virtual reservation spans multiple allocations. + if (requestedAddress != mappedAllocationData.second->ptr) { + this->residencyContainer.push_back(mappedAllocationData.second->mappedAllocation->allocation); + } else if (mappedAllocationData.second->mappedAllocation->allocation->getUnderlyingBufferSize() < allocData->virtualReservationData->virtualAddressRange.size) { + // If the target buffer is the same as the virtual reservation, but the allocation is less than the full reserved size, then extend the size to the full reserved size. + mappedAllocationData.second->mappedAllocation->allocation->setExtendedSize(allocData->virtualReservationData->virtualAddressRange.size); + } + } + } + return setArgBufferWithAlloc(argIndex, gpuAddress, alloc, peerAllocData); } diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_6.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_6.cpp index 940d8c296a..e850ca18e2 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_6.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_6.cpp @@ -15,6 +15,7 @@ #include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/libult/ult_command_stream_receiver.h" #include "shared/test/common/mocks/mock_command_stream_receiver.h" +#include "shared/test/common/mocks/mock_memory_operations_handler.h" #include "shared/test/common/mocks/ult_device_factory.h" #include "shared/test/common/test_macros/hw_test.h" @@ -774,6 +775,95 @@ HWTEST2_F(CommandListTest, givenComputeCommandListWhenMemoryCopyInUsmDeviceAlloc context->freeMem(dstBuffer); } +HWTEST2_F(CommandListTest, givenComputeCommandListWhenMemoryCopyWithReservedDeviceAllocationThenResidencyContainerHasImplicitMappedAllocations, IsAtLeastSkl) { + auto commandList = std::make_unique>>(); + commandList->initialize(device, NEO::EngineGroupType::RenderCompute, 0u); + + driverHandle->devices[0]->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[0]->memoryOperationsInterface = + std::make_unique(); + + void *dstBuffer = nullptr; + size_t size = MemoryConstants::pageSize64k; + size_t reservationSize = size * 2; + + auto res = context->reserveVirtualMem(nullptr, reservationSize, &dstBuffer); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + ze_physical_mem_desc_t desc = {}; + desc.size = size; + ze_physical_mem_handle_t phPhysicalMemory; + res = context->createPhysicalMem(device->toHandle(), &desc, &phPhysicalMemory); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + ze_physical_mem_handle_t phPhysicalMemory2; + res = context->createPhysicalMem(device->toHandle(), &desc, &phPhysicalMemory2); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + res = context->mapVirtualMem(dstBuffer, size, phPhysicalMemory, 0, ZE_MEMORY_ACCESS_ATTRIBUTE_READWRITE); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + void *offsetAddress = reinterpret_cast(reinterpret_cast(dstBuffer) + size); + res = context->mapVirtualMem(offsetAddress, size, phPhysicalMemory2, 0, ZE_MEMORY_ACCESS_ATTRIBUTE_READWRITE); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + void *srcPtr = reinterpret_cast(0x1234); + + commandList->appendMemoryCopy(dstBuffer, srcPtr, size, nullptr, 0, nullptr, false); + + bool phys2Resident = false; + for (auto alloc : commandList->getCmdContainer().getResidencyContainer()) { + if (alloc && alloc->getGpuAddress() == reinterpret_cast(offsetAddress)) { + phys2Resident = true; + } + } + NEO::GraphicsAllocation *baseAlloc = reinterpret_cast(phPhysicalMemory); + EXPECT_EQ(reservationSize, baseAlloc->getExtendedBufferSize()); + + EXPECT_TRUE(phys2Resident); + res = context->unMapVirtualMem(dstBuffer, size); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + res = context->unMapVirtualMem(offsetAddress, size); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + res = context->freeVirtualMem(dstBuffer, reservationSize); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + res = context->destroyPhysicalMem(phPhysicalMemory); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + res = context->destroyPhysicalMem(phPhysicalMemory2); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); +} + +HWTEST2_F(CommandListTest, givenComputeCommandListWhenMemoryCopyWithOneReservedDeviceAllocationMappedToFullReservationThenExtendedBufferSizeIsZero, IsAtLeastSkl) { + auto commandList = std::make_unique>>(); + commandList->initialize(device, NEO::EngineGroupType::RenderCompute, 0u); + + driverHandle->devices[0]->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[0]->memoryOperationsInterface = + std::make_unique(); + + void *dstBuffer = nullptr; + size_t size = MemoryConstants::pageSize64k; + size_t reservationSize = size * 2; + + auto res = context->reserveVirtualMem(nullptr, reservationSize, &dstBuffer); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + ze_physical_mem_desc_t desc = {}; + desc.size = reservationSize; + ze_physical_mem_handle_t phPhysicalMemory; + res = context->createPhysicalMem(device->toHandle(), &desc, &phPhysicalMemory); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + res = context->mapVirtualMem(dstBuffer, reservationSize, phPhysicalMemory, 0, ZE_MEMORY_ACCESS_ATTRIBUTE_READWRITE); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + void *srcPtr = reinterpret_cast(0x1234); + + commandList->appendMemoryCopy(dstBuffer, srcPtr, reservationSize, nullptr, 0, nullptr, false); + + NEO::GraphicsAllocation *baseAlloc = reinterpret_cast(phPhysicalMemory); + EXPECT_EQ(0u, baseAlloc->getExtendedBufferSize()); + + res = context->unMapVirtualMem(dstBuffer, reservationSize); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + res = context->freeVirtualMem(dstBuffer, reservationSize); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + res = context->destroyPhysicalMem(phPhysicalMemory); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); +} + HWTEST2_F(CommandListTest, givenComputeCommandListWhenMemoryFillInUsmHostThenBuiltinFlagAndDestinationAllocSystemIsSet, IsAtLeastSkl) { auto commandList = std::make_unique>>(); commandList->initialize(device, NEO::EngineGroupType::RenderCompute, 0u); diff --git a/level_zero/core/test/unit_tests/sources/module/test_module.cpp b/level_zero/core/test/unit_tests/sources/module/test_module.cpp index c7f5cb717f..86ed400f26 100644 --- a/level_zero/core/test/unit_tests/sources/module/test_module.cpp +++ b/level_zero/core/test/unit_tests/sources/module/test_module.cpp @@ -25,6 +25,7 @@ #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/mocks/mock_elf.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" +#include "shared/test/common/mocks/mock_memory_operations_handler.h" #include "shared/test/common/mocks/mock_modules_zebin.h" #include "shared/test/common/mocks/mock_source_level_debugger.h" #include "shared/test/common/test_macros/hw_test.h" @@ -2060,6 +2061,121 @@ class MultiDeviceModuleSetArgBufferTest : public MultiDeviceModuleFixture, publi } }; +HWTEST_F(MultiDeviceModuleSetArgBufferTest, + givenCallsToSetArgBufferWithReservedMemoryThenResidencyContainerHasAllMappedAllocations) { + + for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < numRootDevices; rootDeviceIndex++) { + createModuleFromMockBinary(rootDeviceIndex); + auto device = driverHandle->devices[rootDeviceIndex]; + driverHandle->devices[rootDeviceIndex]->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = + std::make_unique(); + + ze_kernel_handle_t kernelHandle; + void *ptr = nullptr; + size_t size = MemoryConstants::pageSize64k; + size_t reservationSize = size * 2; + ze_kernel_desc_t kernelDesc = {}; + kernelDesc.pKernelName = kernelName.c_str(); + ze_result_t res = modules[rootDeviceIndex]->createKernel(&kernelDesc, &kernelHandle); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + res = context->reserveVirtualMem(nullptr, reservationSize, &ptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + ze_physical_mem_desc_t desc = {}; + desc.size = size; + ze_physical_mem_handle_t phPhysicalMemory; + res = context->createPhysicalMem(device->toHandle(), &desc, &phPhysicalMemory); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + ze_physical_mem_handle_t phPhysicalMemory2; + res = context->createPhysicalMem(device->toHandle(), &desc, &phPhysicalMemory2); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + res = context->mapVirtualMem(ptr, size, phPhysicalMemory, 0, ZE_MEMORY_ACCESS_ATTRIBUTE_READWRITE); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + void *offsetAddress = reinterpret_cast(reinterpret_cast(ptr) + size); + res = context->mapVirtualMem(offsetAddress, size, phPhysicalMemory2, 0, ZE_MEMORY_ACCESS_ATTRIBUTE_READWRITE); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + L0::KernelImp *kernel = reinterpret_cast(Kernel::fromHandle(kernelHandle)); + kernel->setArgBuffer(0, sizeof(ptr), &ptr); + + bool phys1Resident = false; + bool phys2Resident = false; + NEO::GraphicsAllocation *baseAlloc = nullptr; + for (auto alloc : kernel->getResidencyContainer()) { + if (alloc && alloc->getGpuAddress() == reinterpret_cast(ptr)) { + phys1Resident = true; + baseAlloc = alloc; + } + if (alloc && alloc->getGpuAddress() == reinterpret_cast(offsetAddress)) { + phys2Resident = true; + } + } + EXPECT_TRUE(phys1Resident); + EXPECT_TRUE(phys2Resident); + res = context->unMapVirtualMem(ptr, size); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + EXPECT_EQ(0u, baseAlloc->getExtendedBufferSize()); + res = context->unMapVirtualMem(offsetAddress, size); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + res = context->freeVirtualMem(ptr, reservationSize); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + res = context->destroyPhysicalMem(phPhysicalMemory); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + res = context->destroyPhysicalMem(phPhysicalMemory2); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + Kernel::fromHandle(kernelHandle)->destroy(); + } +} + +HWTEST_F(MultiDeviceModuleSetArgBufferTest, + givenCallsToSetArgBufferWithReservedMemoryWithMappingToFullReservedSizeThenExtendedBufferSizeIsZero) { + + for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < numRootDevices; rootDeviceIndex++) { + createModuleFromMockBinary(rootDeviceIndex); + auto device = driverHandle->devices[rootDeviceIndex]; + driverHandle->devices[rootDeviceIndex]->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = + std::make_unique(); + + ze_kernel_handle_t kernelHandle; + void *ptr = nullptr; + size_t size = MemoryConstants::pageSize64k; + size_t reservationSize = size * 2; + ze_kernel_desc_t kernelDesc = {}; + kernelDesc.pKernelName = kernelName.c_str(); + ze_result_t res = modules[rootDeviceIndex]->createKernel(&kernelDesc, &kernelHandle); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + res = context->reserveVirtualMem(nullptr, reservationSize, &ptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + ze_physical_mem_desc_t desc = {}; + desc.size = reservationSize; + ze_physical_mem_handle_t phPhysicalMemory; + res = context->createPhysicalMem(device->toHandle(), &desc, &phPhysicalMemory); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + res = context->mapVirtualMem(ptr, reservationSize, phPhysicalMemory, 0, ZE_MEMORY_ACCESS_ATTRIBUTE_READWRITE); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + L0::KernelImp *kernel = reinterpret_cast(Kernel::fromHandle(kernelHandle)); + kernel->setArgBuffer(0, sizeof(ptr), &ptr); + + bool phys1Resident = false; + NEO::GraphicsAllocation *baseAlloc = nullptr; + for (auto alloc : kernel->getResidencyContainer()) { + if (alloc && alloc->getGpuAddress() == reinterpret_cast(ptr)) { + phys1Resident = true; + baseAlloc = alloc; + } + } + EXPECT_TRUE(phys1Resident); + EXPECT_EQ(0u, baseAlloc->getExtendedBufferSize()); + res = context->unMapVirtualMem(ptr, reservationSize); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + res = context->freeVirtualMem(ptr, reservationSize); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + res = context->destroyPhysicalMem(phPhysicalMemory); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + Kernel::fromHandle(kernelHandle)->destroy(); + } +} + HWTEST_F(MultiDeviceModuleSetArgBufferTest, givenCallsToSetArgBufferThenAllocationIsSetForCorrectDevice) { diff --git a/shared/source/memory_manager/graphics_allocation.h b/shared/source/memory_manager/graphics_allocation.h index 299b789055..148da2b465 100644 --- a/shared/source/memory_manager/graphics_allocation.h +++ b/shared/source/memory_manager/graphics_allocation.h @@ -82,6 +82,8 @@ class GraphicsAllocation : public IDNode { } size_t getUnderlyingBufferSize() const { return size; } void setSize(size_t size) { this->size = size; } + void setExtendedSize(size_t size) { this->extendedSize = size; } + size_t getExtendedBufferSize() const { return extendedSize; } uint64_t getAllocationOffset() const { return allocationOffset; @@ -347,6 +349,7 @@ class GraphicsAllocation : public IDNode { size_t size = 0; void *cpuPtr = nullptr; void *lockedPtr = nullptr; + size_t extendedSize = 0; MemoryPool memoryPool = MemoryPool::MemoryNull; AllocationType allocationType = AllocationType::UNKNOWN; diff --git a/shared/source/memory_manager/memory_manager.h b/shared/source/memory_manager/memory_manager.h index b1fb74e606..ab2c23586a 100644 --- a/shared/source/memory_manager/memory_manager.h +++ b/shared/source/memory_manager/memory_manager.h @@ -68,7 +68,6 @@ struct VirtualMemoryReservation { AddressRange virtualAddressRange; MemoryFlags flags; std::map mappedAllocations; - struct PhysicalMemoryAllocation *mappedAllocation; uint32_t rootDeviceIndex; }; diff --git a/shared/source/memory_manager/unified_memory_manager.h b/shared/source/memory_manager/unified_memory_manager.h index 4fa7a9b360..a81f41c563 100644 --- a/shared/source/memory_manager/unified_memory_manager.h +++ b/shared/source/memory_manager/unified_memory_manager.h @@ -25,6 +25,7 @@ class CommandStreamReceiver; class GraphicsAllocation; class MemoryManager; class Device; +struct VirtualMemoryReservation; struct SvmAllocationData { SvmAllocationData(uint32_t maxRootDeviceIndex) : gpuAllocations(maxRootDeviceIndex), maxRootDeviceIndex(maxRootDeviceIndex){}; @@ -43,10 +44,12 @@ struct SvmAllocationData { } } this->mappedAllocData = svmAllocData.mappedAllocData; + this->virtualReservationData = svmAllocData.virtualReservationData; } SvmAllocationData &operator=(const SvmAllocationData &) = delete; GraphicsAllocation *cpuAllocation = nullptr; MultiGraphicsAllocation gpuAllocations; + VirtualMemoryReservation *virtualReservationData = nullptr; size_t size = 0; size_t pageSizeForAlignment = 0; InternalMemoryType memoryType = InternalMemoryType::SVM; diff --git a/shared/test/unit_test/memory_manager/memory_manager_tests.cpp b/shared/test/unit_test/memory_manager/memory_manager_tests.cpp index 800aeaa517..2bb391c4e1 100644 --- a/shared/test/unit_test/memory_manager/memory_manager_tests.cpp +++ b/shared/test/unit_test/memory_manager/memory_manager_tests.cpp @@ -35,6 +35,21 @@ TEST(MemoryManagerTest, WhenCallingCloseInternalHandleWithOsAgnosticThenNoChange memoryManager.closeInternalHandle(handle, 0u, nullptr); } +TEST(MemoryManagerTest, givenDefaultMemoryManagerWhenGraphicsAllocationContainsExtendedSizeThenExtendedSizeObtainedIsTheNewSize) { + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + OsAgnosticMemoryManager memoryManager(executionEnvironment); + + auto graphicsAllocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{0, MemoryConstants::pageSize}); + + EXPECT_EQ(0u, graphicsAllocation->getExtendedBufferSize()); + graphicsAllocation->setExtendedSize(MemoryConstants::pageSize * 2); + + EXPECT_NE(MemoryConstants::pageSize, graphicsAllocation->getExtendedBufferSize()); + EXPECT_EQ(MemoryConstants::pageSize * 2, graphicsAllocation->getExtendedBufferSize()); + + memoryManager.freeGraphicsMemory(graphicsAllocation); +} + TEST(MemoryManagerTest, WhenCallingIsAllocationTypeToCaptureThenScratchAndPrivateTypesReturnTrue) { MockMemoryManager mockMemoryManager;