Skip to content

Commit 9f5b3ef

Browse files
L0: Add xe_hp_core unit tests
Signed-off-by: Bartosz Dunajski <[email protected]>
1 parent 566415a commit 9f5b3ef

File tree

8 files changed

+1032
-1
lines changed

8 files changed

+1032
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Copyright (C) 2021 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#
6+
7+
if(TESTS_XE_HP_CORE)
8+
target_sources(${TARGET_NAME} PRIVATE
9+
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
10+
${CMAKE_CURRENT_SOURCE_DIR}/enable_l0_mocks_xe_hp_core.cpp
11+
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_xe_hp_core.cpp
12+
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdqueue_debugger_xe_hp_core.cpp
13+
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdqueue_enqueuecommandlist_xe_hp_core.cpp
14+
${CMAKE_CURRENT_SOURCE_DIR}/test_device_xe_hp_core.cpp
15+
${CMAKE_CURRENT_SOURCE_DIR}/test_module_xe_hp_core.cpp
16+
)
17+
add_subdirectoriesL0(${CMAKE_CURRENT_SOURCE_DIR} "*")
18+
endif()
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+
8+
#include "level_zero/core/test/unit_tests/mocks/mock_l0_debugger.h"
9+
10+
namespace NEO {
11+
struct XeHpFamily;
12+
using GfxFamily = XeHpFamily;
13+
} // namespace NEO
14+
15+
namespace L0 {
16+
namespace ult {
17+
static MockDebuggerL0HwPopulateFactory<IGFX_XE_HP_CORE, NEO::GfxFamily> mockDebuggerXE_HP_CORE;
18+
}
19+
} // namespace L0

level_zero/core/test/unit_tests/xe_hp_core/test_cmdlist_xe_hp_core.cpp

Lines changed: 526 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/command_stream/linear_stream.h"
9+
#include "shared/source/gen_common/reg_configs_common.h"
10+
#include "shared/source/helpers/preamble.h"
11+
#include "shared/test/common/cmd_parse/gen_cmd_parse.h"
12+
13+
#include "test.h"
14+
15+
#include "level_zero/core/source/cmdqueue/cmdqueue_hw.h"
16+
#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h"
17+
#include "level_zero/core/test/unit_tests/sources/debugger/active_debugger_fixture.h"
18+
#include "level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h"
19+
#include <level_zero/ze_api.h>
20+
21+
namespace L0 {
22+
namespace ult {
23+
24+
using CommandQueueDebugCommandsForSldXeHP = Test<ActiveDebuggerFixture>;
25+
using CommandQueueDebugCommandsDebuggerL0XeHP = Test<L0DebuggerHwFixture>;
26+
27+
XEHPTEST_F(CommandQueueDebugCommandsForSldXeHP, givenSteppingA0OrBWhenGlobalSipIsUsedThenMmioIsRestoredAtTheEndOfCmdBuffer) {
28+
using MI_LOAD_REGISTER_IMM = typename FamilyType::MI_LOAD_REGISTER_IMM;
29+
ze_command_queue_desc_t queueDesc = {};
30+
ze_result_t returnValue;
31+
HwHelper &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
32+
33+
std::array<uint32_t, 2> revisions = {hwHelper.getHwRevIdFromStepping(REVID::REVISION_A0, hwInfo),
34+
hwHelper.getHwRevIdFromStepping(REVID::REVISION_B, hwInfo)};
35+
36+
for (auto revision : revisions) {
37+
hwInfo.platform.usRevId = revision;
38+
39+
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, deviceL0, device->getDefaultEngine().commandStreamReceiver, &queueDesc, false, false, returnValue));
40+
ASSERT_NE(nullptr, commandQueue->commandStream);
41+
42+
ze_command_list_handle_t commandLists[] = {
43+
CommandList::create(productFamily, deviceL0, NEO::EngineGroupType::RenderCompute, 0u, returnValue)->toHandle()};
44+
45+
uint32_t globalSipFound = 0;
46+
uint32_t debugModeFound = 0;
47+
uint32_t tdCtlFound = 0;
48+
std::vector<MI_LOAD_REGISTER_IMM *> globalSip;
49+
50+
for (uint32_t execCount = 0; execCount < 2; execCount++) {
51+
auto startPointer = ptrOffset(commandQueue->commandStream->getCpuBase(), commandQueue->commandStream->getUsed());
52+
auto usedSpaceBefore = commandQueue->commandStream->getUsed();
53+
54+
auto result = commandQueue->executeCommandLists(1, commandLists, nullptr, true);
55+
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
56+
commandQueue->synchronize(0);
57+
58+
auto usedSpaceAfter = commandQueue->commandStream->getUsed();
59+
EXPECT_GT(usedSpaceAfter, usedSpaceBefore);
60+
61+
GenCmdList cmdList;
62+
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(cmdList, startPointer, usedSpaceAfter - usedSpaceBefore));
63+
64+
auto miLoadImm = findAll<MI_LOAD_REGISTER_IMM *>(cmdList.begin(), cmdList.end());
65+
66+
for (size_t i = 0; i < miLoadImm.size(); i++) {
67+
MI_LOAD_REGISTER_IMM *miLoad = genCmdCast<MI_LOAD_REGISTER_IMM *>(*miLoadImm[i]);
68+
ASSERT_NE(nullptr, miLoad);
69+
70+
if (miLoad->getRegisterOffset() == GlobalSipRegister<FamilyType>::registerOffset) {
71+
globalSip.push_back(miLoad);
72+
globalSipFound++;
73+
} else if (miLoad->getRegisterOffset() == DebugModeRegisterOffset<FamilyType>::registerOffset) {
74+
debugModeFound++;
75+
} else if (miLoad->getRegisterOffset() == TdDebugControlRegisterOffset<FamilyType>::registerOffset) {
76+
tdCtlFound++;
77+
}
78+
}
79+
}
80+
81+
EXPECT_EQ(1u, debugModeFound);
82+
EXPECT_EQ(1u, tdCtlFound);
83+
84+
ASSERT_EQ(4u, globalSipFound);
85+
86+
auto sipAddress = globalSip[0]->getDataDword();
87+
auto sipAllocation = SipKernel::getSipKernel(*device).getSipAllocation();
88+
EXPECT_EQ(sipAllocation->getGpuAddressToPatch(), sipAddress & 0xfffffff8);
89+
90+
auto sipAddress2 = globalSip[1]->getDataDword();
91+
EXPECT_EQ(0u, sipAddress2);
92+
93+
auto sipAddress3 = globalSip[2]->getDataDword();
94+
EXPECT_EQ(sipAllocation->getGpuAddressToPatch(), sipAddress3 & 0xfffffff8);
95+
96+
auto sipAddress4 = globalSip[3]->getDataDword();
97+
EXPECT_EQ(0u, sipAddress4);
98+
99+
auto commandList = CommandList::fromHandle(commandLists[0]);
100+
commandList->destroy();
101+
102+
commandQueue->destroy();
103+
}
104+
}
105+
106+
XEHPTEST_F(CommandQueueDebugCommandsDebuggerL0XeHP, givenSteppingA0OrBWhenGlobalSipIsUsedThenMmioIsRestoredAtTheEndOfCmdBuffer) {
107+
using MI_LOAD_REGISTER_IMM = typename FamilyType::MI_LOAD_REGISTER_IMM;
108+
ze_command_queue_desc_t queueDesc = {};
109+
ze_result_t returnValue;
110+
HwHelper &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
111+
112+
std::array<uint32_t, 2> revisions = {hwHelper.getHwRevIdFromStepping(REVID::REVISION_A0, hwInfo),
113+
hwHelper.getHwRevIdFromStepping(REVID::REVISION_B, hwInfo)};
114+
115+
for (auto revision : revisions) {
116+
hwInfo.platform.usRevId = revision;
117+
118+
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false, false, returnValue));
119+
ASSERT_NE(nullptr, commandQueue->commandStream);
120+
121+
ze_command_list_handle_t commandLists[] = {
122+
CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue)->toHandle()};
123+
124+
uint32_t globalSipFound = 0;
125+
std::vector<MI_LOAD_REGISTER_IMM *> globalSip;
126+
127+
for (uint32_t execCount = 0; execCount < 2; execCount++) {
128+
auto startPointer = ptrOffset(commandQueue->commandStream->getCpuBase(), commandQueue->commandStream->getUsed());
129+
auto usedSpaceBefore = commandQueue->commandStream->getUsed();
130+
131+
auto result = commandQueue->executeCommandLists(1, commandLists, nullptr, true);
132+
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
133+
commandQueue->synchronize(0);
134+
135+
auto usedSpaceAfter = commandQueue->commandStream->getUsed();
136+
EXPECT_GT(usedSpaceAfter, usedSpaceBefore);
137+
138+
GenCmdList cmdList;
139+
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(cmdList, startPointer, usedSpaceAfter - usedSpaceBefore));
140+
141+
auto miLoadImm = findAll<MI_LOAD_REGISTER_IMM *>(cmdList.begin(), cmdList.end());
142+
143+
for (size_t i = 0; i < miLoadImm.size(); i++) {
144+
MI_LOAD_REGISTER_IMM *miLoad = genCmdCast<MI_LOAD_REGISTER_IMM *>(*miLoadImm[i]);
145+
ASSERT_NE(nullptr, miLoad);
146+
147+
if (miLoad->getRegisterOffset() == GlobalSipRegister<FamilyType>::registerOffset) {
148+
globalSip.push_back(miLoad);
149+
globalSipFound++;
150+
}
151+
}
152+
}
153+
154+
ASSERT_EQ(4u, globalSipFound);
155+
156+
auto sipAddress = globalSip[0]->getDataDword();
157+
auto sipAllocation = SipKernel::getSipKernel(*neoDevice).getSipAllocation();
158+
EXPECT_EQ(sipAllocation->getGpuAddressToPatch(), sipAddress & 0xfffffff8);
159+
160+
auto sipAddress2 = globalSip[1]->getDataDword();
161+
EXPECT_EQ(0u, sipAddress2);
162+
163+
auto sipAddress3 = globalSip[2]->getDataDword();
164+
EXPECT_EQ(sipAllocation->getGpuAddressToPatch(), sipAddress3 & 0xfffffff8);
165+
166+
auto sipAddress4 = globalSip[3]->getDataDword();
167+
EXPECT_EQ(0u, sipAddress4);
168+
169+
auto commandList = CommandList::fromHandle(commandLists[0]);
170+
commandList->destroy();
171+
172+
commandQueue->destroy();
173+
}
174+
}
175+
176+
} // namespace ult
177+
} // namespace L0
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/command_stream/linear_stream.h"
9+
#include "shared/source/memory_manager/graphics_allocation.h"
10+
#include "shared/test/common/cmd_parse/gen_cmd_parse.h"
11+
12+
#include "test.h"
13+
14+
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
15+
#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h"
16+
#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h"
17+
#include "level_zero/core/test/unit_tests/mocks/mock_device.h"
18+
#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h"
19+
#include <level_zero/ze_api.h>
20+
21+
#include "gtest/gtest.h"
22+
23+
namespace L0 {
24+
namespace ult {
25+
26+
using CommandQueueExecuteCommandListsXE_HP_CORE = Test<DeviceFixture>;
27+
28+
XE_HP_CORE_TEST_F(CommandQueueExecuteCommandListsXE_HP_CORE, WhenExecutingCmdListsThenPipelineSelectAndCfeStateAreAddedToCmdBuffer) {
29+
const ze_command_queue_desc_t desc = {};
30+
ze_result_t returnValue;
31+
auto commandQueue = whitebox_cast(CommandQueue::create(
32+
productFamily,
33+
device, neoDevice->getDefaultEngine().commandStreamReceiver, &desc, false, false, returnValue));
34+
ASSERT_NE(nullptr, commandQueue->commandStream);
35+
auto usedSpaceBefore = commandQueue->commandStream->getUsed();
36+
37+
ze_command_list_handle_t commandLists[] = {
38+
CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue)->toHandle()};
39+
uint32_t numCommandLists = sizeof(commandLists) / sizeof(commandLists[0]);
40+
auto result = commandQueue->executeCommandLists(numCommandLists, commandLists, nullptr, true);
41+
42+
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
43+
44+
auto usedSpaceAfter = commandQueue->commandStream->getUsed();
45+
ASSERT_GT(usedSpaceAfter, usedSpaceBefore);
46+
47+
GenCmdList cmdList;
48+
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
49+
cmdList, ptrOffset(commandQueue->commandStream->getCpuBase(), 0), usedSpaceAfter));
50+
51+
using CFE_STATE = typename FamilyType::CFE_STATE;
52+
auto itorCFE = find<CFE_STATE *>(cmdList.begin(), cmdList.end());
53+
ASSERT_NE(itorCFE, cmdList.end());
54+
55+
// Should have a PS before a CFE
56+
using PIPELINE_SELECT = typename FamilyType::PIPELINE_SELECT;
57+
auto itorPS = find<PIPELINE_SELECT *>(cmdList.begin(), itorCFE);
58+
ASSERT_NE(itorPS, itorCFE);
59+
{
60+
auto cmd = genCmdCast<PIPELINE_SELECT *>(*itorPS);
61+
EXPECT_EQ(cmd->getMaskBits() & 3u, 3u);
62+
EXPECT_EQ(cmd->getPipelineSelection(), PIPELINE_SELECT::PIPELINE_SELECTION_GPGPU);
63+
}
64+
65+
CommandList::fromHandle(commandLists[0])->destroy();
66+
commandQueue->destroy();
67+
}
68+
69+
XE_HP_CORE_TEST_F(CommandQueueExecuteCommandListsXE_HP_CORE, WhenExecutingCmdListsThenStateBaseAddressForGeneralStateBaseAddressIsNotAdded) {
70+
const ze_command_queue_desc_t desc = {};
71+
ze_result_t returnValue;
72+
auto commandQueue = whitebox_cast(CommandQueue::create(
73+
productFamily,
74+
device, neoDevice->getDefaultEngine().commandStreamReceiver, &desc, false, false, returnValue));
75+
ASSERT_NE(nullptr, commandQueue->commandStream);
76+
auto usedSpaceBefore = commandQueue->commandStream->getUsed();
77+
78+
ze_command_list_handle_t commandLists[] = {
79+
CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue)->toHandle()};
80+
uint32_t numCommandLists = sizeof(commandLists) / sizeof(commandLists[0]);
81+
auto result = commandQueue->executeCommandLists(numCommandLists, commandLists, nullptr, true);
82+
83+
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
84+
85+
auto usedSpaceAfter = commandQueue->commandStream->getUsed();
86+
ASSERT_GT(usedSpaceAfter, usedSpaceBefore);
87+
88+
GenCmdList cmdList;
89+
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
90+
cmdList, ptrOffset(commandQueue->commandStream->getCpuBase(), 0), usedSpaceAfter));
91+
using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
92+
93+
auto itorSba = find<STATE_BASE_ADDRESS *>(cmdList.begin(), cmdList.end());
94+
EXPECT_EQ(itorSba, cmdList.end());
95+
96+
CommandList::fromHandle(commandLists[0])->destroy();
97+
commandQueue->destroy();
98+
}
99+
100+
} // namespace ult
101+
} // namespace L0

0 commit comments

Comments
 (0)