// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. // Experimental C++ API consumer header. // // This header provides typed inline accessors in the Ort::Experimental namespace for experimental ORT API functions, // and any C++ wrapper types associated with the experimental API functions. // // It is the C++ companion to onnxruntime_experimental_c_api.h. // // IMPORTANT: Experimental functions are NOT part of the stable ABI. They may be added, changed, or removed between // releases without notice. Anything in this file should be treated as experimental and unstable. // // Two accessor flavors are generated for each experimental function: // // 1. Get__SinceV_Fn(api) // Returns the typed function pointer, or nullptr if the function is not available in this build. // Use this to check availability at runtime. // // 2. Get__SinceV_FnOrThrow(api) // Returns the typed function pointer, or throws Ort::Exception (ORT_NOT_IMPLEMENTED) if the function is not // available in this build. // Use this when the function is required. // // C++ usage (nullable): // if (auto* fn = Ort::Experimental::Get_OrtApi_ExperimentalApiTest_SinceV28_Fn(api)) { // Ort::Status status(fn(&result)); // } // // C++ usage (throwing): // auto* fn = Ort::Experimental::Get_OrtApi_ExperimentalApiTest_SinceV28_FnOrThrow(api); // Ort::Status status(fn(&result)); #pragma once #include "onnxruntime_experimental_c_api.h" #include "onnxruntime_cxx_api.h" namespace Ort { namespace Experimental { // // Nullable typed accessors // // For each .inc entry, this generates a typed accessor in Ort::Experimental: // // inline OrtExperimental__SinceV_Fn Get__SinceV_Fn(const OrtApi* api); // // Example: ORT_EXPERIMENTAL_API(28, OrtStatusPtr, OrtApi_ExperimentalApiTest, ...) produces: // inline OrtExperimental_OrtApi_ExperimentalApiTest_SinceV28_Fn // Get_OrtApi_ExperimentalApiTest_SinceV28_Fn(const OrtApi* api) { // return reinterpret_cast( // api->GetExperimentalFunction(kOrtExperimental_OrtApi_ExperimentalApiTest_SinceV28_FnName)); // } #define ORT_EXPERIMENTAL_API(VER, RET, NAME, ...) \ inline OrtExperimental_##NAME##_SinceV##VER##_Fn Get_##NAME##_SinceV##VER##_Fn( \ const OrtApi* api) { \ return reinterpret_cast( \ api->GetExperimentalFunction(kOrtExperimental_##NAME##_SinceV##VER##_FnName)); \ } #include "onnxruntime_experimental_c_api.inc" #undef ORT_EXPERIMENTAL_API // // Throwing typed accessors // // For each .inc entry, this generates a throwing accessor in Ort::Experimental: // // inline OrtExperimental__SinceV_Fn Get__SinceV_FnOrThrow(const OrtApi* api); // // It returns the non-null typed function pointer, or throws Ort::Exception (ORT_NOT_IMPLEMENTED) if the function is // not available in this build. // // Example: ORT_EXPERIMENTAL_API(28, OrtStatusPtr, OrtApi_ExperimentalApiTest, ...) produces: // inline OrtExperimental_OrtApi_ExperimentalApiTest_SinceV28_Fn // Get_OrtApi_ExperimentalApiTest_SinceV28_FnOrThrow(const OrtApi* api) { // auto* fn = Get_OrtApi_ExperimentalApiTest_SinceV28_Fn(api); // if (fn == nullptr) { // ORT_CXX_API_THROW( // "Experimental function OrtApi_ExperimentalApiTest_SinceV28 is not available in this build", // ORT_NOT_IMPLEMENTED); // } // return fn; // } #define ORT_EXPERIMENTAL_API(VER, RET, NAME, ...) \ inline OrtExperimental_##NAME##_SinceV##VER##_Fn Get_##NAME##_SinceV##VER##_FnOrThrow( \ const OrtApi* api) { \ auto* fn = Get_##NAME##_SinceV##VER##_Fn(api); \ if (fn == nullptr) { \ ORT_CXX_API_THROW( \ "Experimental function " #NAME "_SinceV" #VER " is not available in this build", \ ORT_NOT_IMPLEMENTED); \ } \ return fn; \ } #include "onnxruntime_experimental_c_api.inc" #undef ORT_EXPERIMENTAL_API } // namespace Experimental } // namespace Ort