Debian Codegraph @

level_zero/tools/test/unit_tests/sources/debug/debug_session_thread_tests.cpp

raw
1 /*
2 * Copyright (C) 2021-2026 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #include "shared/source/helpers/gfx_core_helper.h"
9 #include "shared/test/common/helpers/default_hw_info.h"
10 #include "shared/test/common/helpers/gtest_helpers.h"
11 #include "shared/test/common/helpers/stream_capture.h"
12 #include "shared/test/common/mocks/mock_device.h"
13 #include "shared/test/common/mocks/ult_device_factory.h"
14 #include "shared/test/common/test_macros/test.h"
15
16 #include "level_zero/core/source/device/device.h"
17 #include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
18 #include "level_zero/core/test/unit_tests/mock.h"
19 #include "level_zero/core/test/unit_tests/mocks/mock_device.h"
20 #include "level_zero/tools/test/unit_tests/sources/debug/mock_debug_session.h"
21
22 namespace L0 {
23 namespace ult {
24
25 TEST(DebugSession, givenThreadWhenIsThreadAllCalledThenTrueReturnedOnlyForAllValuesEqualMax) {
26 ze_device_thread_t thread = {UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX};
27 EXPECT_TRUE(DebugSession::isThreadAll(thread));
28
29 thread = {0, UINT32_MAX, UINT32_MAX, UINT32_MAX};
30 EXPECT_FALSE(DebugSession::isThreadAll(thread));
31 thread = {UINT32_MAX, 0, UINT32_MAX, UINT32_MAX};
32 EXPECT_FALSE(DebugSession::isThreadAll(thread));
33 thread = {UINT32_MAX, UINT32_MAX, 0, UINT32_MAX};
34 EXPECT_FALSE(DebugSession::isThreadAll(thread));
35 thread = {UINT32_MAX, UINT32_MAX, UINT32_MAX, 0};
36 EXPECT_FALSE(DebugSession::isThreadAll(thread));
37 }
38
39 TEST(DebugSession, givenThreadWhenIsSingleThreadCalledThenTrueReturnedOnlyForNonMaxValues) {
40 ze_device_thread_t thread = {UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX};
41 EXPECT_FALSE(DebugSession::isSingleThread(thread));
42
43 thread = {0, UINT32_MAX, UINT32_MAX, UINT32_MAX};
44 EXPECT_FALSE(DebugSession::isSingleThread(thread));
45
46 thread = {UINT32_MAX, 0, UINT32_MAX, UINT32_MAX};
47 EXPECT_FALSE(DebugSession::isSingleThread(thread));
48
49 thread = {UINT32_MAX, UINT32_MAX, 0, UINT32_MAX};
50 EXPECT_FALSE(DebugSession::isSingleThread(thread));
51
52 thread = {UINT32_MAX, UINT32_MAX, UINT32_MAX, 0};
53 EXPECT_FALSE(DebugSession::isSingleThread(thread));
54
55 thread = {UINT32_MAX, UINT32_MAX, 0, 0};
56 EXPECT_FALSE(DebugSession::isSingleThread(thread));
57
58 thread = {UINT32_MAX, 0, 0, 0};
59 EXPECT_FALSE(DebugSession::isSingleThread(thread));
60
61 thread = {UINT32_MAX, 0, UINT32_MAX, 0};
62 EXPECT_FALSE(DebugSession::isSingleThread(thread));
63
64 thread = {0, UINT32_MAX, 0, UINT32_MAX};
65 EXPECT_FALSE(DebugSession::isSingleThread(thread));
66
67 thread = {UINT32_MAX, 0, 0, UINT32_MAX};
68 EXPECT_FALSE(DebugSession::isSingleThread(thread));
69
70 thread = {0, UINT32_MAX, UINT32_MAX, 0};
71 EXPECT_FALSE(DebugSession::isSingleThread(thread));
72
73 thread = {0, 0, UINT32_MAX, 0};
74 EXPECT_FALSE(DebugSession::isSingleThread(thread));
75
76 thread = {0, 0, 0, UINT32_MAX};
77 EXPECT_FALSE(DebugSession::isSingleThread(thread));
78
79 thread = {1, 2, 3, 0};
80 EXPECT_TRUE(DebugSession::isSingleThread(thread));
81 }
82
83 TEST(DebugSession, givenThreadsWhenAreThreadsEqualCalledThenTrueReturnedForEqualThreads) {
84 ze_device_thread_t thread = {UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX};
85 ze_device_thread_t thread2 = {UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX};
86
87 EXPECT_TRUE(DebugSession::areThreadsEqual(thread, thread2));
88
89 thread = {0, UINT32_MAX, UINT32_MAX, UINT32_MAX};
90 EXPECT_FALSE(DebugSession::areThreadsEqual(thread, thread2));
91 thread2 = {UINT32_MAX, 0, UINT32_MAX, UINT32_MAX};
92 EXPECT_FALSE(DebugSession::areThreadsEqual(thread, thread2));
93
94 thread = {1, 0, 0, 0};
95 thread2 = {1, 0, 0, UINT32_MAX};
96 EXPECT_FALSE(DebugSession::areThreadsEqual(thread, thread2));
97
98 thread2 = {1, 0, 1, 0};
99 EXPECT_FALSE(DebugSession::areThreadsEqual(thread, thread2));
100
101 thread2 = {1, 1, 0, 0};
102 EXPECT_FALSE(DebugSession::areThreadsEqual(thread, thread2));
103
104 thread2 = {0, 0, 0, 0};
105 EXPECT_FALSE(DebugSession::areThreadsEqual(thread, thread2));
106 {
107 ze_device_thread_t thread = {1, 1, 1, 1};
108 ze_device_thread_t thread2 = {1, 1, 1, 1};
109
110 EXPECT_TRUE(DebugSession::areThreadsEqual(thread, thread2));
111 }
112 }
113
114 TEST(DebugSession, givenThreadWhenCheckSingleThreadWithinDeviceThreadCalledThenTrueReturnedForMatchingThread) {
115 ze_device_thread_t thread = {0, 1, 2, 3};
116 ze_device_thread_t thread2 = {UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX};
117
118 EXPECT_TRUE(DebugSession::checkSingleThreadWithinDeviceThread(thread, thread2));
119
120 thread = {0, 1, 2, 3};
121 thread2 = {0, UINT32_MAX, UINT32_MAX, UINT32_MAX};
122
123 EXPECT_TRUE(DebugSession::checkSingleThreadWithinDeviceThread(thread, thread2));
124
125 thread = {0, 1, 2, 3};
126 thread2 = {0, 1, 2, 3};
127
128 EXPECT_TRUE(DebugSession::checkSingleThreadWithinDeviceThread(thread, thread2));
129
130 thread = {0, 1, 2, 3};
131 thread2 = {0, UINT32_MAX, UINT32_MAX, 4};
132
133 EXPECT_FALSE(DebugSession::checkSingleThreadWithinDeviceThread(thread, thread2));
134
135 thread = {0, 1, 2, 3};
136 thread2 = {0, 1, 2, 4};
137
138 EXPECT_FALSE(DebugSession::checkSingleThreadWithinDeviceThread(thread, thread2));
139
140 thread = {0, 1, 2, 3};
141 thread2 = {1, 1, 2, 3};
142
143 EXPECT_FALSE(DebugSession::checkSingleThreadWithinDeviceThread(thread, thread2));
144
145 thread = {0, 1, 2, 3};
146 thread2 = {0, 2, 2, 3};
147
148 EXPECT_FALSE(DebugSession::checkSingleThreadWithinDeviceThread(thread, thread2));
149
150 thread = {0, 1, 3, 3};
151 thread2 = {0, 1, 2, 3};
152
153 EXPECT_FALSE(DebugSession::checkSingleThreadWithinDeviceThread(thread, thread2));
154
155 thread = {0, 1, 3, 3};
156 thread2 = {UINT32_MAX, 0, 2, 3};
157
158 EXPECT_FALSE(DebugSession::checkSingleThreadWithinDeviceThread(thread, thread2));
159 }
160
161 TEST(DebugSession, givenSingleThreadWhenGettingSingleThreadsThenCorrectThreadIsReturned) {
162 zet_debug_config_t config = {};
163 config.pid = 0x1234;
164
165 auto hwInfo = *NEO::defaultHwInfo.get();
166 NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
167 MockDeviceImp mockDevice(neoDevice);
168 auto debugSession = std::make_unique<DebugSessionMock>(config, &mockDevice);
169
170 auto subslice = hwInfo.gtSystemInfo.MaxSubSlicesSupported / hwInfo.gtSystemInfo.MaxSlicesSupported - 1;
171 ze_device_thread_t physicalThread = {0, subslice, 2, 3};
172
173 auto threads = debugSession->getSingleThreadsForDevice(0, physicalThread, hwInfo);
174
175 EXPECT_EQ(1u, threads.size());
176
177 EXPECT_EQ(0u, threads[0].tileIndex);
178 EXPECT_EQ(0u, threads[0].slice);
179 EXPECT_EQ(subslice, threads[0].subslice);
180 EXPECT_EQ(2u, threads[0].eu);
181 EXPECT_EQ(3u, threads[0].thread);
182 }
183
184 TEST(DebugSession, givenAllThreadsWithLowSliceDisabledWhenGettingSingleThreadsThenCorrectThreadsAreReturned) {
185
186 zet_debug_config_t config = {};
187 config.pid = 0x1234;
188
189 auto hwInfo = *NEO::defaultHwInfo.get();
190 hwInfo.gtSystemInfo.MaxSlicesSupported = 2;
191 hwInfo.gtSystemInfo.IsDynamicallyPopulated = true;
192 for (auto &sliceInfo : hwInfo.gtSystemInfo.SliceInfo) {
193 sliceInfo.Enabled = false;
194 }
195 hwInfo.gtSystemInfo.SliceInfo[2].Enabled = true;
196 hwInfo.gtSystemInfo.SliceInfo[3].Enabled = true;
197
198 NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
199 MockDeviceImp mockDevice(neoDevice);
200 auto debugSession = std::make_unique<DebugSessionMock>(config, &mockDevice);
201
202 ze_device_thread_t physicalThread = {UINT32_MAX, 0, 0, 0};
203
204 auto threads = debugSession->getSingleThreadsForDevice(0, physicalThread, hwInfo);
205
206 EXPECT_EQ(2u, threads.size());
207
208 for (uint32_t i = 0; i < 2; i++) {
209 EXPECT_EQ(0u, threads[i].tileIndex);
210 EXPECT_EQ(i + 2, threads[i].slice);
211 EXPECT_EQ(0u, threads[i].subslice);
212 EXPECT_EQ(0u, threads[i].eu);
213 EXPECT_EQ(0u, threads[i].thread);
214 }
215 }
216
217 TEST(DebugSession, givenAllThreadsWhenGettingSingleThreadsThenCorrectThreadsAreReturned) {
218 zet_debug_config_t config = {};
219 config.pid = 0x1234;
220
221 auto hwInfo = *NEO::defaultHwInfo.get();
222 NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
223 MockDeviceImp mockDevice(neoDevice);
224 auto debugSession = std::make_unique<DebugSessionMock>(config, &mockDevice);
225
226 auto subslice = hwInfo.gtSystemInfo.MaxSubSlicesSupported / hwInfo.gtSystemInfo.MaxSlicesSupported - 1;
227 ze_device_thread_t physicalThread = {0, subslice, 2, UINT32_MAX};
228 const uint32_t numThreadsPerEu = hwInfo.gtSystemInfo.NumThreadsPerEu;
229
230 auto threads = debugSession->getSingleThreadsForDevice(0, physicalThread, hwInfo);
231
232 EXPECT_EQ(numThreadsPerEu, threads.size());
233
234 for (uint32_t i = 0; i < numThreadsPerEu; i++) {
235 EXPECT_EQ(0u, threads[i].tileIndex);
236 EXPECT_EQ(0u, threads[i].slice);
237 EXPECT_EQ(subslice, threads[i].subslice);
238 EXPECT_EQ(2u, threads[i].eu);
239 EXPECT_EQ(i, threads[i].thread);
240 }
241 }
242
243 TEST(DebugSession, givenAllEUsWhenGettingSingleThreadsThenCorrectThreadsAreReturned) {
244 zet_debug_config_t config = {};
245 config.pid = 0x1234;
246
247 auto hwInfo = *NEO::defaultHwInfo.get();
248 NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
249 MockDeviceImp mockDevice(neoDevice);
250 auto debugSession = std::make_unique<DebugSessionMock>(config, &mockDevice);
251
252 auto subslice = hwInfo.gtSystemInfo.MaxSubSlicesSupported / hwInfo.gtSystemInfo.MaxSlicesSupported - 1;
253 ze_device_thread_t physicalThread = {0, subslice, UINT32_MAX, 0};
254 const uint32_t numEuPerSubslice = hwInfo.gtSystemInfo.MaxEuPerSubSlice;
255
256 auto threads = debugSession->getSingleThreadsForDevice(0, physicalThread, hwInfo);
257
258 EXPECT_EQ(numEuPerSubslice, threads.size());
259
260 for (uint32_t i = 0; i < numEuPerSubslice; i++) {
261 EXPECT_EQ(0u, threads[i].slice);
262 EXPECT_EQ(subslice, threads[i].subslice);
263 EXPECT_EQ(i, threads[i].eu);
264 EXPECT_EQ(0u, threads[i].thread);
265 }
266 }
267
268 TEST(DebugSession, givenAllSubslicesWhenGettingSingleThreadsThenCorrectThreadsAreReturned) {
269 zet_debug_config_t config = {};
270 config.pid = 0x1234;
271
272 auto hwInfo = *NEO::defaultHwInfo.get();
273 NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
274 MockDeviceImp mockDevice(neoDevice);
275 auto debugSession = std::make_unique<DebugSessionMock>(config, &mockDevice);
276
277 ze_device_thread_t physicalThread = {0, UINT32_MAX, 0, 0};
278 const uint32_t numSubslicesPerSlice = hwInfo.gtSystemInfo.MaxSubSlicesSupported / hwInfo.gtSystemInfo.MaxSlicesSupported;
279
280 auto threads = debugSession->getSingleThreadsForDevice(0, physicalThread, hwInfo);
281
282 EXPECT_EQ(numSubslicesPerSlice, threads.size());
283
284 for (uint32_t i = 0; i < numSubslicesPerSlice; i++) {
285 EXPECT_EQ(0u, threads[i].slice);
286 EXPECT_EQ(i, threads[i].subslice);
287 EXPECT_EQ(0u, threads[i].eu);
288 EXPECT_EQ(0u, threads[i].thread);
289 }
290 }
291
292 TEST(DebugSession, givenAllSlicesWhenGettingSingleThreadsThenCorrectThreadsAreReturned) {
293 zet_debug_config_t config = {};
294 config.pid = 0x1234;
295
296 auto hwInfo = *NEO::defaultHwInfo.get();
297 NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
298 MockDeviceImp mockDevice(neoDevice);
299 auto debugSession = std::make_unique<DebugSessionMock>(config, &mockDevice);
300
301 ze_device_thread_t physicalThread = {UINT32_MAX, 0, 0, 0};
302 const uint32_t numSlices = neoDevice->getGfxCoreHelper().getHighestEnabledSlice(hwInfo);
303
304 auto threads = debugSession->getSingleThreadsForDevice(0, physicalThread, hwInfo);
305
306 EXPECT_EQ(numSlices, threads.size());
307
308 for (uint32_t i = 0; i < numSlices; i++) {
309 EXPECT_EQ(0u, threads[i].tileIndex);
310 EXPECT_EQ(i, threads[i].slice);
311 EXPECT_EQ(0u, threads[i].subslice);
312 EXPECT_EQ(0u, threads[i].eu);
313 EXPECT_EQ(0u, threads[i].thread);
314 }
315 }
316
317 TEST(DebugSession, givenBindlessSystemRoutineWhenQueryingIsBindlessThenTrueReturned) {
318 zet_debug_config_t config = {};
319 config.pid = 0x1234;
320
321 auto hwInfo = *NEO::defaultHwInfo.get();
322 NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
323 MockDeviceImp mockDevice(neoDevice);
324 auto debugSession = std::make_unique<DebugSessionMock>(config, &mockDevice);
325
326 debugSession->debugArea.reserved1 = 1u;
327
328 EXPECT_TRUE(debugSession->isBindlessSystemRoutine());
329 }
330
331 TEST(DebugSession, givenBindfulSystemRoutineWhenQueryingIsBindlessThenFalseReturned) {
332 zet_debug_config_t config = {};
333 config.pid = 0x1234;
334
335 auto hwInfo = *NEO::defaultHwInfo.get();
336 NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
337 MockDeviceImp mockDevice(neoDevice);
338 auto debugSession = std::make_unique<DebugSessionMock>(config, &mockDevice);
339
340 debugSession->debugArea.reserved1 = 0u;
341
342 EXPECT_FALSE(debugSession->isBindlessSystemRoutine());
343 }
344
345 TEST(DebugSession, givenApiThreadAndSingleTileWhenConvertingThenCorrectValuesReturned) {
346 auto hwInfo = *NEO::defaultHwInfo.get();
347 NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
348 MockDeviceImp mockDevice(neoDevice);
349 auto debugSession = std::make_unique<DebugSessionMock>(zet_debug_config_t{0x1234}, &mockDevice);
350
351 ze_device_thread_t thread = {hwInfo.gtSystemInfo.SliceCount - 1, hwInfo.gtSystemInfo.SubSliceCount - 1, 0, 0};
352
353 uint32_t deviceIndex = 0;
354
355 auto convertedThread = debugSession->convertToPhysicalWithinDevice(thread, deviceIndex);
356
357 EXPECT_EQ(0u, deviceIndex);
358 EXPECT_EQ(convertedThread.slice, thread.slice);
359 EXPECT_EQ(convertedThread.subslice, thread.subslice);
360 EXPECT_EQ(convertedThread.eu, thread.eu);
361 EXPECT_EQ(convertedThread.thread, thread.thread);
362
363 thread.slice = UINT32_MAX;
364 convertedThread = debugSession->convertToPhysicalWithinDevice(thread, deviceIndex);
365
366 EXPECT_EQ(0u, deviceIndex);
367 if (hwInfo.gtSystemInfo.SliceCount == 1) {
368 EXPECT_EQ(convertedThread.slice, 0u);
369 } else {
370 EXPECT_EQ(convertedThread.slice, thread.slice);
371 }
372 }
373
374 TEST(DebugSession, givenApiThreadAndSingleTileWhenGettingDeviceIndexThenCorrectIndexIsReturned) {
375 auto hwInfo = *NEO::defaultHwInfo.get();
376 NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
377 MockDeviceImp mockDevice(neoDevice);
378 auto debugSession = std::make_unique<DebugSessionMock>(zet_debug_config_t{0x1234}, &mockDevice);
379
380 ze_device_thread_t thread = {hwInfo.gtSystemInfo.SliceCount - 1, 0, 0, 0};
381
382 uint32_t deviceIndex = debugSession->getDeviceIndexFromApiThread(thread);
383 EXPECT_EQ(0u, deviceIndex);
384
385 thread.slice = UINT32_MAX;
386
387 deviceIndex = debugSession->getDeviceIndexFromApiThread(thread);
388 EXPECT_EQ(0u, deviceIndex);
389 }
390
391 TEST(DebugSession, givenAllStoppedThreadsWhenAreRequestedThreadsStoppedCalledThenTrueReturned) {
392 zet_debug_config_t config = {};
393 config.pid = 0x1234;
394 auto hwInfo = *NEO::defaultHwInfo.get();
395
396 NEO::MockDevice *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
397 MockDeviceImp mockDevice(neoDevice);
398
399 auto sessionMock = std::make_unique<DebugSessionMock>(config, &mockDevice);
400 sessionMock->initialize();
401 for (uint32_t i = 0; i < hwInfo.gtSystemInfo.NumThreadsPerEu; i++) {
402 EuThread::ThreadId thread(0, 0, 0, 0, i);
403 sessionMock->allThreads[thread]->stopThread(1u);
404 sessionMock->allThreads[thread]->reportAsStopped();
405 }
406
407 ze_device_thread_t apiThread = {0, 0, 0, UINT32_MAX};
408 EXPECT_TRUE(sessionMock->areRequestedThreadsStopped(apiThread));
409 }
410
411 TEST(DebugSession, givenSomeStoppedThreadsWhenAreRequestedThreadsStoppedCalledThenFalseReturned) {
412 zet_debug_config_t config = {};
413 config.pid = 0x1234;
414 auto hwInfo = *NEO::defaultHwInfo.get();
415
416 NEO::MockDevice *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
417 MockDeviceImp mockDevice(neoDevice);
418
419 auto sessionMock = std::make_unique<DebugSessionMock>(config, &mockDevice);
420 sessionMock->initialize();
421 for (uint32_t i = 0; i < hwInfo.gtSystemInfo.NumThreadsPerEu; i++) {
422 EuThread::ThreadId thread(0, 0, 0, 0, i);
423 if (i % 2) {
424 sessionMock->allThreads[thread]->stopThread(1u);
425 sessionMock->allThreads[thread]->reportAsStopped();
426 }
427 }
428
429 ze_device_thread_t apiThread = {0, 0, 0, UINT32_MAX};
430 EXPECT_FALSE(sessionMock->areRequestedThreadsStopped(apiThread));
431 }
432
433 TEST(DebugSession, givenApiThreadAndSingleTileWhenFillingDevicesThenVectorEntryIsSet) {
434 auto hwInfo = *NEO::defaultHwInfo.get();
435 NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
436 MockDeviceImp mockDevice(neoDevice);
437 auto debugSession = std::make_unique<DebugSessionMock>(zet_debug_config_t{0x1234}, &mockDevice);
438
439 ze_device_thread_t thread = {hwInfo.gtSystemInfo.SliceCount - 1, hwInfo.gtSystemInfo.SubSliceCount - 1, 0, 0};
440
441 std::vector<uint8_t> devices(1);
442 debugSession->fillDevicesFromThread(thread, devices);
443
444 EXPECT_EQ(1u, devices[0]);
445 }
446
447 TEST(DebugSession, givenDifferentCombinationsOfThreadsAndMemoryTypeCheckExpectedMemoryAccess) {
448 zet_debug_config_t config = {};
449 config.pid = 0x1234;
450 auto hwInfo = *NEO::defaultHwInfo.get();
451
452 NEO::MockDevice *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
453 MockDeviceImp mockDevice(neoDevice);
454
455 auto sessionMock = std::make_unique<DebugSessionMock>(config, &mockDevice);
456 sessionMock->initialize();
457 ze_device_thread_t thread = {UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX};
458 zet_debug_memory_space_desc_t desc;
459 desc.address = 0x1000;
460 desc.type = ZET_DEBUG_MEMORY_SPACE_TYPE_DEFAULT;
461
462 ze_result_t retVal = sessionMock->sanityMemAccessThreadCheck(thread, &desc);
463 EXPECT_EQ(ZE_RESULT_SUCCESS, retVal);
464
465 desc.type = ZET_DEBUG_MEMORY_SPACE_TYPE_SLM;
466
467 retVal = sessionMock->sanityMemAccessThreadCheck(thread, &desc);
468 EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, retVal);
469
470 thread = {1, 1, UINT32_MAX, UINT32_MAX};
471 retVal = sessionMock->sanityMemAccessThreadCheck(thread, &desc);
472 EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, retVal);
473
474 thread = {0, 0, 0, 1};
475 desc.type = ZET_DEBUG_MEMORY_SPACE_TYPE_DEFAULT;
476
477 retVal = sessionMock->sanityMemAccessThreadCheck(thread, &desc);
478 EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, retVal);
479
480 for (uint32_t i = 0; i < hwInfo.gtSystemInfo.NumThreadsPerEu; i++) {
481 EuThread::ThreadId thread(0, 0, 0, 0, i);
482 sessionMock->allThreads[thread]->stopThread(1u);
483 sessionMock->allThreads[thread]->reportAsStopped();
484 }
485
486 retVal = sessionMock->sanityMemAccessThreadCheck(thread, &desc);
487 EXPECT_EQ(ZE_RESULT_SUCCESS, retVal);
488 }
489
490 TEST(DebugSession, givenDifferentThreadsWhenGettingPerThreadScratchOffsetThenCorrectOffsetReturned) {
491 auto hwInfo = *NEO::defaultHwInfo.get();
492 NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
493 MockDeviceImp mockDevice(neoDevice);
494 auto debugSession = std::make_unique<DebugSessionMock>(zet_debug_config_t{0x1234}, &mockDevice);
495 auto &productHelper = neoDevice->getProductHelper();
496
497 const uint32_t multiplyFactor = productHelper.getThreadEuRatioForScratch(hwInfo) / 8u;
498 const uint32_t numThreadsPerEu = hwInfo.gtSystemInfo.NumThreadsPerEu * multiplyFactor;
499 EuThread::ThreadId thread0Eu0 = {0, 0, 0, 0, 0};
500 EuThread::ThreadId thread0Eu1 = {0, 0, 0, 1, 0};
501 EuThread::ThreadId thread2Subslice1 = {0, 0, 1, 0, 2};
502
503 const uint32_t ptss = 128;
504
505 auto size = debugSession->getPerThreadScratchOffset(ptss, thread0Eu0);
506 EXPECT_EQ(0u, size);
507
508 size = debugSession->getPerThreadScratchOffset(ptss, thread0Eu1);
509 EXPECT_EQ(ptss * numThreadsPerEu, size);
510
511 size = debugSession->getPerThreadScratchOffset(ptss, thread2Subslice1);
512 EXPECT_EQ(2 * ptss + ptss * hwInfo.gtSystemInfo.MaxEuPerSubSlice * numThreadsPerEu, size);
513 }
514
515 TEST(DebugSession, GivenLogsEnabledWhenPrintBitmaskCalledThenBitmaskIsPrinted) {
516 DebugManagerStateRestore restorer;
517 NEO::debugManager.flags.DebuggerLogBitmask.set(255);
518
519 StreamCapture capture;
520 capture.captureStdout();
521
522 uint64_t bitmask[2] = {0x404080808080, 0x1111ffff1111ffff};
523 DebugSession::printBitmask(reinterpret_cast<uint8_t *>(bitmask), sizeof(bitmask));
524
525 auto output = capture.getCapturedStdout();
526
527 EXPECT_TRUE(hasSubstr(output, std::string("\nINFO: Bitmask: ")));
528 EXPECT_TRUE(hasSubstr(output, std::string("[0] = 0x0000404080808080")));
529 EXPECT_TRUE(hasSubstr(output, std::string("[1] = 0x1111ffff1111ffff")));
530 }
531
532 TEST(DebugSession, GivenLogsDisabledWhenPrintBitmaskCalledThenBitmaskIsNotPrinted) {
533 DebugManagerStateRestore restorer;
534 NEO::debugManager.flags.DebuggerLogBitmask.set(0);
535
536 StreamCapture capture;
537 capture.captureStdout();
538
539 uint64_t bitmask[2] = {0x404080808080, 0x1111ffff1111ffff};
540 DebugSession::printBitmask(reinterpret_cast<uint8_t *>(bitmask), sizeof(bitmask));
541
542 auto output = capture.getCapturedStdout();
543
544 EXPECT_EQ(0u, output.size());
545 }
546
547 TEST(DebugSession, WhenConvertingThreadIdsThenDeviceFunctionsAreCalled) {
548
549 auto hwInfo = *NEO::defaultHwInfo.get();
550
551 NEO::MockDevice *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
552 MockDeviceImp mockDevice(neoDevice);
553
554 auto sessionMock = std::make_unique<DebugSessionMock>(zet_debug_config_t{0x1234}, &mockDevice);
555 ASSERT_NE(nullptr, sessionMock);
556
557 ze_device_thread_t thread = {0, 0, 0, 0};
558
559 auto threadID = sessionMock->convertToThreadId(thread);
560
561 EXPECT_EQ(0u, threadID.tileIndex);
562 EXPECT_EQ(0u, threadID.slice);
563 EXPECT_EQ(0u, threadID.subslice);
564 EXPECT_EQ(0u, threadID.eu);
565 EXPECT_EQ(0u, threadID.thread);
566
567 auto apiThread = sessionMock->convertToApi(threadID);
568
569 EXPECT_EQ(0u, apiThread.slice);
570 EXPECT_EQ(0u, apiThread.subslice);
571 EXPECT_EQ(0u, apiThread.eu);
572 EXPECT_EQ(0u, apiThread.thread);
573
574 uint32_t deviceIndex = 1;
575
576 auto physicalThread = sessionMock->convertToPhysicalWithinDevice(thread, deviceIndex);
577
578 EXPECT_EQ(1u, deviceIndex);
579 EXPECT_EQ(0u, physicalThread.slice);
580 EXPECT_EQ(0u, physicalThread.subslice);
581 EXPECT_EQ(0u, physicalThread.eu);
582 EXPECT_EQ(0u, physicalThread.thread);
583
584 thread.slice = UINT32_MAX;
585 physicalThread = sessionMock->convertToPhysicalWithinDevice(thread, deviceIndex);
586
587 EXPECT_EQ(1u, deviceIndex);
588 EXPECT_EQ(uint32_t(UINT32_MAX), physicalThread.slice);
589 EXPECT_EQ(0u, physicalThread.subslice);
590 EXPECT_EQ(0u, physicalThread.eu);
591 EXPECT_EQ(0u, physicalThread.thread);
592
593 thread.slice = 0;
594 thread.subslice = UINT32_MAX;
595 thread.eu = 1;
596 thread.thread = 3;
597 physicalThread = sessionMock->convertToPhysicalWithinDevice(thread, deviceIndex);
598
599 EXPECT_EQ(1u, deviceIndex);
600 EXPECT_EQ(0u, physicalThread.slice);
601 EXPECT_EQ(uint32_t(UINT32_MAX), physicalThread.subslice);
602 EXPECT_EQ(1u, physicalThread.eu);
603 EXPECT_EQ(3u, physicalThread.thread);
604 }
605
606 TEST(DebugSessionTest, WhenConvertingThreadIDsForDeviceWithSingleSliceThenSubsliceIsCorrectlyRemapped) {
607 auto hwInfo = *NEO::defaultHwInfo.get();
608 hwInfo.gtSystemInfo.SliceCount = 2;
609 hwInfo.gtSystemInfo.SubSliceCount = 8;
610
611 NEO::MockDevice *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
612 MockDeviceImp mockDevice(neoDevice);
613 auto sessionMock = std::make_unique<DebugSessionMock>(zet_debug_config_t{0x1234}, &mockDevice);
614 ASSERT_NE(nullptr, sessionMock);
615
616 // fuse off first slice
617 sessionMock->topologyMap[0].sliceIndices.erase(sessionMock->topologyMap[0].sliceIndices.begin());
618 hwInfo.gtSystemInfo.SliceCount = 1;
619 sessionMock->topologyMap[0].subsliceIndices.push_back(2);
620 sessionMock->topologyMap[0].subsliceIndices.push_back(3);
621
622 ze_device_thread_t thread = {UINT32_MAX, 1, 0, 0};
623 uint32_t deviceIndex = 0;
624
625 auto physicalThread = sessionMock->convertToPhysicalWithinDevice(thread, deviceIndex);
626
627 EXPECT_EQ(1u, physicalThread.slice);
628 EXPECT_EQ(3u, physicalThread.subslice);
629 EXPECT_EQ(0u, physicalThread.eu);
630 EXPECT_EQ(0u, physicalThread.thread);
631
632 thread.slice = 0;
633 physicalThread = sessionMock->convertToPhysicalWithinDevice(thread, deviceIndex);
634
635 EXPECT_EQ(1u, physicalThread.slice);
636 EXPECT_EQ(3u, physicalThread.subslice);
637 EXPECT_EQ(0u, physicalThread.eu);
638 EXPECT_EQ(0u, physicalThread.thread);
639 }
640
641 TEST(DebugSessionTest, WhenConvertingThreadIDsForDeviceWithMultipleSlicesThenSubsliceIsNotRemapped) {
642 auto hwInfo = *NEO::defaultHwInfo.get();
643
644 hwInfo.gtSystemInfo.SliceCount = 8;
645 hwInfo.gtSystemInfo.SubSliceCount = 8;
646
647 NEO::MockDevice *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
648 MockDeviceImp mockDevice(neoDevice);
649
650 auto sessionMock = std::make_unique<DebugSessionMock>(zet_debug_config_t{0x1234}, &mockDevice);
651 ASSERT_NE(nullptr, sessionMock);
652
653 // fuse off first slice
654 sessionMock->topologyMap[0].sliceIndices.erase(sessionMock->topologyMap[0].sliceIndices.begin());
655 hwInfo.gtSystemInfo.SliceCount = 7;
656
657 ze_device_thread_t thread = {UINT32_MAX, 1, 0, 0};
658 uint32_t deviceIndex = 0;
659
660 auto physicalThread = sessionMock->convertToPhysicalWithinDevice(thread, deviceIndex);
661
662 EXPECT_EQ(UINT32_MAX, physicalThread.slice);
663 EXPECT_EQ(thread.subslice, physicalThread.subslice);
664 EXPECT_EQ(0u, physicalThread.eu);
665 EXPECT_EQ(0u, physicalThread.thread);
666
667 thread.slice = 0;
668 physicalThread = sessionMock->convertToPhysicalWithinDevice(thread, deviceIndex);
669
670 EXPECT_EQ(1u, physicalThread.slice);
671 EXPECT_EQ(thread.subslice, physicalThread.subslice);
672 EXPECT_EQ(0u, physicalThread.eu);
673 EXPECT_EQ(0u, physicalThread.thread);
674 }
675
676 struct AffinityMaskMultipleSubdevices : MultipleDevicesWithCustomHwInfo {
677 void setUp() {
678 debugManager.flags.ZE_AFFINITY_MASK.set("0.0,0.1,0.3");
679 MultipleDevicesWithCustomHwInfo::numSubDevices = 4;
680 MultipleDevicesWithCustomHwInfo::setUp();
681 }
682
683 void tearDown() {
684 MultipleDevicesWithCustomHwInfo::tearDown();
685 }
686 DebugManagerStateRestore restorer;
687 };
688
689 using AffinityMaskMultipleSubdevicesTest = Test<AffinityMaskMultipleSubdevices>;
690
691 TEST_F(AffinityMaskMultipleSubdevicesTest, givenApiThreadAndMultipleTilesWhenConvertingToPhysicalThenCorrectValuesReturned) {
692
693 L0::Device *device = driverHandle->devices[0];
694 auto l0Device = static_cast<Device *>(device);
695
696 auto debugSession = std::make_unique<DebugSessionMock>(zet_debug_config_t{0x1234}, l0Device);
697 ASSERT_NE(nullptr, debugSession);
698
699 ze_device_thread_t thread = {2 * sliceCount - 1, 0, 0, 0};
700
701 uint32_t deviceIndex = debugSession->getDeviceIndexFromApiThread(thread);
702 EXPECT_EQ(1u, deviceIndex);
703
704 auto convertedThread = debugSession->convertToPhysicalWithinDevice(thread, deviceIndex);
705
706 EXPECT_EQ(1u, deviceIndex);
707 EXPECT_EQ(sliceCount - 1, convertedThread.slice);
708 EXPECT_EQ(thread.subslice, convertedThread.subslice);
709 EXPECT_EQ(thread.eu, convertedThread.eu);
710 EXPECT_EQ(thread.thread, convertedThread.thread);
711
712 thread = {3 * sliceCount - 1, 0, 0, 0};
713
714 deviceIndex = debugSession->getDeviceIndexFromApiThread(thread);
715 EXPECT_EQ(3u, deviceIndex);
716
717 convertedThread = debugSession->convertToPhysicalWithinDevice(thread, deviceIndex);
718
719 EXPECT_EQ(3u, deviceIndex);
720 EXPECT_EQ(sliceCount - 1, convertedThread.slice);
721 EXPECT_EQ(thread.subslice, convertedThread.subslice);
722 EXPECT_EQ(thread.eu, convertedThread.eu);
723 EXPECT_EQ(thread.thread, convertedThread.thread);
724
725 thread = {sliceCount - 1, 0, 0, 0};
726
727 deviceIndex = debugSession->getDeviceIndexFromApiThread(thread);
728 EXPECT_EQ(0u, deviceIndex);
729
730 convertedThread = debugSession->convertToPhysicalWithinDevice(thread, deviceIndex);
731
732 EXPECT_EQ(0u, deviceIndex);
733 EXPECT_EQ(sliceCount - 1, convertedThread.slice);
734 EXPECT_EQ(thread.subslice, convertedThread.subslice);
735 EXPECT_EQ(thread.eu, convertedThread.eu);
736 EXPECT_EQ(thread.thread, convertedThread.thread);
737
738 thread.slice = UINT32_MAX;
739 deviceIndex = debugSession->getDeviceIndexFromApiThread(thread);
740 EXPECT_EQ(UINT32_MAX, deviceIndex);
741 }
742
743 using DebugSessionMultiTile = Test<MultipleDevicesWithCustomHwInfo>;
744
745 TEST_F(DebugSessionMultiTile, givenApiThreadAndMultipleTilesWhenConvertingToPhysicalThenCorrectValueReturned) {
746 L0::Device *device = driverHandle->devices[0];
747
748 auto debugSession = std::make_unique<DebugSessionMock>(zet_debug_config_t{0x1234}, device);
749
750 ze_device_thread_t thread = {sliceCount * 2 - 1, 0, 0, 0};
751
752 uint32_t deviceIndex = debugSession->getDeviceIndexFromApiThread(thread);
753
754 auto convertedThread = debugSession->convertToPhysicalWithinDevice(thread, deviceIndex);
755
756 EXPECT_EQ(1u, deviceIndex);
757 EXPECT_EQ(sliceCount - 1, convertedThread.slice);
758 EXPECT_EQ(thread.subslice, convertedThread.subslice);
759 EXPECT_EQ(thread.eu, convertedThread.eu);
760 EXPECT_EQ(thread.thread, convertedThread.thread);
761
762 thread = {sliceCount - 1, 0, 0, 0};
763
764 deviceIndex = debugSession->getDeviceIndexFromApiThread(thread);
765 convertedThread = debugSession->convertToPhysicalWithinDevice(thread, deviceIndex);
766
767 EXPECT_EQ(0u, deviceIndex);
768 EXPECT_EQ(sliceCount - 1, convertedThread.slice);
769 EXPECT_EQ(thread.subslice, convertedThread.subslice);
770 EXPECT_EQ(thread.eu, convertedThread.eu);
771 EXPECT_EQ(thread.thread, convertedThread.thread);
772
773 thread.slice = UINT32_MAX;
774 deviceIndex = debugSession->getDeviceIndexFromApiThread(thread);
775 EXPECT_EQ(UINT32_MAX, deviceIndex);
776
777 deviceIndex = 0;
778 convertedThread = debugSession->convertToPhysicalWithinDevice(thread, deviceIndex);
779 EXPECT_EQ(convertedThread.slice, thread.slice);
780
781 deviceIndex = 1;
782 convertedThread = debugSession->convertToPhysicalWithinDevice(thread, deviceIndex);
783 EXPECT_EQ(convertedThread.slice, thread.slice);
784
785 L0::Device *l0Device = static_cast<Device *>(device);
786 debugSession = std::make_unique<DebugSessionMock>(zet_debug_config_t{0x1234}, l0Device->subDevices[1]);
787
788 thread = {sliceCount - 1, 0, 0, 0};
789 deviceIndex = debugSession->getDeviceIndexFromApiThread(thread);
790 convertedThread = debugSession->convertToPhysicalWithinDevice(thread, deviceIndex);
791 EXPECT_EQ(1u, deviceIndex);
792 EXPECT_EQ(sliceCount - 1, convertedThread.slice);
793 EXPECT_EQ(thread.subslice, convertedThread.subslice);
794 EXPECT_EQ(thread.eu, convertedThread.eu);
795 EXPECT_EQ(thread.thread, convertedThread.thread);
796 }
797
798 TEST_F(DebugSessionMultiTile, WhenConvertingToThreadIdAndBackThenCorrectThreadIdsAreReturned) {
799 L0::Device *device = driverHandle->devices[0];
800
801 auto debugSession = std::make_unique<DebugSessionMock>(zet_debug_config_t{0x1234}, device);
802
803 ze_device_thread_t thread = {sliceCount * 2 - 1, 0, 0, 0};
804
805 auto threadID = debugSession->convertToThreadId(thread);
806
807 EXPECT_EQ(1u, threadID.tileIndex);
808 EXPECT_EQ(sliceCount - 1, threadID.slice);
809 EXPECT_EQ(thread.subslice, threadID.subslice);
810 EXPECT_EQ(thread.eu, threadID.eu);
811 EXPECT_EQ(thread.thread, threadID.thread);
812
813 auto apiThread = debugSession->convertToApi(threadID);
814
815 EXPECT_EQ(thread.slice, apiThread.slice);
816 EXPECT_EQ(thread.subslice, apiThread.subslice);
817 EXPECT_EQ(thread.eu, apiThread.eu);
818 EXPECT_EQ(thread.thread, apiThread.thread);
819
820 L0::Device *l0Device = static_cast<Device *>(device);
821 debugSession = std::make_unique<DebugSessionMock>(zet_debug_config_t{0x1234}, l0Device->subDevices[1]);
822
823 thread = {sliceCount - 1, 0, 0, 0};
824
825 threadID = debugSession->convertToThreadId(thread);
826
827 EXPECT_EQ(1u, threadID.tileIndex);
828 EXPECT_EQ(sliceCount - 1, threadID.slice);
829 EXPECT_EQ(thread.subslice, threadID.subslice);
830 EXPECT_EQ(thread.eu, threadID.eu);
831 EXPECT_EQ(thread.thread, threadID.thread);
832
833 apiThread = debugSession->convertToApi(threadID);
834
835 EXPECT_EQ(thread.slice, apiThread.slice);
836 EXPECT_EQ(thread.subslice, apiThread.subslice);
837 EXPECT_EQ(thread.eu, apiThread.eu);
838 EXPECT_EQ(thread.thread, apiThread.thread);
839 }
840
841 TEST_F(DebugSessionMultiTile, givenApiThreadAndMultiTileWhenFillingDevicesThenVectorEntriesAreSet) {
842 L0::Device *device = driverHandle->devices[0];
843
844 auto debugSession = std::make_unique<DebugSessionMock>(zet_debug_config_t{0x1234}, device);
845
846 ze_device_thread_t thread = {UINT32_MAX, 0, 0, 0};
847
848 std::vector<uint8_t> devices(numSubDevices);
849 debugSession->fillDevicesFromThread(thread, devices);
850
851 EXPECT_EQ(1u, devices[0]);
852 EXPECT_EQ(1u, devices[1]);
853 }
854
855 TEST_F(DebugSessionMultiTile, givenApiThreadAndSingleTileWhenFillingDevicesThenVectorEntryIsSet) {
856 L0::Device *device = driverHandle->devices[0];
857
858 auto debugSession = std::make_unique<DebugSessionMock>(zet_debug_config_t{0x1234}, device);
859
860 ze_device_thread_t thread = {sliceCount * numSubDevices - 1, 0, 0, 0};
861
862 std::vector<uint8_t> devices(numSubDevices);
863 debugSession->fillDevicesFromThread(thread, devices);
864
865 EXPECT_EQ(0u, devices[0]);
866 EXPECT_EQ(1u, devices[1]);
867 }
868
869 TEST_F(DebugSessionMultiTile, givenApiThreadAndMultipleTilesWhenGettingDeviceIndexThenCorrectValueReturned) {
870 L0::Device *device = driverHandle->devices[0];
871 auto debugSession = std::make_unique<DebugSessionMock>(zet_debug_config_t{0x1234}, device);
872
873 ze_device_thread_t thread = {sliceCount * 2 - 1, 0, 0, 0};
874
875 uint32_t deviceIndex = debugSession->getDeviceIndexFromApiThread(thread);
876 EXPECT_EQ(1u, deviceIndex);
877
878 thread = {sliceCount - 1, 0, 0, 0};
879 deviceIndex = debugSession->getDeviceIndexFromApiThread(thread);
880 EXPECT_EQ(0u, deviceIndex);
881
882 thread.slice = UINT32_MAX;
883 deviceIndex = debugSession->getDeviceIndexFromApiThread(thread);
884 EXPECT_EQ(UINT32_MAX, deviceIndex);
885
886 L0::Device *l0Device = static_cast<Device *>(device);
887 debugSession = std::make_unique<DebugSessionMock>(zet_debug_config_t{0x1234}, l0Device->subDevices[0]);
888
889 thread = {sliceCount - 1, 0, 0, 0};
890 deviceIndex = debugSession->getDeviceIndexFromApiThread(thread);
891 EXPECT_EQ(0u, deviceIndex);
892
893 debugSession = std::make_unique<DebugSessionMock>(zet_debug_config_t{0x1234}, l0Device->subDevices[1]);
894
895 thread = {sliceCount - 1, 0, 0, 0};
896 deviceIndex = debugSession->getDeviceIndexFromApiThread(thread);
897 EXPECT_EQ(1u, deviceIndex);
898 }
899
900 } // namespace ult
901 } // namespace L0