Pass execution environment to memory manager

Change-Id: If43cf9d1353b4cbc02ea269fb9105c01cc4e0876
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2018-10-01 16:10:54 +02:00
committed by sys_ocldev
parent 84865512cd
commit b602cd2bb8
59 changed files with 479 additions and 399 deletions

View File

@@ -55,12 +55,13 @@ class DrmCommandStreamFixture {
csr = new DrmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(*platformDevices[0], executionEnvironment,
gemCloseWorkerMode::gemCloseWorkerActive);
ASSERT_NE(nullptr, csr);
executionEnvironment.commandStreamReceivers.resize(1);
executionEnvironment.commandStreamReceivers[0].reset(csr);
// Memory manager creates pinBB with ioctl, expect one call
EXPECT_CALL(*mock, ioctl(::testing::_, ::testing::_))
.Times(1);
mm = static_cast<DrmMemoryManager *>(csr->createMemoryManager(false, false));
mm->csr = csr;
::testing::Mock::VerifyAndClearExpectations(mock);
//assert we have memory manager
@@ -70,7 +71,7 @@ class DrmCommandStreamFixture {
void TearDown() {
mm->waitForDeletions();
mm->peekGemCloseWorker()->close(true);
delete csr;
executionEnvironment.commandStreamReceivers.clear();
::testing::Mock::VerifyAndClearExpectations(mock);
// Memory manager closes pinBB with ioctl, expect one call
EXPECT_CALL(*mock, ioctl(::testing::_, ::testing::_))

View File

@@ -13,6 +13,7 @@
#include <thread>
#include "runtime/command_stream/device_command_stream.h"
#include "runtime/execution_environment/execution_environment.h"
#include "hw_cmds.h"
#include "runtime/helpers/aligned_memory.h"
#include "runtime/mem_obj/buffer.h"
@@ -64,7 +65,7 @@ class DrmGemCloseWorkerFixture {
this->drmMock->gem_close_cnt = 0;
this->drmMock->gem_close_expected = 0;
this->mm = new DrmMemoryManager(this->drmMock, gemCloseWorkerMode::gemCloseWorkerInactive, false, false);
this->mm = new DrmMemoryManager(this->drmMock, gemCloseWorkerMode::gemCloseWorkerInactive, false, false, executionEnvironment);
}
void TearDown() {
@@ -88,6 +89,7 @@ class DrmGemCloseWorkerFixture {
DrmAllocationWrapper(BufferObject *bo) : DrmAllocation(bo, nullptr, 0, MemoryPool::MemoryNull) {
}
};
ExecutionEnvironment executionEnvironment;
};
typedef Test<DrmGemCloseWorkerFixture> DrmGemCloseWorkerTests;

View File

@@ -49,8 +49,9 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture {
void SetUp() override {
MemoryManagementFixture::SetUp();
this->mock = new DrmMockCustom;
memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock);
executionEnvironment = new ExecutionEnvironment;
executionEnvironment->incRefInternal();
memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, *executionEnvironment);
//assert we have memory manager
ASSERT_NE(nullptr, memoryManager);
if (memoryManager->getgemCloseWorker()) {
@@ -60,6 +61,7 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture {
void TearDown() override {
delete memoryManager;
executionEnvironment->decRefInternal();
this->mock->testIoctls();
@@ -69,6 +71,7 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture {
}
protected:
ExecutionEnvironment *executionEnvironment;
DrmMockCustom::IoctlResExt ioctlResExt = {0, 0};
};
@@ -80,7 +83,7 @@ class DrmMemoryManagerFixtureWithoutQuietIoctlExpectation : public MemoryManagem
void SetUp() override {
MemoryManagementFixture::SetUp();
this->mock = new DrmMockCustom;
memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock);
memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, executionEnvironment);
ASSERT_NE(nullptr, memoryManager);
if (memoryManager->getgemCloseWorker()) {
memoryManager->getgemCloseWorker()->close(true);
@@ -95,6 +98,7 @@ class DrmMemoryManagerFixtureWithoutQuietIoctlExpectation : public MemoryManagem
}
protected:
ExecutionEnvironment executionEnvironment;
DrmMockCustom::IoctlResExt ioctlResExt = {0, 0};
};
@@ -144,29 +148,27 @@ TEST_F(DrmMemoryManagerTest, GivenGraphicsAllocationWhenAddAndRemoveAllocationTo
}
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenforcePinAllowedWhenMemoryManagerIsCreatedThenPinBbIsCreated) {
auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false);
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(this->mock, true, false, executionEnvironment);
EXPECT_NE(nullptr, memoryManager->getPinBB());
delete memoryManager;
}
TEST_F(DrmMemoryManagerTest, pinBBisCreated) {
mock->ioctl_expected.gemUserptr = 1;
mock->ioctl_expected.gemClose = 1;
auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false);
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(this->mock, true, false, *executionEnvironment);
EXPECT_NE(nullptr, memoryManager->getPinBB());
delete memoryManager;
}
TEST_F(DrmMemoryManagerTest, givenNotAllowedForcePinWhenMemoryManagerIsCreatedThenPinBBIsNotCreated) {
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, false, false));
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, false, false, *executionEnvironment));
EXPECT_EQ(nullptr, memoryManager->getPinBB());
}
TEST_F(DrmMemoryManagerTest, pinBBnotCreatedWhenIoctlFailed) {
mock->ioctl_expected.gemUserptr = 1;
mock->ioctl_res = -1;
auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false);
auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false, *executionEnvironment);
EXPECT_EQ(nullptr, memoryManager->getPinBB());
delete memoryManager;
}
@@ -177,7 +179,7 @@ TEST_F(DrmMemoryManagerTest, pinAfterAllocateWhenAskedAndAllowedAndBigAllocation
mock->ioctl_expected.gemWait = 1;
mock->ioctl_expected.gemClose = 2;
auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false);
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(this->mock, true, false, *executionEnvironment);
ASSERT_NE(nullptr, memoryManager->getPinBB());
auto alloc = memoryManager->allocateGraphicsMemory(10 * 1014 * 1024, 1024, true, false);
@@ -185,8 +187,6 @@ TEST_F(DrmMemoryManagerTest, pinAfterAllocateWhenAskedAndAllowedAndBigAllocation
EXPECT_NE(nullptr, alloc->getBO());
memoryManager->freeGraphicsMemory(alloc);
delete memoryManager;
}
TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedAndAllowedButSmallAllocation) {
@@ -194,7 +194,7 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedAndAllowedButSmallAll
mock->ioctl_expected.gemWait = 1;
mock->ioctl_expected.gemClose = 2;
auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false);
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(this->mock, true, false, *executionEnvironment);
ASSERT_NE(nullptr, memoryManager->getPinBB());
// one page is too small for early pinning
@@ -203,8 +203,6 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedAndAllowedButSmallAll
EXPECT_NE(nullptr, alloc->getBO());
memoryManager->freeGraphicsMemory(alloc);
delete memoryManager;
}
TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenNotAskedButAllowed) {
@@ -212,7 +210,7 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenNotAskedButAllowed) {
mock->ioctl_expected.gemClose = 2;
mock->ioctl_expected.gemWait = 1;
auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false);
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(this->mock, true, false, *executionEnvironment);
ASSERT_NE(nullptr, memoryManager->getPinBB());
auto alloc = memoryManager->allocateGraphicsMemory(1024, 1024, false, false);
@@ -220,8 +218,6 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenNotAskedButAllowed) {
EXPECT_NE(nullptr, alloc->getBO());
memoryManager->freeGraphicsMemory(alloc);
delete memoryManager;
}
TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedButNotAllowed) {
@@ -229,15 +225,13 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedButNotAllowed) {
mock->ioctl_expected.gemWait = 1;
mock->ioctl_expected.gemClose = 1;
auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, false, false);
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(this->mock, false, false, *executionEnvironment);
auto alloc = memoryManager->allocateGraphicsMemory(1024, 1024, true, false);
ASSERT_NE(nullptr, alloc);
EXPECT_NE(nullptr, alloc->getBO());
memoryManager->freeGraphicsMemory(alloc);
delete memoryManager;
}
// ---- HostPtr
@@ -247,7 +241,7 @@ TEST_F(DrmMemoryManagerTest, pinAfterAllocateWhenAskedAndAllowedAndBigAllocation
mock->ioctl_expected.execbuffer2 = 1;
mock->ioctl_expected.gemWait = 1;
auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false);
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(this->mock, true, false, *executionEnvironment);
ASSERT_NE(nullptr, memoryManager->getPinBB());
size_t size = 10 * 1024 * 1024;
@@ -257,8 +251,6 @@ TEST_F(DrmMemoryManagerTest, pinAfterAllocateWhenAskedAndAllowedAndBigAllocation
EXPECT_NE(nullptr, alloc->getBO());
memoryManager->freeGraphicsMemory(alloc);
delete memoryManager;
::alignedFree(ptr);
}
@@ -267,7 +259,7 @@ TEST_F(DrmMemoryManagerTest, givenSmallAllocationHostPtrAllocationWhenForcePinIs
mock->ioctl_expected.gemWait = 1;
mock->ioctl_expected.gemClose = 2;
auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false);
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(this->mock, true, false, *executionEnvironment);
ASSERT_NE(nullptr, memoryManager->getPinBB());
// one page is too small for early pinning
@@ -279,7 +271,6 @@ TEST_F(DrmMemoryManagerTest, givenSmallAllocationHostPtrAllocationWhenForcePinIs
memoryManager->freeGraphicsMemory(alloc);
delete memoryManager;
::alignedFree(ptr);
}
@@ -288,7 +279,7 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenNotAskedButAllowedHostPtr)
mock->ioctl_expected.gemWait = 1;
mock->ioctl_expected.gemClose = 2;
auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false);
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(this->mock, true, false, *executionEnvironment);
ASSERT_NE(nullptr, memoryManager->getPinBB());
size_t size = 4 * 1024;
@@ -299,7 +290,6 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenNotAskedButAllowedHostPtr)
memoryManager->freeGraphicsMemory(alloc);
delete memoryManager;
::alignedFree(ptr);
}
@@ -308,7 +298,7 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedButNotAllowedHostPtr)
mock->ioctl_expected.gemWait = 1;
mock->ioctl_expected.gemClose = 1;
auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, false, false);
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(this->mock, false, false, *executionEnvironment);
size_t size = 4 * 1024;
void *ptr = ::alignedMalloc(size, 4096);
@@ -318,7 +308,6 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedButNotAllowedHostPtr)
memoryManager->freeGraphicsMemory(alloc);
delete memoryManager;
::alignedFree(ptr);
}
@@ -335,12 +324,12 @@ TEST_F(DrmMemoryManagerTest, UnreferenceNullPtr) {
}
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerCreatedWithGemCloseWorkerModeInactiveThenGemCloseWorkerIsNotCreated) {
DrmMemoryManager drmMemoryManger(this->mock, gemCloseWorkerMode::gemCloseWorkerInactive, false, false);
DrmMemoryManager drmMemoryManger(this->mock, gemCloseWorkerMode::gemCloseWorkerInactive, false, false, executionEnvironment);
EXPECT_EQ(nullptr, drmMemoryManger.peekGemCloseWorker());
}
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerCreatedWithGemCloseWorkerActiveThenGemCloseWorkerIsCreated) {
DrmMemoryManager drmMemoryManger(this->mock, gemCloseWorkerMode::gemCloseWorkerActive, false, false);
DrmMemoryManager drmMemoryManger(this->mock, gemCloseWorkerMode::gemCloseWorkerActive, false, false, executionEnvironment);
EXPECT_NE(nullptr, drmMemoryManger.peekGemCloseWorker());
}
@@ -557,7 +546,7 @@ TEST_F(DrmMemoryManagerTest, NullOsHandleStorageAskedForPopulationReturnsFilledP
}
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValidationWhenReadOnlyPointerCausesPinningFailWithEfaultThenPopulateOsHandlesReturnsInvalidHostPointerError) {
std::unique_ptr<TestedDrmMemoryManager> testedMemoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, false, true));
std::unique_ptr<TestedDrmMemoryManager> testedMemoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, false, true, executionEnvironment));
OsHandleStorage storage;
storage.fragmentStorageData[0].cpuPtr = reinterpret_cast<void *>(0x1000);
@@ -586,7 +575,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValid
}
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValidationWhenPinningFailWithErrorDifferentThanEfaultThenPopulateOsHandlesReturnsError) {
std::unique_ptr<TestedDrmMemoryManager> testedMemoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, false, true));
std::unique_ptr<TestedDrmMemoryManager> testedMemoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, false, true, executionEnvironment));
OsHandleStorage storage;
storage.fragmentStorageData[0].cpuPtr = reinterpret_cast<void *>(0x1000);
@@ -1227,9 +1216,9 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedFr
mock->ioctl_expected.gemWait = 1;
mock->ioctl_expected.gemClose = 1;
MockContext context;
std::unique_ptr<Device> device(MockDevice::createWithExecutionEnvironment<MockDevice>(*platformDevices, executionEnvironment, 0u));
MockContext context(device.get());
context.setMemoryManager(memoryManager);
memoryManager->csr = &context.getDevice(0)->getCommandStreamReceiver();
cl_image_format imageFormat;
imageFormat.image_channel_data_type = CL_UNORM_INT8;
@@ -2235,60 +2224,69 @@ TEST(MmapFlags, givenVariousMmapParametersGetTimeDeltaForTheOperation) {
}
TEST(DrmMemoryManager, givenDefaultMemoryManagerWhenItIsCreatedThenAsyncDeleterEnabledIsTrue) {
DrmMemoryManager memoryManager(Drm::get(0), gemCloseWorkerMode::gemCloseWorkerInactive, false, true);
ExecutionEnvironment executionEnvironment;
DrmMemoryManager memoryManager(Drm::get(0), gemCloseWorkerMode::gemCloseWorkerInactive, false, true, executionEnvironment);
EXPECT_FALSE(memoryManager.isAsyncDeleterEnabled());
EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter());
}
TEST(DrmMemoryManager, givenEnabledAsyncDeleterFlagWhenMemoryManagerIsCreatedThenAsyncDeleterEnabledIsFalseAndDeleterIsNullptr) {
ExecutionEnvironment executionEnvironment;
DebugManagerStateRestore dbgStateRestore;
DebugManager.flags.EnableDeferredDeleter.set(true);
DrmMemoryManager memoryManager(Drm::get(0), gemCloseWorkerMode::gemCloseWorkerInactive, false, true);
DrmMemoryManager memoryManager(Drm::get(0), gemCloseWorkerMode::gemCloseWorkerInactive, false, true, executionEnvironment);
EXPECT_FALSE(memoryManager.isAsyncDeleterEnabled());
EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter());
}
TEST(DrmMemoryManager, givenDisabledAsyncDeleterFlagWhenMemoryManagerIsCreatedThenAsyncDeleterEnabledIsFalseAndDeleterIsNullptr) {
ExecutionEnvironment executionEnvironment;
DebugManagerStateRestore dbgStateRestore;
DebugManager.flags.EnableDeferredDeleter.set(false);
DrmMemoryManager memoryManager(Drm::get(0), gemCloseWorkerMode::gemCloseWorkerInactive, false, true);
DrmMemoryManager memoryManager(Drm::get(0), gemCloseWorkerMode::gemCloseWorkerInactive, false, true, executionEnvironment);
EXPECT_FALSE(memoryManager.isAsyncDeleterEnabled());
EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter());
}
TEST(DrmMemoryManager, givenDefaultDrmMemoryManagerWhenItIsQueriedForInternalHeapBaseThenInternalHeapBaseIsReturned) {
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), true, true));
ExecutionEnvironment executionEnvironment;
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), true, true, executionEnvironment));
auto internalAllocator = memoryManager->getDrmInternal32BitAllocator();
auto heapBase = internalAllocator->getBase();
EXPECT_EQ(heapBase, memoryManager->getInternalHeapBaseAddress());
}
TEST(DrmMemoryManager, givenMemoryManagerWithEnabledHostMemoryValidationWhenFeatureIsQueriedThenTrueIsReturned) {
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true));
ExecutionEnvironment executionEnvironment;
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment));
ASSERT_NE(nullptr, memoryManager.get());
EXPECT_TRUE(memoryManager->isValidateHostMemoryEnabled());
}
TEST(DrmMemoryManager, givenMemoryManagerWithDisabledHostMemoryValidationWhenFeatureIsQueriedThenFalseIsReturned) {
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, false));
ExecutionEnvironment executionEnvironment;
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, false, executionEnvironment));
ASSERT_NE(nullptr, memoryManager.get());
EXPECT_FALSE(memoryManager->isValidateHostMemoryEnabled());
}
TEST(DrmMemoryManager, givenEnabledHostMemoryValidationWhenMemoryManagerIsCreatedThenPinBBIsCreated) {
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true));
ExecutionEnvironment executionEnvironment;
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment));
ASSERT_NE(nullptr, memoryManager.get());
ASSERT_NE(nullptr, memoryManager->getPinBB());
}
TEST(DrmMemoryManager, givenEnabledHostMemoryValidationAndForcePinWhenMemoryManagerIsCreatedThenPinBBIsCreated) {
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), true, true));
ExecutionEnvironment executionEnvironment;
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), true, true, executionEnvironment));
ASSERT_NE(nullptr, memoryManager.get());
ASSERT_NE(nullptr, memoryManager->getPinBB());
}
TEST(DrmMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenMemoryPoolIsSystem4KBPages) {
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true));
ExecutionEnvironment executionEnvironment;
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment));
auto size = 4096u;
auto allocation = memoryManager->allocateGraphicsMemory(size);
@@ -2303,7 +2301,8 @@ TEST(DrmMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenM
}
TEST(DrmMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPages) {
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true));
ExecutionEnvironment executionEnvironment;
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment));
void *ptr = reinterpret_cast<void *>(0x1001);
auto size = 4096u;
auto allocation = memoryManager->allocateGraphicsMemory(size, ptr, false);
@@ -2313,7 +2312,8 @@ TEST(DrmMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryWithPtrIsCall
}
TEST(DrmMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) {
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true));
ExecutionEnvironment executionEnvironment;
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment));
memoryManager->setForce32BitAllocations(true);
void *ptr = reinterpret_cast<void *>(0x1001);
@@ -2328,7 +2328,8 @@ TEST(DrmMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithPtrI
}
TEST(DrmMemoryManager, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMIsCalledThen4KBGraphicsAllocationIsReturned) {
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true));
ExecutionEnvironment executionEnvironment;
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment));
auto size = MemoryConstants::pageSize;
auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false);
@@ -2338,7 +2339,8 @@ TEST(DrmMemoryManager, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphi
}
TEST(DrmMemoryManager, givenMemoryManagerWhenCreateAllocationFromHandleIsCalledThenMemoryPoolIsSystemCpuInaccessible) {
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true));
ExecutionEnvironment executionEnvironment;
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment));
auto osHandle = 1u;
auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false);
EXPECT_NE(nullptr, allocation);
@@ -2347,7 +2349,8 @@ TEST(DrmMemoryManager, givenMemoryManagerWhenCreateAllocationFromHandleIsCalledT
}
TEST(DrmMemoryManager, DISABLED_givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemory64kbIsCalledThenMemoryPoolIsSystem64KBPages) {
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true));
ExecutionEnvironment executionEnvironment;
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment));
auto size = 4096u;
auto allocation = memoryManager->allocateGraphicsMemory64kb(size, MemoryConstants::preferredAlignment, false, false);
ASSERT_NE(nullptr, allocation);
@@ -2356,7 +2359,8 @@ TEST(DrmMemoryManager, DISABLED_givenMemoryManagerWith64KBPagesEnabledWhenAlloca
}
TEST(DrmMemoryManager, DISABLED_givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMIsCalledThenMemoryPoolIsSystem64KBPages) {
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true));
ExecutionEnvironment executionEnvironment;
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment));
auto size = MemoryConstants::pageSize;
auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false);
@@ -2370,7 +2374,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEna
this->mock->ioctl_expected.gemUserptr = 1;
EXPECT_THROW(
{
std::unique_ptr<TestedDrmMemoryManager> testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true));
std::unique_ptr<TestedDrmMemoryManager> testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true, executionEnvironment));
EXPECT_NE(nullptr, testedMemoryManager.get());
},
std::exception);
@@ -2380,7 +2384,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEna
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEnabledValidateHostMemoryWhenPopulateOsHandlesIsCalledThenHostMemoryIsValidated) {
std::unique_ptr<DrmMemoryManager> testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true));
std::unique_ptr<DrmMemoryManager> testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true, executionEnvironment));
ASSERT_NE(nullptr, testedMemoryManager.get());
ASSERT_NE(nullptr, testedMemoryManager->getPinBB());
@@ -2420,7 +2424,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEna
size_t numberOfBosPinned;
};
std::unique_ptr<TestedDrmMemoryManager> testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true));
std::unique_ptr<TestedDrmMemoryManager> testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true, executionEnvironment));
ASSERT_NE(nullptr, testedMemoryManager.get());
ASSERT_NE(nullptr, testedMemoryManager->getPinBB());
@@ -2469,7 +2473,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenValidateHostPtrMemoryE
mock->ioctl_expected.gemWait = 1;
mock->ioctl_expected.gemClose = 2;
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, true, true));
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, true, true, executionEnvironment));
ASSERT_NE(nullptr, memoryManager->getPinBB());
size_t size = 10 * 1024 * 1024;
@@ -2483,7 +2487,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenValidateHostPtrMemoryE
}
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValidationWhenValidHostPointerIsPassedToPopulateThenSuccessIsReturned) {
std::unique_ptr<TestedDrmMemoryManager> testedMemoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, false, true));
std::unique_ptr<TestedDrmMemoryManager> testedMemoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, false, true, executionEnvironment));
OsHandleStorage storage;
storage.fragmentStorageData[0].cpuPtr = reinterpret_cast<void *>(0x1000);
@@ -2502,7 +2506,7 @@ TEST_F(DrmMemoryManagerTest, givenForcePinAndHostMemoryValidationEnabledWhenSmal
mock->ioctl_expected.gemWait = 1; // in freeGraphicsAllocation
mock->ioctl_expected.gemClose = 2; // 1 pinBB, 1 small allocation
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, true, true));
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, true, true, *executionEnvironment));
ASSERT_NE(nullptr, memoryManager->getPinBB());
// one page is too small for early pinning but pinning is used for host memory validation
@@ -2521,7 +2525,7 @@ TEST_F(DrmMemoryManagerTest, givenForcePinAllowedAndNoPinBBInMemoryManagerWhenAl
mock->ioctl_expected.gemWait = 1;
mock->ioctl_expected.gemClose = 1;
mock->ioctl_res = -1;
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false));
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false, *executionEnvironment));
EXPECT_EQ(nullptr, memoryManager->getPinBB());
mock->ioctl_res = 0;
@@ -2535,7 +2539,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenAllocateGraphicsMemoryForN
}
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenForcePinNotAllowedAndHostMemoryValidationEnabledWhenAllocationIsCreatedThenBufferObjectIsPinnedOnlyOnce) {
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new TestedDrmMemoryManager(this->mock, false, true));
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new TestedDrmMemoryManager(this->mock, false, true, executionEnvironment));
mock->reset();
mock->ioctl_expected.gemUserptr = 1;
mock->ioctl_expected.execbuffer2 = 1;
@@ -2555,7 +2559,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenForcePinNotAllowedAndH
}
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenForcePinNotAllowedAndHostMemoryValidationDisabledWhenAllocationIsCreatedThenBufferObjectIsNotPinned) {
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new TestedDrmMemoryManager(this->mock, false, false));
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new TestedDrmMemoryManager(this->mock, false, false, executionEnvironment));
mock->reset();
mock->ioctl_expected.gemUserptr = 1;
mock->ioctl_expected.gemClose = 1;
@@ -2574,7 +2578,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenForcePinNotAllowedAndH
}
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMemoryWhenReadOnlyPointerCausesPinningFailWithEfaultThenPopulateOsHandlesMarksFragmentsToFree) {
std::unique_ptr<TestedDrmMemoryManager> testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true));
std::unique_ptr<TestedDrmMemoryManager> testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true, executionEnvironment));
ASSERT_NE(nullptr, testedMemoryManager.get());
ASSERT_NE(nullptr, testedMemoryManager->getPinBB());
@@ -2620,7 +2624,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem
}
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMemoryWhenReadOnlyPointerCausesPinningFailWithEfaultThenPopulateOsHandlesDoesNotStoreTheFragments) {
std::unique_ptr<TestedDrmMemoryManager> testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true));
std::unique_ptr<TestedDrmMemoryManager> testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true, executionEnvironment));
ASSERT_NE(nullptr, testedMemoryManager->getPinBB());
mock->reset();
@@ -2662,7 +2666,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem
}
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMemoryWhenPopulateOsHandlesSucceedsThenFragmentIsStoredInHostPtrManager) {
std::unique_ptr<TestedDrmMemoryManager> testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true));
std::unique_ptr<TestedDrmMemoryManager> testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true, executionEnvironment));
ASSERT_NE(nullptr, testedMemoryManager->getPinBB());
mock->reset();
@@ -2687,7 +2691,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem
}
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenCleanOsHandlesDeletesHandleDataThenOsHandleStorageAndResidencyIsSetToNullptr) {
std::unique_ptr<TestedDrmMemoryManager> testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true));
std::unique_ptr<TestedDrmMemoryManager> testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true, executionEnvironment));
ASSERT_NE(nullptr, testedMemoryManager->getPinBB());
OsHandleStorage handleStorage;

View File

@@ -65,7 +65,7 @@ class WddmCommandStreamFixture {
ASSERT_NE(nullptr, csr);
mockWddmMM = new MockWddmMemoryManager(wddm);
mockWddmMM = new MockWddmMemoryManager(wddm, *executionEnvironment);
memManager.reset(mockWddmMM);
csr->setMemoryManager(memManager.get());

View File

@@ -24,9 +24,9 @@ class MockWddmMemoryManager : public WddmMemoryManager {
using BaseClass::trimCandidatesCount;
using BaseClass::trimResidency;
using BaseClass::trimResidencyToBudget;
using BaseClass::WddmMemoryManager;
MockWddmMemoryManager(bool enable64kbPages, bool enableLocalMemory, Wddm *wddm) : WddmMemoryManager(enable64kbPages, enableLocalMemory, wddm){};
MockWddmMemoryManager(Wddm *wddm) : WddmMemoryManager(false, false, wddm){};
MockWddmMemoryManager(Wddm *wddm, ExecutionEnvironment &executionEnvironment) : WddmMemoryManager(false, false, wddm, executionEnvironment){};
void setDeferredDeleter(DeferredDeleter *deleter) {
this->deferredDeleter.reset(deleter);
}

View File

@@ -165,7 +165,7 @@ TEST_F(Wddm20Tests, whenInitializeWddmThenContextIsCreated) {
}
TEST_F(Wddm20Tests, allocation) {
OsAgnosticMemoryManager mm(false, false);
OsAgnosticMemoryManager mm(false, false, executionEnvironment);
WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull);
Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize());
@@ -313,7 +313,7 @@ TEST_F(Wddm20WithMockGdiDllTests, GivenThreeOsHandlesWhenAskedForDestroyAllocati
}
TEST_F(Wddm20Tests, mapAndFreeGpuVa) {
OsAgnosticMemoryManager mm(false, false);
OsAgnosticMemoryManager mm(false, false, executionEnvironment);
WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull);
Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize());
@@ -338,7 +338,7 @@ TEST_F(Wddm20Tests, mapAndFreeGpuVa) {
}
TEST_F(Wddm20Tests, givenNullAllocationWhenCreateThenAllocateAndMap) {
OsAgnosticMemoryManager mm(false, false);
OsAgnosticMemoryManager mm(false, false, executionEnvironment);
WddmAllocation allocation(nullptr, 100, nullptr, MemoryPool::MemoryNull);
Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize());
@@ -358,7 +358,7 @@ TEST_F(Wddm20Tests, givenNullAllocationWhenCreateThenAllocateAndMap) {
}
TEST_F(Wddm20Tests, makeResidentNonResident) {
OsAgnosticMemoryManager mm(false, false);
OsAgnosticMemoryManager mm(false, false, executionEnvironment);
WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull);
Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize());
@@ -397,7 +397,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF
auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u);
EXPECT_EQ(0u, status);
WddmMemoryManager mm(false, false, wddm);
WddmMemoryManager mm(false, false, wddm, executionEnvironment);
auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false);
auto wddmAllocation = (WddmAllocation *)graphicsAllocation;
@@ -434,7 +434,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF
auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u);
EXPECT_EQ(0u, status);
WddmMemoryManager mm(false, false, wddm);
WddmMemoryManager mm(false, false, wddm, executionEnvironment);
auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false);
auto wddmAllocation = (WddmAllocation *)graphicsAllocation;
@@ -563,7 +563,7 @@ TEST(DebugFlagTest, givenDebugManagerWhenGetForUseNoRingFlushesKmdModeIsCalledTh
}
TEST_F(Wddm20Tests, makeResidentMultipleHandles) {
OsAgnosticMemoryManager mm(false, false);
OsAgnosticMemoryManager mm(false, false, executionEnvironment);
WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull);
allocation.handle = ALLOCATION_HANDLE;
@@ -585,7 +585,7 @@ TEST_F(Wddm20Tests, makeResidentMultipleHandles) {
}
TEST_F(Wddm20Tests, makeResidentMultipleHandlesWithReturnBytesToTrim) {
OsAgnosticMemoryManager mm(false, false);
OsAgnosticMemoryManager mm(false, false, executionEnvironment);
WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull);
allocation.handle = ALLOCATION_HANDLE;

View File

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

View File

@@ -16,6 +16,7 @@
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/mocks/mock_deferred_deleter.h"
#include "unit_tests/mocks/mock_device.h"
#include "unit_tests/os_interface/windows/mock_wddm_allocation.h"
#include "unit_tests/os_interface/windows/wddm_memory_manager_tests.h"
@@ -39,7 +40,7 @@ void WddmMemoryManagerFixture::SetUp() {
osInterface = std::make_unique<OSInterface>();
osInterface->get()->setWddm(wddm);
memoryManager = std::make_unique<MockWddmMemoryManager>(wddm);
memoryManager = std::make_unique<MockWddmMemoryManager>(wddm, executionEnvironment);
}
TEST(WddmMemoryManager, NonCopyable) {
@@ -71,12 +72,13 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenRegisteringOsContextThen
}
TEST(WddmMemoryManagerAllocator32BitTest, allocator32BitIsCreatedWithCorrectBase) {
ExecutionEnvironment executionEnvironment;
std::unique_ptr<WddmMock> wddm(static_cast<WddmMock *>(Wddm::createWddm()));
uint64_t base = 0x56000;
uint64_t size = 0x9000;
wddm->setHeap32(base, size);
std::unique_ptr<WddmMemoryManager> memoryManager = std::unique_ptr<WddmMemoryManager>(new WddmMemoryManager(false, false, wddm.get()));
std::unique_ptr<WddmMemoryManager> memoryManager = std::unique_ptr<WddmMemoryManager>(new WddmMemoryManager(false, false, wddm.get(), executionEnvironment));
ASSERT_NE(nullptr, memoryManager->allocator32Bit.get());
@@ -84,10 +86,11 @@ TEST(WddmMemoryManagerAllocator32BitTest, allocator32BitIsCreatedWithCorrectBase
}
TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWMMWhenAsyncDeleterIsEnabledAndWaitForDeletionsIsCalledThenDeleterInWddmIsSetToNullptr) {
ExecutionEnvironment executionEnvironment;
auto wddm = std::make_unique<WddmMock>();
bool actualDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get();
DebugManager.flags.EnableDeferredDeleter.set(true);
MockWddmMemoryManager memoryManager(wddm.get());
MockWddmMemoryManager memoryManager(wddm.get(), executionEnvironment);
EXPECT_NE(nullptr, memoryManager.getDeferredDeleter());
memoryManager.waitForDeletions();
EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter());
@@ -95,7 +98,7 @@ TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWMMWhenAsyncDeleterIsEnabled
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenMemoryPoolIsSystem4KBPages) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm));
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment));
auto size = 4096u;
auto allocation = memoryManager->allocateGraphicsMemory(size);
@@ -112,7 +115,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemory
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemory64kbIsCalledThenMemoryPoolIsSystem64KBPages) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm));
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment));
auto size = 4096u;
auto allocation = memoryManager->allocateGraphicsMemory64kb(size, MemoryConstants::preferredAlignment, false, false);
EXPECT_NE(nullptr, allocation);
@@ -122,7 +125,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAl
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPages) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm));
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment));
void *ptr = reinterpret_cast<void *>(0x1001);
auto size = 4096u;
auto allocation = memoryManager->allocateGraphicsMemory(size, ptr, false);
@@ -135,7 +138,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemory
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm));
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment));
void *ptr = reinterpret_cast<void *>(0x1001);
auto size = MemoryConstants::pageSize;
@@ -149,7 +152,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocate32BitGraphicsM
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMIsCalledThen4KBGraphicsAllocationIsReturned) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm));
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment));
auto size = MemoryConstants::pageSize;
auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false);
@@ -160,7 +163,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesDisabledWhenA
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMIsCalledThenMemoryPoolIsSystem64KBPages) {
memoryManager.reset(new MockWddmMemoryManager(true, false, wddm));
memoryManager.reset(new MockWddmMemoryManager(true, false, wddm, executionEnvironment));
auto size = MemoryConstants::pageSize;
auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false);
@@ -170,7 +173,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAl
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenCreateAllocationFromHandleIsCalledThenMemoryPoolIsSystemCpuInaccessible) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm));
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment));
auto osHandle = 1u;
gdi->getQueryResourceInfoArgOut().NumAllocations = 1;
std::unique_ptr<Gmm> gmm(new Gmm(nullptr, 0, false));
@@ -190,7 +193,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenCreateAllocationFromHa
TEST_F(WddmMemoryManagerSimpleTest,
givenAllocateGraphicsMemoryForNonSvmHostPtrIsCalledWhenNotAlignedPtrIsPassedThenAlignedGraphicsAllocationIsCreated) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm));
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment));
void *hostPtr = reinterpret_cast<void *>(0x5001);
auto allocation = memoryManager->allocateGraphicsMemoryForNonSvmHostPtr(13, hostPtr);
@@ -482,9 +485,10 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageWithMipCountNo
}
TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreatedFromHostPtrThenallocateGraphicsMemoryForImageIsUsed) {
MockContext context;
executionEnvironment.incRefInternal(); // to prevent destrorying execution environment by destructor of device
std::unique_ptr<Device> device(MockDevice::createWithExecutionEnvironment<MockDevice>(*platformDevices, &executionEnvironment, 0u));
MockContext context(device.get());
context.setMemoryManager(memoryManager.get());
memoryManager->csr = &context.getDevice(0)->getCommandStreamReceiver();
cl_image_format imageFormat;
imageFormat.image_channel_data_type = CL_UNORM_INT8;
@@ -1850,34 +1854,34 @@ TEST_F(WddmMemoryManagerTest2, givenMemoryManagerWhenMakeResidentFailsThenMemory
EXPECT_TRUE(memoryManager->isMemoryBudgetExhausted());
}
TEST(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsEnabledThenCanDeferDeletions) {
auto wddm = std::make_unique<WddmMock>();
wddm->callBaseDestroyAllocations = false;
MockDeferredDeleter *deleter = new MockDeferredDeleter;
MockWddmMemoryManager memoryManager(wddm.get());
memoryManager.setDeferredDeleter(deleter);
struct WddmMemoryManagerWithAsyncDeleterTest : ::testing::Test {
void SetUp() {
wddm = std::make_unique<WddmMock>();
wddm->callBaseDestroyAllocations = false;
deleter = new MockDeferredDeleter;
memoryManager = std::make_unique<MockWddmMemoryManager>(wddm.get(), executionEnvironment);
memoryManager->setDeferredDeleter(deleter);
}
MockDeferredDeleter *deleter = nullptr;
std::unique_ptr<MockWddmMemoryManager> memoryManager;
ExecutionEnvironment executionEnvironment;
std::unique_ptr<WddmMock> wddm;
};
TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsEnabledThenCanDeferDeletions) {
EXPECT_EQ(0, deleter->deferDeletionCalled);
memoryManager.tryDeferDeletions(nullptr, 0, 0);
memoryManager->tryDeferDeletions(nullptr, 0, 0);
EXPECT_EQ(1, deleter->deferDeletionCalled);
EXPECT_EQ(1u, wddm.get()->destroyAllocationResult.called);
}
TEST(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsDisabledThenCannotDeferDeletions) {
auto wddm = std::make_unique<WddmMock>();
wddm->callBaseDestroyAllocations = false;
MockWddmMemoryManager memoryManager(wddm.get());
memoryManager.setDeferredDeleter(nullptr);
memoryManager.tryDeferDeletions(nullptr, 0, 0);
TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsDisabledThenCannotDeferDeletions) {
memoryManager->setDeferredDeleter(nullptr);
memoryManager->tryDeferDeletions(nullptr, 0, 0);
EXPECT_EQ(1u, wddm->destroyAllocationResult.called);
}
TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWhenCannotAllocateMemoryForTiledImageThenDrainIsCalledAndCreateAllocationIsCalledTwice) {
auto wddm = std::make_unique<WddmMock>();
wddm->callBaseDestroyAllocations = false;
MockDeferredDeleter *deleter = new MockDeferredDeleter;
MockWddmMemoryManager memoryManager(wddm.get());
memoryManager.setDeferredDeleter(deleter);
TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWhenCannotAllocateMemoryForTiledImageThenDrainIsCalledAndCreateAllocationIsCalledTwice) {
cl_image_desc imgDesc;
imgDesc.image_type = CL_MEM_OBJECT_IMAGE3D;
ImageInfo imgInfo;
@@ -1886,18 +1890,12 @@ TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWh
EXPECT_EQ(0, deleter->drainCalled);
EXPECT_EQ(0u, wddm->createAllocationResult.called);
deleter->expectDrainBlockingValue(true);
memoryManager.allocateGraphicsMemoryForImage(imgInfo, nullptr);
memoryManager->allocateGraphicsMemoryForImage(imgInfo, nullptr);
EXPECT_EQ(1, deleter->drainCalled);
EXPECT_EQ(2u, wddm->createAllocationResult.called);
}
TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWhenCanAllocateMemoryForTiledImageThenDrainIsNotCalledAndCreateAllocationIsCalledOnce) {
auto wddm = std::make_unique<WddmMock>();
wddm->callBaseDestroyAllocations = false;
MockDeferredDeleter *deleter = new MockDeferredDeleter;
MockWddmMemoryManager memoryManager(wddm.get());
memoryManager.setDeferredDeleter(deleter);
TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWhenCanAllocateMemoryForTiledImageThenDrainIsNotCalledAndCreateAllocationIsCalledOnce) {
cl_image_desc imgDesc;
imgDesc.image_type = CL_MEM_OBJECT_IMAGE3D;
ImageInfo imgInfo;
@@ -1908,41 +1906,39 @@ TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWh
EXPECT_EQ(0, deleter->drainCalled);
EXPECT_EQ(0u, wddm->createAllocationResult.called);
EXPECT_EQ(0u, wddm->mapGpuVirtualAddressResult.called);
auto allocation = memoryManager.allocateGraphicsMemoryForImage(imgInfo, nullptr);
auto allocation = memoryManager->allocateGraphicsMemoryForImage(imgInfo, nullptr);
EXPECT_EQ(0, deleter->drainCalled);
EXPECT_EQ(1u, wddm->createAllocationResult.called);
EXPECT_EQ(1u, wddm->mapGpuVirtualAddressResult.called);
memoryManager.freeGraphicsMemory(allocation);
memoryManager->freeGraphicsMemory(allocation);
}
TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithoutAsyncDeleterWhenCannotAllocateMemoryForTiledImageThenCreateAllocationIsCalledOnce) {
auto wddm = std::make_unique<WddmMock>();
wddm->callBaseDestroyAllocations = false;
MockWddmMemoryManager memoryManager(wddm.get());
memoryManager.setDeferredDeleter(nullptr);
TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithoutAsyncDeleterWhenCannotAllocateMemoryForTiledImageThenCreateAllocationIsCalledOnce) {
memoryManager->setDeferredDeleter(nullptr);
cl_image_desc imgDesc;
imgDesc.image_type = CL_MEM_OBJECT_IMAGE3D;
ImageInfo imgInfo;
imgInfo.imgDesc = &imgDesc;
wddm->createAllocationStatus = STATUS_GRAPHICS_NO_VIDEO_MEMORY;
EXPECT_EQ(0u, wddm->createAllocationResult.called);
memoryManager.allocateGraphicsMemoryForImage(imgInfo, nullptr);
memoryManager->allocateGraphicsMemoryForImage(imgInfo, nullptr);
EXPECT_EQ(1u, wddm->createAllocationResult.called);
}
TEST(WddmMemoryManagerDefaults, givenDefaultWddmMemoryManagerWhenItIsQueriedForInternalHeapBaseThenHeap1BaseIsReturned) {
ExecutionEnvironment executionEnvironment;
auto wddm = std::make_unique<WddmMock>();
wddm->callBaseDestroyAllocations = false;
MockWddmMemoryManager memoryManager(wddm.get());
MockWddmMemoryManager memoryManager(wddm.get(), executionEnvironment);
auto heapBase = wddm->getGfxPartition().Heap32[1].Base;
EXPECT_EQ(heapBase, memoryManager.getInternalHeapBaseAddress());
}
TEST_F(MockWddmMemoryManagerTest, givenValidateAllocationFunctionWhenItIsCalledWithTripleAllocationThenSuccessIsReturned) {
ExecutionEnvironment executionEnvironment;
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init());
MockWddmMemoryManager memoryManager(wddm.get());
MockWddmMemoryManager memoryManager(wddm.get(), executionEnvironment);
auto wddmAlloc = (WddmAllocation *)memoryManager.allocateGraphicsMemory(4096u, reinterpret_cast<void *>(0x1000));
@@ -1956,7 +1952,7 @@ TEST_F(MockWddmMemoryManagerTest, givenEnabled64kbpagesWhenCreatingGraphicsMemor
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init());
DebugManager.flags.Enable64kbpages.set(true);
WddmMemoryManager memoryManager64k(true, false, wddm.get());
WddmMemoryManager memoryManager64k(true, false, wddm.get(), executionEnvironment);
EXPECT_EQ(0, wddm->createAllocationResult.called);
GraphicsAllocation *galloc = memoryManager64k.allocateGraphicsMemoryInPreferredPool(AllocationFlags(true), 0, nullptr, static_cast<size_t>(MemoryConstants::pageSize64k), GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
@@ -1974,7 +1970,7 @@ TEST_F(OsAgnosticMemoryManagerUsingWddmTest, givenEnabled64kbPagesWhenAllocation
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init());
DebugManager.flags.Enable64kbpages.set(true);
WddmMemoryManager memoryManager(true, false, wddm.get());
WddmMemoryManager memoryManager(true, false, wddm.get(), executionEnvironment);
auto graphicsAllocation = memoryManager.allocateGraphicsMemory64kb(1, MemoryConstants::pageSize64k, false, false);
EXPECT_NE(nullptr, graphicsAllocation);
@@ -1987,11 +1983,12 @@ TEST_F(OsAgnosticMemoryManagerUsingWddmTest, givenEnabled64kbPagesWhenAllocation
}
TEST_F(MockWddmMemoryManagerTest, givenWddmWhenallocateGraphicsMemory64kbThenLockResultAndmapGpuVirtualAddressIsCalled) {
ExecutionEnvironment executionEnvironment;
DebugManagerStateRestore dbgRestore;
DebugManager.flags.Enable64kbpages.set(true);
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init());
MockWddmMemoryManager memoryManager64k(wddm.get());
MockWddmMemoryManager memoryManager64k(wddm.get(), executionEnvironment);
uint32_t lockCount = wddm->lockResult.called;
uint32_t mapGpuVirtualAddressResult = wddm->mapGpuVirtualAddressResult.called;
GraphicsAllocation *galloc = memoryManager64k.allocateGraphicsMemory64kb(65536, 65536, true, false);
@@ -2003,14 +2000,14 @@ TEST_F(MockWddmMemoryManagerTest, givenWddmWhenallocateGraphicsMemory64kbThenLoc
TEST_F(MockWddmMemoryManagerTest, givenDefaultMemoryManagerWhenItIsCreatedThenAsyncDeleterEnabledIsTrue) {
auto wddm = std::make_unique<WddmMock>();
WddmMemoryManager memoryManager(false, false, wddm.get());
WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment);
EXPECT_TRUE(memoryManager.isAsyncDeleterEnabled());
EXPECT_NE(nullptr, memoryManager.getDeferredDeleter());
}
TEST_F(MockWddmMemoryManagerTest, givenDefaultWddmMemoryManagerWhenItIsCreatedThenMemoryBudgetIsNotExhausted) {
auto wddm = std::make_unique<WddmMock>();
WddmMemoryManager memoryManager(false, false, wddm.get());
WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment);
EXPECT_FALSE(memoryManager.isMemoryBudgetExhausted());
}
@@ -2018,7 +2015,7 @@ TEST_F(MockWddmMemoryManagerTest, givenEnabledAsyncDeleterFlagWhenMemoryManagerI
bool defaultEnableDeferredDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get();
DebugManager.flags.EnableDeferredDeleter.set(true);
auto wddm = std::make_unique<WddmMock>();
WddmMemoryManager memoryManager(false, false, wddm.get());
WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment);
EXPECT_TRUE(memoryManager.isAsyncDeleterEnabled());
EXPECT_NE(nullptr, memoryManager.getDeferredDeleter());
DebugManager.flags.EnableDeferredDeleter.set(defaultEnableDeferredDeleterFlag);
@@ -2028,7 +2025,7 @@ TEST_F(MockWddmMemoryManagerTest, givenDisabledAsyncDeleterFlagWhenMemoryManager
bool defaultEnableDeferredDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get();
DebugManager.flags.EnableDeferredDeleter.set(false);
auto wddm = std::make_unique<WddmMock>();
WddmMemoryManager memoryManager(false, false, wddm.get());
WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment);
EXPECT_FALSE(memoryManager.isAsyncDeleterEnabled());
EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter());
DebugManager.flags.EnableDeferredDeleter.set(defaultEnableDeferredDeleterFlag);
@@ -2037,7 +2034,7 @@ TEST_F(MockWddmMemoryManagerTest, givenDisabledAsyncDeleterFlagWhenMemoryManager
TEST_F(MockWddmMemoryManagerTest, givenPageTableManagerWhenMapAuxGpuVaCalledThenUseWddmToMap) {
auto myWddm = std::make_unique<WddmMock>();
EXPECT_TRUE(myWddm->init());
WddmMemoryManager memoryManager(false, false, myWddm.get());
WddmMemoryManager memoryManager(false, false, myWddm.get(), executionEnvironment);
auto mockMngr = new NiceMock<MockGmmPageTableMngr>();
myWddm->resetPageTableManager(mockMngr);
@@ -2097,7 +2094,7 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenMappedGpuVa
TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenReleaseingThenUnmapAuxVa) {
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init());
WddmMemoryManager memoryManager(false, false, wddm.get());
WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment);
D3DGPU_VIRTUAL_ADDRESS gpuVa = 123;
auto mockMngr = new NiceMock<MockGmmPageTableMngr>();
@@ -2123,7 +2120,7 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenReleaseingT
TEST_F(MockWddmMemoryManagerTest, givenNonRenderCompressedAllocationWhenReleaseingThenDontUnmapAuxVa) {
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init());
WddmMemoryManager memoryManager(false, false, wddm.get());
WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment);
auto mockMngr = new NiceMock<MockGmmPageTableMngr>();
wddm->resetPageTableManager(mockMngr);
@@ -2167,7 +2164,7 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedFlagSetWhenInternalIsUnse
D3DGPU_VIRTUAL_ADDRESS gpuVa = 0;
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init());
WddmMemoryManager memoryManager(false, false, wddm.get());
WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment);
auto mockMngr = new NiceMock<MockGmmPageTableMngr>();
wddm->resetPageTableManager(mockMngr);

View File

@@ -58,7 +58,7 @@ class MockWddmMemoryManagerFixture : public GmmEnvironmentFixture {
osContext = new OsContext(osInterface.get(), 0u);
osContext->incRefInternal();
memoryManager = std::make_unique<MockWddmMemoryManager>(wddm);
memoryManager = std::make_unique<MockWddmMemoryManager>(wddm, executionEnvironment);
memoryManager->registerOsContext(osContext);
}
@@ -120,7 +120,7 @@ class WddmMemoryManagerFixtureWithGmockWddm : public GmmEnvironmentFixture {
osContext = new OsContext(osInterface.get(), 0u);
osContext->incRefInternal();
wddm->init();
memoryManager = new (std::nothrow) MockWddmMemoryManager(wddm);
memoryManager = new (std::nothrow) MockWddmMemoryManager(wddm, executionEnvironment);
//assert we have memory manager
ASSERT_NE(nullptr, memoryManager);