Reverse logic of creating Memory Manager - part 4

-Remove a redundant parameter from WddmMemoryManager constructor

Change-Id: Ied9118d136e7d1f3e93b1bb6ce0e29d748bdbe01
Signed-off-by: Jobczyk, Lukasz <lukasz.jobczyk@intel.com>
This commit is contained in:
Jobczyk, Lukasz
2019-03-21 17:45:00 +01:00
committed by sys_ocldev
parent 14824f1dff
commit ee1854bfe8
14 changed files with 97 additions and 84 deletions

View File

@ -14,6 +14,6 @@
namespace OCLRT {
std::unique_ptr<MemoryManager> MemoryManager::createMemoryManager(ExecutionEnvironment &executionEnvironment) {
return std::make_unique<WddmMemoryManager>(executionEnvironment.osInterface->get()->getWddm(), executionEnvironment);
return std::make_unique<WddmMemoryManager>(executionEnvironment);
}
} // namespace OCLRT

View File

@ -9,6 +9,7 @@
#include "runtime/command_stream/command_stream_receiver_hw.h"
#include "runtime/device/device.h"
#include "runtime/execution_environment/execution_environment.h"
#include "runtime/gmm_helper/gmm.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/gmm_helper/resource_info.h"
@ -18,7 +19,9 @@
#include "runtime/memory_manager/deferrable_deletion.h"
#include "runtime/memory_manager/deferred_deleter.h"
#include "runtime/memory_manager/host_ptr_manager.h"
#include "runtime/os_interface/os_interface.h"
#include "runtime/os_interface/windows/os_context_win.h"
#include "runtime/os_interface/windows/os_interface.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include "runtime/os_interface/windows/wddm_allocation.h"
#include "runtime/os_interface/windows/wddm_residency_controller.h"
@ -32,9 +35,10 @@ WddmMemoryManager::~WddmMemoryManager() {
applyCommonCleanup();
}
WddmMemoryManager::WddmMemoryManager(Wddm *wddm, ExecutionEnvironment &executionEnvironment) : MemoryManager(executionEnvironment) {
WddmMemoryManager::WddmMemoryManager(ExecutionEnvironment &executionEnvironment) : MemoryManager(executionEnvironment) {
DEBUG_BREAK_IF(wddm == nullptr);
this->wddm = wddm;
wddm = executionEnvironment.osInterface->get()->getWddm();
allocator32Bit = std::unique_ptr<Allocator32bit>(new Allocator32bit(wddm->getExternalHeapBase(), wddm->getExternalHeapSize()));
asyncDeleterEnabled = DebugManager.flags.EnableDeferredDeleter.get();
if (asyncDeleterEnabled)

View File

@ -28,7 +28,7 @@ class WddmMemoryManager : public MemoryManager {
using MemoryManager::allocateGraphicsMemoryWithProperties;
~WddmMemoryManager() override;
WddmMemoryManager(Wddm *wddm, ExecutionEnvironment &executionEnvironment);
WddmMemoryManager(ExecutionEnvironment &executionEnvironment);
WddmMemoryManager(const WddmMemoryManager &) = delete;
WddmMemoryManager &operator=(const WddmMemoryManager &) = delete;

View File

@ -19,6 +19,6 @@ std::unique_ptr<MemoryManager> MemoryManager::createMemoryManager(ExecutionEnvir
if (overrideMemoryManagerCreation) {
return std::make_unique<OsAgnosticMemoryManager>(executionEnvironment);
}
return std::make_unique<WddmMemoryManager>(executionEnvironment.osInterface->get()->getWddm(), executionEnvironment);
return std::make_unique<WddmMemoryManager>(executionEnvironment);
}
} // namespace OCLRT

View File

@ -61,7 +61,7 @@ class WddmCommandStreamFixture {
csr = new WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(*executionEnvironment);
memoryManager = new MockWddmMemoryManager(wddm, *executionEnvironment);
memoryManager = new MockWddmMemoryManager(*executionEnvironment);
executionEnvironment->memoryManager.reset(memoryManager);
device.reset(MockDevice::create<MockDevice>(platformDevices[0], executionEnvironment, 0u));
@ -121,7 +121,7 @@ class WddmCommandStreamWithMockGdiFixture {
ASSERT_NE(wddm, nullptr);
DebugManager.flags.CsrDispatchMode.set(static_cast<uint32_t>(DispatchMode::ImmediateDispatch));
this->csr = new MockWddmCsr<DEFAULT_TEST_FAMILY_NAME>(*executionEnvironment);
memoryManager = new WddmMemoryManager(wddm, *executionEnvironment);
memoryManager = new WddmMemoryManager(*executionEnvironment);
ASSERT_NE(nullptr, memoryManager);
executionEnvironment->memoryManager.reset(memoryManager);
device = std::unique_ptr<MockDevice>(Device::create<MockDevice>(platformDevices[0], executionEnvironment, 0u));
@ -244,7 +244,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOf
auto wddm = static_cast<WddmMock *>(executionEnvironment->osInterface->get()->getWddm());
executionEnvironment->commandStreamReceivers.resize(1);
executionEnvironment->commandStreamReceivers[0].push_back(std::make_unique<MockWddmCsr<DEFAULT_TEST_FAMILY_NAME>>(*executionEnvironment));
executionEnvironment->memoryManager.reset(new MemoryManagerCreate<WddmMemoryManager>(false, false, wddm, *executionEnvironment));
executionEnvironment->memoryManager.reset(new MemoryManagerCreate<WddmMemoryManager>(false, false, *executionEnvironment));
executionEnvironment->commandStreamReceivers[0][0]->overrideDispatchPolicy(DispatchMode::ImmediateDispatch);
OsContextWin osContext(*wddm, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0],
PreemptionHelper::getDefaultPreemptionMode(*hwInfo), false);
@ -270,7 +270,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOn
auto wddm = static_cast<WddmMock *>(executionEnvironment->osInterface->get()->getWddm());
executionEnvironment->commandStreamReceivers.resize(1);
executionEnvironment->commandStreamReceivers[0].push_back(std::make_unique<MockWddmCsr<DEFAULT_TEST_FAMILY_NAME>>(*executionEnvironment));
executionEnvironment->memoryManager.reset(new MemoryManagerCreate<WddmMemoryManager>(false, false, wddm, *executionEnvironment));
executionEnvironment->memoryManager.reset(new MemoryManagerCreate<WddmMemoryManager>(false, false, *executionEnvironment));
executionEnvironment->commandStreamReceivers[0][0]->overrideDispatchPolicy(DispatchMode::ImmediateDispatch);
OsContextWin osContext(*wddm, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0],
PreemptionHelper::getDefaultPreemptionMode(*hwInfo), false);
@ -892,7 +892,7 @@ HWTEST_P(WddmCsrCompressionParameterizedTest, givenEnabledCompressionWhenFlushin
auto mockWddmCsr = new MockWddmCsr<FamilyType>(*executionEnvironment);
mockWddmCsr->createPageTableManager();
mockWddmCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch);
executionEnvironment->memoryManager.reset(new WddmMemoryManager(executionEnvironment->osInterface->get()->getWddm(), *executionEnvironment));
executionEnvironment->memoryManager.reset(new WddmMemoryManager(*executionEnvironment));
auto mockMngr = reinterpret_cast<MockGmmPageTableMngr *>(myMockWddm->getPageTableManager());
std::unique_ptr<MockDevice> device(Device::create<MockDevice>(hwInfo, executionEnvironment, 0u));
@ -938,7 +938,7 @@ HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenFlushingThenDontIn
auto mockWddmCsr = new MockWddmCsr<FamilyType>(*executionEnvironment);
mockWddmCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch);
executionEnvironment->memoryManager.reset(new WddmMemoryManager(executionEnvironment->osInterface->get()->getWddm(), *executionEnvironment));
executionEnvironment->memoryManager.reset(new WddmMemoryManager(*executionEnvironment));
std::unique_ptr<MockDevice> device(Device::create<MockDevice>(hwInfo, executionEnvironment, 0u));
device->resetCommandStreamReceiver(mockWddmCsr);

View File

@ -24,7 +24,7 @@ class MockWddmMemoryManager : public MemoryManagerCreate<WddmMemoryManager> {
using BaseClass::createWddmAllocation;
using MemoryManagerCreate<WddmMemoryManager>::MemoryManagerCreate;
MockWddmMemoryManager(Wddm *wddm, ExecutionEnvironment &executionEnvironment) : MemoryManagerCreate(false, false, wddm, executionEnvironment) {
MockWddmMemoryManager(ExecutionEnvironment &executionEnvironment) : MemoryManagerCreate(false, false, executionEnvironment) {
hostPtrManager.reset(new MockHostPtrManager);
};
void setDeferredDeleter(DeferredDeleter *deleter) {

View File

@ -388,7 +388,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF
auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u);
EXPECT_EQ(0u, status);
MemoryManagerCreate<WddmMemoryManager> mm(false, false, wddm, *executionEnvironment);
MemoryManagerCreate<WddmMemoryManager> mm(false, false, *executionEnvironment);
auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false);
auto wddmAllocation = (WddmAllocation *)graphicsAllocation;
@ -424,7 +424,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF
auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u);
EXPECT_EQ(0u, status);
MemoryManagerCreate<WddmMemoryManager> mm(false, false, wddm, *executionEnvironment);
MemoryManagerCreate<WddmMemoryManager> mm(false, false, *executionEnvironment);
auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false);
auto wddmAllocation = (WddmAllocation *)graphicsAllocation;
@ -940,7 +940,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceThenOtherReso
}
TEST_F(WddmLockWithMakeResidentTests, whenAlllocationNeedsBlockingMakeResidentBeforeLockThenLockWithBlockingMakeResident) {
WddmMemoryManager memoryManager(wddm, *executionEnvironment);
WddmMemoryManager memoryManager(*executionEnvironment);
MockWddmAllocation allocation;
allocation.needsMakeResidentBeforeLock = false;
memoryManager.lockResource(&allocation);

View File

@ -8,6 +8,7 @@
#pragma once
#include "runtime/command_stream/preemption.h"
#include "runtime/execution_environment/execution_environment.h"
#include "runtime/helpers/hw_helper.h"
#include "runtime/os_interface/windows/gdi_interface.h"
#include "runtime/os_interface/windows/os_context_win.h"
@ -25,8 +26,9 @@ struct WddmFixture : ::testing::Test {
void SetUp() {
executionEnvironment = platformImpl->peekExecutionEnvironment();
wddm = static_cast<WddmMock *>(Wddm::createWddm());
osInterface = std::make_unique<OSInterface>();
osInterface->get()->setWddm(wddm);
executionEnvironment->osInterface = std::make_unique<OSInterface>();
executionEnvironment->osInterface->get()->setWddm(wddm);
osInterface = executionEnvironment->osInterface.get();
gdi = new MockGdi();
wddm->gdi.reset(gdi);
auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]);
@ -36,7 +38,7 @@ struct WddmFixture : ::testing::Test {
}
WddmMock *wddm = nullptr;
std::unique_ptr<OSInterface> osInterface;
OSInterface *osInterface;
std::unique_ptr<OsContextWin> osContext;
ExecutionEnvironment *executionEnvironment;
@ -48,8 +50,9 @@ struct WddmFixtureWithMockGdiDll : public GdiDllFixture {
executionEnvironment = platformImpl->peekExecutionEnvironment();
GdiDllFixture::SetUp();
wddm = static_cast<WddmMock *>(Wddm::createWddm());
osInterface = std::make_unique<OSInterface>();
osInterface->get()->setWddm(wddm);
executionEnvironment->osInterface = std::make_unique<OSInterface>();
executionEnvironment->osInterface->get()->setWddm(wddm);
osInterface = executionEnvironment->osInterface.get();
}
void init() {
@ -64,7 +67,7 @@ struct WddmFixtureWithMockGdiDll : public GdiDllFixture {
}
WddmMock *wddm = nullptr;
std::unique_ptr<OSInterface> osInterface;
OSInterface *osInterface;
std::unique_ptr<OsContextWin> osContext;
ExecutionEnvironment *executionEnvironment;
};

View File

@ -14,7 +14,7 @@ using namespace OCLRT;
using namespace ::testing;
TEST_F(WddmMemoryManagerSimpleTest, givenUseSystemMemorySetToTrueWhenAllocateInDevicePoolIsCalledThenNullptrIsReturned) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment));
memoryManager.reset(new MockWddmMemoryManager(false, false, *executionEnvironment));
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;
AllocationData allocData;
allocData.size = MemoryConstants::pageSize;

View File

@ -19,6 +19,7 @@
#include "runtime/platform/platform.h"
#include "runtime/utilities/tag_allocator.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/helpers/execution_environment_helper.h"
#include "unit_tests/mocks/mock_deferred_deleter.h"
#include "unit_tests/mocks/mock_device.h"
#include "unit_tests/mocks/mock_memory_manager.h"
@ -46,7 +47,7 @@ void WddmMemoryManagerFixture::SetUp() {
executionEnvironment->osInterface = std::make_unique<OSInterface>();
executionEnvironment->osInterface->get()->setWddm(wddm);
memoryManager = std::make_unique<MockWddmMemoryManager>(wddm, *executionEnvironment);
memoryManager = std::make_unique<MockWddmMemoryManager>(*executionEnvironment);
}
TEST(ResidencyData, givenNewlyConstructedResidencyDataThenItIsNotResidentOnAnyOsContext) {
@ -104,13 +105,15 @@ TEST(WddmAllocationTest, givenMemoryPoolWhenPassedToWddmAllocationConstructorThe
}
TEST(WddmMemoryManagerAllocator32BitTest, allocator32BitIsCreatedWithCorrectBase) {
ExecutionEnvironment executionEnvironment;
HardwareInfo *hwInfo;
auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo);
std::unique_ptr<WddmMock> wddm(static_cast<WddmMock *>(Wddm::createWddm()));
uint64_t base = 0x56000;
uint64_t size = 0x9000;
wddm->setHeap32(base, size);
executionEnvironment->osInterface->get()->setWddm(wddm.release());
std::unique_ptr<WddmMemoryManager> memoryManager = std::unique_ptr<WddmMemoryManager>(new WddmMemoryManager(wddm.get(), executionEnvironment));
std::unique_ptr<WddmMemoryManager> memoryManager = std::unique_ptr<WddmMemoryManager>(new WddmMemoryManager(*executionEnvironment));
ASSERT_NE(nullptr, memoryManager->allocator32Bit.get());
@ -118,11 +121,13 @@ TEST(WddmMemoryManagerAllocator32BitTest, allocator32BitIsCreatedWithCorrectBase
}
TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWMMWhenAsyncDeleterIsEnabledAndWaitForDeletionsIsCalledThenDeleterInWddmIsSetToNullptr) {
ExecutionEnvironment executionEnvironment;
HardwareInfo *hwInfo;
auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo);
auto wddm = std::make_unique<WddmMock>();
executionEnvironment->osInterface->get()->setWddm(wddm.release());
bool actualDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get();
DebugManager.flags.EnableDeferredDeleter.set(true);
MockWddmMemoryManager memoryManager(wddm.get(), executionEnvironment);
MockWddmMemoryManager memoryManager(*executionEnvironment);
EXPECT_NE(nullptr, memoryManager.getDeferredDeleter());
memoryManager.waitForDeletions();
EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter());
@ -130,7 +135,7 @@ TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWMMWhenAsyncDeleterIsEnabled
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenMemoryPoolIsSystem4KBPages) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment));
memoryManager.reset(new MockWddmMemoryManager(false, false, *executionEnvironment));
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
EXPECT_NE(nullptr, allocation);
@ -140,7 +145,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemory
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemory64kbIsCalledThenMemoryPoolIsSystem64KBPages) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment));
memoryManager.reset(new MockWddmMemoryManager(false, false, *executionEnvironment));
AllocationData allocationData;
allocationData.size = 4096u;
auto allocation = memoryManager->allocateGraphicsMemory64kb(allocationData);
@ -151,7 +156,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAl
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPages) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment));
memoryManager.reset(new MockWddmMemoryManager(false, false, *executionEnvironment));
void *ptr = reinterpret_cast<void *>(0x1001);
auto size = 4096u;
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, ptr);
@ -164,7 +169,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemory
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment));
memoryManager.reset(new MockWddmMemoryManager(false, false, *executionEnvironment));
void *ptr = reinterpret_cast<void *>(0x1001);
auto size = MemoryConstants::pageSize;
@ -178,7 +183,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocate32BitGraphicsM
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMThen4KBGraphicsAllocationIsReturned) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment));
memoryManager.reset(new MockWddmMemoryManager(false, false, *executionEnvironment));
auto size = MemoryConstants::pageSize;
auto svmAllocation = memoryManager->allocateGraphicsMemoryWithProperties({size, GraphicsAllocation::AllocationType::SVM});
@ -189,7 +194,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesDisabledWhenA
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMThenMemoryPoolIsSystem64KBPages) {
memoryManager.reset(new MockWddmMemoryManager(true, false, wddm, *executionEnvironment));
memoryManager.reset(new MockWddmMemoryManager(true, false, *executionEnvironment));
auto size = MemoryConstants::pageSize;
auto svmAllocation = memoryManager->allocateGraphicsMemoryWithProperties({size, GraphicsAllocation::AllocationType::SVM});
@ -199,7 +204,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAl
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenCreateAllocationFromHandleIsCalledThenMemoryPoolIsSystemCpuInaccessible) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment));
memoryManager.reset(new MockWddmMemoryManager(false, false, *executionEnvironment));
auto osHandle = 1u;
gdi->getQueryResourceInfoArgOut().NumAllocations = 1;
std::unique_ptr<Gmm> gmm(new Gmm(nullptr, 0, false));
@ -218,7 +223,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenCreateAllocationFromHa
}
TEST_F(WddmMemoryManagerSimpleTest, whenCreateAllocationFromHandleAndMapCallFailsThenFreeGraphicsMemoryIsCalled) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment));
memoryManager.reset(new MockWddmMemoryManager(false, false, *executionEnvironment));
auto osHandle = 1u;
gdi->getQueryResourceInfoArgOut().NumAllocations = 1;
auto gmm = std::make_unique<Gmm>(nullptr, 0, false);
@ -239,7 +244,7 @@ TEST_F(WddmMemoryManagerSimpleTest, whenCreateAllocationFromHandleAndMapCallFail
TEST_F(WddmMemoryManagerSimpleTest,
givenAllocateGraphicsMemoryForNonSvmHostPtrIsCalledWhenNotAlignedPtrIsPassedThenAlignedGraphicsAllocationIsCreated) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment));
memoryManager.reset(new MockWddmMemoryManager(false, false, *executionEnvironment));
auto size = 13u;
auto hostPtr = reinterpret_cast<const void *>(0x5001);
@ -1171,28 +1176,25 @@ TEST_F(BufferWithWddmMemory, givenFragmentsThatAreNotInOrderWhenGraphicsAllocati
memoryManager->freeGraphicsMemory(allocation);
}
struct WddmMemoryManagerWithAsyncDeleterTest : ::testing::Test {
struct WddmMemoryManagerWithAsyncDeleterTest : public MockWddmMemoryManagerTest {
void SetUp() {
executionEnvironment = platform()->peekExecutionEnvironment();
wddm = std::make_unique<WddmMock>();
MockWddmMemoryManagerTest::SetUp();
wddm->gdi.reset(new MockGdi());
wddm->callBaseDestroyAllocations = false;
wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
deleter = new MockDeferredDeleter;
memoryManager = std::make_unique<MockWddmMemoryManager>(wddm.get(), *executionEnvironment);
memoryManager = std::make_unique<MockWddmMemoryManager>(*executionEnvironment);
memoryManager->setDeferredDeleter(deleter);
}
MockDeferredDeleter *deleter = nullptr;
std::unique_ptr<WddmMock> wddm;
std::unique_ptr<MockWddmMemoryManager> memoryManager;
ExecutionEnvironment *executionEnvironment;
};
TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsEnabledThenCanDeferDeletions) {
EXPECT_EQ(0, deleter->deferDeletionCalled);
memoryManager->tryDeferDeletions(nullptr, 0, 0);
EXPECT_EQ(1, deleter->deferDeletionCalled);
EXPECT_EQ(1u, wddm.get()->destroyAllocationResult.called);
EXPECT_EQ(1u, wddm->destroyAllocationResult.called);
}
TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsDisabledThenCannotDeferDeletions) {
@ -1255,19 +1257,19 @@ TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithoutAsyncDele
}
TEST(WddmMemoryManagerDefaults, givenDefaultWddmMemoryManagerWhenItIsQueriedForInternalHeapBaseThenHeapInternalBaseIsReturned) {
auto executionEnvironment = platform()->peekExecutionEnvironment();
auto wddm = std::make_unique<WddmMock>();
HardwareInfo *hwInfo;
auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo);
auto wddm = new WddmMock();
executionEnvironment->osInterface->get()->setWddm(wddm);
wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
MockWddmMemoryManager memoryManager(wddm.get(), *executionEnvironment);
MockWddmMemoryManager memoryManager(*executionEnvironment);
auto heapBase = wddm->getGfxPartition().Heap32[static_cast<uint32_t>(internalHeapIndex)].Base;
EXPECT_EQ(heapBase, memoryManager.getInternalHeapBaseAddress());
}
TEST_F(MockWddmMemoryManagerTest, givenValidateAllocationFunctionWhenItIsCalledWithTripleAllocationThenSuccessIsReturned) {
auto executionEnvironment = platform()->peekExecutionEnvironment();
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])));
MockWddmMemoryManager memoryManager(wddm.get(), *executionEnvironment);
MockWddmMemoryManager memoryManager(*executionEnvironment);
auto wddmAlloc = static_cast<WddmAllocation *>(memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize}, reinterpret_cast<void *>(0x1000)));
@ -1278,10 +1280,9 @@ TEST_F(MockWddmMemoryManagerTest, givenValidateAllocationFunctionWhenItIsCalledW
TEST_F(MockWddmMemoryManagerTest, givenEnabled64kbpagesWhenCreatingGraphicsMemoryForBufferWithoutHostPtrThen64kbAdressIsAllocated) {
DebugManagerStateRestore dbgRestore;
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])));
DebugManager.flags.Enable64kbpages.set(true);
MemoryManagerCreate<WddmMemoryManager> memoryManager64k(true, false, wddm.get(), *executionEnvironment);
MemoryManagerCreate<WddmMemoryManager> memoryManager64k(true, false, *executionEnvironment);
EXPECT_EQ(0, wddm->createAllocationResult.called);
GraphicsAllocation *galloc = memoryManager64k.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY});
@ -1296,10 +1297,9 @@ TEST_F(MockWddmMemoryManagerTest, givenEnabled64kbpagesWhenCreatingGraphicsMemor
TEST_F(OsAgnosticMemoryManagerUsingWddmTest, givenEnabled64kbPagesWhenAllocationIsCreatedWithSizeSmallerThan64kbThenGraphicsAllocationsHas64kbAlignedUnderlyingSize) {
DebugManagerStateRestore dbgRestore;
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])));
DebugManager.flags.Enable64kbpages.set(true);
MockWddmMemoryManager memoryManager(true, false, wddm.get(), *executionEnvironment);
MockWddmMemoryManager memoryManager(true, false, *executionEnvironment);
AllocationData allocationData;
allocationData.size = 1u;
auto graphicsAllocation = memoryManager.allocateGraphicsMemory64kb(allocationData);
@ -1314,12 +1314,10 @@ TEST_F(OsAgnosticMemoryManagerUsingWddmTest, givenEnabled64kbPagesWhenAllocation
}
TEST_F(MockWddmMemoryManagerTest, givenWddmWhenallocateGraphicsMemory64kbThenLockResultAndmapGpuVirtualAddressIsCalled) {
auto executionEnvironment = platform()->peekExecutionEnvironment();
DebugManagerStateRestore dbgRestore;
DebugManager.flags.Enable64kbpages.set(true);
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])));
MockWddmMemoryManager memoryManager64k(wddm.get(), *executionEnvironment);
MockWddmMemoryManager memoryManager64k(*executionEnvironment);
uint32_t lockCount = wddm->lockResult.called;
uint32_t mapGpuVirtualAddressResult = wddm->mapGpuVirtualAddressResult.called;
AllocationData allocationData;
@ -1336,8 +1334,7 @@ TEST_F(MockWddmMemoryManagerTest, givenWddmWhenallocateGraphicsMemory64kbThenLoc
}
TEST_F(MockWddmMemoryManagerTest, givenDefaultMemoryManagerWhenItIsCreatedThenAsyncDeleterEnabledIsTrue) {
auto wddm = std::make_unique<WddmMock>();
WddmMemoryManager memoryManager(wddm.get(), *executionEnvironment);
WddmMemoryManager memoryManager(*executionEnvironment);
EXPECT_TRUE(memoryManager.isAsyncDeleterEnabled());
EXPECT_NE(nullptr, memoryManager.getDeferredDeleter());
}
@ -1365,8 +1362,7 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWithRegisteredOsContextWithE
TEST_F(MockWddmMemoryManagerTest, givenEnabledAsyncDeleterFlagWhenMemoryManagerIsCreatedThenAsyncDeleterEnabledIsTrueAndDeleterIsNotNullptr) {
bool defaultEnableDeferredDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get();
DebugManager.flags.EnableDeferredDeleter.set(true);
auto wddm = std::make_unique<WddmMock>();
WddmMemoryManager memoryManager(wddm.get(), *executionEnvironment);
WddmMemoryManager memoryManager(*executionEnvironment);
EXPECT_TRUE(memoryManager.isAsyncDeleterEnabled());
EXPECT_NE(nullptr, memoryManager.getDeferredDeleter());
DebugManager.flags.EnableDeferredDeleter.set(defaultEnableDeferredDeleterFlag);
@ -1375,20 +1371,18 @@ TEST_F(MockWddmMemoryManagerTest, givenEnabledAsyncDeleterFlagWhenMemoryManagerI
TEST_F(MockWddmMemoryManagerTest, givenDisabledAsyncDeleterFlagWhenMemoryManagerIsCreatedThenAsyncDeleterEnabledIsFalseAndDeleterIsNullptr) {
bool defaultEnableDeferredDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get();
DebugManager.flags.EnableDeferredDeleter.set(false);
auto wddm = std::make_unique<WddmMock>();
WddmMemoryManager memoryManager(wddm.get(), *executionEnvironment);
WddmMemoryManager memoryManager(*executionEnvironment);
EXPECT_FALSE(memoryManager.isAsyncDeleterEnabled());
EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter());
DebugManager.flags.EnableDeferredDeleter.set(defaultEnableDeferredDeleterFlag);
}
TEST_F(MockWddmMemoryManagerTest, givenPageTableManagerWhenMapAuxGpuVaCalledThenUseWddmToMap) {
auto myWddm = std::make_unique<WddmMock>();
EXPECT_TRUE(myWddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])));
WddmMemoryManager memoryManager(myWddm.get(), *executionEnvironment);
EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])));
WddmMemoryManager memoryManager(*executionEnvironment);
auto mockMngr = new NiceMock<MockGmmPageTableMngr>();
myWddm->resetPageTableManager(mockMngr);
wddm->resetPageTableManager(mockMngr);
auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
@ -1436,9 +1430,8 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenMappedGpuVa
}
TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenReleaseingThenUnmapAuxVa) {
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])));
WddmMemoryManager memoryManager(wddm.get(), *executionEnvironment);
WddmMemoryManager memoryManager(*executionEnvironment);
D3DGPU_VIRTUAL_ADDRESS gpuVa = 123;
auto mockMngr = new NiceMock<MockGmmPageTableMngr>();
@ -1462,9 +1455,8 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenReleaseingT
}
TEST_F(MockWddmMemoryManagerTest, givenNonRenderCompressedAllocationWhenReleaseingThenDontUnmapAuxVa) {
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])));
WddmMemoryManager memoryManager(wddm.get(), *executionEnvironment);
WddmMemoryManager memoryManager(*executionEnvironment);
auto mockMngr = new NiceMock<MockGmmPageTableMngr>();
wddm->resetPageTableManager(mockMngr);
@ -1506,9 +1498,8 @@ TEST_F(MockWddmMemoryManagerTest, givenFailingAllocationWhenMappedGpuVaThenRetur
TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedFlagSetWhenInternalIsUnsetThenDontUpdateAuxTable) {
D3DGPU_VIRTUAL_ADDRESS gpuVa = 0;
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])));
WddmMemoryManager memoryManager(wddm.get(), *executionEnvironment);
WddmMemoryManager memoryManager(*executionEnvironment);
auto mockMngr = new NiceMock<MockGmmPageTableMngr>();
wddm->resetPageTableManager(mockMngr);
@ -1580,7 +1571,7 @@ TEST(WddmMemoryManagerCleanupTest, givenUsedTagAllocationInWddmMemoryManagerWhen
executionEnvironment.osInterface->get()->setWddm(wddm);
executionEnvironment.commandStreamReceivers.resize(1);
executionEnvironment.commandStreamReceivers[0].push_back(std::unique_ptr<CommandStreamReceiver>(csr));
executionEnvironment.memoryManager = std::make_unique<WddmMemoryManager>(wddm, executionEnvironment);
executionEnvironment.memoryManager = std::make_unique<WddmMemoryManager>(executionEnvironment);
auto osContext = executionEnvironment.memoryManager->createAndRegisterOsContext(csr, ENGINE_RCS, 1, preemptionMode, false);
csr->setupContext(*osContext);
EXPECT_EQ(csr, executionEnvironment.memoryManager->getDefaultCommandStreamReceiver(0));

View File

@ -9,6 +9,7 @@
#include "runtime/os_interface/windows/os_interface.h"
#include "test.h"
#include "unit_tests/helpers/execution_environment_helper.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_gmm.h"
#include "unit_tests/mocks/mock_gmm_page_table_mngr.h"
@ -54,7 +55,7 @@ class MockWddmMemoryManagerFixture {
executionEnvironment->osInterface.reset(new OSInterface());
executionEnvironment->osInterface->get()->setWddm(wddm);
memoryManager = std::make_unique<MockWddmMemoryManager>(wddm, *executionEnvironment);
memoryManager = std::make_unique<MockWddmMemoryManager>(*executionEnvironment);
osContext = memoryManager->createAndRegisterOsContext(nullptr, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0],
1, PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), false);
@ -90,13 +91,14 @@ class WddmMemoryManagerFixtureWithGmockWddm : public ExecutionEnvironmentFixture
void SetUp() override {
// wddm is deleted by memory manager
wddm = new NiceMock<GmockWddm>;
osInterface = std::make_unique<OSInterface>();
executionEnvironment->osInterface = std::make_unique<OSInterface>();
ASSERT_NE(nullptr, wddm);
auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]);
EXPECT_TRUE(wddm->init(preemptionMode));
osInterface->get()->setWddm(wddm);
executionEnvironment->osInterface->get()->setWddm(wddm);
osInterface = executionEnvironment->osInterface.get();
wddm->init(preemptionMode);
memoryManager = new (std::nothrow) MockWddmMemoryManager(wddm, *executionEnvironment);
memoryManager = new (std::nothrow) MockWddmMemoryManager(*executionEnvironment);
//assert we have memory manager
ASSERT_NE(nullptr, memoryManager);
osContext = memoryManager->createAndRegisterOsContext(nullptr, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], 1, preemptionMode, false);
@ -112,7 +114,7 @@ class WddmMemoryManagerFixtureWithGmockWddm : public ExecutionEnvironmentFixture
}
NiceMock<GmockWddm> *wddm = nullptr;
std::unique_ptr<OSInterface> osInterface;
OSInterface *osInterface;
OsContext *osContext;
};
@ -151,5 +153,17 @@ class WddmMemoryManagerSimpleTest : public MockWddmMemoryManagerFixture, public
}
};
using MockWddmMemoryManagerTest = ExecutionEnvironmentFixture;
class MockWddmMemoryManagerTest : public ::testing::Test {
public:
void SetUp() override {
executionEnvironment = getExecutionEnvironmentImpl(hwInfo);
wddm = new WddmMock();
executionEnvironment->osInterface->get()->setWddm(wddm);
}
HardwareInfo *hwInfo;
WddmMock *wddm;
ExecutionEnvironment *executionEnvironment;
};
using OsAgnosticMemoryManagerUsingWddmTest = MockWddmMemoryManagerTest;

View File

@ -29,8 +29,9 @@ class WddmPreemptionTests : public Test<WddmFixtureWithMockGdiDll> {
void createAndInitWddm(unsigned int forceReturnPreemptionRegKeyValue) {
wddm = static_cast<WddmMock *>(Wddm::createWddm());
osInterface = std::make_unique<OSInterface>();
osInterface->get()->setWddm(wddm);
executionEnvironment->osInterface = std::make_unique<OSInterface>();
executionEnvironment->osInterface->get()->setWddm(wddm);
osInterface = executionEnvironment->osInterface.get();
auto regReader = new RegistryReaderMock();
wddm->registryReader.reset(regReader);
regReader->forceRetValue = forceReturnPreemptionRegKeyValue;

View File

@ -90,7 +90,7 @@ struct WddmResidencyControllerWithMockWddmTest : public WddmResidencyControllerT
executionEnvironment->osInterface = std::make_unique<OSInterface>();
executionEnvironment->osInterface->get()->setWddm(wddm);
memoryManager = std::make_unique<MockWddmMemoryManager>(wddm, *executionEnvironment);
memoryManager = std::make_unique<MockWddmMemoryManager>(*executionEnvironment);
osContext = memoryManager->createAndRegisterOsContext(nullptr, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], 1, preemptionMode, false);
@ -122,7 +122,7 @@ struct WddmResidencyControllerWithGdiAndMemoryManagerTest : ::testing::Test {
executionEnvironment->osInterface = std::make_unique<OSInterface>();
executionEnvironment->osInterface->get()->setWddm(wddm);
memoryManager = std::make_unique<MockWddmMemoryManager>(wddm, *executionEnvironment);
memoryManager = std::make_unique<MockWddmMemoryManager>(*executionEnvironment);
osContext = memoryManager->createAndRegisterOsContext(nullptr, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0],
1, PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), false);

View File

@ -40,7 +40,7 @@ struct EnqueueBufferWindowsTest : public HardwareParse,
executionEnvironment->commandStreamReceivers.resize(1);
executionEnvironment->commandStreamReceivers[0].push_back(std::unique_ptr<CommandStreamReceiver>(wddmCsr));
memoryManager = new MockWddmMemoryManager(executionEnvironment->osInterface->get()->getWddm(), *executionEnvironment);
memoryManager = new MockWddmMemoryManager(*executionEnvironment);
executionEnvironment->memoryManager.reset(memoryManager);
device = std::unique_ptr<MockDevice>(Device::create<MockDevice>(hwInfo, executionEnvironment, 0));