Program debug commands for DebuggerL0

Related-To: NEO-4547, NEO-4549

Change-Id: Idf9139190a85aae7ec52de7a1899a46123809e63
Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2020-06-22 17:13:30 +02:00
committed by sys_ocldev
parent f5e9abae3d
commit 15b91c4d45
7 changed files with 179 additions and 9 deletions

View File

@@ -230,7 +230,8 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
residencyContainer.push_back(sipIsa);
}
if (neoDevice->isDebuggerActive()) {
if (neoDevice->getDebugger() &&
device->getDebugSurface() != nullptr) {
residencyContainer.push_back(device->getDebugSurface());
}
}

View File

@@ -9,6 +9,6 @@
namespace L0 {
bool DebuggerL0::isDebuggerActive() {
return false;
return true;
}
} // namespace L0

View File

@@ -639,7 +639,7 @@ Device *Device::create(DriverHandle *driverHandle, NEO::Device *neoDevice, uint3
device->neoDevice->getHardwareInfo().platform.eProductFamily, device, &cmdQueueDesc, true, false);
}
if (neoDevice->getDeviceInfo().debuggerActive) {
if (device->getSourceLevelDebugger()) {
auto osInterface = neoDevice->getRootDeviceEnvironment().osInterface.get();
device->getSourceLevelDebugger()
->notifyNewDevice(osInterface ? osInterface->getDeviceHandle() : 0);
@@ -659,7 +659,7 @@ DeviceImp::~DeviceImp() {
metricContext.reset();
builtins.reset();
if (neoDevice->getDeviceInfo().debuggerActive) {
if (getSourceLevelDebugger()) {
getSourceLevelDebugger()->notifyDeviceDestruction();
}

View File

@@ -9,6 +9,7 @@
#include "shared/test/unit_test/mocks/mock_device.h"
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
#include "level_zero/core/test/unit_tests/mocks/mock_l0_debugger.h"
namespace L0 {
@@ -16,7 +17,15 @@ namespace ult {
struct L0DebuggerFixture {
void SetUp() {
neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get());
auto executionEnvironment = new NEO::ExecutionEnvironment();
auto mockBuiltIns = new MockBuiltins();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
executionEnvironment->initializeMemoryManager();
neoDevice = NEO::MockDevice::create<NEO::MockDevice>(executionEnvironment, 0u);
NEO::DeviceVector devices;
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
@@ -38,6 +47,8 @@ struct MockL0DebuggerFixture : public L0DebuggerFixture {
void SetUp() {
L0DebuggerFixture::SetUp();
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[neoDevice->getRootDeviceIndex()]->debugger.reset(new MockDebuggerL0(neoDevice));
neoDevice->setDebuggerActive(true);
neoDevice->setPreemptionMode(PreemptionMode::Disabled);
}
void TearDown() {

View File

@@ -5,8 +5,13 @@
*
*/
#include "shared/source/command_stream/linear_stream.h"
#include "shared/source/gen_common/reg_configs/reg_configs_common.h"
#include "shared/test/unit_test/cmd_parse/gen_cmd_parse.h"
#include "test.h"
#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h"
#include "level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h"
namespace L0 {
@@ -22,8 +27,155 @@ TEST_F(L0DebuggerTest, givenL0DebuggerWhenGettingSourceLevelDebuggerThenNullptrR
EXPECT_EQ(nullptr, neoDevice->getSourceLevelDebugger());
}
TEST_F(L0DebuggerTest, givenL0DebuggerWhenCallingIsDebuggerActiveThenFalseIsReturned) {
EXPECT_FALSE(neoDevice->getDebugger()->isDebuggerActive());
TEST_F(L0DebuggerTest, givenL0DebuggerWhenCallingIsDebuggerActiveThenTrueIsReturned) {
EXPECT_TRUE(neoDevice->getDebugger()->isDebuggerActive());
}
HWTEST_F(L0DebuggerTest, givenDebuggingEnabledWhenCommandListIsExecutedThenKernelDebugCommandsAreAdded) {
using MI_LOAD_REGISTER_IMM = typename FamilyType::MI_LOAD_REGISTER_IMM;
using STATE_SIP = typename FamilyType::STATE_SIP;
ze_command_queue_desc_t queueDesc = {};
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false));
ASSERT_NE(nullptr, commandQueue->commandStream);
auto usedSpaceBefore = commandQueue->commandStream->getUsed();
ze_command_list_handle_t commandLists[] = {
CommandList::create(productFamily, device, false)->toHandle()};
uint32_t numCommandLists = sizeof(commandLists) / sizeof(commandLists[0]);
auto result = commandQueue->executeCommandLists(numCommandLists, commandLists, nullptr, true);
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
auto usedSpaceAfter = commandQueue->commandStream->getUsed();
ASSERT_GT(usedSpaceAfter, usedSpaceBefore);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
cmdList, ptrOffset(commandQueue->commandStream->getCpuBase(), 0), usedSpaceAfter));
auto miLoadImm = findAll<MI_LOAD_REGISTER_IMM *>(cmdList.begin(), cmdList.end());
ASSERT_LE(2u, miLoadImm.size());
size_t debugModeRegisterCount = 0;
size_t tdDebugControlRegisterCount = 0;
for (size_t i = 0; i < miLoadImm.size(); i++) {
MI_LOAD_REGISTER_IMM *miLoad = genCmdCast<MI_LOAD_REGISTER_IMM *>(*miLoadImm[i]);
ASSERT_NE(nullptr, miLoad);
if (miLoad->getRegisterOffset() == DebugModeRegisterOffset<FamilyType>::registerOffset) {
EXPECT_EQ(DebugModeRegisterOffset<FamilyType>::debugEnabledValue, miLoad->getDataDword());
debugModeRegisterCount++;
}
if (miLoad->getRegisterOffset() == TdDebugControlRegisterOffset::registerOffset) {
EXPECT_EQ(TdDebugControlRegisterOffset::debugEnabledValue, miLoad->getDataDword());
tdDebugControlRegisterCount++;
}
}
EXPECT_EQ(1u, debugModeRegisterCount);
EXPECT_EQ(1u, tdDebugControlRegisterCount);
auto stateSipCmds = findAll<STATE_SIP *>(cmdList.begin(), cmdList.end());
ASSERT_EQ(1u, stateSipCmds.size());
STATE_SIP *stateSip = genCmdCast<STATE_SIP *>(*stateSipCmds[0]);
auto systemRoutine = SipKernel::getSipKernelAllocation(*neoDevice);
ASSERT_NE(nullptr, systemRoutine);
EXPECT_EQ(systemRoutine->getGpuAddress(), stateSip->getSystemInstructionPointer());
for (auto i = 0u; i < numCommandLists; i++) {
auto commandList = CommandList::fromHandle(commandLists[i]);
commandList->destroy();
}
commandQueue->destroy();
}
HWTEST_F(L0DebuggerTest, givenDebuggingEnabledWhenCommandListIsExecutedTwiceThenKernelDebugCommandsAreAddedOnlyOnce) {
using MI_LOAD_REGISTER_IMM = typename FamilyType::MI_LOAD_REGISTER_IMM;
using STATE_SIP = typename FamilyType::STATE_SIP;
ze_command_queue_desc_t queueDesc = {};
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false));
ASSERT_NE(nullptr, commandQueue->commandStream);
auto usedSpaceBefore = commandQueue->commandStream->getUsed();
ze_command_list_handle_t commandLists[] = {
CommandList::create(productFamily, device, false)->toHandle()};
uint32_t numCommandLists = sizeof(commandLists) / sizeof(commandLists[0]);
auto result = commandQueue->executeCommandLists(numCommandLists, commandLists, nullptr, true);
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
auto usedSpaceAfter = commandQueue->commandStream->getUsed();
ASSERT_GT(usedSpaceAfter, usedSpaceBefore);
size_t debugModeRegisterCount = 0;
size_t tdDebugControlRegisterCount = 0;
{
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
cmdList, ptrOffset(commandQueue->commandStream->getCpuBase(), 0), usedSpaceAfter));
auto miLoadImm = findAll<MI_LOAD_REGISTER_IMM *>(cmdList.begin(), cmdList.end());
for (size_t i = 0; i < miLoadImm.size(); i++) {
MI_LOAD_REGISTER_IMM *miLoad = genCmdCast<MI_LOAD_REGISTER_IMM *>(*miLoadImm[i]);
ASSERT_NE(nullptr, miLoad);
if (miLoad->getRegisterOffset() == DebugModeRegisterOffset<FamilyType>::registerOffset) {
EXPECT_EQ(DebugModeRegisterOffset<FamilyType>::debugEnabledValue, miLoad->getDataDword());
debugModeRegisterCount++;
}
if (miLoad->getRegisterOffset() == TdDebugControlRegisterOffset::registerOffset) {
EXPECT_EQ(TdDebugControlRegisterOffset::debugEnabledValue, miLoad->getDataDword());
tdDebugControlRegisterCount++;
}
}
EXPECT_EQ(1u, debugModeRegisterCount);
EXPECT_EQ(1u, tdDebugControlRegisterCount);
}
result = commandQueue->executeCommandLists(numCommandLists, commandLists, nullptr, true);
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
auto usedSpaceAfter2 = commandQueue->commandStream->getUsed();
ASSERT_GT(usedSpaceAfter2, usedSpaceAfter);
{
GenCmdList cmdList2;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
cmdList2, ptrOffset(commandQueue->commandStream->getCpuBase(), usedSpaceAfter), usedSpaceAfter2 - usedSpaceAfter));
auto miLoadImm2 = findAll<MI_LOAD_REGISTER_IMM *>(cmdList2.begin(), cmdList2.end());
for (size_t i = 0; i < miLoadImm2.size(); i++) {
MI_LOAD_REGISTER_IMM *miLoad = genCmdCast<MI_LOAD_REGISTER_IMM *>(*miLoadImm2[i]);
ASSERT_NE(nullptr, miLoad);
if (miLoad->getRegisterOffset() == DebugModeRegisterOffset<FamilyType>::registerOffset) {
debugModeRegisterCount++;
}
if (miLoad->getRegisterOffset() == TdDebugControlRegisterOffset::registerOffset) {
tdDebugControlRegisterCount++;
}
}
EXPECT_EQ(1u, debugModeRegisterCount);
EXPECT_EQ(1u, tdDebugControlRegisterCount);
}
for (auto i = 0u; i < numCommandLists; i++) {
auto commandList = CommandList::fromHandle(commandLists[i]);
commandList->destroy();
}
commandQueue->destroy();
}
} // namespace ult