feature: skip not needed event waits in in-order mode

Related-To: NEO-7966

Signed-off-by: Dunajski, Bartosz <bartosz.dunajski@intel.com>
This commit is contained in:
Dunajski, Bartosz
2023-10-02 09:09:37 +00:00
committed by Compute-Runtime-Automation
parent 0461af492d
commit b4733dedb7
5 changed files with 72 additions and 8 deletions

View File

@@ -329,7 +329,7 @@ struct CommandListCoreFamily : CommandListImp {
NEO::PreemptionMode obtainKernelPreemptionMode(Kernel *kernel);
virtual bool isRelaxedOrderingDispatchAllowed(uint32_t numWaitEvents) const { return false; }
virtual void setupFlushMethod(const NEO::RootDeviceEnvironment &rootDeviceEnvironment) {}
bool isInOrderEventWaitRequired(const Event &event) const;
bool canSkipInOrderEventWait(const Event &event) const;
void handleInOrderImplicitDependencies(bool relaxedOrderingAllowed);
virtual void handleInOrderDependencyCounter(Event *signalEvent);
bool isQwordInOrderCounter() const { return GfxFamily::isQwordInOrderCounter; }

View File

@@ -2330,8 +2330,13 @@ void CommandListCoreFamily<gfxCoreFamily>::appendWaitOnInOrderDependency(NEO::Gr
}
template <GFXCORE_FAMILY gfxCoreFamily>
bool CommandListCoreFamily<gfxCoreFamily>::isInOrderEventWaitRequired(const Event &event) const {
return (event.getInOrderExecDataAllocation() != &inOrderExecInfo->inOrderDependencyCounterAllocation);
bool CommandListCoreFamily<gfxCoreFamily>::canSkipInOrderEventWait(const Event &event) const {
if (isInOrderExecutionEnabled()) {
return ((this->cmdListType == TYPE_IMMEDIATE && event.getLatestUsedCmdQueue() == this->cmdQImmediate) || // 1. Immediate CmdList can skip "regular Events" from the same CmdList
(event.getInOrderExecDataAllocation() == &inOrderExecInfo->inOrderDependencyCounterAllocation)); // 2. Both Immediate and Regular CmdLists can skip "in-order Events" from the same CmdList
}
return false;
}
template <GFXCORE_FAMILY gfxCoreFamily>
@@ -2375,7 +2380,8 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendWaitOnEvents(uint32_t nu
for (uint32_t i = 0; i < numEvents; i++) {
auto event = Event::fromHandle(phEvent[i]);
if (this->cmdListType == TYPE_IMMEDIATE && event->isAlreadyCompleted()) {
if ((this->cmdListType == TYPE_IMMEDIATE && event->isAlreadyCompleted()) ||
canSkipInOrderEventWait(*event)) {
continue;
}
@@ -2383,9 +2389,9 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendWaitOnEvents(uint32_t nu
if (!event->getInOrderExecDataAllocation()) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT; // in-order event not signaled yet
}
if (isInOrderEventWaitRequired(*event)) {
CommandListCoreFamily<gfxCoreFamily>::appendWaitOnInOrderDependency(event->getInOrderExecDataAllocation(), event->getInOrderExecSignalValue(), event->getInOrderAllocationOffset(), relaxedOrderingAllowed, false);
}
CommandListCoreFamily<gfxCoreFamily>::appendWaitOnInOrderDependency(event->getInOrderExecDataAllocation(), event->getInOrderExecSignalValue(), event->getInOrderAllocationOffset(), relaxedOrderingAllowed, false);
continue;
}

View File

@@ -494,7 +494,7 @@ bool CommandListCoreFamilyImmediate<gfxCoreFamily>::isSkippingInOrderBarrierAllo
uint32_t eventsToWait = numWaitEvents;
for (uint32_t i = 0; i < numWaitEvents; i++) {
if (!CommandListCoreFamily<gfxCoreFamily>::isInOrderEventWaitRequired(*Event::fromHandle(phWaitEvents[i]))) {
if (CommandListCoreFamily<gfxCoreFamily>::canSkipInOrderEventWait(*Event::fromHandle(phWaitEvents[i]))) {
eventsToWait--;
}
}

View File

@@ -227,6 +227,7 @@ struct Event : _ze_event_handle_t {
return &referenceTs;
}
void setReferenceTs(uint64_t currentCpuTimeStamp);
const CommandQueue *getLatestUsedCmdQueue() const { return latestUsedCmdQueue; }
bool hasKerneMappedTsCapability = false;
protected:

View File

@@ -1206,6 +1206,63 @@ HWTEST2_F(InOrderCmdListTests, givenInOrderModeWhenWaitingForEventFromPreviousAp
EXPECT_EQ(cmdList.end(), itor);
}
HWTEST2_F(InOrderCmdListTests, givenInOrderModeWhenWaitingForEventFromPreviousAppendOnRegularCmdListThenSkip, IsAtLeastSkl) {
using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT;
auto regularCmdList = createRegularCmdList<gfxCoreFamily>(false);
auto eventPool = createEvents<FamilyType>(1, false);
auto eventHandle = events[0]->toHandle();
auto cmdStream = regularCmdList->getCmdContainer().getCommandStream();
regularCmdList->appendLaunchKernel(kernel->toHandle(), groupCount, eventHandle, 0, nullptr, launchParams, false);
auto offset = cmdStream->getUsed();
regularCmdList->appendLaunchKernel(kernel->toHandle(), groupCount, nullptr, 1, &eventHandle, launchParams, false);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(cmdList, ptrOffset(cmdStream->getCpuBase(), offset), cmdStream->getUsed() - offset));
auto itor = find<typename FamilyType::MI_SEMAPHORE_WAIT *>(cmdList.begin(), cmdList.end());
ASSERT_NE(cmdList.end(), itor); // implicit dependency
itor = find<typename FamilyType::MI_SEMAPHORE_WAIT *>(++itor, cmdList.end());
EXPECT_EQ(cmdList.end(), itor);
}
HWTEST2_F(InOrderCmdListTests, givenInOrderModeWhenWaitingForRegularEventFromPreviousAppendThenSkip, IsAtLeastSkl) {
using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT;
auto immCmdList = createImmCmdList<gfxCoreFamily>();
auto eventPool = createEvents<FamilyType>(1, false);
events[0]->inOrderExecEvent = false;
auto eventHandle = events[0]->toHandle();
auto cmdStream = immCmdList->getCmdContainer().getCommandStream();
immCmdList->appendLaunchKernel(kernel->toHandle(), groupCount, eventHandle, 0, nullptr, launchParams, false);
auto offset = cmdStream->getUsed();
immCmdList->appendLaunchKernel(kernel->toHandle(), groupCount, nullptr, 1, &eventHandle, launchParams, false);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(cmdList, ptrOffset(cmdStream->getCpuBase(), offset), cmdStream->getUsed() - offset));
auto itor = find<typename FamilyType::MI_SEMAPHORE_WAIT *>(cmdList.begin(), cmdList.end());
ASSERT_NE(cmdList.end(), itor); // implicit dependency
itor = find<typename FamilyType::MI_SEMAPHORE_WAIT *>(++itor, cmdList.end());
EXPECT_EQ(cmdList.end(), itor);
}
HWTEST2_F(InOrderCmdListTests, givenInOrderModeWhenWaitingForEventFromAfterResetThenDontSkip, IsAtLeastXeHpCore) {
auto immCmdList = createImmCmdList<gfxCoreFamily>();