refactor: unify completion check methods

Signed-off-by: Dunajski, Bartosz <bartosz.dunajski@intel.com>
This commit is contained in:
Dunajski, Bartosz 2023-07-25 12:28:31 +00:00 committed by Compute-Runtime-Automation
parent af559e4fac
commit 6656e23b86
6 changed files with 25 additions and 33 deletions

View File

@ -419,13 +419,17 @@ volatile TagAddressType *CommandQueue::getHwTagAddress() const {
return getGpgpuCommandStreamReceiver().getTagAddress();
}
bool CommandQueue::isCompleted(TaskCountType gpgpuTaskCount, CopyEngineState bcsState) {
bool CommandQueue::isCompleted(TaskCountType gpgpuTaskCount, const Range<CopyEngineState> &bcsStates) {
DEBUG_BREAK_IF(getHwTag() == CompletionStamp::notReady);
if (getGpgpuCommandStreamReceiver().testTaskCountReady(getHwTagAddress(), gpgpuTaskCount)) {
if (bcsState.isValid()) {
auto bcsCsr = getBcsCommandStreamReceiver(bcsState.engineType);
return bcsCsr->testTaskCountReady(bcsCsr->getTagAddress(), peekBcsTaskCount(bcsState.engineType));
for (auto &bcsState : bcsStates) {
if (bcsState.isValid()) {
auto bcsCsr = getBcsCommandStreamReceiver(bcsState.engineType);
if (!bcsCsr->testTaskCountReady(bcsCsr->getTagAddress(), peekBcsTaskCount(bcsState.engineType))) {
return false;
}
}
}
return true;
@ -1380,7 +1384,7 @@ bool CommandQueue::migrateMultiGraphicsAllocationsIfRequired(const BuiltinOpPara
void CommandQueue::tryReleaseDeferredNodes(bool checkEventsState) {
TakeOwnershipWrapper<CommandQueue> queueOwnership(*this);
if (checkEventsState && !allEnginesReady()) {
if (checkEventsState && !isCompleted(this->taskCount, this->bcsStates)) {
return;
}
@ -1394,21 +1398,4 @@ void CommandQueue::tryReleaseDeferredNodes(bool checkEventsState) {
}
}
bool CommandQueue::allEnginesReady() {
if (getGpgpuCommandStreamReceiver().testTaskCountReady(getHwTagAddress(), this->taskCount)) {
for (auto &bcsState : bcsStates) {
if (bcsState.isValid()) {
auto bcsCsr = getBcsCommandStreamReceiver(bcsState.engineType);
if (!bcsCsr->testTaskCountReady(bcsCsr->getTagAddress(), peekBcsTaskCount(bcsState.engineType))) {
return false;
}
}
}
return true;
}
return false;
}
} // namespace NEO

View File

@ -214,7 +214,7 @@ class CommandQueue : public BaseObject<_cl_command_queue> {
volatile TagAddressType *getHwTagAddress() const;
MOCKABLE_VIRTUAL bool isCompleted(TaskCountType gpgpuTaskCount, CopyEngineState bcsState);
MOCKABLE_VIRTUAL bool isCompleted(TaskCountType gpgpuTaskCount, const Range<CopyEngineState> &bcsStates);
bool isWaitForTimestampsEnabled() const;
virtual bool waitForTimestamps(Range<CopyEngineState> copyEnginesToWait, WaitStatus &status, TimestampPacketContainer *mainContainer, TimestampPacketContainer *deferredContainer) = 0;
@ -379,8 +379,6 @@ class CommandQueue : public BaseObject<_cl_command_queue> {
void tryReleaseDeferredNodes(bool checkEventsState);
bool allEnginesReady();
protected:
void *enqueueReadMemObjForMap(TransferProperties &transferProperties, EventsRequest &eventsRequest, cl_int &errcodeRet);
cl_int enqueueWriteMemObjForUnmap(MemObj *memObj, void *mappedPtr, EventsRequest &eventsRequest);

View File

@ -711,7 +711,9 @@ bool Event::isCompleted() {
return true;
}
if (cmdQueue->isCompleted(getCompletionStamp(), this->bcsState) || this->areTimestampsCompleted()) {
Range<CopyEngineState> states{&bcsState, bcsState.isValid() ? 1u : 0u};
if (cmdQueue->isCompleted(getCompletionStamp(), states) || this->areTimestampsCompleted()) {
gpuStateWaited = true;
}

View File

@ -187,22 +187,25 @@ HWTEST_F(clEnqueueWaitForEventsTests, givenAlreadyCompletedEventWhenWaitForCompl
auto retVal = clEnqueueWaitForEvents(pCommandQueue, 1, &hEvent1);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(3u, pCommandQueue->isCompletedCalled);
EXPECT_EQ(4u, pCommandQueue->isCompletedCalled);
// Event 2
retVal = clEnqueueWaitForEvents(pCommandQueue, 1, &hEvent2);
EXPECT_EQ(CL_SUCCESS, retVal);
// clEnqueueWaitForEvents signals completion before isCompletedCalled()
EXPECT_EQ(3u, pCommandQueue->isCompletedCalled);
EXPECT_EQ(5u, pCommandQueue->isCompletedCalled);
retVal = clEnqueueWaitForEvents(pCommandQueue, 1, &hEvent2);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(3u, pCommandQueue->isCompletedCalled);
EXPECT_EQ(6u, pCommandQueue->isCompletedCalled);
event2.updateExecutionStatus();
EXPECT_EQ(3u, pCommandQueue->isCompletedCalled);
EXPECT_EQ(6u, pCommandQueue->isCompletedCalled);
event2.isCompleted();
EXPECT_EQ(6u, pCommandQueue->isCompletedCalled);
}
struct GTPinMockCommandQueue : MockCommandQueue {

View File

@ -78,9 +78,11 @@ HWTEST_F(CommandQueueHwTest, whenCallingIsCompletedThenTestTaskCountValue) {
cmdQ.bcsEngines[0] = &control;
cmdQ.bcsStates[0] = state;
Range<CopyEngineState> states{&state};
EXPECT_EQ(0u, ultCsr.downloadAllocationsCalledCount);
EXPECT_EQ(0u, bcsCsr->downloadAllocationsCalledCount);
cmdQ.isCompleted(1, state);
cmdQ.isCompleted(1, states);
EXPECT_EQ(1u, ultCsr.downloadAllocationsCalledCount);
EXPECT_EQ(1u, bcsCsr->downloadAllocationsCalledCount);
}

View File

@ -224,10 +224,10 @@ class MockCommandQueue : public CommandQueue {
return false;
};
bool isCompleted(TaskCountType gpgpuTaskCount, CopyEngineState bcsState) override {
bool isCompleted(TaskCountType gpgpuTaskCount, const Range<CopyEngineState> &bcsStates) override {
isCompletedCalled++;
return CommandQueue::isCompleted(gpgpuTaskCount, bcsState);
return CommandQueue::isCompleted(gpgpuTaskCount, bcsStates);
}
bool releaseIndirectHeapCalled = false;