Show / Hide Table of Contents

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
Object
CriticalFinalizerObject
SafeHandle
OrtEnv
Implements
IDisposable
Inherited Members
SafeHandle.handle
SafeHandle.Close()
SafeHandle.DangerousAddRef(Boolean)
SafeHandle.DangerousGetHandle()
SafeHandle.DangerousRelease()
SafeHandle.Dispose()
SafeHandle.Dispose(Boolean)
SafeHandle.SetHandle(IntPtr)
SafeHandle.SetHandleAsInvalid()
SafeHandle.IsClosed
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: Microsoft.ML.OnnxRuntime
Assembly: Microsoft.ML.OnnxRuntime.dll
Syntax
public sealed class OrtEnv : SafeHandle, IDisposable

Properties

| Improve this Doc View Source

EnvLogLevel

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

| Improve this Doc View Source

IsCreated

Provides visibility if singleton already been instantiated

Declaration
public static bool IsCreated { get; }
Property Value
Type Description
Boolean
| Improve this Doc View Source

IsInvalid

Overrides SafeHandle.IsInvalid

Declaration
public override bool IsInvalid { get; }
Property Value
Type Description
Boolean

returns true if handle is equal to Zero

Overrides
System.Runtime.InteropServices.SafeHandle.IsInvalid

Methods

| Improve this Doc View Source

CreateAndRegisterAllocator(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 allocator
Declaration
public void CreateAndRegisterAllocator(OrtMemoryInfo memInfo, OrtArenaCfg arenaCfg)
Parameters
Type Name Description
OrtMemoryInfo memInfo
OrtArenaCfg arenaCfg
| Improve this Doc View Source

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

| Improve this Doc View Source

DisableTelemetryEvents()

Disable platform telemetry collection

Declaration
public void DisableTelemetryEvents()
| Improve this Doc View Source

EnableTelemetryEvents()

Enable platform telemetry collection where applicable (currently only official Windows ORT builds have telemetry collection capabilities)

Declaration
public void EnableTelemetryEvents()
| Improve this Doc View Source

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

| Improve this Doc View Source

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>
| Improve this Doc View Source

GetVersionString()

This function returns the onnxruntime version string

Declaration
public string GetVersionString()
Returns
Type Description
String

version string

| Improve this Doc View Source

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

| Improve this Doc View Source

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.

| Improve this Doc View Source

ReleaseHandle()

Destroys native object

Declaration
protected override bool ReleaseHandle()
Returns
Type Description
Boolean

always returns true

Overrides
System.Runtime.InteropServices.SafeHandle.ReleaseHandle()
| Improve this Doc View Source

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.

Implements

System.IDisposable
  • Improve this Doc
  • View Source
In This Article
Back to top