Create DebuggerL0 only when debugging is supported

Related-To: NEO-5239

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2020-11-23 14:31:20 +00:00
committed by Compute-Runtime-Automation
parent 8fdc35bb4b
commit 8aacad1854
19 changed files with 173 additions and 37 deletions

View File

@@ -81,7 +81,7 @@ class DebuggerL0 : public NEO::Debugger, NEO::NonCopyableOrMovableClass {
sba.SurfaceStateBaseAddress != 0 ||
sba.BindlessSurfaceStateBaseAddress != 0;
}
static void initDebuggingInOs(NEO::OSInterface *osInterface);
static bool initDebuggingInOs(NEO::OSInterface *osInterface);
void initialize();

View File

@@ -13,10 +13,14 @@
#include "level_zero/core/source/debugger/debugger_l0.h"
namespace L0 {
void DebuggerL0::initDebuggingInOs(NEO::OSInterface *osInterface) {
bool DebuggerL0::initDebuggingInOs(NEO::OSInterface *osInterface) {
if (osInterface != nullptr) {
auto drm = osInterface->get()->getDrm();
drm->registerResourceClasses();
if (drm->isVmBindAvailable() && drm->isPerContextVMRequired()) {
drm->registerResourceClasses();
return true;
}
}
return false;
}
} // namespace L0

View File

@@ -8,6 +8,7 @@
#include "level_zero/core/source/debugger/debugger_l0.h"
namespace L0 {
void DebuggerL0::initDebuggingInOs(NEO::OSInterface *osInterface) {
bool DebuggerL0::initDebuggingInOs(NEO::OSInterface *osInterface) {
return false;
}
} // namespace L0

View File

@@ -13,9 +13,12 @@
namespace L0 {
std::unique_ptr<NEO::Debugger> DebuggerL0::create(NEO::Device *device) {
initDebuggingInOs(device->getRootDeviceEnvironment().osInterface.get());
auto debugger = debuggerL0Factory[device->getHardwareInfo().platform.eRenderCoreFamily](device);
return std::unique_ptr<DebuggerL0>(debugger);
auto success = initDebuggingInOs(device->getRootDeviceEnvironment().osInterface.get());
if (success) {
auto debugger = debuggerL0Factory[device->getHardwareInfo().platform.eRenderCoreFamily](device);
return std::unique_ptr<DebuggerL0>(debugger);
}
return std::unique_ptr<DebuggerL0>(nullptr);
}
} // namespace L0

View File

@@ -46,7 +46,7 @@ void DriverImp::initialize(ze_result_t *result) {
UNRECOVERABLE_IF(nullptr == executionEnvironment);
if (envVariables.programDebugging) {
executionEnvironment->setPerContextMemorySpace();
executionEnvironment->setDebuggingEnabled();
}
executionEnvironment->incRefInternal();

View File

@@ -7,6 +7,7 @@
#pragma once
#include "level_zero/core/source/debugger/debugger_l0.h"
#include "level_zero/core/test/unit_tests/white_box.h"
namespace L0 {
namespace ult {
@@ -52,5 +53,11 @@ struct MockDebuggerL0HwPopulateFactory {
}
};
template <>
struct WhiteBox<::L0::DebuggerL0> : public ::L0::DebuggerL0 {
using BaseClass = ::L0::DebuggerL0;
using BaseClass::initDebuggingInOs;
};
} // namespace ult
} // namespace L0

View File

@@ -49,8 +49,7 @@ struct L0DebuggerFixture {
struct L0DebuggerHwFixture : public L0DebuggerFixture {
void SetUp() {
L0DebuggerFixture::SetUp();
debuggerHw = mockDebuggerL0HwFactory[neoDevice->getHardwareInfo().platform.eRenderCoreFamily](neoDevice);
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[neoDevice->getRootDeviceIndex()]->debugger.reset(debuggerHw);
debuggerHw = static_cast<DebuggerL0 *>(neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[neoDevice->getRootDeviceIndex()]->debugger.get());
neoDevice->setPreemptionMode(PreemptionMode::Disabled);
}

View File

@@ -23,7 +23,7 @@ struct L0DebuggerLinuxFixture {
auto executionEnvironment = new NEO::ExecutionEnvironment();
auto mockBuiltIns = new MockBuiltins();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->setDebuggingEnabled();
executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
executionEnvironment->initializeMemoryManager();
@@ -67,5 +67,68 @@ TEST_F(L0DebuggerLinuxTest, whenDebuggerIsCreatedThenItCallsDrmToRegisterResourc
EXPECT_TRUE(drmMock->registerClassesCalled);
}
TEST(L0DebuggerLinux, givenVmBindAndPerContextVmEnabledInDrmWhenInitializingDebuggingInOsThenRegisterResourceClassesIsCalled) {
auto executionEnvironment = std::make_unique<NEO::ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->setDebuggingEnabled();
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
executionEnvironment->initializeMemoryManager();
auto osInterface = new OSInterface();
auto drmMock = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]);
drmMock->bindAvailable = true;
drmMock->setPerContextVMRequired(true);
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);
executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setDrm(static_cast<Drm *>(drmMock));
auto result = WhiteBox<::L0::DebuggerL0>::initDebuggingInOs(osInterface);
EXPECT_TRUE(result);
EXPECT_TRUE(drmMock->registerClassesCalled);
}
TEST(L0DebuggerLinux, givenVmBindNotAvailableInDrmWhenInitializingDebuggingInOsThenRegisterResourceClassesIsNotCalled) {
auto executionEnvironment = std::make_unique<NEO::ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->setDebuggingEnabled();
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
executionEnvironment->initializeMemoryManager();
auto osInterface = new OSInterface();
auto drmMock = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]);
drmMock->bindAvailable = false;
drmMock->setPerContextVMRequired(true);
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);
executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setDrm(static_cast<Drm *>(drmMock));
auto result = WhiteBox<::L0::DebuggerL0>::initDebuggingInOs(osInterface);
EXPECT_FALSE(result);
EXPECT_FALSE(drmMock->registerClassesCalled);
}
TEST(L0DebuggerLinux, givenPerContextVmNotEnabledWhenInitializingDebuggingInOsThenRegisterResourceClassesIsNotCalled) {
auto executionEnvironment = std::make_unique<NEO::ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->setDebuggingEnabled();
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
executionEnvironment->initializeMemoryManager();
auto osInterface = new OSInterface();
auto drmMock = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]);
drmMock->bindAvailable = true;
drmMock->setPerContextVMRequired(false);
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);
executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setDrm(static_cast<Drm *>(drmMock));
auto result = WhiteBox<::L0::DebuggerL0>::initDebuggingInOs(osInterface);
EXPECT_FALSE(result);
EXPECT_FALSE(drmMock->registerClassesCalled);
}
} // namespace ult
} // namespace L0

View File

@@ -183,7 +183,7 @@ TEST(DriverImpTest, DISABLED_givenMissingMetricApiDependenciesWhenInitializingDr
EXPECT_EQ(nullptr, L0::GlobalDriver);
}
TEST(DriverImpTest, givenEnabledProgramDebuggingWhenCreatingExecutionEnvironmentThenPerContextMemorySpaceIsTrue) {
TEST(DriverImpTest, givenEnabledProgramDebuggingWhenCreatingExecutionEnvironmentThenDebuggingEnabledIsTrue) {
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
hwInfo.capabilityTable.levelZeroSupported = true;
@@ -197,14 +197,14 @@ TEST(DriverImpTest, givenEnabledProgramDebuggingWhenCreatingExecutionEnvironment
ASSERT_NE(nullptr, L0::GlobalDriver);
ASSERT_NE(0u, L0::GlobalDriver->numDevices);
EXPECT_TRUE(L0::GlobalDriver->devices[0]->getNEODevice()->getExecutionEnvironment()->isPerContextMemorySpaceRequired());
EXPECT_TRUE(L0::GlobalDriver->devices[0]->getNEODevice()->getExecutionEnvironment()->isDebuggingEnabled());
delete L0::GlobalDriver;
L0::GlobalDriverHandle = nullptr;
L0::GlobalDriver = nullptr;
}
TEST(DriverImpTest, givenNoProgramDebuggingEnvVarWhenCreatingExecutionEnvironmentThenPerContextMemorySpaceIsFalse) {
TEST(DriverImpTest, givenNoProgramDebuggingEnvVarWhenCreatingExecutionEnvironmentThenDebuggingEnabledIsFalse) {
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
hwInfo.capabilityTable.levelZeroSupported = true;
@@ -214,7 +214,7 @@ TEST(DriverImpTest, givenNoProgramDebuggingEnvVarWhenCreatingExecutionEnvironmen
ASSERT_NE(nullptr, L0::GlobalDriver);
ASSERT_NE(0u, L0::GlobalDriver->numDevices);
EXPECT_FALSE(L0::GlobalDriver->devices[0]->getNEODevice()->getExecutionEnvironment()->isPerContextMemorySpaceRequired());
EXPECT_FALSE(L0::GlobalDriver->devices[0]->getNEODevice()->getExecutionEnvironment()->isDebuggingEnabled());
delete L0::GlobalDriver;
L0::GlobalDriverHandle = nullptr;