From d8d7419aee2796834a900545a25d1394e0eb7529 Mon Sep 17 00:00:00 2001 From: Aravind Gopalakrishnan Date: Wed, 18 Dec 2024 19:24:29 +0000 Subject: [PATCH] feature: Append recorded commandlist into immediate (8/N) Add primary dispatch capability for immediate command list Related-To: NEO-10356 Signed-off-by: Aravind Gopalakrishnan --- level_zero/core/source/cmdlist/cmdlist_hw.inl | 2 +- .../source/cmdlist/cmdlist_hw_immediate.h | 2 +- .../source/cmdlist/cmdlist_hw_immediate.inl | 69 +++++++---- level_zero/core/source/cmdqueue/cmdqueue.cpp | 2 +- .../core/source/cmdqueue/cmdqueue_hw.inl | 4 - .../sources/cmdlist/test_cmdlist_2.cpp | 4 +- .../sources/cmdlist/test_cmdlist_5.cpp | 108 +++++++++++++++++- .../sources/cmdlist/test_cmdlist_7.cpp | 8 +- .../test_cmdlist_append_launch_kernel_3.cpp | 2 +- .../test_cmdlist_append_signal_event.cpp | 87 +++++++++++++- .../test_cmdlist_append_wait_on_events.cpp | 8 +- .../sources/cmdqueue/test_cmdqueue_1.cpp | 42 ------- .../source/command_container/cmdcontainer.h | 4 +- .../command_container_tests.cpp | 35 ++++++ 14 files changed, 283 insertions(+), 94 deletions(-) diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.inl b/level_zero/core/source/cmdlist/cmdlist_hw.inl index 0310bef0e0..f4568ce963 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw.inl @@ -242,7 +242,7 @@ ze_result_t CommandListCoreFamily::initialize(Device *device, NEO this->l1CachePolicyData.init(productHelper); this->cmdListHeapAddressModel = L0GfxCoreHelper::getHeapAddressModel(rootDeviceEnvironment); this->dummyBlitWa.rootDeviceEnvironment = &(neoDevice->getRootDeviceEnvironmentRef()); - this->dispatchCmdListBatchBufferAsPrimary = L0GfxCoreHelper::dispatchCmdListBatchBufferAsPrimary(rootDeviceEnvironment, !isImmediateType()); + this->dispatchCmdListBatchBufferAsPrimary = L0GfxCoreHelper::dispatchCmdListBatchBufferAsPrimary(rootDeviceEnvironment, !(isImmediateType() && this->internalUsage)); this->useOnlyGlobalTimestamps = gfxCoreHelper.useOnlyGlobalTimestamps(); this->maxFillPaternSizeForCopyEngine = productHelper.getMaxFillPaternSizeForCopyEngine(); this->heaplessModeEnabled = compilerProductHelper.isHeaplessModeEnabled(); diff --git a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.h b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.h index cbb73718b1..7b04f9cf6a 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.h +++ b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.h @@ -193,7 +193,7 @@ struct CommandListCoreFamilyImmediate : public CommandListCoreFamily::CommandListCoreFamilyImmediate(ui } template -void CommandListCoreFamilyImmediate::checkAvailableSpace(uint32_t numEvents, bool hasRelaxedOrderingDependencies, size_t commandSize) { +void CommandListCoreFamilyImmediate::checkAvailableSpace(uint32_t numEvents, bool hasRelaxedOrderingDependencies, size_t commandSize, bool requestCommandBufferInLocalMem) { this->commandContainer.fillReusableAllocationLists(); - /* Command container might has two command buffers. If it has, one is in local memory, because relaxed ordering requires that and one in system for copying it into ring buffer. - If relaxed ordering is needed in given dispatch and current command stream is in system memory, swap of command streams is required to ensure local memory. Same in the opposite scenario. */ - if (hasRelaxedOrderingDependencies == NEO::MemoryPoolHelper::isSystemMemoryPool(this->commandContainer.getCommandStream()->getGraphicsAllocation()->getMemoryPool())) { + // Command container might have two command buffers - one in local mem (mainly for relaxed ordering and any other specific purposes) and one in system mem for copying into ring buffer. + // If relaxed ordering is needed in given dispatch or if we need to force Local mem usage, and current command stream is in system memory, swap of command streams is required to ensure local memory. + // If relaxed ordering is not needed and command buffer is in local mem, then also we need to swap. + bool swapStreams = false; + if (hasRelaxedOrderingDependencies) { + if (!NEO::MemoryPoolHelper::isSystemMemoryPool(this->commandContainer.getCommandStream()->getGraphicsAllocation()->getMemoryPool())) { + swapStreams = true; + } + } else { + if (requestCommandBufferInLocalMem && NEO::MemoryPoolHelper::isSystemMemoryPool(this->commandContainer.getCommandStream()->getGraphicsAllocation()->getMemoryPool())) { + swapStreams = true; + } else if (!NEO::MemoryPoolHelper::isSystemMemoryPool(this->commandContainer.getCommandStream()->getGraphicsAllocation()->getMemoryPool())) { + swapStreams = true; + } + } + + if (swapStreams) { if (this->commandContainer.swapStreams()) { this->cmdListCurrentStartOffset = this->commandContainer.getCommandStream()->getUsed(); } @@ -514,7 +528,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendLaunchKernel( relaxedOrderingDispatch = isRelaxedOrderingDispatchAllowed(numWaitEvents, false); bool stallingCmdsForRelaxedOrdering = hasStallingCmdsForRelaxedOrdering(numWaitEvents, relaxedOrderingDispatch); - checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize); + checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize, false); bool hostWait = waitForEventsFromHost(); if (hostWait) { this->synchronizeEventList(numWaitEvents, phWaitEvents); @@ -571,7 +585,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendLaunchKernelInd ze_event_handle_t hSignalEvent, uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents, bool relaxedOrderingDispatch) { relaxedOrderingDispatch = isRelaxedOrderingDispatchAllowed(numWaitEvents, false); - checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize); + checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize, false); auto ret = CommandListCoreFamily::appendLaunchKernelIndirect(kernelHandle, pDispatchArgumentsBuffer, hSignalEvent, numWaitEvents, phWaitEvents, relaxedOrderingDispatch); @@ -598,7 +612,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendBarrier(ze_even isStallingOperation = hasStallingCmdsForRelaxedOrdering(numWaitEvents, relaxedOrderingDispatch); } - checkAvailableSpace(numWaitEvents, false, commonImmediateCommandSize); + checkAvailableSpace(numWaitEvents, false, commonImmediateCommandSize, false); ret = CommandListCoreFamily::appendBarrier(hSignalEvent, numWaitEvents, phWaitEvents, relaxedOrderingDispatch); @@ -623,7 +637,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendMemoryCopy( auto sizePerBlit = sizeof(typename GfxFamily::XY_COPY_BLT) + NEO::BlitCommandsHelper::estimatePostBlitCommandSize(); estimatedSize += nBlits * sizePerBlit; } - checkAvailableSpace(numWaitEvents, memoryCopyParams.relaxedOrderingDispatch, estimatedSize); + checkAvailableSpace(numWaitEvents, memoryCopyParams.relaxedOrderingDispatch, estimatedSize, false); bool hasStallindCmds = hasStallingCmdsForRelaxedOrdering(numWaitEvents, memoryCopyParams.relaxedOrderingDispatch); @@ -679,7 +693,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendMemoryCopyRegio auto sizePerBlit = sizeof(typename GfxFamily::XY_COPY_BLT) + NEO::BlitCommandsHelper::estimatePostBlitCommandSize(); estimatedSize += xBlits * yBlits * zBlits * sizePerBlit; } - checkAvailableSpace(numWaitEvents, memoryCopyParams.relaxedOrderingDispatch, estimatedSize); + checkAvailableSpace(numWaitEvents, memoryCopyParams.relaxedOrderingDispatch, estimatedSize, false); bool hasStallindCmds = hasStallingCmdsForRelaxedOrdering(numWaitEvents, memoryCopyParams.relaxedOrderingDispatch); @@ -722,7 +736,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendMemoryFill(void ze_event_handle_t *phWaitEvents, bool relaxedOrderingDispatch) { relaxedOrderingDispatch = isRelaxedOrderingDispatchAllowed(numWaitEvents, false); - checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize); + checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize, false); auto ret = CommandListCoreFamily::appendMemoryFill(ptr, pattern, patternSize, size, hSignalEvent, numWaitEvents, phWaitEvents, relaxedOrderingDispatch); @@ -736,7 +750,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendSignalEvent(ze_ relaxedOrderingDispatch = isRelaxedOrderingDispatchAllowed(0, false); bool hasStallingCmds = !Event::fromHandle(hSignalEvent)->isCounterBased() || hasStallingCmdsForRelaxedOrdering(0, relaxedOrderingDispatch); - checkAvailableSpace(0, false, commonImmediateCommandSize); + checkAvailableSpace(0, false, commonImmediateCommandSize, false); ret = CommandListCoreFamily::appendSignalEvent(hSignalEvent, relaxedOrderingDispatch); return flushImmediate(ret, true, hasStallingCmds, relaxedOrderingDispatch, false, false, hSignalEvent, false); } @@ -745,7 +759,7 @@ template ze_result_t CommandListCoreFamilyImmediate::appendEventReset(ze_event_handle_t hSignalEvent) { ze_result_t ret = ZE_RESULT_SUCCESS; - checkAvailableSpace(0, false, commonImmediateCommandSize); + checkAvailableSpace(0, false, commonImmediateCommandSize, false); ret = CommandListCoreFamily::appendEventReset(hSignalEvent); return flushImmediate(ret, true, true, false, false, false, hSignalEvent, false); } @@ -755,7 +769,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendPageFaultCopy(N NEO::GraphicsAllocation *srcAllocation, size_t size, bool flushHost) { - checkAvailableSpace(0, false, commonImmediateCommandSize); + checkAvailableSpace(0, false, commonImmediateCommandSize, false); ze_result_t ret; @@ -792,7 +806,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendWaitOnEvents(ui } if (!skipFlush) { - checkAvailableSpace(numEvents, false, commonImmediateCommandSize); + checkAvailableSpace(numEvents, false, commonImmediateCommandSize, false); } auto ret = CommandListCoreFamily::appendWaitOnEvents(numEvents, phWaitEvents, outWaitCmds, relaxedOrderingAllowed, trackDependencies, apiRequest, skipAddingWaitEventsToResidency, false, copyOffloadOperation); @@ -810,7 +824,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendWriteGlobalTime uint64_t *dstptr, ze_event_handle_t hSignalEvent, uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) { - checkAvailableSpace(numWaitEvents, false, commonImmediateCommandSize); + checkAvailableSpace(numWaitEvents, false, commonImmediateCommandSize, false); auto ret = CommandListCoreFamily::appendWriteGlobalTimestamp(dstptr, hSignalEvent, numWaitEvents, phWaitEvents); @@ -854,7 +868,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendImageCopyRegion auto sizePerBlit = sizeof(typename GfxFamily::XY_BLOCK_COPY_BLT) + NEO::BlitCommandsHelper::estimatePostBlitCommandSize(); estimatedSize += nBlits * sizePerBlit; } - checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, estimatedSize); + checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, estimatedSize, false); auto ret = CommandListCoreFamily::appendImageCopyRegion(hDstImage, hSrcImage, pDstRegion, pSrcRegion, hSignalEvent, numWaitEvents, phWaitEvents, relaxedOrderingDispatch); @@ -872,7 +886,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendImageCopyFromMe ze_event_handle_t *phWaitEvents, bool relaxedOrderingDispatch) { relaxedOrderingDispatch = isRelaxedOrderingDispatchAllowed(numWaitEvents, false); - checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize); + checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize, false); auto ret = CommandListCoreFamily::appendImageCopyFromMemory(hDstImage, srcPtr, pDstRegion, hSignalEvent, numWaitEvents, phWaitEvents, relaxedOrderingDispatch); @@ -890,7 +904,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendImageCopyToMemo ze_event_handle_t *phWaitEvents, bool relaxedOrderingDispatch) { relaxedOrderingDispatch = isRelaxedOrderingDispatchAllowed(numWaitEvents, false); - checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize); + checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize, false); auto ret = CommandListCoreFamily::appendImageCopyToMemory(dstPtr, hSrcImage, pSrcRegion, hSignalEvent, numWaitEvents, phWaitEvents, relaxedOrderingDispatch); @@ -910,7 +924,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendImageCopyFromMe ze_event_handle_t *phWaitEvents, bool relaxedOrderingDispatch) { relaxedOrderingDispatch = isRelaxedOrderingDispatchAllowed(numWaitEvents, false); - checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize); + checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize, false); auto ret = CommandListCoreFamily::appendImageCopyFromMemoryExt(hDstImage, srcPtr, pDstRegion, srcRowPitch, srcSlicePitch, hSignalEvent, numWaitEvents, phWaitEvents, relaxedOrderingDispatch); @@ -930,7 +944,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendImageCopyToMemo ze_event_handle_t *phWaitEvents, bool relaxedOrderingDispatch) { relaxedOrderingDispatch = isRelaxedOrderingDispatchAllowed(numWaitEvents, false); - checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize); + checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize, false); auto ret = CommandListCoreFamily::appendImageCopyToMemoryExt(dstPtr, hSrcImage, pSrcRegion, destRowPitch, destSlicePitch, hSignalEvent, numWaitEvents, phWaitEvents, relaxedOrderingDispatch); @@ -945,7 +959,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendMemoryRangesBar ze_event_handle_t hSignalEvent, uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) { - checkAvailableSpace(numWaitEvents, false, commonImmediateCommandSize); + checkAvailableSpace(numWaitEvents, false, commonImmediateCommandSize, false); auto ret = CommandListCoreFamily::appendMemoryRangesBarrier(numRanges, pRangeSizes, pRanges, hSignalEvent, numWaitEvents, phWaitEvents); return flushImmediate(ret, true, true, false, false, false, hSignalEvent, false); @@ -953,14 +967,14 @@ ze_result_t CommandListCoreFamilyImmediate::appendMemoryRangesBar template ze_result_t CommandListCoreFamilyImmediate::appendWaitOnMemory(void *desc, void *ptr, uint64_t data, ze_event_handle_t signalEventHandle, bool useQwordData) { - checkAvailableSpace(0, false, commonImmediateCommandSize); + checkAvailableSpace(0, false, commonImmediateCommandSize, false); auto ret = CommandListCoreFamily::appendWaitOnMemory(desc, ptr, data, signalEventHandle, useQwordData); return flushImmediate(ret, true, false, false, false, false, signalEventHandle, false); } template ze_result_t CommandListCoreFamilyImmediate::appendWriteToMemory(void *desc, void *ptr, uint64_t data) { - checkAvailableSpace(0, false, commonImmediateCommandSize); + checkAvailableSpace(0, false, commonImmediateCommandSize, false); auto ret = CommandListCoreFamily::appendWriteToMemory(desc, ptr, data); return flushImmediate(ret, true, false, false, false, false, nullptr, false); } @@ -1559,7 +1573,10 @@ ze_result_t CommandListCoreFamilyImmediate::appendCommandLists(ui ze_event_handle_t hSignalEvent, uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) { auto ret = ZE_RESULT_SUCCESS; - checkAvailableSpace(numWaitEvents, false, commonImmediateCommandSize); + + // For API functionality, we require command buffer alloc in local mem for. + // So ensure we force it when checking available space and when allocating any new comand buffer allocs + checkAvailableSpace(numWaitEvents, false, commonImmediateCommandSize, true); if (numWaitEvents) { ret = this->appendWaitOnEvents(numWaitEvents, phWaitEvents, nullptr, false, true, true, true, true, false); } @@ -1584,7 +1601,9 @@ ze_result_t CommandListCoreFamilyImmediate::appendCommandLists(ui } bool hasStallingCmds = true; - return flushImmediate(ret, true, hasStallingCmds, relaxedOrderingDispatch, true, false, hSignalEvent, true); + ret = flushImmediate(ret, true, hasStallingCmds, relaxedOrderingDispatch, true, false, hSignalEvent, true); + + return ret; } } // namespace L0 diff --git a/level_zero/core/source/cmdqueue/cmdqueue.cpp b/level_zero/core/source/cmdqueue/cmdqueue.cpp index 0a9dbe19b7..71defe8ec0 100644 --- a/level_zero/core/source/cmdqueue/cmdqueue.cpp +++ b/level_zero/core/source/cmdqueue/cmdqueue.cpp @@ -98,7 +98,7 @@ ze_result_t CommandQueueImp::initialize(bool copyOnly, bool isInternal, bool imm auto &productHelper = rootDeviceEnvironment.getHelper(); this->doubleSbaWa = productHelper.isAdditionalStateBaseAddressWARequired(hwInfo); this->cmdListHeapAddressModel = L0GfxCoreHelper::getHeapAddressModel(rootDeviceEnvironment); - this->dispatchCmdListBatchBufferAsPrimary = L0GfxCoreHelper::dispatchCmdListBatchBufferAsPrimary(rootDeviceEnvironment, !immediateCmdListQueue); + this->dispatchCmdListBatchBufferAsPrimary = L0GfxCoreHelper::dispatchCmdListBatchBufferAsPrimary(rootDeviceEnvironment, !(immediateCmdListQueue && internalUsage)); auto &compilerProductHelper = rootDeviceEnvironment.getHelper(); this->heaplessModeEnabled = compilerProductHelper.isHeaplessModeEnabled(); this->heaplessStateInitEnabled = compilerProductHelper.isHeaplessStateInitEnabled(this->heaplessModeEnabled); diff --git a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl index 575c094cd8..0ccc035f97 100644 --- a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl +++ b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl @@ -1287,10 +1287,6 @@ void CommandQueueHw::programOneCmdListBatchBufferStartSecondaryBa } } } - - if (ctx.containsParentImmediateStream) { - NEO::EncodeBatchBufferStartOrEnd::programBatchBufferEnd(commandContainer); - } } template diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp index 36ccf63202..4f1b861166 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp @@ -1733,10 +1733,10 @@ HWTEST_F(PrimaryBatchBufferCmdListTest, givenForcedPrimaryBatchBufferWhenRegular EXPECT_TRUE(commandList->dispatchCmdListBatchBufferAsPrimary); EXPECT_TRUE(commandQueue->dispatchCmdListBatchBufferAsPrimary); - EXPECT_FALSE(commandListImmediate->dispatchCmdListBatchBufferAsPrimary); + EXPECT_TRUE(commandListImmediate->dispatchCmdListBatchBufferAsPrimary); ASSERT_NE(nullptr, commandListImmediate->cmdQImmediate); auto immediateCmdQueue = static_cast(commandListImmediate->cmdQImmediate); - EXPECT_FALSE(immediateCmdQueue->dispatchCmdListBatchBufferAsPrimary); + EXPECT_TRUE(immediateCmdQueue->dispatchCmdListBatchBufferAsPrimary); } HWTEST_F(PrimaryBatchBufferCmdListTest, givenPrimaryBatchBufferWhenAppendingKernelAndClosingCommandListThenExpectAlignedSpaceForBatchBufferStart) { diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_5.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_5.cpp index 9069112977..89b7ba484b 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_5.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_5.cpp @@ -927,7 +927,7 @@ HWTEST2_F(CommandListCreate, givenSecondaryCommandStreamForImmediateCmdListWhenC auto immediateCmdList = static_cast *>(commandList.get()); auto secondaryCmdStream = reinterpret_cast(&commandList->getCmdContainer())->secondaryCommandStreamForImmediateCmdList.get(); - immediateCmdList->checkAvailableSpace(0u, false, commonImmediateCommandSize); + immediateCmdList->checkAvailableSpace(0u, false, commonImmediateCommandSize, false); EXPECT_EQ(commandList->getCmdContainer().getCommandStream(), secondaryCmdStream); EXPECT_TRUE(MemoryPoolHelper::isSystemMemoryPool(commandList->getCmdContainer().getCommandStream()->getGraphicsAllocation()->getMemoryPool())); @@ -938,6 +938,110 @@ HWTEST2_F(CommandListCreate, givenSecondaryCommandStreamForImmediateCmdListWhenC EXPECT_TRUE(MemoryPoolHelper::isSystemMemoryPool(reinterpret_cast(&commandList->getCmdContainer())->secondaryCommandStreamForImmediateCmdList->getGraphicsAllocation()->getMemoryPool())); } +struct CmdContainerMockLocalAllocTests : public CommandContainer { + using CommandContainer::secondaryCommandStreamForImmediateCmdList; +}; + +HWTEST2_F(CommandListCreate, givenSecondaryCommandStreamForImmediateCmdListButNotYetUsingHostAllocWhenCallingAppendCmdlistsThenDoNotSwapCommandStreams, IsPVC) { + DebugManagerStateRestore restorer; + debugManager.flags.DirectSubmissionFlatRingBuffer.set(-1); + + static_cast(device->getNEODevice()->getMemoryManager())->localMemorySupported[0] = true; + ze_command_queue_desc_t desc = {}; + desc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS; + ze_result_t returnValue; + CommandStreamReceiver *csr = nullptr; + device->getCsrForOrdinalAndIndex(&csr, desc.ordinal, desc.index, ZE_COMMAND_QUEUE_PRIORITY_NORMAL, false); + reinterpret_cast *>(csr)->directSubmissionAvailable = true; + std::unique_ptr commandList(CommandList::createImmediate(productFamily, device, &desc, false, NEO::EngineGroupType::copy, returnValue)); + ASSERT_NE(nullptr, commandList); + EXPECT_NE(reinterpret_cast(&commandList->getCmdContainer())->secondaryCommandStreamForImmediateCmdList.get(), nullptr); + EXPECT_TRUE(MemoryPoolHelper::isSystemMemoryPool(reinterpret_cast(&commandList->getCmdContainer())->secondaryCommandStreamForImmediateCmdList->getGraphicsAllocation()->getMemoryPool())); + + auto secondaryCmdStream = reinterpret_cast(&commandList->getCmdContainer())->secondaryCommandStreamForImmediateCmdList.get(); + + std::unique_ptr commandListRegular(CommandList::create(productFamily, device, NEO::EngineGroupType::copy, 0u, returnValue, false)); + commandListRegular->close(); + auto commandListHandle = commandListRegular->toHandle(); + + ze_result_t result = ZE_RESULT_SUCCESS; + result = commandList->appendCommandLists(1u, &commandListHandle, nullptr, 0u, nullptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + + EXPECT_EQ(commandList->getCmdContainer().getCommandStream(), secondaryCmdStream); + EXPECT_TRUE(MemoryPoolHelper::isSystemMemoryPool(commandList->getCmdContainer().getCommandStream()->getGraphicsAllocation()->getMemoryPool())); +} + +HWTEST2_F(CommandListCreate, givenSecondaryCommandStreamForImmediateCmdListButAndUsingHostAllocWhenCallingAppendCmdlistsThenSwapCommandStreamsAndAppendSucceeds, IsAtLeastXeHpcCore) { + DebugManagerStateRestore restorer; + debugManager.flags.DirectSubmissionFlatRingBuffer.set(-1); + + static_cast(device->getNEODevice()->getMemoryManager())->localMemorySupported[0] = true; + ze_command_queue_desc_t desc = {}; + desc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS; + ze_result_t returnValue; + CommandStreamReceiver *csr = nullptr; + device->getCsrForOrdinalAndIndex(&csr, desc.ordinal, desc.index, ZE_COMMAND_QUEUE_PRIORITY_NORMAL, false); + reinterpret_cast *>(csr)->directSubmissionAvailable = true; + std::unique_ptr commandList(CommandList::createImmediate(productFamily, device, &desc, false, NEO::EngineGroupType::copy, returnValue)); + ASSERT_NE(nullptr, commandList); + EXPECT_NE(reinterpret_cast(&commandList->getCmdContainer())->secondaryCommandStreamForImmediateCmdList.get(), nullptr); + EXPECT_TRUE(MemoryPoolHelper::isSystemMemoryPool(reinterpret_cast(&commandList->getCmdContainer())->secondaryCommandStreamForImmediateCmdList->getGraphicsAllocation()->getMemoryPool())); + + auto secondaryCmdStream = reinterpret_cast(&commandList->getCmdContainer())->secondaryCommandStreamForImmediateCmdList.get(); + + std::unique_ptr commandListRegular(CommandList::create(productFamily, device, NEO::EngineGroupType::compute, 0u, returnValue, false)); + commandListRegular->close(); + auto commandListHandle = commandListRegular->toHandle(); + + commandList->getCmdContainer().swapStreams(); + EXPECT_EQ(commandList->getCmdContainer().getCommandStream(), secondaryCmdStream); + + ze_result_t result = ZE_RESULT_SUCCESS; + result = commandList->appendCommandLists(1u, &commandListHandle, nullptr, 0u, nullptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + + EXPECT_NE(commandList->getCmdContainer().getCommandStream(), secondaryCmdStream); +} + +HWTEST2_F(CommandListCreate, givenSecondaryCommandStreamForImmediateCmdListAndAlreadyUsingHostAllocThenAppendingRegularCommandlistsIntoImmediateUsesLocalAndRestoresHostAlloc, MatchAny) { + if (!device->getHwInfo().featureTable.flags.ftrLocalMemory) { + GTEST_SKIP(); + } + DebugManagerStateRestore restorer; + debugManager.flags.DirectSubmissionFlatRingBuffer.set(-1); + + static_cast(device->getNEODevice()->getMemoryManager())->localMemorySupported[0] = true; + ze_command_queue_desc_t desc = {}; + desc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS; + ze_result_t returnValue; + CommandStreamReceiver *csr = nullptr; + device->getCsrForOrdinalAndIndex(&csr, desc.ordinal, desc.index, ZE_COMMAND_QUEUE_PRIORITY_NORMAL, false); + reinterpret_cast *>(csr)->directSubmissionAvailable = true; + std::unique_ptr commandList(CommandList::createImmediate(productFamily, device, &desc, false, NEO::EngineGroupType::copy, returnValue)); + ASSERT_NE(nullptr, commandList); + EXPECT_NE(reinterpret_cast(&commandList->getCmdContainer())->secondaryCommandStreamForImmediateCmdList.get(), nullptr); + EXPECT_TRUE(MemoryPoolHelper::isSystemMemoryPool(reinterpret_cast(&commandList->getCmdContainer())->secondaryCommandStreamForImmediateCmdList->getGraphicsAllocation()->getMemoryPool())); + + auto immediateCmdList = static_cast *>(commandList.get()); + auto secondaryCmdStream = reinterpret_cast(&commandList->getCmdContainer())->secondaryCommandStreamForImmediateCmdList.get(); + + immediateCmdList->checkAvailableSpace(0u, false, commonImmediateCommandSize, false); + + EXPECT_EQ(commandList->getCmdContainer().getCommandStream(), secondaryCmdStream); + EXPECT_TRUE(MemoryPoolHelper::isSystemMemoryPool(commandList->getCmdContainer().getCommandStream()->getGraphicsAllocation()->getMemoryPool())); + + std::unique_ptr commandListRegular(CommandList::create(productFamily, device, NEO::EngineGroupType::copy, 0u, returnValue, false)); + commandListRegular->close(); + auto commandListHandle = commandListRegular->toHandle(); + + ze_result_t result = ZE_RESULT_SUCCESS; + result = commandList->appendCommandLists(1u, &commandListHandle, nullptr, 0u, nullptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + EXPECT_EQ(commandList->getCmdContainer().getCommandStream(), secondaryCmdStream); + EXPECT_TRUE(commandList->getCmdContainer().usingSecondaryCmdbufInHostMem()); +} + HWTEST2_F(CommandListCreate, givenNoSecondaryCommandStreamForImmediateCmdListWhenCheckAvailableSpaceThenNotSwapCommandStreams, MatchAny) { if (!device->getHwInfo().featureTable.flags.ftrLocalMemory) { GTEST_SKIP(); @@ -956,7 +1060,7 @@ HWTEST2_F(CommandListCreate, givenNoSecondaryCommandStreamForImmediateCmdListWhe auto immediateCmdList = static_cast *>(commandList.get()); auto cmdStream = commandList->getCmdContainer().getCommandStream(); - immediateCmdList->checkAvailableSpace(0u, false, commonImmediateCommandSize); + immediateCmdList->checkAvailableSpace(0u, false, commonImmediateCommandSize, false); EXPECT_EQ(commandList->getCmdContainer().getCommandStream(), cmdStream); EXPECT_FALSE(MemoryPoolHelper::isSystemMemoryPool(commandList->getCmdContainer().getCommandStream()->getGraphicsAllocation()->getMemoryPool())); 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 e63731510d..8a94013039 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 @@ -1889,12 +1889,12 @@ HWTEST2_F(CommandListCreate, givenImmediateCommandListWhenThereIsNoEnoughSpaceFo commandList->getCmdContainer().getCommandStream()->getGraphicsAllocation()->updateTaskCount(0u, 0u); commandList->getCmdContainer().getCommandStream()->getSpace(useSize); - reinterpret_cast *>(commandList.get())->checkAvailableSpace(0, false, commonImmediateCommandSize); + reinterpret_cast *>(commandList.get())->checkAvailableSpace(0, false, commonImmediateCommandSize, false); EXPECT_EQ(1U, commandList->getCmdContainer().getCmdBufferAllocations().size()); commandList->getCmdContainer().getCommandStream()->getSpace(useSize); auto latestFlushedTaskCount = whiteBoxCmdList->getCsr(false)->peekLatestFlushedTaskCount(); - reinterpret_cast *>(commandList.get())->checkAvailableSpace(0, false, commonImmediateCommandSize); + reinterpret_cast *>(commandList.get())->checkAvailableSpace(0, false, commonImmediateCommandSize, false); EXPECT_EQ(1U, commandList->getCmdContainer().getCmdBufferAllocations().size()); EXPECT_EQ(latestFlushedTaskCount + 1, whiteBoxCmdList->getCsr(false)->peekLatestFlushedTaskCount()); } @@ -1916,12 +1916,12 @@ HWTEST2_F(CommandListCreate, givenImmediateCommandListWhenThereIsNoEnoughSpaceFo commandList->getCmdContainer().getCommandStream()->getGraphicsAllocation()->updateTaskCount(0u, 0u); commandList->getCmdContainer().getCommandStream()->getSpace(useSize); - reinterpret_cast *>(commandList.get())->checkAvailableSpace(numEvents, false, commonImmediateCommandSize); + reinterpret_cast *>(commandList.get())->checkAvailableSpace(numEvents, false, commonImmediateCommandSize, false); EXPECT_EQ(1U, commandList->getCmdContainer().getCmdBufferAllocations().size()); commandList->getCmdContainer().getCommandStream()->getSpace(useSize); auto latestFlushedTaskCount = whiteBoxCmdList->getCsr(false)->peekLatestFlushedTaskCount(); - reinterpret_cast *>(commandList.get())->checkAvailableSpace(numEvents, false, commonImmediateCommandSize); + reinterpret_cast *>(commandList.get())->checkAvailableSpace(numEvents, false, commonImmediateCommandSize, false); EXPECT_EQ(1U, commandList->getCmdContainer().getCmdBufferAllocations().size()); EXPECT_EQ(latestFlushedTaskCount + 1, whiteBoxCmdList->getCsr(false)->peekLatestFlushedTaskCount()); } 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 15097c8b0c..ae6e2c2d0c 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 @@ -1280,7 +1280,7 @@ HWTEST2_F(MultiTileImmediateCommandListAppendLaunchKernelXeHpCoreTest, givenImpl auto itorBbStart = find(cmdList.begin(), cmdList.end()); ASSERT_NE(cmdList.end(), itorBbStart); auto cmdBbStart = genCmdCast(*itorBbStart); - EXPECT_EQ(MI_BATCH_BUFFER_START::SECOND_LEVEL_BATCH_BUFFER::SECOND_LEVEL_BATCH_BUFFER_SECOND_LEVEL_BATCH, cmdBbStart->getSecondLevelBatchBuffer()); + EXPECT_NE(MI_BATCH_BUFFER_START::SECOND_LEVEL_BATCH_BUFFER::SECOND_LEVEL_BATCH_BUFFER_SECOND_LEVEL_BATCH, cmdBbStart->getSecondLevelBatchBuffer()); } } // namespace ult } // namespace L0 diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_signal_event.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_signal_event.cpp index 2d55278fe7..129dc00dad 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_signal_event.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_signal_event.cpp @@ -154,7 +154,7 @@ HWTEST2_F(CommandListAppendSignalEvent, givenCommandListWhenAppendWriteGlobalTim EXPECT_FALSE(cmd->getDcFlushEnable()); } -HWTEST2_F(CommandListAppendSignalEvent, givenImmediateCmdListAndAppendingRegularCommandlistWithWaitOnEventsAndSignalEventThenUseSemaphoreAndPipeControl, IsAtLeastXeHpcCore) { +HWTEST2_F(CommandListAppendSignalEvent, givenImmediateCmdListAndAppendingRegularCommandlistWithWaitOnEventsAndSignalEventThenUseSemaphoreAndPipeControl, IsXeHpcCore) { using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT; using POST_SYNC_OPERATION = typename PIPE_CONTROL::POST_SYNC_OPERATION; @@ -222,6 +222,81 @@ HWTEST2_F(CommandListAppendSignalEvent, givenImmediateCmdListAndAppendingRegular ASSERT_TRUE(postSyncFound); } +HWTEST2_F(CommandListAppendSignalEvent, givenImmediateCmdListAndSecondaryDispatchModeForcedAndAppendingRegularCommandlistWithWaitOnEventsAndSignalEventThenUseSemaphoreAndPipeControl, MatchAny) { + DebugManagerStateRestore restorer; + debugManager.flags.DispatchCmdlistCmdBufferPrimary.set(0); + + using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; + using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT; + using POST_SYNC_OPERATION = typename PIPE_CONTROL::POST_SYNC_OPERATION; + using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START; + using MI_BATCH_BUFFER_END = typename FamilyType::MI_BATCH_BUFFER_END; + + ze_event_pool_desc_t eventPoolDesc = {}; + eventPoolDesc.count = 1; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE; + + ze_event_desc_t eventDesc = {}; + eventDesc.index = 0; + eventDesc.signal = ZE_EVENT_SCOPE_FLAG_HOST; + + ze_result_t result = ZE_RESULT_SUCCESS; + auto eventPoolHostVisible = std::unique_ptr(EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result)); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + auto eventHostVisible = std::unique_ptr(Event::create(eventPoolHostVisible.get(), &eventDesc, device)); + + auto waitEventPool = std::unique_ptr(EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result)); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + auto waitEvent = std::unique_ptr(Event::create(waitEventPool.get(), &eventDesc, device)); + + ze_command_queue_desc_t desc = {}; + desc.mode = ZE_COMMAND_QUEUE_MODE_SYNCHRONOUS; + ze_result_t returnValue; + std::unique_ptr immCommandList(CommandList::createImmediate(productFamily, device, &desc, false, NEO::EngineGroupType::renderCompute, returnValue)); + ASSERT_NE(nullptr, immCommandList); + + ze_event_handle_t hSignalEventHandle = eventHostVisible->toHandle(); + ze_event_handle_t hWaitEventHandle = waitEvent->toHandle(); + std::unique_ptr commandListRegular(CommandList::create(productFamily, device, NEO::EngineGroupType::compute, 0u, returnValue, false)); + commandListRegular->close(); + auto commandListHandle = commandListRegular->toHandle(); + auto usedSpaceBefore = immCommandList->getCmdContainer().getCommandStream()->getUsed(); + result = immCommandList->appendCommandLists(1u, &commandListHandle, hSignalEventHandle, 1u, &hWaitEventHandle); + + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + + auto usedSpaceAfter = immCommandList->getCmdContainer().getCommandStream()->getUsed(); + ASSERT_GT(usedSpaceAfter, usedSpaceBefore); + + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::Parse::parseCommandBuffer(cmdList, + immCommandList->getCmdContainer().getCommandStream()->getCpuBase(), + usedSpaceAfter)); + + auto itorSemaphore = find(cmdList.begin(), cmdList.end()); + ASSERT_NE(cmdList.end(), itorSemaphore); + + auto itorBBStart = find(itorSemaphore, cmdList.end()); + ASSERT_NE(cmdList.end(), itorBBStart); + + auto itorPC = findAll(itorBBStart, cmdList.end()); + ASSERT_NE(0u, itorPC.size()); + bool postSyncFound = false; + for (auto it : itorPC) { + auto cmd = genCmdCast(*it); + if (cmd->getPostSyncOperation() == POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA) { + EXPECT_NE(cmd->getImmediateData(), Event::STATE_CLEARED); + EXPECT_TRUE(cmd->getCommandStreamerStallEnable()); + EXPECT_EQ(MemorySynchronizationCommands::getDcFlushEnable(true, device->getNEODevice()->getRootDeviceEnvironment()), cmd->getDcFlushEnable()); + postSyncFound = true; + } + } + ASSERT_TRUE(postSyncFound); + + auto itorBBEnd = find(itorBBStart, cmdList.end()); + ASSERT_NE(cmdList.end(), itorBBEnd); +} + HWTEST2_F(CommandListAppendSignalEvent, givenImmediateCmdListWithComputeQueueAndAppendingRegularCommandlistThenCsrMakeNonTesidentSkippedFromCmdQueue, IsAtLeastXeHpcCore) { ze_command_queue_desc_t desc = {}; desc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS; @@ -254,7 +329,6 @@ HWTEST2_F(CommandListAppendSignalEvent, givenImmediateCmdListWithComputeQueueAnd HWTEST2_F(CommandListAppendSignalEvent, givenCopyOnlyImmediateCmdListAndAppendingRegularCommandlistWithWaitOnEventsAndSignalEventThenUseSemaphoreAndFlushDw, IsAtLeastXeHpcCore) { using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT; - using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START; using MI_FLUSH_DW = typename FamilyType::MI_FLUSH_DW; ze_event_pool_desc_t eventPoolDesc = {}; @@ -283,6 +357,10 @@ HWTEST2_F(CommandListAppendSignalEvent, givenCopyOnlyImmediateCmdListAndAppendin ze_event_handle_t hSignalEventHandle = eventHostVisible->toHandle(); ze_event_handle_t hWaitEventHandle = waitEvent->toHandle(); std::unique_ptr commandListRegular(CommandList::create(productFamily, device, NEO::EngineGroupType::copy, 0u, returnValue, false)); + void *srcPtr = reinterpret_cast(0x1234); + void *dstPtr = reinterpret_cast(0x2345); + CmdListMemoryCopyParams copyParams = {}; + commandListRegular->appendMemoryCopy(dstPtr, srcPtr, 8, nullptr, 0, nullptr, copyParams); commandListRegular->close(); auto commandListHandle = commandListRegular->toHandle(); auto usedSpaceBefore = immCommandList->getCmdContainer().getCommandStream()->getUsed(); @@ -301,9 +379,6 @@ HWTEST2_F(CommandListAppendSignalEvent, givenCopyOnlyImmediateCmdListAndAppendin auto itorSemaphore = find(cmdList.begin(), cmdList.end()); ASSERT_NE(cmdList.end(), itorSemaphore); - auto itorBBStart = find(itorSemaphore, cmdList.end()); - ASSERT_NE(cmdList.end(), itorBBStart); - uint32_t expectedMiFlushCount = 1; NEO::EncodeDummyBlitWaArgs waArgs{false, &(device->getNEODevice()->getRootDeviceEnvironmentRef())}; if (MockEncodeMiFlushDW::getWaSize(waArgs) > 0) { @@ -664,7 +739,7 @@ HWTEST2_F(CommandListAppendUsedPacketSignalEvent, event->signalScope = ZE_EVENT_SCOPE_FLAG_HOST; commandList->partitionCount = packets; - commandList->checkAvailableSpace(0, false, commonImmediateCommandSize); + commandList->checkAvailableSpace(0, false, commonImmediateCommandSize, false); commandList->appendSignalEventPostWalker(event.get(), nullptr, nullptr, false, false, false); EXPECT_EQ(packets, event->getPacketsInUse()); diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_wait_on_events.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_wait_on_events.cpp index bbaf1b018d..5cfdc92be5 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_wait_on_events.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_wait_on_events.cpp @@ -202,7 +202,6 @@ HWTEST2_F(CommandListAppendWaitOnEvent, givenImmediateCmdListWithDirectSubmissio HWTEST2_F(CommandListAppendWaitOnEvent, givenImmediateCmdListAndAppendingRegularCommandlistWithWaitOnEventsThenUseSemaphore, IsAtLeastXeHpcCore) { using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT; - using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START; ze_command_queue_desc_t desc = {}; desc.mode = ZE_COMMAND_QUEUE_MODE_SYNCHRONOUS; @@ -212,6 +211,10 @@ HWTEST2_F(CommandListAppendWaitOnEvent, givenImmediateCmdListAndAppendingRegular ze_event_handle_t hEventHandle = event->toHandle(); std::unique_ptr commandListRegular(CommandList::create(productFamily, device, NEO::EngineGroupType::compute, 0u, returnValue, false)); + void *srcPtr = reinterpret_cast(0x1234); + void *dstPtr = reinterpret_cast(0x2345); + CmdListMemoryCopyParams copyParams = {}; + commandListRegular->appendMemoryCopy(dstPtr, srcPtr, 8, nullptr, 0, nullptr, copyParams); commandListRegular->close(); auto commandListHandle = commandListRegular->toHandle(); auto result = immCommandList->appendCommandLists(1u, &commandListHandle, nullptr, 1u, &hEventHandle); @@ -227,9 +230,6 @@ HWTEST2_F(CommandListAppendWaitOnEvent, givenImmediateCmdListAndAppendingRegular auto itor = find(cmdList.begin(), cmdList.end()); ASSERT_NE(cmdList.end(), itor); - - auto itorBBStart = find(itor, cmdList.end()); - ASSERT_NE(cmdList.end(), itorBBStart); } template diff --git a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp index 309cdcc757..d8490e55d1 100644 --- a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp @@ -540,48 +540,6 @@ HWTEST_F(CommandQueueCreate, givenUpdateTaskCountFromWaitAndRegularCmdListWhenDi commandQueue->destroy(); } -HWTEST_F(CommandQueueCreate, givenUpdateTaskCountFromWaitAndImmediateCmdListWhenDispatchTaskCountWriteThenNoPipeControlFlushed) { - using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; - using POST_SYNC_OPERATION = typename FamilyType::PIPE_CONTROL::POST_SYNC_OPERATION; - - DebugManagerStateRestore restorer; - debugManager.flags.UpdateTaskCountFromWait.set(3); - - const ze_command_queue_desc_t desc = {}; - ze_result_t returnValue; - auto commandQueue = whiteboxCast(CommandQueue::create(productFamily, - device, - neoDevice->getDefaultEngine().commandStreamReceiver, - &desc, - false, - false, - true, - returnValue)); - - auto commandList = CommandList::createImmediate(productFamily, device, &desc, false, NEO::EngineGroupType::renderCompute, returnValue); - ASSERT_NE(nullptr, commandList); - - ze_command_list_handle_t cmdListHandle = commandList->toHandle(); - commandQueue->executeCommandLists(1, &cmdListHandle, nullptr, false, nullptr); - - GenCmdList cmdList; - ASSERT_TRUE(FamilyType::Parse::parseCommandBuffer( - cmdList, ptrOffset(commandQueue->commandStream.getCpuBase(), 0), commandQueue->commandStream.getUsed())); - - auto pipeControls = findAll(cmdList.begin(), cmdList.end()); - bool pipeControlsPostSync = false; - for (size_t i = 0; i < pipeControls.size(); i++) { - auto pipeControl = reinterpret_cast(*pipeControls[i]); - if (pipeControl->getPostSyncOperation() == POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA) { - pipeControlsPostSync = true; - } - } - EXPECT_FALSE(pipeControlsPostSync); - - commandList->destroy(); - commandQueue->destroy(); -} - HWTEST_F(CommandQueueCreate, givenContainerWithAllocationsWhenResidencyContainerIsEmptyThenMakeResidentWasNotCalled) { auto csr = std::make_unique(*neoDevice->getExecutionEnvironment(), 0, neoDevice->getDeviceBitfield()); csr->setupContext(*neoDevice->getDefaultEngine().osContext); diff --git a/shared/source/command_container/cmdcontainer.h b/shared/source/command_container/cmdcontainer.h index a9527493e4..a58fb53146 100644 --- a/shared/source/command_container/cmdcontainer.h +++ b/shared/source/command_container/cmdcontainer.h @@ -89,6 +89,8 @@ class CommandContainer : public NonCopyableOrMovableClass { LinearStream *getCommandStream() { return commandStream.get(); } + bool usingSecondaryCmdbufInHostMem() { return useSecondaryCommandStream; } + IndirectHeap *getIndirectHeap(HeapType heapType); HeapHelper *getHeapHelper() { return heapHelper.get(); } @@ -119,7 +121,7 @@ class CommandContainer : public NonCopyableOrMovableClass { GraphicsAllocation *obtainNextCommandBufferAllocation(); GraphicsAllocation *obtainNextCommandBufferAllocation(bool forceHostMemory); - bool swapStreams(); + MOCKABLE_VIRTUAL bool swapStreams(); void reset(); diff --git a/shared/test/unit_test/command_container/command_container_tests.cpp b/shared/test/unit_test/command_container/command_container_tests.cpp index cdbc56fe46..8b0c6cf23b 100644 --- a/shared/test/unit_test/command_container/command_container_tests.cpp +++ b/shared/test/unit_test/command_container/command_container_tests.cpp @@ -98,6 +98,25 @@ TEST_F(CommandContainerHeapStateTests, givenDirtyHeapsWhenSettingStateForSingleH } } +using CommandContainerSwapStreamTest = Test; +TEST_F(CommandContainerSwapStreamTest, givenCommandContainerInitializedWithSecondaryCmdBufferAndForceSwapStreamsReturnsFalseThenCallIsUnsuccessful) { + class MyMockCommandContainer : public CommandContainer { + public: + bool swapStreams() override { + swapStreamsCalled++; + return forceSwapAction; + } + + uint32_t swapStreamsCalled = 0u; + bool forceSwapAction = false; + }; + + MyMockCommandContainer cmdContainer; + cmdContainer.initialize(pDevice, nullptr, HeapSize::defaultHeapSize, true, true); + + EXPECT_FALSE(cmdContainer.swapStreams()); +} + TEST_F(CommandContainerTest, givenCmdContainerWhenCreatingCommandBufferThenCorrectAllocationTypeIsSet) { CommandContainer cmdContainer; cmdContainer.initialize(pDevice, nullptr, HeapSize::defaultHeapSize, true, false); @@ -126,6 +145,22 @@ TEST_F(CommandContainerTest, givenCreateSecondaryCmdBufferInHostMemWhenInitializ EXPECT_EQ(cmdContainer.secondaryCommandStreamForImmediateCmdList.get(), cmdStream); } +TEST_F(CommandContainerTest, givenCreateSecondaryCmdBufferInHostMemWhenInitializeThenCreateAdditionalLinearStreamAndReturnAccordingly) { + MyMockCommandContainer cmdContainer; + cmdContainer.initialize(pDevice, nullptr, HeapSize::defaultHeapSize, true, true); + + EXPECT_NE(cmdContainer.secondaryCommandStreamForImmediateCmdList.get(), nullptr); + + auto secondaryCmdStream = cmdContainer.secondaryCommandStreamForImmediateCmdList.get(); + auto cmdStream = cmdContainer.getCommandStream(); + + EXPECT_TRUE(cmdContainer.swapStreams()); + EXPECT_TRUE(cmdContainer.usingSecondaryCmdbufInHostMem()); + + EXPECT_EQ(cmdContainer.getCommandStream(), secondaryCmdStream); + EXPECT_EQ(cmdContainer.secondaryCommandStreamForImmediateCmdList.get(), cmdStream); +} + TEST_F(CommandContainerTest, whenInitializeThenNotCreateAdditionalLinearStream) { MyMockCommandContainer cmdContainer; cmdContainer.initialize(pDevice, nullptr, HeapSize::defaultHeapSize, true, false);