Skip to content

Commit e2bd9d2

Browse files
JSKittyclaude
andcommitted
fix: disable Vulkan GPU for whisper on Android to prevent device freeze
Vulkan compute shaders can hang the shared GPU, stalling the Android compositor and freezing the entire device. Use CPU-only inference on Android — modern SoCs transcribe in seconds without GPU offload. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0209e67 commit e2bd9d2

2 files changed

Lines changed: 22 additions & 13 deletions

File tree

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ bs58 = "0.5.1"
9191
jni = "0.21.1"
9292
ndk-context = "0.1.1"
9393
openssl = { version = "0.10.75", features = ["vendored"] }
94-
whisper-rs = { version = "0.15.1", features = ["vulkan"], optional = true }
94+
whisper-rs = { version = "0.15.1", optional = true }
9595

9696
# Whisper (with platform-specific GPU acceleration)
9797
[target.'cfg(target_os = "macos")'.dependencies]

src-tauri/src/whisper.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,29 @@ pub async fn transcribe<R: Runtime>(handle: &AppHandle<R>, model_name: &str, tra
153153
// Different model or first run — create new context
154154
let mut ctx_params = WhisperContextParameters::default();
155155
ctx_params.flash_attn(true);
156-
ctx_params.use_gpu(true);
157156

158-
let ctx = match WhisperContext::new_with_params(&model_path, ctx_params) {
159-
Ok(ctx) => {
160-
println!("[Whisper] GPU context initialized");
161-
ctx
162-
}
163-
Err(gpu_err) => {
164-
println!("[Whisper] GPU init failed ({}), falling back to CPU", gpu_err);
165-
let mut cpu_params = WhisperContextParameters::default();
166-
cpu_params.flash_attn(true);
167-
cpu_params.use_gpu(false);
168-
WhisperContext::new_with_params(&model_path, cpu_params)?
157+
// Android: CPU-only (Vulkan GPU hangs freeze the entire device via compositor stall)
158+
// Desktop: try GPU first, fall back to CPU
159+
let use_gpu = !cfg!(target_os = "android");
160+
ctx_params.use_gpu(use_gpu);
161+
162+
let ctx = if use_gpu {
163+
match WhisperContext::new_with_params(&model_path, ctx_params) {
164+
Ok(ctx) => {
165+
println!("[Whisper] GPU context initialized");
166+
ctx
167+
}
168+
Err(gpu_err) => {
169+
println!("[Whisper] GPU init failed ({}), falling back to CPU", gpu_err);
170+
let mut cpu_params = WhisperContextParameters::default();
171+
cpu_params.flash_attn(true);
172+
cpu_params.use_gpu(false);
173+
WhisperContext::new_with_params(&model_path, cpu_params)?
174+
}
169175
}
176+
} else {
177+
println!("[Whisper] CPU context initialized (GPU disabled on this platform)");
178+
WhisperContext::new_with_params(&model_path, ctx_params)?
170179
};
171180

172181
*cache_guard = Some(CachedWhisperCtx {

0 commit comments

Comments
 (0)