Skip to content

Commit 65214e2

Browse files
bmyatesCompute-Runtime-Automation
authored andcommitted
Add windows debugger feature check
Related-To: NEO-6717 Signed-off-by: Yates, Brandon <brandon.yates@intel.com>
1 parent 3f04769 commit 65214e2

File tree

10 files changed

+154
-4
lines changed

10 files changed

+154
-4
lines changed

level_zero/core/source/debugger/windows/debugger_l0_windows.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@
88
#include "shared/source/device/device.h"
99
#include "shared/source/helpers/hw_helper.h"
1010
#include "shared/source/kernel/debug_data.h"
11+
#include "shared/source/os_interface/windows/wddm/wddm.h"
1112

1213
#include "level_zero/core/source/debugger/debugger_l0.h"
1314

1415
namespace L0 {
1516
bool DebuggerL0::initDebuggingInOs(NEO::OSInterface *osInterface) {
16-
return false;
17+
18+
if (osInterface == nullptr) {
19+
return false;
20+
}
21+
if (osInterface->isDebugAttachAvailable() == false) {
22+
return false;
23+
}
24+
25+
return true;
1726
}
1827

1928
void DebuggerL0::registerElf(NEO::DebugData *debugData, NEO::GraphicsAllocation *isaAllocation) {
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -9,6 +9,15 @@
99

1010
namespace L0 {
1111
std::unique_ptr<NEO::Debugger> DebuggerL0::create(NEO::Device *device) {
12-
return std::unique_ptr<NEO::Debugger>(nullptr);
12+
auto &hwInfo = device->getHardwareInfo();
13+
if (!hwInfo.capabilityTable.l0DebuggerSupported) {
14+
return std::unique_ptr<DebuggerL0>(nullptr);
15+
}
16+
auto success = initDebuggingInOs(device->getRootDeviceEnvironment().osInterface.get());
17+
if (success) {
18+
auto debugger = debuggerL0Factory[device->getHardwareInfo().platform.eRenderCoreFamily](device);
19+
return std::unique_ptr<DebuggerL0>(debugger);
20+
}
21+
return std::unique_ptr<DebuggerL0>(nullptr);
1322
}
1423
} // namespace L0

level_zero/core/test/unit_tests/mocks/debugger_l0_create.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright (C) 2022 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#
6+
7+
if(WIN32)
8+
target_sources(${TARGET_NAME} PRIVATE
9+
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
10+
${CMAKE_CURRENT_SOURCE_DIR}/test_l0_debugger_windows.cpp
11+
)
12+
endif()
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (C) 2020-2022 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/command_stream/preemption.h"
9+
#include "shared/source/execution_environment/execution_environment.h"
10+
#include "shared/source/execution_environment/root_device_environment.h"
11+
#include "shared/source/helpers/hw_helper.h"
12+
#include "shared/source/os_interface/os_interface.h"
13+
#include "shared/source/os_interface/windows/gdi_interface.h"
14+
#include "shared/source/os_interface/windows/os_context_win.h"
15+
#include "shared/source/os_interface/windows/os_environment_win.h"
16+
#include "shared/source/os_interface/windows/wddm_memory_operations_handler.h"
17+
#include "shared/test/common/helpers/default_hw_info.h"
18+
#include "shared/test/common/helpers/engine_descriptor_helper.h"
19+
#include "shared/test/common/mocks/mock_wddm.h"
20+
#include "shared/test/common/mocks/windows/mock_gdi_interface.h"
21+
#include "shared/test/common/mocks/windows/mock_gmm_memory_base.h"
22+
#include "shared/test/common/test_macros/test.h"
23+
24+
#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h"
25+
#include "level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h"
26+
27+
#include <algorithm>
28+
#include <memory>
29+
30+
using namespace NEO;
31+
32+
namespace L0 {
33+
namespace ult {
34+
35+
struct WddmEuDebugInterfaceMock : public WddmMock {
36+
WddmEuDebugInterfaceMock(RootDeviceEnvironment &rootDeviceEnvironment) : WddmMock(rootDeviceEnvironment) {}
37+
38+
bool isDebugAttachAvailable() override {
39+
return true;
40+
}
41+
};
42+
43+
struct L0DebuggerWindowsFixture {
44+
void SetUp() {
45+
auto executionEnvironment = new NEO::ExecutionEnvironment();
46+
executionEnvironment->prepareRootDeviceEnvironments(1);
47+
executionEnvironment->setDebuggingEnabled();
48+
rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get();
49+
auto osEnvironment = new OsEnvironmentWin();
50+
gdi = new MockGdi();
51+
osEnvironment->gdi.reset(gdi);
52+
executionEnvironment->osEnvironment.reset(osEnvironment);
53+
wddm = new WddmEuDebugInterfaceMock(*rootDeviceEnvironment);
54+
rootDeviceEnvironment->osInterface = std::make_unique<OSInterface>();
55+
rootDeviceEnvironment->osInterface->setDriverModel(std::unique_ptr<DriverModel>(wddm));
56+
rootDeviceEnvironment->memoryOperationsInterface = std::make_unique<WddmMemoryOperationsHandler>(wddm);
57+
wddm->init();
58+
auto hwInfo = rootDeviceEnvironment->getHardwareInfo();
59+
auto engine = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0];
60+
61+
neoDevice = NEO::MockDevice::create<NEO::MockDevice>(executionEnvironment, 0u);
62+
63+
NEO::DeviceVector devices;
64+
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
65+
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
66+
driverHandle->enableProgramDebugging = true;
67+
68+
driverHandle->initialize(std::move(devices));
69+
device = driverHandle->devices[0];
70+
}
71+
72+
void TearDown() {
73+
}
74+
75+
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
76+
NEO::MockDevice *neoDevice = nullptr;
77+
L0::Device *device = nullptr;
78+
WddmEuDebugInterfaceMock *wddm = nullptr;
79+
RootDeviceEnvironment *rootDeviceEnvironment = nullptr;
80+
MockGdi *gdi = nullptr;
81+
};
82+
83+
using L0DebuggerWindowsTest = Test<L0DebuggerWindowsFixture>;
84+
85+
TEST_F(L0DebuggerWindowsTest, givenProgramDebuggingEnabledWhenDriverHandleIsCreatedThenItAllocatesL0Debugger) {
86+
EXPECT_NE(nullptr, neoDevice->getDebugger());
87+
EXPECT_FALSE(neoDevice->getDebugger()->isLegacy());
88+
EXPECT_EQ(nullptr, neoDevice->getSourceLevelDebugger());
89+
}
90+
91+
} // namespace ult
92+
} // namespace L0

shared/source/os_interface/windows/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ set(NEO_CORE_OS_INTERFACE_WDDM
112112
${CMAKE_CURRENT_SOURCE_DIR}/windows_wrapper.h
113113
${CMAKE_CURRENT_SOURCE_DIR}/sys_calls_wrapper.h
114114
${CMAKE_CURRENT_SOURCE_DIR}/wddm${BRANCH_DIR_SUFFIX}/init_context_private_data.cpp
115+
${CMAKE_CURRENT_SOURCE_DIR}/wddm${BRANCH_DIR_SUFFIX}/wddm_debug_interface.cpp
115116
)
116117

117118
if(NOT WIN32 AND NOT DISABLE_WDDM_LINUX)

shared/source/os_interface/windows/os_interface_win.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include "shared/source/os_interface/os_interface.h"
9+
#include "shared/source/os_interface/windows/wddm/wddm.h"
910

1011
namespace NEO {
1112

@@ -15,6 +16,9 @@ bool OSInterface::gpuIdleImplicitFlush = false;
1516
bool OSInterface::requiresSupportForWddmTrimNotification = true;
1617

1718
bool OSInterface::isDebugAttachAvailable() const {
19+
if (driverModel) {
20+
return driverModel->as<NEO::Wddm>()->isDebugAttachAvailable();
21+
}
1822
return false;
1923
}
2024

shared/source/os_interface/windows/wddm/wddm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class Wddm : public DriverModel {
111111
MOCKABLE_VIRTUAL void virtualFree(void *ptr, size_t size);
112112

113113
MOCKABLE_VIRTUAL bool isShutdownInProgress();
114+
MOCKABLE_VIRTUAL bool isDebugAttachAvailable();
114115

115116
bool isGpuHangDetected(OsContext &osContext) override;
116117

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright (C) 2022 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/os_interface/os_interface.h"
9+
#include "shared/source/os_interface/windows/wddm/wddm.h"
10+
11+
namespace NEO {
12+
13+
bool Wddm::isDebugAttachAvailable() {
14+
return false;
15+
}
16+
17+
} // namespace NEO

shared/test/unit_test/os_interface/windows/wddm_tests.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ TEST_F(WddmTests, whenCreatingContextWithPowerHintSuccessIsReturned) {
8383
EXPECT_TRUE(wddm->createContext(*newContext));
8484
}
8585

86+
TEST_F(WddmTests, whenftrEuDebugIsFalseThenDebuggingEnabledReturnsFalse) {
87+
init();
88+
EXPECT_FALSE(wddm->isDebugAttachAvailable());
89+
}
90+
8691
TEST(WddmPciSpeedInfoTest, WhenGetPciSpeedInfoIsCalledThenUnknownIsReturned) {
8792
MockExecutionEnvironment executionEnvironment;
8893
RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment);

0 commit comments

Comments
 (0)