mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-08 05:56:36 +08:00
Evict unused allocations when exec fails
Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
8a037399d1
commit
2ecab0fdc7
@@ -67,6 +67,8 @@ bool DrmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, Reside
|
||||
this->printDeviceIndex();
|
||||
DrmAllocation *alloc = static_cast<DrmAllocation *>(batchBuffer.commandBufferAllocation);
|
||||
DEBUG_BREAK_IF(!alloc);
|
||||
alloc->updateTaskCount(this->taskCount + 1, this->osContext->getContextId());
|
||||
alloc->updateResidencyTaskCount(this->taskCount + 1, this->osContext->getContextId());
|
||||
|
||||
BufferObject *bb = alloc->getBO();
|
||||
if (bb == nullptr) {
|
||||
|
||||
@@ -77,10 +77,10 @@ class DrmMockCustom : public Drm {
|
||||
using Drm::memoryInfo;
|
||||
|
||||
struct IoctlResExt {
|
||||
int32_t no;
|
||||
std::vector<int32_t> no;
|
||||
int32_t res;
|
||||
|
||||
IoctlResExt(int32_t no, int32_t res) : no(no), res(res) {}
|
||||
IoctlResExt(int32_t no, int32_t res) : no(1u, no), res(res) {}
|
||||
};
|
||||
|
||||
class Ioctls {
|
||||
@@ -319,7 +319,7 @@ class DrmMockCustom : public Drm {
|
||||
}
|
||||
}
|
||||
|
||||
if (ext->no != -1 && ext->no == ioctl_cnt.total.load()) {
|
||||
if (!ext->no.empty() && std::find(ext->no.begin(), ext->no.end(), ioctl_cnt.total.load()) != ext->no.end()) {
|
||||
ioctl_cnt.total.fetch_add(1);
|
||||
return ext->res;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ class DrmBufferObjectFixture {
|
||||
void SetUp() {
|
||||
this->mock = std::make_unique<DrmMockCustom>();
|
||||
ASSERT_NE(nullptr, this->mock);
|
||||
constructPlatform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock.get(), 0u);
|
||||
osContext.reset(new OsContextLinux(*this->mock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false));
|
||||
this->mock->reset();
|
||||
bo = new TestedBufferObject(this->mock.get());
|
||||
@@ -84,7 +85,7 @@ TEST_F(DrmBufferObjectTest, WhenCallingExecThenReturnIsCorrect) {
|
||||
}
|
||||
|
||||
TEST_F(DrmBufferObjectTest, GivenInvalidParamsWhenCallingExecThenEfaultIsReturned) {
|
||||
mock->ioctl_expected.total = 1;
|
||||
mock->ioctl_expected.total = 2;
|
||||
mock->ioctl_res = -1;
|
||||
mock->errnoValue = EFAULT;
|
||||
drm_i915_gem_exec_object2 execObjectsStorage = {};
|
||||
@@ -143,7 +144,7 @@ TEST_F(DrmBufferObjectTest, givenAddressThatWhenSizeIsAddedWithin32BitBoundaryWh
|
||||
TEST_F(DrmBufferObjectTest, whenExecFailsThenPinFails) {
|
||||
std::unique_ptr<uint32_t[]> buff(new uint32_t[1024]);
|
||||
|
||||
mock->ioctl_expected.total = 1;
|
||||
mock->ioctl_expected.total = 2;
|
||||
mock->ioctl_res = -1;
|
||||
this->mock->errnoValue = EINVAL;
|
||||
|
||||
@@ -159,7 +160,7 @@ TEST_F(DrmBufferObjectTest, whenExecFailsThenPinFails) {
|
||||
TEST_F(DrmBufferObjectTest, whenExecFailsThenValidateHostPtrFails) {
|
||||
std::unique_ptr<uint32_t[]> buff(new uint32_t[1024]);
|
||||
|
||||
mock->ioctl_expected.total = 1;
|
||||
mock->ioctl_expected.total = 2;
|
||||
mock->ioctl_res = -1;
|
||||
this->mock->errnoValue = EINVAL;
|
||||
|
||||
@@ -233,6 +234,7 @@ TEST_F(DrmBufferObjectTest, whenPrintExecutionBufferIsSetToTrueThenMessageFoundI
|
||||
TEST(DrmBufferObjectSimpleTest, givenInvalidBoWhenValidateHostptrIsCalledThenErrorIsReturned) {
|
||||
std::unique_ptr<uint32_t[]> buff(new uint32_t[256]);
|
||||
std::unique_ptr<DrmMockCustom> mock(new DrmMockCustom);
|
||||
constructPlatform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock.get(), 0u);
|
||||
OsContextLinux osContext(*mock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
|
||||
ASSERT_NE(nullptr, mock.get());
|
||||
std::unique_ptr<TestedBufferObject> bo(new TestedBufferObject(mock.get()));
|
||||
@@ -256,6 +258,7 @@ TEST(DrmBufferObjectSimpleTest, givenInvalidBoWhenValidateHostptrIsCalledThenErr
|
||||
TEST(DrmBufferObjectSimpleTest, givenInvalidBoWhenPinIsCalledThenErrorIsReturned) {
|
||||
std::unique_ptr<uint32_t[]> buff(new uint32_t[256]);
|
||||
std::unique_ptr<DrmMockCustom> mock(new DrmMockCustom);
|
||||
constructPlatform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock.get(), 0u);
|
||||
OsContextLinux osContext(*mock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
|
||||
ASSERT_NE(nullptr, mock.get());
|
||||
std::unique_ptr<TestedBufferObject> bo(new TestedBufferObject(mock.get()));
|
||||
|
||||
@@ -807,7 +807,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamBatchingTests, givenRecordedCommandBufferWhen
|
||||
EXPECT_TRUE(cmdBuffers.peekIsEmpty());
|
||||
|
||||
auto commandBufferGraphicsAllocation = submittedCommandBuffer.getGraphicsAllocation();
|
||||
EXPECT_FALSE(commandBufferGraphicsAllocation->isResident(csr->getOsContext().getContextId()));
|
||||
EXPECT_TRUE(commandBufferGraphicsAllocation->isResident(csr->getOsContext().getContextId()));
|
||||
|
||||
//preemption allocation
|
||||
size_t csrSurfaceCount = (device->getPreemptionMode() == PreemptionMode::MidThread) ? 2 : 0;
|
||||
|
||||
@@ -119,6 +119,10 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenNoAllocsInMemoryOperationH
|
||||
}
|
||||
};
|
||||
|
||||
auto osContext = std::make_unique<OsContextLinux>(*mock, 0u, 1, HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*defaultHwInfo)[0],
|
||||
PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo),
|
||||
false);
|
||||
|
||||
auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
|
||||
LinearStream cs(commandBuffer);
|
||||
CommandStreamReceiverHw<FamilyType>::addBatchBufferEnd(cs, nullptr);
|
||||
@@ -126,6 +130,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenNoAllocsInMemoryOperationH
|
||||
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr, false};
|
||||
|
||||
MockDrmCsr mockCsr(*executionEnvironment, rootDeviceIndex, 1, gemCloseWorkerMode::gemCloseWorkerInactive);
|
||||
mockCsr.setupContext(*osContext.get());
|
||||
mockCsr.flush(batchBuffer, mockCsr.getResidencyAllocations());
|
||||
|
||||
mm->freeGraphicsMemory(commandBuffer);
|
||||
@@ -144,6 +149,10 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenAllocsInMemoryOperationHan
|
||||
}
|
||||
};
|
||||
|
||||
auto osContext = std::make_unique<OsContextLinux>(*mock, 0u, 1, HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*defaultHwInfo)[0],
|
||||
PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo),
|
||||
false);
|
||||
|
||||
auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
|
||||
executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(device.get(), ArrayRef<GraphicsAllocation *>(&allocation, 1));
|
||||
|
||||
@@ -154,6 +163,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenAllocsInMemoryOperationHan
|
||||
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr, false};
|
||||
|
||||
MockDrmCsr mockCsr(*executionEnvironment, rootDeviceIndex, 1, gemCloseWorkerMode::gemCloseWorkerInactive);
|
||||
mockCsr.setupContext(*osContext.get());
|
||||
mockCsr.flush(batchBuffer, mockCsr.getResidencyAllocations());
|
||||
|
||||
mm->freeGraphicsMemory(commandBuffer);
|
||||
|
||||
@@ -888,10 +888,11 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValid
|
||||
mock->reset();
|
||||
|
||||
DrmMockCustom::IoctlResExt ioctlResExt = {1, -1};
|
||||
ioctlResExt.no.push_back(2);
|
||||
mock->ioctl_res_ext = &ioctlResExt;
|
||||
mock->errnoValue = EFAULT;
|
||||
mock->ioctl_expected.gemUserptr = 1;
|
||||
mock->ioctl_expected.execbuffer2 = 1;
|
||||
mock->ioctl_expected.execbuffer2 = 2;
|
||||
|
||||
MemoryManager::AllocationStatus result = memoryManager->populateOsHandles(storage, rootDeviceIndex);
|
||||
|
||||
@@ -922,10 +923,11 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValid
|
||||
size_t dummySize = 13u;
|
||||
|
||||
DrmMockCustom::IoctlResExt ioctlResExt = {1, -1};
|
||||
ioctlResExt.no.push_back(2);
|
||||
mock->ioctl_res_ext = &ioctlResExt;
|
||||
mock->errnoValue = EFAULT;
|
||||
mock->ioctl_expected.gemUserptr = 1;
|
||||
mock->ioctl_expected.execbuffer2 = 1;
|
||||
mock->ioctl_expected.execbuffer2 = 2;
|
||||
mock->ioctl_expected.gemClose = 1;
|
||||
|
||||
AllocationData allocationData;
|
||||
@@ -965,10 +967,11 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValid
|
||||
mock->reset();
|
||||
|
||||
DrmMockCustom::IoctlResExt ioctlResExt = {1, -1};
|
||||
ioctlResExt.no.push_back(2);
|
||||
mock->ioctl_res_ext = &ioctlResExt;
|
||||
mock->errnoValue = 0;
|
||||
mock->ioctl_expected.gemUserptr = 1;
|
||||
mock->ioctl_expected.execbuffer2 = 1;
|
||||
mock->ioctl_expected.execbuffer2 = 2;
|
||||
|
||||
AllocationData allocationData;
|
||||
allocationData.size = 13u;
|
||||
@@ -999,10 +1002,11 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValid
|
||||
mock->reset();
|
||||
|
||||
DrmMockCustom::IoctlResExt ioctlResExt = {1, -1};
|
||||
ioctlResExt.no.push_back(2);
|
||||
mock->ioctl_res_ext = &ioctlResExt;
|
||||
mock->errnoValue = 0;
|
||||
mock->ioctl_expected.gemUserptr = 1;
|
||||
mock->ioctl_expected.execbuffer2 = 1;
|
||||
mock->ioctl_expected.execbuffer2 = 2;
|
||||
|
||||
AllocationData allocationData;
|
||||
allocationData.size = 13u;
|
||||
@@ -1036,10 +1040,11 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValid
|
||||
mock->reset();
|
||||
|
||||
DrmMockCustom::IoctlResExt ioctlResExt = {1, -1};
|
||||
ioctlResExt.no.push_back(2);
|
||||
mock->ioctl_res_ext = &ioctlResExt;
|
||||
mock->errnoValue = ENOMEM;
|
||||
mock->ioctl_expected.gemUserptr = 1;
|
||||
mock->ioctl_expected.execbuffer2 = 1;
|
||||
mock->ioctl_expected.execbuffer2 = 2;
|
||||
|
||||
MemoryManager::AllocationStatus result = memoryManager->populateOsHandles(storage, rootDeviceIndex);
|
||||
|
||||
@@ -3549,10 +3554,11 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem
|
||||
mock->reset();
|
||||
|
||||
DrmMockCustom::IoctlResExt ioctlResExt = {2, -1};
|
||||
ioctlResExt.no.push_back(3);
|
||||
mock->ioctl_res_ext = &ioctlResExt;
|
||||
mock->errnoValue = EFAULT;
|
||||
mock->ioctl_expected.gemUserptr = 2;
|
||||
mock->ioctl_expected.execbuffer2 = 1;
|
||||
mock->ioctl_expected.execbuffer2 = 2;
|
||||
|
||||
OsHandleStorage handleStorage;
|
||||
OsHandleLinux handle1;
|
||||
@@ -3599,10 +3605,11 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem
|
||||
mock->reset();
|
||||
|
||||
DrmMockCustom::IoctlResExt ioctlResExt = {2, -1};
|
||||
ioctlResExt.no.push_back(3);
|
||||
mock->ioctl_res_ext = &ioctlResExt;
|
||||
mock->errnoValue = EFAULT;
|
||||
mock->ioctl_expected.gemUserptr = 2;
|
||||
mock->ioctl_expected.execbuffer2 = 1;
|
||||
mock->ioctl_expected.execbuffer2 = 2;
|
||||
|
||||
OsHandleStorage handleStorage;
|
||||
OsHandleLinux handle1;
|
||||
|
||||
@@ -159,6 +159,7 @@ class DrmMemoryManagerFixtureWithoutQuietIoctlExpectation {
|
||||
i++;
|
||||
}
|
||||
mock = static_cast<DrmMockCustom *>(executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->getDriverModel()->as<Drm>());
|
||||
constructPlatform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);
|
||||
memoryManager.reset(new TestedDrmMemoryManager(*executionEnvironment));
|
||||
|
||||
ASSERT_NE(nullptr, memoryManager);
|
||||
|
||||
Reference in New Issue
Block a user