diff --git a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl index ebcbd3dfda..ed1179c66f 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl @@ -893,7 +893,11 @@ template ze_result_t CommandListCoreFamilyImmediate::hostSynchronize(uint64_t timeout, TaskCountType taskCount, bool handlePostWaitOperations) { ze_result_t status = ZE_RESULT_SUCCESS; - bool inOrderWaitAllowed = (isInOrderExecutionEnabled() && !handlePostWaitOperations && this->latestFlushIsHostVisible); + auto internalAllocStorage = this->csr->getInternalAllocationStorage(); + + auto tempAllocsCleanupRequired = handlePostWaitOperations && !internalAllocStorage->getTemporaryAllocations().peekIsEmpty(); + + bool inOrderWaitAllowed = (isInOrderExecutionEnabled() && !tempAllocsCleanupRequired && this->latestFlushIsHostVisible); if (inOrderWaitAllowed) { status = synchronizeInOrderExecution(timeout); @@ -912,7 +916,10 @@ ze_result_t CommandListCoreFamilyImmediate::hostSynchronize(uint6 if (handlePostWaitOperations && status != ZE_RESULT_NOT_READY) { if (status == ZE_RESULT_SUCCESS) { this->cmdQImmediate->unregisterCsrClient(); - this->csr->getInternalAllocationStorage()->cleanAllocationList(taskCount, NEO::AllocationUsage::TEMPORARY_ALLOCATION); + + if (tempAllocsCleanupRequired) { + internalAllocStorage->cleanAllocationList(taskCount, NEO::AllocationUsage::TEMPORARY_ALLOCATION); + } } this->printKernelsPrintfOutput(status == ZE_RESULT_ERROR_DEVICE_LOST); 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 9821d7f4db..750fce284e 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 @@ -17,6 +17,7 @@ #include "shared/source/helpers/register_offsets.h" #include "shared/source/indirect_heap/indirect_heap.h" #include "shared/source/kernel/implicit_args.h" +#include "shared/source/memory_manager/internal_allocation_storage.h" #include "shared/source/os_interface/os_context.h" #include "shared/source/os_interface/product_helper.h" #include "shared/test/common/cmd_parse/gen_cmd_parse.h" @@ -26,6 +27,7 @@ #include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/libult/ult_command_stream_receiver.h" #include "shared/test/common/mocks/mock_direct_submission_hw.h" +#include "shared/test/common/mocks/mock_graphics_allocation.h" #include "shared/test/common/mocks/mock_os_context.h" #include "shared/test/common/test_macros/hw_test.h" @@ -867,6 +869,11 @@ HWTEST2_F(InOrderCmdListTests, givenCmdListsWhenDispatchingThenUseInternalTaskCo auto ultCsr = static_cast *>(device->getNEODevice()->getDefaultEngine().commandStreamReceiver); + auto mockAlloc = std::make_unique(); + + auto internalAllocStorage = ultCsr->getInternalAllocationStorage(); + internalAllocStorage->storeAllocationWithTaskCount(std::move(mockAlloc), NEO::AllocationUsage::TEMPORARY_ALLOCATION, 123); + immCmdList0->appendLaunchKernel(kernel->toHandle(), groupCount, nullptr, 0, nullptr, launchParams, false); immCmdList1->appendLaunchKernel(kernel->toHandle(), groupCount, nullptr, 0, nullptr, launchParams, false); @@ -2082,6 +2089,11 @@ HWTEST2_F(InOrderCmdListTests, givenInOrderModeWhenProgrammingRegularEventThenCl HWTEST2_F(InOrderCmdListTests, givenHostVisibleEventOnLatestFlushWhenCallingSynchronizeThenUseInOrderSync, IsAtLeastSkl) { auto ultCsr = static_cast *>(device->getNEODevice()->getDefaultEngine().commandStreamReceiver); + auto mockAlloc = std::make_unique(); + + auto internalAllocStorage = ultCsr->getInternalAllocationStorage(); + internalAllocStorage->storeAllocationWithTaskCount(std::move(mockAlloc), NEO::AllocationUsage::TEMPORARY_ALLOCATION, 123); + auto immCmdList = createImmCmdList(); auto eventPool = createEvents(1, true); @@ -2131,6 +2143,37 @@ HWTEST2_F(InOrderCmdListTests, givenHostVisibleEventOnLatestFlushWhenCallingSync } } +HWTEST2_F(InOrderCmdListTests, givenEmptyTempAllocationsStorageWhenCallingSynchronizeThenUseInternalCounter, IsAtLeastSkl) { + auto ultCsr = static_cast *>(device->getNEODevice()->getDefaultEngine().commandStreamReceiver); + + auto mockAlloc = std::make_unique(); + + auto internalAllocStorage = ultCsr->getInternalAllocationStorage(); + + auto immCmdList = createImmCmdList(); + + auto eventPool = createEvents(1, true); + events[0]->signalScope = ZE_EVENT_SCOPE_FLAG_HOST; + + immCmdList->appendLaunchKernel(kernel->toHandle(), groupCount, events[0]->toHandle(), 0, nullptr, launchParams, false); + EXPECT_TRUE(immCmdList->latestFlushIsHostVisible); + + EXPECT_EQ(0u, immCmdList->synchronizeInOrderExecutionCalled); + EXPECT_EQ(0u, ultCsr->waitForCompletionWithTimeoutTaskCountCalled); + + immCmdList->hostSynchronize(0, 1, true); + + EXPECT_EQ(1u, immCmdList->synchronizeInOrderExecutionCalled); + EXPECT_EQ(0u, ultCsr->waitForCompletionWithTimeoutTaskCountCalled); + + internalAllocStorage->storeAllocationWithTaskCount(std::move(mockAlloc), NEO::AllocationUsage::TEMPORARY_ALLOCATION, 123); + + immCmdList->hostSynchronize(0, 1, true); + + EXPECT_EQ(1u, immCmdList->synchronizeInOrderExecutionCalled); + EXPECT_EQ(1u, ultCsr->waitForCompletionWithTimeoutTaskCountCalled); +} + using NonPostSyncWalkerMatcher = IsWithinGfxCore; HWTEST2_F(InOrderCmdListTests, givenNonPostSyncWalkerWhenPatchingThenThrow, NonPostSyncWalkerMatcher) { @@ -3332,6 +3375,11 @@ HWTEST2_F(InOrderCmdListTests, givenInOrderModeWhenCallingSyncThenHandleCompleti auto ultCsr = static_cast *>(device->getNEODevice()->getDefaultEngine().commandStreamReceiver); + auto mockAlloc = std::make_unique(); + + auto internalAllocStorage = ultCsr->getInternalAllocationStorage(); + internalAllocStorage->storeAllocationWithTaskCount(std::move(mockAlloc), NEO::AllocationUsage::TEMPORARY_ALLOCATION, 123); + auto eventPool = createEvents(1, false); immCmdList->appendLaunchKernel(kernel->toHandle(), groupCount, events[0]->toHandle(), 0, nullptr, launchParams, false);