💚 End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Enable Vulkan GPU offload for Ensu desktop on Linux
Thorbjørn Lindeijer148c38f5d456
diff --git a/rust/apps/ensu/src-tauri/src/commands/llm.rs b/rust/apps/ensu/src-tauri/src/commands/llm.rsindex 7564f62e1a..eccc4f3007 100644--- a/rust/apps/ensu/src-tauri/src/commands/llm.rs+++ b/rust/apps/ensu/src-tauri/src/commands/llm.rs@@ -400,6 +400,31 @@ pub async fn llm_load_model("LLM",format!("load model requested model_path={}", params.model_path),);+ // GPU offload selection, in order of precedence: an explicit value from the+ // web layer > the ENSU_N_GPU_LAYERS env override > the default. Benchmarking+ // on the Vulkan backend (RX 480, Gemma 4 E4B) showed full offload is both+ // fastest (no per-token CPU<->GPU activation transfers; partial offload was+ // up to ~1.6x slower) and most robust (it sidesteps a ggml scheduler assert+ // that can abort partial CPU/GPU splits). The driver spills any VRAM overflow+ // to system memory instead of failing, so "offload everything" is a safe+ // default. Set ENSU_N_GPU_LAYERS to cap it on a small GPU, or to 0 for CPU.+ const DEFAULT_GPU_LAYERS: i32 = 999; // llama.cpp clamps to the model's layer count+ let mut params = params;+ if params.n_gpu_layers.is_none() {+ params.n_gpu_layers = Some(match std::env::var("ENSU_N_GPU_LAYERS") {+ Ok(raw) => match raw.trim().parse::<i32>() {+ Ok(layers) => {+ logging::log("LLM", format!("n_gpu_layers from ENSU_N_GPU_LAYERS={layers}"));+ layers+ }+ Err(_) => {+ logging::log("LLM", format!("ignoring invalid ENSU_N_GPU_LAYERS={raw:?}"));+ DEFAULT_GPU_LAYERS+ }+ },+ Err(_) => DEFAULT_GPU_LAYERS,+ });+ }let model = async_runtime::spawn_blocking(move || {match catch_unwind(AssertUnwindSafe(|| llm::Model::load(params))) {Ok(result) => result.map_err(llm_api_error),diff --git a/rust/crates/ensu/Cargo.toml b/rust/crates/ensu/Cargo.tomlindex 4ced215648..60582c646e 100644--- a/rust/crates/ensu/Cargo.toml+++ b/rust/crates/ensu/Cargo.toml@@ -39,7 +39,18 @@ zeroize = { version = "1.8", features = ["derive"] }[target.'cfg(target_os = "macos")'.dependencies]llama-cpp-2 = { version = "=0.1.144", default-features = false, features = ["mtmd"] }-[target.'cfg(not(target_os = "macos"))'.dependencies]+# Desktop Linux enables the Vulkan GPU backend, which runs on AMD, Intel and+# NVIDIA GPUs through the system Vulkan loader (no vendor SDK required). The+# build needs a Vulkan loader plus "glslc" to compile the compute shaders. GPU+# offload is opt-in at runtime via the ENSU_N_GPU_LAYERS env variable; with it+# unset the app still runs entirely on the CPU.+[target.'cfg(target_os = "linux")'.dependencies]+llama-cpp-2 = { version = "=0.1.144", features = ["mtmd", "vulkan"] }++# Android (and anything else that is neither macOS nor desktop Linux) stays on+# the CPU backend. Windows Vulkan additionally requires a VULKAN_SDK, so it is+# intentionally left out here.+[target.'cfg(all(not(target_os = "macos"), not(target_os = "linux")))'.dependencies]llama-cpp-2 = { version = "=0.1.144", features = ["mtmd"] }[target.'cfg(target_os = "android")'.dependencies]