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(); }