Skip to content

Commit 34a7059

Browse files
Avoid reading command buffer in flushed batched submissions
Signed-off-by: Lukasz Jobczyk <[email protected]>
1 parent cdd2cd7 commit 34a7059

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_3_tests.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,9 +996,13 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenCommandA
996996

997997
parseCommands<FamilyType>(commandStream);
998998
auto itorPipeControl = find<typename FamilyType::PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
999+
if (MemorySynchronizationCommands<FamilyType>::isPipeControlWArequired(pDevice->getHardwareInfo())) {
1000+
itorPipeControl++;
1001+
}
9991002
auto pipeControl = genCmdCast<typename FamilyType::PIPE_CONTROL *>(*itorPipeControl);
10001003

10011004
mockCsr->flushBatchedSubmissions();
1005+
10021006
EXPECT_EQ(MemorySynchronizationCommands<FamilyType>::getDcFlushEnable(true, *defaultHwInfo), pipeControl->getDcFlushEnable());
10031007
}
10041008

@@ -1028,9 +1032,13 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWithOutOfOrd
10281032

10291033
parseCommands<FamilyType>(commandStream);
10301034
auto itorPipeControl = find<typename FamilyType::PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
1035+
if (MemorySynchronizationCommands<FamilyType>::isPipeControlWArequired(pDevice->getHardwareInfo())) {
1036+
itorPipeControl++;
1037+
}
10311038
auto pipeControl = genCmdCast<typename FamilyType::PIPE_CONTROL *>(*itorPipeControl);
10321039

10331040
mockCsr->flushBatchedSubmissions();
1041+
10341042
EXPECT_EQ(MemorySynchronizationCommands<FamilyType>::getDcFlushEnable(true, *defaultHwInfo), pipeControl->getDcFlushEnable());
10351043
}
10361044

@@ -1233,8 +1241,16 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenEpiloguePipeControlThenDcFlus
12331241
ASSERT_NE(nullptr, cmdBuffer->epiloguePipeControlLocation);
12341242
auto pipeControl = genCmdCast<PIPE_CONTROL *>(cmdBuffer->epiloguePipeControlLocation);
12351243
ASSERT_NE(nullptr, pipeControl);
1244+
parseCommands<FamilyType>(commandStream);
1245+
auto itorPipeControl = find<typename FamilyType::PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
1246+
if (MemorySynchronizationCommands<FamilyType>::isPipeControlWArequired(pDevice->getHardwareInfo())) {
1247+
itorPipeControl++;
1248+
}
1249+
auto pipeControlCmdBuffer = genCmdCast<typename FamilyType::PIPE_CONTROL *>(*itorPipeControl);
1250+
12361251
mockCsr->flushBatchedSubmissions();
1237-
EXPECT_EQ(MemorySynchronizationCommands<FamilyType>::getDcFlushEnable(true, *defaultHwInfo), pipeControl->getDcFlushEnable());
1252+
1253+
EXPECT_EQ(MemorySynchronizationCommands<FamilyType>::getDcFlushEnable(true, *defaultHwInfo), pipeControlCmdBuffer->getDcFlushEnable());
12381254
}
12391255

12401256
HWTEST_F(CommandStreamReceiverFlushTaskTests, givenEpiloguePipeControlWhendDcFlushDisabledByDebugFlagThenDcFlushIsDisabled) {

shared/source/command_stream/command_stream_receiver_hw_base.inl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
187187
bool implicitFlush = dispatchFlags.implicitFlush || dispatchFlags.blocking || DebugManager.flags.ForceImplicitFlush.get();
188188
void *currentPipeControlForNooping = nullptr;
189189
void *epiloguePipeControlLocation = nullptr;
190+
PipeControlArgs args;
190191

191192
bool csrFlush = this->wasSubmittedToSingleSubdevice != dispatchFlags.useSingleSubdevice;
192193

@@ -226,7 +227,6 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
226227

227228
auto address = getTagAllocation()->getGpuAddress();
228229

229-
PipeControlArgs args;
230230
args.dcFlushEnable = MemorySynchronizationCommands<GfxFamily>::getDcFlushEnable(dispatchFlags.dcFlush, hwInfo);
231231
args.notifyEnable = isUsedNotifyEnableForPostSync();
232232
args.tlbInvalidation |= dispatchFlags.memoryMigrationRequired;
@@ -613,6 +613,7 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
613613
commandBuffer->flushStamp->replaceStampObject(dispatchFlags.flushStampReference);
614614
commandBuffer->pipeControlThatMayBeErasedLocation = currentPipeControlForNooping;
615615
commandBuffer->epiloguePipeControlLocation = epiloguePipeControlLocation;
616+
commandBuffer->epiloguePipeControlArgs = args;
616617
this->submissionAggregator->recordCommandBuffer(commandBuffer);
617618
}
618619
} else {
@@ -716,6 +717,7 @@ inline bool CommandStreamReceiverHw<GfxFamily>::flushBatchedSubmissions() {
716717
auto nextCommandBuffer = commandBufferList.peekHead();
717718
auto currentBBendLocation = primaryCmdBuffer->batchBufferEndLocation;
718719
auto lastTaskCount = primaryCmdBuffer->taskCount;
720+
auto lastPipeControlArgs = primaryCmdBuffer->epiloguePipeControlArgs;
719721

720722
FlushStampUpdateHelper flushStampUpdateHelper;
721723
flushStampUpdateHelper.insert(primaryCmdBuffer->flushStamp->getStampReference());
@@ -760,6 +762,7 @@ inline bool CommandStreamReceiverHw<GfxFamily>::flushBatchedSubmissions() {
760762

761763
currentBBendLocation = nextCommandBuffer->batchBufferEndLocation;
762764
lastTaskCount = nextCommandBuffer->taskCount;
765+
lastPipeControlArgs = nextCommandBuffer->epiloguePipeControlArgs;
763766
nextCommandBuffer = nextCommandBuffer->next;
764767

765768
commandBufferList.removeFrontOne();
@@ -771,13 +774,19 @@ inline bool CommandStreamReceiverHw<GfxFamily>::flushBatchedSubmissions() {
771774

772775
// make sure we flush DC if needed
773776
if (epiloguePipeControlLocation && MemorySynchronizationCommands<GfxFamily>::getDcFlushEnable(true, hwInfo)) {
777+
lastPipeControlArgs.dcFlushEnable = true;
774778

775-
auto emitDcFlush = true;
776779
if (DebugManager.flags.DisableDcFlushInEpilogue.get()) {
777-
emitDcFlush = false;
780+
lastPipeControlArgs.dcFlushEnable = false;
778781
}
779782

780-
((PIPE_CONTROL *)epiloguePipeControlLocation)->setDcFlushEnable(emitDcFlush);
783+
MemorySynchronizationCommands<GfxFamily>::setPipeControlAndProgramPostSyncOperation(
784+
epiloguePipeControlLocation,
785+
PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA,
786+
getTagAllocation()->getGpuAddress(),
787+
lastTaskCount,
788+
hwInfo,
789+
lastPipeControlArgs);
781790
}
782791

783792
primaryCmdBuffer->batchBuffer.endCmdPtr = currentBBendLocation;

shared/source/command_stream/submissions_aggregator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#pragma once
99
#include "shared/source/command_stream/csr_definitions.h"
1010
#include "shared/source/command_stream/linear_stream.h"
11+
#include "shared/source/helpers/pipe_control_args.h"
1112
#include "shared/source/memory_manager/residency_container.h"
1213
#include "shared/source/utilities/idlist.h"
1314
#include "shared/source/utilities/stackvec.h"
@@ -60,6 +61,7 @@ struct CommandBuffer : public IDNode<CommandBuffer> {
6061
uint32_t taskCount = 0u;
6162
void *pipeControlThatMayBeErasedLocation = nullptr;
6263
void *epiloguePipeControlLocation = nullptr;
64+
PipeControlArgs epiloguePipeControlArgs;
6365
std::unique_ptr<FlushStampTracker> flushStamp;
6466
Device &device;
6567
};

0 commit comments

Comments
 (0)