From 74e6c7407171f30bc9088ef489da7a69accce261 Mon Sep 17 00:00:00 2001 From: Szymon Morek Date: Tue, 27 Jul 2021 17:02:31 +0000 Subject: [PATCH] Disable shareable allocs with huge size Signed-off-by: Szymon Morek --- .../windows/mock_wddm_memory_manager.h | 6 ++++++ .../windows/wddm_memory_manager_tests.cpp | 16 +++++++++++++++- .../os_interface/windows/wddm_memory_manager.cpp | 3 +++ .../os_interface/windows/wddm_memory_manager.h | 2 +- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/opencl/test/unit_test/os_interface/windows/mock_wddm_memory_manager.h b/opencl/test/unit_test/os_interface/windows/mock_wddm_memory_manager.h index 3bbb81126e..8ffdbd59ed 100644 --- a/opencl/test/unit_test/os_interface/windows/mock_wddm_memory_manager.h +++ b/opencl/test/unit_test/os_interface/windows/mock_wddm_memory_manager.h @@ -73,8 +73,14 @@ class MockWddmMemoryManager : public MemoryManagerCreate { BaseClass::freeGraphicsMemoryImpl(gfxAllocation); } + GraphicsAllocation *allocateHugeGraphicsMemory(const AllocationData &allocationData, bool sharedVirtualAddress) override { + allocateHugeGraphicsMemoryCalled = true; + return BaseClass::allocateHugeGraphicsMemory(allocationData, sharedVirtualAddress); + } + uint32_t freeGraphicsMemoryImplCalled = 0u; bool allocationGraphicsMemory64kbCreated = false; bool allocateGraphicsMemoryInNonDevicePool = false; + bool allocateHugeGraphicsMemoryCalled = false; }; } // namespace NEO 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 9b04f6e6eb..0e2355e46c 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 @@ -347,13 +347,27 @@ TEST_F(WddmMemoryManagerTest, givenAllocateGraphicsMemoryForNonSvmHostPtrIsCalle memoryManager->freeGraphicsMemory(allocation); } -TEST_F(WddmMemoryManagerSimpleTest, GivenShareableEnabledWhenAskedToCreateGrahicsAllocationThenValidAllocationIsReturned) { +TEST_F(WddmMemoryManagerSimpleTest, GivenShareableEnabledAndSmallSizeWhenAskedToCreateGrahicsAllocationThenValidAllocationIsReturned) { memoryManager.reset(new MockWddmMemoryManager(false, false, *executionEnvironment)); + memoryManager->hugeGfxMemoryChunkSize = MemoryConstants::pageSize64k; AllocationData allocationData; allocationData.size = 4096u; allocationData.flags.shareable = true; auto allocation = memoryManager->allocateShareableMemory(allocationData); EXPECT_NE(nullptr, allocation); + EXPECT_FALSE(memoryManager->allocateHugeGraphicsMemoryCalled); + memoryManager->freeGraphicsMemory(allocation); +} + +TEST_F(WddmMemoryManagerSimpleTest, GivenShareableEnabledAndHugeSizeWhenAskedToCreateGrahicsAllocationThenValidAllocationIsReturned) { + memoryManager.reset(new MockWddmMemoryManager(false, false, *executionEnvironment)); + memoryManager->hugeGfxMemoryChunkSize = MemoryConstants::pageSize64k; + AllocationData allocationData; + allocationData.size = 2ULL * MemoryConstants::pageSize64k; + allocationData.flags.shareable = true; + auto allocation = memoryManager->allocateShareableMemory(allocationData); + EXPECT_NE(nullptr, allocation); + EXPECT_TRUE(memoryManager->allocateHugeGraphicsMemoryCalled); memoryManager->freeGraphicsMemory(allocation); } diff --git a/shared/source/os_interface/windows/wddm_memory_manager.cpp b/shared/source/os_interface/windows/wddm_memory_manager.cpp index 7d59718cbc..49e6070eb0 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.cpp +++ b/shared/source/os_interface/windows/wddm_memory_manager.cpp @@ -62,6 +62,9 @@ WddmMemoryManager::WddmMemoryManager(ExecutionEnvironment &executionEnvironment) } GraphicsAllocation *WddmMemoryManager::allocateShareableMemory(const AllocationData &allocationData) { + if (allocationData.size > getHugeGfxMemoryChunkSize(GfxMemoryAllocationMethod::AllocateByKmd)) { + return allocateHugeGraphicsMemory(allocationData, false); + } auto gmm = std::make_unique(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), allocationData.hostPtr, allocationData.size, 0u, false); auto allocation = std::make_unique(allocationData.rootDeviceIndex, 1u, // numGmms diff --git a/shared/source/os_interface/windows/wddm_memory_manager.h b/shared/source/os_interface/windows/wddm_memory_manager.h index 582b332ab0..e2632396b4 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.h +++ b/shared/source/os_interface/windows/wddm_memory_manager.h @@ -93,7 +93,7 @@ class WddmMemoryManager : public MemoryManager { GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override; MOCKABLE_VIRTUAL size_t getHugeGfxMemoryChunkSize(GfxMemoryAllocationMethod allocationMethod) const; - GraphicsAllocation *allocateHugeGraphicsMemory(const AllocationData &allocationData, bool sharedVirtualAddress); + MOCKABLE_VIRTUAL GraphicsAllocation *allocateHugeGraphicsMemory(const AllocationData &allocationData, bool sharedVirtualAddress); GraphicsAllocation *createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle, GraphicsAllocation::AllocationType allocationType, uint32_t rootDeviceIndex); static bool validateAllocation(WddmAllocation *alloc);