Skip to content

Commit 7ff258f

Browse files
L0Debug - Enable attaching to Root or Subdevices
- enable tile attach mode by default - both root device and subdevice may be attached to Related-To: NEO-7347 Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
1 parent 57d35c8 commit 7ff258f

24 files changed

+388
-110
lines changed

level_zero/core/source/device/device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct Device : _ze_device_handle_t {
100100
virtual uint32_t getPlatformInfo() const = 0;
101101
virtual MetricDeviceContext &getMetricDeviceContext() = 0;
102102
virtual DebugSession *getDebugSession(const zet_debug_config_t &config) = 0;
103-
virtual DebugSession *createDebugSession(const zet_debug_config_t &config, ze_result_t &result) = 0;
103+
virtual DebugSession *createDebugSession(const zet_debug_config_t &config, ze_result_t &result, bool isRootAttach) = 0;
104104
virtual void removeDebugSession() = 0;
105105

106106
virtual ze_result_t activateMetricGroupsDeferred(uint32_t count,

level_zero/core/source/device/device_imp.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -888,10 +888,11 @@ ze_result_t DeviceImp::getDebugProperties(zet_device_debug_properties_t *pDebugP
888888
}
889889

890890
bool tileAttach = NEO::DebugManager.flags.ExperimentalEnableTileAttach.get();
891-
if (isDebugAttachAvailable && (isSubdevice == tileAttach)) {
892-
pDebugProperties->flags = zet_device_debug_property_flag_t::ZET_DEVICE_DEBUG_PROPERTY_FLAG_ATTACH;
893-
} else {
894-
pDebugProperties->flags = 0;
891+
pDebugProperties->flags = 0;
892+
if (isDebugAttachAvailable) {
893+
if ((isSubdevice && tileAttach) || !isSubdevice) {
894+
pDebugProperties->flags = zet_device_debug_property_flag_t::ZET_DEVICE_DEBUG_PROPERTY_FLAG_ATTACH;
895+
}
895896
}
896897
return ZE_RESULT_SUCCESS;
897898
}
@@ -1306,10 +1307,10 @@ DebugSession *DeviceImp::getDebugSession(const zet_debug_config_t &config) {
13061307
return debugSession.get();
13071308
}
13081309

1309-
DebugSession *DeviceImp::createDebugSession(const zet_debug_config_t &config, ze_result_t &result) {
1310+
DebugSession *DeviceImp::createDebugSession(const zet_debug_config_t &config, ze_result_t &result, bool isRootAttach) {
13101311
if (!this->isSubdevice) {
13111312
if (debugSession.get() == nullptr) {
1312-
auto session = DebugSession::create(config, this, result);
1313+
auto session = DebugSession::create(config, this, result, isRootAttach);
13131314
debugSession.reset(session);
13141315
} else {
13151316
result = ZE_RESULT_SUCCESS;
@@ -1320,7 +1321,7 @@ DebugSession *DeviceImp::createDebugSession(const zet_debug_config_t &config, ze
13201321

13211322
auto session = rootL0Device->getDebugSession(config);
13221323
if (!session) {
1323-
session = rootL0Device->createDebugSession(config, result);
1324+
session = rootL0Device->createDebugSession(config, result, isRootAttach);
13241325
}
13251326

13261327
if (result == ZE_RESULT_SUCCESS) {

level_zero/core/source/device/device_imp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct DeviceImp : public Device {
7575
MetricDeviceContext &getMetricDeviceContext() override;
7676
DebugSession *getDebugSession(const zet_debug_config_t &config) override;
7777
void setDebugSession(DebugSession *session);
78-
DebugSession *createDebugSession(const zet_debug_config_t &config, ze_result_t &result) override;
78+
DebugSession *createDebugSession(const zet_debug_config_t &config, ze_result_t &result, bool isRootAttach) override;
7979
void removeDebugSession() override;
8080

8181
uint32_t getMaxNumHwThreads() const override;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct Mock<Device> : public Device {
8383
ADDMETHOD_NOBASE(obtainReusableAllocation, NEO::GraphicsAllocation *, nullptr, (size_t requiredSize, NEO::AllocationType type))
8484
ADDMETHOD_NOBASE_VOIDRETURN(storeReusableAllocation, (NEO::GraphicsAllocation & alloc));
8585

86-
DebugSession *createDebugSession(const zet_debug_config_t &config, ze_result_t &result) override {
86+
DebugSession *createDebugSession(const zet_debug_config_t &config, ze_result_t &result, bool isRootAttach) override {
8787
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
8888
return nullptr;
8989
}

level_zero/tools/source/debug/debug_handlers.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ std::mutex debugSessionMutex;
2020
ze_result_t debugAttach(zet_device_handle_t hDevice, const zet_debug_config_t *config, zet_debug_session_handle_t *phDebug) {
2121
ze_result_t result = ZE_RESULT_SUCCESS;
2222

23-
if (!L0::Device::fromHandle(hDevice)->getNEODevice()->isSubDevice() && NEO::DebugManager.flags.ExperimentalEnableTileAttach.get()) {
23+
if (L0::Device::fromHandle(hDevice)->getNEODevice()->isSubDevice() && !NEO::DebugManager.flags.ExperimentalEnableTileAttach.get()) {
2424
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
2525
}
2626

@@ -35,10 +35,25 @@ ze_result_t debugAttach(zet_device_handle_t hDevice, const zet_debug_config_t *c
3535
auto session = L0::Device::fromHandle(hDevice)->getDebugSession(*config);
3636

3737
std::unique_lock<std::mutex> lock(debugSessionMutex);
38+
39+
auto rootSession = L0::Device::fromHandle(hDevice)->getNEODevice()->getRootDevice()->getSpecializedDevice<DeviceImp>()->getDebugSession(*config);
40+
41+
// If root device with active TileSessions or
42+
// subdevice with root device attached - fail
43+
if ((!L0::Device::fromHandle(hDevice)->getNEODevice()->isSubDevice() && session && !session->areAllTileDebugSessionDetached()) ||
44+
(L0::Device::fromHandle(hDevice)->getNEODevice()->isSubDevice() && rootSession && rootSession->isAttached())) {
45+
result = ZE_RESULT_ERROR_NOT_AVAILABLE;
46+
*phDebug = nullptr;
47+
return result;
48+
}
49+
3850
if (!session) {
39-
session = L0::Device::fromHandle(hDevice)->createDebugSession(*config, result);
51+
bool isRootAttach = !L0::Device::fromHandle(hDevice)->getNEODevice()->isSubDevice();
52+
session = L0::Device::fromHandle(hDevice)->createDebugSession(*config, result, isRootAttach);
4053
}
54+
4155
if (session) {
56+
session->setAttached();
4257
*phDebug = session->toHandle();
4358
}
4459
return result;
@@ -58,6 +73,7 @@ ze_result_t debugDetach(zet_debug_session_handle_t hDebug) {
5873
auto rootL0Device = device->getNEODevice()->getRootDevice()->getSpecializedDevice<DeviceImp>();
5974
zet_debug_config_t dummy = {};
6075
auto rootSession = rootL0Device->getDebugSession(dummy);
76+
session->setDetached();
6177
rootSession->detachTileDebugSession(session);
6278

6379
if (rootSession->areAllTileDebugSessionDetached()) {

level_zero/tools/source/debug/debug_session.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ struct DebugSession : _zet_debug_session_handle_t {
2525
virtual ~DebugSession() = default;
2626
DebugSession() = delete;
2727

28-
static DebugSession *create(const zet_debug_config_t &config, Device *device, ze_result_t &result);
28+
static DebugSession *create(const zet_debug_config_t &config, Device *device, ze_result_t &result, bool isRootAttach);
2929

3030
static DebugSession *fromHandle(zet_debug_session_handle_t handle) { return static_cast<DebugSession *>(handle); }
3131
inline zet_debug_session_handle_t toHandle() { return this; }
3232

33-
void createEuThreads();
3433
virtual bool closeConnection() = 0;
3534
virtual ze_result_t initialize() = 0;
3635

@@ -85,6 +84,11 @@ struct DebugSession : _zet_debug_session_handle_t {
8584
virtual void detachTileDebugSession(DebugSession *tileSession) = 0;
8685
virtual bool areAllTileDebugSessionDetached() = 0;
8786

87+
virtual void setAttachMode(bool isRootAttach) = 0;
88+
void setAttached() { attached = true; }
89+
void setDetached() { attached = false; }
90+
bool isAttached() { return attached; }
91+
8892
struct ThreadHelper {
8993
void close() {
9094
threadActive.store(false);
@@ -105,6 +109,8 @@ struct DebugSession : _zet_debug_session_handle_t {
105109

106110
protected:
107111
DebugSession(const zet_debug_config_t &config, Device *device);
112+
void createEuThreads();
113+
108114
virtual void startAsyncThread() = 0;
109115

110116
virtual bool isBindlessSystemRoutine();
@@ -121,6 +127,7 @@ struct DebugSession : _zet_debug_session_handle_t {
121127

122128
Device *connectedDevice = nullptr;
123129
std::map<uint64_t, std::unique_ptr<EuThread>> allThreads;
130+
bool attached = false;
124131
};
125132

126133
} // namespace L0

level_zero/tools/source/debug/debug_session_imp.cpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,38 @@ DebugSession::DebugSession(const zet_debug_config_t &config, Device *device) : c
2626
void DebugSession::createEuThreads() {
2727
if (connectedDevice) {
2828

29-
bool isRootDevice = !connectedDevice->getNEODevice()->isSubDevice();
3029
bool isSubDevice = connectedDevice->getNEODevice()->isSubDevice();
3130

32-
if ((isRootDevice && NEO::DebugManager.flags.ExperimentalEnableTileAttach.get() == 0) ||
33-
(isSubDevice && NEO::DebugManager.flags.ExperimentalEnableTileAttach.get() == 1)) {
34-
auto &hwInfo = connectedDevice->getHwInfo();
35-
const uint32_t numSubslicesPerSlice = hwInfo.gtSystemInfo.MaxSubSlicesSupported / hwInfo.gtSystemInfo.MaxSlicesSupported;
36-
const uint32_t numEuPerSubslice = hwInfo.gtSystemInfo.MaxEuPerSubSlice;
37-
const uint32_t numThreadsPerEu = (hwInfo.gtSystemInfo.ThreadCount / hwInfo.gtSystemInfo.EUCount);
38-
uint32_t subDeviceCount = std::max(1u, connectedDevice->getNEODevice()->getNumSubDevices());
31+
auto &hwInfo = connectedDevice->getHwInfo();
32+
const uint32_t numSubslicesPerSlice = hwInfo.gtSystemInfo.MaxSubSlicesSupported / hwInfo.gtSystemInfo.MaxSlicesSupported;
33+
const uint32_t numEuPerSubslice = hwInfo.gtSystemInfo.MaxEuPerSubSlice;
34+
const uint32_t numThreadsPerEu = (hwInfo.gtSystemInfo.ThreadCount / hwInfo.gtSystemInfo.EUCount);
35+
uint32_t subDeviceCount = std::max(1u, connectedDevice->getNEODevice()->getNumSubDevices());
3936

40-
UNRECOVERABLE_IF(isSubDevice && subDeviceCount > 1);
37+
UNRECOVERABLE_IF(isSubDevice && subDeviceCount > 1);
4138

42-
for (uint32_t tileIndex = 0; tileIndex < subDeviceCount; tileIndex++) {
39+
for (uint32_t tileIndex = 0; tileIndex < subDeviceCount; tileIndex++) {
4340

44-
if (isSubDevice || subDeviceCount == 1) {
45-
tileIndex = Math::log2(static_cast<uint32_t>(connectedDevice->getNEODevice()->getDeviceBitfield().to_ulong()));
46-
}
41+
if (isSubDevice || subDeviceCount == 1) {
42+
tileIndex = Math::log2(static_cast<uint32_t>(connectedDevice->getNEODevice()->getDeviceBitfield().to_ulong()));
43+
}
4744

48-
for (uint32_t sliceID = 0; sliceID < hwInfo.gtSystemInfo.MaxSlicesSupported; sliceID++) {
49-
for (uint32_t subsliceID = 0; subsliceID < numSubslicesPerSlice; subsliceID++) {
50-
for (uint32_t euID = 0; euID < numEuPerSubslice; euID++) {
45+
for (uint32_t sliceID = 0; sliceID < hwInfo.gtSystemInfo.MaxSlicesSupported; sliceID++) {
46+
for (uint32_t subsliceID = 0; subsliceID < numSubslicesPerSlice; subsliceID++) {
47+
for (uint32_t euID = 0; euID < numEuPerSubslice; euID++) {
5148

52-
for (uint32_t threadID = 0; threadID < numThreadsPerEu; threadID++) {
49+
for (uint32_t threadID = 0; threadID < numThreadsPerEu; threadID++) {
5350

54-
EuThread::ThreadId thread = {tileIndex, sliceID, subsliceID, euID, threadID};
51+
EuThread::ThreadId thread = {tileIndex, sliceID, subsliceID, euID, threadID};
5552

56-
allThreads[uint64_t(thread)] = std::make_unique<EuThread>(thread);
57-
}
53+
allThreads[uint64_t(thread)] = std::make_unique<EuThread>(thread);
5854
}
5955
}
6056
}
57+
}
6158

62-
if (isSubDevice || subDeviceCount == 1) {
63-
break;
64-
}
59+
if (isSubDevice || subDeviceCount == 1) {
60+
break;
6561
}
6662
}
6763
}

level_zero/tools/source/debug/debug_session_imp.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ struct DebugSessionImp : DebugSession {
3434

3535
DebugSessionImp(const zet_debug_config_t &config, Device *device) : DebugSession(config, device) {
3636
tileAttachEnabled = NEO::DebugManager.flags.ExperimentalEnableTileAttach.get();
37-
createEuThreads();
3837
}
3938

4039
ze_result_t interrupt(ze_device_thread_t thread) override;
@@ -48,6 +47,12 @@ struct DebugSessionImp : DebugSession {
4847
void detachTileDebugSession(DebugSession *tileSession) override;
4948
bool areAllTileDebugSessionDetached() override;
5049

50+
void setAttachMode(bool isRootAttach) override {
51+
if (isRootAttach) {
52+
tileAttachEnabled = false;
53+
}
54+
}
55+
5156
virtual void attachTile() = 0;
5257
virtual void detachTile() = 0;
5358
virtual void cleanRootSessionAfterDetach(uint32_t deviceIndex) = 0;

level_zero/tools/source/debug/linux/debug_session.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace L0 {
1313

14-
DebugSession *DebugSession::create(const zet_debug_config_t &config, Device *device, ze_result_t &result) {
14+
DebugSession *DebugSession::create(const zet_debug_config_t &config, Device *device, ze_result_t &result, bool isRootAttach) {
1515
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
1616
return nullptr;
1717
}

level_zero/tools/source/debug/linux/prelim/debug_session.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ DebugSessionLinux::~DebugSessionLinux() {
5050
closeFd();
5151
}
5252

53-
DebugSession *DebugSession::create(const zet_debug_config_t &config, Device *device, ze_result_t &result) {
53+
DebugSession *DebugSession::create(const zet_debug_config_t &config, Device *device, ze_result_t &result, bool isRootAttach) {
5454
if (device->getOsInterface().isDebugAttachAvailable()) {
5555
struct prelim_drm_i915_debugger_open_param open = {};
5656
open.pid = config.pid;
@@ -62,6 +62,7 @@ DebugSession *DebugSession::create(const zet_debug_config_t &config, Device *dev
6262
open.pid, open.events, debugFd);
6363

6464
auto debugSession = createDebugSessionHelper(config, device, debugFd);
65+
debugSession->setAttachMode(isRootAttach);
6566
result = debugSession->initialize();
6667

6768
if (result != ZE_RESULT_SUCCESS) {
@@ -245,6 +246,10 @@ ze_result_t DebugSessionLinux::initialize() {
245246
return ZE_RESULT_NOT_READY;
246247
}
247248

249+
bool isRootDevice = !connectedDevice->getNEODevice()->isSubDevice();
250+
if (isRootDevice && !tileAttachEnabled) {
251+
createEuThreads();
252+
}
248253
createTileSessionsIfEnabled();
249254
startInternalEventsThread();
250255

@@ -292,7 +297,9 @@ void DebugSessionLinux::createTileSessionsIfEnabled() {
292297
}
293298

294299
TileDebugSessionLinux *DebugSessionLinux::createTileSession(const zet_debug_config_t &config, Device *device, DebugSessionImp *rootDebugSession) {
295-
return new TileDebugSessionLinux(config, device, rootDebugSession);
300+
auto tileSession = new TileDebugSessionLinux(config, device, rootDebugSession);
301+
tileSession->initialize();
302+
return tileSession;
296303
}
297304

298305
void *DebugSessionLinux::asyncThreadFunction(void *arg) {

0 commit comments

Comments
 (0)