From 2e242a40898e0b2b4ccaf63a21a9f71ffd06954a Mon Sep 17 00:00:00 2001 From: Scott McKay Date: Tue, 10 Sep 2019 08:32:33 +1000 Subject: [PATCH] Clarify naming of the API involving the RunOptions terminate flag. (#1768) * Clarify naming of the RunOptions terminate flag. * Update C# code to use new names. --- csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.cs | 4 ++-- csharp/src/Microsoft.ML.OnnxRuntime/RunOptions.cs | 6 +++--- include/onnxruntime/core/session/onnxruntime_c_api.h | 9 +++++---- include/onnxruntime/core/session/onnxruntime_cxx_api.h | 6 ++++-- .../onnxruntime/core/session/onnxruntime_cxx_inline.h | 8 ++++---- onnxruntime/core/framework/run_options.cc | 4 ++-- onnxruntime/core/providers/cpu/symbols.txt | 4 ++-- 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.cs b/csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.cs index c6b6c325bb..1cb366d716 100644 --- a/csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.cs +++ b/csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.cs @@ -237,10 +237,10 @@ namespace Microsoft.ML.OnnxRuntime // Set a flag so that any running OrtRun* calls that are using this instance of OrtRunOptions // will exit as soon as possible if the flag is true. [DllImport(nativeLib, CharSet = charSet)] - public static extern IntPtr /*(OrtStatus*)*/ OrtRunOptionsEnableTerminate(IntPtr /* OrtRunOptions* */ options); + public static extern IntPtr /*(OrtStatus*)*/ OrtRunOptionsSetTerminate(IntPtr /* OrtRunOptions* */ options); [DllImport(nativeLib, CharSet = charSet)] - public static extern IntPtr /*(OrtStatus*)*/ OrtRunOptionsDisableTerminate(IntPtr /* OrtRunOptions* */ options); + public static extern IntPtr /*(OrtStatus*)*/ OrtRunOptionsUnsetTerminate(IntPtr /* OrtRunOptions* */ options); diff --git a/csharp/src/Microsoft.ML.OnnxRuntime/RunOptions.cs b/csharp/src/Microsoft.ML.OnnxRuntime/RunOptions.cs index 849863cacc..ad95bcae9b 100644 --- a/csharp/src/Microsoft.ML.OnnxRuntime/RunOptions.cs +++ b/csharp/src/Microsoft.ML.OnnxRuntime/RunOptions.cs @@ -65,7 +65,7 @@ namespace Microsoft.ML.OnnxRuntime /// - /// Sets a flag to terminate any other Run() call that is using the same RunOptions object + /// Sets a flag to terminate all Run() calls that are currently using this RunOptions object /// Default = false /// public bool Terminate @@ -78,12 +78,12 @@ namespace Microsoft.ML.OnnxRuntime { if (!_terminate && value) { - NativeApiStatus.VerifySuccess(NativeMethods.OrtRunOptionsEnableTerminate(_nativePtr)); + NativeApiStatus.VerifySuccess(NativeMethods.OrtRunOptionsSetTerminate(_nativePtr)); _terminate = true; } else if (_terminate && !value) { - NativeApiStatus.VerifySuccess(NativeMethods.OrtRunOptionsDisableTerminate(_nativePtr)); + NativeApiStatus.VerifySuccess(NativeMethods.OrtRunOptionsUnsetTerminate(_nativePtr)); _terminate = false; } } diff --git a/include/onnxruntime/core/session/onnxruntime_c_api.h b/include/onnxruntime/core/session/onnxruntime_c_api.h index 47414b470d..dd2dc98be5 100644 --- a/include/onnxruntime/core/session/onnxruntime_c_api.h +++ b/include/onnxruntime/core/session/onnxruntime_c_api.h @@ -300,10 +300,11 @@ ORT_API_STATUS(OrtRunOptionsGetRunLogVerbosityLevel, _In_ const OrtRunOptions* o ORT_API_STATUS(OrtRunOptionsGetRunLogSeverityLevel, _In_ const OrtRunOptions* options, _Out_ int* out); ORT_API_STATUS(OrtRunOptionsGetRunTag, _In_ const OrtRunOptions*, _Out_ const char** out); -// Set a flag so that any running OrtRun* calls that are using this instance of OrtRunOptions -// will exit as soon as possible if the flag is true. -ORT_API_STATUS(OrtRunOptionsEnableTerminate, _Inout_ OrtRunOptions* options); -ORT_API_STATUS(OrtRunOptionsDisableTerminate, _Inout_ OrtRunOptions* options); +// Set a flag so that ALL incomplete OrtRun calls that are using this instance of OrtRunOptions +// will exit as soon as possible. +ORT_API_STATUS(OrtRunOptionsSetTerminate, _Inout_ OrtRunOptions* options); +// Unset the terminate flag to enable this OrtRunOptions instance being used in new OrtRun calls. +ORT_API_STATUS(OrtRunOptionsUnsetTerminate, _Inout_ OrtRunOptions* options); /** * Create a tensor from an allocator. OrtReleaseValue will also release the buffer inside the output value diff --git a/include/onnxruntime/core/session/onnxruntime_cxx_api.h b/include/onnxruntime/core/session/onnxruntime_cxx_api.h index 020922f2cf..daccf1eb18 100644 --- a/include/onnxruntime/core/session/onnxruntime_cxx_api.h +++ b/include/onnxruntime/core/session/onnxruntime_cxx_api.h @@ -125,8 +125,10 @@ struct RunOptions : Base { RunOptions& SetRunTag(const char* run_tag); const char* GetRunTag() const; - RunOptions& EnableTerminate(); - RunOptions& DisableTerminate(); + // terminate ALL currently executing Session::Run calls that were made using this RunOptions instance + RunOptions& SetTerminate(); + // unset the terminate flag so this RunOptions instance can be used in a new Session::Run call + RunOptions& UnsetTerminate(); }; struct SessionOptions : Base { diff --git a/include/onnxruntime/core/session/onnxruntime_cxx_inline.h b/include/onnxruntime/core/session/onnxruntime_cxx_inline.h index 24f6171666..54eb699782 100644 --- a/include/onnxruntime/core/session/onnxruntime_cxx_inline.h +++ b/include/onnxruntime/core/session/onnxruntime_cxx_inline.h @@ -116,13 +116,13 @@ inline const char* RunOptions::GetRunTag() const { return out; } -inline RunOptions& RunOptions::EnableTerminate() { - ORT_THROW_ON_ERROR(OrtRunOptionsEnableTerminate(p_)); +inline RunOptions& RunOptions::SetTerminate() { + ORT_THROW_ON_ERROR(OrtRunOptionsSetTerminate(p_)); return *this; } -inline RunOptions& RunOptions::DisableTerminate() { - ORT_THROW_ON_ERROR(OrtRunOptionsDisableTerminate(p_)); +inline RunOptions& RunOptions::UnsetTerminate() { + ORT_THROW_ON_ERROR(OrtRunOptionsUnsetTerminate(p_)); return *this; } diff --git a/onnxruntime/core/framework/run_options.cc b/onnxruntime/core/framework/run_options.cc index 640c610841..1d535b474b 100644 --- a/onnxruntime/core/framework/run_options.cc +++ b/onnxruntime/core/framework/run_options.cc @@ -43,12 +43,12 @@ ORT_API_STATUS_IMPL(OrtRunOptionsGetRunTag, _In_ const OrtRunOptions* options, c return nullptr; } -ORT_API_STATUS_IMPL(OrtRunOptionsEnableTerminate, _Inout_ OrtRunOptions* options) { +ORT_API_STATUS_IMPL(OrtRunOptionsSetTerminate, _Inout_ OrtRunOptions* options) { options->terminate = true; return nullptr; } -ORT_API_STATUS_IMPL(OrtRunOptionsDisableTerminate, _Inout_ OrtRunOptions* options) { +ORT_API_STATUS_IMPL(OrtRunOptionsUnsetTerminate, _Inout_ OrtRunOptions* options) { options->terminate = false; return nullptr; } diff --git a/onnxruntime/core/providers/cpu/symbols.txt b/onnxruntime/core/providers/cpu/symbols.txt index 632bff9d77..e2523d2115 100644 --- a/onnxruntime/core/providers/cpu/symbols.txt +++ b/onnxruntime/core/providers/cpu/symbols.txt @@ -67,8 +67,8 @@ OrtRunOptionsGetRunTag OrtRunOptionsSetRunLogVerbosityLevel OrtRunOptionsSetRunLogSeverityLevel OrtRunOptionsSetRunTag -OrtRunOptionsEnableTerminate -OrtRunOptionsDisableTerminate +OrtRunOptionsSetTerminate +OrtRunOptionsUnsetTerminate OrtSessionGetInputCount OrtSessionGetInputName OrtSessionGetInputTypeInfo