From 83a903764037f2d86aa8a1ac02ea1a234d5e6e55 Mon Sep 17 00:00:00 2001 From: Bartosz Dunajski Date: Thu, 12 May 2022 12:13:48 +0000 Subject: [PATCH] Revert async Event destruction This reverts f9a5f8a86e966eabf4d09b6cf82d71ec1a7d0977 and f89c731a11464f8feb0e46b50d3a1e9f8d499ad9 Signed-off-by: Bartosz Dunajski --- opencl/source/api/api.cpp | 1 - opencl/source/event/async_events_handler.cpp | 6 +- opencl/source/event/event.cpp | 10 --- opencl/source/event/event.h | 5 -- .../unit_test/api/cl_release_event_tests.inl | 7 +- .../command_queue_hw_1_tests.cpp | 7 +- .../event/async_events_handler_tests.cpp | 76 +------------------ 7 files changed, 6 insertions(+), 106 deletions(-) diff --git a/opencl/source/api/api.cpp b/opencl/source/api/api.cpp index d29232cec6..67bdbf6685 100644 --- a/opencl/source/api/api.cpp +++ b/opencl/source/api/api.cpp @@ -2159,7 +2159,6 @@ cl_int CL_API_CALL clReleaseEvent(cl_event event) { DBG_LOG_INPUTS("cl_event", event, "Event", pEvent); if (pEvent) { - pEvent->handleCompletionBeforeDestruction(); pEvent->release(); TRACING_EXIT(clReleaseEvent, &retVal); return retVal; diff --git a/opencl/source/event/async_events_handler.cpp b/opencl/source/event/async_events_handler.cpp index 62c42ffaf3..7619721e7b 100644 --- a/opencl/source/event/async_events_handler.cpp +++ b/opencl/source/event/async_events_handler.cpp @@ -44,11 +44,7 @@ Event *AsyncEventsHandler::processList() { for (auto event : list) { event->updateExecutionStatus(); - - bool eventNotReady = (event->peekExecutionStatus() > CL_COMPLETE); - bool trackDeferredDeletion = event->isDeletionDeferred() && eventNotReady; - - if (event->peekHasCallbacks() || (event->isExternallySynchronized() && eventNotReady) || trackDeferredDeletion) { + if (event->peekHasCallbacks() || (event->isExternallySynchronized() && (event->peekExecutionStatus() > CL_COMPLETE))) { pendingList.push_back(event); if (event->peekTaskCount() < lowestTaskCount) { sleepCandidate = event; diff --git a/opencl/source/event/event.cpp b/opencl/source/event/event.cpp index f600144432..142a62c6a1 100644 --- a/opencl/source/event/event.cpp +++ b/opencl/source/event/event.cpp @@ -144,16 +144,6 @@ Event::~Event() { unblockEventsBlockedByThis(executionStatus); } -void Event::handleCompletionBeforeDestruction() { - if (!cmdQueue || isCompleted() || peekExecutionStatus() < 0 || (getRefInternalCount() > 1)) { - return; - } - - this->deletionDeferredToAsyncThread = true; - cmdQueue->flush(); - ctx->getAsyncEventsHandler().registerEvent(this); -} - cl_int Event::getEventProfilingInfo(cl_profiling_info paramName, size_t paramValueSize, void *paramValue, diff --git a/opencl/source/event/event.h b/opencl/source/event/event.h index 3d32f059d5..bdc441471d 100644 --- a/opencl/source/event/event.h +++ b/opencl/source/event/event.h @@ -301,16 +301,12 @@ class Event : public BaseObject<_cl_event>, public IDNode { this->cmdType = cmdType; } - void handleCompletionBeforeDestruction(); - std::vector &getParentEvents() { return this->parentEvents; } virtual bool isExternallySynchronized() const { return false; } - bool isDeletionDeferred() const { return deletionDeferredToAsyncThread; } - static bool checkUserEventDependencies(cl_uint numEventsInWaitList, const cl_event *eventWaitList); static void getBoundaryTimestampValues(TimestampPacketContainer *timestampContainer, uint64_t &globalStartTS, uint64_t &globalEndTS); @@ -383,7 +379,6 @@ class Event : public BaseObject<_cl_event>, public IDNode { bool profilingEnabled; bool profilingCpuPath; bool dataCalculated; - bool deletionDeferredToAsyncThread = false; TimeStampData queueTimeStamp; TimeStampData submitTimeStamp; uint64_t startTimeStamp; diff --git a/opencl/test/unit_test/api/cl_release_event_tests.inl b/opencl/test/unit_test/api/cl_release_event_tests.inl index 0cf2d1265f..a77e62152a 100644 --- a/opencl/test/unit_test/api/cl_release_event_tests.inl +++ b/opencl/test/unit_test/api/cl_release_event_tests.inl @@ -9,7 +9,6 @@ #include "opencl/source/context/context.h" #include "opencl/source/event/event.h" -#include "opencl/test/unit_test/mocks/mock_event.h" #include "cl_api_tests.h" @@ -36,7 +35,7 @@ TEST_F(clEventTests, GivenNullEventWhenReleasingEventThenClInvalidEventErrorIsRe } TEST_F(clEventTests, GivenValidEventWhenReleasingEventThenSuccessIsReturned) { - auto *pEvent = new MockEvent(pContext, pCommandQueue, CL_COMMAND_NDRANGE_KERNEL, 0, 0); + auto *pEvent = new Event(nullptr, 0, 0, 0); ASSERT_NE(nullptr, pEvent); cl_event event = (cl_event)pEvent; @@ -46,7 +45,7 @@ TEST_F(clEventTests, GivenValidEventWhenReleasingEventThenSuccessIsReturned) { } TEST_F(clEventTests, GivenValidEventWhenRetainedAndReleasedThenReferenceCountIsUpdated) { - auto *pEvent = new MockEvent(pContext, pCommandQueue, CL_COMMAND_NDRANGE_KERNEL, 0, 0); + auto *pEvent = new Event(nullptr, 0, 0, 0); ASSERT_NE(nullptr, pEvent); cl_event event = (cl_event)pEvent; @@ -62,7 +61,7 @@ TEST_F(clEventTests, GivenValidEventWhenRetainedAndReleasedThenReferenceCountIsU } TEST_F(clEventTests, GivenValidEventWhenRetainedAndReleasedTwiceThenClSuccessIsReturned) { - auto *pEvent = new MockEvent(pContext, pCommandQueue, CL_COMMAND_NDRANGE_KERNEL, 0, 0); + auto *pEvent = new Event(nullptr, 0, 0, 0); ASSERT_NE(nullptr, pEvent); cl_event event = (cl_event)pEvent; diff --git a/opencl/test/unit_test/command_queue/command_queue_hw_1_tests.cpp b/opencl/test/unit_test/command_queue/command_queue_hw_1_tests.cpp index f18b5459d1..c6863cca66 100644 --- a/opencl/test/unit_test/command_queue/command_queue_hw_1_tests.cpp +++ b/opencl/test/unit_test/command_queue/command_queue_hw_1_tests.cpp @@ -861,12 +861,7 @@ HWTEST_F(CommandQueueHwTest, givenCommandQueueThatIsBlockedAndUsesCpuCopyWhenEve EventsRequest eventsRequest(0, nullptr, &returnEvent); cmdQHw->cpuDataTransferHandler(transferProperties, eventsRequest, retVal); EXPECT_EQ(CL_SUCCESS, retVal); - - auto neoEvent = castToObject(returnEvent); - - EXPECT_EQ(CompletionStamp::notReady, neoEvent->peekTaskCount()); - - neoEvent->updateTaskCount(1, 1); + EXPECT_EQ(CompletionStamp::notReady, castToObject(returnEvent)->peekTaskCount()); clReleaseEvent(returnEvent); } diff --git a/opencl/test/unit_test/event/async_events_handler_tests.cpp b/opencl/test/unit_test/event/async_events_handler_tests.cpp index 0d5026d719..72e2a5b077 100644 --- a/opencl/test/unit_test/event/async_events_handler_tests.cpp +++ b/opencl/test/unit_test/event/async_events_handler_tests.cpp @@ -18,7 +18,6 @@ #include "opencl/test/unit_test/mocks/mock_async_event_handler.h" #include "opencl/test/unit_test/mocks/mock_command_queue.h" #include "opencl/test/unit_test/mocks/mock_context.h" -#include "opencl/test/unit_test/mocks/mock_event.h" using namespace NEO; using namespace ::testing; @@ -55,10 +54,6 @@ class AsyncEventsHandlerTests : public ::testing::Test { ++(*(int *)data); } - void setTagValue(uint32_t newValue) { - *(commandQueue->getGpgpuCommandStreamReceiver().getTagAddress()) = newValue; - } - void SetUp() override { dbgRestore.reset(new DebugManagerStateRestore()); DebugManager.flags.EnableAsyncEventsHandler.set(false); @@ -67,7 +62,7 @@ class AsyncEventsHandlerTests : public ::testing::Test { commandQueue = make_releaseable(context.get(), context->getDevice(0), nullptr, false); - setTagValue(0); + *(commandQueue->getGpgpuCommandStreamReceiver().getTagAddress()) = 0; event1 = make_releaseable(context.get(), commandQueue.get(), CL_COMMAND_BARRIER, CompletionStamp::notReady, CompletionStamp::notReady); event2 = make_releaseable(context.get(), commandQueue.get(), CL_COMMAND_BARRIER, CompletionStamp::notReady, CompletionStamp::notReady); @@ -316,75 +311,6 @@ TEST_F(AsyncEventsHandlerTests, givenUserEventWhenCallbackIsAddedThenDontRegiste userEvent.decRefInternal(); } -TEST_F(AsyncEventsHandlerTests, givenNotReadyEventWhenReleasingThenRegisterAndTrackUntilCompleted) { - DebugManager.flags.EnableAsyncEventsHandler.set(true); - auto myHandler = new MockHandler(false); - context->getAsyncEventsHandlerUniquePtr().reset(myHandler); - - constexpr uint32_t eventTaskCount = 1; - setTagValue(0); - - auto mockEvent = new MockEvent(context.get(), commandQueue.get(), CL_COMMAND_NDRANGE_KERNEL, 0, eventTaskCount); - - EXPECT_TRUE(myHandler->peekIsRegisterListEmpty()); - clReleaseEvent(mockEvent); - EXPECT_FALSE(myHandler->peekIsRegisterListEmpty()); - - EXPECT_TRUE(myHandler->peekIsListEmpty()); - myHandler->process(); - EXPECT_FALSE(myHandler->peekIsListEmpty()); - - setTagValue(eventTaskCount); - myHandler->process(); - EXPECT_TRUE(myHandler->peekIsRegisterListEmpty()); - EXPECT_TRUE(myHandler->peekIsListEmpty()); -} - -TEST_F(AsyncEventsHandlerTests, givenTerminatedEventWhenReleasingThenDontRegister) { - DebugManager.flags.EnableAsyncEventsHandler.set(true); - auto myHandler = new MockHandler(false); - context->getAsyncEventsHandlerUniquePtr().reset(myHandler); - - constexpr uint32_t eventTaskCount = 1; - setTagValue(0); - - auto mockEvent = new MockEvent(context.get(), commandQueue.get(), CL_COMMAND_NDRANGE_KERNEL, 0, eventTaskCount); - mockEvent->setStatus(-1); - - clReleaseEvent(mockEvent); - EXPECT_TRUE(myHandler->peekIsRegisterListEmpty()); -} - -TEST_F(AsyncEventsHandlerTests, givenNotReadyEventWithRefCountWhenReleasingThenDontRegister) { - DebugManager.flags.EnableAsyncEventsHandler.set(true); - auto myHandler = new MockHandler(false); - context->getAsyncEventsHandlerUniquePtr().reset(myHandler); - - constexpr uint32_t eventTaskCount = 1; - setTagValue(0); - - auto mockEvent = new MockEvent(context.get(), commandQueue.get(), CL_COMMAND_NDRANGE_KERNEL, 0, eventTaskCount); - mockEvent->incRefInternal(); - - clReleaseEvent(mockEvent); - EXPECT_TRUE(myHandler->peekIsRegisterListEmpty()); - - setTagValue(eventTaskCount); - mockEvent->decRefInternal(); -} - -TEST_F(AsyncEventsHandlerTests, givenEventWithoutCommandQueueWhenReleasingThenDontRegister) { - DebugManager.flags.EnableAsyncEventsHandler.set(true); - auto myHandler = new MockHandler(false); - context->getAsyncEventsHandlerUniquePtr().reset(myHandler); - - auto userEvent = new UserEvent(context.get()); - userEvent->setStatus(CL_QUEUED); - - clReleaseEvent(userEvent); - EXPECT_TRUE(myHandler->peekIsRegisterListEmpty()); -} - TEST_F(AsyncEventsHandlerTests, givenRegistredEventsWhenProcessIsCalledThenReturnCandidateWithLowestTaskCount) { int event1Counter(0), event2Counter(0), event3Counter(0);