From 4ca213d4d753616ff5206b19601fa07a086d7cd7 Mon Sep 17 00:00:00 2001 From: "Baj, Tomasz" Date: Tue, 27 Jun 2023 19:34:37 +0000 Subject: [PATCH] fix: commandContainer is nullptr in LinearStream for immediate cmdList Related-To: GSD-4084 Signed-off-by: Baj, Tomasz --- level_zero/core/source/cmdlist/cmdlist_hw.inl | 5 +- .../source/cmdlist/cmdlist_hw_immediate.h | 4 +- .../source/cmdlist/cmdlist_hw_immediate.inl | 70 ++++++++++++------- .../core/source/cmdqueue/cmdqueue_hw.inl | 2 +- .../sources/cmdlist/test_cmdlist_1.cpp | 8 ++- .../sources/cmdlist/test_cmdlist_5.cpp | 4 +- .../sources/cmdlist/test_cmdlist_7.cpp | 12 ++-- .../test_cmdlist_append_launch_kernel_3.cpp | 18 +---- .../source/command_container/cmdcontainer.cpp | 6 +- shared/source/command_stream/linear_stream.h | 3 +- .../command_container_tests.cpp | 7 ++ 11 files changed, 78 insertions(+), 61 deletions(-) diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.inl b/level_zero/core/source/cmdlist/cmdlist_hw.inl index 9788d8b76e..fa275cad8b 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw.inl @@ -184,13 +184,10 @@ ze_result_t CommandListCoreFamily::initialize(Device *device, NEO this->commandContainer.doubleSbaWaRef() = this->doubleSbaWa; this->commandContainer.l1CachePolicyDataRef() = &this->l1CachePolicyData; this->commandContainer.setHeapAddressModel(this->cmdListHeapAddressModel); + this->commandContainer.setImmediateCmdListCsr(this->csr); this->commandContainer.setStateBaseAddressTracking(this->stateBaseAddressTracking); this->commandContainer.setUsingPrimaryBuffer(this->dispatchCmdListBatchBufferAsPrimary); - if (this->cmdListType == CommandListType::TYPE_IMMEDIATE) { - this->commandContainer.setImmediateCmdListCsr(this->csr); - } - if (device->isImplicitScalingCapable() && !this->internalUsage && !isCopyOnly()) { this->partitionCount = static_cast(neoDevice->getDeviceBitfield().count()); } diff --git a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.h b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.h index a49a506c25..7bf5d95228 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.h +++ b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.h @@ -23,7 +23,7 @@ namespace L0 { struct EventPool; struct Event; -inline constexpr size_t maxImmediateCommandSize = 4 * MemoryConstants::kiloByte; +inline constexpr size_t commonImmediateCommandSize = 4 * MemoryConstants::kiloByte; struct CpuMemCopyInfo { void *const dstPtr; @@ -157,7 +157,7 @@ struct CommandListCoreFamilyImmediate : public CommandListCoreFamily + namespace L0 { template @@ -42,7 +44,7 @@ NEO::LogicalStateHelper *CommandListCoreFamilyImmediate::getLogic } template -void CommandListCoreFamilyImmediate::checkAvailableSpace(uint32_t numEvents, bool hasRelaxedOrderingDependencies) { +void CommandListCoreFamilyImmediate::checkAvailableSpace(uint32_t numEvents, bool hasRelaxedOrderingDependencies, size_t commandSize) { 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. @@ -54,7 +56,7 @@ void CommandListCoreFamilyImmediate::checkAvailableSpace(uint32_t } size_t semaphoreSize = NEO::EncodeSemaphore::getSizeMiSemaphoreWait() * numEvents; - if (this->commandContainer.getCommandStream()->getAvailableSpace() < maxImmediateCommandSize + semaphoreSize) { + if (this->commandContainer.getCommandStream()->getAvailableSpace() < commandSize + semaphoreSize) { bool requireSystemMemoryCommandBuffer = !hasRelaxedOrderingDependencies; auto alloc = this->commandContainer.reuseExistingCmdBuffer(requireSystemMemoryCommandBuffer); @@ -435,9 +437,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendLaunchKernel( relaxedOrderingDispatch = isRelaxedOrderingDispatchAllowed(numWaitEvents); - if (this->isFlushTaskSubmissionEnabled) { - checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch); - } + checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize); bool hostWait = waitForEventsFromHost(); if (hostWait || this->eventWaitlistSyncRequired()) { this->synchronizeEventList(numWaitEvents, phWaitEvents); @@ -460,8 +460,8 @@ ze_result_t CommandListCoreFamilyImmediate::appendLaunchKernelInd ze_event_handle_t hSignalEvent, uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents, bool relaxedOrderingDispatch) { relaxedOrderingDispatch = isRelaxedOrderingDispatchAllowed(numWaitEvents); + checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize); if (this->isFlushTaskSubmissionEnabled) { - checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch); checkWaitEventsState(numWaitEvents, phWaitEvents); } @@ -505,8 +505,8 @@ ze_result_t CommandListCoreFamilyImmediate::appendBarrier( return ZE_RESULT_SUCCESS; } + checkAvailableSpace(numWaitEvents, false, commonImmediateCommandSize); if (this->isFlushTaskSubmissionEnabled) { - checkAvailableSpace(numWaitEvents, false); checkWaitEventsState(numWaitEvents, phWaitEvents); } ret = CommandListCoreFamily::appendBarrier(hSignalEvent, numWaitEvents, phWaitEvents); @@ -525,8 +525,15 @@ ze_result_t CommandListCoreFamilyImmediate::appendMemoryCopy( ze_event_handle_t *phWaitEvents, bool relaxedOrderingDispatch, bool forceDisableCopyOnlyInOrderSignaling) { relaxedOrderingDispatch = isRelaxedOrderingDispatchAllowed(numWaitEvents); + auto estimatedSize = commonImmediateCommandSize; + if (isCopyOnly()) { + auto nBlits = static_cast(std::ceil(size / static_cast(BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight))); + auto sizePerBlit = sizeof(typename GfxFamily::XY_COPY_BLT) + NEO::BlitCommandsHelper::estimatePostBlitCommandSize(this->device->getNEODevice()->getRootDeviceEnvironment()); + estimatedSize += nBlits * sizePerBlit; + } + checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, estimatedSize); + if (this->isFlushTaskSubmissionEnabled) { - checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch); checkWaitEventsState(numWaitEvents, phWaitEvents); } @@ -575,8 +582,17 @@ ze_result_t CommandListCoreFamilyImmediate::appendMemoryCopyRegio ze_event_handle_t *phWaitEvents, bool relaxedOrderingDispatch, bool forceDisableCopyOnlyInOrderSignaling) { relaxedOrderingDispatch = isRelaxedOrderingDispatchAllowed(numWaitEvents); + auto estimatedSize = commonImmediateCommandSize; + if (isCopyOnly()) { + auto xBlits = static_cast(std::ceil(srcRegion->width / static_cast(BlitterConstants::maxBlitWidth))); + auto yBlits = static_cast(std::ceil(srcRegion->height / static_cast(BlitterConstants::maxBlitHeight))); + auto zBlits = static_cast(srcRegion->depth); + auto sizePerBlit = sizeof(typename GfxFamily::XY_COPY_BLT) + NEO::BlitCommandsHelper::estimatePostBlitCommandSize(this->device->getNEODevice()->getRootDeviceEnvironment()); + estimatedSize += xBlits * yBlits * zBlits * sizePerBlit; + } + checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, estimatedSize); + if (this->isFlushTaskSubmissionEnabled) { - checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch); checkWaitEventsState(numWaitEvents, phWaitEvents); } @@ -620,8 +636,8 @@ ze_result_t CommandListCoreFamilyImmediate::appendMemoryFill(void ze_event_handle_t *phWaitEvents, bool relaxedOrderingDispatch) { relaxedOrderingDispatch = isRelaxedOrderingDispatchAllowed(numWaitEvents); + checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize); if (this->isFlushTaskSubmissionEnabled) { - checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch); checkWaitEventsState(numWaitEvents, phWaitEvents); } @@ -635,9 +651,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendSignalEvent(ze_ using GfxFamily = typename NEO::GfxFamilyMapper::GfxFamily; ze_result_t ret = ZE_RESULT_SUCCESS; - if (this->isFlushTaskSubmissionEnabled) { - checkAvailableSpace(0, false); - } + checkAvailableSpace(0, false, commonImmediateCommandSize); ret = CommandListCoreFamily::appendSignalEvent(hSignalEvent); return flushImmediate(ret, true, true, false, hSignalEvent); } @@ -647,9 +661,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendEventReset(ze_e using GfxFamily = typename NEO::GfxFamilyMapper::GfxFamily; ze_result_t ret = ZE_RESULT_SUCCESS; - if (this->isFlushTaskSubmissionEnabled) { - checkAvailableSpace(0, false); - } + checkAvailableSpace(0, false, commonImmediateCommandSize); ret = CommandListCoreFamily::appendEventReset(hSignalEvent); return flushImmediate(ret, true, true, false, hSignalEvent); } @@ -659,9 +671,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendPageFaultCopy(N NEO::GraphicsAllocation *srcAllocation, size_t size, bool flushHost) { - if (this->isFlushTaskSubmissionEnabled) { - checkAvailableSpace(0, false); - } + checkAvailableSpace(0, false, commonImmediateCommandSize); ze_result_t ret; @@ -695,8 +705,8 @@ ze_result_t CommandListCoreFamilyImmediate::appendWaitOnEvents(ui if (allSignaled) { return ZE_RESULT_SUCCESS; } + checkAvailableSpace(numEvents, false, commonImmediateCommandSize); if (this->isFlushTaskSubmissionEnabled) { - checkAvailableSpace(numEvents, false); checkWaitEventsState(numEvents, phWaitEvents); } auto ret = CommandListCoreFamily::appendWaitOnEvents(numEvents, phWaitEvents, relaxedOrderingAllowed, trackDependencies, signalInOrderCompletion); @@ -709,8 +719,8 @@ 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); if (this->isFlushTaskSubmissionEnabled) { - checkAvailableSpace(numWaitEvents, false); checkWaitEventsState(numWaitEvents, phWaitEvents); } auto ret = CommandListCoreFamily::appendWriteGlobalTimestamp(dstptr, hSignalEvent, numWaitEvents, phWaitEvents); @@ -747,8 +757,16 @@ ze_result_t CommandListCoreFamilyImmediate::appendImageCopyRegion ze_event_handle_t *phWaitEvents, bool relaxedOrderingDispatch) { relaxedOrderingDispatch = isRelaxedOrderingDispatchAllowed(numWaitEvents); + auto estimatedSize = commonImmediateCommandSize; + if (isCopyOnly()) { + auto imgSize = L0::Image::fromHandle(hSrcImage)->getImageInfo().size; + auto nBlits = static_cast(std::ceil(imgSize / static_cast(BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight))); + auto sizePerBlit = sizeof(typename GfxFamily::XY_BLOCK_COPY_BLT) + NEO::BlitCommandsHelper::estimatePostBlitCommandSize(this->device->getNEODevice()->getRootDeviceEnvironment()); + estimatedSize += nBlits * sizePerBlit; + } + checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, estimatedSize); + if (this->isFlushTaskSubmissionEnabled) { - checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch); checkWaitEventsState(numWaitEvents, phWaitEvents); } @@ -768,8 +786,8 @@ ze_result_t CommandListCoreFamilyImmediate::appendImageCopyFromMe ze_event_handle_t *phWaitEvents, bool relaxedOrderingDispatch) { relaxedOrderingDispatch = isRelaxedOrderingDispatchAllowed(numWaitEvents); + checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize); if (this->isFlushTaskSubmissionEnabled) { - checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch); checkWaitEventsState(numWaitEvents, phWaitEvents); } @@ -789,8 +807,8 @@ ze_result_t CommandListCoreFamilyImmediate::appendImageCopyToMemo ze_event_handle_t *phWaitEvents, bool relaxedOrderingDispatch) { relaxedOrderingDispatch = isRelaxedOrderingDispatchAllowed(numWaitEvents); + checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize); if (this->isFlushTaskSubmissionEnabled) { - checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch); checkWaitEventsState(numWaitEvents, phWaitEvents); } @@ -807,8 +825,8 @@ ze_result_t CommandListCoreFamilyImmediate::appendMemoryRangesBar ze_event_handle_t hSignalEvent, uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) { + checkAvailableSpace(numWaitEvents, false, commonImmediateCommandSize); if (this->isFlushTaskSubmissionEnabled) { - checkAvailableSpace(numWaitEvents, false); checkWaitEventsState(numWaitEvents, phWaitEvents); } auto ret = CommandListCoreFamily::appendMemoryRangesBarrier(numRanges, pRangeSizes, pRanges, hSignalEvent, numWaitEvents, phWaitEvents); @@ -823,8 +841,8 @@ ze_result_t CommandListCoreFamilyImmediate::appendLaunchCooperati ze_event_handle_t *waitEventHandles, bool relaxedOrderingDispatch) { relaxedOrderingDispatch = isRelaxedOrderingDispatchAllowed(numWaitEvents); + checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch, commonImmediateCommandSize); if (this->isFlushTaskSubmissionEnabled) { - checkAvailableSpace(numWaitEvents, relaxedOrderingDispatch); checkWaitEventsState(numWaitEvents, waitEventHandles); } diff --git a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl index 2faddb6867..4c17963094 100644 --- a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl +++ b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl @@ -1073,7 +1073,7 @@ void CommandQueueHw::programOneCmdListBatchBufferStartSecondaryBa for (size_t iter = 0; iter < cmdBufferCount; iter++) { auto allocation = cmdBufferAllocations[iter]; uint64_t startOffset = allocation->getGpuAddress(); - if (isCommandListImmediate && (iter == (cmdBufferCount - 1))) { + if (isCommandListImmediate) { startOffset = ptrOffset(allocation->getGpuAddress(), commandContainer.currentLinearStreamStartOffsetRef()); } NEO::EncodeBatchBufferStartOrEnd::programBatchBufferStart(&commandStream, startOffset, true, false, false); diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_1.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_1.cpp index 8cdd38aa8b..493997976f 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_1.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_1.cpp @@ -1740,7 +1740,7 @@ TEST_F(CommandListCreate, givenImmediateCommandListWhenThereIsNoEnoughSpaceForIm ze_command_queue_desc_t desc = {}; desc.mode = ZE_COMMAND_QUEUE_MODE_SYNCHRONOUS; ze_result_t returnValue; - std::unique_ptr commandList(CommandList::createImmediate(productFamily, device, &desc, false, NEO::EngineGroupType::RenderCompute, returnValue)); + std::unique_ptr commandList(CommandList::createImmediate(productFamily, device, &desc, false, NEO::EngineGroupType::Copy, returnValue)); ASSERT_NE(nullptr, commandList); auto whiteBoxCmdList = static_cast(commandList.get()); @@ -1754,12 +1754,16 @@ TEST_F(CommandListCreate, givenImmediateCommandListWhenThereIsNoEnoughSpaceForIm void *dstPtr = reinterpret_cast(0x2345); // reduce available cmd buffer size, so next command can't fit in 1st and we need to use 2nd cmd buffer - size_t useSize = commandList->getCmdContainer().getCommandStream()->getMaxAvailableSpace() - maxImmediateCommandSize + 1; + size_t useSize = commandList->getCmdContainer().getCommandStream()->getMaxAvailableSpace() - commonImmediateCommandSize + 1; commandList->getCmdContainer().getCommandStream()->getSpace(useSize); EXPECT_EQ(1U, commandList->getCmdContainer().getCmdBufferAllocations().size()); + auto oldStreamPtr = commandList->getCmdContainer().getCommandStream()->getCpuBase(); auto result = commandList->appendMemoryCopy(dstPtr, srcPtr, 8, nullptr, 0, nullptr, false, false); + auto newStreamPtr = commandList->getCmdContainer().getCommandStream()->getCpuBase(); + ASSERT_EQ(ZE_RESULT_SUCCESS, result); + EXPECT_NE(oldStreamPtr, newStreamPtr); EXPECT_EQ(1U, commandList->getCmdContainer().getCmdBufferAllocations().size()); whiteBoxCmdList->csr->getInternalAllocationStorage()->getTemporaryAllocations().freeAllGraphicsAllocations(device->getNEODevice()); } 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 8039378fe9..253020eb0f 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 @@ -917,7 +917,7 @@ HWTEST2_F(CommandListCreate, givenSecondaryCommandStreamForImmediateCmdListWhenC auto immediateCmdList = static_cast *>(commandList.get()); auto secondaryCmdStream = reinterpret_cast(&commandList->getCmdContainer())->secondaryCommandStreamForImmediateCmdList.get(); - immediateCmdList->checkAvailableSpace(0u, false); + immediateCmdList->checkAvailableSpace(0u, false, commonImmediateCommandSize); EXPECT_EQ(commandList->getCmdContainer().getCommandStream(), secondaryCmdStream); EXPECT_TRUE(MemoryPoolHelper::isSystemMemoryPool(commandList->getCmdContainer().getCommandStream()->getGraphicsAllocation()->getMemoryPool())); @@ -941,7 +941,7 @@ HWTEST2_F(CommandListCreate, givenNoSecondaryCommandStreamForImmediateCmdListWhe auto immediateCmdList = static_cast *>(commandList.get()); auto cmdStream = commandList->getCmdContainer().getCommandStream(); - immediateCmdList->checkAvailableSpace(0u, false); + immediateCmdList->checkAvailableSpace(0u, false, commonImmediateCommandSize); 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 9dfd64c91a..fdf8c6e30a 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 @@ -1834,17 +1834,17 @@ HWTEST2_F(CommandListCreate, givenImmediateCommandListWhenThereIsNoEnoughSpaceFo ASSERT_NE(nullptr, commandList); auto whiteBoxCmdList = static_cast(commandList.get()); - size_t useSize = commandList->getCmdContainer().getCommandStream()->getMaxAvailableSpace() - maxImmediateCommandSize + 1; + size_t useSize = commandList->getCmdContainer().getCommandStream()->getMaxAvailableSpace() - commonImmediateCommandSize + 1; EXPECT_EQ(1U, commandList->getCmdContainer().getCmdBufferAllocations().size()); commandList->getCmdContainer().getCommandStream()->getGraphicsAllocation()->updateTaskCount(0u, 0u); commandList->getCmdContainer().getCommandStream()->getSpace(useSize); - reinterpret_cast *>(commandList.get())->checkAvailableSpace(0, false); + reinterpret_cast *>(commandList.get())->checkAvailableSpace(0, false, commonImmediateCommandSize); EXPECT_EQ(1U, commandList->getCmdContainer().getCmdBufferAllocations().size()); commandList->getCmdContainer().getCommandStream()->getSpace(useSize); auto latestFlushedTaskCount = whiteBoxCmdList->csr->peekLatestFlushedTaskCount(); - reinterpret_cast *>(commandList.get())->checkAvailableSpace(0, false); + reinterpret_cast *>(commandList.get())->checkAvailableSpace(0, false, commonImmediateCommandSize); EXPECT_EQ(1U, commandList->getCmdContainer().getCmdBufferAllocations().size()); EXPECT_EQ(latestFlushedTaskCount + 1, whiteBoxCmdList->csr->peekLatestFlushedTaskCount()); } @@ -1860,18 +1860,18 @@ HWTEST2_F(CommandListCreate, givenImmediateCommandListWhenThereIsNoEnoughSpaceFo constexpr uint32_t numEvents = 100; constexpr size_t eventWaitSize = numEvents * NEO::EncodeSemaphore::getSizeMiSemaphoreWait(); - size_t useSize = commandList->getCmdContainer().getCommandStream()->getMaxAvailableSpace() - (maxImmediateCommandSize + eventWaitSize) + 1; + size_t useSize = commandList->getCmdContainer().getCommandStream()->getMaxAvailableSpace() - (commonImmediateCommandSize + eventWaitSize) + 1; EXPECT_EQ(1U, commandList->getCmdContainer().getCmdBufferAllocations().size()); commandList->getCmdContainer().getCommandStream()->getGraphicsAllocation()->updateTaskCount(0u, 0u); commandList->getCmdContainer().getCommandStream()->getSpace(useSize); - reinterpret_cast *>(commandList.get())->checkAvailableSpace(numEvents, false); + reinterpret_cast *>(commandList.get())->checkAvailableSpace(numEvents, false, commonImmediateCommandSize); EXPECT_EQ(1U, commandList->getCmdContainer().getCmdBufferAllocations().size()); commandList->getCmdContainer().getCommandStream()->getSpace(useSize); auto latestFlushedTaskCount = whiteBoxCmdList->csr->peekLatestFlushedTaskCount(); - reinterpret_cast *>(commandList.get())->checkAvailableSpace(numEvents, false); + reinterpret_cast *>(commandList.get())->checkAvailableSpace(numEvents, false, commonImmediateCommandSize); EXPECT_EQ(1U, commandList->getCmdContainer().getCmdBufferAllocations().size()); EXPECT_EQ(latestFlushedTaskCount + 1, whiteBoxCmdList->csr->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 4634822fdf..ae2d89bbc9 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 @@ -599,7 +599,7 @@ HWTEST2_F(CommandListAppendLaunchKernel, givenCooperativeAndNonCooperativeKernel EXPECT_EQ(ZE_RESULT_SUCCESS, result); } -HWTEST2_F(CommandListAppendLaunchKernel, givenNotEnoughSpaceInCommandStreamWhenAppendingKernelWithImmediateListWithoutFlushTaskThenNewCmdBufferAllocated, IsWithinXeGfxFamily) { +HWTEST2_F(CommandListAppendLaunchKernel, givenNotEnoughSpaceInCommandStreamWhenAppendingKernelWithImmediateListWithoutFlushTaskUnrecoverableIsCalled, IsWithinXeGfxFamily) { DebugManagerStateRestore restorer; NEO::DebugManager.flags.EnableFlushTaskSubmission.set(0); using MI_BATCH_BUFFER_END = typename FamilyType::MI_BATCH_BUFFER_END; @@ -611,7 +611,6 @@ HWTEST2_F(CommandListAppendLaunchKernel, givenNotEnoughSpaceInCommandStreamWhenA auto &commandContainer = commandList->getCmdContainer(); const auto stream = commandContainer.getCommandStream(); - const auto streamCpu = stream->getCpuBase(); Vec3 groupCount{1, 1, 1}; auto sizeLeftInStream = sizeof(MI_BATCH_BUFFER_END); @@ -641,20 +640,7 @@ HWTEST2_F(CommandListAppendLaunchKernel, givenNotEnoughSpaceInCommandStreamWhenA false, false, commandList->getDcFlushRequired(true)}; - NEO::EncodeDispatchKernel::encode(commandContainer, dispatchKernelArgs, nullptr); - - auto usedSpaceAfter = commandContainer.getCommandStream()->getUsed(); - ASSERT_GT(usedSpaceAfter, 0u); - - const auto streamCpu2 = stream->getCpuBase(); - - EXPECT_NE(nullptr, streamCpu2); - EXPECT_NE(streamCpu, streamCpu2); - - EXPECT_EQ(2u, commandContainer.getCmdBufferAllocations().size()); - auto immediateHandle = commandList->toHandle(); - returnValue = commandList->cmdQImmediate->executeCommandLists(1, &immediateHandle, nullptr, false); - EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue); + EXPECT_THROW(NEO::EncodeDispatchKernel::encode(commandContainer, dispatchKernelArgs, nullptr), std::exception); } HWTEST_F(CommandListAppendLaunchKernel, givenInvalidKernelWhenAppendingThenReturnErrorInvalidArgument) { diff --git a/shared/source/command_container/cmdcontainer.cpp b/shared/source/command_container/cmdcontainer.cpp index 8001e1f44d..7bc04c4ce9 100644 --- a/shared/source/command_container/cmdcontainer.cpp +++ b/shared/source/command_container/cmdcontainer.cpp @@ -91,8 +91,12 @@ CommandContainer::ErrorCode CommandContainer::initialize(Device *device, Allocat this->bbEndReference = gfxCoreHelper.getBatchBufferEndReference(); } + CommandContainer *cmdcontainer = this; + if (this->immediateCmdListCsr) { + cmdcontainer = nullptr; + } commandStream = std::make_unique(cmdBufferAllocation->getUnderlyingBuffer(), - usableSize, this, this->selectedBbCmdSize); + usableSize, cmdcontainer, this->selectedBbCmdSize); commandStream->replaceGraphicsAllocation(cmdBufferAllocation); diff --git a/shared/source/command_stream/linear_stream.h b/shared/source/command_stream/linear_stream.h index 95bdf6f06b..9001a0e986 100644 --- a/shared/source/command_stream/linear_stream.h +++ b/shared/source/command_stream/linear_stream.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -32,6 +32,7 @@ class LinearStream { size_t getMaxAvailableSpace() const; size_t getAvailableSpace() const; size_t getUsed() const; + void *getCmdContainer() const { return cmdContainer; } uint64_t getGpuBase() const; void setGpuBase(uint64_t gpuAddress); 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 41b4b6849a..53870e7829 100644 --- a/shared/test/unit_test/command_container/command_container_tests.cpp +++ b/shared/test/unit_test/command_container/command_container_tests.cpp @@ -1855,3 +1855,10 @@ HWTEST_F(CommandContainerTest, EXPECT_EQ(nullptr, cmdContainer.getEndCmdPtr()); EXPECT_EQ(0u, cmdContainer.getAlignedPrimarySize()); } + +TEST_F(CommandContainerTest, givenCmdContainerWhenImmediateCmdListCsrIsSetThenCommandStreamHasCmdContainerSetToNullptr) { + CommandContainer cmdContainer; + cmdContainer.setImmediateCmdListCsr(pDevice->getDefaultEngine().commandStreamReceiver); + cmdContainer.initialize(pDevice, nullptr, HeapSize::defaultHeapSize, false, false); + EXPECT_EQ(cmdContainer.getCommandStream()->getCmdContainer(), nullptr); +}