InferenceEngine
Common contract of every Kggml engine (WhisperEngine, LlamaEngine, DiffusionEngine, …).
Engines are ordinary instantiable classes — never global singletons — and multiple instances may be alive concurrently. Each instance serializes all of its native work (init, inference, close) on its own dedicated single-threaded dispatcher.
Closing contract:
close releases all native resources held by the engine and is idempotent: calling it again (from any thread) is a no-op.
After close, isClosed returns
trueand any further inference call fails with IllegalStateException.close does not wait for the native memory to be freed: it aborts a running inference and schedules the release on the engine thread, behind the work already there, then returns. closeAndAwait closes the engine the same way and suspends until that release has completed, so the engine's native memory (model weights, compute buffers, backends) is freed when it returns. Use it before measuring memory, or before loading another large model that needs the space.
Properties
The concrete backend selected for this engine after ComputeBackend.resolve; never ComputeBackend.AUTO.
The ggml description of the GPU the engine runs on (the driver's device name, e.g. "Adreno (TM) 730" or "Apple M2"; the Metal device for ComputeBackend.NPU_COREML), or null on the CPU or when it is unknown.
The configuration this engine was constructed with.
Why activeBackend is not the backend of backendConfig, or null when it is (and for a ComputeBackend.AUTO request with nothing to report). Examples: "PowerVR excluded (set KGGML_VULKAN_ALLOW_POWERVR=1 to allow): PowerVR C-Series CXTP-48-1536", "Vulkan backend failed the load-time warm-up: vk::Device::createComputePipeline: ErrorUnknown", "no Vulkan device", or, for an AUTO request that ended on the CPU, the engine's AUTO policy ("AUTO prefers the CPU for Whisper on Android") or why the device's GPU cannot be used. Several reasons (a fallback chain) are joined with "; ". Each fallback is also logged as one kggml line (logcat on Android).
Functions
Closes the engine and schedules the release of its native resources on the engine thread, without waiting for it (see closeAndAwait). Idempotent and safe from any thread.
closes the engine (if it is not closed yet) and suspends until its native resources have been released. A running inference is aborted first, and the release follows once it has left native code. Idempotent: every call, from any coroutine, returns once the release has completed. Cancelling the caller stops the wait, not the release.