diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.inl b/level_zero/core/source/cmdlist/cmdlist_hw.inl index dd7f942ec7..6347637d9f 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw.inl @@ -400,7 +400,7 @@ ze_result_t CommandListCoreFamily::appendEventReset(ze_event_hand packetsToReset = event->getMaxPacketsCount(); } event->resetPackets(false); - event->resetCompletionStatus(); + event->resetCompletionStatus(true); commandContainer.addToResidencyContainer(&event->getAllocation(this->device)); const auto &hwInfo = this->device->getHwInfo(); if (isCopyOnly()) { diff --git a/level_zero/core/source/event/event.h b/level_zero/core/source/event/event.h index 4205fea960..fea60be1fc 100644 --- a/level_zero/core/source/event/event.h +++ b/level_zero/core/source/event/event.h @@ -45,6 +45,7 @@ struct Event : _ze_event_handle_t { virtual ze_result_t queryTimestampsExp(Device *device, uint32_t *pCount, ze_kernel_timestamp_result_t *pTimestamps) = 0; enum State : uint32_t { STATE_SIGNALED = 0u, + HOST_CACHING_DISABLED = std::numeric_limits::max() - 1, STATE_CLEARED = std::numeric_limits::max(), STATE_INITIAL = STATE_CLEARED }; @@ -121,8 +122,18 @@ struct Event : _ze_event_handle_t { l3FlushAppliedOnKernel.set(kernelCount - 1); } - void resetCompletionStatus() { - this->isCompleted = false; + void resetCompletionStatus(bool disableHostSideStatusCaching) { + this->isCompleted.store(disableHostSideStatusCaching ? HOST_CACHING_DISABLED : STATE_CLEARED); + } + + void setIsCompleted() { + if (this->isCompleted.load() != HOST_CACHING_DISABLED) { + this->isCompleted = STATE_SIGNALED; + } + } + + bool isAlreadyCompleted() { + return this->isCompleted == STATE_SIGNALED; } uint32_t getMaxPacketsCount() const { @@ -172,7 +183,7 @@ struct Event : _ze_event_handle_t { bool isTimestampEvent = false; bool usingContextEndOffset = false; bool signalAllEventPackets = false; - std::atomic isCompleted{false}; + std::atomic isCompleted{STATE_INITIAL}; }; template diff --git a/level_zero/core/source/event/event_impl.inl b/level_zero/core/source/event/event_impl.inl index e5e77c90b9..4ff8baf2d8 100644 --- a/level_zero/core/source/event/event_impl.inl +++ b/level_zero/core/source/event/event_impl.inl @@ -172,7 +172,7 @@ ze_result_t EventImp::queryStatusEventPackets() { remainingPacketSyncAddress = ptrOffset(remainingPacketSyncAddress, this->singlePacketSize); } } - isCompleted = true; + this->setIsCompleted(); this->csr->getInternalAllocationStorage()->cleanAllocationList(this->csr->peekTaskCount(), NEO::AllocationUsage::TEMPORARY_ALLOCATION); return ZE_RESULT_SUCCESS; } @@ -184,7 +184,7 @@ ze_result_t EventImp::queryStatus() { } this->csr->downloadAllocations(); this->csr->downloadAllocation(*eventPool->getAllocation().getGraphicsAllocation(device->getNEODevice()->getRootDeviceIndex())); - if (isCompleted == true) { + if (isAlreadyCompleted()) { return ZE_RESULT_SUCCESS; } else { return queryStatusEventPackets(); @@ -273,7 +273,7 @@ template ze_result_t EventImp::hostSignal() { auto status = hostEventSetValue(Event::STATE_SIGNALED); if (status == ZE_RESULT_SUCCESS) { - isCompleted = true; + this->setIsCompleted(); } return status; } @@ -328,7 +328,7 @@ ze_result_t EventImp::hostSynchronize(uint64_t timeout) { template ze_result_t EventImp::reset() { - this->resetCompletionStatus(); + this->resetCompletionStatus(false); this->resetDeviceCompletionData(false); this->l3FlushAppliedOnKernel.reset(); return ZE_RESULT_SUCCESS; diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_7.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_7.cpp index e2f3c5775c..6a1409ff8f 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_7.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_7.cpp @@ -632,12 +632,12 @@ HWTEST2_F(CmdlistAppendLaunchKernelTests, ze_group_count_t groupCount = {3, 2, 1}; CmdListKernelLaunchParams launchParams = {}; ze_event_handle_t eventHandles[1] = {event->toHandle()}; - EXPECT_FALSE(static_cast(event.get())->isCompleted); + EXPECT_EQ(MockEvent::STATE_CLEARED, static_cast(event.get())->isCompleted); result = CommandList::fromHandle(cmdListHandle)->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 1, eventHandles, launchParams); EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_TRUE(static_cast(event.get())->isCompleted); + EXPECT_EQ(MockEvent::STATE_SIGNALED, static_cast(event.get())->isCompleted); CommandList::fromHandle(cmdListHandle)->destroy(); } diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_event_reset.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_event_reset.cpp index c27a3f31ea..a026462742 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_event_reset.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_event_reset.cpp @@ -200,12 +200,27 @@ HWTEST_F(CommandListAppendEventReset, givenCmdlistWhenAppendingEventResetThenEve } } -HWTEST_F(CommandListAppendEventReset, givenCmdlistWhenAppendingEventResetThenIsCompletedResetted) { +HWTEST_F(CommandListAppendEventReset, givenCmdlistWhenAppendingEventResetThenIsCompletedFlagDisabled) { MockEvent event; - event.isCompleted = true; + event.isCompleted = MockEvent::STATE_SIGNALED; auto result = commandList->appendEventReset(event.toHandle()); ASSERT_EQ(ZE_RESULT_SUCCESS, result); - EXPECT_FALSE(event.isCompleted); + ASSERT_EQ(MockEvent::HOST_CACHING_DISABLED, event.isCompleted); +} + +HWTEST_F(CommandListAppendEventReset, WhenIsCompletedClearedThenSetStateSignaledWhenSignalAgain) { + event->reset(); + EXPECT_FALSE(event->isAlreadyCompleted()); + event->hostSignal(); + EXPECT_TRUE(event->isAlreadyCompleted()); +} + +HWTEST_F(CommandListAppendEventReset, WhenIsCompletedDisabledThenDontSetStateSignaledWhenSignalAgain) { + auto result = commandList->appendEventReset(event->toHandle()); + ASSERT_EQ(ZE_RESULT_SUCCESS, result); + EXPECT_FALSE(event->isAlreadyCompleted()); + event->hostSignal(); + EXPECT_FALSE(event->isAlreadyCompleted()); } HWTEST2_F(CommandListAppendEventReset, givenImmediateCmdlistWhenAppendingEventResetThenCommandsAreExecuted, IsAtLeastSkl) { diff --git a/level_zero/core/test/unit_tests/sources/event/test_event.cpp b/level_zero/core/test/unit_tests/sources/event/test_event.cpp index 1c44467894..618bf069bf 100644 --- a/level_zero/core/test/unit_tests/sources/event/test_event.cpp +++ b/level_zero/core/test/unit_tests/sources/event/test_event.cpp @@ -2455,7 +2455,7 @@ struct EventDynamicPacketUseFixture : public DeviceFixture { result = event->queryStatus(); EXPECT_EQ(ZE_RESULT_NOT_READY, result); - event->resetCompletionStatus(); + event->resetCompletionStatus(false); event->hostSignal(); @@ -2472,7 +2472,7 @@ struct EventDynamicPacketUseFixture : public DeviceFixture { result = event->queryStatus(); EXPECT_EQ(ZE_RESULT_SUCCESS, result); - event->resetCompletionStatus(); + event->resetCompletionStatus(false); remainingPacketsAddress = ptrOffset(eventHostAddress, (usedPackets * packetSize)); if (event->isUsingContextEndOffset()) { @@ -2485,13 +2485,13 @@ struct EventDynamicPacketUseFixture : public DeviceFixture { result = event->queryStatus(); EXPECT_EQ(queryRetAfterPartialReset, result); - event->resetCompletionStatus(); + event->resetCompletionStatus(false); *completionField = Event::STATE_SIGNALED; result = event->queryStatus(); EXPECT_EQ(ZE_RESULT_SUCCESS, result); - event->resetCompletionStatus(); + event->resetCompletionStatus(false); } event->reset();