2019-08-14 19:02:02 +00:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.ML.OnnxRuntime
|
|
|
|
|
{
|
2020-11-20 22:03:55 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Sets various runtime options.
|
|
|
|
|
/// </summary>
|
2020-08-27 16:17:42 +00:00
|
|
|
public class RunOptions : SafeHandle
|
2019-08-14 19:02:02 +00:00
|
|
|
{
|
2019-08-22 17:14:50 +00:00
|
|
|
internal IntPtr Handle
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-08-27 16:17:42 +00:00
|
|
|
return handle;
|
2019-08-22 17:14:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-20 22:03:55 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Default __ctor. Creates default RuntimeOptions
|
|
|
|
|
/// </summary>
|
2021-01-21 01:44:36 +00:00
|
|
|
public RunOptions()
|
|
|
|
|
: base(IntPtr.Zero, true)
|
2019-08-14 19:02:02 +00:00
|
|
|
{
|
2020-08-27 16:17:42 +00:00
|
|
|
NativeApiStatus.VerifySuccess(NativeMethods.OrtCreateRunOptions(out handle));
|
2019-08-14 19:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
2020-11-20 22:03:55 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Overrides SafeHandle.IsInvalid
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>returns true if handle is equal to Zero</value>
|
2020-08-27 16:17:42 +00:00
|
|
|
public override bool IsInvalid { get { return handle == IntPtr.Zero; } }
|
|
|
|
|
|
2020-05-08 21:31:06 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Log Severity Level for the session logs. Default = ORT_LOGGING_LEVEL_WARNING
|
|
|
|
|
/// </summary>
|
|
|
|
|
public OrtLoggingLevel LogSeverityLevel
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _logSeverityLevel;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2020-08-27 16:17:42 +00:00
|
|
|
NativeApiStatus.VerifySuccess(NativeMethods.OrtRunOptionsSetRunLogSeverityLevel(handle, value));
|
2020-05-08 21:31:06 +00:00
|
|
|
_logSeverityLevel = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private OrtLoggingLevel _logSeverityLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_WARNING;
|
2019-08-14 19:02:02 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
2020-05-08 21:31:06 +00:00
|
|
|
/// Log Verbosity Level for the session logs. Default = 0. Valid values are >=0.
|
|
|
|
|
/// This takes into effect only when the LogSeverityLevel is set to ORT_LOGGING_LEVEL_VERBOSE.
|
2019-08-14 19:02:02 +00:00
|
|
|
/// </summary>
|
2020-05-08 21:31:06 +00:00
|
|
|
public int LogVerbosityLevel
|
2019-08-14 19:02:02 +00:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-05-08 21:31:06 +00:00
|
|
|
return _logVerbosityLevel;
|
2019-08-14 19:02:02 +00:00
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2020-08-27 16:17:42 +00:00
|
|
|
NativeApiStatus.VerifySuccess(NativeMethods.OrtRunOptionsSetRunLogVerbosityLevel(handle, value));
|
2020-05-08 21:31:06 +00:00
|
|
|
_logVerbosityLevel = value;
|
2019-08-14 19:02:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-05-08 21:31:06 +00:00
|
|
|
private int _logVerbosityLevel = 0;
|
2019-08-14 19:02:02 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Log tag to be used during the run. default = ""
|
|
|
|
|
/// </summary>
|
2020-05-08 21:31:06 +00:00
|
|
|
public string LogId
|
2019-08-14 19:02:02 +00:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2021-01-21 01:44:36 +00:00
|
|
|
return _logId;
|
2019-08-14 19:02:02 +00:00
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2021-01-21 01:44:36 +00:00
|
|
|
var logIdPinned = GCHandle.Alloc(NativeOnnxValueHelper.StringToZeroTerminatedUtf8(value), GCHandleType.Pinned);
|
|
|
|
|
using (var pinnedlogIdName = new PinnedGCHandle(logIdPinned))
|
|
|
|
|
{
|
|
|
|
|
NativeApiStatus.VerifySuccess(NativeMethods.OrtRunOptionsSetRunTag(handle, pinnedlogIdName.Pointer));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logId = value;
|
2019-08-14 19:02:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-21 01:44:36 +00:00
|
|
|
private string _logId = "";
|
|
|
|
|
|
2019-08-14 19:02:02 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-09 22:32:33 +00:00
|
|
|
/// Sets a flag to terminate all Run() calls that are currently using this RunOptions object
|
2019-08-14 19:02:02 +00:00
|
|
|
/// Default = false
|
|
|
|
|
/// </summary>
|
2020-11-20 22:03:55 +00:00
|
|
|
/// <value>terminate flag value</value>
|
2019-08-14 19:02:02 +00:00
|
|
|
public bool Terminate
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _terminate;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (!_terminate && value)
|
|
|
|
|
{
|
2020-08-27 16:17:42 +00:00
|
|
|
NativeApiStatus.VerifySuccess(NativeMethods.OrtRunOptionsSetTerminate(handle));
|
2019-08-14 19:02:02 +00:00
|
|
|
_terminate = true;
|
|
|
|
|
}
|
|
|
|
|
else if (_terminate && !value)
|
|
|
|
|
{
|
2020-08-27 16:17:42 +00:00
|
|
|
NativeApiStatus.VerifySuccess(NativeMethods.OrtRunOptionsUnsetTerminate(handle));
|
2019-08-14 19:02:02 +00:00
|
|
|
_terminate = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private bool _terminate = false; //value set to default value of the C++ RunOptions
|
|
|
|
|
|
|
|
|
|
|
2020-08-27 16:17:42 +00:00
|
|
|
#region SafeHandle
|
2020-11-20 22:03:55 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Overrides SafeHandle.ReleaseHandle() to properly dispose of
|
|
|
|
|
/// the native instance of RunOptions
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>always returns true</returns>
|
2020-08-27 16:17:42 +00:00
|
|
|
protected override bool ReleaseHandle()
|
2019-08-14 19:02:02 +00:00
|
|
|
{
|
2021-01-21 01:44:36 +00:00
|
|
|
NativeMethods.OrtReleaseRunOptions(handle);
|
|
|
|
|
handle = IntPtr.Zero;
|
2020-08-27 16:17:42 +00:00
|
|
|
return true;
|
2019-08-14 19:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|