Add alternative residency model on Linux

Related-To: NEO-4732

Change-Id: I79e165d2b647af200ca314e1183ecf05903de644
Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
Lukasz Jobczyk
2020-07-02 11:49:46 +02:00
parent 519e75e3d6
commit ff0add74e3
50 changed files with 521 additions and 272 deletions

View File

@ -35,7 +35,7 @@ class DrmCommandStreamTest : public ::testing::Test {
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(mock);
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique<DrmMemoryOperationsHandler>();
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create();
auto hwInfo = executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo();
mock->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(hwInfo));
@ -82,11 +82,12 @@ class DrmCommandStreamTest : public ::testing::Test {
std::unique_ptr<OsContextLinux> osContext;
};
class DrmCommandStreamEnhancedTest : public ::testing::Test {
template <typename T>
class DrmCommandStreamEnhancedTemplate : public ::testing::Test {
public:
std::unique_ptr<DebugManagerStateRestore> dbgState;
MockExecutionEnvironment *executionEnvironment;
DrmMockCustom *mock;
T *mock;
CommandStreamReceiver *csr = nullptr;
const uint32_t rootDeviceIndex = 0u;
@ -102,10 +103,10 @@ class DrmCommandStreamEnhancedTest : public ::testing::Test {
//make sure this is disabled, we don't want to test this now
DebugManager.flags.EnableForcePin.set(false);
mock = new DrmMockCustom();
mock = new T();
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface = std::make_unique<OSInterface>();
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->setDrm(mock);
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = std::make_unique<DrmMemoryOperationsHandler>();
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = DrmMemoryOperationsHandler::create();
csr = new TestedDrmCommandStreamReceiver<GfxFamily>(*executionEnvironment, rootDeviceIndex);
ASSERT_NE(nullptr, csr);
@ -127,7 +128,7 @@ class DrmCommandStreamEnhancedTest : public ::testing::Test {
template <typename GfxFamily>
void makeResidentBufferObjects(DrmAllocation *drmAllocation) {
drmAllocation->appendBOs(0u, static_cast<TestedDrmCommandStreamReceiver<GfxFamily> *>(csr)->residency);
drmAllocation->bindBOs(0u, 0u, &static_cast<TestedDrmCommandStreamReceiver<GfxFamily> *>(csr)->residency, false);
}
template <typename GfxFamily>
@ -143,7 +144,7 @@ class DrmCommandStreamEnhancedTest : public ::testing::Test {
protected:
class MockBufferObject : public BufferObject {
friend DrmCommandStreamEnhancedTest;
friend DrmCommandStreamEnhancedTemplate<T>;
protected:
MockBufferObject(Drm *drm, size_t size) : BufferObject(drm, 1, 0) {
@ -155,3 +156,5 @@ class DrmCommandStreamEnhancedTest : public ::testing::Test {
return new MockBufferObject(this->mock, size);
}
};
using DrmCommandStreamEnhancedTest = DrmCommandStreamEnhancedTemplate<DrmMockCustom>;

View File

@ -32,7 +32,7 @@ HWTEST_F(DrmCommandStreamMMTest, MMwithPinBB) {
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(drm);
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique<DrmMemoryOperationsHandler>();
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create();
DrmCommandStreamReceiver<FamilyType> csr(executionEnvironment, 0, gemCloseWorkerMode::gemCloseWorkerInactive);
@ -69,7 +69,7 @@ HWTEST_F(DrmCommandStreamMMTest, givenExecutionEnvironmentWithMoreThanOneRootDev
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->setHwInfo(defaultHwInfo.get());
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface = std::make_unique<OSInterface>();
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->setDrm(new DrmMockCustom());
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = std::make_unique<DrmMemoryOperationsHandler>();
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = DrmMemoryOperationsHandler::create();
}
auto memoryManager = new TestedDrmMemoryManager(false, true, false, executionEnvironment);

View File

@ -14,6 +14,7 @@
#include "shared/source/memory_manager/internal_allocation_storage.h"
#include "shared/source/memory_manager/residency.h"
#include "shared/source/os_interface/linux/drm_buffer_object.h"
#include "shared/source/os_interface/linux/drm_memory_operations_handler_default.h"
#include "shared/source/os_interface/linux/os_context_linux.h"
#include "shared/source/os_interface/linux/os_interface.h"
#include "shared/source/os_interface/os_context.h"
@ -592,73 +593,6 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenGemCloseWorkerInactiveMode
mm->freeGraphicsMemory(dummyAllocation);
}
HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenAllocInMemoryOperationsInterfaceWhenFlushThenAllocIsResident) {
auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
LinearStream cs(commandBuffer);
CommandStreamReceiverHw<FamilyType>::addBatchBufferEnd(cs, nullptr);
CommandStreamReceiverHw<FamilyType>::alignToCacheLine(cs);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr};
auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(ArrayRef<GraphicsAllocation *>(&allocation, 1));
csr->flush(batchBuffer, csr->getResidencyAllocations());
const auto boRequirments = [&allocation](const auto &bo) {
return (static_cast<int>(bo.handle) == static_cast<DrmAllocation *>(allocation)->getBO()->peekHandle() &&
bo.offset == static_cast<DrmAllocation *>(allocation)->getBO()->peekAddress());
};
auto &residency = static_cast<TestedDrmCommandStreamReceiver<FamilyType> *>(csr)->getExecStorage();
EXPECT_TRUE(std::find_if(residency.begin(), residency.end(), boRequirments) != residency.end());
EXPECT_EQ(residency.size(), 2u);
residency.clear();
csr->flush(batchBuffer, csr->getResidencyAllocations());
EXPECT_TRUE(std::find_if(residency.begin(), residency.end(), boRequirments) != residency.end());
EXPECT_EQ(residency.size(), 2u);
residency.clear();
csr->getResidencyAllocations().clear();
executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->evict(*allocation);
csr->flush(batchBuffer, csr->getResidencyAllocations());
EXPECT_FALSE(std::find_if(residency.begin(), residency.end(), boRequirments) != residency.end());
EXPECT_EQ(residency.size(), 1u);
mm->freeGraphicsMemory(allocation);
mm->freeGraphicsMemory(commandBuffer);
}
HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenMakeAllBuffersResidentSetWhenFlushThenDrmMemoryOperationHandlerIsLocked) {
struct MockDrmMemoryOperationsHandler : public DrmMemoryOperationsHandler {
using DrmMemoryOperationsHandler::mutex;
};
struct MockDrmCsr : public DrmCommandStreamReceiver<FamilyType> {
using DrmCommandStreamReceiver<FamilyType>::DrmCommandStreamReceiver;
void flushInternal(const BatchBuffer &batchBuffer, const ResidencyContainer &allocationsForResidency) override {
auto memoryOperationsInterface = static_cast<MockDrmMemoryOperationsHandler *>(this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface.get());
EXPECT_FALSE(memoryOperationsInterface->mutex.try_lock());
}
};
DebugManagerStateRestore restorer;
DebugManager.flags.MakeAllBuffersResident.set(true);
auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
LinearStream cs(commandBuffer);
CommandStreamReceiverHw<FamilyType>::addBatchBufferEnd(cs, nullptr);
CommandStreamReceiverHw<FamilyType>::alignToCacheLine(cs);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr};
MockDrmCsr mockCsr(*executionEnvironment, rootDeviceIndex, gemCloseWorkerMode::gemCloseWorkerInactive);
mockCsr.flush(batchBuffer, mockCsr.getResidencyAllocations());
mm->freeGraphicsMemory(commandBuffer);
}
HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, GivenTwoAllocationsWhenBackingStorageIsDifferentThenMakeResidentShouldAddTwoLocations) {
auto allocation = static_cast<DrmAllocation *>(mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}));
auto allocation2 = static_cast<DrmAllocation *>(mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}));

View File

@ -72,7 +72,7 @@ class DrmGemCloseWorkerFixture {
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(drmMock);
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique<DrmMemoryOperationsHandler>();
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create();
this->mm = new DrmMemoryManager(gemCloseWorkerMode::gemCloseWorkerInactive,
false,

View File

@ -9,9 +9,13 @@
#include "shared/source/os_interface/linux/drm_memory_manager.h"
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
#include "shared/source/os_interface/linux/os_interface.h"
#include "shared/test/unit_test/helpers/ult_hw_config.h"
#include "opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
#include "opencl/test/unit_test/mocks/mock_allocation_properties.h"
#include "opencl/test/unit_test/mocks/mock_context.h"
#include "opencl/test/unit_test/mocks/mock_execution_environment.h"
#include "opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h"
#include "opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.h"
#include "test.h"
@ -22,7 +26,7 @@ using namespace NEO;
TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenAllocateInDevicePoolIsCalledThenNullptrAndStatusRetryIsReturned) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique<DrmMemoryOperationsHandler>();
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create();
executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[0]));
TestedDrmMemoryManager memoryManager(executionEnvironment);
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;
@ -39,7 +43,7 @@ TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenAllocateInDevicePoolIs
TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenLockResourceIsCalledOnNullBufferObjectThenReturnNullPtr) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique<DrmMemoryOperationsHandler>();
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create();
TestedDrmMemoryManager memoryManager(executionEnvironment);
DrmAllocation drmAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory);
@ -52,7 +56,7 @@ TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenLockResourceIsCalledOn
TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenFreeGraphicsMemoryIsCalledOnAllocationWithNullBufferObjectThenEarlyReturn) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique<DrmMemoryOperationsHandler>();
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create();
TestedDrmMemoryManager memoryManager(executionEnvironment);
auto drmAllocation = new DrmAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory);
@ -95,3 +99,87 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationThen
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenGetLocalMemoryIsCalledThenSizeOfLocalMemoryIsReturned) {
EXPECT_EQ(0 * GB, memoryManager->getLocalMemorySize(rootDeviceIndex));
}
HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenMakeAllBuffersResidentSetWhenFlushThenDrmMemoryOperationHandlerIsLocked) {
struct MockDrmMemoryOperationsHandler : public DrmMemoryOperationsHandler {
using DrmMemoryOperationsHandler::mutex;
};
struct MockDrmCsr : public DrmCommandStreamReceiver<FamilyType> {
using DrmCommandStreamReceiver<FamilyType>::DrmCommandStreamReceiver;
void flushInternal(const BatchBuffer &batchBuffer, const ResidencyContainer &allocationsForResidency) override {
auto memoryOperationsInterface = static_cast<MockDrmMemoryOperationsHandler *>(this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface.get());
EXPECT_FALSE(memoryOperationsInterface->mutex.try_lock());
}
};
DebugManagerStateRestore restorer;
DebugManager.flags.MakeAllBuffersResident.set(true);
auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
LinearStream cs(commandBuffer);
CommandStreamReceiverHw<FamilyType>::addBatchBufferEnd(cs, nullptr);
CommandStreamReceiverHw<FamilyType>::alignToCacheLine(cs);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr};
MockDrmCsr mockCsr(*executionEnvironment, rootDeviceIndex, gemCloseWorkerMode::gemCloseWorkerInactive);
mockCsr.flush(batchBuffer, mockCsr.getResidencyAllocations());
mm->freeGraphicsMemory(commandBuffer);
}
HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenAllocInMemoryOperationsInterfaceWhenFlushThenAllocIsResident) {
auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
LinearStream cs(commandBuffer);
CommandStreamReceiverHw<FamilyType>::addBatchBufferEnd(cs, nullptr);
CommandStreamReceiverHw<FamilyType>::alignToCacheLine(cs);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr};
auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(device.get(), ArrayRef<GraphicsAllocation *>(&allocation, 1));
csr->flush(batchBuffer, csr->getResidencyAllocations());
const auto boRequirments = [&allocation](const auto &bo) {
return (static_cast<int>(bo.handle) == static_cast<DrmAllocation *>(allocation)->getBO()->peekHandle() &&
bo.offset == static_cast<DrmAllocation *>(allocation)->getBO()->peekAddress());
};
auto &residency = static_cast<TestedDrmCommandStreamReceiver<FamilyType> *>(csr)->getExecStorage();
EXPECT_TRUE(std::find_if(residency.begin(), residency.end(), boRequirments) != residency.end());
EXPECT_EQ(residency.size(), 2u);
residency.clear();
csr->flush(batchBuffer, csr->getResidencyAllocations());
EXPECT_TRUE(std::find_if(residency.begin(), residency.end(), boRequirments) != residency.end());
EXPECT_EQ(residency.size(), 2u);
residency.clear();
csr->getResidencyAllocations().clear();
executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->evict(device.get(), *allocation);
csr->flush(batchBuffer, csr->getResidencyAllocations());
EXPECT_FALSE(std::find_if(residency.begin(), residency.end(), boRequirments) != residency.end());
EXPECT_EQ(residency.size(), 1u);
mm->freeGraphicsMemory(allocation);
mm->freeGraphicsMemory(commandBuffer);
}
TEST(ResidencyTests, whenBuffersIsCreatedWithMakeResidentFlagThenItSuccessfulyCreates) {
VariableBackup<UltHwConfig> backup(&ultHwConfig);
ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false;
ultHwConfig.forceOsAgnosticMemoryManager = false;
DebugManagerStateRestore restorer;
DebugManager.flags.MakeAllBuffersResident.set(true);
initPlatform();
auto device = platform()->getClDevice(0u);
MockContext context(device, false);
auto retValue = CL_SUCCESS;
auto clBuffer = clCreateBuffer(&context, 0u, 4096u, nullptr, &retValue);
ASSERT_EQ(retValue, CL_SUCCESS);
clReleaseMemObject(clBuffer);
}

View File

@ -3671,7 +3671,7 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryCallSequenceTest, givenDrmMemoryManagerAn
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[0]));
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique<DrmMemoryOperationsHandler>();
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create();
GMockDrmMemoryManager gmockDrmMemoryManager(executionEnvironment);
AllocationProperties properties{0, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER};
@ -3691,7 +3691,7 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryCallSequenceTest, givenDrmMemoryManagerAn
TEST(DrmMemoryManagerFreeGraphicsMemoryUnreferenceTest, givenDrmMemoryManagerAndFreeGraphicsMemoryIsCalledForSharedAllocationThenUnreferenceBufferObjectIsCalledWithSynchronousDestroySetToFalse) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
const uint32_t rootDeviceIndex = 0u;
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = std::make_unique<DrmMemoryOperationsHandler>();
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = DrmMemoryOperationsHandler::create();
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface = std::make_unique<OSInterface>();
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->setDrm(Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]));
::testing::NiceMock<GMockDrmMemoryManager> gmockDrmMemoryManager(executionEnvironment);

View File

@ -28,7 +28,7 @@ class DrmMemoryManagerBasic : public ::testing::Test {
for (auto i = 0u; i < numRootDevices; i++) {
executionEnvironment.rootDeviceEnvironments[i]->osInterface = std::make_unique<OSInterface>();
executionEnvironment.rootDeviceEnvironments[i]->osInterface->get()->setDrm(Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[i]));
executionEnvironment.rootDeviceEnvironments[i]->memoryOperationsInterface = std::make_unique<DrmMemoryOperationsHandler>();
executionEnvironment.rootDeviceEnvironments[i]->memoryOperationsInterface = DrmMemoryOperationsHandler::create();
}
}
const uint32_t rootDeviceIndex = 1u;
@ -59,7 +59,7 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture {
auto rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[i].get();
rootDeviceEnvironment->osInterface = std::make_unique<OSInterface>();
rootDeviceEnvironment->osInterface->get()->setDrm(new DrmMockCustom());
rootDeviceEnvironment->memoryOperationsInterface = std::make_unique<DrmMemoryOperationsHandler>();
rootDeviceEnvironment->memoryOperationsInterface = DrmMemoryOperationsHandler::create();
}
rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[rootDeviceIndex].get();
@ -132,7 +132,7 @@ class DrmMemoryManagerFixtureWithoutQuietIoctlExpectation {
rootDeviceEnvironment->setHwInfo(defaultHwInfo.get());
rootDeviceEnvironment->osInterface = std::make_unique<OSInterface>();
rootDeviceEnvironment->osInterface->get()->setDrm(new DrmMockCustom);
rootDeviceEnvironment->memoryOperationsInterface = std::make_unique<DrmMemoryOperationsHandler>();
rootDeviceEnvironment->memoryOperationsInterface = DrmMemoryOperationsHandler::create();
}
mock = static_cast<DrmMockCustom *>(executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->getDrm());
memoryManager.reset(new TestedDrmMemoryManager(*executionEnvironment));

View File

@ -114,6 +114,11 @@ int DrmMock::ioctl(unsigned long request, void *arg) {
static_cast<drm_i915_gem_context_param *>(arg)->value = this->StoredPersistentContextsSupport;
return this->StoredRetValForPersistant;
}
if (receivedContextParamRequest.param == I915_CONTEXT_PARAM_VM) {
static_cast<drm_i915_gem_context_param *>(arg)->value = 1u;
return 0u;
}
}
if (request == DRM_IOCTL_I915_GEM_EXECBUFFER2) {

View File

@ -5,7 +5,7 @@
*
*/
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
#include "shared/source/os_interface/linux/drm_memory_operations_handler_default.h"
#include "opencl/test/unit_test/mocks/mock_graphics_allocation.h"
#include "test.h"
@ -14,45 +14,36 @@
using namespace NEO;
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
#include "opencl/test/unit_test/mocks/mock_graphics_allocation.h"
#include "test.h"
#include <memory>
using namespace NEO;
struct MockDrmMemoryOperationsHandler : public DrmMemoryOperationsHandler {
using DrmMemoryOperationsHandler::residency;
struct MockDrmMemoryOperationsHandlerDefault : public DrmMemoryOperationsHandlerDefault {
using DrmMemoryOperationsHandlerDefault::residency;
};
struct DrmMemoryOperationsHandlerTest : public ::testing::Test {
struct DrmMemoryOperationsHandlerBaseTest : public ::testing::Test {
void SetUp() override {
drmMemoryOperationsHandler = std::make_unique<MockDrmMemoryOperationsHandler>();
drmMemoryOperationsHandler = std::make_unique<MockDrmMemoryOperationsHandlerDefault>();
allocationPtr = &graphicsAllocation;
}
MockGraphicsAllocation graphicsAllocation;
GraphicsAllocation *allocationPtr;
std::unique_ptr<MockDrmMemoryOperationsHandler> drmMemoryOperationsHandler;
std::unique_ptr<MockDrmMemoryOperationsHandlerDefault> drmMemoryOperationsHandler;
};
TEST_F(DrmMemoryOperationsHandlerTest, whenMakingResidentAllocaionExpectMakeResidentFail) {
EXPECT_EQ(drmMemoryOperationsHandler->makeResident(ArrayRef<GraphicsAllocation *>(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS);
TEST_F(DrmMemoryOperationsHandlerBaseTest, whenMakingResidentAllocaionExpectMakeResidentFail) {
EXPECT_EQ(drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u);
EXPECT_TRUE(drmMemoryOperationsHandler->residency.find(allocationPtr) != drmMemoryOperationsHandler->residency.end());
EXPECT_EQ(drmMemoryOperationsHandler->isResident(graphicsAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, graphicsAllocation), MemoryOperationsStatus::SUCCESS);
}
TEST_F(DrmMemoryOperationsHandlerTest, whenEvictingResidentAllocationExpectEvictFalse) {
TEST_F(DrmMemoryOperationsHandlerBaseTest, whenEvictingResidentAllocationExpectEvictFalse) {
EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u);
EXPECT_EQ(drmMemoryOperationsHandler->makeResident(ArrayRef<GraphicsAllocation *>(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(drmMemoryOperationsHandler->isResident(graphicsAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, graphicsAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u);
EXPECT_TRUE(drmMemoryOperationsHandler->residency.find(allocationPtr) != drmMemoryOperationsHandler->residency.end());
EXPECT_EQ(drmMemoryOperationsHandler->evict(graphicsAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(drmMemoryOperationsHandler->isResident(graphicsAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND);
EXPECT_EQ(drmMemoryOperationsHandler->evict(nullptr, graphicsAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, graphicsAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND);
EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u);
}

View File

@ -26,7 +26,7 @@ struct clCreateCommandQueueWithPropertiesLinux : public UltCommandStreamReceiver
auto osInterface = new OSInterface();
osInterface->get()->setDrm(drm);
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface.reset(osInterface);
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = std::make_unique<DrmMemoryOperationsHandler>();
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = DrmMemoryOperationsHandler::create();
executionEnvironment->memoryManager.reset(new TestedDrmMemoryManager(*executionEnvironment));
mdevice = std::make_unique<MockClDevice>(MockDevice::create<MockDevice>(executionEnvironment, rootDeviceIndex));

View File

@ -10,6 +10,7 @@
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
#include "shared/test/unit_test/helpers/ult_hw_config.h"
#include "shared/test/unit_test/helpers/variable_backup.h"
#include "shared/test/unit_test/mocks/mock_device.h"
#include "opencl/source/cl_device/cl_device.h"
#include "opencl/test/unit_test/mocks/mock_allocation_properties.h"
@ -53,43 +54,43 @@ struct WddmMemoryOperationsHandlerTest : public WddmTest {
};
TEST_F(WddmMemoryOperationsHandlerTest, givenRegularAllocatioWhenMakingResidentAllocaionExpectMakeResidentCalled) {
EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(ArrayRef<GraphicsAllocation *>(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(nullptr, wddmAllocation), MemoryOperationsStatus::SUCCESS);
}
TEST_F(WddmMemoryOperationsHandlerTest, givenFragmentedAllocationWhenMakingResidentAllocaionExpectMakeResidentCalled) {
allocationPtr = &wddmFragmentedAllocation;
EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(ArrayRef<GraphicsAllocation *>(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmFragmentedAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(nullptr, wddmFragmentedAllocation), MemoryOperationsStatus::SUCCESS);
}
TEST_F(WddmMemoryOperationsHandlerTest, givenVariousAllocationsWhenMakingResidentAllocaionExpectMakeResidentCalled) {
EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(ArrayRef<GraphicsAllocation *>(allocationData)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmFragmentedAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(allocationData)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(nullptr, wddmAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(nullptr, wddmFragmentedAllocation), MemoryOperationsStatus::SUCCESS);
}
TEST_F(WddmMemoryOperationsHandlerTest, givenRegularAllocatioWhenEvictingResidentAllocationExpectEvictCalled) {
EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(ArrayRef<GraphicsAllocation *>(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->evict(wddmAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND);
EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->evict(nullptr, wddmAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(nullptr, wddmAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND);
}
TEST_F(WddmMemoryOperationsHandlerTest, givenFragmentedAllocationWhenEvictingResidentAllocationExpectEvictCalled) {
allocationPtr = &wddmFragmentedAllocation;
EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(ArrayRef<GraphicsAllocation *>(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->evict(wddmFragmentedAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmFragmentedAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND);
EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->evict(nullptr, wddmFragmentedAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(nullptr, wddmFragmentedAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND);
}
TEST_F(WddmMemoryOperationsHandlerTest, givenVariousAllocationsWhenEvictingResidentAllocationExpectEvictCalled) {
EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(ArrayRef<GraphicsAllocation *>(allocationData)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->evict(wddmAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND);
EXPECT_EQ(wddmMemoryOperationsHandler->evict(wddmFragmentedAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmFragmentedAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND);
EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(allocationData)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->evict(nullptr, wddmAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(nullptr, wddmAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND);
EXPECT_EQ(wddmMemoryOperationsHandler->evict(nullptr, wddmFragmentedAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(nullptr, wddmFragmentedAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND);
}
TEST(WddmResidentBufferTests, whenBuffersIsCreatedWithMakeResidentFlagSetThenItIsMadeResidentUponCreation) {
@ -110,7 +111,7 @@ TEST(WddmResidentBufferTests, whenBuffersIsCreatedWithMakeResidentFlagSetThenItI
auto memoryOperationsHandler = device->getRootDeviceEnvironment().memoryOperationsInterface.get();
auto neoBuffer = castToObject<MemObj>(clBuffer);
auto bufferAllocation = neoBuffer->getGraphicsAllocation(device->getRootDeviceIndex());
auto status = memoryOperationsHandler->isResident(*bufferAllocation);
auto status = memoryOperationsHandler->isResident(nullptr, *bufferAllocation);
EXPECT_EQ(status, MemoryOperationsStatus::SUCCESS);