From 2ca97d38810ca4d63d60641405d66267b3557098 Mon Sep 17 00:00:00 2001 From: "Venevtsev, Igor" Date: Tue, 16 Apr 2019 11:47:47 +0200 Subject: [PATCH] Introduce MemoryManager::getExternalHeapBaseAddress() Related-To: NEO-2877 Change-Id: I4307224c3be9609f7fc60d7fcb4f91ccdc8a9883 Signed-off-by: Venevtsev, Igor --- runtime/command_stream/command_stream_receiver_hw.inl | 2 +- runtime/memory_manager/memory_manager.h | 2 ++ runtime/memory_manager/os_agnostic_memory_manager.cpp | 8 ++++++-- runtime/memory_manager/os_agnostic_memory_manager.h | 1 + runtime/os_interface/linux/drm_memory_manager.cpp | 6 +++++- runtime/os_interface/linux/drm_memory_manager.h | 1 + runtime/os_interface/windows/wddm_memory_manager.cpp | 8 ++++++-- runtime/os_interface/windows/wddm_memory_manager.h | 1 + unit_tests/command_queue/enqueue_kernel_2_tests.cpp | 4 ++-- .../command_stream_receiver_flush_task_2_tests.cpp | 4 ++-- unit_tests/memory_manager/memory_manager_tests.cpp | 10 +++++----- .../os_interface/linux/drm_memory_manager_tests.cpp | 2 +- .../os_interface/windows/wddm_memory_manager_tests.cpp | 4 ++-- 13 files changed, 35 insertions(+), 18 deletions(-) diff --git a/runtime/command_stream/command_stream_receiver_hw.inl b/runtime/command_stream/command_stream_receiver_hw.inl index 441b5d7ed0..6735eb510b 100644 --- a/runtime/command_stream/command_stream_receiver_hw.inl +++ b/runtime/command_stream/command_stream_receiver_hw.inl @@ -310,7 +310,7 @@ CompletionStamp CommandStreamReceiverHw::flushTask( if (is64bit && scratchSpaceController->getScratchSpaceAllocation() && !force32BitAllocations) { newGSHbase = scratchSpaceController->calculateNewGSH(); } else if (is64bit && force32BitAllocations && dispatchFlags.GSBA32BitRequired) { - newGSHbase = getMemoryManager()->allocator32Bit->getBase(); + newGSHbase = getMemoryManager()->getExternalHeapBaseAddress(); GSBAFor32BitProgrammed = true; } diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index fc57cf04df..96b09c263e 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -108,6 +108,8 @@ class MemoryManager { virtual uint64_t getInternalHeapBaseAddress() = 0; + virtual uint64_t getExternalHeapBaseAddress() = 0; + bool peek64kbPagesEnabled() const { return enable64kbpages; } bool peekForce32BitAllocations() const { return force32bitAllocations; } void setForce32BitAllocations(bool newValue); diff --git a/runtime/memory_manager/os_agnostic_memory_manager.cpp b/runtime/memory_manager/os_agnostic_memory_manager.cpp index 93a7c744e0..a33d782a4d 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.cpp +++ b/runtime/memory_manager/os_agnostic_memory_manager.cpp @@ -104,7 +104,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(con allocationData.type, nullptr, const_cast(allocationData.hostPtr), GmmHelper::canonize(gpuVirtualAddress + offset), allocationData.size, counter, MemoryPool::System4KBPagesWith32BitGpuAddressing, false, false, false); memAlloc->set32BitAllocation(true); - memAlloc->setGpuBaseAddress(GmmHelper::canonize(allocator32Bit->getBase())); + memAlloc->setGpuBaseAddress(GmmHelper::canonize(getExternalHeapBaseAddress())); memAlloc->sizeToFree = allocationSize; counter++; @@ -129,7 +129,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(con allocationData.size, counter, MemoryPool::System4KBPagesWith32BitGpuAddressing, false, false, false); memoryAllocation->set32BitAllocation(true); - memoryAllocation->setGpuBaseAddress(GmmHelper::canonize(allocator32Bit->getBase())); + memoryAllocation->setGpuBaseAddress(GmmHelper::canonize(getExternalHeapBaseAddress())); memoryAllocation->sizeToFree = allocationSize; } counter++; @@ -214,6 +214,10 @@ uint64_t OsAgnosticMemoryManager::getInternalHeapBaseAddress() { return this->allocator32Bit->getBase(); } +uint64_t OsAgnosticMemoryManager::getExternalHeapBaseAddress() { + return this->allocator32Bit->getBase(); +} + GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) { auto allocation = new MemoryAllocation(allocationData.type, nullptr, const_cast(allocationData.hostPtr), reinterpret_cast(allocationData.hostPtr), allocationData.size, counter++, diff --git a/runtime/memory_manager/os_agnostic_memory_manager.h b/runtime/memory_manager/os_agnostic_memory_manager.h index a6ef78a627..04436b1d91 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.h +++ b/runtime/memory_manager/os_agnostic_memory_manager.h @@ -60,6 +60,7 @@ class OsAgnosticMemoryManager : public MemoryManager { uint64_t getSystemSharedMemory() override; uint64_t getMaxApplicationAddress() override; uint64_t getInternalHeapBaseAddress() override; + uint64_t getExternalHeapBaseAddress() override; void turnOnFakingBigAllocations(); diff --git a/runtime/os_interface/linux/drm_memory_manager.cpp b/runtime/os_interface/linux/drm_memory_manager.cpp index 08ed2f9741..288a059679 100644 --- a/runtime/os_interface/linux/drm_memory_manager.cpp +++ b/runtime/os_interface/linux/drm_memory_manager.cpp @@ -506,7 +506,7 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o if (requireSpecificBitness && this->force32bitAllocations) { drmAllocation->set32BitAllocation(true); - drmAllocation->setGpuBaseAddress(allocator32Bit->getBase()); + drmAllocation->setGpuBaseAddress(getExternalHeapBaseAddress()); } else if (this->limitedGpuAddressRangeAllocator.get()) { drmAllocation->setGpuBaseAddress(this->limitedGpuAddressRangeAllocator->getBase()); } @@ -630,6 +630,10 @@ uint64_t DrmMemoryManager::getInternalHeapBaseAddress() { return this->internal32bitAllocator->getBase(); } +uint64_t DrmMemoryManager::getExternalHeapBaseAddress() { + return this->allocator32Bit->getBase(); +} + MemoryManager::AllocationStatus DrmMemoryManager::populateOsHandles(OsHandleStorage &handleStorage) { BufferObject *allocatedBos[maxFragmentsCount]; uint32_t numberOfBosAllocated = 0; diff --git a/runtime/os_interface/linux/drm_memory_manager.h b/runtime/os_interface/linux/drm_memory_manager.h index d9a7a195e9..fe91eec65e 100644 --- a/runtime/os_interface/linux/drm_memory_manager.h +++ b/runtime/os_interface/linux/drm_memory_manager.h @@ -41,6 +41,7 @@ class DrmMemoryManager : public MemoryManager { uint64_t getSystemSharedMemory() override; uint64_t getMaxApplicationAddress() override; uint64_t getInternalHeapBaseAddress() override; + uint64_t getExternalHeapBaseAddress() override; AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) override; void cleanOsHandles(OsHandleStorage &handleStorage) override; diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index 5a71cd1bb9..29ec447e06 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -207,7 +207,7 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemoryImpl(const All return nullptr; } - auto baseAddress = useInternal32BitAllocator(allocationData.type) ? getInternalHeapBaseAddress() : allocator32Bit->getBase(); + auto baseAddress = useInternal32BitAllocator(allocationData.type) ? getInternalHeapBaseAddress() : getExternalHeapBaseAddress(); wddmAllocation->setGpuBaseAddress(GmmHelper::canonize(baseAddress)); return wddmAllocation.release(); @@ -235,7 +235,7 @@ GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handl allocation->setReservedAddressRange(ptr, size); } else if (requireSpecificBitness && this->force32bitAllocations) { allocation->set32BitAllocation(true); - allocation->setGpuBaseAddress(GmmHelper::canonize(allocator32Bit->getBase())); + allocation->setGpuBaseAddress(GmmHelper::canonize(getExternalHeapBaseAddress())); } status = mapGpuVirtualAddressWithRetry(allocation.get(), allocation->getReservedAddressPtr()); DEBUG_BREAK_IF(!status); @@ -481,6 +481,10 @@ uint64_t WddmMemoryManager::getInternalHeapBaseAddress() { return wddm->getGfxPartition().Heap32[static_cast(internalHeapIndex)].Base; } +uint64_t WddmMemoryManager::getExternalHeapBaseAddress() { + return allocator32Bit->getBase(); +} + bool WddmMemoryManager::mapAuxGpuVA(GraphicsAllocation *graphicsAllocation) { return wddm->updateAuxTable(graphicsAllocation->getGpuAddress(), graphicsAllocation->getDefaultGmm(), true); } diff --git a/runtime/os_interface/windows/wddm_memory_manager.h b/runtime/os_interface/windows/wddm_memory_manager.h index fbb4f610da..d230738e8e 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.h +++ b/runtime/os_interface/windows/wddm_memory_manager.h @@ -50,6 +50,7 @@ class WddmMemoryManager : public MemoryManager { uint64_t getSystemSharedMemory() override; uint64_t getMaxApplicationAddress() override; uint64_t getInternalHeapBaseAddress() override; + uint64_t getExternalHeapBaseAddress() override; bool tryDeferDeletions(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle); diff --git a/unit_tests/command_queue/enqueue_kernel_2_tests.cpp b/unit_tests/command_queue/enqueue_kernel_2_tests.cpp index 72ffdda8e9..428d139c34 100644 --- a/unit_tests/command_queue/enqueue_kernel_2_tests.cpp +++ b/unit_tests/command_queue/enqueue_kernel_2_tests.cpp @@ -184,7 +184,7 @@ HWCMDTEST_P(IGFX_GEN8_CORE, EnqueueWorkItemTestsWithLimitedParamSet, WhenEnqueue enqueueKernel(); validateStateBaseAddress(this->pDevice->getCommandStreamReceiver().getMemoryManager()->getInternalHeapBaseAddress(), pDSH, pIOH, pSSH, itorPipelineSelect, itorWalker, cmdList, - context->getMemoryManager()->peekForce32BitAllocations() ? context->getMemoryManager()->allocator32Bit->getBase() : 0llu); + context->getMemoryManager()->peekForce32BitAllocations() ? context->getMemoryManager()->getExternalHeapBaseAddress() : 0llu); } HWCMDTEST_P(IGFX_GEN8_CORE, EnqueueWorkItemTestsWithLimitedParamSet, MediaInterfaceDescriptorLoad) { @@ -491,7 +491,7 @@ HWCMDTEST_P(IGFX_GEN8_CORE, EnqueueKernelWithScratch, givenDeviceForcing32bitAll auto GSHaddress = (uintptr_t)sba->getGeneralStateBaseAddress(); - EXPECT_EQ(memoryManager->allocator32Bit->getBase(), GSHaddress); + EXPECT_EQ(memoryManager->getExternalHeapBaseAddress(), GSHaddress); //now re-try to see if SBA is not programmed diff --git a/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp b/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp index 246b8b70e5..6adeb720c7 100644 --- a/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp @@ -513,7 +513,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverFlushTaskTests, givenTwoConsecu } if (pDevice->getDeviceInfo().force32BitAddressess == true) { - EXPECT_EQ(pDevice->getMemoryManager()->allocator32Bit->getBase(), GSHaddress); + EXPECT_EQ(pDevice->getMemoryManager()->getExternalHeapBaseAddress(), GSHaddress); } else { if (is64bit) { EXPECT_EQ(graphicsAddress - HwHelperHw::get().getScratchSpaceOffsetFor64bit(), GSHaddress); @@ -622,7 +622,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverFlushTaskTests, givenNDRangeKer EXPECT_EQ(highPartGraphicsAddress, scratchBaseHighPart); if (pDevice->getDeviceInfo().force32BitAddressess == true) { - EXPECT_EQ(pDevice->getMemoryManager()->allocator32Bit->getBase(), GSHaddress); + EXPECT_EQ(pDevice->getMemoryManager()->getExternalHeapBaseAddress(), GSHaddress); } else { if (is64bit) { EXPECT_EQ(graphicsAddress - HwHelperHw::get().getScratchSpaceOffsetFor64bit(), GSHaddress); diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index 82e21e227d..2871ef10ab 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -1034,7 +1034,7 @@ TEST(OsAgnosticMemoryManager, givenPointerAndSizeWhenCreateInternalAllocationIsC TEST(OsAgnosticMemoryManager, givenDefaultOsAgnosticMemoryManagerWhenItIsQueriedForInternalHeapBaseThen32BitAllocatorBaseIsReturned) { MockExecutionEnvironment executionEnvironment(*platformDevices); OsAgnosticMemoryManager memoryManager(executionEnvironment); - auto heapBase = memoryManager.allocator32Bit->getBase(); + auto heapBase = memoryManager.getExternalHeapBaseAddress(); EXPECT_EQ(heapBase, memoryManager.getInternalHeapBaseAddress()); } TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenAllocateGraphicsMemoryForNonSvmHostPtrIsCalledThenAllocationIsCreated) { @@ -1126,7 +1126,7 @@ TEST(OsAgnosticMemoryManager, givenLocalMemoryNotSupportedWhenMemoryManagerIsCre if (is32bit) { heap32Base = 0; } - EXPECT_EQ(heap32Base, memoryManager.allocator32Bit->getBase()); + EXPECT_EQ(heap32Base, memoryManager.getExternalHeapBaseAddress()); } TEST(OsAgnosticMemoryManager, givenLocalMemorySupportedAndNotAubUsageWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) { @@ -1138,7 +1138,7 @@ TEST(OsAgnosticMemoryManager, givenLocalMemorySupportedAndNotAubUsageWhenMemoryM if (is32bit) { heap32Base = 0; } - EXPECT_EQ(heap32Base, memoryManager.allocator32Bit->getBase()); + EXPECT_EQ(heap32Base, memoryManager.getExternalHeapBaseAddress()); } TEST(OsAgnosticMemoryManager, givenLocalMemoryNotSupportedAndAubUsageWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) { @@ -1149,7 +1149,7 @@ TEST(OsAgnosticMemoryManager, givenLocalMemoryNotSupportedAndAubUsageWhenMemoryM if (is32bit) { heap32Base = 0; } - EXPECT_EQ(heap32Base, memoryManager.allocator32Bit->getBase()); + EXPECT_EQ(heap32Base, memoryManager.getExternalHeapBaseAddress()); } TEST(OsAgnosticMemoryManager, givenLocalMemorySupportedAndAubUsageWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) { @@ -1163,7 +1163,7 @@ TEST(OsAgnosticMemoryManager, givenLocalMemorySupportedAndAubUsageWhenMemoryMana } else { heap32Base = 0x40000000000ul; } - EXPECT_EQ(heap32Base, memoryManager.allocator32Bit->getBase()); + EXPECT_EQ(heap32Base, memoryManager.getExternalHeapBaseAddress()); } TEST(MemoryManager, givenSharedResourceCopyWhenAllocatingGraphicsMemoryThenAllocateGraphicsMemoryForImageIsCalled) { diff --git a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp index 727d808d3b..4265a89c82 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -719,7 +719,7 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedFor32BitAllocationThen32 EXPECT_GE(bo->peekUnmapSize(), 0u); EXPECT_TRUE(allocation->is32BitAllocation()); - EXPECT_EQ(memoryManager->allocator32Bit->getBase(), allocation->getGpuBaseAddress()); + EXPECT_EQ(memoryManager->getExternalHeapBaseAddress(), allocation->getGpuBaseAddress()); EXPECT_EQ(bo->peekAllocationType(), StorageAllocatorType::BIT32_ALLOCATOR_EXTERNAL); diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp index fd9312a13c..2fc51a97db 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -118,7 +118,7 @@ TEST(WddmMemoryManagerAllocator32BitTest, allocator32BitIsCreatedWithCorrectBase ASSERT_NE(nullptr, memoryManager->allocator32Bit.get()); - EXPECT_EQ(base, memoryManager->allocator32Bit->getBase()); + EXPECT_EQ(base, memoryManager->getExternalHeapBaseAddress()); } TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWMMWhenAsyncDeleterIsEnabledAndWaitForDeletionsIsCalledThenDeleterInWddmIsSetToNullptr) { @@ -519,7 +519,7 @@ TEST_F(WddmMemoryManagerTest, createAllocationFromSharedHandleReturns32BitAllocW if (is64bit) { EXPECT_TRUE(gpuAllocation->is32BitAllocation()); - uint64_t base = memoryManager->allocator32Bit->getBase(); + uint64_t base = memoryManager->getExternalHeapBaseAddress(); EXPECT_EQ(GmmHelper::canonize(base), gpuAllocation->getGpuBaseAddress()); }