Skip to content

Commit 8f87dfa

Browse files
Add Debug API handlers
Related-To: NEO-4554 Signed-off-by: Mateusz Hoppe <[email protected]>
1 parent 4764cbd commit 8f87dfa

File tree

25 files changed

+417
-13
lines changed

25 files changed

+417
-13
lines changed

level_zero/api/tools/zet_debug.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@
55
*
66
*/
77

8+
#include "level_zero/core/source/device/device.h"
9+
#include "level_zero/tools/source/debug/debug_handlers.h"
810
#include <level_zero/zet_api.h>
911

1012
ZE_APIEXPORT ze_result_t ZE_APICALL
1113
zetDeviceGetDebugProperties(
1214
zet_device_handle_t hDevice,
1315
zet_device_debug_properties_t *pDebugProperties) {
14-
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
16+
return L0::Device::fromHandle(hDevice)->getDebugProperties(pDebugProperties);
1517
}
1618

1719
ZE_APIEXPORT ze_result_t ZE_APICALL
1820
zetDebugAttach(
1921
zet_device_handle_t hDevice,
2022
const zet_debug_config_t *config,
2123
zet_debug_session_handle_t *phDebug) {
22-
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
24+
return L0::debugAttach(hDevice, config, phDebug);
2325
}
2426

2527
ZE_APIEXPORT ze_result_t ZE_APICALL

level_zero/core/source/device/device.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2020 Intel Corporation
2+
* Copyright (C) 2019-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -36,6 +36,7 @@ struct BuiltinFunctionsLib;
3636
struct ExecutionEnvironment;
3737
struct MetricContext;
3838
struct SysmanDevice;
39+
struct DebugSession;
3940

4041
enum class ModuleType;
4142

@@ -72,6 +73,8 @@ struct Device : _ze_device_handle_t {
7273

7374
virtual ze_result_t getCommandQueueGroupProperties(uint32_t *pCount,
7475
ze_command_queue_group_properties_t *pCommandQueueGroupProperties) = 0;
76+
virtual ze_result_t getDebugProperties(zet_device_debug_properties_t *pDebugProperties) = 0;
77+
7578
virtual ze_result_t systemBarrier() = 0;
7679

7780
virtual ~Device() = default;
@@ -87,6 +90,7 @@ struct Device : _ze_device_handle_t {
8790
virtual NEO::OSInterface &getOsInterface() = 0;
8891
virtual uint32_t getPlatformInfo() const = 0;
8992
virtual MetricContext &getMetricContext() = 0;
93+
virtual DebugSession *getDebugSession(const zet_debug_config_t &config) = 0;
9094

9195
virtual ze_result_t activateMetricGroups(uint32_t count,
9296
zet_metric_group_handle_t *phMetricGroups) = 0;

level_zero/core/source/device/device_imp.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "level_zero/core/source/module/module.h"
4141
#include "level_zero/core/source/printf_handler/printf_handler.h"
4242
#include "level_zero/core/source/sampler/sampler.h"
43+
#include "level_zero/tools/source/debug/debug_session.h"
4344
#include "level_zero/tools/source/metrics/metric.h"
4445
#include "level_zero/tools/source/sysman/sysman.h"
4546

@@ -486,6 +487,16 @@ ze_result_t DeviceImp::getDeviceImageProperties(ze_device_image_properties_t *pD
486487
return ZE_RESULT_SUCCESS;
487488
}
488489

490+
ze_result_t DeviceImp::getDebugProperties(zet_device_debug_properties_t *pDebugProperties) {
491+
bool isDebugAttachAvailable = getOsInterface().isDebugAttachAvailable();
492+
if (isDebugAttachAvailable && !isSubdevice) {
493+
pDebugProperties->flags = zet_device_debug_property_flag_t::ZET_DEVICE_DEBUG_PROPERTY_FLAG_ATTACH;
494+
} else {
495+
pDebugProperties->flags = 0;
496+
}
497+
return ZE_RESULT_SUCCESS;
498+
}
499+
489500
ze_result_t DeviceImp::systemBarrier() { return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; }
490501

491502
ze_result_t DeviceImp::activateMetricGroups(uint32_t count,
@@ -799,4 +810,17 @@ ze_result_t DeviceImp::mapOrdinalForAvailableEngineGroup(uint32_t *ordinal) {
799810
*ordinal = i - 1;
800811
return ZE_RESULT_SUCCESS;
801812
};
813+
814+
DebugSession *DeviceImp::getDebugSession(const zet_debug_config_t &config) {
815+
if (debugSession != nullptr) {
816+
return debugSession.get();
817+
}
818+
819+
if (!this->isSubdevice) {
820+
auto session = DebugSession::create(config, this);
821+
debugSession.reset(session);
822+
}
823+
return debugSession.get();
824+
}
825+
802826
} // namespace L0

level_zero/core/source/device/device_imp.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
#include "level_zero/core/source/device/device.h"
1313
#include "level_zero/core/source/driver/driver_handle.h"
1414
#include "level_zero/core/source/module/module.h"
15+
#include "level_zero/tools/source/debug/debug_session.h"
1516
#include "level_zero/tools/source/metrics/metric.h"
1617

1718
namespace L0 {
1819
struct SysmanDevice;
20+
1921
struct DeviceImp : public Device {
2022
uint32_t getRootDeviceIndex() override;
2123
ze_result_t canAccessPeer(ze_device_handle_t hPeerDevice, ze_bool_t *value) override;
@@ -44,6 +46,8 @@ struct DeviceImp : public Device {
4446
ze_result_t getCommandQueueGroupProperties(uint32_t *pCount,
4547
ze_command_queue_group_properties_t *pCommandQueueGroupProperties) override;
4648
ze_result_t getExternalMemoryProperties(ze_device_external_memory_properties_t *pExternalMemoryProperties) override;
49+
ze_result_t getDebugProperties(zet_device_debug_properties_t *pDebugProperties) override;
50+
4751
ze_result_t systemBarrier() override;
4852
void *getExecEnvironment() override;
4953
BuiltinFunctionsLib *getBuiltinFunctionsLib() override;
@@ -54,6 +58,8 @@ struct DeviceImp : public Device {
5458
NEO::OSInterface &getOsInterface() override;
5559
uint32_t getPlatformInfo() const override;
5660
MetricContext &getMetricContext() override;
61+
DebugSession *getDebugSession(const zet_debug_config_t &config) override;
62+
5763
uint32_t getMaxNumHwThreads() const override;
5864
ze_result_t activateMetricGroups(uint32_t count,
5965
zet_metric_group_handle_t *phMetricGroups) override;
@@ -95,6 +101,7 @@ struct DeviceImp : public Device {
95101
protected:
96102
NEO::GraphicsAllocation *debugSurface = nullptr;
97103
SysmanDevice *pSysmanDevice = nullptr;
104+
std::unique_ptr<DebugSession> debugSession = nullptr;
98105
};
99106

100107
} // namespace L0

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2020 Intel Corporation
2+
* Copyright (C) 2019-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -9,6 +9,8 @@
99

1010
#include "shared/source/device/device.h"
1111

12+
#include "level_zero/tools/source/debug/debug_session.h"
13+
1214
#include "gmock/gmock.h"
1315

1416
namespace L0 {

level_zero/core/test/unit_tests/mocks/mock_device.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2020 Intel Corporation
2+
* Copyright (C) 2019-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -242,11 +242,20 @@ struct Mock<Device> : public Device {
242242
ze_result_t mapOrdinalForAvailableEngineGroup(uint32_t *ordinal) override {
243243
return ZE_RESULT_SUCCESS;
244244
}
245+
246+
ze_result_t getDebugProperties(zet_device_debug_properties_t *properties) override {
247+
return ZE_RESULT_SUCCESS;
248+
}
249+
250+
DebugSession *getDebugSession(const zet_debug_config_t &config) override {
251+
return nullptr;
252+
}
245253
};
246254

247255
template <>
248256
struct Mock<L0::DeviceImp> : public L0::DeviceImp {
249257
using Base = L0::DeviceImp;
258+
using Base::debugSession;
250259

251260
explicit Mock(NEO::Device *device, NEO::ExecutionEnvironment *execEnv) {
252261
device->incRefInternal();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "opencl/test/unit_test/global_environment.h"
1414
#include "opencl/test/unit_test/helpers/kernel_binary_helper.h"
1515

16+
#include "level_zero/tools/source/debug/debug_session.h"
17+
1618
namespace L0 {
1719
namespace ult {
1820
template <bool useImagesBuiltins>

level_zero/tools/source/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#
2-
# Copyright (C) 2019-2020 Intel Corporation
2+
# Copyright (C) 2019-2021 Intel Corporation
33
#
44
# SPDX-License-Identifier: MIT
55
#
66

7+
add_subdirectory(debug)
78
add_subdirectory(metrics)
89
add_subdirectory(sysman)
910
add_subdirectory(pin)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Copyright (C) 2021 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#
6+
7+
set(L0_SRCS_TOOLS_DEBUG
8+
${CMAKE_CURRENT_SOURCE_DIR}/debug_session.h
9+
${CMAKE_CURRENT_SOURCE_DIR}/debug_handlers.h
10+
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/debug_handlers.cpp
11+
)
12+
13+
add_subdirectories()
14+
15+
target_sources(${L0_STATIC_LIB_NAME}
16+
PRIVATE
17+
${L0_SRCS_TOOLS_DEBUG}
18+
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
19+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "level_zero/tools/source/debug/debug_session.h"
9+
10+
namespace L0 {
11+
12+
DebugSession *DebugSession::create(const zet_debug_config_t &config, Device *device) {
13+
return nullptr;
14+
}
15+
16+
ze_result_t debugAttach(zet_device_handle_t hDevice, const zet_debug_config_t *config, zet_debug_session_handle_t *phDebug) {
17+
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
18+
}
19+
20+
} // namespace L0

0 commit comments

Comments
 (0)