@@ -348,6 +348,9 @@ ORT_RUNTIME_CLASS(ExternalSemaphoreHandle); // EP-imported view of shared exte
348348ORT_RUNTIME_CLASS (DeviceEpIncompatibilityDetails);
349349ORT_RUNTIME_CLASS (EpAssignedSubgraph);
350350ORT_RUNTIME_CLASS (EpAssignedNode);
351+ ORT_RUNTIME_CLASS (ModelPackageOptions);
352+ ORT_RUNTIME_CLASS (ModelPackageContext);
353+ ORT_RUNTIME_CLASS (ModelPackageComponentContext);
351354
352355#ifdef _MSC_VER
353356typedef _Return_type_success_ (return == 0 ) OrtStatus* OrtStatusPtr;
@@ -925,6 +928,9 @@ typedef struct OrtCompileApi OrtCompileApi;
925928struct OrtInteropApi ;
926929typedef struct OrtInteropApi OrtInteropApi;
927930
931+ struct OrtModelPackageApi ;
932+ typedef struct OrtModelPackageApi OrtModelPackageApi;
933+
928934struct OrtEpApi ;
929935typedef struct OrtEpApi OrtEpApi;
930936
@@ -7486,6 +7492,26 @@ struct OrtApi {
74867492 * \since Version 1.27.
74877493 */
74887494 ORT_API2_STATUS (SessionReleaseCapturedGraph, _In_ OrtSession* session, _In_ int graph_annotation_id);
7495+
7496+ /* * \brief Get the model package API table.
7497+ *
7498+ * Returns a pointer to the ::OrtModelPackageApi function table, which provides APIs to:
7499+ * - create and release model package options and contexts,
7500+ * - inspect model package metadata (components/variants),
7501+ * - select a component/variant and query selected files/options,
7502+ * - create a session from model package selection results.
7503+ *
7504+ * The returned pointer is owned by ONNX Runtime and is valid for the process lifetime.
7505+ * Do not free it.
7506+ *
7507+ * \note May return NULL if model package support is not available in the current build
7508+ * (for example, minimal builds).
7509+ *
7510+ * \return Pointer to ::OrtModelPackageApi, or NULL if unsupported.
7511+ *
7512+ * \since Version 1.27.
7513+ */
7514+ const OrtModelPackageApi*(ORT_API_CALL * GetModelPackageApi)(void );
74897515};
74907516
74917517/*
@@ -8573,6 +8599,250 @@ struct OrtInteropApi {
85738599 // / @}
85748600};
85758601
8602+ /* * \brief API table for model package workflows.
8603+ *
8604+ * A model package is a directory containing one or more *components* (logical models).
8605+ * Each component has one or more *variants*, where each variant targets a single
8606+ * execution provider (EP). The package manifest declares the EP name, device type,
8607+ * and an optional compatibility string for every variant so that the runtime can
8608+ * automatically select the best variant for the hardware and EPs available in the
8609+ * caller's session options.
8610+ *
8611+ * Obtain this table from OrtApi::GetModelPackageApi(). The APIs support:
8612+ * - creating model package options that capture EP configuration from OrtSessionOptions,
8613+ * - loading a package context (manifest + metadata) from a package root path,
8614+ * - querying component/variant metadata including per-variant EP information,
8615+ * - selecting a component (which also resolves the best-matching variant),
8616+ * - querying the selected variant's name and folder path,
8617+ * - creating an OrtSession from the selected component context.
8618+ *
8619+ * Typical flow:
8620+ * 1) Create model package options:
8621+ * - CreateModelPackageOptionsFromSessionOptions()
8622+ * 2) Load package metadata:
8623+ * - CreateModelPackageContext()
8624+ * 3) Query metadata (optional):
8625+ * - ModelPackage_GetSchemaVersion()
8626+ * - ModelPackage_GetComponentCount()
8627+ * - ModelPackage_GetComponentNames()
8628+ * - ModelPackage_GetVariantCount()
8629+ * - ModelPackage_GetVariantNames()
8630+ * - ModelPackage_GetVariantEpName()
8631+ * 4) Select a component and resolve variant:
8632+ * - SelectComponent()
8633+ * 5) Query selected variant info (optional):
8634+ * - ModelPackageComponent_GetSelectedVariantName()
8635+ * - ModelPackageComponent_GetSelectedVariantFolderPath()
8636+ * 6) Create session:
8637+ * - CreateSession()
8638+ *
8639+ * Ownership:
8640+ * - Release objects created by this API with the corresponding release methods:
8641+ * ReleaseModelPackageOptions(), ReleaseModelPackageContext(),
8642+ * ReleaseModelPackageComponentContext().
8643+ *
8644+ * \since Version 1.27.
8645+ */
8646+ struct OrtModelPackageApi {
8647+ // / \name OrtModelPackageOptions
8648+ // / @{
8649+
8650+ /* * \brief Create model package options from an existing OrtSessionOptions.
8651+ *
8652+ * Captures EP configuration (registered execution providers and their devices) from
8653+ * the session options for use during variant selection. The resulting OrtModelPackageOptions
8654+ * is passed to SelectComponent() to resolve the best variant for the available EPs.
8655+ *
8656+ * \param[in] env The ORT environment.
8657+ * \param[in] session_options Session options containing registered EPs.
8658+ * \param[out] out Receives the newly created OrtModelPackageOptions. Must be released
8659+ * with ReleaseModelPackageOptions().
8660+ *
8661+ * \since Version 1.27.
8662+ */
8663+ ORT_API2_STATUS (CreateModelPackageOptionsFromSessionOptions,
8664+ _In_ const OrtEnv* env,
8665+ _In_ const OrtSessionOptions* session_options,
8666+ _Outptr_ OrtModelPackageOptions** out);
8667+
8668+ ORT_CLASS_RELEASE (ModelPackageOptions);
8669+ // / @}
8670+ // / \name OrtModelPackageContext
8671+ // / @{
8672+
8673+ /* * \brief Create a model package context by parsing the package at the given root path.
8674+ *
8675+ * Parses the manifest.json and component metadata from the specified directory.
8676+ * The returned context provides read-only access to the package structure (components,
8677+ * variants, EP declarations).
8678+ *
8679+ * \param[in] package_root Path to the model package root directory (containing manifest.json).
8680+ * \param[out] out Receives the newly created OrtModelPackageContext. Must be released
8681+ * with ReleaseModelPackageContext().
8682+ *
8683+ * \since Version 1.27.
8684+ */
8685+ ORT_API2_STATUS (CreateModelPackageContext,
8686+ _In_ const ORTCHAR_T * package_root,
8687+ _Outptr_ OrtModelPackageContext** out);
8688+
8689+ ORT_CLASS_RELEASE (ModelPackageContext);
8690+
8691+ /* * \brief Get the schema version declared in the model package manifest.
8692+ *
8693+ * \param[in] ctx The model package context.
8694+ * \param[out] out_version Receives the schema version number.
8695+ *
8696+ * \since Version 1.27.
8697+ */
8698+ ORT_API2_STATUS (ModelPackage_GetSchemaVersion,
8699+ _In_ const OrtModelPackageContext* ctx,
8700+ _Out_ int64_t * out_version);
8701+
8702+ /* * \brief Get the number of components in the model package.
8703+ *
8704+ * \param[in] ctx The model package context.
8705+ * \param[out] out_count Receives the component count.
8706+ *
8707+ * \since Version 1.27.
8708+ */
8709+ ORT_API2_STATUS (ModelPackage_GetComponentCount,
8710+ _In_ const OrtModelPackageContext* ctx,
8711+ _Out_ size_t * out_count);
8712+
8713+ /* * \brief Get the names of all components in the model package.
8714+ *
8715+ * Returns a pointer to an array of UTF-8 component name strings. The array and its
8716+ * strings are owned by `ctx` and remain valid until the context is released.
8717+ *
8718+ * \param[in] ctx The model package context.
8719+ * \param[out] out_names Receives a pointer to an array of component name strings.
8720+ * \param[out] out_count Receives the number of elements in the array.
8721+ *
8722+ * \since Version 1.27.
8723+ */
8724+ ORT_API2_STATUS (ModelPackage_GetComponentNames,
8725+ _In_ const OrtModelPackageContext* ctx,
8726+ _Outptr_result_buffer_maybenull_ (*out_count) const char* const ** out_names,
8727+ _Out_ size_t* out_count);
8728+
8729+ /* * \brief Get the number of variants for a given component.
8730+ *
8731+ * \param[in] ctx The model package context.
8732+ * \param[in] component_name Name of the component to query.
8733+ * \param[out] out_count Receives the variant count.
8734+ *
8735+ * \since Version 1.27.
8736+ */
8737+ ORT_API2_STATUS (ModelPackage_GetVariantCount,
8738+ _In_ const OrtModelPackageContext* ctx,
8739+ _In_ const char * component_name,
8740+ _Out_ size_t * out_count);
8741+
8742+ /* * \brief Get the names of all variants for a given component.
8743+ *
8744+ * Returns a pointer to an array of UTF-8 variant name strings. The array and its
8745+ * strings are owned by `ctx` and remain valid until the context is released.
8746+ *
8747+ * \param[in] ctx The model package context.
8748+ * \param[in] component_name Name of the component to query.
8749+ * \param[out] out_variant_names Receives a pointer to an array of variant name strings.
8750+ * \param[out] out_count Receives the number of elements in the array.
8751+ *
8752+ * \since Version 1.27.
8753+ */
8754+ ORT_API2_STATUS (ModelPackage_GetVariantNames,
8755+ _In_ const OrtModelPackageContext* ctx,
8756+ _In_ const char * component_name,
8757+ _Outptr_result_buffer_maybenull_ (*out_count) const char* const ** out_variant_names,
8758+ _Out_ size_t* out_count);
8759+
8760+ /* * \brief Get the EP name declared for a (component, variant) pair.
8761+ *
8762+ * Each variant targets a single EP. `out_ep` receives the EP name string.
8763+ * When the variant does not declare an EP, the returned pointer is NULL.
8764+ * String memory is owned by `ctx` and remains valid until the context is released.
8765+ *
8766+ * \since Version 1.27.
8767+ */
8768+ ORT_API2_STATUS (ModelPackage_GetVariantEpName,
8769+ _In_ const OrtModelPackageContext* ctx,
8770+ _In_ const char * component_name,
8771+ _In_ const char * variant_name,
8772+ _Outptr_result_maybenull_ const char ** out_ep);
8773+
8774+ /* * \brief Select a component model and return an opaque component instance.
8775+ *
8776+ * The variant selection is also performed during this call based on the component metadata and the provided options.
8777+ * The returned `OrtModelPackgeComponentContext*` is independent of `context` lifetime and must be released via
8778+ * `ReleaseComponentInstance`.
8779+ *
8780+ * \since Version 1.27.
8781+ */
8782+ ORT_API2_STATUS (SelectComponent,
8783+ _In_ const OrtModelPackageContext* context,
8784+ _In_ const char * component_name,
8785+ _In_ const OrtModelPackageOptions* options,
8786+ _Outptr_ OrtModelPackageComponentContext** out);
8787+
8788+ ORT_CLASS_RELEASE (ModelPackageComponentContext);
8789+
8790+ /* * \brief Get the name of the selected variant after SelectComponent has been called.
8791+ *
8792+ * String memory is owned by `ctx` and remains valid until the context is released.
8793+ *
8794+ * \param[in] ctx The component context returned by SelectComponent().
8795+ * \param[out] out_name Receives the selected variant's name string.
8796+ *
8797+ * \since Version 1.27.
8798+ */
8799+ ORT_API2_STATUS (ModelPackageComponent_GetSelectedVariantName,
8800+ _In_ const OrtModelPackageComponentContext* ctx,
8801+ _Outptr_ const char ** out_name);
8802+
8803+ /* * \brief Get the folder path of the selected variant.
8804+ *
8805+ * Returns the resolved absolute path to the variant's directory on disk.
8806+ * The string is owned by `ctx` and remains valid until the context is released.
8807+ *
8808+ * \param[in] ctx The component context returned by SelectComponent().
8809+ * \param[out] folder_path Receives the variant folder path string.
8810+ *
8811+ * \since Version 1.27.
8812+ */
8813+ ORT_API2_STATUS (ModelPackageComponent_GetSelectedVariantFolderPath,
8814+ _In_ const OrtModelPackageComponentContext* ctx,
8815+ _Outptr_ const ORTCHAR_T ** folder_path);
8816+
8817+ // / @}
8818+ /* * \brief Create an OrtSession for a selected file within a component model variant.
8819+ *
8820+ * The chosen variant (and thus its EP selection) is determined by `context`, which
8821+ * was built from an OrtSessionOptions via CreateModelPackageOptionsFromSessionOptions.
8822+ *
8823+ * Session options precedence:
8824+ * 1. session_options == NULL (default path):
8825+ * ORT uses the OrtSessionOptions that was captured when `context` was created.
8826+ * Any variant-specific session and provider options declared in the package
8827+ * metadata are merged on top.
8828+ *
8829+ * 2. session_options != NULL (advanced path):
8830+ * ORT uses the caller-provided OrtSessionOptions as-is. Variant-specific
8831+ * session and provider options from the package metadata are NOT applied.
8832+ * Use this when custom EP setup is required (e.g., shared CUDA streams,
8833+ * shared QNN EP contexts, custom allocators).
8834+ *
8835+ * \since Version 1.27.
8836+ */
8837+ ORT_API2_STATUS (CreateSession,
8838+ _In_ const OrtEnv* env,
8839+ _In_ OrtModelPackageComponentContext* context,
8840+ _In_opt_ const OrtSessionOptions* session_options,
8841+ _Outptr_ OrtSession** session);
8842+
8843+ // End of Version 1.27 - DO NOT MODIFY ABOVE
8844+ };
8845+
85768846/*
85778847 * This is the old way to add the CUDA provider to the session, please use SessionOptionsAppendExecutionProvider_CUDA above to access the latest functionality
85788848 * This function always exists, but will only succeed if Onnxruntime was built with CUDA support and the CUDA provider shared library exists
0 commit comments