diff --git a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp index 197a0cd3bb..0b3ce7e577 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp +++ b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp @@ -1087,6 +1087,70 @@ TEST(OsAgnosticMemoryManager, givenCommonMemoryManagerWhenIsAskedIfApplicationMe EXPECT_FALSE(memoryManager.isMemoryBudgetExhausted()); } +TEST(OsAgnosticMemoryManager, givenDebugModuleAreaTypeWhenCreatingAllocationThen32BitAllocationWithFrontWindowGpuVaIsReturned) { + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + MemoryManagerCreate memoryManager(false, false, executionEnvironment); + const auto size = MemoryConstants::pageSize64k; + + NEO::AllocationProperties properties{0, true, size, + NEO::GraphicsAllocation::AllocationType::DEBUG_MODULE_AREA, + false, + mockDeviceBitfield}; + + auto moduleDebugArea = memoryManager.allocateGraphicsMemoryWithProperties(properties); + + EXPECT_NE(nullptr, moduleDebugArea); + EXPECT_NE(nullptr, moduleDebugArea->getUnderlyingBuffer()); + EXPECT_GE(moduleDebugArea->getUnderlyingBufferSize(), size); + + auto address64bit = moduleDebugArea->getGpuAddressToPatch(); + EXPECT_LT(address64bit, MemoryConstants::max32BitAddress); + EXPECT_TRUE(moduleDebugArea->is32BitAllocation()); + + auto frontWindowBase = GmmHelper::canonize(memoryManager.getGfxPartition(moduleDebugArea->getRootDeviceIndex())->getHeapBase(memoryManager.selectInternalHeap(moduleDebugArea->isAllocatedInLocalMemoryPool()))); + EXPECT_EQ(frontWindowBase, moduleDebugArea->getGpuBaseAddress()); + EXPECT_EQ(frontWindowBase, moduleDebugArea->getGpuAddress()); + + memoryManager.freeGraphicsMemory(moduleDebugArea); +} + +TEST(OsAgnosticMemoryManager, givenLocalMemoryAndDebugModuleAreaTypeWhenCreatingAllocationThen32BitAllocationWithFrontWindowGpuVaIsReturned) { + auto hwInfo = *defaultHwInfo; + hwInfo.featureTable.ftrLocalMemory = true; + DebugManagerStateRestore dbgRestore; + DebugManager.flags.EnableLocalMemory.set(true); + + // Ensure family supports local memory + if (!HwHelper::get(hwInfo.platform.eRenderCoreFamily).isLocalMemoryEnabled(hwInfo)) { + GTEST_SKIP(); + } + + MockExecutionEnvironment executionEnvironment(&hwInfo); + MemoryManagerCreate memoryManager(false, true, executionEnvironment); + const auto size = MemoryConstants::pageSize64k; + + NEO::AllocationProperties properties{0, true, size, + NEO::GraphicsAllocation::AllocationType::DEBUG_MODULE_AREA, + false, + mockDeviceBitfield}; + + auto moduleDebugArea = memoryManager.allocateGraphicsMemoryWithProperties(properties); + + EXPECT_NE(nullptr, moduleDebugArea); + EXPECT_NE(nullptr, moduleDebugArea->getUnderlyingBuffer()); + EXPECT_GE(moduleDebugArea->getUnderlyingBufferSize(), size); + + auto address64bit = moduleDebugArea->getGpuAddressToPatch(); + EXPECT_LT(address64bit, MemoryConstants::max32BitAddress); + EXPECT_TRUE(moduleDebugArea->is32BitAllocation()); + + auto frontWindowBase = GmmHelper::canonize(memoryManager.getGfxPartition(moduleDebugArea->getRootDeviceIndex())->getHeapBase(memoryManager.selectInternalHeap(moduleDebugArea->isAllocatedInLocalMemoryPool()))); + EXPECT_EQ(frontWindowBase, moduleDebugArea->getGpuBaseAddress()); + EXPECT_EQ(frontWindowBase, moduleDebugArea->getGpuAddress()); + + memoryManager.freeGraphicsMemory(moduleDebugArea); +} + class MemoryManagerWithAsyncDeleterTest : public ::testing::Test { public: MemoryManagerWithAsyncDeleterTest() : memoryManager(false, false){}; @@ -2182,6 +2246,19 @@ TEST_F(HeapSelectorTest, givenLimitedAddressSpaceWhenSelectingHeapForNullAllocat EXPECT_EQ(HeapIndex::HEAP_STANDARD, memoryManager->selectHeap(nullptr, false, false, false)); } +TEST_F(HeapSelectorTest, givenDebugModuleAreaAllocationAndUseFrontWindowWhenSelectingHeapThenInternalFrontWindowHeapIsReturned) { + GraphicsAllocation allocation{0, GraphicsAllocation::AllocationType::DEBUG_MODULE_AREA, nullptr, 0, 0, 0, MemoryPool::MemoryNull, 1}; + allocation.set32BitAllocation(true); + EXPECT_EQ(HeapIndex::HEAP_INTERNAL_FRONT_WINDOW, memoryManager->selectHeap(&allocation, false, false, true)); +} + +TEST_F(HeapSelectorTest, givenDebugModuleAreaAllocationInLocalMemoryAndUseFrontWindowWhenSelectingHeapThenInternalDeviceFrontWindowHeapIsReturned) { + GraphicsAllocation allocation{0, GraphicsAllocation::AllocationType::DEBUG_MODULE_AREA, nullptr, 0, 0, 0, MemoryPool::LocalMemory, 1}; + allocation.set32BitAllocation(true); + EXPECT_TRUE(allocation.isAllocatedInLocalMemoryPool()); + EXPECT_EQ(HeapIndex::HEAP_INTERNAL_DEVICE_FRONT_WINDOW, memoryManager->selectHeap(&allocation, false, false, true)); +} + TEST(MemoryAllocationTest, givenAllocationTypeWhenPassedToMemoryAllocationConstructorThenAllocationTypeIsStored) { MemoryAllocation allocation{0, GraphicsAllocation::AllocationType::COMMAND_BUFFER, nullptr, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false, false, mockMaxOsContextCount}; @@ -2384,3 +2461,13 @@ HWTEST_F(PageTableManagerTest, givenMemoryManagerThatSupportsPageTableManagerWhe EXPECT_EQ(HwHelper::get(hwInfo->platform.eRenderCoreFamily).isPageTableManagerSupported(*hwInfo), mapped); } + +TEST(MemoryManagerTest, givenDebugModuleAreaAllocationTypeWhenCallingGetAllocationDataThenUse32BitFrontWindowsIsSet) { + AllocationData allocData; + AllocationProperties properties(mockRootDeviceIndex, 1, GraphicsAllocation::AllocationType::DEBUG_MODULE_AREA, mockDeviceBitfield); + + MockMemoryManager mockMemoryManager; + + mockMemoryManager.getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); + EXPECT_EQ(1u, allocData.flags.use32BitFrontWindow); +} diff --git a/opencl/test/unit_test/mock_gdi/mock_gdi.cpp b/opencl/test/unit_test/mock_gdi/mock_gdi.cpp index 97fb2a941d..dc438f2601 100644 --- a/opencl/test/unit_test/mock_gdi/mock_gdi.cpp +++ b/opencl/test/unit_test/mock_gdi/mock_gdi.cpp @@ -227,9 +227,6 @@ NTSTATUS __stdcall D3DKMTMapGpuVirtualAddress(IN OUT D3DDDI_MAPGPUVIRTUALADDRESS mapGpuVA->VirtualAddress = MemoryConstants::pageSize64k; } } else { - if (MemoryConstants::maxSvmAddress != mapGpuVA->MaximumAddress && gLastCallReserveGpuVaArg.MinimumAddress != mapGpuVA->BaseAddress) { - return STATUS_INVALID_PARAMETER; - } mapGpuVA->VirtualAddress = mapGpuVA->BaseAddress; } diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index 96246d6cad..16fb1dde75 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -3669,6 +3669,35 @@ TEST_F(DrmMemoryManagerBasic, givenLocalMemoryDisabledWhenAllocateInDevicePoolIs EXPECT_EQ(MemoryManager::AllocationStatus::RetryInNonDevicePool, status); } +TEST_F(DrmMemoryManagerTest, givenDebugModuleAreaTypeWhenCreatingAllocationThen32BitDrmAllocationWithFrontWindowGpuVaIsReturned) { + mock->ioctl_expected.gemUserptr = 1; + mock->ioctl_expected.gemWait = 1; + mock->ioctl_expected.gemClose = 1; + + const auto size = MemoryConstants::pageSize64k; + + NEO::AllocationProperties properties{device->getRootDeviceIndex(), true, size, + NEO::GraphicsAllocation::AllocationType::DEBUG_MODULE_AREA, + false, + device->getDeviceBitfield()}; + + auto moduleDebugArea = memoryManager->allocateGraphicsMemoryWithProperties(properties); + + EXPECT_NE(nullptr, moduleDebugArea); + EXPECT_NE(nullptr, moduleDebugArea->getUnderlyingBuffer()); + EXPECT_GE(moduleDebugArea->getUnderlyingBufferSize(), size); + + auto address64bit = moduleDebugArea->getGpuAddressToPatch(); + EXPECT_LT(address64bit, MemoryConstants::max32BitAddress); + EXPECT_TRUE(moduleDebugArea->is32BitAllocation()); + + auto frontWindowBase = GmmHelper::canonize(memoryManager->getGfxPartition(moduleDebugArea->getRootDeviceIndex())->getHeapBase(memoryManager->selectInternalHeap(moduleDebugArea->isAllocatedInLocalMemoryPool()))); + EXPECT_EQ(frontWindowBase, moduleDebugArea->getGpuBaseAddress()); + EXPECT_EQ(frontWindowBase, moduleDebugArea->getGpuAddress()); + + memoryManager->freeGraphicsMemory(moduleDebugArea); +} + TEST(DrmAllocationTest, givenAllocationTypeWhenPassedToDrmAllocationConstructorThenAllocationTypeIsStored) { DrmAllocation allocation{0, GraphicsAllocation::AllocationType::COMMAND_BUFFER, nullptr, nullptr, static_cast(0), 0u, MemoryPool::MemoryNull}; EXPECT_EQ(GraphicsAllocation::AllocationType::COMMAND_BUFFER, allocation.getAllocationType()); diff --git a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp index 64a776eec1..8983a85a8d 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp @@ -2049,6 +2049,31 @@ TEST_F(WddmMemoryManagerSimpleTest, givenBufferHostMemoryAllocationAndLimitedRan memoryManager->freeGraphicsMemory(allocation); } +TEST_F(WddmMemoryManagerSimpleTest, givenDebugModuleAreaTypeWhenCreatingAllocationThen32BitAllocationWithFrontWindowGpuVaIsReturned) { + const auto size = MemoryConstants::pageSize64k; + + NEO::AllocationProperties properties{0, true, size, + NEO::GraphicsAllocation::AllocationType::DEBUG_MODULE_AREA, + false, + mockDeviceBitfield}; + + auto moduleDebugArea = memoryManager->allocateGraphicsMemoryWithProperties(properties); + + EXPECT_NE(nullptr, moduleDebugArea); + EXPECT_NE(nullptr, moduleDebugArea->getUnderlyingBuffer()); + EXPECT_GE(moduleDebugArea->getUnderlyingBufferSize(), size); + + auto address64bit = moduleDebugArea->getGpuAddressToPatch(); + EXPECT_LT(address64bit, MemoryConstants::max32BitAddress); + EXPECT_TRUE(moduleDebugArea->is32BitAllocation()); + + auto frontWindowBase = GmmHelper::canonize(memoryManager->getGfxPartition(moduleDebugArea->getRootDeviceIndex())->getHeapBase(memoryManager->selectInternalHeap(moduleDebugArea->isAllocatedInLocalMemoryPool()))); + EXPECT_EQ(frontWindowBase, moduleDebugArea->getGpuBaseAddress()); + EXPECT_EQ(frontWindowBase, moduleDebugArea->getGpuAddress()); + + memoryManager->freeGraphicsMemory(moduleDebugArea); +} + TEST(WddmMemoryManager, givenMultipleRootDeviceWhenMemoryManagerGetsWddmThenWddmIsFromCorrectRootDevice) { DebugManagerStateRestore restorer; DebugManager.flags.CreateMultipleRootDevices.set(4); diff --git a/shared/source/helpers/heap_assigner.cpp b/shared/source/helpers/heap_assigner.cpp index c5b3d36d03..7992db971d 100644 --- a/shared/source/helpers/heap_assigner.cpp +++ b/shared/source/helpers/heap_assigner.cpp @@ -18,16 +18,17 @@ HeapAssigner::HeapAssigner() { } bool HeapAssigner::useInternal32BitHeap(GraphicsAllocation::AllocationType allocType) { return allocType == GraphicsAllocation::AllocationType::KERNEL_ISA || - allocType == GraphicsAllocation::AllocationType::INTERNAL_HEAP; + allocType == GraphicsAllocation::AllocationType::INTERNAL_HEAP || + allocType == GraphicsAllocation::AllocationType::DEBUG_MODULE_AREA; } bool HeapAssigner::use32BitHeap(GraphicsAllocation::AllocationType allocType) { return useExternal32BitHeap(allocType) || useInternal32BitHeap(allocType); } -HeapIndex HeapAssigner::get32BitHeapIndex(GraphicsAllocation::AllocationType allocType, bool useLocalMem, const HardwareInfo &hwInfo, bool useExternalWindow) { +HeapIndex HeapAssigner::get32BitHeapIndex(GraphicsAllocation::AllocationType allocType, bool useLocalMem, const HardwareInfo &hwInfo, bool useFrontWindow) { if (useInternal32BitHeap(allocType)) { - return MemoryManager::selectInternalHeap(useLocalMem); + return useFrontWindow ? mapInternalWindowIndex(MemoryManager::selectInternalHeap(useLocalMem)) : MemoryManager::selectInternalHeap(useLocalMem); } - return useExternalWindow ? mapExternalWindowIndex(MemoryManager::selectExternalHeap(useLocalMem)) : MemoryManager::selectExternalHeap(useLocalMem); + return useFrontWindow ? mapExternalWindowIndex(MemoryManager::selectExternalHeap(useLocalMem)) : MemoryManager::selectExternalHeap(useLocalMem); } bool HeapAssigner::useExternal32BitHeap(GraphicsAllocation::AllocationType allocType) { if (apiAllowExternalHeapForSshAndDsh) { diff --git a/shared/source/helpers/heap_assigner.h b/shared/source/helpers/heap_assigner.h index 8376e0ae87..6519bce918 100644 --- a/shared/source/helpers/heap_assigner.h +++ b/shared/source/helpers/heap_assigner.h @@ -16,7 +16,7 @@ struct HeapAssigner { bool useExternal32BitHeap(GraphicsAllocation::AllocationType allocType); bool useInternal32BitHeap(GraphicsAllocation::AllocationType allocType); bool use32BitHeap(GraphicsAllocation::AllocationType allocType); - HeapIndex get32BitHeapIndex(GraphicsAllocation::AllocationType allocType, bool useLocalMem, const HardwareInfo &hwInfo, bool useExternalWindow); + HeapIndex get32BitHeapIndex(GraphicsAllocation::AllocationType allocType, bool useLocalMem, const HardwareInfo &hwInfo, bool useFrontWindow); static bool heapTypeWithFrontWindowPool(HeapIndex heap); static bool isInternalHeap(HeapIndex heap); diff --git a/shared/source/memory_manager/memory_manager.cpp b/shared/source/memory_manager/memory_manager.cpp index f432dcc85a..6375c4b15a 100644 --- a/shared/source/memory_manager/memory_manager.cpp +++ b/shared/source/memory_manager/memory_manager.cpp @@ -386,7 +386,12 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo (mayRequireL3Flush ? properties.flags.flushL3RequiredForRead | properties.flags.flushL3RequiredForWrite : 0u); allocationData.flags.preferRenderCompressed = CompressionSelector::preferRenderCompressedBuffer(properties); allocationData.flags.multiOsContextCapable = properties.flags.multiOsContextCapable; - allocationData.flags.use32BitFrontWindow = properties.flags.use32BitFrontWindow; + + if (properties.allocationType == GraphicsAllocation::AllocationType::DEBUG_MODULE_AREA) { + allocationData.flags.use32BitFrontWindow = true; + } else { + allocationData.flags.use32BitFrontWindow = properties.flags.use32BitFrontWindow; + } allocationData.hostPtr = hostPtr; allocationData.size = properties.size; @@ -559,7 +564,7 @@ void MemoryManager::unlockResource(GraphicsAllocation *graphicsAllocation) { HeapIndex MemoryManager::selectHeap(const GraphicsAllocation *allocation, bool hasPointer, bool isFullRangeSVM, bool useFrontWindow) { if (allocation) { if (heapAssigner.useInternal32BitHeap(allocation->getAllocationType())) { - return selectInternalHeap(allocation->isAllocatedInLocalMemoryPool()); + return useFrontWindow ? HeapAssigner::mapInternalWindowIndex(selectInternalHeap(allocation->isAllocatedInLocalMemoryPool())) : selectInternalHeap(allocation->isAllocatedInLocalMemoryPool()); } if (allocation->is32BitAllocation() || heapAssigner.useExternal32BitHeap(allocation->getAllocationType())) { return useFrontWindow ? HeapAssigner::mapExternalWindowIndex(selectExternalHeap(allocation->isAllocatedInLocalMemoryPool()))