Table of Contents

Struct LiteRtBackend

Namespace
LiteRtLmSharp
Assembly
LiteRtLmSharp.dll

A compute backend for the engine or one of its encoders. Use a well-known value (Cpu, Gpu, Npu) or Custom(string) for a backend exposed by your own native build. The underlying native identifier is Value; backends compare by it.

public readonly struct LiteRtBackend : IEquatable<LiteRtBackend>
Implements
Inherited Members

Remarks

This is a closed-but-extensible "smart enum": the named values cover the backends this project builds and validates, while Custom(string) lets a caller who ships their own LiteRT-LM natives target a backend those binaries add, without waiting for a new enum member. The default value (default(LiteRtBackend)) is Cpu.

Properties

Cpu

Run on the CPU. The default backend.

public static LiteRtBackend Cpu { get; }

Property Value

LiteRtBackend

Gpu

Run on the GPU (WebGPU / Metal / OpenCL, depending on platform).

public static LiteRtBackend Gpu { get; }

Property Value

LiteRtBackend

Npu

Run on a neural processing unit (NPU). Requires vendor NPU libraries the native engine can load (Qualcomm / MediaTek on Android, Intel OpenVINO on Windows/Linux), which this project does not ship or validate. On a build without them, Load(LiteRtEngineOptions) fails with a LiteRtException.

public static LiteRtBackend Npu { get; }

Property Value

LiteRtBackend

Value

The native backend identifier passed to LiteRT-LM (e.g. "cpu", "gpu", "npu").

public string Value { get; }

Property Value

string

Methods

Custom(string)

A backend identified by an arbitrary native string, for a custom LiteRT-LM build that supports additional backends. The string is passed through to the native layer verbatim.

public static LiteRtBackend Custom(string value)

Parameters

value string

Returns

LiteRtBackend

Exceptions

ArgumentException

value is null or empty.

Equals(LiteRtBackend)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(LiteRtBackend other)

Parameters

other LiteRtBackend

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Parse(string)

Parses a backend identifier (case-insensitive): "cpu", "gpu" and "npu" map to the named values; anything else becomes a Custom(string) backend carrying the given string. Handy for config/CLI-driven hosts.

public static LiteRtBackend Parse(string value)

Parameters

value string

Returns

LiteRtBackend

Exceptions

ArgumentException

value is null or empty.

ToString()

The native backend identifier (same as Value).

public override string ToString()

Returns

string

Operators

operator ==(LiteRtBackend, LiteRtBackend)

Compares two backends by their native value.

public static bool operator ==(LiteRtBackend left, LiteRtBackend right)

Parameters

left LiteRtBackend
right LiteRtBackend

Returns

bool

operator !=(LiteRtBackend, LiteRtBackend)

Compares two backends by their native value.

public static bool operator !=(LiteRtBackend left, LiteRtBackend right)

Parameters

left LiteRtBackend
right LiteRtBackend

Returns

bool