Class OrtEnv
The singleton class OrtEnv contains the process-global ONNX Runtime environment. It sets up logging, creates system wide thread-pools (if Thread Pool options are provided) and other necessary things for OnnxRuntime to function.
Create or access OrtEnv by calling the Instance() method. Instance() can be called multiple times. It would return the same instance.
CreateInstanceWithOptions() provides a way to create environment with options. It must be called once before Instance() is called, otherwise it would not have effect.
If the environment is not explicitly created, it will be created as needed, e.g., when creating a SessionOptions instance.
Inheritance
Implements
Inherited Members
Namespace: Microsoft.ML.OnnxRuntime
Assembly: Microsoft.ML.OnnxRuntime.dll
Syntax
public sealed class OrtEnv : SafeHandle, IDisposable
Properties
| Improve this Doc View SourceEnvLogLevel
Get/Set log level property of OrtEnv instance Default LogLevel.Warning
Declaration
public OrtLoggingLevel EnvLogLevel { get; set; }
Property Value
Type | Description |
---|---|
OrtLoggingLevel | env log level |
IsCreated
Provides visibility if singleton already been instantiated
Declaration
public static bool IsCreated { get; }
Property Value
Type | Description |
---|---|
Boolean |
IsInvalid
Overrides SafeHandle.IsInvalid
Declaration
public override bool IsInvalid { get; }
Property Value
Type | Description |
---|---|
Boolean | returns true if handle is equal to Zero |
Overrides
Methods
| Improve this Doc View SourceCreateAndRegisterAllocator(OrtMemoryInfo, OrtArenaCfg)
Create and register an allocator to the OrtEnv instance so as to enable sharing across all sessions using the OrtEnv instance
OrtMemoryInfo instance to be used for allocator creation OrtArenaCfg instance that will be used to define the behavior of the arena based allocatorDeclaration
public void CreateAndRegisterAllocator(OrtMemoryInfo memInfo, OrtArenaCfg arenaCfg)
Parameters
Type | Name | Description |
---|---|---|
OrtMemoryInfo | memInfo | |
OrtArenaCfg | arenaCfg |
CreateInstanceWithOptions(ref EnvironmentCreationOptions)
Provides a way to create an instance with options. It throws if the instance already exists and the specified options not have effect.
Declaration
public static OrtEnv CreateInstanceWithOptions(ref EnvironmentCreationOptions options)
Parameters
Type | Name | Description |
---|---|---|
EnvironmentCreationOptions | options |
Returns
Type | Description |
---|---|
OrtEnv |
Exceptions
Type | Condition |
---|---|
OnnxRuntimeException | if the singleton has already been created |
DisableTelemetryEvents()
Disable platform telemetry collection
Declaration
public void DisableTelemetryEvents()
EnableTelemetryEvents()
Enable platform telemetry collection where applicable (currently only official Windows ORT builds have telemetry collection capabilities)
Declaration
public void EnableTelemetryEvents()
GetAvailableProviders()
Queries all the execution providers supported in the native onnxruntime shared library
Declaration
public string[] GetAvailableProviders()
Returns
Type | Description |
---|---|
String[] | an array of strings that represent execution provider names |
GetEpDevices()
Get the list of all execution provider and device combinations that are available. These can be used to select the execution provider and device for a session.
Declaration
public IReadOnlyList<OrtEpDevice> GetEpDevices()
Returns
Type | Description |
---|---|
IReadOnlyList<OrtEpDevice> |
GetVersionString()
This function returns the onnxruntime version string
Declaration
public string GetVersionString()
Returns
Type | Description |
---|---|
String | version string |
Instance()
Instantiates (if not already done so) a new OrtEnv instance with the default logging level and no other options. Otherwise returns the existing instance.
It returns the same instance on every call - OrtEnv
is singleton
Declaration
public static OrtEnv Instance()
Returns
Type | Description |
---|---|
OrtEnv | Returns a singleton instance of OrtEnv that represents native OrtEnv object |
RegisterExecutionProviderLibrary(String, String)
Register an execution provider library with the OrtEnv instance. A registered execution provider library can be used by all sessions created with the OrtEnv instance. Devices the execution provider can utilize are added to the values returned by GetEpDevices() and can be used in SessionOptions.AppendExecutionProvider to select an execution provider for a device.
Coming: A selection policy can be specified and ORT will automatically select the best execution providers and devices for the model.
Declaration
public void RegisterExecutionProviderLibrary(string registrationName, string libraryPath)
Parameters
Type | Name | Description |
---|---|---|
String | registrationName | The name to register the library under. |
String | libraryPath | The path to the library to register. |
ReleaseHandle()
Destroys native object
Declaration
protected override bool ReleaseHandle()
Returns
Type | Description |
---|---|
Boolean | always returns true |
Overrides
UnregisterExecutionProviderLibrary(String)
Unregister an execution provider library from the OrtEnv instance.
Declaration
public void UnregisterExecutionProviderLibrary(string registrationName)
Parameters
Type | Name | Description |
---|---|---|
String | registrationName | The name the library was registered under. |