KggmlRuntime

Kotlin entry point to the shared native ggml runtime (kggml_runtime.h).

The native runtime is inherently process-wide (one shared ggml per process, see AGENTS.md §2.1), so this is a stateless facade over a reference-counted native lifecycle rather than an engine singleton: engines remain ordinary instantiable classes that each acquire their own RuntimeHandle and close it with themselves.

  • Android / JVM Desktop: calls go through the kggml_runtime_jni JNI bridge. On the JVM the native libraries are loaded from the directory named by the kggml.native.path system property, else extracted from the jar (/kggml/native/<os>-<arch>/), else from java.library.path.

  • iOS: calls go straight to the C ABI through Kotlin/Native cinterop, linked against the dynamic GgmlRuntime.framework (GgmlRuntime.xcframework).

Every native failure surfaces as a typed com.donfuldauer.kggml.core.InferenceException; status codes 0..6 map onto their NativeErrorCode counterparts and runtime-specific codes (100+) onto com.donfuldauer.kggml.core.NativeFailureException with the raw code preserved. A runtime that cannot be loaded at all is reported as a NativeFailureException whose cause is the platform loading error.

Functions

Link copied to clipboard

Takes a reference on the native runtime (initializing it on the first reference). Close the returned handle to release it; the runtime shuts down when the last handle is closed.

Link copied to clipboard

The backends usable on this device with this build. Always contains ComputeBackend.CPU_ONLY and never ComputeBackend.AUTO.

Link copied to clipboard

Every backend kind known to the runtime, CPU first, with compile-time and device availability.

Link copied to clipboard

The ggml descriptions (the driver's device names, e.g. "Adreno (TM) 730") of the GPU devices of backend, in the order the engines' gpuDevice options count them. Devices the runtime does not offer (PowerVR) are listed too, so indices stay aligned. Empty for ComputeBackend.CPU_ONLY, ComputeBackend.NPU_COREML and ComputeBackend.AUTO, and for a backend without devices.

Link copied to clipboard

Number of logical hardware threads (at least 1).

Link copied to clipboard

Version metadata of the loaded native runtime and its pinned ggml.

Link copied to clipboard

true while at least one runtime reference is held (by any caller in this process).

Link copied to clipboard

Recommended inference thread count: the number of performance cores, always at least 1 and at most hardwareThreadCount. On phones these are the cores of the top tiers (at least 75% of the fastest core's scheduler capacity, at most 4 of them), never the efficiency cores; on Apple silicon the P-cores. The engines use it for BackendConfig.AUTO_THREADS.

Link copied to clipboard
fun resolveBackend(requested: ComputeBackend, allowFallback: Boolean = true): ComputeBackend
Link copied to clipboard

Why backend is not available on this device with this build, or null when it is (always for ComputeBackend.CPU_ONLY and ComputeBackend.AUTO). Examples: "no Vulkan device", "PowerVR excluded (set KGGML_VULKAN_ALLOW_POWERVR=1 to allow): PowerVR C-Series CXTP-48-1536", "OpenCL is not available (no kggml-runtime-opencl add-on)". Diagnostic text for logs and UIs, not a stable format. The engines report it as InferenceEngine.backendFallbackReason when they fall back from backend.