From baa11187c3c4875604a1f6c96a10ecc029734cdd Mon Sep 17 00:00:00 2001 From: "Mrozek, Michal" Date: Mon, 8 Jul 2019 18:07:46 +0200 Subject: [PATCH] Simplify isStatusCompletedByTermination. - remove default parameter. - remove branch. Change-Id: Ia829adfc684057516a2fc204e853ad3948853e22 --- runtime/command_queue/command_queue.cpp | 5 +-- runtime/event/event.cpp | 14 ++++---- runtime/event/event.h | 8 ++--- runtime/event/user_event.cpp | 2 +- .../command_queue/command_queue_hw_tests.cpp | 33 +++++++++++++++++++ 5 files changed, 46 insertions(+), 16 deletions(-) diff --git a/runtime/command_queue/command_queue.cpp b/runtime/command_queue/command_queue.cpp index 2b518b589a..3c3204d97a 100644 --- a/runtime/command_queue/command_queue.cpp +++ b/runtime/command_queue/command_queue.cpp @@ -141,10 +141,11 @@ bool CommandQueue::isQueueBlocked() { TakeOwnershipWrapper takeOwnershipWrapper(*this); //check if we have user event and if so, if it is in blocked state. if (this->virtualEvent) { - if (this->virtualEvent->peekExecutionStatus() <= CL_SUBMITTED) { + auto executionStatus = this->virtualEvent->peekExecutionStatus(); + if (executionStatus <= CL_SUBMITTED) { UNRECOVERABLE_IF(this->virtualEvent == nullptr); - if (this->virtualEvent->isStatusCompletedByTermination() == false) { + if (this->virtualEvent->isStatusCompletedByTermination(executionStatus) == false) { taskCount = this->virtualEvent->peekTaskCount(); flushStamp->setStamp(this->virtualEvent->flushStamp->peekStamp()); taskLevel = this->virtualEvent->taskLevel; diff --git a/runtime/event/event.cpp b/runtime/event/event.cpp index 197f72f8c7..e111198f61 100644 --- a/runtime/event/event.cpp +++ b/runtime/event/event.cpp @@ -358,7 +358,7 @@ void Event::updateExecutionStatus() { } if (statusSnapshot == CL_QUEUED) { - bool abortBlockedTasks = isStatusCompletedByTermination(&statusSnapshot); + bool abortBlockedTasks = isStatusCompletedByTermination(statusSnapshot); submitCommand(abortBlockedTasks); transitionExecutionStatus(CL_SUBMITTED); executeCallbacks(CL_SUBMITTED); @@ -399,7 +399,7 @@ void Event::unblockEventsBlockedByThis(int32_t transitionStatus) { uint32_t taskLevelToPropagate = Event::eventNotReady; - if (isStatusCompletedByTermination(&transitionStatus) == false) { + if (isStatusCompletedByTermination(transitionStatus) == false) { //if we are event on top of the tree , obtain taskLevel from CSR if (taskLevel == Event::eventNotReady) { this->taskLevel = getTaskLevel(); @@ -435,12 +435,12 @@ bool Event::setStatus(cl_int status) { return false; } - if (peekIsBlocked() && (isStatusCompletedByTermination(&status) == false)) { + if (peekIsBlocked() && (isStatusCompletedByTermination(status) == false)) { return false; } if ((status == CL_SUBMITTED) || (isStatusCompleted(&status))) { - bool abortBlockedTasks = isStatusCompletedByTermination(&status); + bool abortBlockedTasks = isStatusCompletedByTermination(status); submitCommand(abortBlockedTasks); } @@ -563,7 +563,7 @@ inline void Event::unblockEventBy(Event &event, uint32_t taskLevel, int32_t tran int32_t blockerStatus = transitionStatus; DEBUG_BREAK_IF(!(isStatusCompleted(&blockerStatus) || peekIsSubmitted(&blockerStatus))); - if ((numEventsBlockingThis > 0) && (isStatusCompletedByTermination(&blockerStatus) == false)) { + if ((numEventsBlockingThis > 0) && (isStatusCompletedByTermination(blockerStatus) == false)) { return; } DBG_LOG(EventsDebugEnable, "Event", this, "is unblocked by", &event); @@ -575,7 +575,7 @@ inline void Event::unblockEventBy(Event &event, uint32_t taskLevel, int32_t tran } int32_t statusToPropagate = CL_SUBMITTED; - if (isStatusCompletedByTermination(&blockerStatus)) { + if (isStatusCompletedByTermination(blockerStatus)) { statusToPropagate = blockerStatus; } setStatus(statusToPropagate); @@ -625,7 +625,7 @@ void Event::addCallback(Callback::ClbFuncT fn, cl_int type, void *data) { void Event::executeCallbacks(int32_t executionStatusIn) { int32_t execStatus = executionStatusIn; - bool terminated = isStatusCompletedByTermination(&execStatus); + bool terminated = isStatusCompletedByTermination(execStatus); ECallbackTarget target; if (terminated) { target = ECallbackTarget::Completed; diff --git a/runtime/event/event.h b/runtime/event/event.h index 1dc592d5d9..aacecc2a5e 100644 --- a/runtime/event/event.h +++ b/runtime/event/event.h @@ -184,12 +184,8 @@ class Event : public BaseObject<_cl_event>, public IDNode { // Note from OCL spec : // "A negative integer value causes all enqueued commands that wait on this user event // to be terminated." - bool isStatusCompletedByTermination(const int32_t *executionStatusSnapshot = nullptr) const { - if (executionStatusSnapshot == nullptr) { - return (peekExecutionStatus() < 0); - } else { - return (*executionStatusSnapshot < 0); - } + bool isStatusCompletedByTermination(const int32_t executionStatusSnapshot) const { + return executionStatusSnapshot < 0; } bool peekIsSubmitted(const int32_t *executionStatusSnapshot = nullptr) const { diff --git a/runtime/event/user_event.cpp b/runtime/event/user_event.cpp index 6fd6839dac..fee093729f 100644 --- a/runtime/event/user_event.cpp +++ b/runtime/event/user_event.cpp @@ -76,7 +76,7 @@ uint32_t VirtualEvent::getTaskLevel() { bool VirtualEvent::setStatus(cl_int status) { // virtual events are just helper events and will have either // "waiting" (after construction) or "complete" (on change if not blocked) execution state - if (isStatusCompletedByTermination(&status) == false) { + if (isStatusCompletedByTermination(status) == false) { status = CL_COMPLETE; } return Event::setStatus(status); diff --git a/unit_tests/command_queue/command_queue_hw_tests.cpp b/unit_tests/command_queue/command_queue_hw_tests.cpp index 5a0d8dfea3..7960b51e43 100644 --- a/unit_tests/command_queue/command_queue_hw_tests.cpp +++ b/unit_tests/command_queue/command_queue_hw_tests.cpp @@ -898,6 +898,39 @@ HWTEST_F(CommandQueueHwTest, givenBlockedInOrderCmdQueueAndAsynchronouslyComplet event->decRefInternal(); } +HWTEST_F(CommandQueueHwTest, givenBlockedOutOfOrderQueueWhenUserEventIsSubmittedThenNDREventIsSubmittedAsWell) { + CommandQueueHw *cmdQHw = static_cast *>(this->pCmdQ); + auto &mockCsr = pDevice->getUltCommandStreamReceiver(); + + MockKernelWithInternals mockKernelWithInternals(*pDevice); + auto mockKernel = mockKernelWithInternals.mockKernel; + size_t offset = 0; + size_t size = 1; + + cl_event userEvent = clCreateUserEvent(this->pContext, nullptr); + cl_event blockedEvent = nullptr; + + *mockCsr.getTagAddress() = 0u; + cmdQHw->enqueueKernel(mockKernel, 1, &offset, &size, &size, 1, &userEvent, &blockedEvent); + + auto neoEvent = castToObject(blockedEvent); + EXPECT_EQ(neoEvent->peekExecutionStatus(), CL_QUEUED); + + neoEvent->updateExecutionStatus(); + + EXPECT_EQ(neoEvent->peekExecutionStatus(), CL_QUEUED); + EXPECT_EQ(neoEvent->peekTaskCount(), Event::eventNotReady); + + clSetUserEventStatus(userEvent, 0u); + + EXPECT_EQ(neoEvent->peekExecutionStatus(), CL_SUBMITTED); + EXPECT_EQ(neoEvent->peekTaskCount(), 1u); + + *mockCsr.getTagAddress() = initialHardwareTag; + clReleaseEvent(blockedEvent); + clReleaseEvent(userEvent); +} + HWTEST_F(OOQueueHwTest, givenBlockedOutOfOrderCmdQueueAndAsynchronouslyCompletedEventWhenEnqueueCompletesVirtualEventThenUpdatedTaskLevelIsPassedToEnqueueAndFlushTask) { CommandQueueHw *cmdQHw = static_cast *>(this->pCmdQ);