Skip to content

Commit 13947f3

Browse files
L0 Debugger minor fixes
- Do not make Builtin kernel allocations resident in Module::initialize() - Notify debugger with all segment allocations in module - refactoring: extract logic to dedicated methods Signed-off-by: Mateusz Hoppe <[email protected]>
1 parent c4362c1 commit 13947f3

File tree

8 files changed

+100
-12
lines changed

8 files changed

+100
-12
lines changed

level_zero/core/source/debugger/debugger_l0.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,13 @@ void DebuggerL0::captureStateBaseAddress(NEO::CommandContainer &container, SbaAd
123123
programSbaTrackingCommands(*container.getCommandStream(), sba);
124124
}
125125
}
126+
127+
void DebuggerL0::notifyModuleLoadAllocations(const StackVec<NEO::GraphicsAllocation *, 32> &allocs) {
128+
NEO::MemoryOperationsHandler *memoryOperationsIface = device->getRootDeviceEnvironment().memoryOperationsInterface.get();
129+
if (memoryOperationsIface) {
130+
for (auto gfxAlloc : allocs) {
131+
memoryOperationsIface->makeResident(device, ArrayRef<NEO::GraphicsAllocation *>(&gfxAlloc, 1));
132+
}
133+
}
134+
}
126135
} // namespace L0

level_zero/core/source/debugger/debugger_l0.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class DebuggerL0 : public NEO::Debugger, NEO::NonCopyableOrMovableClass {
9797
MOCKABLE_VIRTUAL void registerElf(NEO::DebugData *debugData, NEO::GraphicsAllocation *isaAllocation);
9898
MOCKABLE_VIRTUAL void notifyCommandQueueCreated();
9999
MOCKABLE_VIRTUAL void notifyCommandQueueDestroyed();
100+
MOCKABLE_VIRTUAL void notifyModuleLoadAllocations(const StackVec<NEO::GraphicsAllocation *, 32> &allocs);
100101

101102
virtual size_t getSbaTrackingCommandsSize(size_t trackedAddressCount) = 0;
102103
virtual void programSbaTrackingCommands(NEO::LinearStream &cmdStream, const SbaAddresses &sba) = 0;

level_zero/core/source/module/module_imp.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -556,25 +556,22 @@ bool ModuleImp::initialize(const ze_module_desc_t *desc, NEO::Device *neoDevice)
556556
auto &hwInfo = neoDevice->getHardwareInfo();
557557
auto &hwHelper = NEO::HwHelper::get(hwInfo.platform.eRenderCoreFamily);
558558

559-
if (this->isFullyLinked) {
559+
if (this->isFullyLinked && this->type == ModuleType::User) {
560560
for (auto &ki : kernelImmDatas) {
561561

562-
if (this->type == ModuleType::User && !ki->isIsaCopiedToAllocation()) {
562+
if (!ki->isIsaCopiedToAllocation()) {
563563

564564
NEO::MemoryTransferHelper::transferMemoryToAllocation(hwHelper.isBlitCopyRequiredForLocalMemory(hwInfo, *ki->getIsaGraphicsAllocation()),
565565
*neoDevice, ki->getIsaGraphicsAllocation(), 0, ki->getKernelInfo()->heapInfo.pKernelHeap,
566566
static_cast<size_t>(ki->getKernelInfo()->heapInfo.KernelHeapSize));
567567

568568
ki->setIsaCopiedToAllocation();
569569
}
570+
}
570571

571-
if (device->getL0Debugger()) {
572-
NEO::MemoryOperationsHandler *memoryOperationsIface = neoDevice->getRootDeviceEnvironment().memoryOperationsInterface.get();
573-
if (memoryOperationsIface) {
574-
auto allocation = ki->getIsaGraphicsAllocation();
575-
memoryOperationsIface->makeResident(neoDevice, ArrayRef<NEO::GraphicsAllocation *>(&allocation, 1));
576-
}
577-
}
572+
if (device->getL0Debugger()) {
573+
auto allocs = getModuleAllocations();
574+
device->getL0Debugger()->notifyModuleLoadAllocations(allocs);
578575
}
579576
}
580577
return success;
@@ -1158,6 +1155,23 @@ void ModuleImp::registerElfInDebuggerL0() {
11581155
}
11591156
}
11601157

1158+
StackVec<NEO::GraphicsAllocation *, 32> ModuleImp::getModuleAllocations() {
1159+
StackVec<NEO::GraphicsAllocation *, 32> allocs;
1160+
for (auto &kernImmData : kernelImmDatas) {
1161+
allocs.push_back(kernImmData->getIsaGraphicsAllocation());
1162+
}
1163+
1164+
if (translationUnit) {
1165+
if (translationUnit->globalVarBuffer) {
1166+
allocs.push_back(translationUnit->globalVarBuffer);
1167+
}
1168+
if (translationUnit->globalConstBuffer) {
1169+
allocs.push_back(translationUnit->globalConstBuffer);
1170+
}
1171+
}
1172+
return allocs;
1173+
}
1174+
11611175
bool moveBuildOption(std::string &dstOptionsSet, std::string &srcOptionSet, NEO::ConstStringRef dstOptionName, NEO::ConstStringRef srcOptionName) {
11621176
const char optDelim = ' ';
11631177
const char valDelim = '=';

level_zero/core/source/module/module_imp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ struct ModuleImp : public Module {
151151
void createDebugZebin();
152152
void registerElfInDebuggerL0();
153153
bool populateHostGlobalSymbolsMap(std::unordered_map<std::string, std::string> &devToHostNameMapping);
154+
StackVec<NEO::GraphicsAllocation *, 32> getModuleAllocations();
154155

155156
Device *device = nullptr;
156157
PRODUCT_FAMILY productFamily{};

level_zero/core/test/unit_tests/mocks/mock_module.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct MockModuleTranslationUnit : public L0::ModuleTranslationUnit {
7575
struct MockModule : public L0::ModuleImp {
7676
using ModuleImp::debugEnabled;
7777
using ModuleImp::debugModuleHandle;
78+
using ModuleImp::getModuleAllocations;
7879
using ModuleImp::kernelImmDatas;
7980
using ModuleImp::populateHostGlobalSymbolsMap;
8081
using ModuleImp::symbols;

level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger_1.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,18 @@ HWTEST_F(L0DebuggerSimpleTest, givenChangedBaseAddressesWhenCapturingSBAThenNoTr
10811081
}
10821082
}
10831083

1084+
HWTEST_F(L0DebuggerSimpleTest, givenDebuggerWithoutMemoryOperationsHandlerWhenNotifyingModuleAllocationsThenNoAllocationIsResident) {
1085+
auto debugger = std::make_unique<MockDebuggerL0Hw<FamilyType>>(neoDevice);
1086+
1087+
StackVec<NEO::GraphicsAllocation *, 32> allocs;
1088+
NEO::GraphicsAllocation alloc(0, NEO::AllocationType::INTERNAL_HOST_MEMORY,
1089+
reinterpret_cast<void *>(0x1234), 0x1000, 0, sizeof(uint32_t),
1090+
MemoryPool::System4KBPages);
1091+
allocs.push_back(&alloc);
1092+
1093+
debugger->notifyModuleLoadAllocations(allocs);
1094+
}
1095+
10841096
HWTEST_F(L0DebuggerTest, givenDebuggerWhenCreatedThenModuleHeapDebugAreaIsCreated) {
10851097
auto mockBlitMemoryToAllocation = [](const NEO::Device &device, NEO::GraphicsAllocation *memory, size_t offset, const void *hostPtr,
10861098
Vec3<size_t> size) -> NEO::BlitOperationResult {

level_zero/core/test/unit_tests/sources/debugger/test_module_with_debug.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ HWTEST_F(ModuleWithZebinAndL0DebuggerTest, GivenModuleDebugHandleZeroWhenInitial
689689

690690
using NotifyModuleLoadTest = Test<ModuleFixture>;
691691

692-
HWTEST_F(NotifyModuleLoadTest, givenDebuggingEnabledWhenModuleIsCreatedAndFullyLinkedThenIsaAllocationsAreCopiedAndResident) {
692+
HWTEST_F(NotifyModuleLoadTest, givenDebuggingEnabledWhenModuleIsCreatedAndFullyLinkedThenIsaAllocationsAreCopiedAndResidentOnlyForUserModules) {
693693
NEO::MockCompilerEnableGuard mock(true);
694694
auto cip = new NEO::MockCompilerInterfaceCaptureBuildOptions();
695695
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[neoDevice->getRootDeviceIndex()]->compilerInterface.reset(cip);
@@ -715,20 +715,33 @@ HWTEST_F(NotifyModuleLoadTest, givenDebuggingEnabledWhenModuleIsCreatedAndFullyL
715715
moduleDesc.inputSize = size;
716716

717717
ModuleBuildLog *moduleBuildLog = nullptr;
718+
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(nullptr);
718719

719720
auto module = std::unique_ptr<L0::ModuleImp>(new L0::ModuleImp(device, moduleBuildLog, ModuleType::User));
720721
ASSERT_NE(nullptr, module.get());
721722

722723
memoryOperationsHandler->makeResidentCalledCount = 0;
723724

724-
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(nullptr);
725725
module->initialize(&moduleDesc, neoDevice);
726726

727-
EXPECT_EQ(4, memoryOperationsHandler->makeResidentCalledCount);
727+
EXPECT_EQ(5, memoryOperationsHandler->makeResidentCalledCount);
728728

729729
for (auto &ki : module->getKernelImmutableDataVector()) {
730730
EXPECT_TRUE(ki->isIsaCopiedToAllocation());
731731
}
732+
733+
auto moduleBuiltin = std::unique_ptr<L0::ModuleImp>(new L0::ModuleImp(device, moduleBuildLog, ModuleType::Builtin));
734+
ASSERT_NE(nullptr, moduleBuiltin.get());
735+
736+
memoryOperationsHandler->makeResidentCalledCount = 0;
737+
738+
moduleBuiltin->initialize(&moduleDesc, neoDevice);
739+
740+
EXPECT_EQ(0, memoryOperationsHandler->makeResidentCalledCount);
741+
742+
for (auto &ki : moduleBuiltin->getKernelImmutableDataVector()) {
743+
EXPECT_FALSE(ki->isIsaCopiedToAllocation());
744+
}
732745
}
733746

734747
HWTEST_F(NotifyModuleLoadTest, givenDebuggingEnabledWhenModuleWithUnresolvedSymbolsIsCreatedThenIsaAllocationsAreNotCopiedAndNotResident) {

level_zero/core/test/unit_tests/sources/module/test_module.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,6 +2510,43 @@ TEST_F(ModuleTests, givenImplicitArgsRelocationAndNoDebuggerOrStackCallsWhenLink
25102510
EXPECT_FALSE(kernelInfo->kernelDescriptor.kernelAttributes.flags.requiresImplicitArgs);
25112511
}
25122512

2513+
TEST_F(ModuleTests, givenModuleWithGlobalAndConstAllocationsWhenGettingModuleAllocationsThenAllAreReturned) {
2514+
std::unique_ptr<MockModule> module = std::make_unique<MockModule>(device,
2515+
nullptr,
2516+
ModuleType::User);
2517+
module->translationUnit = std::make_unique<MockModuleTranslationUnit>(device);
2518+
2519+
module->translationUnit->globalVarBuffer = neoDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(
2520+
{device->getRootDeviceIndex(), MemoryConstants::pageSize, NEO::AllocationType::BUFFER, neoDevice->getDeviceBitfield()});
2521+
module->translationUnit->globalConstBuffer = neoDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(
2522+
{device->getRootDeviceIndex(), MemoryConstants::pageSize, NEO::AllocationType::BUFFER, neoDevice->getDeviceBitfield()});
2523+
2524+
uint32_t kernelHeap = 0;
2525+
auto kernelInfo = new KernelInfo();
2526+
kernelInfo->heapInfo.KernelHeapSize = 1;
2527+
kernelInfo->heapInfo.pKernelHeap = &kernelHeap;
2528+
2529+
// pass kernelInfo ownership to programInfo
2530+
module->translationUnit->programInfo.kernelInfos.push_back(kernelInfo);
2531+
2532+
std::unique_ptr<WhiteBox<::L0::KernelImmutableData>> kernelImmData{new WhiteBox<::L0::KernelImmutableData>(this->device)};
2533+
kernelImmData->initialize(kernelInfo, device, 0, module->translationUnit->globalConstBuffer, module->translationUnit->globalVarBuffer, false);
2534+
module->kernelImmDatas.push_back(std::move(kernelImmData));
2535+
2536+
const auto allocs = module->getModuleAllocations();
2537+
2538+
EXPECT_EQ(3u, allocs.size());
2539+
2540+
auto iter = std::find(allocs.begin(), allocs.end(), module->translationUnit->globalConstBuffer);
2541+
EXPECT_NE(allocs.end(), iter);
2542+
2543+
iter = std::find(allocs.begin(), allocs.end(), module->translationUnit->globalVarBuffer);
2544+
EXPECT_NE(allocs.end(), iter);
2545+
2546+
iter = std::find(allocs.begin(), allocs.end(), module->kernelImmDatas[0]->getIsaGraphicsAllocation());
2547+
EXPECT_NE(allocs.end(), iter);
2548+
}
2549+
25132550
using ModuleIsaCopyTest = Test<ModuleImmutableDataFixture>;
25142551

25152552
TEST_F(ModuleIsaCopyTest, whenModuleIsInitializedThenIsaIsCopied) {

0 commit comments

Comments
 (0)