// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once #include #include #include #include "core/common/inlined_containers_fwd.h" #ifndef SHARED_PROVIDER #include "core/framework/ort_value.h" #endif namespace onnxruntime { class ExecutionProviders; class IExecutionProvider; class OrtValueNameIdxMap; class SessionState; enum class DeviceCopyCheck { Unknown, NoCopy, Copy }; struct DeviceCopyChecks { DeviceCopyCheck status = DeviceCopyCheck::Unknown; ///< Overall status. NoCopy means input_copy_needed and output_copy_needed are both NoCopy DeviceCopyCheck input_copy_needed = DeviceCopyCheck::Unknown; DeviceCopyCheck output_copy_needed = DeviceCopyCheck::Unknown; }; struct FeedsFetchesInfo { FeedsFetchesInfo() = default; FeedsFetchesInfo(gsl::span feed_names_in, gsl::span output_names_in, const OrtValueNameIdxMap& ort_value_name_idx_map) : feed_names(), output_names() { feed_names.reserve(feed_names_in.size()); feed_names.assign(feed_names_in.begin(), feed_names_in.end()); output_names.reserve(output_names_in.size()); output_names.assign(output_names_in.begin(), output_names_in.end()); ORT_THROW_IF_ERROR(SetMLValueIdxs(ort_value_name_idx_map)); } FeedsFetchesInfo(gsl::span feed_names_in, gsl::span output_names_in, const OrtValueNameIdxMap& ort_value_name_idx_map) : feed_names(), output_names() { feed_names.reserve(feed_names_in.size()); feed_names.assign(feed_names_in.begin(), feed_names_in.end()); output_names.reserve(output_names_in.size()); output_names.assign(output_names_in.begin(), output_names_in.end()); ORT_THROW_IF_ERROR(SetMLValueIdxs(ort_value_name_idx_map)); } static Status MapNamesToMLValueIdxs(gsl::span names, const OrtValueNameIdxMap& ort_value_name_idx_map, InlinedVector& ort_value_idxs); // set the ort_value_idxs for the current values in feed_names and output_names Status SetMLValueIdxs(const OrtValueNameIdxMap& ort_value_name_idx_map); InlinedVector feed_names; InlinedVector output_names; InlinedVector feeds_mlvalue_idxs; InlinedVector fetches_mlvalue_idxs; }; struct MLValueCopyInfo { OrtDevice source_device{}; OrtDevice target_device{}; // default is CPU // if all the consume ops are from the same stream, this variable is the stream index; otherwise -1 int unique_stream_index_consumes_it = -1; }; class FeedsFetchesManager { public: static Status Create(gsl::span feed_names, gsl::span output_names, const OrtValueNameIdxMap& ort_value_name_idx_map, std::unique_ptr& feeds_fetches_manager); static Status Create(gsl::span feed_names, gsl::span output_names, const OrtValueNameIdxMap& ort_value_name_idx_map, std::optional& feeds_fetches_manager); FeedsFetchesManager(FeedsFetchesInfo&& info); const FeedsFetchesInfo& GetFeedsFetchesInfo() const { return feeds_fetches_info_; } std::vector& GetMutableFeedsDeviceCopyInfo() { return feeds_device_copy_info_; } const std::vector& GetFeedsDeviceCopyInfo() const { return feeds_device_copy_info_; } std::vector& GetMutableFetchesDeviceCopyInfo() { return fetches_device_copy_info_; } const std::vector& GetFetchesDeviceCopyInfo() const { return fetches_device_copy_info_; } const DeviceCopyChecks& GetDeviceCopyChecks() const { return device_copy_checks_; } void SetDeviceCopyChecks(DeviceCopyCheck input_copy_needed, DeviceCopyCheck output_copy_needed); private: ORT_DISALLOW_COPY_ASSIGNMENT_AND_MOVE(FeedsFetchesManager); DeviceCopyChecks device_copy_checks_ = {}; FeedsFetchesInfo feeds_fetches_info_; std::vector feeds_device_copy_info_; std::vector fetches_device_copy_info_; }; } // namespace onnxruntime