|
| 1 | +/* |
| 2 | + * Copyright (C) 2021 Intel Corporation |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: MIT |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +#include "shared/test/common/helpers/default_hw_info.h" |
| 9 | +#include "shared/test/common/mocks/mock_device.h" |
| 10 | + |
| 11 | +#include "test.h" |
| 12 | + |
| 13 | +#include "level_zero/core/source/device/device_imp.h" |
| 14 | +#include "level_zero/core/test/unit_tests/mock.h" |
| 15 | +#include "level_zero/core/test/unit_tests/mocks/mock_device.h" |
| 16 | +#include "level_zero/tools/test/unit_tests/sources/debug/mock_debug_session.h" |
| 17 | + |
| 18 | +namespace L0 { |
| 19 | +namespace ult { |
| 20 | + |
| 21 | +TEST(RootDebugSession, givenSingleThreadWhenGettingSingleThreadsThenCorrectThreadIsReturned) { |
| 22 | + zet_debug_config_t config = {}; |
| 23 | + config.pid = 0x1234; |
| 24 | + |
| 25 | + auto hwInfo = *NEO::defaultHwInfo.get(); |
| 26 | + NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0)); |
| 27 | + Mock<L0::DeviceImp> deviceImp(neoDevice, neoDevice->getExecutionEnvironment()); |
| 28 | + auto debugSession = std::make_unique<DebugSessionMock>(config, &deviceImp); |
| 29 | + |
| 30 | + auto subslice = hwInfo.gtSystemInfo.MaxSubSlicesSupported / hwInfo.gtSystemInfo.MaxSlicesSupported - 1; |
| 31 | + ze_device_thread_t physicalThread = {0, subslice, 2, 3}; |
| 32 | + |
| 33 | + auto threads = debugSession->getSingleThreads(physicalThread, hwInfo); |
| 34 | + |
| 35 | + EXPECT_EQ(1u, threads.size()); |
| 36 | + EXPECT_EQ(0u, threads[0].slice); |
| 37 | + EXPECT_EQ(subslice, threads[0].subslice); |
| 38 | + EXPECT_EQ(2u, threads[0].eu); |
| 39 | + EXPECT_EQ(3u, threads[0].thread); |
| 40 | +} |
| 41 | + |
| 42 | +TEST(RootDebugSession, givenAllThreadsWhenGettingSingleThreadsThenCorrectThreadsAreReturned) { |
| 43 | + zet_debug_config_t config = {}; |
| 44 | + config.pid = 0x1234; |
| 45 | + |
| 46 | + auto hwInfo = *NEO::defaultHwInfo.get(); |
| 47 | + NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0)); |
| 48 | + Mock<L0::DeviceImp> deviceImp(neoDevice, neoDevice->getExecutionEnvironment()); |
| 49 | + auto debugSession = std::make_unique<DebugSessionMock>(config, &deviceImp); |
| 50 | + |
| 51 | + auto subslice = hwInfo.gtSystemInfo.MaxSubSlicesSupported / hwInfo.gtSystemInfo.MaxSlicesSupported - 1; |
| 52 | + ze_device_thread_t physicalThread = {0, subslice, 2, UINT32_MAX}; |
| 53 | + const uint32_t numThreadsPerEu = (hwInfo.gtSystemInfo.ThreadCount / hwInfo.gtSystemInfo.EUCount); |
| 54 | + |
| 55 | + auto threads = debugSession->getSingleThreads(physicalThread, hwInfo); |
| 56 | + |
| 57 | + EXPECT_EQ(numThreadsPerEu, threads.size()); |
| 58 | + |
| 59 | + for (uint32_t i = 0; i < numThreadsPerEu; i++) { |
| 60 | + EXPECT_EQ(0u, threads[i].slice); |
| 61 | + EXPECT_EQ(subslice, threads[i].subslice); |
| 62 | + EXPECT_EQ(2u, threads[i].eu); |
| 63 | + EXPECT_EQ(i, threads[i].thread); |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +TEST(RootDebugSession, givenAllEUsWhenGettingSingleThreadsThenCorrectThreadsAreReturned) { |
| 68 | + zet_debug_config_t config = {}; |
| 69 | + config.pid = 0x1234; |
| 70 | + |
| 71 | + auto hwInfo = *NEO::defaultHwInfo.get(); |
| 72 | + NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0)); |
| 73 | + Mock<L0::DeviceImp> deviceImp(neoDevice, neoDevice->getExecutionEnvironment()); |
| 74 | + auto debugSession = std::make_unique<DebugSessionMock>(config, &deviceImp); |
| 75 | + |
| 76 | + auto subslice = hwInfo.gtSystemInfo.MaxSubSlicesSupported / hwInfo.gtSystemInfo.MaxSlicesSupported - 1; |
| 77 | + ze_device_thread_t physicalThread = {0, subslice, UINT32_MAX, 0}; |
| 78 | + const uint32_t numEuPerSubslice = hwInfo.gtSystemInfo.MaxEuPerSubSlice; |
| 79 | + |
| 80 | + auto threads = debugSession->getSingleThreads(physicalThread, hwInfo); |
| 81 | + |
| 82 | + EXPECT_EQ(numEuPerSubslice, threads.size()); |
| 83 | + |
| 84 | + for (uint32_t i = 0; i < numEuPerSubslice; i++) { |
| 85 | + EXPECT_EQ(0u, threads[i].slice); |
| 86 | + EXPECT_EQ(subslice, threads[i].subslice); |
| 87 | + EXPECT_EQ(i, threads[i].eu); |
| 88 | + EXPECT_EQ(0u, threads[i].thread); |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +TEST(RootDebugSession, givenAllSubslicesWhenGettingSingleThreadsThenCorrectThreadsAreReturned) { |
| 93 | + zet_debug_config_t config = {}; |
| 94 | + config.pid = 0x1234; |
| 95 | + |
| 96 | + auto hwInfo = *NEO::defaultHwInfo.get(); |
| 97 | + NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0)); |
| 98 | + Mock<L0::DeviceImp> deviceImp(neoDevice, neoDevice->getExecutionEnvironment()); |
| 99 | + auto debugSession = std::make_unique<DebugSessionMock>(config, &deviceImp); |
| 100 | + |
| 101 | + ze_device_thread_t physicalThread = {0, UINT32_MAX, 0, 0}; |
| 102 | + const uint32_t numSubslicesPerSlice = hwInfo.gtSystemInfo.MaxSubSlicesSupported / hwInfo.gtSystemInfo.MaxSlicesSupported; |
| 103 | + |
| 104 | + auto threads = debugSession->getSingleThreads(physicalThread, hwInfo); |
| 105 | + |
| 106 | + EXPECT_EQ(numSubslicesPerSlice, threads.size()); |
| 107 | + |
| 108 | + for (uint32_t i = 0; i < numSubslicesPerSlice; i++) { |
| 109 | + EXPECT_EQ(0u, threads[i].slice); |
| 110 | + EXPECT_EQ(i, threads[i].subslice); |
| 111 | + EXPECT_EQ(0u, threads[i].eu); |
| 112 | + EXPECT_EQ(0u, threads[i].thread); |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +TEST(RootDebugSession, givenAllSlicesWhenGettingSingleThreadsThenCorrectThreadsAreReturned) { |
| 117 | + zet_debug_config_t config = {}; |
| 118 | + config.pid = 0x1234; |
| 119 | + |
| 120 | + auto hwInfo = *NEO::defaultHwInfo.get(); |
| 121 | + NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0)); |
| 122 | + Mock<L0::DeviceImp> deviceImp(neoDevice, neoDevice->getExecutionEnvironment()); |
| 123 | + auto debugSession = std::make_unique<DebugSessionMock>(config, &deviceImp); |
| 124 | + |
| 125 | + ze_device_thread_t physicalThread = {UINT32_MAX, 0, 0, 0}; |
| 126 | + const uint32_t numSlices = hwInfo.gtSystemInfo.MaxSlicesSupported; |
| 127 | + |
| 128 | + auto threads = debugSession->getSingleThreads(physicalThread, hwInfo); |
| 129 | + |
| 130 | + EXPECT_EQ(numSlices, threads.size()); |
| 131 | + |
| 132 | + for (uint32_t i = 0; i < numSlices; i++) { |
| 133 | + EXPECT_EQ(i, threads[i].slice); |
| 134 | + EXPECT_EQ(0u, threads[i].subslice); |
| 135 | + EXPECT_EQ(0u, threads[i].eu); |
| 136 | + EXPECT_EQ(0u, threads[i].thread); |
| 137 | + } |
| 138 | +} |
| 139 | + |
| 140 | +} // namespace ult |
| 141 | +} // namespace L0 |
0 commit comments