fix: Update SIP kernel initialization logic

Initialize SIP kernel when shared device is being initialized
instead of api-specific device.

Initialize debugger when shared device is being initialized
instead of during platform or driver initialization.

Add missing makeResident calls for SIP kernel in heapless paths.

Related-To: HSD-18038645398, HSD-18038819112

Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
This commit is contained in:
Filip Hazubski
2024-06-20 11:56:15 +00:00
committed by Compute-Runtime-Automation
parent 6ded319b0f
commit 2f6eaf149a
29 changed files with 218 additions and 196 deletions

View File

@@ -1368,9 +1368,6 @@ Device *Device::create(DriverHandle *driverHandle, NEO::Device *neoDevice, bool
if (neoDevice->getDebugger() || neoDevice->getPreemptionMode() == NEO::PreemptionMode::MidThread) {
if (neoDevice->getCompilerInterface()) {
bool ret = NEO::SipKernel::initSipKernel(NEO::SipKernel::getSipKernelType(*neoDevice), *neoDevice);
UNRECOVERABLE_IF(!ret);
if (rootDeviceEnvironment.executionEnvironment.getDebuggingMode() == NEO::DebuggingMode::offline) {
if (NEO::SipKernel::getSipKernel(*neoDevice, nullptr).getCtxOffset() == 0) {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr,

View File

@@ -226,14 +226,6 @@ void DriverHandleImp::updateRootDeviceBitFields(std::unique_ptr<NEO::Device> &ne
entry->second = neoDevice->getDeviceBitfield();
}
void DriverHandleImp::enableRootDeviceDebugger(std::unique_ptr<NEO::Device> &neoDevice) {
if (enableProgramDebugging != NEO::DebuggingMode::disabled) {
const auto rootDeviceIndex = neoDevice->getRootDeviceIndex();
auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex].get();
rootDeviceEnvironment->initDebuggerL0(neoDevice.get());
}
}
ze_result_t DriverHandleImp::initialize(std::vector<std::unique_ptr<NEO::Device>> neoDevices) {
bool multiOsContextDriver = false;
for (auto &neoDevice : neoDevices) {
@@ -251,15 +243,6 @@ ze_result_t DriverHandleImp::initialize(std::vector<std::unique_ptr<NEO::Device>
const auto rootDeviceIndex = neoDevice->getRootDeviceIndex();
auto osInterface = neoDevice->getRootDeviceEnvironment().osInterface.get();
if (osInterface && !osInterface->isDebugAttachAvailable() && enableProgramDebugging != NEO::DebuggingMode::disabled) {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr,
"Debug mode is not enabled in the system.\n");
enableProgramDebugging = NEO::DebuggingMode::disabled;
}
enableRootDeviceDebugger(neoDevice);
this->rootDeviceIndices.pushUnique(rootDeviceIndex);
this->deviceBitfields.insert({rootDeviceIndex, neoDevice->getDeviceBitfield()});

View File

@@ -158,7 +158,6 @@ struct DriverHandleImp : public DriverHandle {
RootDeviceIndicesContainer rootDeviceIndices;
std::map<uint32_t, NEO::DeviceBitfield> deviceBitfields;
void updateRootDeviceBitFields(std::unique_ptr<NEO::Device> &neoDevice);
void enableRootDeviceDebugger(std::unique_ptr<NEO::Device> &neoDevice);
// Environment Variables
NEO::DebuggingMode enableProgramDebugging = NEO::DebuggingMode::disabled;

View File

@@ -415,40 +415,6 @@ HWTEST_F(L0DebuggerLinuxTest, givenDebuggingEnabledAndDebugAttachAvailableWhenIn
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
}
HWTEST_F(L0DebuggerLinuxTest, givenDebuggingEnabledAndDebugAttachNotAvailableWhenInitializingDriverThenErrorIsPrintedButNotReturned) {
DebugManagerStateRestore restorer;
NEO::debugManager.flags.PrintDebugMessages.set(1);
auto executionEnvironment = new NEO::ExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->setDebuggingMode(NEO::DebuggingMode::online);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(defaultHwInfo.get());
executionEnvironment->initializeMemoryManager();
auto osInterface = new OSInterface();
auto drmMock = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]);
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);
executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<Drm>(drmMock));
auto neoDevice = NEO::MockDevice::create<NEO::MockDevice>(executionEnvironment, 0u);
NEO::DeviceVector devices;
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
auto driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
driverHandle->enableProgramDebugging = NEO::DebuggingMode::online;
drmMock->allowDebugAttach = false;
::testing::internal::CaptureStderr();
ze_result_t result = driverHandle->initialize(std::move(devices));
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
auto output = testing::internal::GetCapturedStderr();
EXPECT_EQ(std::string("Debug mode is not enabled in the system.\n"), output);
EXPECT_EQ(NEO::DebuggingMode::disabled, driverHandle->enableProgramDebugging);
EXPECT_EQ(nullptr, neoDevice->getL0Debugger());
}
HWTEST_F(L0DebuggerLinuxTest, givenDebuggingEnabledWhenImmCommandListsCreatedAndDestroyedThenDebuggerL0IsNotified) {
auto debuggerL0Hw = static_cast<MockDebuggerL0Hw<FamilyType> *>(device->getL0Debugger());

View File

@@ -35,8 +35,8 @@ struct L0DebuggerWindowsFixture {
void setUp() {
debugManager.flags.ForcePreferredAllocationMethod.set(static_cast<int32_t>(GfxMemoryAllocationMethod::useUmdSystemPtr));
executionEnvironment = new NEO::ExecutionEnvironment;
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->setDebuggingMode(NEO::DebuggingMode::online);
executionEnvironment->prepareRootDeviceEnvironments(1);
rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get();
auto osEnvironment = new OsEnvironmentWin();
gdi = new MockGdi();
@@ -225,47 +225,5 @@ TEST_F(L0DebuggerWindowsTest, givenProgramDebuggingEnabledAndDebugAttachAvailabl
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
}
TEST_F(L0DebuggerWindowsTest, givenProgramDebuggingEnabledAndDebugAttachNotAvailableWhenInitializingDriverThenErrorIsPrintedButNotReturned) {
DebugManagerStateRestore restorer;
auto executionEnvironment = new NEO::ExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->setDebuggingMode(NEO::DebuggingMode::online);
auto hwInfo = *NEO::defaultHwInfo.get();
executionEnvironment->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(&hwInfo);
WddmEuDebugInterfaceMock *wddm = new WddmEuDebugInterfaceMock(*executionEnvironment->rootDeviceEnvironments[0]);
wddm->callBaseDestroyAllocations = false;
wddm->callBaseMapGpuVa = false;
wddm->callBaseWaitFromCpu = false;
auto osInterface = new OSInterface();
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);
executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(wddm));
wddm->init();
executionEnvironment->memoryManager.reset(new MockWddmMemoryManager(*executionEnvironment));
auto neoDevice = NEO::MockDevice::create<NEO::MockDevice>(executionEnvironment, 0u);
NEO::DeviceVector devices;
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
auto driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
driverHandle->enableProgramDebugging = NEO::DebuggingMode::online;
wddm->debugAttachAvailable = false;
::testing::internal::CaptureStderr();
NEO::debugManager.flags.PrintDebugMessages.set(1);
ze_result_t result = driverHandle->initialize(std::move(devices));
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
NEO::debugManager.flags.PrintDebugMessages.set(0);
auto output = testing::internal::GetCapturedStderr();
EXPECT_EQ(std::string("Debug mode is not enabled in the system.\n"), output);
EXPECT_EQ(NEO::DebuggingMode::disabled, driverHandle->enableProgramDebugging);
EXPECT_EQ(nullptr, neoDevice->getL0Debugger());
}
} // namespace ult
} // namespace L0

View File

@@ -226,7 +226,6 @@ HWTEST2_F(DeviceCopyEngineTests, givenRootOrSubDeviceWhenAskingForCopyOrdinalThe
TEST(L0DeviceTest, givenMidThreadPreemptionWhenCreatingDeviceThenSipKernelIsInitialized) {
ze_result_t returnValue = ZE_RESULT_SUCCESS;
VariableBackup<bool> mockSipCalled(&NEO::MockSipData::called, false);
VariableBackup<NEO::SipKernelType> mockSipCalledType(&NEO::MockSipData::calledType, NEO::SipKernelType::count);
VariableBackup<bool> backupSipInitType(&MockSipData::useMockSip, true);
@@ -237,12 +236,6 @@ TEST(L0DeviceTest, givenMidThreadPreemptionWhenCreatingDeviceThenSipKernelIsInit
auto neoDevice = std::unique_ptr<NEO::Device>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
EXPECT_EQ(NEO::SipKernelType::count, NEO::MockSipData::calledType);
EXPECT_FALSE(NEO::MockSipData::called);
auto device = std::unique_ptr<L0::Device>(Device::create(driverHandle.get(), neoDevice.release(), false, &returnValue));
ASSERT_NE(nullptr, device);
EXPECT_EQ(NEO::SipKernelType::csr, NEO::MockSipData::calledType);
EXPECT_TRUE(NEO::MockSipData::called);
}
@@ -338,15 +331,16 @@ TEST(L0DeviceTest, givenDeviceWithoutAnyCompilerLibraryThenInvalidDependencyIsNo
}
TEST(L0DeviceTest, givenDeviceWithoutIGCCompilerLibraryAndMidThreadPreemptionThenInvalidDependencyIsReturned) {
DebugManagerStateRestore restore{};
debugManager.flags.ForcePreemptionMode.set(PreemptionMode::MidThread);
ze_result_t returnValue = ZE_RESULT_SUCCESS;
std::unique_ptr<DriverHandleImp> driverHandle(new DriverHandleImp);
auto hwInfo = *NEO::defaultHwInfo;
auto neoDevice = std::unique_ptr<NEO::Device>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
auto oldIgcDllName = Os::igcDllName;
Os::igcDllName = "_invalidIGC";
auto neoDevice = std::unique_ptr<NEO::Device>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
auto mockDevice = reinterpret_cast<NEO::MockDevice *>(neoDevice.get());
mockDevice->setPreemptionMode(NEO::PreemptionMode::MidThread);
@@ -358,17 +352,18 @@ TEST(L0DeviceTest, givenDeviceWithoutIGCCompilerLibraryAndMidThreadPreemptionThe
}
TEST(L0DeviceTest, givenDeviceWithoutAnyCompilerLibraryAndMidThreadPreemptionThenInvalidDependencyIsReturned) {
DebugManagerStateRestore restore{};
debugManager.flags.ForcePreemptionMode.set(PreemptionMode::MidThread);
ze_result_t returnValue = ZE_RESULT_SUCCESS;
std::unique_ptr<DriverHandleImp> driverHandle(new DriverHandleImp);
auto hwInfo = *NEO::defaultHwInfo;
auto neoDevice = std::unique_ptr<NEO::Device>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
auto oldFclDllName = Os::frontEndDllName;
auto oldIgcDllName = Os::igcDllName;
Os::frontEndDllName = "_invalidFCL";
Os::igcDllName = "_invalidIGC";
auto neoDevice = std::unique_ptr<NEO::Device>(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
auto mockDevice = reinterpret_cast<NEO::MockDevice *>(neoDevice.get());
mockDevice->setPreemptionMode(NEO::PreemptionMode::MidThread);

View File

@@ -24,6 +24,7 @@
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/mocks/mock_io_functions.h"
#include "shared/test/common/mocks/mock_sip.h"
#include "shared/test/common/mocks/ult_device_factory.h"
#include "shared/test/common/test_macros/hw_test.h"
@@ -868,11 +869,13 @@ TEST(DriverTest, givenBuiltinsAsyncInitEnabledWhenCreatingDriverThenMakeSureBuil
}
TEST(DriverTest, givenInvalidCompilerEnvironmentThenDependencyUnavailableErrorIsReturned) {
VariableBackup<bool> backupUseMockSip{&MockSipData::useMockSip};
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
hwInfo.capabilityTable.levelZeroSupported = true;
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZET_ENABLE_PROGRAM_DEBUGGING", "1"}};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
backupUseMockSip = true;
ze_result_t result = ZE_RESULT_ERROR_UNINITIALIZED;
DriverImp driverImp;
@@ -890,11 +893,13 @@ TEST(DriverTest, givenInvalidCompilerEnvironmentThenDependencyUnavailableErrorIs
}
TEST(DriverTest, givenInvalidCompilerEnvironmentAndEnableProgramDebuggingWithValue2ThenDependencyUnavailableErrorIsReturned) {
VariableBackup<bool> backupUseMockSip{&MockSipData::useMockSip};
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
hwInfo.capabilityTable.levelZeroSupported = true;
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZET_ENABLE_PROGRAM_DEBUGGING", "2"}};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
backupUseMockSip = true;
ze_result_t result = ZE_RESULT_ERROR_UNINITIALIZED;
DriverImp driverImp;

View File

@@ -385,7 +385,6 @@ ze_result_t LinuxSysmanImp::initDevice() {
return ZE_RESULT_ERROR_DEVICE_LOST;
}
static_cast<L0::DriverHandleImp *>(device->getDriverHandle())->updateRootDeviceBitFields(neoDevice);
static_cast<L0::DriverHandleImp *>(device->getDriverHandle())->enableRootDeviceDebugger(neoDevice);
Device::deviceReinit(device->getDriverHandle(), device, neoDevice, &result);
reInitSysmanDeviceResources();

View File

@@ -1086,21 +1086,21 @@ TEST_F(SysmanGlobalOperationsIntegratedFixture, GivenProcessStartsMidResetWhenCa
}
TEST(SysmanGlobalOperationsTest, GivenValidDevicePciPathWhenPreparingDeviceEnvironmentThenPrepareDeviceEnvironmentReturnsTrue) {
auto device1 = std::unique_ptr<MockDevice>{MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get())};
MockExecutionEnvironment executionEnvironment;
std::string pciPath1 = "0000:00:02.0";
EXPECT_TRUE(DeviceFactory::prepareDeviceEnvironment(*device1->getExecutionEnvironment(), pciPath1, 0u));
EXPECT_TRUE(DeviceFactory::prepareDeviceEnvironment(executionEnvironment, pciPath1, 0u));
}
TEST(SysmanGlobalOperationsTest, GivenValidDevicePciPathWhoseFileDescriptorOpenFailedThenPrepareDeviceEnvironmentReturnsFalse) {
auto device2 = std::unique_ptr<MockDevice>{MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get())};
MockExecutionEnvironment executionEnvironment;
std::string pciPath2 = "0000:00:03.0";
EXPECT_FALSE(DeviceFactory::prepareDeviceEnvironment(*device2->getExecutionEnvironment(), pciPath2, 0u));
EXPECT_FALSE(DeviceFactory::prepareDeviceEnvironment(executionEnvironment, pciPath2, 0u));
}
TEST(SysmanGlobalOperationsTest, GivenNotExisitingPciPathWhenPrepareDeviceEnvironmentIsCalledThenFalseIsReturned) {
auto device3 = std::unique_ptr<MockDevice>{MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get())};
MockExecutionEnvironment executionEnvironment;
std::string pciPath3 = "0000:00:04.0";
EXPECT_FALSE(DeviceFactory::prepareDeviceEnvironment(*device3->getExecutionEnvironment(), pciPath3, 0u));
EXPECT_FALSE(DeviceFactory::prepareDeviceEnvironment(executionEnvironment, pciPath3, 0u));
}
TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleWhenCallingDeviceGetStateThenSuccessResultIsReturned) {