Skip to content

Commit beff001

Browse files
SBA tracking for single address space
Related-To: NEO-6539 Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
1 parent 4374197 commit beff001

File tree

25 files changed

+972
-114
lines changed

25 files changed

+972
-114
lines changed

level_zero/core/source/cmdqueue/cmdqueue_hw.inl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
148148
preemptionSize += NEO::PreemptionHelper::getRequiredCmdStreamSize<GfxFamily>(devicePreemption, commandQueuePreemptionMode);
149149

150150
if (NEO::Debugger::isDebugEnabled(internalUsage) && !commandQueueDebugCmdsProgrammed) {
151-
debuggerCmdsSize += NEO::PreambleHelper<GfxFamily>::getKernelDebuggingCommandsSize(neoDevice->getSourceLevelDebugger() != nullptr);
151+
if (neoDevice->getSourceLevelDebugger() != nullptr) {
152+
debuggerCmdsSize += NEO::PreambleHelper<GfxFamily>::getKernelDebuggingCommandsSize(true);
153+
} else if (device->getL0Debugger()) {
154+
debuggerCmdsSize += device->getL0Debugger()->getSbaAddressLoadCommandsSize();
155+
}
152156
}
153157

154158
if (devicePreemption == NEO::PreemptionMode::MidThread) {
@@ -275,7 +279,7 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
275279
size_t padding = alignedSize - linearStreamSizeEstimate;
276280
reserveLinearStreamSize(alignedSize);
277281
NEO::LinearStream child(commandStream->getSpace(alignedSize), alignedSize);
278-
child.setGpuBase(ptrOffset(commandStream->getGpuBase(), commandStream->getUsed()));
282+
child.setGpuBase(ptrOffset(commandStream->getGpuBase(), commandStream->getUsed() - alignedSize));
279283

280284
const auto globalFenceAllocation = csr->getGlobalFenceAllocation();
281285
if (globalFenceAllocation) {
@@ -307,9 +311,15 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
307311
programPipelineSelect(child);
308312
}
309313

310-
if (NEO::Debugger::isDebugEnabled(internalUsage) && !commandQueueDebugCmdsProgrammed && neoDevice->getSourceLevelDebugger()) {
311-
NEO::PreambleHelper<GfxFamily>::programKernelDebugging(&child);
312-
commandQueueDebugCmdsProgrammed = true;
314+
if (NEO::Debugger::isDebugEnabled(internalUsage) && !commandQueueDebugCmdsProgrammed) {
315+
if (neoDevice->getSourceLevelDebugger()) {
316+
NEO::PreambleHelper<GfxFamily>::programKernelDebugging(&child);
317+
commandQueueDebugCmdsProgrammed = true;
318+
} else if (device->getL0Debugger()) {
319+
device->getL0Debugger()->programSbaAddressLoad(child,
320+
device->getL0Debugger()->getSbaTrackingBuffer(csr->getOsContext().getContextId())->getGpuAddress());
321+
commandQueueDebugCmdsProgrammed = true;
322+
}
313323
}
314324

315325
if (gsbaStateDirty) {

level_zero/core/source/debugger/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2020 Intel Corporation
2+
# Copyright (C) 2020-2022 Intel Corporation
33
#
44
# SPDX-License-Identifier: MIT
55
#
@@ -9,6 +9,8 @@ set(L0_SRCS_DEBUGGER
99
${CMAKE_CURRENT_SOURCE_DIR}/debugger_l0.cpp
1010
${CMAKE_CURRENT_SOURCE_DIR}/debugger_l0.h
1111
${CMAKE_CURRENT_SOURCE_DIR}/debugger_l0.inl
12+
${CMAKE_CURRENT_SOURCE_DIR}/debugger_l0_base.inl
13+
${CMAKE_CURRENT_SOURCE_DIR}/debugger_l0_tgllp_and_later.inl
1214
)
1315

1416
add_subdirectories()

level_zero/core/source/debugger/debugger_l0.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,34 @@ DebugerL0CreateFn debuggerL0Factory[IGFX_MAX_CORE] = {};
2424

2525
DebuggerL0::DebuggerL0(NEO::Device *device) : device(device) {
2626
isLegacyMode = false;
27+
2728
initialize();
2829
}
2930

3031
void DebuggerL0::initialize() {
31-
auto &engines = device->getMemoryManager()->getRegisteredEngines();
3232

33-
sbaTrackingGpuVa = device->getMemoryManager()->reserveGpuAddress(MemoryConstants::pageSize, device->getRootDeviceIndex());
33+
if (NEO::DebugManager.flags.DebuggerForceSbaTrackingMode.get() != -1) {
34+
setSingleAddressSpaceSbaTracking(NEO::DebugManager.flags.DebuggerForceSbaTrackingMode.get());
35+
}
36+
37+
auto &engines = device->getMemoryManager()->getRegisteredEngines();
3438

3539
NEO::AllocationProperties properties{device->getRootDeviceIndex(), true, MemoryConstants::pageSize,
3640
NEO::AllocationType::DEBUG_SBA_TRACKING_BUFFER,
3741
false,
3842
device->getDeviceBitfield()};
3943

40-
properties.gpuAddress = sbaTrackingGpuVa.address;
44+
if (!singleAddressSpaceSbaTracking) {
45+
sbaTrackingGpuVa = device->getMemoryManager()->reserveGpuAddress(MemoryConstants::pageSize, device->getRootDeviceIndex());
46+
properties.gpuAddress = sbaTrackingGpuVa.address;
47+
}
48+
4149
SbaTrackedAddresses sbaHeader;
4250

4351
for (auto &engine : engines) {
44-
properties.osContext = engine.osContext;
52+
if (!singleAddressSpaceSbaTracking) {
53+
properties.osContext = engine.osContext;
54+
}
4555
auto sbaAllocation = device->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
4656
memset(sbaAllocation->getUnderlyingBuffer(), 0, sbaAllocation->getUnderlyingBufferSize());
4757

@@ -102,7 +112,9 @@ DebuggerL0 ::~DebuggerL0() {
102112
for (auto &alloc : perContextSbaAllocations) {
103113
device->getMemoryManager()->freeGraphicsMemory(alloc.second);
104114
}
105-
device->getMemoryManager()->freeGpuAddress(sbaTrackingGpuVa, device->getRootDeviceIndex());
115+
if (sbaTrackingGpuVa.size != 0) {
116+
device->getMemoryManager()->freeGpuAddress(sbaTrackingGpuVa, device->getRootDeviceIndex());
117+
}
106118
device->getMemoryManager()->freeGraphicsMemory(moduleDebugArea);
107119
}
108120

level_zero/core/source/debugger/debugger_l0.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <level_zero/ze_api.h>
1414

15+
#include <cstdint>
1516
#include <memory>
1617
#include <unordered_map>
1718

@@ -99,10 +100,16 @@ class DebuggerL0 : public NEO::Debugger, NEO::NonCopyableOrMovableClass {
99100

100101
virtual size_t getSbaTrackingCommandsSize(size_t trackedAddressCount) = 0;
101102
virtual void programSbaTrackingCommands(NEO::LinearStream &cmdStream, const SbaAddresses &sba) = 0;
103+
virtual size_t getSbaAddressLoadCommandsSize() = 0;
104+
virtual void programSbaAddressLoad(NEO::LinearStream &cmdStream, uint64_t sbaGpuVa) = 0;
102105

103106
MOCKABLE_VIRTUAL bool attachZebinModuleToSegmentAllocations(const StackVec<NEO::GraphicsAllocation *, 32> &kernelAlloc, uint32_t &moduleHandle);
104107
MOCKABLE_VIRTUAL bool removeZebinModule(uint32_t moduleHandle);
105108

109+
void setSingleAddressSpaceSbaTracking(bool value) {
110+
singleAddressSpaceSbaTracking = value;
111+
}
112+
106113
protected:
107114
static bool isAnyTrackedAddressChanged(SbaAddresses sba) {
108115
return sba.GeneralStateBaseAddress != 0 ||
@@ -116,10 +123,11 @@ class DebuggerL0 : public NEO::Debugger, NEO::NonCopyableOrMovableClass {
116123
NEO::Device *device = nullptr;
117124
NEO::GraphicsAllocation *sbaAllocation = nullptr;
118125
std::unordered_map<uint32_t, NEO::GraphicsAllocation *> perContextSbaAllocations;
119-
NEO::AddressRange sbaTrackingGpuVa;
126+
NEO::AddressRange sbaTrackingGpuVa{};
120127
NEO::GraphicsAllocation *moduleDebugArea = nullptr;
121128
std::atomic<uint32_t> commandQueueCount = 0u;
122129
uint32_t uuidL0CommandQueueHandle = 0;
130+
bool singleAddressSpaceSbaTracking = false;
123131
};
124132

125133
using DebugerL0CreateFn = DebuggerL0 *(*)(NEO::Device *device);
@@ -132,6 +140,10 @@ class DebuggerL0Hw : public DebuggerL0 {
132140

133141
size_t getSbaTrackingCommandsSize(size_t trackedAddressCount) override;
134142
void programSbaTrackingCommands(NEO::LinearStream &cmdStream, const SbaAddresses &sba) override;
143+
size_t getSbaAddressLoadCommandsSize() override;
144+
void programSbaAddressLoad(NEO::LinearStream &cmdStream, uint64_t sbaGpuVa) override;
145+
146+
void programSbaTrackingCommandsSingleAddressSpace(NEO::LinearStream &cmdStream, const SbaAddresses &sba);
135147

136148
protected:
137149
DebuggerL0Hw(NEO::Device *device) : DebuggerL0(device){};
Lines changed: 90 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -16,14 +16,13 @@
1616

1717
namespace L0 {
1818

19-
template <typename GfxFamily>
20-
size_t DebuggerL0Hw<GfxFamily>::getSbaTrackingCommandsSize(size_t trackedAddressCount) {
21-
return trackedAddressCount * NEO::EncodeStoreMemory<GfxFamily>::getStoreDataImmSize();
22-
}
23-
2419
template <typename GfxFamily>
2520
void DebuggerL0Hw<GfxFamily>::programSbaTrackingCommands(NEO::LinearStream &cmdStream, const SbaAddresses &sba) {
26-
auto gpuAddress = NEO::GmmHelper::decanonize(sbaTrackingGpuVa.address);
21+
using MI_STORE_DATA_IMM = typename GfxFamily::MI_STORE_DATA_IMM;
22+
using MI_STORE_REGISTER_MEM = typename GfxFamily::MI_STORE_REGISTER_MEM;
23+
using MI_BATCH_BUFFER_START = typename GfxFamily::MI_BATCH_BUFFER_START;
24+
using MI_ARB_CHECK = typename GfxFamily::MI_ARB_CHECK;
25+
const auto gpuAddress = NEO::GmmHelper::decanonize(sbaTrackingGpuVa.address);
2726

2827
PRINT_DEBUGGER_INFO_LOG("Debugger: SBA stored ssh = %" SCNx64
2928
" gsba = %" SCNx64
@@ -34,59 +33,63 @@ void DebuggerL0Hw<GfxFamily>::programSbaTrackingCommands(NEO::LinearStream &cmdS
3433
sba.SurfaceStateBaseAddress, sba.GeneralStateBaseAddress, sba.DynamicStateBaseAddress,
3534
sba.IndirectObjectBaseAddress, sba.InstructionBaseAddress, sba.BindlessSurfaceStateBaseAddress);
3635

37-
if (sba.GeneralStateBaseAddress) {
38-
auto generalStateBaseAddress = NEO::GmmHelper::decanonize(sba.GeneralStateBaseAddress);
39-
NEO::EncodeStoreMemory<GfxFamily>::programStoreDataImm(cmdStream,
40-
gpuAddress + offsetof(SbaTrackedAddresses, GeneralStateBaseAddress),
41-
static_cast<uint32_t>(generalStateBaseAddress & 0x0000FFFFFFFFULL),
42-
static_cast<uint32_t>(generalStateBaseAddress >> 32),
43-
true,
44-
false);
45-
}
46-
if (sba.SurfaceStateBaseAddress) {
47-
auto surfaceStateBaseAddress = NEO::GmmHelper::decanonize(sba.SurfaceStateBaseAddress);
48-
NEO::EncodeStoreMemory<GfxFamily>::programStoreDataImm(cmdStream,
49-
gpuAddress + offsetof(SbaTrackedAddresses, SurfaceStateBaseAddress),
50-
static_cast<uint32_t>(surfaceStateBaseAddress & 0x0000FFFFFFFFULL),
51-
static_cast<uint32_t>(surfaceStateBaseAddress >> 32),
52-
true,
53-
false);
54-
}
55-
if (sba.DynamicStateBaseAddress) {
56-
auto dynamicStateBaseAddress = NEO::GmmHelper::decanonize(sba.DynamicStateBaseAddress);
57-
NEO::EncodeStoreMemory<GfxFamily>::programStoreDataImm(cmdStream,
58-
gpuAddress + offsetof(SbaTrackedAddresses, DynamicStateBaseAddress),
59-
static_cast<uint32_t>(dynamicStateBaseAddress & 0x0000FFFFFFFFULL),
60-
static_cast<uint32_t>(dynamicStateBaseAddress >> 32),
61-
true,
62-
false);
63-
}
64-
if (sba.IndirectObjectBaseAddress) {
65-
auto indirectObjectBaseAddress = NEO::GmmHelper::decanonize(sba.IndirectObjectBaseAddress);
66-
NEO::EncodeStoreMemory<GfxFamily>::programStoreDataImm(cmdStream,
67-
gpuAddress + offsetof(SbaTrackedAddresses, IndirectObjectBaseAddress),
68-
static_cast<uint32_t>(indirectObjectBaseAddress & 0x0000FFFFFFFFULL),
69-
static_cast<uint32_t>(indirectObjectBaseAddress >> 32),
70-
true,
71-
false);
72-
}
73-
if (sba.InstructionBaseAddress) {
74-
auto instructionBaseAddress = NEO::GmmHelper::decanonize(sba.InstructionBaseAddress);
75-
NEO::EncodeStoreMemory<GfxFamily>::programStoreDataImm(cmdStream,
76-
gpuAddress + offsetof(SbaTrackedAddresses, InstructionBaseAddress),
77-
static_cast<uint32_t>(instructionBaseAddress & 0x0000FFFFFFFFULL),
78-
static_cast<uint32_t>(instructionBaseAddress >> 32),
79-
true,
80-
false);
81-
}
82-
if (sba.BindlessSurfaceStateBaseAddress) {
83-
auto bindlessSurfaceStateBaseAddress = NEO::GmmHelper::decanonize(sba.BindlessSurfaceStateBaseAddress);
84-
NEO::EncodeStoreMemory<GfxFamily>::programStoreDataImm(cmdStream,
85-
gpuAddress + offsetof(SbaTrackedAddresses, BindlessSurfaceStateBaseAddress),
86-
static_cast<uint32_t>(bindlessSurfaceStateBaseAddress & 0x0000FFFFFFFFULL),
87-
static_cast<uint32_t>(bindlessSurfaceStateBaseAddress >> 32),
88-
true,
89-
false);
36+
if (singleAddressSpaceSbaTracking) {
37+
programSbaTrackingCommandsSingleAddressSpace(cmdStream, sba);
38+
} else {
39+
if (sba.GeneralStateBaseAddress) {
40+
auto generalStateBaseAddress = NEO::GmmHelper::decanonize(sba.GeneralStateBaseAddress);
41+
NEO::EncodeStoreMemory<GfxFamily>::programStoreDataImm(cmdStream,
42+
gpuAddress + offsetof(SbaTrackedAddresses, GeneralStateBaseAddress),
43+
static_cast<uint32_t>(generalStateBaseAddress & 0x0000FFFFFFFFULL),
44+
static_cast<uint32_t>(generalStateBaseAddress >> 32),
45+
true,
46+
false);
47+
}
48+
if (sba.SurfaceStateBaseAddress) {
49+
auto surfaceStateBaseAddress = NEO::GmmHelper::decanonize(sba.SurfaceStateBaseAddress);
50+
NEO::EncodeStoreMemory<GfxFamily>::programStoreDataImm(cmdStream,
51+
gpuAddress + offsetof(SbaTrackedAddresses, SurfaceStateBaseAddress),
52+
static_cast<uint32_t>(surfaceStateBaseAddress & 0x0000FFFFFFFFULL),
53+
static_cast<uint32_t>(surfaceStateBaseAddress >> 32),
54+
true,
55+
false);
56+
}
57+
if (sba.DynamicStateBaseAddress) {
58+
auto dynamicStateBaseAddress = NEO::GmmHelper::decanonize(sba.DynamicStateBaseAddress);
59+
NEO::EncodeStoreMemory<GfxFamily>::programStoreDataImm(cmdStream,
60+
gpuAddress + offsetof(SbaTrackedAddresses, DynamicStateBaseAddress),
61+
static_cast<uint32_t>(dynamicStateBaseAddress & 0x0000FFFFFFFFULL),
62+
static_cast<uint32_t>(dynamicStateBaseAddress >> 32),
63+
true,
64+
false);
65+
}
66+
if (sba.IndirectObjectBaseAddress) {
67+
auto indirectObjectBaseAddress = NEO::GmmHelper::decanonize(sba.IndirectObjectBaseAddress);
68+
NEO::EncodeStoreMemory<GfxFamily>::programStoreDataImm(cmdStream,
69+
gpuAddress + offsetof(SbaTrackedAddresses, IndirectObjectBaseAddress),
70+
static_cast<uint32_t>(indirectObjectBaseAddress & 0x0000FFFFFFFFULL),
71+
static_cast<uint32_t>(indirectObjectBaseAddress >> 32),
72+
true,
73+
false);
74+
}
75+
if (sba.InstructionBaseAddress) {
76+
auto instructionBaseAddress = NEO::GmmHelper::decanonize(sba.InstructionBaseAddress);
77+
NEO::EncodeStoreMemory<GfxFamily>::programStoreDataImm(cmdStream,
78+
gpuAddress + offsetof(SbaTrackedAddresses, InstructionBaseAddress),
79+
static_cast<uint32_t>(instructionBaseAddress & 0x0000FFFFFFFFULL),
80+
static_cast<uint32_t>(instructionBaseAddress >> 32),
81+
true,
82+
false);
83+
}
84+
if (sba.BindlessSurfaceStateBaseAddress) {
85+
auto bindlessSurfaceStateBaseAddress = NEO::GmmHelper::decanonize(sba.BindlessSurfaceStateBaseAddress);
86+
NEO::EncodeStoreMemory<GfxFamily>::programStoreDataImm(cmdStream,
87+
gpuAddress + offsetof(SbaTrackedAddresses, BindlessSurfaceStateBaseAddress),
88+
static_cast<uint32_t>(bindlessSurfaceStateBaseAddress & 0x0000FFFFFFFFULL),
89+
static_cast<uint32_t>(bindlessSurfaceStateBaseAddress >> 32),
90+
true,
91+
false);
92+
}
9093
}
9194
}
9295

@@ -95,4 +98,31 @@ DebuggerL0 *DebuggerL0Hw<GfxFamily>::allocate(NEO::Device *device) {
9598
return new DebuggerL0Hw<GfxFamily>(device);
9699
}
97100

101+
template <typename GfxFamily>
102+
size_t DebuggerL0Hw<GfxFamily>::getSbaAddressLoadCommandsSize() {
103+
if (!singleAddressSpaceSbaTracking) {
104+
return 0;
105+
}
106+
return 2 * sizeof(typename GfxFamily::MI_LOAD_REGISTER_IMM);
107+
}
108+
109+
template <typename GfxFamily>
110+
void DebuggerL0Hw<GfxFamily>::programSbaAddressLoad(NEO::LinearStream &cmdStream, uint64_t sbaGpuVa) {
111+
if (!singleAddressSpaceSbaTracking) {
112+
return;
113+
}
114+
uint32_t low = sbaGpuVa & 0xffffffff;
115+
uint32_t high = (sbaGpuVa >> 32) & 0xffffffff;
116+
117+
NEO::LriHelper<GfxFamily>::program(&cmdStream,
118+
CS_GPR_R15,
119+
low,
120+
true);
121+
122+
NEO::LriHelper<GfxFamily>::program(&cmdStream,
123+
CS_GPR_R15 + 4,
124+
high,
125+
true);
126+
}
127+
98128
} // namespace L0
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (C) 2022 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
namespace L0 {
9+
template <typename GfxFamily>
10+
size_t DebuggerL0Hw<GfxFamily>::getSbaTrackingCommandsSize(size_t trackedAddressCount) {
11+
if (singleAddressSpaceSbaTracking) {
12+
UNRECOVERABLE_IF(true);
13+
return 0;
14+
}
15+
return trackedAddressCount * NEO::EncodeStoreMemory<GfxFamily>::getStoreDataImmSize();
16+
}
17+
18+
template <typename GfxFamily>
19+
void DebuggerL0Hw<GfxFamily>::programSbaTrackingCommandsSingleAddressSpace(NEO::LinearStream &cmdStream, const SbaAddresses &sba) {
20+
UNRECOVERABLE_IF(true);
21+
}
22+
} // namespace L0

0 commit comments

Comments
 (0)