From 9779f66fdea6e3eeb2471e15468080d54ca2c8a2 Mon Sep 17 00:00:00 2001 From: "Dunajski, Bartosz" Date: Fri, 17 Nov 2023 17:16:00 +0000 Subject: [PATCH] feature: return error when CB Event is passed to non-inOrder CmdList Related-To: NEO-8145 Signed-off-by: Dunajski, Bartosz --- level_zero/core/source/cmdlist/cmdlist_hw.h | 2 +- level_zero/core/source/cmdlist/cmdlist_hw.inl | 76 ++++++++++++++----- .../source/cmdlist/cmdlist_hw_immediate.inl | 2 +- level_zero/core/source/device/bcs_split.h | 4 +- .../test_cmdlist_append_launch_kernel_3.cpp | 60 +++++++++++++++ 5 files changed, 120 insertions(+), 24 deletions(-) diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.h b/level_zero/core/source/cmdlist/cmdlist_hw.h index 1403e9d463..f4babacdec 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.h +++ b/level_zero/core/source/cmdlist/cmdlist_hw.h @@ -191,7 +191,7 @@ struct CommandListCoreFamily : CommandListImp { ze_result_t executeCommandListImmediateImpl(bool performMigration, L0::CommandQueue *cmdQImmediate); size_t getReserveSshSize(); void patchInOrderCmds() override; - void handleCounterBasedEventTransition(Event *signalEvent); + bool handleCounterBasedEventOperations(Event *signalEvent); protected: MOCKABLE_VIRTUAL ze_result_t appendMemoryCopyKernelWithGA(void *dstPtr, NEO::GraphicsAllocation *dstPtrAlloc, diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.inl b/level_zero/core/source/cmdlist/cmdlist_hw.inl index a198845d7f..a4b9ce2f20 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw.inl @@ -363,7 +363,9 @@ ze_result_t CommandListCoreFamily::appendLaunchKernel(ze_kernel_h } } - handleCounterBasedEventTransition(event); + if (!handleCounterBasedEventOperations(event)) { + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + } auto res = appendLaunchKernelWithParams(Kernel::fromHandle(kernelHandle), threadGroupDimensions, event, launchParams); @@ -402,7 +404,9 @@ ze_result_t CommandListCoreFamily::appendLaunchCooperativeKernel( event->resetKernelCountAndPacketUsedCount(); } - handleCounterBasedEventTransition(event); + if (!handleCounterBasedEventOperations(event)) { + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + } CmdListKernelLaunchParams launchParams = {}; launchParams.isCooperative = true; @@ -442,7 +446,9 @@ ze_result_t CommandListCoreFamily::appendLaunchKernelIndirect(ze_ launchParams.isHostSignalScopeEvent = event->isSignalScope(ZE_EVENT_SCOPE_FLAG_HOST); } - handleCounterBasedEventTransition(event); + if (!handleCounterBasedEventOperations(event)) { + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + } appendEventForProfiling(event, true, false); launchParams.isIndirect = true; @@ -482,7 +488,9 @@ ze_result_t CommandListCoreFamily::appendLaunchMultipleKernelsInd launchParams.isHostSignalScopeEvent = event->isSignalScope(ZE_EVENT_SCOPE_FLAG_HOST); } - handleCounterBasedEventTransition(event); + if (!handleCounterBasedEventOperations(event)) { + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + } appendEventForProfiling(event, true, false); auto allocData = device->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(static_cast(pNumLaunchArguments)); @@ -580,7 +588,9 @@ ze_result_t CommandListCoreFamily::appendMemoryRangesBarrier(uint signalEvent = Event::fromHandle(hSignalEvent); } - handleCounterBasedEventTransition(signalEvent); + if (!handleCounterBasedEventOperations(signalEvent)) { + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + } appendEventForProfiling(signalEvent, true, false); applyMemoryRangesBarrier(numRanges, pRangeSizes, pRanges); @@ -1240,7 +1250,9 @@ ze_result_t CommandListCoreFamily::appendMemoryCopyBlitRegion(Ali return ret; } - handleCounterBasedEventTransition(signalEvent); + if (!handleCounterBasedEventOperations(signalEvent)) { + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + } appendEventForProfiling(signalEvent, true, false); auto &rootDeviceEnvironment = device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[device->getRootDeviceIndex()]; @@ -1428,7 +1440,9 @@ ze_result_t CommandListCoreFamily::appendMemoryCopy(void *dstptr, dcFlush = getDcFlushRequired(signalEvent->isSignalScope()); } - handleCounterBasedEventTransition(signalEvent); + if (!handleCounterBasedEventOperations(signalEvent)) { + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + } launchParams.numKernelsInSplitLaunch = kernelCounter; launchParams.isKernelSplitOperation = kernelCounter > 1; @@ -1847,7 +1861,9 @@ ze_result_t CommandListCoreFamily::appendMemoryFill(void *ptr, return res; } - handleCounterBasedEventTransition(signalEvent); + if (!handleCounterBasedEventOperations(signalEvent)) { + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + } bool hostPointerNeedsFlush = false; @@ -2097,7 +2113,9 @@ ze_result_t CommandListCoreFamily::appendBlitFill(void *ptr, return ret; } - handleCounterBasedEventTransition(signalEvent); + if (!handleCounterBasedEventOperations(signalEvent)) { + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + } auto neoDevice = device->getNEODevice(); appendEventForProfiling(signalEvent, true, false); @@ -2342,7 +2360,9 @@ ze_result_t CommandListCoreFamily::appendSignalEvent(ze_event_han auto event = Event::fromHandle(hEvent); event->resetKernelCountAndPacketUsedCount(); - handleCounterBasedEventTransition(event); + if (!handleCounterBasedEventOperations(event)) { + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + } commandContainer.addToResidencyContainer(&event->getAllocation(this->device)); NEO::Device *neoDevice = device->getNEODevice(); @@ -2642,7 +2662,9 @@ ze_result_t CommandListCoreFamily::appendWriteGlobalTimestamp( signalEvent = Event::fromHandle(hSignalEvent); } - handleCounterBasedEventTransition(signalEvent); + if (!handleCounterBasedEventOperations(signalEvent)) { + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + } appendEventForProfiling(signalEvent, true, false); @@ -3161,7 +3183,9 @@ ze_result_t CommandListCoreFamily::appendBarrier(ze_event_handle_ signalEvent = Event::fromHandle(hSignalEvent); } - handleCounterBasedEventTransition(signalEvent); + if (!handleCounterBasedEventOperations(signalEvent)) { + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + } appendEventForProfiling(signalEvent, true, false); @@ -3314,7 +3338,9 @@ ze_result_t CommandListCoreFamily::appendWaitOnMemory(void *desc, handleInOrderImplicitDependencies(false); } - handleCounterBasedEventTransition(signalEvent); + if (!handleCounterBasedEventOperations(signalEvent)) { + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + } appendEventForProfiling(signalEvent, true, false); @@ -3603,18 +3629,26 @@ bool CommandListCoreFamily::hasInOrderDependencies() const { } template -void CommandListCoreFamily::handleCounterBasedEventTransition(Event *signalEvent) { - if (signalEvent && (NEO::DebugManager.flags.EnableImplicitConvertionToCounterBasedEvents.get() == 1)) { - if (signalEvent->isCounterBasedExplicitlyEnabled()) { - return; +bool CommandListCoreFamily::handleCounterBasedEventOperations(Event *signalEvent) { + if (signalEvent) { + if (signalEvent->isCounterBased() && !isInOrderExecutionEnabled()) { + return false; } - if (isInOrderExecutionEnabled() && (this->cmdListType == TYPE_IMMEDIATE)) { - signalEvent->enableCounterBasedMode(false); - } else { - signalEvent->disableImplicitCounterBasedMode(); + if ((NEO::DebugManager.flags.EnableImplicitConvertionToCounterBasedEvents.get() == 1)) { + if (signalEvent->isCounterBasedExplicitlyEnabled()) { + return true; + } + + if (isInOrderExecutionEnabled() && (this->cmdListType == TYPE_IMMEDIATE)) { + signalEvent->enableCounterBasedMode(false); + } else { + signalEvent->disableImplicitCounterBasedMode(); + } } } + + return true; } } // namespace L0 diff --git a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl index 8a97ebccd5..1cc79db1a9 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl @@ -1043,7 +1043,7 @@ ze_result_t CommandListCoreFamilyImmediate::performCpuMemcpy(cons if (hSignalEvent) { signalEvent = Event::fromHandle(hSignalEvent); } - this->handleCounterBasedEventTransition(signalEvent); + this->handleCounterBasedEventOperations(signalEvent); const void *cpuMemcpySrcPtr = srcLockPointer ? srcLockPointer : cpuMemCopyInfo.srcPtr; void *cpuMemcpyDstPtr = dstLockPointer ? dstLockPointer : cpuMemCopyInfo.dstPtr; diff --git a/level_zero/core/source/device/bcs_split.h b/level_zero/core/source/device/bcs_split.h index f0fce6f673..6fc802ad57 100644 --- a/level_zero/core/source/device/bcs_split.h +++ b/level_zero/core/source/device/bcs_split.h @@ -88,7 +88,9 @@ struct BcsSplit { auto signalEvent = Event::fromHandle(hSignalEvent); - cmdList->handleCounterBasedEventTransition(signalEvent); + if (!cmdList->handleCounterBasedEventOperations(signalEvent)) { + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + } auto totalSize = size; auto engineCount = cmdQsForSplit.size(); diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel_3.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel_3.cpp index 595e327982..4b91470923 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel_3.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel_3.cpp @@ -1678,6 +1678,66 @@ HWTEST2_F(InOrderCmdListTests, givenImmediateCmdListWhenDispatchingWithRegularEv context->freeMem(alloc); } +HWTEST2_F(InOrderCmdListTests, givenNonInOrderCmdListWhenPassingCounterBasedEventThenReturnError, IsAtLeastXeHpCore) { + DebugManager.flags.EnableImplicitConvertionToCounterBasedEvents.set(1); + + auto immCmdList = createImmCmdList(); + immCmdList->inOrderExecInfo.reset(); + EXPECT_FALSE(immCmdList->isInOrderExecutionEnabled()); + + auto copyOnlyCmdList = createCopyOnlyImmCmdList(); + copyOnlyCmdList->inOrderExecInfo.reset(); + EXPECT_FALSE(copyOnlyCmdList->isInOrderExecutionEnabled()); + + auto eventPool = createEvents(1, true); + + auto eventHandle = events[0]->toHandle(); + + ze_copy_region_t region = {0, 0, 0, 1, 1, 1}; + uint32_t copyData[64] = {}; + + void *alloc = nullptr; + ze_device_mem_alloc_desc_t deviceDesc = {}; + auto result = context->allocDeviceMem(device->toHandle(), &deviceDesc, 16384u, 4096u, &alloc); + ASSERT_EQ(result, ZE_RESULT_SUCCESS); + + NEO::MockGraphicsAllocation mockAllocation(0, NEO::AllocationType::INTERNAL_HOST_MEMORY, + reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), + MemoryPool::System4KBPages, MemoryManager::maxOsContextCount); + + AlignedAllocationData allocationData = {mockAllocation.gpuAddress, 0, &mockAllocation, false}; + + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, immCmdList->appendLaunchKernel(kernel->toHandle(), groupCount, eventHandle, 0, nullptr, launchParams, false)); + + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, immCmdList->appendLaunchCooperativeKernel(kernel->toHandle(), groupCount, eventHandle, 0, nullptr, false)); + + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, immCmdList->appendLaunchKernelIndirect(kernel->toHandle(), *static_cast(alloc), eventHandle, 0, nullptr, false)); + + size_t rangeSizes = 1; + const void **ranges = reinterpret_cast(©Data[0]); + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, immCmdList->appendMemoryRangesBarrier(1, &rangeSizes, ranges, eventHandle, 0, nullptr)); + + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, copyOnlyCmdList->appendMemoryCopyBlitRegion(&allocationData, &allocationData, region, region, {0, 0, 0}, 0, 0, 0, 0, {0, 0, 0}, {0, 0, 0}, events[0].get(), 0, nullptr, false)); + + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, immCmdList->appendMemoryCopy(©Data, ©Data, 1, eventHandle, 0, nullptr, false, false)); + + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, immCmdList->appendMemoryFill(alloc, ©Data, 1, 16, eventHandle, 0, nullptr, false)); + + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, copyOnlyCmdList->appendBlitFill(alloc, ©Data, 1, 16, events[0].get(), 0, nullptr, false)); + + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, immCmdList->appendSignalEvent(eventHandle)); + + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, immCmdList->appendWriteGlobalTimestamp(reinterpret_cast(copyData), eventHandle, 0, nullptr)); + + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, immCmdList->appendBarrier(eventHandle, 0, nullptr, false)); + + zex_wait_on_mem_desc_t desc; + desc.actionFlag = ZEX_WAIT_ON_MEMORY_FLAG_NOT_EQUAL; + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, immCmdList->appendWaitOnMemory(reinterpret_cast(&desc), copyData, 1, eventHandle, false)); + + context->freeMem(alloc); +} + HWTEST2_F(InOrderCmdListTests, givenCmdsChainingFromAppendCopyWhenDispatchingKernelThenProgramSemaphoreOnce, IsAtLeastXeHpCore) { using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT;