From 4e4d160efd43f4c160ae6d138a2e3be4a18251cc Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Wed, 25 Mar 2020 15:15:03 +0100 Subject: [PATCH] Extend MockAllocationProperties constructor, pass root device index Related-To: NEO-4512, NEO-3691 Change-Id: I1af3e513ae272e5baae116a176445e6e6af297fb Signed-off-by: Mateusz Jablonski --- .../aub_command_stream_fixture.h | 2 +- .../aub_tests/fixtures/aub_fixture.cpp | 2 +- .../tbx_command_stream_tests.cpp | 4 +- opencl/test/unit_test/event/event_tests.cpp | 2 +- .../hardware_commands_helper_tests.cpp | 2 +- .../memory_manager/host_ptr_manager_tests.cpp | 18 +++--- .../memory_manager/memory_manager_tests.cpp | 49 ++++++++-------- .../mocks/linux/mock_drm_memory_manager.cpp | 4 +- .../mocks/linux/mock_drm_memory_manager.h | 2 +- .../mocks/mock_allocation_properties.h | 4 +- .../unit_test/mocks/mock_memory_manager.cpp | 6 +- .../unit_test/mocks/mock_memory_manager.h | 2 +- .../linux/drm_command_stream_tests.cpp | 16 ++--- .../linux/drm_memory_manager_tests.cpp | 40 ++++++------- .../linux/drm_memory_manager_tests.h | 3 +- .../windows/device_command_stream_tests.cpp | 12 ++-- .../windows/mock_wddm_memory_manager.h | 4 +- .../windows/wddm_memory_manager_tests.cpp | 58 +++++++++---------- .../windows/wddm_memory_manager_tests.h | 14 +++-- .../wddm_residency_controller_tests.cpp | 10 ++-- 20 files changed, 128 insertions(+), 126 deletions(-) diff --git a/opencl/test/unit_test/aub_tests/command_stream/aub_command_stream_fixture.h b/opencl/test/unit_test/aub_tests/command_stream/aub_command_stream_fixture.h index 5d716e30c6..2314db254a 100644 --- a/opencl/test/unit_test/aub_tests/command_stream/aub_command_stream_fixture.h +++ b/opencl/test/unit_test/aub_tests/command_stream/aub_command_stream_fixture.h @@ -95,7 +95,7 @@ class AUBCommandStreamFixture : public CommandStreamFixture { } GraphicsAllocation *createResidentAllocationAndStoreItInCsr(const void *address, size_t size) { - GraphicsAllocation *graphicsAllocation = pCommandStreamReceiver->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, address); + GraphicsAllocation *graphicsAllocation = pCommandStreamReceiver->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{pCommandStreamReceiver->getRootDeviceIndex(), false, size}, address); pCommandStreamReceiver->makeResidentHostPtrAllocation(graphicsAllocation); pCommandStreamReceiver->getInternalAllocationStorage()->storeAllocation(std::unique_ptr(graphicsAllocation), TEMPORARY_ALLOCATION); return graphicsAllocation; diff --git a/opencl/test/unit_test/aub_tests/fixtures/aub_fixture.cpp b/opencl/test/unit_test/aub_tests/fixtures/aub_fixture.cpp index 90d9bc2346..887f9084a2 100644 --- a/opencl/test/unit_test/aub_tests/fixtures/aub_fixture.cpp +++ b/opencl/test/unit_test/aub_tests/fixtures/aub_fixture.cpp @@ -16,7 +16,7 @@ namespace NEO { GraphicsAllocation *AUBFixture::createHostPtrAllocationFromSvmPtr(void *svmPtr, size_t size) { - GraphicsAllocation *allocation = csr->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, svmPtr); + GraphicsAllocation *allocation = csr->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, size}, svmPtr); csr->makeResidentHostPtrAllocation(allocation); csr->getInternalAllocationStorage()->storeAllocation(std::unique_ptr(allocation), TEMPORARY_ALLOCATION); allocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER); diff --git a/opencl/test/unit_test/command_stream/tbx_command_stream_tests.cpp b/opencl/test/unit_test/command_stream/tbx_command_stream_tests.cpp index 6cd24d446b..98a78dabaf 100644 --- a/opencl/test/unit_test/command_stream/tbx_command_stream_tests.cpp +++ b/opencl/test/unit_test/command_stream/tbx_command_stream_tests.cpp @@ -91,7 +91,7 @@ TEST_F(TbxCommandStreamTests, DISABLED_makeResident) { uint8_t buffer[0x10000]; size_t size = sizeof(buffer); - GraphicsAllocation *graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, buffer); + GraphicsAllocation *graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{pCommandStreamReceiver->getRootDeviceIndex(), false, size}, buffer); pCommandStreamReceiver->makeResident(*graphicsAllocation); pCommandStreamReceiver->makeNonResident(*graphicsAllocation); memoryManager->freeGraphicsMemory(graphicsAllocation); @@ -409,7 +409,7 @@ HWTEST_F(TbxCommandSteamSimpleTest, givenTbxCsrWhenCallingWaitForTaskCountWithKm MockOsContext osContext(0, 1, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false, false, false); uint32_t tag = 0u; tbxCsr.setupContext(osContext); - tbxCsr.setTagAllocation(pDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, sizeof(tag)}, &tag)); + tbxCsr.setTagAllocation(pDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{pDevice->getRootDeviceIndex(), false, sizeof(tag)}, &tag)); tbxCsr.latestFlushedTaskCount = 1u; MockGraphicsAllocation allocation1, allocation2, allocation3; diff --git a/opencl/test/unit_test/event/event_tests.cpp b/opencl/test/unit_test/event/event_tests.cpp index 008bcec226..602194b3cd 100644 --- a/opencl/test/unit_test/event/event_tests.cpp +++ b/opencl/test/unit_test/event/event_tests.cpp @@ -417,7 +417,7 @@ struct UpdateEventTest : public ::testing::Test { TEST_F(UpdateEventTest, givenEventContainingCommandQueueWhenItsStatusIsUpdatedToCompletedThenTemporaryAllocationsAreDeleted) { void *ptr = (void *)0x1000; size_t size = 4096; - auto temporary = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, ptr); + auto temporary = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), false, size}, ptr); temporary->updateTaskCount(3, commandQueue->getGpgpuCommandStreamReceiver().getOsContext().getContextId()); commandQueue->getGpgpuCommandStreamReceiver().getInternalAllocationStorage()->storeAllocation(std::unique_ptr(temporary), TEMPORARY_ALLOCATION); Event event(commandQueue.get(), CL_COMMAND_NDRANGE_KERNEL, 3, 3); diff --git a/opencl/test/unit_test/helpers/hardware_commands_helper_tests.cpp b/opencl/test/unit_test/helpers/hardware_commands_helper_tests.cpp index 36348a1673..91b1034776 100644 --- a/opencl/test/unit_test/helpers/hardware_commands_helper_tests.cpp +++ b/opencl/test/unit_test/helpers/hardware_commands_helper_tests.cpp @@ -216,7 +216,7 @@ HWTEST_F(HardwareCommandsTest, givenIndirectHeapNotAllocatedFromInternalPoolWhen } HWTEST_F(HardwareCommandsTest, givenIndirectHeapAllocatedFromInternalPoolWhenSendCrossThreadDataIsCalledThenHeapBaseOffsetIsReturned) { - auto internalAllocation = pDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties(true, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::INTERNAL_HEAP)); + auto internalAllocation = pDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties(pDevice->getRootDeviceIndex(), true, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::INTERNAL_HEAP)); IndirectHeap indirectHeap(internalAllocation, true); auto expectedOffset = internalAllocation->getGpuAddressToPatch(); diff --git a/opencl/test/unit_test/memory_manager/host_ptr_manager_tests.cpp b/opencl/test/unit_test/memory_manager/host_ptr_manager_tests.cpp index 0e7a575af4..7d4bd8a8a1 100644 --- a/opencl/test/unit_test/memory_manager/host_ptr_manager_tests.cpp +++ b/opencl/test/unit_test/memory_manager/host_ptr_manager_tests.cpp @@ -788,10 +788,10 @@ TEST_F(HostPtrAllocationTest, givenTwoAllocationsThatSharesOneFragmentWhenOneIsD void *cpuPtr2 = ptrOffset(cpuPtr1, MemoryConstants::pageSize); auto hostPtrManager = static_cast(memoryManager->getHostPtrManager()); - auto graphicsAllocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, 2 * MemoryConstants::pageSize - 1}, cpuPtr1); + auto graphicsAllocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, 2 * MemoryConstants::pageSize - 1}, cpuPtr1); EXPECT_EQ(2u, hostPtrManager->getFragmentCount()); - auto graphicsAllocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize}, cpuPtr2); + auto graphicsAllocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, MemoryConstants::pageSize}, cpuPtr2); EXPECT_EQ(3u, hostPtrManager->getFragmentCount()); memoryManager->freeGraphicsMemory(graphicsAllocation1); EXPECT_EQ(2u, hostPtrManager->getFragmentCount()); @@ -820,7 +820,7 @@ TEST_F(HostPtrAllocationTest, whenOverlappedFragmentIsBiggerThenStoredAndStoredF void *cpuPtr1 = (void *)0x100004; auto hostPtrManager = static_cast(memoryManager->getHostPtrManager()); - auto graphicsAllocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize}, cpuPtr1); + auto graphicsAllocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, MemoryConstants::pageSize}, cpuPtr1); EXPECT_EQ(2u, hostPtrManager->getFragmentCount()); EXPECT_NE(nullptr, graphicsAllocation1); @@ -874,8 +874,8 @@ HWTEST_F(HostPtrAllocationTest, givenOverlappingFragmentsWhenCheckIsCalledThenWa void *cpuPtr = reinterpret_cast(0x100004); auto hostPtrManager = static_cast(memoryManager->getHostPtrManager()); - auto graphicsAllocation0 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize}, cpuPtr); - auto graphicsAllocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize}, cpuPtr); + auto graphicsAllocation0 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, MemoryConstants::pageSize}, cpuPtr); + auto graphicsAllocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, MemoryConstants::pageSize}, cpuPtr); auto storage0 = new MockInternalAllocationStorage(*csr0); auto storage1 = new MockInternalAllocationStorage(*csr1); @@ -913,7 +913,7 @@ TEST_F(HostPtrAllocationTest, whenOverlappedFragmentIsBiggerThenStoredAndStoredF void *cpuPtr1 = (void *)0x100004; auto hostPtrManager = static_cast(memoryManager->getHostPtrManager()); - auto graphicsAllocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize}, cpuPtr1); + auto graphicsAllocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, MemoryConstants::pageSize}, cpuPtr1); EXPECT_EQ(2u, hostPtrManager->getFragmentCount()); EXPECT_NE(nullptr, graphicsAllocation1); @@ -951,10 +951,10 @@ TEST_F(HostPtrAllocationTest, checkAllocationsForOverlappingWithoutBiggerOverlap void *cpuPtr2 = (void *)0x101008; auto hostPtrManager = static_cast(memoryManager->getHostPtrManager()); - auto graphicsAllocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize}, cpuPtr1); + auto graphicsAllocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, MemoryConstants::pageSize}, cpuPtr1); EXPECT_EQ(2u, hostPtrManager->getFragmentCount()); - auto graphicsAllocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize * 3}, cpuPtr2); + auto graphicsAllocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, MemoryConstants::pageSize * 3}, cpuPtr2); EXPECT_EQ(4u, hostPtrManager->getFragmentCount()); EXPECT_NE(nullptr, graphicsAllocation1); @@ -994,7 +994,7 @@ TEST_F(HostPtrAllocationTest, checkAllocationsForOverlappingWithBiggerOverlapUnt void *cpuPtr1 = (void *)0x100004; - auto graphicsAllocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize}, cpuPtr1); + auto graphicsAllocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, MemoryConstants::pageSize}, cpuPtr1); auto hostPtrManager = static_cast(memoryManager->getHostPtrManager()); EXPECT_EQ(2u, hostPtrManager->getFragmentCount()); 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 faec71d88d..9fe82f51b1 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp +++ b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp @@ -234,7 +234,7 @@ TEST_F(MemoryAllocatorTest, AlignedHostPtrWithAlignedSizeWhenAskedForGraphicsAll auto ptr = (void *)0x1000; MockMemoryManager mockMemoryManager(*executionEnvironment); auto hostPtrManager = static_cast(mockMemoryManager.getHostPtrManager()); - auto graphicsAllocation = mockMemoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, 4096}, ptr); + auto graphicsAllocation = mockMemoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), false, 4096}, ptr); EXPECT_NE(nullptr, graphicsAllocation); EXPECT_EQ(1u, hostPtrManager->getFragmentCount()); @@ -251,7 +251,7 @@ TEST_F(MemoryAllocatorTest, GivenAlignedHostPtrAndCacheAlignedSizeWhenAskedForL3 auto ptr = (void *)0x1000; auto alignedSize = MemoryConstants::cacheLineSize; - auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, alignedSize}, ptr); + auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), false, alignedSize}, ptr); EXPECT_TRUE(isL3Capable(*graphicsAllocation)); @@ -262,7 +262,7 @@ TEST_F(MemoryAllocatorTest, GivenAlignedHostPtrAndNotCacheAlignedSizeWhenAskedFo auto ptr = (void *)0x1000; auto alignedSize = MemoryConstants::cacheLineSize - 1; - auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, alignedSize}, ptr); + auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), false, alignedSize}, ptr); EXPECT_FALSE(isL3Capable(*graphicsAllocation)); @@ -273,7 +273,7 @@ TEST_F(MemoryAllocatorTest, GivenMisAlignedHostPtrAndNotCacheAlignedSizeWhenAske auto ptr = (void *)0x1001; auto alignedSize = MemoryConstants::cacheLineSize - 1; - auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, alignedSize}, ptr); + auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), false, alignedSize}, ptr); EXPECT_FALSE(isL3Capable(*graphicsAllocation)); @@ -284,7 +284,7 @@ TEST_F(MemoryAllocatorTest, GivenHostPtrAlignedToCacheLineWhenAskedForL3Allowanc auto ptr = (void *)0x1040; auto alignedSize = MemoryConstants::cacheLineSize; - auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, alignedSize}, ptr); + auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), false, alignedSize}, ptr); EXPECT_TRUE(isL3Capable(*graphicsAllocation)); @@ -354,7 +354,7 @@ TEST_F(MemoryAllocatorTest, GivenEmptyMemoryManagerAndMisalingedHostPtrWithHugeS ASSERT_EQ(3u, reqs.requiredFragmentsCount); - auto graphicsAllocation = mockMemoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, cpuPtr); + auto graphicsAllocation = mockMemoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), false, size}, cpuPtr); for (int i = 0; i < maxFragmentsCount; i++) { EXPECT_NE(nullptr, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage); EXPECT_EQ(reqs.allocationFragments[i].allocationPtr, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].cpuPtr); @@ -402,7 +402,7 @@ TEST_F(MemoryAllocatorTest, GivenPointerAndSizeWhenAskedToCreateGrahicsAllocatio TEST_F(MemoryAllocatorTest, givenMemoryManagerWhenAskedFor32bitAllocationThen32bitGraphicsAllocationIsReturned) { size_t size = 10; - auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr, GraphicsAllocation::AllocationType::BUFFER); + auto allocation = memoryManager->allocate32BitGraphicsMemory(device->getRootDeviceIndex(), size, nullptr, GraphicsAllocation::AllocationType::BUFFER); EXPECT_NE(nullptr, allocation); EXPECT_NE(nullptr, allocation->getUnderlyingBuffer()); EXPECT_EQ(size, allocation->getUnderlyingBufferSize()); @@ -412,8 +412,8 @@ TEST_F(MemoryAllocatorTest, givenMemoryManagerWhenAskedFor32bitAllocationThen32b TEST_F(MemoryAllocatorTest, givenNotEnoughSpaceInAllocatorWhenAskedFor32bitAllocationNullptrIsReturned) { size_t size = 0xfffff000; - auto allocationFirst = memoryManager->allocate32BitGraphicsMemory(0x5000, nullptr, GraphicsAllocation::AllocationType::BUFFER); - auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr, GraphicsAllocation::AllocationType::BUFFER); + auto allocationFirst = memoryManager->allocate32BitGraphicsMemory(device->getRootDeviceIndex(), 0x5000, nullptr, GraphicsAllocation::AllocationType::BUFFER); + auto allocation = memoryManager->allocate32BitGraphicsMemory(device->getRootDeviceIndex(), size, nullptr, GraphicsAllocation::AllocationType::BUFFER); EXPECT_EQ(nullptr, allocation); memoryManager->freeGraphicsMemory(allocationFirst); } @@ -421,8 +421,8 @@ TEST_F(MemoryAllocatorTest, givenNotEnoughSpaceInAllocatorWhenAskedFor32bitAlloc TEST_F(MemoryAllocatorTest, givenNotEnoughSpaceInAllocatorWhenAskedFor32bitAllocationWithHostPtrThenNullptrIsReturned) { size_t size = 0xfffff000; void *ptr = (void *)0x10000; - auto allocationFirst = memoryManager->allocate32BitGraphicsMemory(0x5000, nullptr, GraphicsAllocation::AllocationType::BUFFER); - auto allocation = memoryManager->allocate32BitGraphicsMemory(size, ptr, GraphicsAllocation::AllocationType::BUFFER); + auto allocationFirst = memoryManager->allocate32BitGraphicsMemory(device->getRootDeviceIndex(), 0x5000, nullptr, GraphicsAllocation::AllocationType::BUFFER); + auto allocation = memoryManager->allocate32BitGraphicsMemory(device->getRootDeviceIndex(), size, ptr, GraphicsAllocation::AllocationType::BUFFER); EXPECT_EQ(nullptr, allocation); memoryManager->freeGraphicsMemory(allocationFirst); } @@ -430,7 +430,7 @@ TEST_F(MemoryAllocatorTest, givenNotEnoughSpaceInAllocatorWhenAskedFor32bitAlloc TEST_F(MemoryAllocatorTest, givenMemoryManagerWhenAskedFor32bitAllocationWithPtrThen32bitGraphicsAllocationWithGpuAddressIsReturned) { size_t size = 10; void *ptr = (void *)0x1000; - auto allocation = memoryManager->allocate32BitGraphicsMemory(size, ptr, GraphicsAllocation::AllocationType::BUFFER); + auto allocation = memoryManager->allocate32BitGraphicsMemory(device->getRootDeviceIndex(), size, ptr, GraphicsAllocation::AllocationType::BUFFER); EXPECT_NE(nullptr, allocation); EXPECT_NE(nullptr, allocation->getUnderlyingBuffer()); EXPECT_EQ(size, allocation->getUnderlyingBufferSize()); @@ -833,7 +833,7 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryWithPt void *ptr = reinterpret_cast(0x1001); auto size = MemoryConstants::pageSize; - auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, ptr); + auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{0, false, size}, ptr); ASSERT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); @@ -847,7 +847,7 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryW void *ptr = reinterpret_cast(0x1001); auto size = MemoryConstants::pageSize; - auto allocation = memoryManager.allocate32BitGraphicsMemory(size, ptr, GraphicsAllocation::AllocationType::BUFFER); + auto allocation = memoryManager.allocate32BitGraphicsMemory(0, size, ptr, GraphicsAllocation::AllocationType::BUFFER); ASSERT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::System4KBPagesWith32BitGpuAddressing, allocation->getMemoryPool()); @@ -861,7 +861,7 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryW void *ptr = nullptr; auto size = MemoryConstants::pageSize; - auto allocation = memoryManager.allocate32BitGraphicsMemory(size, ptr, GraphicsAllocation::AllocationType::BUFFER); + auto allocation = memoryManager.allocate32BitGraphicsMemory(0, size, ptr, GraphicsAllocation::AllocationType::BUFFER); ASSERT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::System4KBPagesWith32BitGpuAddressing, allocation->getMemoryPool()); @@ -1039,6 +1039,7 @@ class MemoryManagerWithAsyncDeleterTest : public ::testing::Test { void SetUp() override { memoryManager.overrideAsyncDeleterFlag(true); } + const uint32_t rootDeviceIndex = 0u; MockMemoryManager memoryManager; }; @@ -1071,7 +1072,7 @@ TEST_F(MemoryManagerWithAsyncDeleterTest, givenMemoryManagerWhenAllocateGraphics char ptr[128]; EXPECT_EQ(0, deleter->drainCalled); deleter->expectDrainBlockingValue(true); - auto allocation = memoryManager.MemoryManager::allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, sizeof(char)}, ptr); + auto allocation = memoryManager.MemoryManager::allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, false, sizeof(char)}, ptr); EXPECT_TRUE(deleter->isQueueEmpty()); memoryManager.freeGraphicsMemoryImpl(allocation); } @@ -1080,7 +1081,7 @@ TEST_F(MemoryManagerWithAsyncDeleterTest, givenMemoryManagerWhenAllocateGraphics memoryManager.setDeferredDeleter(nullptr); EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter()); char ptr[128]; - auto allocation = memoryManager.MemoryManager::allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, sizeof(char)}, ptr); + auto allocation = memoryManager.MemoryManager::allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, false, sizeof(char)}, ptr); memoryManager.freeGraphicsMemoryImpl(allocation); } @@ -1145,7 +1146,7 @@ TEST(OsAgnosticMemoryManager, givenPointerAndSizeWhenCreateInternalAllocationIsC MockMemoryManager memoryManager(false, false, executionEnvironment); auto ptr = (void *)0x100000; size_t allocationSize = 4096; - auto graphicsAllocation = memoryManager.allocate32BitGraphicsMemory(allocationSize, ptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP); + auto graphicsAllocation = memoryManager.allocate32BitGraphicsMemory(0, allocationSize, ptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP); EXPECT_EQ(ptr, graphicsAllocation->getUnderlyingBuffer()); EXPECT_EQ(allocationSize, graphicsAllocation->getUnderlyingBufferSize()); memoryManager.freeGraphicsMemory(graphicsAllocation); @@ -1315,17 +1316,17 @@ TEST_F(MemoryManagerWithCsrTest, GivenAllocationsInHostPtrManagerWhenBiggerOverl void *cpuPtr3 = (void *)0x100000; auto hostPtrManager = static_cast(memoryManager->getHostPtrManager()); - auto graphicsAllocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize}, cpuPtr1); + auto graphicsAllocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, MemoryConstants::pageSize}, cpuPtr1); EXPECT_EQ(2u, hostPtrManager->getFragmentCount()); - auto graphicsAllocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize * 3}, cpuPtr2); + auto graphicsAllocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, MemoryConstants::pageSize * 3}, cpuPtr2); EXPECT_EQ(4u, hostPtrManager->getFragmentCount()); GraphicsAllocation *graphicsAllocation3 = nullptr; bool catchMe = false; try { - graphicsAllocation3 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize * 10}, cpuPtr3); + graphicsAllocation3 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, MemoryConstants::pageSize * 10}, cpuPtr3); } catch (...) { catchMe = true; } @@ -1352,10 +1353,10 @@ TEST_F(MemoryManagerWithCsrTest, GivenAllocationsInHostPtrManagerReadyForCleanin void *cpuPtr3 = (void *)0x100000; auto hostPtrManager = static_cast(memoryManager->getHostPtrManager()); - auto graphicsAllocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize}, cpuPtr1); + auto graphicsAllocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, MemoryConstants::pageSize}, cpuPtr1); EXPECT_EQ(2u, hostPtrManager->getFragmentCount()); - auto graphicsAllocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize * 3}, cpuPtr2); + auto graphicsAllocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, MemoryConstants::pageSize * 3}, cpuPtr2); EXPECT_EQ(4u, hostPtrManager->getFragmentCount()); EXPECT_NE(nullptr, graphicsAllocation1); @@ -1381,7 +1382,7 @@ TEST_F(MemoryManagerWithCsrTest, GivenAllocationsInHostPtrManagerReadyForCleanin taskCount = taskCountReady; csr->latestSentTaskCount = taskCountReady; - auto graphicsAllocation3 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize * 10}, cpuPtr3); + auto graphicsAllocation3 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, MemoryConstants::pageSize * 10}, cpuPtr3); EXPECT_NE(nullptr, graphicsAllocation3); diff --git a/opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.cpp b/opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.cpp index 30ca8bc583..7fd20d4642 100644 --- a/opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.cpp +++ b/opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.cpp @@ -56,10 +56,10 @@ DrmGemCloseWorker *TestedDrmMemoryManager::getgemCloseWorker() { return this->ge void TestedDrmMemoryManager::forceLimitedRangeAllocator(uint64_t range) { getGfxPartition(0)->init(range, getSizeToReserve(), 0, 1); } void TestedDrmMemoryManager::overrideGfxPartition(GfxPartition *newGfxPartition) { gfxPartitions[0].reset(newGfxPartition); } -DrmAllocation *TestedDrmMemoryManager::allocate32BitGraphicsMemory(size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType) { +DrmAllocation *TestedDrmMemoryManager::allocate32BitGraphicsMemory(uint32_t rootDeviceIndex, size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType) { bool allocateMemory = ptr == nullptr; AllocationData allocationData; - MockAllocationProperties properties(allocateMemory, size, allocationType); + MockAllocationProperties properties(rootDeviceIndex, allocateMemory, size, allocationType); getAllocationData(allocationData, properties, ptr, createStorageInfoFromProperties(properties)); return allocate32BitGraphicsMemoryImpl(allocationData); } diff --git a/opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h b/opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h index 0fa1b440d1..d88fdc1996 100644 --- a/opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h +++ b/opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h @@ -71,7 +71,7 @@ class TestedDrmMemoryManager : public MemoryManagerCreate { void forceLimitedRangeAllocator(uint64_t range); void overrideGfxPartition(GfxPartition *newGfxPartition); - DrmAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType); + DrmAllocation *allocate32BitGraphicsMemory(uint32_t rootDeviceIndex, size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType); ~TestedDrmMemoryManager() override; }; } // namespace NEO diff --git a/opencl/test/unit_test/mocks/mock_allocation_properties.h b/opencl/test/unit_test/mocks/mock_allocation_properties.h index 6903498430..ad876f252f 100644 --- a/opencl/test/unit_test/mocks/mock_allocation_properties.h +++ b/opencl/test/unit_test/mocks/mock_allocation_properties.h @@ -12,7 +12,7 @@ namespace NEO { struct MockAllocationProperties : public AllocationProperties { MockAllocationProperties(size_t size, GraphicsAllocation::AllocationType allocationType) : AllocationProperties(0, size, allocationType) {} MockAllocationProperties(size_t size) : AllocationProperties(0, size, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY) {} - MockAllocationProperties(bool allocateMemory, size_t size) : AllocationProperties(0, allocateMemory, size, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, false) {} - MockAllocationProperties(bool allocateMemory, size_t size, GraphicsAllocation::AllocationType allocationType) : AllocationProperties(0, allocateMemory, size, allocationType, false) {} + MockAllocationProperties(uint32_t rootDeviceIndex, bool allocateMemory, size_t size) : AllocationProperties(rootDeviceIndex, allocateMemory, size, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, false) {} + MockAllocationProperties(uint32_t rootDeviceIndex, bool allocateMemory, size_t size, GraphicsAllocation::AllocationType allocationType) : AllocationProperties(rootDeviceIndex, allocateMemory, size, allocationType, false) {} }; } // namespace NEO diff --git a/opencl/test/unit_test/mocks/mock_memory_manager.cpp b/opencl/test/unit_test/mocks/mock_memory_manager.cpp index 3304632ddc..23043cae5f 100644 --- a/opencl/test/unit_test/mocks/mock_memory_manager.cpp +++ b/opencl/test/unit_test/mocks/mock_memory_manager.cpp @@ -96,10 +96,10 @@ GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryWithAlignment(const return OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment(allocationData); } -GraphicsAllocation *MockMemoryManager::allocate32BitGraphicsMemory(size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType) { +GraphicsAllocation *MockMemoryManager::allocate32BitGraphicsMemory(uint32_t rootDeviceIndex, size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType) { bool allocateMemory = ptr == nullptr; - AllocationData allocationData; - MockAllocationProperties properties(allocateMemory, size, allocationType); + AllocationData allocationData{}; + MockAllocationProperties properties(rootDeviceIndex, allocateMemory, size, allocationType); getAllocationData(allocationData, properties, ptr, createStorageInfoFromProperties(properties)); return allocate32BitGraphicsMemoryImpl(allocationData); } diff --git a/opencl/test/unit_test/mocks/mock_memory_manager.h b/opencl/test/unit_test/mocks/mock_memory_manager.h index 015194d401..d56fe13fc4 100644 --- a/opencl/test/unit_test/mocks/mock_memory_manager.h +++ b/opencl/test/unit_test/mocks/mock_memory_manager.h @@ -107,7 +107,7 @@ class MockMemoryManager : public MemoryManagerCreate { bool isCpuCopyRequired(const void *ptr) override { return cpuCopyRequired; } - GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType); + GraphicsAllocation *allocate32BitGraphicsMemory(uint32_t rootDeviceIndex, size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType); GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override; void forceLimitedRangeAllocator(uint32_t rootDeviceIndex, uint64_t range) { getGfxPartition(rootDeviceIndex)->init(range, 0, 0, gfxPartitions.size()); } diff --git a/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp index 62c5fabe07..7918f97959 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp @@ -904,7 +904,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, makeResidentTwiceWhenFragmentSt auto ptr = (void *)0x1001; auto size = MemoryConstants::pageSize * 10; auto reqs = MockHostPtrManager::getAllocationRequirements(ptr, size); - auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, ptr); + auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, size}, ptr); ASSERT_EQ(3u, allocation->fragmentsStorage.fragmentCount); @@ -934,12 +934,12 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenFragmentedAllocationsWithR //3 fragments auto ptr = (void *)0x1001; auto size = MemoryConstants::pageSize * 10; - auto graphicsAllocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, ptr); + auto graphicsAllocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, size}, ptr); auto offsetedPtr = (void *)((uintptr_t)ptr + size); auto size2 = MemoryConstants::pageSize - 1; - auto graphicsAllocation2 = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size2}, offsetedPtr); + auto graphicsAllocation2 = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, size2}, offsetedPtr); //graphicsAllocation2 reuses one fragment from graphicsAllocation EXPECT_EQ(graphicsAllocation->fragmentsStorage.fragmentStorageData[2].residency, graphicsAllocation2->fragmentsStorage.fragmentStorageData[0].residency); @@ -1001,7 +1001,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, GivenAllocationCreatedFromThree auto reqs = MockHostPtrManager::getAllocationRequirements(ptr, size); - auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, ptr); + auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, size}, ptr); ASSERT_EQ(3u, allocation->fragmentsStorage.fragmentCount); @@ -1031,7 +1031,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, GivenAllocationsContainingDiffe auto reqs = MockHostPtrManager::getAllocationRequirements(ptr, size); - auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, ptr); + auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, size}, ptr); ASSERT_EQ(2u, allocation->fragmentsStorage.fragmentCount); ASSERT_EQ(2u, reqs.requiredFragmentsCount); @@ -1055,7 +1055,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, GivenAllocationsContainingDiffe mm->freeGraphicsMemory(allocation); csr->getResidencyAllocations().clear(); - auto allocation2 = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size2}, ptr); + auto allocation2 = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, size2}, ptr); reqs = MockHostPtrManager::getAllocationRequirements(ptr, size2); ASSERT_EQ(1u, allocation2->fragmentsStorage.fragmentCount); @@ -1085,8 +1085,8 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, GivenTwoAllocationsWhenBackingS auto size = MemoryConstants::pageSize; auto ptr2 = (void *)0x1000; - auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, ptr); - auto allocation2 = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, ptr2); + auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, size}, ptr); + auto allocation2 = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, size}, ptr2); csr->makeResident(*allocation); csr->makeResident(*allocation2); 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 cf71359be4..6f23824e5c 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 @@ -423,7 +423,7 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr) { void *ptr = ::alignedMalloc(1024, 4096); ASSERT_NE(nullptr, ptr); - auto alloc = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, 1024}, ptr)); + auto alloc = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, false, 1024}, ptr)); ASSERT_NE(nullptr, alloc); EXPECT_NE(nullptr, alloc->getUnderlyingBuffer()); EXPECT_EQ(ptr, alloc->getUnderlyingBuffer()); @@ -467,7 +467,7 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr_MisAligned) { void *ptr = ptrOffset(ptrT, 128); - auto alloc = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, 1024}, ptr)); + auto alloc = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, false, 1024}, ptr)); ASSERT_NE(nullptr, alloc); EXPECT_NE(nullptr, alloc->getUnderlyingBuffer()); EXPECT_EQ(ptr, alloc->getUnderlyingBuffer()); @@ -487,7 +487,7 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr_UserptrFail) { void *ptrT = ::alignedMalloc(1024, 4096); ASSERT_NE(nullptr, ptrT); - auto alloc = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, 1024}, ptrT); + auto alloc = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, false, 1024}, ptrT); EXPECT_EQ(nullptr, alloc); ::alignedFree(ptrT); @@ -883,7 +883,7 @@ TEST_F(DrmMemoryManagerTest, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAsked auto ptr = reinterpret_cast(0x1001); auto size = MemoryConstants::pageSize * 10; - auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, ptr); + auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, false, size}, ptr); auto hostPtrManager = static_cast(memoryManager->getHostPtrManager()); @@ -907,7 +907,7 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedFor32BitAllocationThen32 auto size = 10u; memoryManager->setForce32BitAllocations(true); - auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr, GraphicsAllocation::AllocationType::BUFFER); + auto allocation = memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, size, nullptr, GraphicsAllocation::AllocationType::BUFFER); EXPECT_NE(nullptr, allocation); EXPECT_NE(nullptr, allocation->getUnderlyingBuffer()); EXPECT_GE(allocation->getUnderlyingBufferSize(), size); @@ -930,7 +930,7 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedFor32BitAllocationWhenLi auto size = 10u; memoryManager->setForce32BitAllocations(true); - auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr, GraphicsAllocation::AllocationType::BUFFER); + auto allocation = memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, size, nullptr, GraphicsAllocation::AllocationType::BUFFER); EXPECT_NE(nullptr, allocation); EXPECT_NE(nullptr, allocation->getUnderlyingBuffer()); EXPECT_GE(allocation->getUnderlyingBufferSize(), size); @@ -1121,7 +1121,7 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedFor32BitAllocationWithHo auto size = 10u; void *host_ptr = reinterpret_cast(0x1000); memoryManager->setForce32BitAllocations(true); - auto allocation = memoryManager->allocate32BitGraphicsMemory(size, host_ptr, GraphicsAllocation::AllocationType::BUFFER); + auto allocation = memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, size, host_ptr, GraphicsAllocation::AllocationType::BUFFER); EXPECT_EQ(nullptr, allocation); mock->ioctl_res_ext = &mock->NONE; @@ -1135,7 +1135,7 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedFor32BitAllocationAndAll auto size = 10u; memoryManager->setForce32BitAllocations(true); - auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr, GraphicsAllocation::AllocationType::BUFFER); + auto allocation = memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, size, nullptr, GraphicsAllocation::AllocationType::BUFFER); EXPECT_EQ(nullptr, allocation); mock->ioctl_res_ext = &mock->NONE; @@ -1149,7 +1149,7 @@ TEST_F(DrmMemoryManagerTest, givenLimitedRangeAllocatorWhenAskedForInternal32Bit auto size = 10u; memoryManager->forceLimitedRangeAllocator(0xFFFFFFFFF); - auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP); + auto allocation = memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, size, nullptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP); EXPECT_EQ(nullptr, allocation); mock->ioctl_res_ext = &mock->NONE; @@ -1276,7 +1276,7 @@ TEST_F(DrmMemoryManagerTest, Given32BitDeviceWithMemoryManagerWhenInternalHeapIs EXPECT_NE(0llu, alloc); size_t allocationSize = 4 * GB; - auto graphicsAllocation = memoryManager->allocate32BitGraphicsMemory(allocationSize, nullptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP); + auto graphicsAllocation = memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, allocationSize, nullptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP); EXPECT_EQ(nullptr, graphicsAllocation); EXPECT_TRUE(pDevice->getDeviceInfo().force32BitAddressess); } @@ -2345,7 +2345,7 @@ TEST_F(DrmMemoryManagerTest, given32BitAllocatorWithHeapAllocatorWhenLargerFragm size_t pages3size = 3 * MemoryConstants::pageSize; void *host_ptr = reinterpret_cast(0x1000); - DrmAllocation *graphicsAlloaction = memoryManager->allocate32BitGraphicsMemory(pages3size, host_ptr, GraphicsAllocation::AllocationType::BUFFER); + DrmAllocation *graphicsAlloaction = memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, pages3size, host_ptr, GraphicsAllocation::AllocationType::BUFFER); auto bo = graphicsAlloaction->getBO(); EXPECT_EQ(pages3size, bo->peekSize()); @@ -2421,7 +2421,7 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForInternalAllocationWit auto bufferSize = MemoryConstants::pageSize; void *ptr = nullptr; - auto drmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(bufferSize, ptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP)); + auto drmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, bufferSize, ptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP)); ASSERT_NE(nullptr, drmAllocation); EXPECT_NE(nullptr, drmAllocation->getUnderlyingBuffer()); @@ -2451,7 +2451,7 @@ TEST_F(DrmMemoryManagerTest, givenLimitedRangeAllocatorWhenAskedForInternalAlloc auto bufferSize = MemoryConstants::pageSize; void *ptr = nullptr; - auto drmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(bufferSize, ptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP)); + auto drmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, bufferSize, ptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP)); ASSERT_NE(nullptr, drmAllocation); EXPECT_NE(nullptr, drmAllocation->getUnderlyingBuffer()); @@ -2485,7 +2485,7 @@ TEST_F(DrmMemoryManagerTest, givenLimitedRangeAllocatorWhenAskedForExternalAlloc auto bufferSize = MemoryConstants::pageSize; void *ptr = nullptr; - auto drmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(bufferSize, ptr, GraphicsAllocation::AllocationType::BUFFER)); + auto drmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, bufferSize, ptr, GraphicsAllocation::AllocationType::BUFFER)); ASSERT_NE(nullptr, drmAllocation); EXPECT_NE(nullptr, drmAllocation->getUnderlyingBuffer()); @@ -2499,7 +2499,7 @@ TEST_F(DrmMemoryManagerTest, givenLimitedRangeAllocatorWhenAskedForInternalAlloc auto bufferSize = 128 * MemoryConstants::megaByte + 4 * MemoryConstants::pageSize; void *ptr = nullptr; - auto drmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(bufferSize, ptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP)); + auto drmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, bufferSize, ptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP)); ASSERT_EQ(nullptr, drmAllocation); } @@ -2510,7 +2510,7 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForInternalAllocationWit auto bufferSize = MemoryConstants::pageSize; void *ptr = reinterpret_cast(0x100000); - auto drmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(bufferSize, ptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP)); + auto drmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, bufferSize, ptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP)); ASSERT_NE(nullptr, drmAllocation); EXPECT_NE(nullptr, drmAllocation->getUnderlyingBuffer()); @@ -2701,7 +2701,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenMemoryManagerWhenAlloc } void *ptr = reinterpret_cast(0x1001); auto size = 4096u; - auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, ptr); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), false, size}, ptr); ASSERT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); memoryManager->freeGraphicsMemory(allocation); @@ -2718,7 +2718,7 @@ TEST_F(DrmMemoryManagerBasic, givenMemoryManagerWhenAllocate32BitGraphicsMemoryW void *ptr = reinterpret_cast(0x1001); auto size = MemoryConstants::pageSize; - auto allocation = memoryManager->allocate32BitGraphicsMemory(size, ptr, GraphicsAllocation::AllocationType::BUFFER); + auto allocation = memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, size, ptr, GraphicsAllocation::AllocationType::BUFFER); ASSERT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::System4KBPagesWith32BitGpuAddressing, allocation->getMemoryPool()); @@ -2873,11 +2873,11 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenValidateHostPtrMemoryE for (auto engine : memoryManager->registeredEngines) { engine.osContext->incRefInternal(); } - ASSERT_NE(nullptr, memoryManager->pinBBs[0]); + ASSERT_NE(nullptr, memoryManager->pinBBs[device->getRootDeviceIndex()]); size_t size = 10 * MB; void *ptr = ::alignedMalloc(size, 4096); - auto alloc = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, ptr)); + auto alloc = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), false, size}, ptr)); ASSERT_NE(nullptr, alloc); EXPECT_NE(nullptr, alloc->getBO()); diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.h b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.h index 5d590a2854..e6e7f644a7 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.h +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.h @@ -30,7 +30,7 @@ class DrmMemoryManagerBasic : public ::testing::Test { executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[0])); executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(); } - + const uint32_t rootDeviceIndex = 0u; MockExecutionEnvironment executionEnvironment; }; @@ -39,6 +39,7 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture { DrmMockCustom *mock; DrmMockCustom *nonDefaultDrm = nullptr; const uint32_t nonDefaultRootDeviceIndex = 1u; + const uint32_t rootDeviceIndex = 0u; TestedDrmMemoryManager *memoryManager = nullptr; MockClDevice *device = nullptr; diff --git a/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp b/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp index fa58f43ffc..5449d43ab0 100644 --- a/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp @@ -616,7 +616,7 @@ TEST_F(WddmCommandStreamTest, givenGraphicsAllocationWhenMakeResidentThenAllocat void *hostPtr = reinterpret_cast(wddm->virtualAllocAddress + 0x1234); auto size = 1234u; - auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, hostPtr); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, size}, hostPtr); ASSERT_NE(nullptr, gfxAllocation); @@ -637,7 +637,7 @@ TEST_F(WddmCommandStreamTest, givenHostPtrAllocationWhenMapFailsThenFragmentsAre wddm->mapGpuVirtualAddressResult.called = 0u; wddm->destroyAllocationResult.called = 0u; - auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, hostPtr); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, size}, hostPtr); EXPECT_EQ(1u, wddm->mapGpuVirtualAddressResult.called); EXPECT_EQ(1u, wddm->destroyAllocationResult.called); @@ -650,7 +650,7 @@ TEST_F(WddmCommandStreamTest, givenAddressWithHighestBitSetWhenItIsMappedThenPro wddm->mapGpuVirtualAddressResult.called = 0u; - auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize}, faultyAddress); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, MemoryConstants::pageSize}, faultyAddress); EXPECT_EQ(1u, wddm->mapGpuVirtualAddressResult.called); ASSERT_NE(nullptr, gfxAllocation); @@ -666,7 +666,7 @@ TEST_F(WddmCommandStreamTest, givenHostPtrWhenPtrBelowRestrictionThenCreateAlloc void *hostPtr = reinterpret_cast(memoryManager->getAlignedMallocRestrictions()->minAddress - 0x1000); auto size = 0x2000u; - auto gfxAllocation = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, hostPtr)); + auto gfxAllocation = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, size}, hostPtr)); void *expectedReserve = reinterpret_cast(wddm->virtualAllocAddress); @@ -686,8 +686,8 @@ TEST_F(WddmCommandStreamTest, givenTwoTemporaryAllocationsWhenCleanTemporaryAllo void *host_ptr2 = (void *)0x2212341; auto size = 17262u; - GraphicsAllocation *graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, host_ptr); - GraphicsAllocation *graphicsAllocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, host_ptr2); + GraphicsAllocation *graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, size}, host_ptr); + GraphicsAllocation *graphicsAllocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, size}, host_ptr2); csr->getInternalAllocationStorage()->storeAllocation(std::unique_ptr(graphicsAllocation), TEMPORARY_ALLOCATION); csr->getInternalAllocationStorage()->storeAllocation(std::unique_ptr(graphicsAllocation2), TEMPORARY_ALLOCATION); 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 9cd0d6c23d..2120399d96 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 @@ -43,10 +43,10 @@ class MockWddmMemoryManager : public MemoryManagerCreate { bool validateAllocationMock(WddmAllocation *graphicsAllocation) { return this->validateAllocation(graphicsAllocation); } - GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType) { + GraphicsAllocation *allocate32BitGraphicsMemory(uint32_t rootDeviceIndex, size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType) { bool allocateMemory = ptr == nullptr; AllocationData allocationData; - MockAllocationProperties properties(allocateMemory, size, allocationType); + MockAllocationProperties properties(rootDeviceIndex, allocateMemory, size, allocationType); getAllocationData(allocationData, properties, ptr, createStorageInfoFromProperties(properties)); return allocate32BitGraphicsMemoryImpl(allocationData); } 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 14fbe19ee8..4b78fb9148 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 @@ -42,19 +42,19 @@ void WddmMemoryManagerFixture::SetUp() { GdiDllFixture::SetUp(); executionEnvironment = platform()->peekExecutionEnvironment(); - rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get(); - wddm = static_cast(Wddm::createWddm(nullptr, *executionEnvironment->rootDeviceEnvironments[0].get())); + rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[rootDeviceIndex].get(); + wddm = static_cast(Wddm::createWddm(nullptr, *rootDeviceEnvironment)); if (defaultHwInfo->capabilityTable.ftrRenderCompressedBuffers || defaultHwInfo->capabilityTable.ftrRenderCompressedImages) { GMM_TRANSLATIONTABLE_CALLBACKS dummyTTCallbacks = {}; - executionEnvironment->rootDeviceEnvironments[0]->pageTableManager.reset(GmmPageTableMngr::create(nullptr, 0, &dummyTTCallbacks)); + rootDeviceEnvironment->pageTableManager.reset(GmmPageTableMngr::create(nullptr, 0, &dummyTTCallbacks)); } wddm->init(); constexpr uint64_t heap32Base = (is32bit) ? 0x1000 : 0x800000000000; wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1); - executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); - executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setWddm(wddm); - executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(wddm); + rootDeviceEnvironment->osInterface = std::make_unique(); + rootDeviceEnvironment->osInterface->get()->setWddm(wddm); + rootDeviceEnvironment->memoryOperationsInterface = std::make_unique(wddm); memoryManager = std::make_unique(*executionEnvironment); } @@ -167,7 +167,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemory memoryManager.reset(new MockWddmMemoryManager(false, false, *executionEnvironment)); void *ptr = reinterpret_cast(0x1001); auto size = 4096u; - auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, ptr); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, size}, ptr); ASSERT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); for (size_t i = 0; i < allocation->fragmentsStorage.fragmentCount; i++) { @@ -181,7 +181,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocate32BitGraphicsM void *ptr = reinterpret_cast(0x1001); auto size = MemoryConstants::pageSize; - auto allocation = memoryManager->allocate32BitGraphicsMemory(size, ptr, GraphicsAllocation::AllocationType::BUFFER); + auto allocation = memoryManager->allocate32BitGraphicsMemory(csr->getRootDeviceIndex(), size, ptr, GraphicsAllocation::AllocationType::BUFFER); ASSERT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::System4KBPagesWith32BitGpuAddressing, allocation->getMemoryPool()); @@ -194,7 +194,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesDisabledWhenA memoryManager.reset(new MockWddmMemoryManager(false, false, *executionEnvironment)); auto size = MemoryConstants::pageSize; - auto svmAllocation = memoryManager->allocateGraphicsMemoryWithProperties({0, size, GraphicsAllocation::AllocationType::SVM_ZERO_COPY}); + auto svmAllocation = memoryManager->allocateGraphicsMemoryWithProperties({csr->getRootDeviceIndex(), size, GraphicsAllocation::AllocationType::SVM_ZERO_COPY}); EXPECT_NE(nullptr, svmAllocation); EXPECT_EQ(MemoryPool::System4KBPages, svmAllocation->getMemoryPool()); EXPECT_TRUE(svmAllocation->getDefaultGmm()->useSystemMemoryPool); @@ -205,7 +205,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAl memoryManager.reset(new MockWddmMemoryManager(true, false, *executionEnvironment)); auto size = MemoryConstants::pageSize; - auto svmAllocation = memoryManager->allocateGraphicsMemoryWithProperties({0, size, GraphicsAllocation::AllocationType::SVM_ZERO_COPY}); + auto svmAllocation = memoryManager->allocateGraphicsMemoryWithProperties({csr->getRootDeviceIndex(), size, GraphicsAllocation::AllocationType::SVM_ZERO_COPY}); EXPECT_NE(nullptr, svmAllocation); EXPECT_EQ(MemoryPool::System64KBPages, svmAllocation->getMemoryPool()); memoryManager->freeGraphicsMemory(svmAllocation); @@ -463,7 +463,7 @@ TEST_F(WddmMemoryManagerTest, AllocateGpuMemHostPtr) { void *ptr = alignedMalloc(3 * 4096, 4096); ASSERT_NE(nullptr, ptr); - auto *gpuAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize}, ptr); + auto *gpuAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, false, MemoryConstants::pageSize}, ptr); // Should be same cpu ptr and gpu ptr EXPECT_EQ(ptr, gpuAllocation->getUnderlyingBuffer()); @@ -788,7 +788,7 @@ TEST_F(WddmMemoryManagerTest, AllocateGpuMemHostPtrOffseted) { size_t baseOffset = 1024; // misalligned buffer spanning accross 3 pages - auto *gpuAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, 2 * MemoryConstants::pageSize}, (char *)ptr + baseOffset); + auto *gpuAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, false, 2 * MemoryConstants::pageSize}, (char *)ptr + baseOffset); // Should be same cpu ptr and gpu ptr EXPECT_EQ((char *)ptr + baseOffset, gpuAllocation->getUnderlyingBuffer()); @@ -806,7 +806,7 @@ TEST_F(WddmMemoryManagerTest, AllocateGpuMemHostPtrOffseted) { // offseted by one page, still in boundary void *offsetedPtr = ptrOffset(ptr, 4096); - auto *gpuAllocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize}, offsetedPtr); + auto *gpuAllocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, false, MemoryConstants::pageSize}, offsetedPtr); // Should be same cpu ptr and gpu ptr EXPECT_EQ(offsetedPtr, gpuAllocation2->getUnderlyingBuffer()); @@ -837,7 +837,7 @@ TEST_F(WddmMemoryManagerTest, AllocateGpuMemCheckGmm) { MockWddmAllocation allocation; // three pages void *ptr = alignedMalloc(3 * 4096, 4096); - auto *gpuAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, 3 * MemoryConstants::pageSize}, ptr); + auto *gpuAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, false, 3 * MemoryConstants::pageSize}, ptr); // Should be same cpu ptr and gpu ptr ASSERT_NE(nullptr, gpuAllocation); EXPECT_EQ(ptr, gpuAllocation->getUnderlyingBuffer()); @@ -855,7 +855,7 @@ TEST_F(WddmMemoryManagerTest, GivenAlignedPointerWhenAllocate32BitMemoryThenGmmC MockWddmAllocation allocation; uint32_t size = 4096; void *ptr = reinterpret_cast(4096); - auto *gpuAllocation = memoryManager->allocate32BitGraphicsMemory(size, ptr, GraphicsAllocation::AllocationType::BUFFER); + auto *gpuAllocation = memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, size, ptr, GraphicsAllocation::AllocationType::BUFFER); EXPECT_EQ(ptr, reinterpret_cast(gpuAllocation->getDefaultGmm()->resourceParams.pExistingSysMem)); EXPECT_EQ(size, gpuAllocation->getDefaultGmm()->resourceParams.ExistingSysMemSize); memoryManager->freeGraphicsMemory(gpuAllocation); @@ -865,7 +865,7 @@ TEST_F(WddmMemoryManagerTest, GivenUnAlignedPointerAndSizeWhenAllocate32BitMemor MockWddmAllocation allocation; uint32_t size = 0x1001; void *ptr = reinterpret_cast(0x1001); - auto *gpuAllocation = memoryManager->allocate32BitGraphicsMemory(size, ptr, GraphicsAllocation::AllocationType::BUFFER); + auto *gpuAllocation = memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, size, ptr, GraphicsAllocation::AllocationType::BUFFER); EXPECT_EQ(reinterpret_cast(0x1000), reinterpret_cast(gpuAllocation->getDefaultGmm()->resourceParams.pExistingSysMem)); EXPECT_EQ(0x2000, gpuAllocation->getDefaultGmm()->resourceParams.ExistingSysMemSize); memoryManager->freeGraphicsMemory(gpuAllocation); @@ -896,7 +896,7 @@ TEST_F(WddmMemoryManagerTest, getMaxApplicationAddress) { } TEST_F(WddmMemoryManagerTest, Allocate32BitMemoryWithNullptr) { - auto *gpuAllocation = memoryManager->allocate32BitGraphicsMemory(3 * MemoryConstants::pageSize, nullptr, GraphicsAllocation::AllocationType::BUFFER); + auto *gpuAllocation = memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, 3 * MemoryConstants::pageSize, nullptr, GraphicsAllocation::AllocationType::BUFFER); ASSERT_NE(nullptr, gpuAllocation); EXPECT_LT(GmmHelper::canonize(memoryManager->getGfxPartition(0)->getHeapBase(HeapIndex::HEAP_EXTERNAL)), gpuAllocation->getGpuAddress()); @@ -907,7 +907,7 @@ TEST_F(WddmMemoryManagerTest, Allocate32BitMemoryWithNullptr) { } TEST_F(WddmMemoryManagerTest, given32BitAllocationWhenItIsCreatedThenItHasNonZeroGpuAddressToPatch) { - auto *gpuAllocation = memoryManager->allocate32BitGraphicsMemory(3 * MemoryConstants::pageSize, nullptr, GraphicsAllocation::AllocationType::BUFFER); + auto *gpuAllocation = memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, 3 * MemoryConstants::pageSize, nullptr, GraphicsAllocation::AllocationType::BUFFER); ASSERT_NE(nullptr, gpuAllocation); EXPECT_NE(0llu, gpuAllocation->getGpuAddressToPatch()); @@ -920,14 +920,14 @@ TEST_F(WddmMemoryManagerTest, Allocate32BitMemoryWithMisalignedHostPtrDoesNotDoT size_t misalignedSize = 0x2500; void *misalignedPtr = reinterpret_cast(0x12500); - auto *gpuAllocation = memoryManager->allocate32BitGraphicsMemory(misalignedSize, misalignedPtr, GraphicsAllocation::AllocationType::BUFFER); + auto *gpuAllocation = memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, misalignedSize, misalignedPtr, GraphicsAllocation::AllocationType::BUFFER); ASSERT_NE(nullptr, gpuAllocation); EXPECT_EQ(alignSizeWholePage(misalignedPtr, misalignedSize), gpuAllocation->getUnderlyingBufferSize()); - EXPECT_LT(GmmHelper::canonize(memoryManager->getGfxPartition(0)->getHeapBase(HeapIndex::HEAP_EXTERNAL)), gpuAllocation->getGpuAddress()); - EXPECT_GT(GmmHelper::canonize(memoryManager->getGfxPartition(0)->getHeapLimit(HeapIndex::HEAP_EXTERNAL)), gpuAllocation->getGpuAddress() + gpuAllocation->getUnderlyingBufferSize()); + EXPECT_LT(GmmHelper::canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapBase(HeapIndex::HEAP_EXTERNAL)), gpuAllocation->getGpuAddress()); + EXPECT_GT(GmmHelper::canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_EXTERNAL)), gpuAllocation->getGpuAddress() + gpuAllocation->getUnderlyingBufferSize()); EXPECT_EQ(0u, gpuAllocation->fragmentsStorage.fragmentCount); @@ -939,7 +939,7 @@ TEST_F(WddmMemoryManagerTest, Allocate32BitMemoryWithMisalignedHostPtrDoesNotDoT } TEST_F(WddmMemoryManagerTest, Allocate32BitMemorySetsCannonizedGpuBaseAddress) { - auto *gpuAllocation = memoryManager->allocate32BitGraphicsMemory(3 * MemoryConstants::pageSize, nullptr, GraphicsAllocation::AllocationType::BUFFER); + auto *gpuAllocation = memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, 3 * MemoryConstants::pageSize, nullptr, GraphicsAllocation::AllocationType::BUFFER); ASSERT_NE(nullptr, gpuAllocation); @@ -1002,7 +1002,7 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCpuMemNotMeetRestriction void *cpuPtr = reinterpret_cast(memoryManager->getAlignedMallocRestrictions()->minAddress - 0x1000); size_t size = 0x1000; - auto allocation = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, cpuPtr)); + auto allocation = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{0, false, size}, cpuPtr)); void *expectReserve = reinterpret_cast(wddm->virtualAllocAddress); @@ -1058,13 +1058,12 @@ TEST_F(WddmMemoryManagerTest, givenManagerWithEnabledDeferredDeleterWhenFirstAnd } TEST_F(WddmMemoryManagerTest, givenNullPtrAndSizePassedToCreateInternalAllocationWhenCallIsMadeThenAllocationIsCreatedIn32BitHeapInternal) { - auto wddmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(MemoryConstants::pageSize, nullptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP)); + auto wddmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, MemoryConstants::pageSize, nullptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP)); ASSERT_NE(nullptr, wddmAllocation); EXPECT_EQ(wddmAllocation->getGpuBaseAddress(), GmmHelper::canonize(memoryManager->getInternalHeapBaseAddress(wddmAllocation->getRootDeviceIndex()))); EXPECT_NE(nullptr, wddmAllocation->getUnderlyingBuffer()); EXPECT_EQ(4096u, wddmAllocation->getUnderlyingBufferSize()); EXPECT_NE((uint64_t)wddmAllocation->getUnderlyingBuffer(), wddmAllocation->getGpuAddress()); - auto rootDeviceIndex = wddmAllocation->getRootDeviceIndex(); auto cannonizedHeapBase = GmmHelper::canonize(memoryManager->getInternalHeapBaseAddress(rootDeviceIndex)); auto cannonizedHeapEnd = GmmHelper::canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY)); @@ -1078,9 +1077,8 @@ TEST_F(WddmMemoryManagerTest, givenNullPtrAndSizePassedToCreateInternalAllocatio TEST_F(WddmMemoryManagerTest, givenPtrAndSizePassedToCreateInternalAllocationWhenCallIsMadeThenAllocationIsCreatedIn32BitHeapInternal) { auto ptr = reinterpret_cast(0x1000000); - auto wddmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(MemoryConstants::pageSize, ptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP)); + auto wddmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(rootDeviceIndex, MemoryConstants::pageSize, ptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP)); ASSERT_NE(nullptr, wddmAllocation); - auto rootDeviceIndex = wddmAllocation->getRootDeviceIndex(); EXPECT_EQ(wddmAllocation->getGpuBaseAddress(), GmmHelper::canonize(memoryManager->getInternalHeapBaseAddress(rootDeviceIndex))); EXPECT_EQ(ptr, wddmAllocation->getUnderlyingBuffer()); EXPECT_EQ(4096u, wddmAllocation->getUnderlyingBufferSize()); @@ -1140,7 +1138,7 @@ TEST_F(BufferWithWddmMemory, NullOsHandleStorageAskedForPopulationReturnsFilledP TEST_F(BufferWithWddmMemory, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAskedForGraphicsAllcoationThenItContainsAllFragmentsWithProperGpuAdrresses) { auto ptr = reinterpret_cast(wddm->virtualAllocAddress + 0x1001); auto size = MemoryConstants::pageSize * 10; - auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, ptr); + auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{context.getDevice(0)->getRootDeviceIndex(), false, size}, ptr); auto hostPtrManager = static_cast(memoryManager->getHostPtrManager()); @@ -1368,7 +1366,7 @@ TEST_F(MockWddmMemoryManagerTest, givenValidateAllocationFunctionWhenItIsCalledW wddm->init(); MockWddmMemoryManager memoryManager(*executionEnvironment); - auto wddmAlloc = static_cast(memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize}, reinterpret_cast(0x1000))); + auto wddmAlloc = static_cast(memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, false, MemoryConstants::pageSize}, reinterpret_cast(0x1000))); EXPECT_TRUE(memoryManager.validateAllocationMock(wddmAlloc)); @@ -1811,7 +1809,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenAllocationWithReservedGpuVirtualAddress TEST_F(WddmMemoryManagerSimpleTest, givenSvmCpuAllocationWhenSizeAndAlignmentProvidedThenAllocateMemoryReserveGpuVa) { size_t size = 2 * MemoryConstants::megaByte; - MockAllocationProperties properties{true, size, GraphicsAllocation::AllocationType::SVM_CPU}; + MockAllocationProperties properties{csr->getRootDeviceIndex(), true, size, GraphicsAllocation::AllocationType::SVM_CPU}; properties.alignment = size; auto allocation = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(properties)); ASSERT_NE(nullptr, allocation); diff --git a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.h b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.h index fd8b9a5e65..0bfecdade1 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.h +++ b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.h @@ -41,7 +41,8 @@ class WddmMemoryManagerFixture : public GdiDllFixture { ExecutionEnvironment *executionEnvironment; RootDeviceEnvironment *rootDeviceEnvironment = nullptr; std::unique_ptr memoryManager; - WddmMock *wddm; + WddmMock *wddm = nullptr; + const uint32_t rootDeviceIndex = 0u; }; typedef ::Test WddmMemoryManagerTest; @@ -180,13 +181,14 @@ class MockWddmMemoryManagerTest : public ::testing::Test { void SetUp() override { executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 2); wddm = new WddmMock(*executionEnvironment->rootDeviceEnvironments[1].get()); - executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setWddm(wddm); - executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(wddm); + executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->setWddm(wddm); + executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = std::make_unique(wddm); } - HardwareInfo *hwInfo; - WddmMock *wddm; - ExecutionEnvironment *executionEnvironment; + HardwareInfo *hwInfo = nullptr; + WddmMock *wddm = nullptr; + ExecutionEnvironment *executionEnvironment = nullptr; + const uint32_t rootDeviceIndex = 0u; }; using OsAgnosticMemoryManagerUsingWddmTest = MockWddmMemoryManagerTest; diff --git a/opencl/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp index 5aaddd78eb..cf33f62de3 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp @@ -550,7 +550,7 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, givenTripleAllocation // 3-fragment Allocation void *ptr = reinterpret_cast(wddm->virtualAllocAddress + 0x1500); - auto allocationTriple = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, 2 * MemoryConstants::pageSize}, ptr)); + auto allocationTriple = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, 2 * MemoryConstants::pageSize}, ptr)); // whole allocation unused since previous trim allocationTriple->getResidencyData().updateCompletionData(0, osContextId); @@ -789,7 +789,7 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, trimToBudgetEvictsDon allocation2.getResidencyData().resident[osContextId] = true; void *ptrTriple = reinterpret_cast(reinterpret_cast(ptr) + 0x500); - WddmAllocation *allocationTriple = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, 2 * MemoryConstants::pageSize}, ptrTriple)); + WddmAllocation *allocationTriple = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, 2 * MemoryConstants::pageSize}, ptrTriple)); allocationTriple->getResidencyData().updateCompletionData(1, osContextId); allocationTriple->getResidencyData().resident[osContextId] = true; @@ -929,7 +929,7 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, makeResidentResidency MockWddmAllocation allocation1, allocation2; void *ptr = reinterpret_cast(wddm->virtualAllocAddress + 0x1500); - WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, 2 * MemoryConstants::pageSize}, ptr); + WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, 2 * MemoryConstants::pageSize}, ptr); ResidencyContainer residencyPack{&allocation1, allocationTriple, &allocation2}; residencyController->makeResidentResidencyAllocations(residencyPack); @@ -946,7 +946,7 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, makeResidentResidency TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, makeResidentResidencyAllocationsSetsLastFencePLusOneForTripleAllocations) { MockWddmAllocation allocation1, allocation2; - WddmAllocation *allocationTriple = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, 2 * MemoryConstants::pageSize}, reinterpret_cast(0x1500))); + WddmAllocation *allocationTriple = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, 2 * MemoryConstants::pageSize}, reinterpret_cast(0x1500))); residencyController->getMonitoredFence().currentFenceValue = 20; @@ -982,7 +982,7 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallin TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallingMakeResidentResidencyAllocationsThenDontMarkTripleAllocationsAsResident) { MockWddmAllocation allocation1, allocation2; void *ptr = reinterpret_cast(wddm->getWddmMinAddress() + 0x1500); - WddmAllocation *allocationTriple = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, 2 * MemoryConstants::pageSize}, ptr)); + WddmAllocation *allocationTriple = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, 2 * MemoryConstants::pageSize}, ptr)); ASSERT_NE(nullptr, allocationTriple); auto makeResidentWithOutBytesToTrim = [](const D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim, size_t size) -> bool { *numberOfBytesToTrim = 4 * 4096; return false; };