diff --git a/level_zero/core/source/cmdqueue/cmdqueue.cpp b/level_zero/core/source/cmdqueue/cmdqueue.cpp index bfe98f13dd..4a6454cd96 100644 --- a/level_zero/core/source/cmdqueue/cmdqueue.cpp +++ b/level_zero/core/source/cmdqueue/cmdqueue.cpp @@ -96,8 +96,6 @@ NEO::SubmissionStatus CommandQueueImp::submitBatchBuffer(size_t offset, NEO::Res csr->setActivePartitions(partitionCount); auto ret = csr->submitBatchBuffer(batchBuffer, csr->getResidencyAllocations()); if (ret != NEO::SubmissionStatus::SUCCESS) { - commandStream->getGraphicsAllocation()->updateTaskCount(csr->peekTaskCount(), csr->getOsContext().getContextId()); - commandStream->getGraphicsAllocation()->updateResidencyTaskCount(csr->peekTaskCount(), csr->getOsContext().getContextId()); return ret; } diff --git a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl index dee39b0dc3..c2801a72db 100644 --- a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl +++ b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl @@ -22,7 +22,6 @@ #include "shared/source/helpers/hw_info.h" #include "shared/source/helpers/pipe_control_args.h" #include "shared/source/helpers/preamble.h" -#include "shared/source/memory_manager/graphics_allocation.h" #include "shared/source/memory_manager/memory_manager.h" #include "shared/source/memory_manager/residency_container.h" #include "shared/source/os_interface/hw_info_config.h" @@ -476,30 +475,27 @@ ze_result_t CommandQueueHw::executeCommandLists( csr->setLatestFlushedTaskCount(this->taskCount); } - ze_result_t retVal = ZE_RESULT_SUCCESS; + csr->makeSurfacePackNonResident(csr->getResidencyAllocations()); + if (getSynchronousMode() == ZE_COMMAND_QUEUE_MODE_SYNCHRONOUS) { const auto synchronizeResult = this->synchronize(std::numeric_limits::max()); if (synchronizeResult == ZE_RESULT_ERROR_DEVICE_LOST) { - retVal = ZE_RESULT_ERROR_DEVICE_LOST; + return ZE_RESULT_ERROR_DEVICE_LOST; } - } else { - csr->pollForCompletion(); } + this->heapContainer.clear(); - if ((ret != NEO::SubmissionStatus::SUCCESS) || (retVal == ZE_RESULT_ERROR_DEVICE_LOST)) { - for (auto &gfx : csr->getResidencyAllocations()) { - gfx->updateTaskCount(csr->peekLatestFlushedTaskCount(), csr->getOsContext().getContextId()); - } - if (retVal != ZE_RESULT_ERROR_DEVICE_LOST) { - retVal = ZE_RESULT_ERROR_UNKNOWN; - } + csr->pollForCompletion(); + + if (ret != NEO::SubmissionStatus::SUCCESS) { if (ret == NEO::SubmissionStatus::OUT_OF_MEMORY) { - retVal = ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; + return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; } + return ZE_RESULT_ERROR_UNKNOWN; } - csr->makeSurfacePackNonResident(csr->getResidencyAllocations()); - return retVal; + + return ZE_RESULT_SUCCESS; } 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 62b4e47ee7..ffe0a01055 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 @@ -353,15 +353,11 @@ HWTEST_F(CommandQueueCreate, givenContainerWithAllocationsWhenResidencyContainer false, returnValue)); ResidencyContainer container; - uint32_t peekTaskCountBefore = commandQueue->csr->peekTaskCount(); - uint32_t flushedTaskCountBefore = commandQueue->csr->peekLatestFlushedTaskCount(); - NEO::SubmissionStatus ret = commandQueue->submitBatchBuffer(0, container, nullptr, false); + commandQueue->submitBatchBuffer(0, container, nullptr, false); EXPECT_EQ(csr->makeResidentCalledTimes, 0u); - EXPECT_EQ(ret, NEO::SubmissionStatus::SUCCESS); - EXPECT_EQ((peekTaskCountBefore + 1), commandQueue->csr->peekTaskCount()); - EXPECT_EQ((flushedTaskCountBefore + 1), commandQueue->csr->peekLatestFlushedTaskCount()); + + EXPECT_EQ(commandQueue->commandStream->getGraphicsAllocation()->getTaskCount(commandQueue->csr->getOsContext().getContextId()), commandQueue->csr->peekTaskCount()); EXPECT_EQ(commandQueue->commandStream->getGraphicsAllocation()->getTaskCount(commandQueue->csr->getOsContext().getContextId()), commandQueue->csr->peekTaskCount()); - EXPECT_EQ(commandQueue->commandStream->getGraphicsAllocation()->getResidencyTaskCount(commandQueue->csr->getOsContext().getContextId()), commandQueue->csr->peekTaskCount()); commandQueue->destroy(); } @@ -378,14 +374,9 @@ HWTEST_F(CommandQueueCreate, givenCommandStreamReceiverFailsThenSubmitBatchBuffe false, returnValue)); ResidencyContainer container; - uint32_t peekTaskCountBefore = commandQueue->csr->peekTaskCount(); - uint32_t flushedTaskCountBefore = commandQueue->csr->peekLatestFlushedTaskCount(); NEO::SubmissionStatus ret = commandQueue->submitBatchBuffer(0, container, nullptr, false); EXPECT_EQ(ret, NEO::SubmissionStatus::FAILED); - EXPECT_EQ(peekTaskCountBefore, commandQueue->csr->peekTaskCount()); - EXPECT_EQ(flushedTaskCountBefore, commandQueue->csr->peekLatestFlushedTaskCount()); - EXPECT_EQ(commandQueue->commandStream->getGraphicsAllocation()->getTaskCount(commandQueue->csr->getOsContext().getContextId()), commandQueue->csr->peekTaskCount()); - EXPECT_EQ(commandQueue->commandStream->getGraphicsAllocation()->getResidencyTaskCount(commandQueue->csr->getOsContext().getContextId()), commandQueue->csr->peekTaskCount()); + commandQueue->destroy(); } @@ -1526,57 +1517,6 @@ HWTEST2_F(ExecuteCommandListTests, givenFailingSubmitBatchBufferThenExecuteComma commandList->destroy(); } -HWTEST2_F(ExecuteCommandListTests, givenFailingSubmitBatchBufferThenResetGraphicsTaskCounts, IsAtLeastSkl) { - ze_command_queue_desc_t desc = {}; - NEO::CommandStreamReceiver *csr; - device->getCsrForOrdinalAndIndex(&csr, 0u, 0u); - auto commandQueue = new MockCommandQueueSubmitBatchBuffer(device, csr, &desc); - commandQueue->submitBatchBufferResult = NEO::SubmissionStatus::FAILED; - - commandQueue->initialize(false, false); - auto commandList = new CommandListCoreFamily(); - commandList->initialize(device, NEO::EngineGroupType::Compute, 0u); - auto commandListHandle = commandList->toHandle(); - - void *alloc = alignedMalloc(0x100, 0x100); - NEO::GraphicsAllocation graphicsAllocation1(0, NEO::AllocationType::BUFFER, alloc, 0u, 0u, 1u, MemoryPool::System4KBPages, 1u); - NEO::GraphicsAllocation graphicsAllocation2(0, NEO::AllocationType::BUFFER, alloc, 0u, 0u, 1u, MemoryPool::System4KBPages, 1u); - graphicsAllocation1.updateTaskCount(3, csr->getOsContext().getContextId()); - graphicsAllocation2.updateTaskCount(3, csr->getOsContext().getContextId()); - commandList->commandContainer.addToResidencyContainer(&graphicsAllocation1); - commandList->commandContainer.addToResidencyContainer(&graphicsAllocation2); - auto res = commandQueue->executeCommandLists(1, &commandListHandle, nullptr, false); - EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, res); - - EXPECT_EQ(0u, graphicsAllocation1.getTaskCount(csr->getOsContext().getContextId())); - EXPECT_EQ(0u, graphicsAllocation2.getTaskCount(csr->getOsContext().getContextId())); - - commandQueue->destroy(); - commandList->destroy(); - alignedFree(alloc); -} - -HWTEST2_F(ExecuteCommandListTests, givenFailingSubmitBatchBufferThenWaitForCompletionFalse, IsAtLeastSkl) { - ze_command_queue_desc_t desc = {}; - NEO::CommandStreamReceiver *csr; - device->getCsrForOrdinalAndIndex(&csr, 0u, 0u); - auto commandQueue = new MockCommandQueueSubmitBatchBuffer(device, csr, &desc); - commandQueue->submitBatchBufferResult = NEO::SubmissionStatus::FAILED; - - commandQueue->initialize(false, false); - auto commandList = new CommandListCoreFamily(); - commandList->initialize(device, NEO::EngineGroupType::Compute, 0u); - auto commandListHandle = commandList->toHandle(); - uint32_t flushedTaskCountPrior = csr->peekTaskCount(); - csr->setLatestFlushedTaskCount(flushedTaskCountPrior); - auto res = commandQueue->executeCommandLists(1, &commandListHandle, nullptr, false); - EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, res); - EXPECT_EQ(csr->peekLatestFlushedTaskCount(), flushedTaskCountPrior); - - commandQueue->destroy(); - commandList->destroy(); -} - HWTEST2_F(ExecuteCommandListTests, givenSuccessfulSubmitBatchBufferThenExecuteCommandListReturnsSuccess, IsAtLeastSkl) { ze_command_queue_desc_t desc = {}; NEO::CommandStreamReceiver *csr; diff --git a/shared/source/command_stream/command_stream_receiver.cpp b/shared/source/command_stream/command_stream_receiver.cpp index 7d1d5c06fa..cce706a655 100644 --- a/shared/source/command_stream/command_stream_receiver.cpp +++ b/shared/source/command_stream/command_stream_receiver.cpp @@ -103,10 +103,6 @@ SubmissionStatus CommandStreamReceiver::submitBatchBuffer(BatchBuffer &batchBuff this->latestSentTaskCount = taskCount + 1; SubmissionStatus retVal = this->flush(batchBuffer, allocationsForResidency); - - if (retVal != NEO::SubmissionStatus::SUCCESS) { - return retVal; - } if (!isUpdateTagFromWaitEnabled()) { this->latestFlushedTaskCount = taskCount + 1; } diff --git a/shared/source/os_interface/linux/drm_command_stream.inl b/shared/source/os_interface/linux/drm_command_stream.inl index aa3c1172b8..0a748bd54f 100644 --- a/shared/source/os_interface/linux/drm_command_stream.inl +++ b/shared/source/os_interface/linux/drm_command_stream.inl @@ -246,12 +246,9 @@ int DrmCommandStreamReceiver::exec(const BatchBuffer &batchBuffer, ui template void DrmCommandStreamReceiver::processResidency(const ResidencyContainer &inputAllocationsForResidency, uint32_t handleId) { - - if ((!drm->isVmBindAvailable()) || (DebugManager.flags.PassBoundBOToExec.get() == 1)) { - for (auto &alloc : inputAllocationsForResidency) { - auto drmAlloc = static_cast(alloc); - drmAlloc->makeBOsResident(osContext, handleId, &this->residency, false); - } + for (auto &alloc : inputAllocationsForResidency) { + auto drmAlloc = static_cast(alloc); + drmAlloc->makeBOsResident(osContext, handleId, &this->residency, false); } } diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp index 0ce34d6c66..c6e2bbcc52 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp +++ b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp @@ -104,7 +104,6 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::isResident(Device *device } MemoryOperationsStatus DrmMemoryOperationsHandlerBind::mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) { - if (DebugManager.flags.MakeEachAllocationResident.get() == 2) { auto memoryManager = static_cast(this->rootDeviceEnvironment.executionEnvironment.memoryManager.get()); @@ -118,6 +117,15 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::mergeWithResidencyContain return retVal; } + auto clearContainer = true; + + if (DebugManager.flags.PassBoundBOToExec.get() != -1) { + clearContainer = !DebugManager.flags.PassBoundBOToExec.get(); + } + + if (clearContainer) { + residencyContainer.clear(); + } return MemoryOperationsStatus::SUCCESS; } diff --git a/shared/test/common/mocks/mock_command_stream_receiver.h b/shared/test/common/mocks/mock_command_stream_receiver.h index 66705aa28f..9379093b90 100644 --- a/shared/test/common/mocks/mock_command_stream_receiver.h +++ b/shared/test/common/mocks/mock_command_stream_receiver.h @@ -197,15 +197,6 @@ class MockCommandStreamReceiverWithOutOfMemorySubmitBatch : public MockCommandSt } }; -class MockCommandStreamReceiverWithFailingFlush : public MockCommandStreamReceiver { - public: - MockCommandStreamReceiverWithFailingFlush(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex, const DeviceBitfield deviceBitfield) - : MockCommandStreamReceiver(executionEnvironment, rootDeviceIndex, deviceBitfield) {} - SubmissionStatus flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override { - return SubmissionStatus::FAILED; - } -}; - template class MockCsrHw2 : public CommandStreamReceiverHw { public: diff --git a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp index f656f7c3da..1f41e94930 100644 --- a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp +++ b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp @@ -492,28 +492,6 @@ TEST(CommandStreamReceiverSimpleTest, givenCsrWhenSubmitiingBatchBufferThenTaskC executionEnvironment.memoryManager->freeGraphicsMemoryImpl(commandBuffer); } -TEST(CommandStreamReceiverSimpleTest, givenCsrWhenSubmittingBatchBufferAndFlushFailThenTaskCountIsNotIncremented) { - MockExecutionEnvironment executionEnvironment; - executionEnvironment.prepareRootDeviceEnvironments(1); - executionEnvironment.initializeMemoryManager(); - DeviceBitfield deviceBitfield(1); - MockCommandStreamReceiverWithFailingFlush csr(executionEnvironment, 0, deviceBitfield); - GraphicsAllocation *commandBuffer = executionEnvironment.memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr.getRootDeviceIndex(), MemoryConstants::pageSize}); - ASSERT_NE(nullptr, commandBuffer); - LinearStream cs(commandBuffer); - - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr, false}; - ResidencyContainer residencyList; - - auto expectedTaskCount = csr.peekTaskCount(); - csr.submitBatchBuffer(batchBuffer, residencyList); - - EXPECT_EQ(expectedTaskCount, csr.peekTaskCount()); - EXPECT_EQ(expectedTaskCount, csr.peekLatestFlushedTaskCount()); - - executionEnvironment.memoryManager->freeGraphicsMemoryImpl(commandBuffer); -} - HWTEST_F(CommandStreamReceiverTest, givenUpdateTaskCountFromWaitWhenSubmitiingBatchBufferThenTaskCountIsIncrementedAndLatestsValuesSetCorrectly) { DebugManagerStateRestore restorer; DebugManager.flags.UpdateTaskCountFromWait.set(3);