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
Gpu
Run on the GPU (WebGPU / Metal / OpenCL, depending on platform).
public static LiteRtBackend Gpu { get; }
Property Value
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
Value
The native backend identifier passed to LiteRT-LM (e.g. "cpu", "gpu",
"npu").
public string Value { get; }
Property Value
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
valuestring
Returns
Exceptions
- ArgumentException
valueis 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
otherLiteRtBackendAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand 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
valuestring
Returns
Exceptions
- ArgumentException
valueis null or empty.
ToString()
The native backend identifier (same as Value).
public override string ToString()
Returns
Operators
operator ==(LiteRtBackend, LiteRtBackend)
Compares two backends by their native value.
public static bool operator ==(LiteRtBackend left, LiteRtBackend right)
Parameters
leftLiteRtBackendrightLiteRtBackend
Returns
operator !=(LiteRtBackend, LiteRtBackend)
Compares two backends by their native value.
public static bool operator !=(LiteRtBackend left, LiteRtBackend right)
Parameters
leftLiteRtBackendrightLiteRtBackend