fix: remove missing resource path from tauri.conf; add GPU detection and layer clamping

This commit is contained in:
Evandro Fonseca Junior committed 2026-03-26 21:22:08 -03:00
1 parent 99672b33d0
commit ae8d79e167
4 files changed
+230 -14

No files matched your search

+52 -1
View File
@@ -4,6 +4,57 @@ use tauri::{Manager, State};
pub struct ServerState(pub Mutex<Option<Child>>);
/// Query GPU info via nvidia-smi.
/// Returns (gpu_name, vram_mib, recommended_layers).
/// recommended_layers is estimated as vram_mib / 80 (rough heuristic for 4-bit quant).
#[tauri::command]
fn query_gpu() -> Result<GpuInfo, String> {
let output = Command::new("nvidia-smi")
.args([
"--query-gpu=name,memory.total",
"--format=csv,noheader,nounits",
])
.output()
.map_err(|_| "nvidia-smi not found — no NVIDIA GPU detected".to_string())?;
if !output.status.success() {
return Err("nvidia-smi failed — no NVIDIA GPU detected".into());
}
let stdout = String::from_utf8_lossy(&output.stdout);
let line = stdout.lines().next().unwrap_or("").trim().to_string();
if line.is_empty() {
return Err("No GPU found".into());
}
// Format: "GPU Name, 8192"
let parts: Vec<&str> = line.splitn(2, ',').collect();
if parts.len() < 2 {
return Err(format!("Unexpected nvidia-smi output: {line}"));
}
let name = parts[0].trim().to_string();
let vram_mib: u32 = parts[1].trim().parse().unwrap_or(0);
// Heuristic: ~80 MiB per layer for Q4/Q6 models (conservative)
// Reserve 1 GiB for OS/other usage
let usable = vram_mib.saturating_sub(1024);
let recommended_layers = (usable / 80).min(200) as i32;
Ok(GpuInfo {
name,
vram_mib,
recommended_layers,
})
}
#[derive(serde::Serialize)]
pub struct GpuInfo {
pub name: String,
pub vram_mib: u32,
pub recommended_layers: i32,
}
#[tauri::command]
fn start_server(
state: State<ServerState>,
@@ -17,7 +68,6 @@ fn start_server(
return Err("Server is already running".into());
}
// Resolve binary path relative to the app's resource dir or PATH
let binary = if cfg!(target_os = "windows") {
"localllm.exe"
} else {
@@ -70,6 +120,7 @@ pub fn run() {
.plugin(tauri_plugin_shell::init())
.manage(ServerState(Mutex::new(None)))
.invoke_handler(tauri::generate_handler![
query_gpu,
start_server,
stop_server,
server_status