From 64f06d0b4a9e5b3b97538c7cd809531a8f7b93af Mon Sep 17 00:00:00 2001 From: cao lei Date: Wed, 30 Aug 2023 16:10:26 -0700 Subject: [PATCH] only Flush once for the same stream in copyInputAcrossDevice() (#17303) ### Description In CopyInputAcrossDevice() function, we assign each feed a stream to copy across device, once the copy is done, each stream will trigger the Flush() function which is undesired. Same stream should be only flushed once ### Motivation and Context This change is to address a perf issue of TLNGv4 inference which contains subgraph with many input feeds. --- onnxruntime/core/framework/utils.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/onnxruntime/core/framework/utils.cc b/onnxruntime/core/framework/utils.cc index d762211f78..b6dd851734 100644 --- a/onnxruntime/core/framework/utils.cc +++ b/onnxruntime/core/framework/utils.cc @@ -478,9 +478,9 @@ static common::Status CopyInputsAcrossDevices(const SessionState& session_state, // TODO: this sync is because the graph inputs can be consumed by multiple stream, // but we can only place the MemCpyAsync on one of the stream. Ideally we should make // other stream wait on the event of the memory copy stream, instead of host sync stream. + std::unordered_set visited; for (auto* stream : feed_streams) { - if (stream) - stream->Flush(); + if (stream && visited.insert(stream).second) stream->Flush(); } return Status::OK(); }