From 5b11a4a5faabd461beaf450b3aae7f7c212695bb Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Mon, 7 Nov 2022 11:50:09 +0000 Subject: [PATCH] Return submission status from flushHandler function Related-To: NEO-7412 Signed-off-by: Mateusz Jablonski --- .../source/cmdlist/cmdlist_hw_immediate.inl | 8 +++++ .../sources/cmdlist/test_cmdlist_6.cpp | 34 +++++++++++++++++++ .../command_stream_receiver_hw.h | 2 +- .../command_stream_receiver_hw_base.inl | 11 ++++-- .../command_stream_receiver_tests.cpp | 33 ++++++++++++++++++ 5 files changed, 84 insertions(+), 4 deletions(-) diff --git a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl index 7a45c39723..a08e36f2e6 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl @@ -10,6 +10,7 @@ #include "shared/source/command_container/command_encoder.h" #include "shared/source/command_stream/command_stream_receiver_hw.h" #include "shared/source/command_stream/wait_status.h" +#include "shared/source/helpers/completion_stamp.h" #include "shared/source/helpers/hw_helper.h" #include "shared/source/helpers/hw_info.h" #include "shared/source/helpers/logical_state_helper.h" @@ -189,6 +190,13 @@ ze_result_t CommandListCoreFamilyImmediate::executeCommandListImm dispatchFlags, *(this->device->getNEODevice())); + if (completionStamp.taskCount > NEO::CompletionStamp::notReady) { + if (completionStamp.taskCount == NEO::CompletionStamp::outOfHostMemory) { + return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY; + } + return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; + } + if (this->isSyncModeQueue) { auto timeoutMicroseconds = NEO::TimeoutControls::maxTimeout; const auto waitStatus = this->csr->waitForCompletionWithTimeout(NEO::WaitParams{false, false, timeoutMicroseconds}, completionStamp.taskCount); 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 b591d7b0ee..ab6b6b8ed7 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 @@ -132,6 +132,40 @@ HWTEST2_F(CommandListExecuteImmediate, whenExecutingCommandListImmediateWithFlus EXPECT_FALSE(commandListImmediate.containsAnyKernel); } +HWTEST2_F(CommandListExecuteImmediate, whenExecutingCommandListImmediateWithFlushTaskThenSuccessIsReturned, IsAtLeastSkl) { + std::unique_ptr commandList; + const ze_command_queue_desc_t desc = {}; + ze_result_t returnValue; + commandList.reset(CommandList::createImmediate(productFamily, device, &desc, false, NEO::EngineGroupType::RenderCompute, returnValue)); + auto &commandListImmediate = static_cast &>(*commandList); + + EXPECT_EQ(ZE_RESULT_SUCCESS, commandListImmediate.executeCommandListImmediateWithFlushTask(false)); +} + +HWTEST2_F(CommandListExecuteImmediate, givenOutOfHostMemoryErrorOnFlushWhenExecutingCommandListImmediateWithFlushTaskThenProperErrorIsReturned, IsAtLeastSkl) { + std::unique_ptr commandList; + const ze_command_queue_desc_t desc = {}; + ze_result_t returnValue; + commandList.reset(CommandList::createImmediate(productFamily, device, &desc, false, NEO::EngineGroupType::RenderCompute, returnValue)); + auto &commandListImmediate = static_cast &>(*commandList); + + auto &commandStreamReceiver = neoDevice->getUltCommandStreamReceiver(); + commandStreamReceiver.flushReturnValue = SubmissionStatus::OUT_OF_HOST_MEMORY; + EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY, commandListImmediate.executeCommandListImmediateWithFlushTask(false)); +} + +HWTEST2_F(CommandListExecuteImmediate, givenOutOfDeviceMemoryErrorOnFlushWhenExecutingCommandListImmediateWithFlushTaskThenProperErrorIsReturned, IsAtLeastSkl) { + std::unique_ptr commandList; + const ze_command_queue_desc_t desc = {}; + ze_result_t returnValue; + commandList.reset(CommandList::createImmediate(productFamily, device, &desc, false, NEO::EngineGroupType::RenderCompute, returnValue)); + auto &commandListImmediate = static_cast &>(*commandList); + + auto &commandStreamReceiver = neoDevice->getUltCommandStreamReceiver(); + commandStreamReceiver.flushReturnValue = SubmissionStatus::OUT_OF_MEMORY; + EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, commandListImmediate.executeCommandListImmediateWithFlushTask(false)); +} + using CommandListTest = Test; using IsDcFlushSupportedPlatform = IsWithinGfxCore; diff --git a/shared/source/command_stream/command_stream_receiver_hw.h b/shared/source/command_stream/command_stream_receiver_hw.h index 5f83675fa9..9a57f5d960 100644 --- a/shared/source/command_stream/command_stream_receiver_hw.h +++ b/shared/source/command_stream/command_stream_receiver_hw.h @@ -104,7 +104,7 @@ class CommandStreamReceiverHw : public CommandStreamReceiver { void flushPipeControl(); void flushSmallTask(LinearStream &commandStreamTask, size_t commandStreamStartTask); - void flushHandler(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency); + SubmissionStatus flushHandler(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency); bool isUpdateTagFromWaitEnabled() override; void updateTagFromWait() override; diff --git a/shared/source/command_stream/command_stream_receiver_hw_base.inl b/shared/source/command_stream/command_stream_receiver_hw_base.inl index 7e84d94985..0cf81a60b7 100644 --- a/shared/source/command_stream/command_stream_receiver_hw_base.inl +++ b/shared/source/command_stream/command_stream_receiver_hw_base.inl @@ -608,7 +608,11 @@ CompletionStamp CommandStreamReceiverHw::flushTask( if (submitCSR || submitTask) { if (this->dispatchMode == DispatchMode::ImmediateDispatch) { - flushHandler(batchBuffer, this->getResidencyAllocations()); + auto submissionStatus = flushHandler(batchBuffer, this->getResidencyAllocations()); + if (submissionStatus != SubmissionStatus::SUCCESS) { + CompletionStamp completionStamp = {CompletionStamp::getTaskCountFromSubmissionStatusError(submissionStatus)}; + return completionStamp; + } if (dispatchFlags.blocking || dispatchFlags.dcFlush || dispatchFlags.guardCommandBufferWithPipeControl) { this->latestFlushedTaskCount = this->taskCount + 1; } @@ -1273,9 +1277,10 @@ void CommandStreamReceiverHw::flushSmallTask(LinearStream &commandStr } template -inline void CommandStreamReceiverHw::flushHandler(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) { - flush(batchBuffer, allocationsForResidency); +inline SubmissionStatus CommandStreamReceiverHw::flushHandler(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) { + auto status = flush(batchBuffer, allocationsForResidency); makeSurfacePackNonResident(allocationsForResidency, true); + return status; } template 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 d939c60625..8d8fa9d9f8 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 @@ -2344,4 +2344,37 @@ HWTEST_F(CommandStreamReceiverHwTest, givenFailureOnFlushWhenFlushingBcsTaskThen EXPECT_EQ(CompletionStamp::outOfHostMemory, commandStreamReceiver.flushBcsTask(container, true, false, *pDevice)); commandStreamReceiver.flushReturnValue = SubmissionStatus::OUT_OF_MEMORY; EXPECT_EQ(CompletionStamp::outOfDeviceMemory, commandStreamReceiver.flushBcsTask(container, true, false, *pDevice)); +} + +HWTEST_F(CommandStreamReceiverHwTest, givenOutOfHostMemoryFailureOnFlushWhenFlushingTaskThenErrorIsPropagated) { + auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); + + commandStreamReceiver.flushReturnValue = SubmissionStatus::OUT_OF_HOST_MEMORY; + + auto completionStamp = commandStreamReceiver.flushTask(commandStream, + 0, + &dsh, + &ioh, + nullptr, + taskLevel, + flushTaskFlags, + *pDevice); + EXPECT_EQ(CompletionStamp::outOfHostMemory, completionStamp.taskCount); +} + +HWTEST_F(CommandStreamReceiverHwTest, givenOutOfDeviceMemoryFailureOnFlushWhenFlushingTaskThenErrorIsPropagated) { + auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); + + commandStreamReceiver.flushReturnValue = SubmissionStatus::OUT_OF_MEMORY; + + auto completionStamp = commandStreamReceiver.flushTask(commandStream, + 0, + &dsh, + &ioh, + nullptr, + taskLevel, + flushTaskFlags, + *pDevice); + + EXPECT_EQ(CompletionStamp::outOfDeviceMemory, completionStamp.taskCount); } \ No newline at end of file