Kggml

Kggml is a modular on-device AI SDK for Kotlin Multiplatform (Android, iOS and JVM desktop) wrapping ggml: whisper.cpp (speech-to-text), llama.cpp and libmtmd (text generation and vision-language models) and stable-diffusion.cpp (image generation). Every engine links the single shared kggml-runtime; add only the modules your app needs, version-aligned by the com.donfuldauer:kggml-bom BOM. Start with kggml-core-api, which holds the types shared by every engine.

All modules:

Link copied to clipboard

The pure-Kotlin contracts shared by every Kggml engine, with no native code: InferenceEngine (AutoCloseable), ComputeBackend and BackendConfig for explicit compute-backend control, the streamed TranscriptionEvent and TokenEvent types, the typed InferenceException hierarchy that every native error code maps to, and MemoryPressureObserver.

Link copied to clipboard

Image generation with stable-diffusion.cpp, dynamically linked against kggml-runtime: DiffusionEngine runs text-to-image inference on the shared ggml runtime.

Link copied to clipboard

Text generation with llama.cpp and vision-language models with libmtmd, dynamically linked against kggml-runtime: LlamaEngine streams a Flow<TokenEvent> and supports KV-cache snapshots, GBNF/JSON-constrained output and embeddings.

Link copied to clipboard

Optional pure-Kotlin model management: resumable chunked downloads with SHA-256 verification, a GGUF / Whisper header parser that estimates a model's RAM needs before loading it, and a model cache that evicts on the operating system's low-memory signals.

Link copied to clipboard

The single shared dynamic ggml runtime that every engine links against, so an app carries exactly one copy of ggml: ggml-base, the CPU backend (on Android one module per CPU variant, the best one loaded at run time), Metal with an embedded .metallib on Apple platforms and Vulkan on desktop when enabled. It ships GgmlRuntime.xcframework (iOS and macOS), libggml.so (Android) and the JVM desktop native libraries, and registers the optional GPU add-ons found in the app.

Link copied to clipboard

Optional Android GPU add-on: ggml's OpenCL backend (Adreno kernels) as a dynamically loaded backend module linked against the shared libggml-base of kggml-runtime and the device vendor's libOpenCL.so (API 28+). It backs ComputeBackend.GPU_OPENCL, which ComputeBackend.AUTO prefers over Vulkan when both add-ons are present.

Link copied to clipboard

Optional GPU add-on: ggml's Vulkan backend as a dynamically loaded backend module linked against the shared libggml-base of kggml-runtime, for Android (API 28+) and desktop Linux and Windows x86_64. Adding the dependency is all it takes: kggml-runtime registers it at run time. It is a no-op on macOS and iOS (Metal) and on arm64 desktops.

Link copied to clipboard

Speech-to-text with whisper.cpp, dynamically linked against kggml-runtime: WhisperEngine transcribes PCM audio (native resampling and downmixing) and streams live audio through a ring-buffer VAD gate as a Flow<TranscriptionEvent>, with no temporary files.