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

@@ -20,6 +20,7 @@ using namespace OCLRT;
class TestedMemoryManager : public OsAgnosticMemoryManager {
public:
using OsAgnosticMemoryManager::OsAgnosticMemoryManager;
GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override {
EXPECT_NE(0u, expectedSize);
if (expectedSize == size) {
@@ -47,7 +48,8 @@ class TestedMemoryManager : public OsAgnosticMemoryManager {
};
TEST(BufferTests, doPinIsSet) {
std::unique_ptr<TestedMemoryManager> mm(new TestedMemoryManager());
ExecutionEnvironment executionEnvironment;
std::unique_ptr<TestedMemoryManager> mm(new TestedMemoryManager(false, false, executionEnvironment));
{
MockContext context;
auto size = MemoryConstants::pageSize * 32;
@@ -69,7 +71,8 @@ TEST(BufferTests, doPinIsSet) {
}
}
TEST(BufferTests, doPinIsSetForHostPtr) {
std::unique_ptr<TestedMemoryManager> mm(new TestedMemoryManager());
ExecutionEnvironment executionEnvironment;
std::unique_ptr<TestedMemoryManager> mm(new TestedMemoryManager(false, false, executionEnvironment));
{
MockContext context;
auto retVal = CL_INVALID_OPERATION;

View File

@@ -94,6 +94,7 @@ INSTANTIATE_TEST_CASE_P(
class GMockMemoryManagerFailFirstAllocation : public MockMemoryManager {
public:
GMockMemoryManagerFailFirstAllocation(const ExecutionEnvironment &executionEnvironment) : MockMemoryManager(const_cast<ExecutionEnvironment &>(executionEnvironment)){};
MOCK_METHOD5(allocateGraphicsMemoryInPreferredPool, GraphicsAllocation *(AllocationFlags flags, DevicesBitfield devicesBitfield, const void *hostPtr, size_t size, GraphicsAllocation::AllocationType type));
GraphicsAllocation *baseallocateGraphicsMemoryInPreferredPool(AllocationFlags flags, DevicesBitfield devicesBitfield, const void *hostPtr, size_t size, GraphicsAllocation::AllocationType type) {
return MockMemoryManager::allocateGraphicsMemoryInPreferredPool(flags, devicesBitfield, hostPtr, size, type);
@@ -107,7 +108,7 @@ TEST(Buffer, givenReadOnlyHostPtrMemoryWhenBufferIsCreatedWithReadOnlyFlagsThenB
memset(memory, 0xAA, MemoryConstants::pageSize);
std::unique_ptr<MockDevice> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
::testing::NiceMock<GMockMemoryManagerFailFirstAllocation> *memoryManager = new ::testing::NiceMock<GMockMemoryManagerFailFirstAllocation>;
::testing::NiceMock<GMockMemoryManagerFailFirstAllocation> *memoryManager = new ::testing::NiceMock<GMockMemoryManagerFailFirstAllocation>(*device->getExecutionEnvironment());
device->injectMemoryManager(memoryManager);
MockContext ctx(device.get());
@@ -137,7 +138,7 @@ TEST(Buffer, givenReadOnlyHostPtrMemoryWhenBufferIsCreatedWithReadOnlyFlagsAndSe
memset(memory, 0xAA, MemoryConstants::pageSize);
std::unique_ptr<MockDevice> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
::testing::NiceMock<GMockMemoryManagerFailFirstAllocation> *memoryManager = new ::testing::NiceMock<GMockMemoryManagerFailFirstAllocation>;
::testing::NiceMock<GMockMemoryManagerFailFirstAllocation> *memoryManager = new ::testing::NiceMock<GMockMemoryManagerFailFirstAllocation>(*device->getExecutionEnvironment());
device->injectMemoryManager(memoryManager);
MockContext ctx(device.get());
@@ -163,7 +164,7 @@ TEST(Buffer, givenReadOnlyHostPtrMemoryWhenBufferIsCreatedWithKernelWriteFlagThe
memset(memory, 0xAA, MemoryConstants::pageSize);
std::unique_ptr<MockDevice> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
::testing::NiceMock<GMockMemoryManagerFailFirstAllocation> *memoryManager = new ::testing::NiceMock<GMockMemoryManagerFailFirstAllocation>;
::testing::NiceMock<GMockMemoryManagerFailFirstAllocation> *memoryManager = new ::testing::NiceMock<GMockMemoryManagerFailFirstAllocation>(*device->getExecutionEnvironment());
device->injectMemoryManager(memoryManager);
MockContext ctx(device.get());
@@ -183,7 +184,7 @@ TEST(Buffer, givenReadOnlyHostPtrMemoryWhenBufferIsCreatedWithKernelWriteFlagThe
TEST(Buffer, givenNullPtrWhenBufferIsCreatedWithKernelReadOnlyFlagsThenBufferAllocationFailsAndReturnsNullptr) {
std::unique_ptr<MockDevice> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
::testing::NiceMock<GMockMemoryManagerFailFirstAllocation> *memoryManager = new ::testing::NiceMock<GMockMemoryManagerFailFirstAllocation>;
::testing::NiceMock<GMockMemoryManagerFailFirstAllocation> *memoryManager = new ::testing::NiceMock<GMockMemoryManagerFailFirstAllocation>(*device->getExecutionEnvironment());
device->injectMemoryManager(memoryManager);
MockContext ctx(device.get());
@@ -202,7 +203,7 @@ TEST(Buffer, givenNullPtrWhenBufferIsCreatedWithKernelReadOnlyFlagsThenBufferAll
TEST(Buffer, givenNullptrPassedToBufferCreateWhenAllocationIsNotSystemMemoryPoolThenBufferIsNotZeroCopy) {
std::unique_ptr<MockDevice> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
::testing::NiceMock<GMockMemoryManagerFailFirstAllocation> *memoryManager = new ::testing::NiceMock<GMockMemoryManagerFailFirstAllocation>;
::testing::NiceMock<GMockMemoryManagerFailFirstAllocation> *memoryManager = new ::testing::NiceMock<GMockMemoryManagerFailFirstAllocation>(*device->getExecutionEnvironment());
device->injectMemoryManager(memoryManager);
MockContext ctx(device.get());
@@ -227,7 +228,7 @@ TEST(Buffer, givenNullptrPassedToBufferCreateWhenAllocationIsNotSystemMemoryPool
TEST(Buffer, givenNullptrPassedToBufferCreateWhenAllocationIsNotSystemMemoryPoolThenAllocationIsNotAddedToHostPtrManager) {
std::unique_ptr<MockDevice> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
::testing::NiceMock<GMockMemoryManagerFailFirstAllocation> *memoryManager = new ::testing::NiceMock<GMockMemoryManagerFailFirstAllocation>;
::testing::NiceMock<GMockMemoryManagerFailFirstAllocation> *memoryManager = new ::testing::NiceMock<GMockMemoryManagerFailFirstAllocation>(*device->getExecutionEnvironment());
device->injectMemoryManager(memoryManager);
MockContext ctx(device.get());
@@ -350,7 +351,7 @@ TEST(Buffer, givenZeroFlagsNoSharedContextAndRenderCompressedBuffersDisabledWhen
TEST(Buffer, givenClMemCopyHostPointerPassedToBufferCreateWhenAllocationIsNotInSystemMemoryPoolThenAllocationIsWrittenByEnqueueWriteBuffer) {
std::unique_ptr<MockDevice> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
::testing::NiceMock<GMockMemoryManagerFailFirstAllocation> *memoryManager = new ::testing::NiceMock<GMockMemoryManagerFailFirstAllocation>;
::testing::NiceMock<GMockMemoryManagerFailFirstAllocation> *memoryManager = new ::testing::NiceMock<GMockMemoryManagerFailFirstAllocation>(*device->getExecutionEnvironment());
device->injectMemoryManager(memoryManager);
MockContext ctx(device.get());

View File

@@ -45,7 +45,7 @@ class CreateImageTest : public DeviceFixture,
protected:
void SetUp() override {
DeviceFixture::SetUp();
memoryManager = new MockMemoryManager();
memoryManager = new MockMemoryManager(*pDevice->getExecutionEnvironment());
pDevice->injectMemoryManager(memoryManager);
@@ -892,6 +892,7 @@ class ImageCompressionTests : public ::testing::Test {
public:
class MyMemoryManager : public MockMemoryManager {
public:
using MockMemoryManager::MockMemoryManager;
GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) override {
mockMethodCalled = true;
capturedImgInfo = imgInfo;
@@ -902,8 +903,8 @@ class ImageCompressionTests : public ::testing::Test {
};
void SetUp() override {
myMemoryManager = new MyMemoryManager();
mockDevice.reset(MockDevice::createWithNewExecutionEnvironment<MockDevice>(*platformDevices));
myMemoryManager = new MyMemoryManager(*mockDevice->getExecutionEnvironment());
mockDevice->injectMemoryManager(myMemoryManager);
mockContext.reset(new MockContext(mockDevice.get()));
}
@@ -1195,8 +1196,8 @@ void MockImageHw<FamilyName>::setClearColorParams(typename FamilyName::RENDER_SU
using HwImageTest = ::testing::Test;
HWTEST_F(HwImageTest, givenImageHwWhenSettingCCSParamsThenSetClearColorParamsIsCalled) {
OsAgnosticMemoryManager memoryManager;
MockContext context;
OsAgnosticMemoryManager memoryManager(false, false, *context.getDevice(0)->getExecutionEnvironment());
context.setMemoryManager(&memoryManager);
cl_image_desc imgDesc = {};

View File

@@ -28,7 +28,7 @@ class MemObjDestructionTest : public ::testing::TestWithParam<bool> {
public:
void SetUp() override {
context.reset(new MockContext());
memoryManager = new MockMemoryManager;
memoryManager = new MockMemoryManager(*context->getDevice(0)->getExecutionEnvironment());
device = static_cast<MockDevice *>(context->getDevice(0));
device->injectMemoryManager(memoryManager);
context->setMemoryManager(memoryManager);

View File

@@ -155,15 +155,14 @@ TEST(MemObj, givenMemObjWhenReleaseAllocatedPtrIsCalledTwiceThenItDoesntCrash) {
}
TEST(MemObj, givenNotReadyGraphicsAllocationWhenMemObjDestroysAllocationAsyncThenAllocationIsAddedToMemoryManagerAllocationList) {
MockMemoryManager memoryManager;
MockContext context;
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
context.setMemoryManager(&memoryManager);
auto allocation = memoryManager.allocateGraphicsMemory(MemoryConstants::pageSize);
allocation->taskCount = 2;
memoryManager.csr = &context.getDevice(0)->getCommandStreamReceiver();
*(memoryManager.csr->getTagAddress()) = 1;
*(memoryManager.getCommandStreamReceiver(0)->getTagAddress()) = 1;
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, CL_MEM_COPY_HOST_PTR,
MemoryConstants::pageSize, nullptr, nullptr, nullptr, true, false, false);
@@ -174,11 +173,10 @@ TEST(MemObj, givenNotReadyGraphicsAllocationWhenMemObjDestroysAllocationAsyncThe
}
TEST(MemObj, givenReadyGraphicsAllocationWhenMemObjDestroysAllocationAsyncThenAllocationIsNotAddedToMemoryManagerAllocationList) {
MockMemoryManager memoryManager;
MockContext context;
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
context.setMemoryManager(&memoryManager);
memoryManager.csr = &context.getDevice(0)->getCommandStreamReceiver();
auto allocation = memoryManager.allocateGraphicsMemory(MemoryConstants::pageSize);
allocation->taskCount = 1;
@@ -193,8 +191,8 @@ TEST(MemObj, givenReadyGraphicsAllocationWhenMemObjDestroysAllocationAsyncThenAl
}
TEST(MemObj, givenNotUsedGraphicsAllocationWhenMemObjDestroysAllocationAsyncThenAllocationIsNotAddedToMemoryManagerAllocationList) {
MockMemoryManager memoryManager;
MockContext context;
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
context.setMemoryManager(&memoryManager);
@@ -210,8 +208,8 @@ TEST(MemObj, givenNotUsedGraphicsAllocationWhenMemObjDestroysAllocationAsyncThen
}
TEST(MemObj, givenMemoryManagerWithoutDeviceWhenMemObjDestroysAllocationAsyncThenAllocationIsNotAddedToMemoryManagerAllocationList) {
MockMemoryManager memoryManager;
MockContext context;
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
context.setMemoryManager(&memoryManager);
@@ -227,11 +225,10 @@ TEST(MemObj, givenMemoryManagerWithoutDeviceWhenMemObjDestroysAllocationAsyncThe
}
TEST(MemObj, givenMemObjWhenItDoesntHaveGraphicsAllocationThenWaitForCsrCompletionDoesntCrash) {
MockMemoryManager memoryManager;
MockContext context;
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
context.setMemoryManager(&memoryManager);
memoryManager.csr = &context.getDevice(0)->getCommandStreamReceiver();
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, CL_MEM_COPY_HOST_PTR,
MemoryConstants::pageSize, nullptr, nullptr, nullptr, true, false, false);