litert_bindings library

Public, native-only export of the LiteRt interpreter FFI bindings (LiteRtBindings) for native-only leaves that need to import the concrete bindings from a file that is itself native-only (never reached on web) — this package's own src/embedding/litert_embedding_forward_pass.dart (as an intra-package import) and the capability package flutter_gemma_speech.

Prefer this over package:flutter_gemma_litertlm/flutter_gemma_litertlm.dart in native-only files: that barrel's LiteRtBindings export is behind an if (dart.library.ffi) conditional that flutter analyze resolves to the empty web stub (single-library analysis, no compile-time environment), which would make the symbol appear undefined during analysis even though it resolves correctly at compile time on native platforms.

This library is unconditional — importing it from code that is also reachable on web will fail to compile there. Native-only leaves should import this directly instead of the implementation path package:flutter_gemma_litertlm/src/ffi/litert_bindings.dart.

Classes

AlignedAlloc
Pair of (raw, aligned) pointers returned by allocAligned.
LiteRtBindings
Minimal C-API surface for running an embedding forward pass.
LiteRtLayoutPosix
LiteRtLayout, identical on every platform. The name predates the upstream fix above. Read LiteRtLayoutView for accessors.
LiteRtLayoutView
View over a LiteRtLayout* filled in by the C API.
LiteRtRankedTensorTypePosix
LiteRtRankedTensorTypeView
Builder for LiteRtRankedTensorType*: element type, rank, dimensions.

Extensions

LiteRtStatusX on int
Throws if a LiteRT C call returned a non-OK status code.

Constants

kLiteRtElementTypeFloat32 → const int
LiteRtElementType values used for embedding pipelines.
kLiteRtElementTypeInt32 → const int
kLiteRtHostMemoryAlignment → const int
Host memory alignment required by LiteRtCreateTensorBufferFromHostMemory (see LITERT_HOST_MEMORY_BUFFER_ALIGNMENT in litert_tensor_buffer_types.h).
kLiteRtHwAcceleratorCpu → const int
kLiteRtHwAcceleratorGpu → const int
kLiteRtHwAcceleratorNone → const int
LiteRtHwAcceleratorSet bit flags (litert_common.h). CPU is enough for embedding; GPU/NPU can be wired later.
kLiteRtHwAcceleratorNpu → const int
kLiteRtMaxRank → const int
kLiteRtStatusOk → const int
kLiteRtTensorBufferLockModeRead → const int
LiteRtTensorBufferLockMode values (litert_common.h).
kLiteRtTensorBufferLockModeReadWrite → const int
kLiteRtTensorBufferLockModeWrite → const int

Functions

allocAligned(int bytes, {int align = kLiteRtHostMemoryAlignment}) AlignedAlloc
Allocate bytes of host memory and return a AlignedAlloc whose .aligned pointer is aligned to align bytes (default 64, the LITERT_HOST_MEMORY_BUFFER_ALIGNMENT value).