Skip to content

Commit d35c20f

Browse files
pwilmaCompute-Runtime-Automation
authored andcommitted
Collect patch info for scratch/global/constant/private
Related-To: NEO-3342 Change-Id: I0b594219cedf5d13d1eb70514816e8048938772e Signed-off-by: Pawel Wilma <[email protected]>
1 parent 026a134 commit d35c20f

File tree

12 files changed

+133
-11
lines changed

12 files changed

+133
-11
lines changed

runtime/command_stream/command_stream_receiver_hw_base.inl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,10 @@ inline void CommandStreamReceiverHw<GfxFamily>::programPreamble(LinearStream &cs
670670
template <typename GfxFamily>
671671
inline void CommandStreamReceiverHw<GfxFamily>::programVFEState(LinearStream &csr, DispatchFlags &dispatchFlags, uint32_t maxFrontEndThreads) {
672672
if (mediaVfeStateDirty) {
673-
PreambleHelper<GfxFamily>::programVFEState(&csr, peekHwInfo(), requiredScratchSize, getScratchPatchAddress(), maxFrontEndThreads);
673+
auto commandOffset = PreambleHelper<GfxFamily>::programVFEState(&csr, peekHwInfo(), requiredScratchSize, getScratchPatchAddress(), maxFrontEndThreads);
674+
if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) {
675+
flatBatchBufferHelper->collectScratchSpacePatchInfo(getScratchPatchAddress(), commandOffset, csr);
676+
}
674677
setMediaVFEStateDirty(false);
675678
}
676679
}

runtime/helpers/address_patch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ enum PatchInfoAllocationType {
2121
TagAddress,
2222
TagValue,
2323
GUCStartMessage,
24+
ScratchSpace
2425
};
2526

2627
struct PatchInfoData {

runtime/helpers/flat_batch_buffer_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class FlatBatchBufferHelper {
3232
virtual GraphicsAllocation *flattenBatchBuffer(BatchBuffer &batchBuffer, size_t &sizeBatchBuffer, DispatchMode dispatchMode) = 0;
3333
virtual char *getIndirectPatchCommands(size_t &indirectPatchCommandsSize, std::vector<PatchInfoData> &indirectPatchInfo) = 0;
3434
virtual void removePipeControlData(size_t pipeControlLocationSize, void *pipeControlForNooping) = 0;
35+
virtual void collectScratchSpacePatchInfo(uint64_t scratchAddress, uint64_t commandOffset, const LinearStream &csr) = 0;
3536
static void fixCrossThreadDataInfo(std::vector<PatchInfoData> &data, size_t offsetCrossThreadData, uint64_t gpuAddress);
3637

3738
std::vector<CommandChunk> &getCommandChunkList() { return commandChunkList; }

runtime/helpers/flat_batch_buffer_helper_hw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class FlatBatchBufferHelperHw : public FlatBatchBufferHelper {
1818
GraphicsAllocation *flattenBatchBuffer(BatchBuffer &batchBuffer, size_t &sizeBatchBuffer, DispatchMode dispatchMode) override;
1919
char *getIndirectPatchCommands(size_t &indirectPatchCommandsSize, std::vector<PatchInfoData> &indirectPatchInfo) override;
2020
void removePipeControlData(size_t pipeControlLocationSize, void *pipeControlForNooping) override;
21+
void collectScratchSpacePatchInfo(uint64_t scratchAddress, uint64_t commandOffset, const LinearStream &csr) override;
2122
};
2223

2324
} // namespace NEO

runtime/helpers/flat_batch_buffer_helper_hw.inl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,13 @@ void FlatBatchBufferHelperHw<GfxFamily>::removePipeControlData(size_t pipeContro
190190
}
191191
}
192192

193+
template <typename GfxFamily>
194+
void FlatBatchBufferHelperHw<GfxFamily>::collectScratchSpacePatchInfo(uint64_t scratchAddress, uint64_t commandOffset, const LinearStream &csr) {
195+
if (scratchAddress) {
196+
auto scratchOffset = reinterpret_cast<uint32_t *>(reinterpret_cast<uint8_t *>(csr.getCpuBase()) + commandOffset)[0] & 0x3FF;
197+
PatchInfoData patchInfoData(scratchAddress, scratchOffset, PatchInfoAllocationType::ScratchSpace, csr.getGraphicsAllocation()->getGpuAddress(), commandOffset, PatchInfoAllocationType::Default);
198+
patchInfoCollection.push_back(patchInfoData);
199+
}
200+
}
201+
193202
}; // namespace NEO

runtime/helpers/preamble.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ struct PreambleHelper {
3232
static void programThreadArbitration(LinearStream *pCommandStream, uint32_t requiredThreadArbitrationPolicy);
3333
static void programPreemption(LinearStream *pCommandStream, Device &device, GraphicsAllocation *preemptionCsr);
3434
static void addPipeControlBeforeVfeCmd(LinearStream *pCommandStream, const HardwareInfo *hwInfo);
35-
static void programVFEState(LinearStream *pCommandStream,
36-
const HardwareInfo &hwInfo,
37-
int scratchSize,
38-
uint64_t scratchAddress,
39-
uint32_t maxFrontEndThreads);
35+
static uint64_t programVFEState(LinearStream *pCommandStream,
36+
const HardwareInfo &hwInfo,
37+
int scratchSize,
38+
uint64_t scratchAddress,
39+
uint32_t maxFrontEndThreads);
4040
static void programPreamble(LinearStream *pCommandStream, Device &device, uint32_t l3Config,
4141
uint32_t requiredThreadArbitrationPolicy, GraphicsAllocation *preemptionCsr);
4242
static void programKernelDebugging(LinearStream *pCommandStream);

runtime/helpers/preamble_bdw_plus.inl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*
66
*/
77

8+
#include "runtime/helpers/flat_batch_buffer_helper.h"
89
#include "runtime/helpers/hw_helper.h"
910
#include "runtime/helpers/preamble_base.inl"
1011

@@ -25,15 +26,16 @@ uint32_t PreambleHelper<GfxFamily>::getUrbEntryAllocationSize() {
2526
}
2627

2728
template <typename GfxFamily>
28-
void PreambleHelper<GfxFamily>::programVFEState(LinearStream *pCommandStream,
29-
const HardwareInfo &hwInfo,
30-
int scratchSize,
31-
uint64_t scratchAddress,
32-
uint32_t maxFrontEndThreads) {
29+
uint64_t PreambleHelper<GfxFamily>::programVFEState(LinearStream *pCommandStream,
30+
const HardwareInfo &hwInfo,
31+
int scratchSize,
32+
uint64_t scratchAddress,
33+
uint32_t maxFrontEndThreads) {
3334
using MEDIA_VFE_STATE = typename GfxFamily::MEDIA_VFE_STATE;
3435

3536
addPipeControlBeforeVfeCmd(pCommandStream, &hwInfo);
3637

38+
auto scratchSpaceAddressOffset = static_cast<uint64_t>(pCommandStream->getUsed() + MEDIA_VFE_STATE::PATCH_CONSTANTS::SCRATCHSPACEBASEPOINTER_BYTEOFFSET);
3739
auto pMediaVfeState = reinterpret_cast<MEDIA_VFE_STATE *>(pCommandStream->getSpace(sizeof(MEDIA_VFE_STATE)));
3840
*pMediaVfeState = GfxFamily::cmdInitMediaVfeState;
3941
pMediaVfeState->setMaximumNumberOfThreads(maxFrontEndThreads);
@@ -45,6 +47,8 @@ void PreambleHelper<GfxFamily>::programVFEState(LinearStream *pCommandStream,
4547
uint32_t highAddress = static_cast<uint32_t>(0xFFFFFFFF & (scratchAddress >> 32));
4648
pMediaVfeState->setScratchSpaceBasePointer(lowAddress);
4749
pMediaVfeState->setScratchSpaceBasePointerHigh(highAddress);
50+
51+
return scratchSpaceAddressOffset;
4852
}
4953

5054
template <typename GfxFamily>

runtime/kernel/kernel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ void Kernel::patchWithImplicitSurface(void *ptrToPatchInCrossThreadData, Graphic
159159
auto pp = ptrOffset(crossThreadData, crossThreadDataOffset);
160160
uintptr_t addressToPatch = reinterpret_cast<uintptr_t>(ptrToPatchInCrossThreadData);
161161
patchWithRequiredSize(pp, pointerSize, addressToPatch);
162+
if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) {
163+
PatchInfoData patchInfoData(addressToPatch, 0u, PatchInfoAllocationType::KernelArg, reinterpret_cast<uint64_t>(getCrossThreadData()), crossThreadDataOffset, PatchInfoAllocationType::IndirectObjectHeap, pointerSize);
164+
this->patchInfoDataList.push_back(patchInfoData);
165+
}
162166
}
163167

164168
if (ssh) {

unit_tests/command_stream/command_stream_receiver_flush_task_gmock_tests.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "runtime/command_stream/command_stream_receiver.h"
1515
#include "runtime/command_stream/linear_stream.h"
1616
#include "runtime/command_stream/preemption.h"
17+
#include "runtime/command_stream/scratch_space_controller.h"
1718
#include "runtime/event/user_event.h"
1819
#include "runtime/helpers/cache_policy.h"
1920
#include "runtime/helpers/preamble.h"
@@ -253,3 +254,60 @@ HWTEST_F(CommandStreamReceiverFlushTaskGmockTests, givenMockCsrWhenCollectStateB
253254
EXPECT_EQ(gshPatch.sourceAllocation, generalStateBase);
254255
EXPECT_EQ(gshPatch.targetAllocationOffset, commandOffset + STATE_BASE_ADDRESS::PATCH_CONSTANTS::GENERALSTATEBASEADDRESS_BYTEOFFSET);
255256
}
257+
258+
HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverFlushTaskGmockTests, givenPatchInfoCollectionEnabledWhenScratchSpaceIsProgrammedThenPatchInfoIsCollected) {
259+
DebugManagerStateRestore dbgRestore;
260+
DebugManager.flags.AddPatchInfoCommentsForAUBDump.set(true);
261+
262+
CommandQueueHw<FamilyType> commandQueue(nullptr, pDevice, 0);
263+
auto &commandStream = commandQueue.getCS(4096u);
264+
265+
std::unique_ptr<MockCsrHw2<FamilyType>> mockCsr(new MockCsrHw2<FamilyType>(*pDevice->executionEnvironment));
266+
mockCsr->overwriteFlatBatchBufferHelper(new MockFlatBatchBufferHelper<FamilyType>(*pDevice->executionEnvironment));
267+
268+
bool stateBaseAddressDirty;
269+
bool vfeStateDirty;
270+
mockCsr->getScratchSpaceController()->setRequiredScratchSpace(nullptr, 10u, 0u, 1u, 0u, stateBaseAddressDirty, vfeStateDirty);
271+
272+
DispatchFlags flags;
273+
mockCsr->requiredScratchSize = 0x200000;
274+
275+
mockCsr->programVFEState(commandStream, flags, 10);
276+
ASSERT_EQ(1u, mockCsr->getFlatBatchBufferHelper().getPatchInfoCollection().size());
277+
EXPECT_EQ(mockCsr->getScratchSpaceController()->getScratchPatchAddress(), mockCsr->getFlatBatchBufferHelper().getPatchInfoCollection().at(0).sourceAllocation);
278+
}
279+
280+
HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverFlushTaskGmockTests, givenPatchInfoCollectionDisabledWhenScratchSpaceIsProgrammedThenPatchInfoIsNotCollected) {
281+
CommandQueueHw<FamilyType> commandQueue(nullptr, pDevice, 0);
282+
auto &commandStream = commandQueue.getCS(4096u);
283+
284+
std::unique_ptr<MockCsrHw2<FamilyType>> mockCsr(new MockCsrHw2<FamilyType>(*pDevice->executionEnvironment));
285+
mockCsr->overwriteFlatBatchBufferHelper(new MockFlatBatchBufferHelper<FamilyType>(*pDevice->executionEnvironment));
286+
287+
bool stateBaseAddressDirty;
288+
bool vfeStateDirty;
289+
mockCsr->getScratchSpaceController()->setRequiredScratchSpace(nullptr, 10u, 0u, 1u, 0u, stateBaseAddressDirty, vfeStateDirty);
290+
291+
DispatchFlags flags;
292+
mockCsr->requiredScratchSize = 0x200000;
293+
294+
mockCsr->programVFEState(commandStream, flags, 10);
295+
EXPECT_EQ(0u, mockCsr->getFlatBatchBufferHelper().getPatchInfoCollection().size());
296+
}
297+
298+
HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverFlushTaskGmockTests, givenPatchInfoCollectionEnabledWhenMediaVfeStateIsProgrammedWithEmptyScratchThenPatchInfoIsNotCollected) {
299+
DebugManagerStateRestore dbgRestore;
300+
DebugManager.flags.AddPatchInfoCommentsForAUBDump.set(true);
301+
302+
CommandQueueHw<FamilyType> commandQueue(nullptr, pDevice, 0);
303+
auto &commandStream = commandQueue.getCS(4096u);
304+
305+
std::unique_ptr<MockCsrHw2<FamilyType>> mockCsr(new MockCsrHw2<FamilyType>(*pDevice->executionEnvironment));
306+
mockCsr->overwriteFlatBatchBufferHelper(new MockFlatBatchBufferHelper<FamilyType>(*pDevice->executionEnvironment));
307+
308+
DispatchFlags flags;
309+
mockCsr->requiredScratchSize = 0x200000;
310+
311+
mockCsr->programVFEState(commandStream, flags, 10);
312+
EXPECT_EQ(0u, mockCsr->getFlatBatchBufferHelper().getPatchInfoCollection().size());
313+
}

unit_tests/kernel/kernel_tests.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,6 +2697,31 @@ TEST(KernelTest, givenKernelWithoutMediaVfeStateSlot1WhenGettingSizeForPrivateSc
26972697
EXPECT_EQ(0u, mockKernel.mockKernel->getPrivateScratchSize());
26982698
}
26992699

2700+
TEST(KernelTest, givenKernelWithPatchInfoCollectionEnabledWhenPatchWithImplicitSurfaceCalledThenPatchInfoDataIsCollected) {
2701+
DebugManagerStateRestore restore;
2702+
DebugManager.flags.AddPatchInfoCommentsForAUBDump.set(true);
2703+
2704+
std::unique_ptr<MockDevice> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(platformDevices[0]));
2705+
MockKernelWithInternals kernel(*device);
2706+
MockGraphicsAllocation mockAllocation;
2707+
SPatchAllocateStatelessGlobalMemorySurfaceWithInitialization patchToken{};
2708+
uint64_t crossThreadData = 0;
2709+
EXPECT_EQ(0u, kernel.mockKernel->getPatchInfoDataList().size());
2710+
kernel.mockKernel->patchWithImplicitSurface(&crossThreadData, mockAllocation, patchToken);
2711+
EXPECT_EQ(1u, kernel.mockKernel->getPatchInfoDataList().size());
2712+
}
2713+
2714+
TEST(KernelTest, givenKernelWithPatchInfoCollectionDisabledWhenPatchWithImplicitSurfaceCalledThenPatchInfoDataIsNotCollected) {
2715+
std::unique_ptr<MockDevice> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(platformDevices[0]));
2716+
MockKernelWithInternals kernel(*device);
2717+
MockGraphicsAllocation mockAllocation;
2718+
SPatchAllocateStatelessGlobalMemorySurfaceWithInitialization patchToken{};
2719+
uint64_t crossThreadData = 0;
2720+
EXPECT_EQ(0u, kernel.mockKernel->getPatchInfoDataList().size());
2721+
kernel.mockKernel->patchWithImplicitSurface(&crossThreadData, mockAllocation, patchToken);
2722+
EXPECT_EQ(0u, kernel.mockKernel->getPatchInfoDataList().size());
2723+
}
2724+
27002725
namespace NEO {
27012726

27022727
template <typename GfxFamily>

0 commit comments

Comments
 (0)