fix: stop direct submission on platform destruction

Related-To: NEO-8072

Signed-off-by: Igor Venevtsev <igor.venevtsev@intel.com>
This commit is contained in:
Igor Venevtsev 2023-06-27 15:50:33 +00:00 committed by Compute-Runtime-Automation
parent 1418300d31
commit c2c622d695
7 changed files with 87 additions and 0 deletions

View File

@ -44,6 +44,7 @@ Platform::~Platform() {
for (auto clDevice : this->clDevices) {
clDevice->getDevice().getRootDeviceEnvironmentRef().debugger.reset(nullptr);
clDevice->getDevice().stopDirectSubmission();
clDevice->decRefInternal();
}

View File

@ -89,6 +89,28 @@ TEST_F(PlatformTest, WhenGetDeviceIsCalledThenExpectedValuesAreReturned) {
EXPECT_EQ(nullptr, pPlatform->getClDevice(numDevices));
}
TEST_F(PlatformTest, WhenPlatformIsDestroyedThenDirectSubmissionIsTerminated) {
VariableBackup<decltype(DeviceFactory::createRootDeviceFunc)> createFuncBackup{&DeviceFactory::createRootDeviceFunc};
DeviceFactory::createRootDeviceFunc = [](ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) -> std::unique_ptr<Device> {
return std::unique_ptr<Device>(MockDevice::create<MockDevice>(&executionEnvironment, rootDeviceIndex));
};
pPlatform->initializeWithNewDevices();
auto clDevice = pPlatform->getClDevice(0);
EXPECT_NE(nullptr, clDevice);
auto mockDevice = static_cast<MockDevice *>(&clDevice->getDevice());
EXPECT_FALSE(mockDevice->stopDirectSubmissionCalled);
clDevice->incRefInternal();
pPlatform = nullptr;
EXPECT_TRUE(mockDevice->stopDirectSubmissionCalled);
clDevice->decRefInternal();
}
TEST_F(PlatformTest, WhenGetClDevicesIsCalledThenExpectedValuesAreReturned) {
EXPECT_EQ(nullptr, pPlatform->getClDevices());

View File

@ -865,6 +865,15 @@ const ReleaseHelper *Device::getReleaseHelper() const {
return getRootDeviceEnvironment().getReleaseHelper();
}
void Device::stopDirectSubmission() {
for (auto &engine : allEngines) {
auto csr = engine.commandStreamReceiver;
if (csr->isAnyDirectSubmissionEnabled()) {
csr->stopDirectSubmission();
}
}
}
void Device::allocateRTDispatchGlobals(uint32_t maxBvhLevels) {
UNRECOVERABLE_IF(rtDispatchGlobalsInfos.size() < maxBvhLevels + 1);
UNRECOVERABLE_IF(rtDispatchGlobalsInfos[maxBvhLevels] != nullptr);

View File

@ -165,6 +165,7 @@ class Device : public ReferenceTrackedObject<Device> {
uint32_t getNumberOfRegularContextsPerEngine() const { return numberOfRegularContextsPerEngine; }
bool isMultiRegularContextSelectionAllowed(aub_stream::EngineType engineType, EngineUsage engineUsage) const;
MOCKABLE_VIRTUAL void stopDirectSubmission();
std::atomic<uint32_t> debugExecutionCounter = 0;

View File

@ -404,6 +404,11 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw<GfxFamily>, publ
return *flushReturnValue;
}
void stopDirectSubmission() override {
stopDirectSubmissionCalled = true;
BaseClass::stopDirectSubmission();
}
std::vector<std::string> aubCommentMessages;
BatchBuffer latestFlushedBatchBuffer = {};
@ -458,6 +463,7 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw<GfxFamily>, publ
bool forceReturnGpuHang = false;
bool callBaseIsKmdWaitOnTaskCountAllowed = false;
bool isKmdWaitOnTaskCountAllowedValue = false;
bool stopDirectSubmissionCalled = false;
};
} // namespace NEO

View File

@ -162,6 +162,11 @@ class MockDevice : public RootDevice {
void setRTDispatchGlobalsForceAllocation() {
rtDispatchGlobalsForceAllocation = true;
}
void stopDirectSubmission() override {
stopDirectSubmissionCalled = true;
Device::stopDirectSubmission();
}
static ExecutionEnvironment *prepareExecutionEnvironment(const HardwareInfo *pHwInfo);
static decltype(&createCommandStream) createCommandStreamReceiverFunc;
@ -172,6 +177,7 @@ class MockDevice : public RootDevice {
bool verifyAdapterLuidReturnValue = true;
size_t maxParameterSizeFromIGC = 0u;
bool rtDispatchGlobalsForceAllocation = true;
bool stopDirectSubmissionCalled = false;
};
template <>

View File

@ -97,6 +97,48 @@ HWTEST_F(DirectSubmissionTest, givenBlitterDirectSubmissionWhenStopThenRingIsNot
csr.blitterDirectSubmission.release();
}
HWTEST_F(DirectSubmissionTest, givenDeviceStopDirectSubmissionCalledThenCsrStopDirecttSubmissionCalled) {
VariableBackup<UltHwConfig> backup(&ultHwConfig);
ultHwConfig.csrBaseCallDirectSubmissionAvailable = true;
ultHwConfig.csrBaseCallBlitterDirectSubmissionAvailable = true;
MockDirectSubmissionHw<FamilyType, RenderDispatcher<FamilyType>> directSubmission(*pDevice->getDefaultEngine().commandStreamReceiver);
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
csr.directSubmission.reset(&directSubmission);
bool ret = directSubmission.initialize(true, false);
EXPECT_TRUE(ret);
EXPECT_FALSE(csr.stopDirectSubmissionCalled);
pDevice->stopDirectSubmission();
EXPECT_TRUE(csr.stopDirectSubmissionCalled);
csr.directSubmission.release();
}
HWTEST_F(DirectSubmissionTest, givenDeviceStopDirectSubmissionCalledThenBcsStopDirecttSubmissionCalled) {
VariableBackup<UltHwConfig> backup(&ultHwConfig);
ultHwConfig.csrBaseCallDirectSubmissionAvailable = true;
ultHwConfig.csrBaseCallBlitterDirectSubmissionAvailable = true;
MockDirectSubmissionHw<FamilyType, BlitterDispatcher<FamilyType>> directSubmission(*pDevice->getDefaultEngine().commandStreamReceiver);
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
std::unique_ptr<OsContext> osContext(OsContext::create(pDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), pDevice->getRootDeviceIndex(), 0,
EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_BCS, EngineUsage::Regular},
PreemptionMode::ThreadGroup, pDevice->getDeviceBitfield())));
csr.blitterDirectSubmission.reset(&directSubmission);
csr.setupContext(*osContext);
bool ret = directSubmission.initialize(true, false);
EXPECT_TRUE(ret);
EXPECT_FALSE(csr.stopDirectSubmissionCalled);
pDevice->stopDirectSubmission();
EXPECT_TRUE(csr.stopDirectSubmissionCalled);
csr.blitterDirectSubmission.release();
}
HWTEST_F(DirectSubmissionTest, givenDirectSubmissionWhenMakingResourcesResidentThenCorrectContextIsUsed) {
auto mockMemoryOperations = std::make_unique<MockMemoryOperations>();