// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once #include #include #include #include #include #include "core/common/common.h" #include "core/session/onnxruntime_c_api.h" onnxruntime::common::Status CopyStringToOutputArg(std::string_view str, const char* err_msg, char* out, size_t* size); struct OrtSessionOptions; struct OrtStatus; struct OrtPrepackedWeightsContainer; namespace onnxruntime { class InferenceSession; class ModelCompilationOptions; } // namespace onnxruntime #if !defined(ORT_MINIMAL_BUILD) namespace onnxruntime { class Environment; class EpLibrary; class EpFactoryInternal; class IExecutionProvider; class ModelPackageComponentContext; struct IExecutionProviderFactory; struct SessionOptions; struct VariantSelectionEpInfo; } // namespace onnxruntime #endif // !defined(ORT_MINIMAL_BUILD) OrtStatus* CreateSessionAndLoadModel(_In_ const OrtSessionOptions* options, _In_ const OrtEnv* env, _In_opt_z_ const ORTCHAR_T* model_path, _In_opt_ const void* model_data, size_t model_data_length, std::unique_ptr& sess); OrtStatus* InitializeSession(_In_ const OrtSessionOptions* options, _In_ onnxruntime::InferenceSession& sess, _Inout_opt_ OrtPrepackedWeightsContainer* prepacked_weights_container = nullptr); #if !defined(ORT_MINIMAL_BUILD) namespace onnxruntime { /// /// Compiles an ONNX model into a model with EPContext nodes. Each EPContext node represents a subgraph compiled for /// a specific execution provider. /// /// A reference to the Environment instance. /// An object specifying the compilation options. /// A Status indicating an error or success. Status CompileModel(const Environment& env, const ModelCompilationOptions& model_compile_options); // load a library that is added using RegisterExecutionProviderLibrary. // infer whether it's a provider bridge library or plugin library Status LoadPluginOrProviderBridge(const std::string& registration_name, const ORTCHAR_T* library_path, std::unique_ptr& ep_library, std::vector& internal_factories); // Creates an IExecutionProviderFactory instance for a list of OrtEpDevices that all refer to the same EP. Status CreateIExecutionProviderFactoryForEpDevices(const Environment& env, gsl::span ep_devices, /*output*/ std::unique_ptr& out); // Adds provider options to the OrtSessionOptions configuration. Status AddEpOptionsToSessionOptions(gsl::span ep_devices, gsl::span ep_options_keys, gsl::span ep_options_vals, SessionOptions& session_options); // Adss EP specific custom domains to the OrtSessionOptions configuration. Status AddEpCustomDomainsToSessionOptions(gsl::span ep_devices, OrtSessionOptions& ort_session_options); // Builds VariantSelectionEpInfo entries from already-created IExecutionProvider instances. // Same logic used by the standard CreateSession path for model package workflows; exposed so // the model package API can pre-resolve EP selection (see ModelPackageOptions::ResolveEpSelection). // /// Constraints (matching the standard path): // - Only one EP is selected (CPU EP is skipped in favor of the first non-CPU EP if available). // - All devices are expected to be supported by the same EP. Status GetVariantSelectionEpInfo(std::vector>& provider_list, std::vector& ep_infos); // Logs available environment EP devices and the ones selected for variant selection. Informational only. Status PrintAvailableAndSelectedEpInfos(const Environment& env, std::vector& ep_infos); // Create session for model package workflow. OrtStatus* CreateSessionForModelPackage( _In_ const OrtSessionOptions* options, const onnxruntime::Environment& env, const std::filesystem::path& selected_model_path, onnxruntime::ModelPackageComponentContext& model_package_context, std::unique_ptr& sess); } // namespace onnxruntime #endif // !defined(ORT_MINIMAL_BUILD)