💚 End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Address review feedback for Linux Vulkan support
Thorbjørn Lindeijer03ce0d683d35
diff --git a/.github/workflows/warm-caches.yml b/.github/workflows/warm-caches.ymlindex deccbc0634..24bddcf549 100644--- a/.github/workflows/warm-caches.yml+++ b/.github/workflows/warm-caches.yml@@ -148,6 +148,13 @@ jobs:workspaces: rustshared-key: ensu-android+ # cargo codegen native builds the uniffi library for the host, which+ # on Linux enables the llama.cpp Vulkan backend.+ - name: Install Vulkan build dependencies+ run: |+ sudo apt-get update+ sudo apt-get install -y libvulkan-dev glslc+- run: cargo codegen nativeworking-directory: rustdiff --git a/rust/apps/ensu/changes/vulkan-gpu-linux.md b/rust/apps/ensu/changes/vulkan-gpu-linux.mdnew file mode 100644index 0000000000..9fb883e7e4--- /dev/null+++ b/rust/apps/ensu/changes/vulkan-gpu-linux.md@@ -0,0 +1 @@+- Chat responses are now GPU-accelerated on Linux via Vulkan, roughly 3x faster. Thanks @bjorn!diff --git a/rust/apps/ensu/src-tauri/src/commands/llm.rs b/rust/apps/ensu/src-tauri/src/commands/llm.rsindex eccc4f3007..0568e42992 100644--- a/rust/apps/ensu/src-tauri/src/commands/llm.rs+++ b/rust/apps/ensu/src-tauri/src/commands/llm.rs@@ -400,30 +400,20 @@ 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.+ // Default to offloading all layers to the GPU when the caller does not+ // specify a count. 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, and without a usable Vulkan device llama.cpp falls+ // back to the CPU. For the rare setups where the GPU must be avoided,+ // Vulkan and llama.cpp already provide runtime knobs (for example+ // GGML_VK_VISIBLE_DEVICES and VK_LOADER_DRIVERS_DISABLE).const DEFAULT_GPU_LAYERS: i32 = 999; // llama.cpp clamps to the model's layer countlet 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,- });+ params.n_gpu_layers = Some(DEFAULT_GPU_LAYERS);}let model = async_runtime::spawn_blocking(move || {match catch_unwind(AssertUnwindSafe(|| llm::Model::load(params))) {diff --git a/rust/apps/ensu/src-tauri/tauri.conf.json b/rust/apps/ensu/src-tauri/tauri.conf.jsonindex 9afab1b7cc..68bb43aaf0 100644--- a/rust/apps/ensu/src-tauri/tauri.conf.json+++ b/rust/apps/ensu/src-tauri/tauri.conf.json@@ -29,7 +29,11 @@"active": true,"targets": "all","icon": ["icons/icon.icns", "icons/icon.ico", "icons/icon.png"],- "macOS": { "minimumSystemVersion": "10.15" }+ "macOS": { "minimumSystemVersion": "10.15" },+ "linux": {+ "deb": { "depends": ["libvulkan1"] },+ "rpm": { "depends": ["vulkan-loader"] }+ }},"plugins": {"updater": {diff --git a/rust/crates/ensu/Cargo.toml b/rust/crates/ensu/Cargo.tomlindex 60582c646e..5a5d90f4df 100644--- a/rust/crates/ensu/Cargo.toml+++ b/rust/crates/ensu/Cargo.toml@@ -41,9 +41,7 @@ llama-cpp-2 = { version = "=0.1.144", default-features = false, features = ["mtm# 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.+# build needs a Vulkan loader plus "glslc" to compile the compute shaders.[target.'cfg(target_os = "linux")'.dependencies]llama-cpp-2 = { version = "=0.1.144", features = ["mtmd", "vulkan"] }