diff --git a/cmake/onnxruntime_config.h.in b/cmake/onnxruntime_config.h.in
index 9fc46018dad1..4f5125569cd7 100644
--- a/cmake/onnxruntime_config.h.in
+++ b/cmake/onnxruntime_config.h.in
@@ -21,5 +21,5 @@
#cmakedefine HAS_FORMAT_TRUNCATION
#cmakedefine HAS_BITWISE_INSTEAD_OF_LOGICAL
#cmakedefine HAS_REALLOCARRAY
-#cmakedefine ORT_VERSION "@ORT_VERSION@"
-#cmakedefine ORT_BUILD_INFO "@ORT_BUILD_INFO@"
+#cmakedefine ORT_VERSION u8"@ORT_VERSION@"
+#cmakedefine ORT_BUILD_INFO u8"@ORT_BUILD_INFO@"
diff --git a/csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.shared.cs b/csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.shared.cs
index 14e93dc05f74..5fcddf7d0cea 100644
--- a/csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.shared.cs
+++ b/csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.shared.cs
@@ -286,6 +286,7 @@ public struct OrtApi
public IntPtr CastTypeInfoToOptionalTypeInfo;
public IntPtr GetOptionalContainedTypeInfo;
public IntPtr GetResizedStringTensorElementBuffer;
+ public IntPtr KernelContext_GetAllocator;
}
internal static class NativeMethods
@@ -1654,7 +1655,6 @@ internal class NativeLib
public static DOrtModelMetadataLookupCustomMetadataMap OrtModelMetadataLookupCustomMetadataMap;
-
///
/// Frees ModelMetadata instance
///
diff --git a/csharp/src/Microsoft.ML.OnnxRuntime/OrtEnv.shared.cs b/csharp/src/Microsoft.ML.OnnxRuntime/OrtEnv.shared.cs
index 2df16ccae032..1a03338298fa 100644
--- a/csharp/src/Microsoft.ML.OnnxRuntime/OrtEnv.shared.cs
+++ b/csharp/src/Microsoft.ML.OnnxRuntime/OrtEnv.shared.cs
@@ -276,7 +276,7 @@ public static OrtEnv Instance()
///
///
/// if the singleton has already been created
- public static OrtEnv CreateInstanceWithOptions(EnvironmentCreationOptions options)
+ public static OrtEnv CreateInstanceWithOptions(ref EnvironmentCreationOptions options)
{
// Non-thread safe, best effort hopefully helpful check.
// Environment is usually created once per process, so this should be fine.
diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/OrtEnvTests.cs b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/OrtEnvTests.cs
index 83d32fa54ba6..229d683c162f 100644
--- a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/OrtEnvTests.cs
+++ b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/OrtEnvTests.cs
@@ -80,7 +80,7 @@ public void TestUpdatingEnvWithCustomLogLevel()
logLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_FATAL
};
- ortEnvInstance = OrtEnv.CreateInstanceWithOptions(envOptions);
+ ortEnvInstance = OrtEnv.CreateInstanceWithOptions(ref envOptions);
Assert.True(OrtEnv.IsCreated);
Assert.Equal(OrtLoggingLevel.ORT_LOGGING_LEVEL_FATAL, ortEnvInstance.EnvLogLevel);
@@ -92,7 +92,7 @@ public void TestUpdatingEnvWithCustomLogLevel()
logId = "CSharpOnnxRuntimeTestLogid"
};
- ortEnvInstance = OrtEnv.CreateInstanceWithOptions(envOptions);
+ ortEnvInstance = OrtEnv.CreateInstanceWithOptions(ref envOptions);
Assert.Equal(OrtLoggingLevel.ORT_LOGGING_LEVEL_WARNING, ortEnvInstance.EnvLogLevel);
// Change and see if this takes effect
@@ -118,7 +118,7 @@ public void TestUpdatingEnvWithThreadingOptions()
};
// Make sure we start anew
- var env = OrtEnv.CreateInstanceWithOptions(envOptions);
+ var env = OrtEnv.CreateInstanceWithOptions(ref envOptions);
Assert.True(OrtEnv.IsCreated);
}
}
@@ -164,7 +164,7 @@ public void TesEnvWithCustomLogger()
LoggingInvokes = 0;
- var env = OrtEnv.CreateInstanceWithOptions(envOptions);
+ var env = OrtEnv.CreateInstanceWithOptions(ref envOptions);
Assert.True(OrtEnv.IsCreated);
var model = TestDataLoader.LoadModelFromEmbeddedResource("squeezenet.onnx");
@@ -199,7 +199,7 @@ public void TestEnvWithCustomLoggerAndThredingOptions()
LoggingInvokes = 0;
- var env = OrtEnv.CreateInstanceWithOptions(envOptions);
+ var env = OrtEnv.CreateInstanceWithOptions(ref envOptions);
Assert.True(OrtEnv.IsCreated);
var model = TestDataLoader.LoadModelFromEmbeddedResource("squeezenet.onnx");
diff --git a/include/onnxruntime/core/session/onnxruntime_c_api.h b/include/onnxruntime/core/session/onnxruntime_c_api.h
index 203a975b2b8b..f02fafcf6199 100644
--- a/include/onnxruntime/core/session/onnxruntime_c_api.h
+++ b/include/onnxruntime/core/session/onnxruntime_c_api.h
@@ -95,6 +95,8 @@ extern "C" {
#define ORTCHAR_T char
#endif
+/// ORTCHAR_T, ORT_TSTR are reserved specifically for path handling.
+/// All other strings are UTF-8 encoded, use char and std::string
#ifndef ORT_TSTR
#ifdef _WIN32
#define ORT_TSTR(X) L##X
@@ -627,11 +629,19 @@ struct OrtApiBase {
* \param[in] version Must be ::ORT_API_VERSION
* \return The ::OrtApi for the version requested, nullptr will be returned if this version is unsupported, for example when using a runtime
* older than the version created with this header file.
+ *
+ * One can call GetVersionString() to get the version of the Onnxruntime library for logging
+ * and error reporting purposes.
*/
const OrtApi*(ORT_API_CALL* GetApi)(uint32_t version)NO_EXCEPTION;
- const ORTCHAR_T*(ORT_API_CALL* GetVersionString)(void)NO_EXCEPTION; ///< Returns a null terminated string of the version of the Onnxruntime library (eg: "1.8.1")
- const ORTCHAR_T*(ORT_API_CALL* GetBuildInfoString)(void)NO_EXCEPTION; ///< Returns a null terminated string of the build info including git info and cxx flags
+
+ /** \brief Returns a null terminated string of the version of the Onnxruntime library (eg: "1.8.1")
+ *
+ * \return UTF-8 encoded version string. Do not deallocate the returned buffer.
+ */
+ const char*(ORT_API_CALL* GetVersionString)(void)NO_EXCEPTION;
};
+
typedef struct OrtApiBase OrtApiBase;
/** \brief The Onnxruntime library's entry point to access the C API
@@ -4193,6 +4203,14 @@ struct OrtApi {
* \since Version 1.15.
*/
ORT_API2_STATUS(KernelContext_GetAllocator, _In_ const OrtKernelContext* context, _In_ const OrtMemoryInfo* mem_info, _Outptr_ OrtAllocator** out);
+
+ /** \brief Returns a null terminated string of the build info including git info and cxx flags
+ *
+ * \return UTF-8 encoded version string. Do not deallocate the returned buffer.
+ *
+ * \since Version 1.15.
+ */
+ const char*(ORT_API_CALL* GetBuildInfoString)(void);
};
/*
diff --git a/include/onnxruntime/core/session/onnxruntime_cxx_api.h b/include/onnxruntime/core/session/onnxruntime_cxx_api.h
index df007b7af4cc..2d5e1a9bddee 100644
--- a/include/onnxruntime/core/session/onnxruntime_cxx_api.h
+++ b/include/onnxruntime/core/session/onnxruntime_cxx_api.h
@@ -125,14 +125,14 @@ inline const OrtApi& GetApi() noexcept { return *Global::api_; }
/// This function returns the onnxruntime version string
///
/// version string major.minor.rev
-std::basic_string GetVersionString();
+std::string GetVersionString();
///
/// This function returns the onnxruntime build information: including git branch,
/// git commit id, build type(Debug/Release/RelWithDebInfo) and cmake cpp flags.
///
/// string
-std::basic_string GetBuildInfoString();
+std::string GetBuildInfoString();
///
/// This is a C++ wrapper for OrtApi::GetAvailableProviders() and
diff --git a/include/onnxruntime/core/session/onnxruntime_cxx_inline.h b/include/onnxruntime/core/session/onnxruntime_cxx_inline.h
index 3e7cf721cddd..b72bcd35fafb 100644
--- a/include/onnxruntime/core/session/onnxruntime_cxx_inline.h
+++ b/include/onnxruntime/core/session/onnxruntime_cxx_inline.h
@@ -1987,14 +1987,12 @@ inline void CustomOpApi::ReleaseKernelInfo(_Frees_ptr_opt_ OrtKernelInfo* info_c
api_.ReleaseKernelInfo(info_copy);
}
-inline std::basic_string GetVersionString() {
- std::basic_string result = OrtGetApiBase()->GetVersionString();
- return result;
+inline std::string GetVersionString() {
+ return OrtGetApiBase()->GetVersionString();
}
-inline std::basic_string GetBuildInfoString() {
- std::basic_string result = OrtGetApiBase()->GetBuildInfoString();
- return result;
+inline std::string GetBuildInfoString() {
+ return GetApi().GetBuildInfoString();
}
inline std::vector GetAvailableProviders() {
diff --git a/java/src/main/native/ai_onnxruntime_OnnxRuntime.c b/java/src/main/native/ai_onnxruntime_OnnxRuntime.c
index 5165f3499e2d..659f34e1fb66 100644
--- a/java/src/main/native/ai_onnxruntime_OnnxRuntime.c
+++ b/java/src/main/native/ai_onnxruntime_OnnxRuntime.c
@@ -76,13 +76,7 @@ JNIEXPORT jobjectArray JNICALL Java_ai_onnxruntime_OnnxRuntime_getAvailableProvi
JNIEXPORT jstring JNICALL Java_ai_onnxruntime_OnnxRuntime_initialiseVersion
(JNIEnv * jniEnv, jclass clazz) {
(void)clazz; // required JNI parameter not needed by functions which don't access their host class.
- const ORTCHAR_T* version = OrtGetApiBase()->GetVersionString();
+ const char* version = ORT_VERSION;
assert(version != NULL);
-#ifdef _WIN32
- jsize len = (jsize)(wcslen(version));
- jstring versionStr = (*jniEnv)->NewString(jniEnv, (const jchar*)version, len);
-#else
- jstring versionStr = (*jniEnv)->NewStringUTF(jniEnv, version);
-#endif
- return versionStr;
+ return (*jniEnv)->NewStringUTF(jniEnv, version);
}
diff --git a/onnxruntime/core/session/onnxruntime_c_api.cc b/onnxruntime/core/session/onnxruntime_c_api.cc
index a3fcaceffcee..f2a241db2737 100644
--- a/onnxruntime/core/session/onnxruntime_c_api.cc
+++ b/onnxruntime/core/session/onnxruntime_c_api.cc
@@ -2380,9 +2380,7 @@ ORT_API(const OrtTrainingApi*, OrtApis::GetTrainingApi, uint32_t version) {
static constexpr OrtApiBase ort_api_base = {
&OrtApis::GetApi,
- &OrtApis::GetVersionString,
- &OrtApis::GetBuildInfoString,
-};
+ &OrtApis::GetVersionString};
/* Rules on how to add a new Ort API version
@@ -2726,7 +2724,8 @@ static constexpr OrtApi ort_api_1_to_16 = {
&OrtApis::CastTypeInfoToOptionalTypeInfo,
&OrtApis::GetOptionalContainedTypeInfo,
&OrtApis::GetResizedStringTensorElementBuffer,
- &OrtApis::KernelContext_GetAllocator};
+ &OrtApis::KernelContext_GetAllocator,
+ &OrtApis::GetBuildInfoString};
// End of Version 15 - DO NOT MODIFY ABOVE (see above text for more information)
// Asserts to do a some checks to ensure older Versions of the OrtApi never change (will detect an addition or deletion but not if they cancel out each other)
@@ -2747,7 +2746,7 @@ static_assert(offsetof(OrtApi, SessionOptionsAppendExecutionProvider_MIGraphX) /
static_assert(offsetof(OrtApi, ReleaseKernelInfo) / sizeof(void*) == 218, "Size of version 12 API cannot change");
static_assert(offsetof(OrtApi, ReleaseCANNProviderOptions) / sizeof(void*) == 224, "Size of version 13 API cannot change");
static_assert(offsetof(OrtApi, GetSessionConfigEntry) / sizeof(void*) == 238, "Size of version 14 API cannot change");
-static_assert(offsetof(OrtApi, KernelContext_GetAllocator) / sizeof(void*) == 253, "Size of version 15 API cannot change");
+static_assert(offsetof(OrtApi, GetBuildInfoString) / sizeof(void*) == 254, "Size of version 15 API cannot change");
// So that nobody forgets to finish an API version, this check will serve as a reminder:
static_assert(std::string_view(ORT_VERSION) == "1.16.0",
@@ -2761,18 +2760,20 @@ ORT_API(const OrtApi*, OrtApis::GetApi, uint32_t version) {
if (version >= 1 && version <= ORT_API_VERSION)
return &ort_api_1_to_16;
- fprintf(stderr, "The given version [%u] is not supported, only version 1 to %u is supported in this build.\n",
- version, ORT_API_VERSION);
+ fprintf(stderr,
+ "The requested API version [%u] is not available, only API versions [1, %u] are supported in this build."
+ " Current ORT Version is: %s\n",
+ version, ORT_API_VERSION, ORT_VERSION);
return nullptr; // Unsupported version
}
-ORT_API(const ORTCHAR_T*, OrtApis::GetVersionString) {
- return ORT_TSTR_ON_MACRO(ORT_VERSION);
+ORT_API(const char*, OrtApis::GetVersionString) {
+ return ORT_VERSION;
}
-ORT_API(const ORTCHAR_T*, OrtApis::GetBuildInfoString) {
- return ORT_TSTR_ON_MACRO(ORT_BUILD_INFO);
+ORT_API(const char*, OrtApis::GetBuildInfoString) {
+ return ORT_BUILD_INFO;
}
const OrtApiBase* ORT_API_CALL OrtGetApiBase(void) NO_EXCEPTION {
diff --git a/onnxruntime/core/session/ort_apis.h b/onnxruntime/core/session/ort_apis.h
index 2354b8297388..8b8ffd38d697 100644
--- a/onnxruntime/core/session/ort_apis.h
+++ b/onnxruntime/core/session/ort_apis.h
@@ -4,8 +4,8 @@
namespace OrtApis {
ORT_API(const OrtApi*, GetApi, uint32_t version);
-ORT_API(const ORTCHAR_T*, GetVersionString);
-ORT_API(const ORTCHAR_T*, GetBuildInfoString);
+
+ORT_API(const char*, GetVersionString);
ORT_API(void, ReleaseEnv, OrtEnv*);
ORT_API(void, ReleaseStatus, _Frees_ptr_opt_ OrtStatus*);
@@ -465,4 +465,6 @@ ORT_API_STATUS_IMPL(GetResizedStringTensorElementBuffer, _Inout_ OrtValue* value
_In_ size_t index, _In_ size_t length_in_bytes, _Inout_ char**);
ORT_API_STATUS_IMPL(KernelContext_GetAllocator, _In_ const OrtKernelContext* context, _In_ const OrtMemoryInfo* mem_info, _Outptr_ OrtAllocator** out);
+
+ORT_API(const char*, GetBuildInfoString);
} // namespace OrtApis
diff --git a/onnxruntime/test/onnx/main.cc b/onnxruntime/test/onnx/main.cc
index 63df472816c1..54b7587ce2b2 100644
--- a/onnxruntime/test/onnx/main.cc
+++ b/onnxruntime/test/onnx/main.cc
@@ -29,7 +29,7 @@ using namespace onnxruntime;
namespace {
void usage() {
- auto version_string = ToUTF8String(OrtGetApiBase()->GetVersionString());
+ auto version_string = Ort::GetVersionString();
printf(
"onnx_test_runner [options...] \n"
"Options:\n"
diff --git a/onnxruntime/test/shared_lib/test_inference.cc b/onnxruntime/test/shared_lib/test_inference.cc
index ffc6f7c961ce..f53a93225b52 100644
--- a/onnxruntime/test/shared_lib/test_inference.cc
+++ b/onnxruntime/test/shared_lib/test_inference.cc
@@ -2209,9 +2209,15 @@ TEST(CApiTest, get_available_providers_cpp) {
}
TEST(CApiTest, get_version_string_cpp) {
- std::basic_string version_string = Ort::GetVersionString();
+ auto version_string = Ort::GetVersionString();
ASSERT_FALSE(version_string.empty());
- ASSERT_EQ(version_string, std::basic_string(ORT_TSTR_ON_MACRO(ORT_VERSION)));
+ ASSERT_EQ(version_string, std::string(ORT_VERSION));
+}
+
+TEST(CApiTest, get_build_info_string) {
+ auto build_info_string = Ort::GetBuildInfoString();
+ ASSERT_FALSE(build_info_string.empty());
+ ASSERT_EQ(build_info_string, std::string(ORT_BUILD_INFO));
}
TEST(CApiTest, TestSharedAllocators) {