DiffusionEngine
Loads a full Stable Diffusion checkpoint (.gguf, .safetensors or .ckpt) with stable-diffusion.cpp and returns a ready DiffusionEngine. Same as the DiffusionModelFiles overload with DiffusionModelFiles(modelPath).
Loads model with stable-diffusion.cpp and returns a ready DiffusionEngine.
The weights are loaded on the new engine's own dedicated thread. backendConfig is enforced at load time:
ComputeBackend.CPU_ONLY pins every stable-diffusion.cpp module to the ggml CPU device, so no GPU backend is ever created (Accelerate / NEON on Apple, legal in the iOS background).
ComputeBackend.GPU_METAL / ComputeBackend.GPU_VULKAN run on the DiffusionEngineOptions.gpuDevice-th device of that kind. BackendConfig.gpuLayers
= 0keeps the weights in host memory and streams them to the GPU per graph (stable-diffusion.cppoffload_params_to_cpu); any other value keeps them on the GPU.ComputeBackend.NPU_COREML is not supported by stable-diffusion.cpp; with DiffusionEngineOptions.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 that on Android it never picks OpenCL: ggml's OpenCL backend has no kernels for some of the diffusion graphs' ops (e.g.
GET_ROWSon a Q8_0 text-encoder embedding), so it resolves to Vulkan or the CPU there. An explicit ComputeBackend.GPU_OPENCL request still uses OpenCL; a graph with an op it cannot run then fails the generation with com.donfuldauer.kggml.core.NativeFailureException instead of aborting the process. On the iOS simulator Metal is unavailable (its Metal device aborts on ggml's buffer allocations), soAUTOresolves to the CPU there and an explicitGPU_METALfalls back to it, or fails when DiffusionEngineOptions.allowBackendFallback isfalse.
BackendConfig.cpuThreads sets the CPU threads (BackendConfig.AUTO_THREADS = performance cores), BackendConfig.useFlashAttention flash attention in every module (off when null), and BackendConfig.useMmap whether the weight files are memory-mapped.
Throws
if a file is missing or not a loadable diffusion model.
if the backend is unavailable and fallback is off.
if the weights cannot be allocated.
if the native libraries cannot be loaded.