DiffusionEngine
stable-diffusion.cpp text-to-image engine with streamed progress and cooperative cancellation.
Create instances with the DiffusionEngine factory functions. Engines are ordinary objects — never singletons — and any number of them can coexist and generate concurrently: each owns its native context (weights + backends) and a dedicated single-threaded dispatcher (SerialExecutor) that serializes loading, every generation and the native release in close.
Cancellation is cooperative at step granularity: cancelling the collector of generate (or abortActiveGeneration / close) latches the native abort flag, and stable-diffusion.cpp stops at its next progress point — after the denoising step (or VAE tile) that is computing finishes. No native image buffer outlives a call, and the engine stays usable afterwards.
Types
Constants and factory functions of DiffusionEngine.
Properties
The backend stable-diffusion.cpp actually runs on (never ComputeBackend.AUTO).
The GPU stable-diffusion.cpp runs on, or null on the CPU (see InferenceEngine.activeDeviceName).
The backend configuration this engine was loaded with.
Why activeBackend is not the requested backend, or null (see InferenceEngine.backendFallbackReason).
true while a generation is executing native code on this engine.
The model files this engine was loaded from.
Static properties of the loaded model.
Diffusion-specific construction options.
true if a GPU device was handed to stable-diffusion.cpp; always false for ComputeBackend.CPU_ONLY.
Functions
Requests the native abort of the generation currently executing, if any; its generate flow then ends with a terminal DiffusionEvent.Error (InferenceCancelledException) at the next step boundary. Safe from any thread. Queued generations are not affected.
Closes the engine: aborts a running generation, rejects queued and future calls with IllegalStateException, frees the native context on the engine thread, and stops that thread. Idempotent and safe from any thread.
closes the engine and suspends until its native memory has been freed on the engine thread (after a running call has been aborted and left native code). Idempotent; cancelling the caller stops the wait, not the release. See InferenceEngine.closeAndAwait.
Generates one image from params as a cold Flow of DiffusionEvents. Each collection runs one generation on the engine thread (collections on the same engine are serialized).
Runs generate to completion and returns the image. onProgress (optional) receives every DiffusionEvent.Progress on the calling coroutine.