-
Notifications
You must be signed in to change notification settings - Fork 4k
Experimental C++ API update #29142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Experimental C++ API update #29142
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| // 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_<NAME>_SinceV<VER>_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_<NAME>_SinceV<VER>_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" | ||
|
Check warning on line 36 in include/onnxruntime/core/session/onnxruntime_experimental_cxx_api.h
|
||
| #include "onnxruntime_cxx_api.h" | ||
|
Check warning on line 37 in include/onnxruntime/core/session/onnxruntime_experimental_cxx_api.h
|
||
|
|
||
| namespace Ort { | ||
| namespace Experimental { | ||
|
|
||
| // | ||
| // Nullable typed accessors | ||
| // | ||
|
|
||
| // For each .inc entry, this generates a typed accessor in Ort::Experimental: | ||
| // | ||
| // inline OrtExperimental_<NAME>_SinceV<VER>_Fn Get_<NAME>_SinceV<VER>_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<OrtExperimental_OrtApi_ExperimentalApiTest_SinceV28_Fn>( | ||
| // 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<OrtExperimental_##NAME##_SinceV##VER##_Fn>( \ | ||
| 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_<NAME>_SinceV<VER>_Fn Get_<NAME>_SinceV<VER>_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" | ||
|
Check warning on line 101 in include/onnxruntime/core/session/onnxruntime_experimental_cxx_api.h
|
||
|
|
||
| #undef ORT_EXPERIMENTAL_API | ||
|
|
||
| // | ||
| // Auxiliary types and helpers | ||
| // | ||
| // C++ wrapper types or helpers go here in the `Ort::Experimental` namespace. | ||
| // | ||
|
|
||
| } // namespace Experimental | ||
| } // namespace Ort | ||
Uh oh!
There was an error while loading. Please reload this page.