Environment

class Environment : JniHandle

Environment to hold configuration options for LiteRT runtime.

Summary

Nested types

Options configurable in LiteRT environment.

Public companion functions

Environment

Creates an environment.

Environment
create(
    npuAcceleratorProvider: NpuAcceleratorProvider,
    options: Map<Environment.OptionString>
)

Creates an environment with a NpuAcceleratorProvider.

Environment
create(
    context: Context,
    options: Map<Environment.OptionString>,
    enableCompilerCache: Boolean
)

Creates an environment.

Environment
create(
    context: Context,
    npuAcceleratorProvider: NpuAcceleratorProvider,
    options: Map<Environment.OptionString>,
    enableCompilerCache: Boolean
)

Creates an environment with a NpuAcceleratorProvider, which provides the NPU libraries.

Public functions

Set<Accelerator>

Returns the set of accelerators available in the environment.

Protected functions

open Unit

Clean up resources associated with the handle.

Inherited functions

From com.google.ai.edge.litert.JniHandle
Unit

Asserts that the handle is not destroyed, otherwise throws an IllegalStateException.

final Unit

Clean up the handle safely to avoid releasing the same JNI handle multiple times.

Public companion functions

create

fun create(options: Map<Environment.OptionString> = mapOf()): Environment

Creates an environment.

Note: This version does not enable compiler caching. Use create(Context, Map, Boolean) to enable caching.

Parameters
options: Map<Environment.OptionString> = mapOf()

The options to configure the environment.

create

fun create(
    npuAcceleratorProvider: NpuAcceleratorProvider,
    options: Map<Environment.OptionString> = mapOf()
): Environment

Creates an environment with a NpuAcceleratorProvider.

Note: This version does not enable compiler caching. Use create(Context, NpuAcceleratorProvider, Map, Boolean) to enable caching.

Parameters
npuAcceleratorProvider: NpuAcceleratorProvider

The NPU accelerator provider.

options: Map<Environment.OptionString> = mapOf()

The options to configure the environment.

create

fun create(
    context: Context,
    options: Map<Environment.OptionString> = mapOf(),
    enableCompilerCache: Boolean = true
): Environment

Creates an environment.

Parameters
context: Context

The Android context.

options: Map<Environment.OptionString> = mapOf()

The options to configure the environment.

enableCompilerCache: Boolean = true

Whether to enable the compiler cache.

create

fun create(
    context: Context,
    npuAcceleratorProvider: NpuAcceleratorProvider,
    options: Map<Environment.OptionString> = mapOf(),
    enableCompilerCache: Boolean = true
): Environment

Creates an environment with a NpuAcceleratorProvider, which provides the NPU libraries.

Parameters
context: Context

The Android context.

npuAcceleratorProvider: NpuAcceleratorProvider

The NPU accelerator provider.

options: Map<Environment.OptionString> = mapOf()

The options to configure the environment.

enableCompilerCache: Boolean = true

Whether to enable the compiler cache.

Public functions

getAvailableAccelerators

fun getAvailableAccelerators(): Set<Accelerator>

Returns the set of accelerators available in the environment.

Protected functions

destroy

protected open fun destroy(): Unit

Clean up resources associated with the handle.