From b6018010c4860dc5477b6c2be69c2210b255e1ff Mon Sep 17 00:00:00 2001 From: Zbigniew Zdanowicz Date: Thu, 5 Jun 2025 18:53:59 +0000 Subject: [PATCH] refactor: add option to skip to add to residency event external allocation Signed-off-by: Zbigniew Zdanowicz --- level_zero/core/source/cmdlist/cmdlist_hw.h | 2 +- level_zero/core/source/cmdlist/cmdlist_hw.inl | 32 ++++++++++--------- .../source/cmdlist/cmdlist_hw_immediate.inl | 4 +-- level_zero/core/source/device/bcs_split.h | 2 +- .../cmdlist/test_in_order_cmdlist_1.cpp | 19 +++++++++-- 5 files changed, 38 insertions(+), 21 deletions(-) diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.h b/level_zero/core/source/cmdlist/cmdlist_hw.h index 2e13d88126..39ebca0b3f 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.h +++ b/level_zero/core/source/cmdlist/cmdlist_hw.h @@ -231,7 +231,7 @@ struct CommandListCoreFamily : public CommandListImp { ze_result_t executeCommandListImmediateImpl(bool performMigration, L0::CommandQueue *cmdQImmediate); size_t getReserveSshSize(); void patchInOrderCmds() override; - MOCKABLE_VIRTUAL bool handleCounterBasedEventOperations(Event *signalEvent); + MOCKABLE_VIRTUAL bool handleCounterBasedEventOperations(Event *signalEvent, bool skipAddingEventToResidency); bool isCbEventBoundToCmdList(Event *event) const; protected: diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.inl b/level_zero/core/source/cmdlist/cmdlist_hw.inl index 414644ede6..4908fee7f5 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw.inl @@ -441,7 +441,7 @@ ze_result_t CommandListCoreFamily::appendLaunchKernel(ze_kernel_h } } - if (!handleCounterBasedEventOperations(event)) { + if (!handleCounterBasedEventOperations(event, launchParams.omitAddingEventResidency)) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } @@ -495,7 +495,7 @@ ze_result_t CommandListCoreFamily::appendLaunchKernelIndirect(ze_ launchParams.isHostSignalScopeEvent = event->isSignalScope(ZE_EVENT_SCOPE_FLAG_HOST); } - if (!handleCounterBasedEventOperations(event)) { + if (!handleCounterBasedEventOperations(event, false)) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } @@ -541,7 +541,7 @@ ze_result_t CommandListCoreFamily::appendLaunchMultipleKernelsInd launchParams.isHostSignalScopeEvent = event->isSignalScope(ZE_EVENT_SCOPE_FLAG_HOST); } - if (!handleCounterBasedEventOperations(event)) { + if (!handleCounterBasedEventOperations(event, false)) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } @@ -709,7 +709,7 @@ ze_result_t CommandListCoreFamily::appendMemoryRangesBarrier(uint signalEvent = Event::fromHandle(hSignalEvent); } - if (!handleCounterBasedEventOperations(signalEvent)) { + if (!handleCounterBasedEventOperations(signalEvent, false)) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } @@ -1567,7 +1567,7 @@ ze_result_t CommandListCoreFamily::appendMemoryCopyBlitRegion(Ali return ret; } - if (!handleCounterBasedEventOperations(signalEvent)) { + if (!handleCounterBasedEventOperations(signalEvent, false)) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } @@ -1616,7 +1616,7 @@ ze_result_t CommandListCoreFamily::appendCopyImageBlit(NEO::Graph return ret; } - if (!handleCounterBasedEventOperations(signalEvent)) { + if (!handleCounterBasedEventOperations(signalEvent, false)) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } @@ -1822,7 +1822,7 @@ ze_result_t CommandListCoreFamily::appendMemoryCopy(void *dstptr, dcFlush = getDcFlushRequired(signalEvent->isSignalScope()); } - if (!handleCounterBasedEventOperations(signalEvent)) { + if (!handleCounterBasedEventOperations(signalEvent, false)) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } @@ -2297,7 +2297,7 @@ ze_result_t CommandListCoreFamily::appendMemoryFill(void *ptr, appendSynchronizedDispatchInitializationSection(); - if (!handleCounterBasedEventOperations(signalEvent)) { + if (!handleCounterBasedEventOperations(signalEvent, false)) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } @@ -2528,7 +2528,7 @@ ze_result_t CommandListCoreFamily::appendBlitFill(void *ptr, cons return ret; } - if (!handleCounterBasedEventOperations(signalEvent)) { + if (!handleCounterBasedEventOperations(signalEvent, false)) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } @@ -2798,7 +2798,7 @@ ze_result_t CommandListCoreFamily::appendSignalEvent(ze_event_han auto event = Event::fromHandle(hEvent); event->resetKernelCountAndPacketUsedCount(); - if (!handleCounterBasedEventOperations(event)) { + if (!handleCounterBasedEventOperations(event, false)) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } @@ -3332,7 +3332,7 @@ ze_result_t CommandListCoreFamily::appendWriteGlobalTimestamp( signalEvent = Event::fromHandle(hSignalEvent); } - if (!handleCounterBasedEventOperations(signalEvent)) { + if (!handleCounterBasedEventOperations(signalEvent, false)) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } @@ -3923,7 +3923,7 @@ ze_result_t CommandListCoreFamily::appendBarrier(ze_event_handle_ signalEvent = Event::fromHandle(hSignalEvent); } - if (!handleCounterBasedEventOperations(signalEvent)) { + if (!handleCounterBasedEventOperations(signalEvent, false)) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } @@ -4064,7 +4064,7 @@ ze_result_t CommandListCoreFamily::appendWaitOnMemory(void *desc, handleInOrderImplicitDependencies(false, false); } - if (!handleCounterBasedEventOperations(signalEvent)) { + if (!handleCounterBasedEventOperations(signalEvent, false)) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } @@ -4410,7 +4410,7 @@ bool CommandListCoreFamily::hasInOrderDependencies() const { } template -bool CommandListCoreFamily::handleCounterBasedEventOperations(Event *signalEvent) { +bool CommandListCoreFamily::handleCounterBasedEventOperations(Event *signalEvent, bool skipAddingEventToResidency) { if (!signalEvent) { return true; } @@ -4452,7 +4452,9 @@ bool CommandListCoreFamily::handleCounterBasedEventOperations(Eve if (signalEvent->isUsingContextEndOffset()) { auto tag = device->getInOrderTimestampAllocator()->getTag(); - this->commandContainer.addToResidencyContainer(tag->getBaseGraphicsAllocation()->getGraphicsAllocation(device->getRootDeviceIndex())); + if (skipAddingEventToResidency == false) { + this->commandContainer.addToResidencyContainer(tag->getBaseGraphicsAllocation()->getGraphicsAllocation(device->getRootDeviceIndex())); + } signalEvent->resetInOrderTimestampNode(tag, this->partitionCount); signalEvent->resetAdditionalTimestampNode(nullptr, this->partitionCount, false); } diff --git a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl index 6c94c5a8e9..d38a92308f 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl @@ -1404,7 +1404,7 @@ ze_result_t CommandListCoreFamilyImmediate::performCpuMemcpy(cons signalEvent = Event::fromHandle(hSignalEvent); } - if (!this->handleCounterBasedEventOperations(signalEvent)) { + if (!this->handleCounterBasedEventOperations(signalEvent, false)) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } @@ -1777,7 +1777,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendCommandLists(ui dcFlush = this->getDcFlushRequired(signalEvent->isSignalScope()); } - if (!this->handleCounterBasedEventOperations(signalEvent)) { + if (!this->handleCounterBasedEventOperations(signalEvent, false)) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } diff --git a/level_zero/core/source/device/bcs_split.h b/level_zero/core/source/device/bcs_split.h index 563a5812f8..04f693422e 100644 --- a/level_zero/core/source/device/bcs_split.h +++ b/level_zero/core/source/device/bcs_split.h @@ -95,7 +95,7 @@ struct BcsSplit { auto signalEvent = Event::fromHandle(hSignalEvent); - if (!cmdList->handleCounterBasedEventOperations(signalEvent)) { + if (!cmdList->handleCounterBasedEventOperations(signalEvent, false)) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist_1.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist_1.cpp index 04db74c747..fe1c7f5492 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist_1.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist_1.cpp @@ -423,6 +423,21 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, InOrderCmdListTests, givenRegularCmdListWhenAppendQ context->freeMem(deviceMem); } +HWCMDTEST_F(IGFX_XE_HP_CORE, InOrderCmdListTests, givenRegularCmdListWhenAppendCbTimestampEventWithSkipAddToResidencyFlagThenEventAllocationNotAddedToResidency) { + auto regularCmdList = createRegularCmdList(false); + + auto eventPool = createEvents(1, true); + + launchParams.omitAddingEventResidency = true; + regularCmdList->appendLaunchKernel(kernel->toHandle(), groupCount, events[0]->toHandle(), 0, nullptr, launchParams); + + auto eventAllocation = events[0]->getAllocation(this->device); + + auto &cmdlistResidency = regularCmdList->getCmdContainer().getResidencyContainer(); + auto eventAllocationIt = std::find(cmdlistResidency.begin(), cmdlistResidency.end(), eventAllocation); + EXPECT_EQ(eventAllocationIt, cmdlistResidency.end()); +} + HWCMDTEST_F(IGFX_XE_HP_CORE, InOrderCmdListTests, givenCounterBasedTimestampEventWhenQueryingTimestampThenEnsureItsCompletion) { struct MyMockEvent : public L0::EventImp { using BaseClass = L0::EventImp; @@ -2927,8 +2942,8 @@ HWTEST2_F(InOrderCmdListTests, givenRelaxedOrderingWhenProgrammingTimestampEvent using BaseClass = WhiteBox>; using BaseClass::BaseClass; - bool handleCounterBasedEventOperations(L0::Event *signalEvent) override { - auto ret = BaseClass::handleCounterBasedEventOperations(signalEvent); + bool handleCounterBasedEventOperations(L0::Event *signalEvent, bool skipAddingEventToResidency) override { + auto ret = BaseClass::handleCounterBasedEventOperations(signalEvent, skipAddingEventToResidency); usedEvent = signalEvent; auto hostAddr = reinterpret_cast(usedEvent->getCompletionFieldHostAddress()); *hostAddr = 0x123;