Skip to content

Commit

Permalink
fix(zebin): fix module load/unload events while debugging
Browse files Browse the repository at this point in the history
- do not trigger incorrect / spurious events from internal modules
for debugger
- do not register Elf for internal modules

Related-To: NEO-7605

Signed-off-by: Mateusz Hoppe <[email protected]>

Source: ee499d6
  • Loading branch information
HoppeMateusz authored and Compute-Runtime-Automation committed Feb 10, 2023
1 parent 4e9c10e commit d9a4eee
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 117 deletions.
5 changes: 3 additions & 2 deletions level_zero/core/source/module/module_imp.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2022 Intel Corporation
* Copyright (C) 2020-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -613,6 +613,7 @@ ze_result_t ModuleImp::initialize(const ze_module_desc_t *desc, NEO::Device *neo
}

registerElfInDebuggerL0();

this->maxGroupSize = static_cast<uint32_t>(neoDevice->getDeviceInfo().maxWorkGroupSize);

checkIfPrivateMemoryPerDispatchIsNeeded();
Expand Down Expand Up @@ -1276,7 +1277,7 @@ ze_result_t ModuleImp::destroy() {
void ModuleImp::registerElfInDebuggerL0() {
auto debuggerL0 = device->getL0Debugger();

if (!debuggerL0) {
if (this->type != ModuleType::User || !debuggerL0) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2022 Intel Corporation
* Copyright (C) 2020-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -518,6 +518,48 @@ HWTEST_F(ModuleWithDebuggerL0Test, GivenDebugDataWithRelocationsWhenInitializing
EXPECT_EQ(reinterpret_cast<char *>(kernelInfo->kernelDescriptor.external.relocatedDebugData.get()), getMockDebuggerL0Hw<FamilyType>()->lastReceivedElf);
}

HWTEST_F(ModuleWithDebuggerL0Test, GivenBuiltinModuleWhenInitializingModuleThenModuleAndElfNOtificationsAreNotCalled) {
auto cip = new NEO::MockCompilerInterfaceCaptureBuildOptions();
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[device->getRootDeviceIndex()]->compilerInterface.reset(cip);

uint8_t binary[10];
ze_module_desc_t moduleDesc = {};
moduleDesc.format = ZE_MODULE_FORMAT_IL_SPIRV;
moduleDesc.pInputModule = binary;
moduleDesc.inputSize = 10;
ModuleBuildLog *moduleBuildLog = nullptr;

std::unique_ptr<MockModule> moduleMock = std::make_unique<MockModule>(device, moduleBuildLog, ModuleType::Builtin);
moduleMock->translationUnit = std::make_unique<MockModuleTranslationUnit>(device);

uint32_t kernelHeap = 0;
auto kernelInfo = new KernelInfo();
kernelInfo->heapInfo.KernelHeapSize = 1;
kernelInfo->heapInfo.pKernelHeap = &kernelHeap;

Mock<::L0::Kernel> kernelMock;
kernelMock.module = moduleMock.get();
kernelMock.immutableData.kernelInfo = kernelInfo;
kernelInfo->kernelDescriptor.payloadMappings.implicitArgs.systemThreadSurfaceAddress.bindful = 0;
moduleMock->kernelImmData = &kernelMock.immutableData;
moduleMock->translationUnit->programInfo.kernelInfos.push_back(kernelInfo);
kernelInfo->kernelDescriptor.external.debugData = std::make_unique<NEO::DebugData>();

auto debugData = MockElfEncoder<>::createRelocateableDebugDataElf();
kernelInfo->kernelDescriptor.external.debugData->vIsaSize = static_cast<uint32_t>(debugData.size());
kernelInfo->kernelDescriptor.external.debugData->vIsa = reinterpret_cast<char *>(debugData.data());
kernelInfo->kernelDescriptor.external.debugData->genIsa = nullptr;
kernelInfo->kernelDescriptor.external.debugData->genIsaSize = 0;

EXPECT_EQ(0u, getMockDebuggerL0Hw<FamilyType>()->registerElfCount);
EXPECT_EQ(moduleMock->initialize(&moduleDesc, neoDevice), ZE_RESULT_SUCCESS);
EXPECT_EQ(0u, getMockDebuggerL0Hw<FamilyType>()->registerElfAndLinkCount);
EXPECT_EQ(0u, getMockDebuggerL0Hw<FamilyType>()->notifyModuleCreateCount);

EXPECT_NE(nullptr, kernelInfo->kernelDescriptor.external.relocatedDebugData.get());
EXPECT_EQ(nullptr, getMockDebuggerL0Hw<FamilyType>()->lastReceivedElf);
}

HWTEST_F(ModuleWithDebuggerL0Test, GivenDebugDataWithoutRelocationsWhenInitializingModuleThenRegisterElfWithUnrelocatedElfAndModuleCreateNotified) {

auto cip = new NEO::MockCompilerInterfaceCaptureBuildOptions();
Expand Down
Loading

0 comments on commit d9a4eee

Please sign in to comment.