LlamaEngine
Loads a GGUF model with llama.cpp and returns a ready LlamaEngine.
The model and its KV-cache context are created on the new engine's own dedicated thread. backendConfig is enforced at load time:
ComputeBackend.CPU_ONLY hands llama.cpp an empty device list, so no GPU backend is ever created: weights, KV cache and compute stay on the CPU (Accelerate / NEON on Apple, legal in the iOS background).
ComputeBackend.GPU_METAL / ComputeBackend.GPU_VULKAN offload BackendConfig.gpuLayers layers (BackendConfig.ALL_GPU_LAYERS = all) to the LlamaEngineOptions.gpuDevice-th device of that kind.
ComputeBackend.NPU_COREML is not supported by llama.cpp; with LlamaEngineOptions.allowBackendFallback it falls back to Metal / CPU, otherwise loading fails with com.donfuldauer.kggml.core.BackendUnavailableException.
ComputeBackend.AUTO picks the first available of Metal, OpenCL, Vulkan, CPU, except on Android, where it always picks the CPU (see LlamaAutoPolicy); an explicit
GPU_OPENCLorGPU_VULKANrequest still uses that GPU there. On the iOS simulator Metal is unavailable (its Metal device makes llama.cpp generate garbage), soAUTOresolves to the CPU there and an explicitGPU_METALfalls back to it, or fails with com.donfuldauer.kggml.core.BackendUnavailableException when LlamaEngineOptions.allowBackendFallback isfalse.
BackendConfig.cpuThreads sets the generation and prompt threads (BackendConfig.AUTO_THREADS = performance cores), BackendConfig.useFlashAttention llama.cpp's flash attention (null: llama.cpp's automatic choice, LLAMA_FLASH_ATTN_TYPE_AUTO), and BackendConfig.useMmap whether the GGUF file is memory-mapped.
With LlamaEngineOptions.projectorPath a multimodal projector (libmtmd) is loaded as well, on the backend the model runs on, enabling image prompts (see LlamaEngine.generate with images). If the GPU refuses the projector weights, the load fails with com.donfuldauer.kggml.core.BackendUnavailableException, or, with LlamaEngineOptions.allowBackendFallback, the model and projector are loaded again on the next backend (the CPU).
Throws
if the file is missing or not a loadable GGUF model, or the projector is missing or does not match the model.
if the backend is unavailable and fallback is off.
if the weights, the projector weights or the KV cache cannot be allocated.
if the native libraries cannot be loaded.