From 4c32529b5b793898c47ecb1cb8bab6c5f0746b22 Mon Sep 17 00:00:00 2001 From: Lukasz Jobczyk Date: Wed, 15 Feb 2023 12:34:14 +0000 Subject: [PATCH] Move fillReusableAllocationLists to first append Related-To: NEO-7422 Signed-off-by: Lukasz Jobczyk --- .../source/cmdlist/cmdlist_hw_immediate.inl | 1 + .../core/source/cmdlist/cmdlist_imp.cpp | 1 - .../sources/cmdlist/test_cmdlist_5.cpp | 1 + .../sources/cmdlist/test_cmdlist_6.cpp | 3 +++ .../sources/cmdlist/test_cmdlist_7.cpp | 1 + .../test_cmdlist_append_launch_kernel_1.cpp | 2 ++ .../xe_hpc_core/test_cmdlist_xe_hpc_core.cpp | 19 +++++++++++++++++-- .../source/command_container/cmdcontainer.cpp | 4 ++++ 8 files changed, 29 insertions(+), 3 deletions(-) diff --git a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl index e4ac99420b..da07519e87 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl @@ -35,6 +35,7 @@ NEO::LogicalStateHelper *CommandListCoreFamilyImmediate::getLogic template void CommandListCoreFamilyImmediate::checkAvailableSpace(uint32_t numEvents) { + this->commandContainer.fillReusableAllocationLists(); size_t semaphoreSize = NEO::EncodeSempahore::getSizeMiSemaphoreWait() * numEvents; if (this->commandContainer.getCommandStream()->getAvailableSpace() < maxImmediateCommandSize + semaphoreSize) { diff --git a/level_zero/core/source/cmdlist/cmdlist_imp.cpp b/level_zero/core/source/cmdlist/cmdlist_imp.cpp index 6f0af74236..8e88d27bfc 100644 --- a/level_zero/core/source/cmdlist/cmdlist_imp.cpp +++ b/level_zero/core/source/cmdlist/cmdlist_imp.cpp @@ -167,7 +167,6 @@ CommandList *CommandList::createImmediate(uint32_t productFamily, Device *device commandList->isBcsSplitNeeded = deviceImp->bcsSplit.setupDevice(productFamily, internalUsage, desc, csr); commandList->commandContainer.setImmediateCmdListCsr(csr); - commandList->commandContainer.fillReusableAllocationLists(); if (commandList->isWaitForEventsFromHostEnabled()) { commandList->numThreads = NEO::SysCalls::getNumThreads(); 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 ed3aa76267..0a9feb61bc 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 @@ -1093,6 +1093,7 @@ HWTEST2_F(CommandListStateBaseAddressTest, givenStateBaseAddressTrackingWhenImmediateCmdListAppendKernelChangesHeapsAndExecuteThenFinalBaseAddressStateIsStoredInCsr, IsAtLeastSkl) { NEO::DebugManager.flags.DisableResourceRecycling.set(true); + NEO::DebugManager.flags.SetAmountOfReusableAllocations.set(0u); NEO::StateBaseAddressPropertiesSupport sbaPropertiesSupport = {}; auto &productHelper = device->getProductHelper(); diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_6.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_6.cpp index c9b820bce1..12462c49a3 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_6.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_6.cpp @@ -308,6 +308,7 @@ HWTEST2_F(CommandListTest, givenImmediateCommandListWhenAppendMemoryRangesBarrie cmdList.isFlushTaskSubmissionEnabled = true; cmdList.cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE; cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u); + cmdList.commandContainer.setImmediateCmdListCsr(device->getNEODevice()->getDefaultEngine().commandStreamReceiver); result = cmdList.appendMemoryRangesBarrier(numRanges, &rangeSizes, ranges, nullptr, 0, @@ -328,6 +329,7 @@ HWTEST2_F(CommandListTest, givenImmediateCommandListWhenAppendMemoryRangesBarrie cmdList.isFlushTaskSubmissionEnabled = false; cmdList.cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE; cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u); + cmdList.commandContainer.setImmediateCmdListCsr(device->getNEODevice()->getDefaultEngine().commandStreamReceiver); result = cmdList.appendMemoryRangesBarrier(numRanges, &rangeSizes, ranges, nullptr, 0, @@ -341,6 +343,7 @@ HWTEST2_F(CommandListTest, givenImmediateCommandListWhenFlushImmediateThenOverri MockCommandListImmediateHw cmdList; cmdList.cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE; cmdList.initialize(device, NEO::EngineGroupType::Copy, 0u); + cmdList.commandContainer.setImmediateCmdListCsr(device->getNEODevice()->getDefaultEngine().commandStreamReceiver); ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.count = 1; 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 45b999382d..eb539d57a3 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 @@ -785,6 +785,7 @@ HWTEST2_F(CmdlistAppendLaunchKernelTests, desc.mode = ZE_COMMAND_QUEUE_MODE_SYNCHRONOUS; MockCommandQueueHw mockCommandQueue(device, device->getNEODevice()->getDefaultEngine().commandStreamReceiver, &desc); commandList->cmdQImmediate = &mockCommandQueue; + commandList->commandContainer.setImmediateCmdListCsr(device->getNEODevice()->getDefaultEngine().commandStreamReceiver); ze_group_count_t groupCount = {3, 2, 1}; CmdListKernelLaunchParams launchParams = {}; diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel_1.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel_1.cpp index 4e052ce684..8ee8c88f97 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel_1.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel_1.cpp @@ -873,6 +873,7 @@ HWTEST2_F(CommandListAppendLaunchKernel, givenImmediateCommandListWhenAppendLaun cmdList.cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE; cmdList.csr = device->getNEODevice()->getDefaultEngine().commandStreamReceiver; cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u); + cmdList.commandContainer.setImmediateCmdListCsr(device->getNEODevice()->getDefaultEngine().commandStreamReceiver); ze_group_count_t groupCount{1, 1, 1}; ze_result_t returnValue; returnValue = cmdList.appendLaunchCooperativeKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr, false); @@ -888,6 +889,7 @@ HWTEST2_F(CommandListAppendLaunchKernel, givenImmediateCommandListWhenAppendLaun cmdList.cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE; cmdList.csr = device->getNEODevice()->getDefaultEngine().commandStreamReceiver; cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u); + cmdList.commandContainer.setImmediateCmdListCsr(device->getNEODevice()->getDefaultEngine().commandStreamReceiver); ze_group_count_t groupCount{1, 1, 1}; ze_result_t returnValue; returnValue = cmdList.appendLaunchCooperativeKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr, false); diff --git a/level_zero/core/test/unit_tests/xe_hpc_core/test_cmdlist_xe_hpc_core.cpp b/level_zero/core/test/unit_tests/xe_hpc_core/test_cmdlist_xe_hpc_core.cpp index ee65e64882..575d6d881a 100644 --- a/level_zero/core/test/unit_tests/xe_hpc_core/test_cmdlist_xe_hpc_core.cpp +++ b/level_zero/core/test/unit_tests/xe_hpc_core/test_cmdlist_xe_hpc_core.cpp @@ -1003,9 +1003,24 @@ HWTEST2_F(CreateCommandListXeHpcTest, whenDestroyImmediateCommandListThenGlobalA EXPECT_FALSE(static_cast(device)->allocationsForReuse->peekIsEmpty()); } -HWTEST2_F(CreateCommandListXeHpcTest, whenFlagDisabledAndCreateImmediateCommandListThenAllocationListEmpty, IsXeHpcCore) { +HWTEST2_F(CreateCommandListXeHpcTest, whenFlagEnabledAndCreateImmediateCommandListThenAllocationListEmpty, IsXeHpcCore) { DebugManagerStateRestore restore; - DebugManager.flags.SetAmountOfReusableAllocations.set(0); + DebugManager.flags.SetAmountOfReusableAllocations.set(2); + const ze_command_queue_desc_t desc = {}; + bool internalEngine = true; + + ze_result_t returnValue; + std::unique_ptr commandList(CommandList::createImmediate(productFamily, + device, + &desc, + internalEngine, + NEO::EngineGroupType::RenderCompute, + returnValue)); + ASSERT_NE(nullptr, commandList); + EXPECT_TRUE(static_cast(device)->allocationsForReuse->peekIsEmpty()); +} + +HWTEST2_F(CreateCommandListXeHpcTest, whenCreateImmediateCommandListThenAllocationListEmpty, IsXeHpcCore) { const ze_command_queue_desc_t desc = {}; bool internalEngine = true; diff --git a/shared/source/command_container/cmdcontainer.cpp b/shared/source/command_container/cmdcontainer.cpp index 1448f5401e..c93d1dee48 100644 --- a/shared/source/command_container/cmdcontainer.cpp +++ b/shared/source/command_container/cmdcontainer.cpp @@ -422,6 +422,10 @@ GraphicsAllocation *CommandContainer::allocateCommandBuffer() { } void CommandContainer::fillReusableAllocationLists() { + if (this->immediateReusableAllocationList) { + return; + } + this->immediateReusableAllocationList = std::make_unique(); const auto &hardwareInfo = device->getHardwareInfo(); auto &gfxCoreHelper = device->getGfxCoreHelper();