BackendConfig

data class BackendConfig(val backend: ComputeBackend = ComputeBackend.AUTO, val gpuLayers: Int = ALL_GPU_LAYERS, val cpuThreads: Int = AUTO_THREADS, val useFlashAttention: Boolean? = null, val useMmap: Boolean = true)(source)

Runtime compute configuration passed to every engine at construction time.

Instances are validated on construction (including via copy); invalid combinations throw IllegalArgumentException.

Constructors

Link copied to clipboard
constructor(backend: ComputeBackend = ComputeBackend.AUTO, gpuLayers: Int = ALL_GPU_LAYERS, cpuThreads: Int = AUTO_THREADS, useFlashAttention: Boolean? = null, useMmap: Boolean = true)

Types

Link copied to clipboard
object Companion

Constants and factory functions of BackendConfig.

Properties

Link copied to clipboard

requested compute backend; resolved by the engine with ComputeBackend.resolve.

Link copied to clipboard

number of CPU worker threads. AUTO_THREADS (-1) lets the SDK choose (see resolveCpuThreads); otherwise must be in 1..MAX_CPU_THREADS.

Link copied to clipboard

number of model layers to offload to the GPU. ALL_GPU_LAYERS (-1) offloads every layer, 0 keeps everything on the CPU. Must be >= -1, and must be 0 or -1 when backend is ComputeBackend.CPU_ONLY.

Link copied to clipboard

flash attention kernels where the engine and backend support them: true turns them on, false off, and null (the default) uses each engine's own default (Whisper: on; llama.cpp: its automatic choice per device; stable-diffusion.cpp: off).

Link copied to clipboard

memory-maps model weights instead of reading them into heap memory.

Functions

Link copied to clipboard
fun effectiveGpuLayers(resolvedBackend: ComputeBackend = backend): Int

The number of GPU layers to request from native code once backend has been resolved to resolvedBackend: always 0 for ComputeBackend.CPU_ONLY, otherwise gpuLayers.

Link copied to clipboard
fun resolveCpuThreads(availableProcessors: Int): Int

The concrete thread count to pass to native code. Explicit values are returned unchanged; AUTO_THREADS resolves to availableProcessors clamped to 1..MAX_AUTO_THREADS.

Link copied to clipboard

Whether to use flash attention: useFlashAttention when it is set, otherwise engineDefault (the calling engine's own default).