Skip to content

Commit 9a66730

Browse files
Refactor: move DebuggerL0 initialization to RootDeviceEnvironment
Signed-off-by: Mateusz Hoppe <[email protected]>
1 parent ba0e3ad commit 9a66730

File tree

5 files changed

+75
-13
lines changed

5 files changed

+75
-13
lines changed

level_zero/core/source/driver/driver_handle_imp.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,20 +168,10 @@ void DriverHandleImp::updateRootDeviceBitFields(std::unique_ptr<NEO::Device> &ne
168168
}
169169

170170
void DriverHandleImp::enableRootDeviceDebugger(std::unique_ptr<NEO::Device> &neoDevice) {
171-
const auto rootDeviceIndex = neoDevice->getRootDeviceIndex();
172-
auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex].get();
173-
174171
if (enableProgramDebugging) {
175-
if (neoDevice->getDebugger() != nullptr) {
176-
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
177-
"%s", "Source Level Debugger cannot be used with Environment Variable enabling program debugging.\n");
178-
UNRECOVERABLE_IF(neoDevice->getDebugger() != nullptr && enableProgramDebugging);
179-
}
180-
rootDeviceEnvironment->getMutableHardwareInfo()->capabilityTable.fusedEuEnabled = false;
181-
rootDeviceEnvironment->getMutableHardwareInfo()->capabilityTable.ftrRenderCompressedBuffers = false;
182-
rootDeviceEnvironment->getMutableHardwareInfo()->capabilityTable.ftrRenderCompressedImages = false;
183-
184-
rootDeviceEnvironment->debugger = NEO::DebuggerL0::create(neoDevice.get());
172+
const auto rootDeviceIndex = neoDevice->getRootDeviceIndex();
173+
auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex].get();
174+
rootDeviceEnvironment->initDebuggerL0(neoDevice.get());
185175
}
186176
}
187177

opencl/source/dll/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ append_sources_from_properties(RUNTIME_SRCS_DLL_BASE
4646
)
4747

4848
set(RUNTIME_SRCS_DLL_LINUX
49+
${NEO_SHARED_DIRECTORY}/dll/linux/debugger_l0_dll_linux.cpp
4950
${NEO_SHARED_DIRECTORY}/dll/linux/drm_neo_create.cpp
5051
${NEO_SHARED_DIRECTORY}/dll/linux/options_linux.cpp
5152
${NEO_SHARED_DIRECTORY}/dll/linux/os_interface.cpp
@@ -57,6 +58,7 @@ set(RUNTIME_SRCS_DLL_LINUX
5758
)
5859

5960
set(RUNTIME_SRCS_DLL_WINDOWS
61+
${NEO_SHARED_DIRECTORY}/dll/windows/debugger_l0_windows.cpp
6062
${NEO_SHARED_DIRECTORY}/dll/windows/options_windows.cpp
6163
${NEO_SHARED_DIRECTORY}/dll/windows/os_interface.cpp
6264
${NEO_SHARED_DIRECTORY}/dll/windows/environment_variables.cpp

shared/source/execution_environment/root_device_environment.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "shared/source/compiler_interface/compiler_interface.h"
1414
#include "shared/source/compiler_interface/default_cache_config.h"
1515
#include "shared/source/debugger/debugger.h"
16+
#include "shared/source/debugger/debugger_l0.h"
1617
#include "shared/source/execution_environment/execution_environment.h"
1718
#include "shared/source/gmm_helper/gmm_helper.h"
1819
#include "shared/source/gmm_helper/page_table_mngr.h"
@@ -46,6 +47,20 @@ void RootDeviceEnvironment::initDebugger() {
4647
debugger = Debugger::create(hwInfo.get());
4748
}
4849

50+
void RootDeviceEnvironment::initDebuggerL0(Device *neoDevice) {
51+
if (this->debugger.get() != nullptr) {
52+
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
53+
"%s", "Source Level Debugger cannot be used with Environment Variable enabling program debugging.\n");
54+
UNRECOVERABLE_IF(this->debugger.get() != nullptr);
55+
}
56+
57+
this->getMutableHardwareInfo()->capabilityTable.fusedEuEnabled = false;
58+
this->getMutableHardwareInfo()->capabilityTable.ftrRenderCompressedBuffers = false;
59+
this->getMutableHardwareInfo()->capabilityTable.ftrRenderCompressedImages = false;
60+
61+
this->debugger = DebuggerL0::create(neoDevice);
62+
}
63+
4964
const HardwareInfo *RootDeviceEnvironment::getHardwareInfo() const {
5065
return hwInfo.get();
5166
}

shared/source/execution_environment/root_device_environment.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class BindlessHeapsHelper;
2222
class BuiltIns;
2323
class CompilerInterface;
2424
class Debugger;
25+
class Device;
2526
class ExecutionEnvironment;
2627
class GmmClientContext;
2728
class GmmHelper;
@@ -54,6 +55,7 @@ struct RootDeviceEnvironment {
5455
void initOsTime();
5556
void initGmm();
5657
void initDebugger();
58+
void initDebuggerL0(Device *neoDevice);
5759
MOCKABLE_VIRTUAL void prepareForCleanup() const;
5860
MOCKABLE_VIRTUAL bool initAilConfiguration();
5961
GmmHelper *getGmmHelper() const;

shared/test/unit_test/debugger/test_l0_debugger.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,59 @@ TEST(Debugger, givenDebuggingEnabledInExecEnvWhenAllocatingIsaThenSingleBankIsUs
120120
neoDevice->getMemoryManager()->freeGraphicsMemory(allocation);
121121
}
122122

123+
TEST(Debugger, WhenInitializingDebuggerL0ThenCapabilitiesAreAdjustedAndDebuggerIsCreated) {
124+
auto executionEnvironment = new NEO::ExecutionEnvironment();
125+
executionEnvironment->incRefInternal();
126+
executionEnvironment->prepareRootDeviceEnvironments(1);
127+
128+
auto hwInfo = *NEO::defaultHwInfo.get();
129+
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(&hwInfo);
130+
executionEnvironment->rootDeviceEnvironments[0]->initGmm();
131+
executionEnvironment->initializeMemoryManager();
132+
133+
executionEnvironment->setDebuggingEnabled();
134+
135+
auto neoDevice = std::unique_ptr<MockDevice>(MockDevice::create<MockDevice>(executionEnvironment, 0u));
136+
137+
executionEnvironment->rootDeviceEnvironments[0]->initDebuggerL0(neoDevice.get());
138+
139+
EXPECT_FALSE(executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo()->capabilityTable.fusedEuEnabled);
140+
EXPECT_FALSE(executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo()->capabilityTable.ftrRenderCompressedBuffers);
141+
EXPECT_FALSE(executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo()->capabilityTable.ftrRenderCompressedImages);
142+
143+
EXPECT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[0]->debugger);
144+
executionEnvironment->decRefInternal();
145+
}
146+
147+
TEST(Debugger, GivenLegacyDebuggerWhenInitializingDebuggerL0ThenAbortIsCalledAfterPrintingError) {
148+
DebugManagerStateRestore restorer;
149+
NEO::DebugManager.flags.PrintDebugMessages.set(1);
150+
151+
::testing::internal::CaptureStderr();
152+
auto executionEnvironment = new NEO::ExecutionEnvironment();
153+
executionEnvironment->incRefInternal();
154+
executionEnvironment->prepareRootDeviceEnvironments(1);
155+
156+
auto mockDebugger = new MockSourceLevelDebugger();
157+
executionEnvironment->rootDeviceEnvironments[0]->debugger.reset(mockDebugger);
158+
159+
auto hwInfo = *NEO::defaultHwInfo.get();
160+
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(&hwInfo);
161+
executionEnvironment->rootDeviceEnvironments[0]->initGmm();
162+
executionEnvironment->initializeMemoryManager();
163+
164+
executionEnvironment->setDebuggingEnabled();
165+
166+
auto neoDevice = std::unique_ptr<MockDevice>(MockDevice::create<MockDevice>(executionEnvironment, 0u));
167+
168+
EXPECT_THROW(executionEnvironment->rootDeviceEnvironments[0]->initDebuggerL0(neoDevice.get()), std::exception);
169+
std::string output = testing::internal::GetCapturedStderr();
170+
171+
EXPECT_EQ(std::string("Source Level Debugger cannot be used with Environment Variable enabling program debugging.\n"), output);
172+
173+
executionEnvironment->decRefInternal();
174+
}
175+
123176
using L0DebuggerTest = Test<DeviceFixture>;
124177

125178
HWTEST_F(L0DebuggerTest, GivenDeviceWhenAllocateCalledThenDebuggerIsCreated) {

0 commit comments

Comments
 (0)