Fill leftover cmdbuffer space with MI_NOOPs in debugger and sw tag paths

Signed-off-by: Kamil Kopryk <kamil.kopryk@intel.com>
Related-To: NEO-7156
This commit is contained in:
Kamil Kopryk
2022-09-08 15:43:26 +00:00
committed by Compute-Runtime-Automation
parent c2cd1a2698
commit fad4bee432
5 changed files with 74 additions and 2 deletions

View File

@@ -156,7 +156,7 @@ struct CommandQueueHw : public CommandQueueImp {
inline void assignCsrTaskCountToFenceIfAvailable(ze_fence_handle_t hFence);
inline void dispatchTaskCountPostSyncRegular(bool isDispatchTaskCountPostSyncRequired, NEO::LinearStream &commandStream);
inline void dispatchTaskCountPostSyncByMiFlushDw(bool isDispatchTaskCountPostSyncRequired, NEO::LinearStream &commandStream);
inline NEO::SubmissionStatus prepareAndSubmitBatchBuffer(CommandListExecutionContext &ctx, NEO::LinearStream &innerCommandStream);
NEO::SubmissionStatus prepareAndSubmitBatchBuffer(CommandListExecutionContext &ctx, NEO::LinearStream &innerCommandStream);
inline void updateTaskCountAndPostSync(bool isDispatchTaskCountPostSyncRequired);
inline ze_result_t waitForCommandQueueCompletionAndCleanHeapContainer();
inline ze_result_t handleSubmissionAndCompletionResults(NEO::SubmissionStatus submitRet, ze_result_t completionRet);

View File

@@ -1017,7 +1017,15 @@ NEO::SubmissionStatus CommandQueueHw<gfxCoreFamily>::prepareAndSubmitBatchBuffer
*(MI_BATCH_BUFFER_END *)buffer = GfxFamily::cmdInitBatchBufferEnd;
}
if (this->alignedChildStreamPadding) {
if (ctx.isNEODebuggerActive(this->device) || NEO::DebugManager.flags.EnableSWTags.get()) {
auto leftoverSpace = outerCommandStream.getUsed() - innerCommandStream.getUsed();
leftoverSpace -= ptrDiff(innerCommandStream.getCpuBase(), outerCommandStream.getCpuBase());
if (leftoverSpace > 0) {
auto memory = innerCommandStream.getSpace(leftoverSpace);
memset(memory, 0, leftoverSpace);
}
} else if (this->alignedChildStreamPadding) {
void *paddingPtr = innerCommandStream.getSpace(this->alignedChildStreamPadding);
memset(paddingPtr, 0, this->alignedChildStreamPadding);
}

View File

@@ -61,6 +61,7 @@ template <GFXCORE_FAMILY gfxCoreFamily>
struct MockCommandQueueHw : public L0::CommandQueueHw<gfxCoreFamily> {
using BaseClass = ::L0::CommandQueueHw<gfxCoreFamily>;
using BaseClass::commandStream;
using BaseClass::prepareAndSubmitBatchBuffer;
using BaseClass::printfFunctionContainer;
using L0::CommandQueue::activeSubDevices;
using L0::CommandQueue::internalUsage;
@@ -68,6 +69,7 @@ struct MockCommandQueueHw : public L0::CommandQueueHw<gfxCoreFamily> {
using L0::CommandQueue::partitionCount;
using L0::CommandQueue::preemptionCmdSyncProgramming;
using L0::CommandQueueImp::csr;
using typename BaseClass::CommandListExecutionContext;
MockCommandQueueHw(L0::Device *device, NEO::CommandStreamReceiver *csr, const ze_command_queue_desc_t *desc) : L0::CommandQueueHw<gfxCoreFamily>(device, csr, desc) {
}

View File

@@ -377,6 +377,39 @@ HWTEST2_F(CommandQueueCreate, givenGpuHangInReservingLinearStreamWhenExecutingCo
EXPECT_EQ(ZE_RESULT_ERROR_DEVICE_LOST, result);
}
HWTEST2_F(CommandQueueCreate, givenSwTagsEnabledWhenPrepareAndSubmitBatchBufferThenLeftoverIsZeroed, IsAtLeastSkl) {
DebugManagerStateRestore restorer;
NEO::DebugManager.flags.EnableSWTags.set(1);
const ze_command_queue_desc_t desc = {};
auto commandQueue = new MockCommandQueueHw<gfxCoreFamily>(device, neoDevice->getDefaultEngine().commandStreamReceiver, &desc);
commandQueue->initialize(false, false);
ze_result_t returnValue;
auto commandList = std::unique_ptr<CommandList>(whiteboxCast(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue)));
ASSERT_NE(nullptr, commandList);
auto &commandStream = commandQueue->commandStream;
auto estimatedSize = 4096u;
NEO::LinearStream linearStream(commandStream->getSpace(estimatedSize), estimatedSize);
// fill with random data
memset(commandStream->getCpuBase(), 0xD, estimatedSize);
typename MockCommandQueueHw<gfxCoreFamily>::CommandListExecutionContext ctx{};
commandQueue->prepareAndSubmitBatchBuffer(ctx, linearStream);
// MI_BATCH_BUFFER END will be added during prepareAndSubmitBatchBuffer
auto offsetInBytes = sizeof(typename FamilyType::MI_BATCH_BUFFER_END);
auto isLeftoverZeroed = true;
for (auto i = offsetInBytes; i < estimatedSize; i++) {
uint8_t *data = reinterpret_cast<uint8_t *>(commandStream->getCpuBase());
if (data[i] != 0) {
isLeftoverZeroed = false;
break;
}
}
EXPECT_TRUE(isLeftoverZeroed);
commandQueue->destroy();
}
template <GFXCORE_FAMILY gfxCoreFamily>
struct MockCommandQueueHwEstimateSizeTest : public MockCommandQueueHw<gfxCoreFamily> {

View File

@@ -330,6 +330,35 @@ HWTEST2_F(L0DebuggerTest, givenDebuggingEnabledWhenCommandListIsExecutedThenSbaB
commandList->destroy();
}
HWTEST2_F(L0DebuggerTest, givenDebugerEnabledWhenPrepareAndSubmitBatchBufferThenLeftoverIsZeroed, Gen12Plus) {
ze_command_queue_desc_t queueDesc = {};
std::unique_ptr<MockCommandQueueHw<gfxCoreFamily>, Deleter> commandQueue(new MockCommandQueueHw<gfxCoreFamily>(device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc));
commandQueue->initialize(false, false);
auto &commandStream = commandQueue->commandStream;
auto estimatedSize = 4096u;
NEO::LinearStream linearStream(commandStream->getSpace(estimatedSize), estimatedSize);
// fill with random data
memset(commandStream->getCpuBase(), 0xD, estimatedSize);
typename MockCommandQueueHw<gfxCoreFamily>::CommandListExecutionContext ctx{};
ctx.isDebugEnabled = true;
commandQueue->prepareAndSubmitBatchBuffer(ctx, linearStream);
// MI_BATCH_BUFFER END is added during prepareAndSubmitBatchBuffer
auto offsetInBytes = sizeof(typename FamilyType::MI_BATCH_BUFFER_END);
auto isLeftoverZeroed = true;
for (auto i = offsetInBytes; i < estimatedSize; i++) {
uint8_t *data = reinterpret_cast<uint8_t *>(commandStream->getCpuBase());
if (data[i] != 0) {
isLeftoverZeroed = false;
break;
}
}
EXPECT_TRUE(isLeftoverZeroed);
}
INSTANTIATE_TEST_CASE_P(SBAModesForDebugger, L0DebuggerParameterizedTests, ::testing::Values(0, 1));
struct L0DebuggerSingleAddressSpace : public Test<L0DebuggerHwFixture> {