diff --git a/level_zero/core/source/debugger/windows/debugger_l0_windows.cpp b/level_zero/core/source/debugger/windows/debugger_l0_windows.cpp index 28f80e4477..0586989e25 100644 --- a/level_zero/core/source/debugger/windows/debugger_l0_windows.cpp +++ b/level_zero/core/source/debugger/windows/debugger_l0_windows.cpp @@ -8,12 +8,21 @@ #include "shared/source/device/device.h" #include "shared/source/helpers/hw_helper.h" #include "shared/source/kernel/debug_data.h" +#include "shared/source/os_interface/windows/wddm/wddm.h" #include "level_zero/core/source/debugger/debugger_l0.h" namespace L0 { bool DebuggerL0::initDebuggingInOs(NEO::OSInterface *osInterface) { - return false; + + if (osInterface == nullptr) { + return false; + } + if (osInterface->isDebugAttachAvailable() == false) { + return false; + } + + return true; } void DebuggerL0::registerElf(NEO::DebugData *debugData, NEO::GraphicsAllocation *isaAllocation) { diff --git a/level_zero/core/source/dll/windows/debugger_l0_windows.cpp b/level_zero/core/source/dll/windows/debugger_l0_windows.cpp index b797daf7a4..a4e9872fc9 100644 --- a/level_zero/core/source/dll/windows/debugger_l0_windows.cpp +++ b/level_zero/core/source/dll/windows/debugger_l0_windows.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -9,6 +9,15 @@ namespace L0 { std::unique_ptr DebuggerL0::create(NEO::Device *device) { - return std::unique_ptr(nullptr); + auto &hwInfo = device->getHardwareInfo(); + if (!hwInfo.capabilityTable.l0DebuggerSupported) { + return std::unique_ptr(nullptr); + } + auto success = initDebuggingInOs(device->getRootDeviceEnvironment().osInterface.get()); + if (success) { + auto debugger = debuggerL0Factory[device->getHardwareInfo().platform.eRenderCoreFamily](device); + return std::unique_ptr(debugger); + } + return std::unique_ptr(nullptr); } } // namespace L0 \ No newline at end of file diff --git a/level_zero/core/test/unit_tests/mocks/debugger_l0_create.cpp b/level_zero/core/test/unit_tests/mocks/debugger_l0_create.cpp index 9e0bb028db..c35b7eca15 100644 --- a/level_zero/core/test/unit_tests/mocks/debugger_l0_create.cpp +++ b/level_zero/core/test/unit_tests/mocks/debugger_l0_create.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * diff --git a/level_zero/core/test/unit_tests/sources/debugger/windows/CMakeLists.txt b/level_zero/core/test/unit_tests/sources/debugger/windows/CMakeLists.txt new file mode 100644 index 0000000000..d68b4cd5c9 --- /dev/null +++ b/level_zero/core/test/unit_tests/sources/debugger/windows/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (C) 2022 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +if(WIN32) + target_sources(${TARGET_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/test_l0_debugger_windows.cpp + ) +endif() diff --git a/level_zero/core/test/unit_tests/sources/debugger/windows/test_l0_debugger_windows.cpp b/level_zero/core/test/unit_tests/sources/debugger/windows/test_l0_debugger_windows.cpp new file mode 100644 index 0000000000..405b2c6e3a --- /dev/null +++ b/level_zero/core/test/unit_tests/sources/debugger/windows/test_l0_debugger_windows.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2020-2022 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/command_stream/preemption.h" +#include "shared/source/execution_environment/execution_environment.h" +#include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/helpers/hw_helper.h" +#include "shared/source/os_interface/os_interface.h" +#include "shared/source/os_interface/windows/gdi_interface.h" +#include "shared/source/os_interface/windows/os_context_win.h" +#include "shared/source/os_interface/windows/os_environment_win.h" +#include "shared/source/os_interface/windows/wddm_memory_operations_handler.h" +#include "shared/test/common/helpers/default_hw_info.h" +#include "shared/test/common/helpers/engine_descriptor_helper.h" +#include "shared/test/common/mocks/mock_wddm.h" +#include "shared/test/common/mocks/windows/mock_gdi_interface.h" +#include "shared/test/common/mocks/windows/mock_gmm_memory_base.h" +#include "shared/test/common/test_macros/test.h" + +#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h" +#include "level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h" + +#include +#include + +using namespace NEO; + +namespace L0 { +namespace ult { + +struct WddmEuDebugInterfaceMock : public WddmMock { + WddmEuDebugInterfaceMock(RootDeviceEnvironment &rootDeviceEnvironment) : WddmMock(rootDeviceEnvironment) {} + + bool isDebugAttachAvailable() override { + return true; + } +}; + +struct L0DebuggerWindowsFixture { + void SetUp() { + auto executionEnvironment = new NEO::ExecutionEnvironment(); + executionEnvironment->prepareRootDeviceEnvironments(1); + executionEnvironment->setDebuggingEnabled(); + rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get(); + auto osEnvironment = new OsEnvironmentWin(); + gdi = new MockGdi(); + osEnvironment->gdi.reset(gdi); + executionEnvironment->osEnvironment.reset(osEnvironment); + wddm = new WddmEuDebugInterfaceMock(*rootDeviceEnvironment); + rootDeviceEnvironment->osInterface = std::make_unique(); + rootDeviceEnvironment->osInterface->setDriverModel(std::unique_ptr(wddm)); + rootDeviceEnvironment->memoryOperationsInterface = std::make_unique(wddm); + wddm->init(); + auto hwInfo = rootDeviceEnvironment->getHardwareInfo(); + auto engine = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0]; + + neoDevice = NEO::MockDevice::create(executionEnvironment, 0u); + + NEO::DeviceVector devices; + devices.push_back(std::unique_ptr(neoDevice)); + driverHandle = std::make_unique>(); + driverHandle->enableProgramDebugging = true; + + driverHandle->initialize(std::move(devices)); + device = driverHandle->devices[0]; + } + + void TearDown() { + } + + std::unique_ptr> driverHandle; + NEO::MockDevice *neoDevice = nullptr; + L0::Device *device = nullptr; + WddmEuDebugInterfaceMock *wddm = nullptr; + RootDeviceEnvironment *rootDeviceEnvironment = nullptr; + MockGdi *gdi = nullptr; +}; + +using L0DebuggerWindowsTest = Test; + +TEST_F(L0DebuggerWindowsTest, givenProgramDebuggingEnabledWhenDriverHandleIsCreatedThenItAllocatesL0Debugger) { + EXPECT_NE(nullptr, neoDevice->getDebugger()); + EXPECT_FALSE(neoDevice->getDebugger()->isLegacy()); + EXPECT_EQ(nullptr, neoDevice->getSourceLevelDebugger()); +} + +} // namespace ult +} // namespace L0 diff --git a/shared/source/os_interface/windows/CMakeLists.txt b/shared/source/os_interface/windows/CMakeLists.txt index b786ad9220..108a8f1d37 100644 --- a/shared/source/os_interface/windows/CMakeLists.txt +++ b/shared/source/os_interface/windows/CMakeLists.txt @@ -112,6 +112,7 @@ set(NEO_CORE_OS_INTERFACE_WDDM ${CMAKE_CURRENT_SOURCE_DIR}/windows_wrapper.h ${CMAKE_CURRENT_SOURCE_DIR}/sys_calls_wrapper.h ${CMAKE_CURRENT_SOURCE_DIR}/wddm${BRANCH_DIR_SUFFIX}/init_context_private_data.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/wddm${BRANCH_DIR_SUFFIX}/wddm_debug_interface.cpp ) if(NOT WIN32 AND NOT DISABLE_WDDM_LINUX) diff --git a/shared/source/os_interface/windows/os_interface_win.cpp b/shared/source/os_interface/windows/os_interface_win.cpp index b4e0c99b28..2ed255900e 100644 --- a/shared/source/os_interface/windows/os_interface_win.cpp +++ b/shared/source/os_interface/windows/os_interface_win.cpp @@ -6,6 +6,7 @@ */ #include "shared/source/os_interface/os_interface.h" +#include "shared/source/os_interface/windows/wddm/wddm.h" namespace NEO { @@ -15,6 +16,9 @@ bool OSInterface::gpuIdleImplicitFlush = false; bool OSInterface::requiresSupportForWddmTrimNotification = true; bool OSInterface::isDebugAttachAvailable() const { + if (driverModel) { + return driverModel->as()->isDebugAttachAvailable(); + } return false; } diff --git a/shared/source/os_interface/windows/wddm/wddm.h b/shared/source/os_interface/windows/wddm/wddm.h index 55f3648fa5..e7bc32d9d6 100644 --- a/shared/source/os_interface/windows/wddm/wddm.h +++ b/shared/source/os_interface/windows/wddm/wddm.h @@ -111,6 +111,7 @@ class Wddm : public DriverModel { MOCKABLE_VIRTUAL void virtualFree(void *ptr, size_t size); MOCKABLE_VIRTUAL bool isShutdownInProgress(); + MOCKABLE_VIRTUAL bool isDebugAttachAvailable(); bool isGpuHangDetected(OsContext &osContext) override; diff --git a/shared/source/os_interface/windows/wddm/wddm_debug_interface.cpp b/shared/source/os_interface/windows/wddm/wddm_debug_interface.cpp new file mode 100644 index 0000000000..e34fdfa88c --- /dev/null +++ b/shared/source/os_interface/windows/wddm/wddm_debug_interface.cpp @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2022 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/os_interface/os_interface.h" +#include "shared/source/os_interface/windows/wddm/wddm.h" + +namespace NEO { + +bool Wddm::isDebugAttachAvailable() { + return false; +} + +} // namespace NEO diff --git a/shared/test/unit_test/os_interface/windows/wddm_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm_tests.cpp index e64ebbd741..ff59889bc7 100644 --- a/shared/test/unit_test/os_interface/windows/wddm_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm_tests.cpp @@ -83,6 +83,11 @@ TEST_F(WddmTests, whenCreatingContextWithPowerHintSuccessIsReturned) { EXPECT_TRUE(wddm->createContext(*newContext)); } +TEST_F(WddmTests, whenftrEuDebugIsFalseThenDebuggingEnabledReturnsFalse) { + init(); + EXPECT_FALSE(wddm->isDebugAttachAvailable()); +} + TEST(WddmPciSpeedInfoTest, WhenGetPciSpeedInfoIsCalledThenUnknownIsReturned) { MockExecutionEnvironment executionEnvironment; RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment);