From 531e875fb550f7a866cd13639fb2e332440e6b96 Mon Sep 17 00:00:00 2001 From: raoanag <127366241+raoanag@users.noreply.github.com> Date: Fri, 17 Nov 2023 16:43:47 -0800 Subject: [PATCH] Avoid command list reset in common case of re-used command list execution (#18370) ### Description ### Motivation and Context Co-authored-by: Jeff Bloomfield --- .../src/DmlCommandRecorder.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/DmlCommandRecorder.cpp b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/DmlCommandRecorder.cpp index 530c26d212..98345f37b6 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/DmlCommandRecorder.cpp +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/DmlCommandRecorder.cpp @@ -251,6 +251,24 @@ void DmlCommandRecorder::ExecuteCommandList( _Out_ uint64_t* completionValue ) { + if (!m_operationsRecordedInCurrentCommandList) + { + // The caller can re-use relevant resources after the next set of work to be + // flushed has completed. Its command list hasn't been executed yet, just batched. + GpuEvent gpuEvent = m_queue->GetNextCompletionEvent(); + gpuEvent.fence.CopyTo(fence); + *completionValue = gpuEvent.fenceValue; + + m_queue->ExecuteCommandLists( + gsl::span(reinterpret_cast(&commandList), 1)); + + // Fail early if something horrifying happens + ORT_THROW_IF_FAILED(m_dmlDevice->GetDeviceRemovedReason()); + ORT_THROW_IF_FAILED(m_d3dDevice->GetDeviceRemovedReason()); + + return; + } + ORT_THROW_IF_FAILED(m_currentCommandList->Close()); if (m_operationsRecordedInCurrentCommandList)