From 84b78eb9c64a132370795af728d95d70af4ff37b Mon Sep 17 00:00:00 2001 From: Jaakko Vanhala Date: Thu, 9 Apr 2026 15:42:35 +0300 Subject: [PATCH] GPU-tunnistus valinnainen: cargo run --no-default-features toimii ilman nvml/wgpu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Native-node kääntyy nyt macOS:llä ja muilla koneilla ilman NVIDIA-ajureita: cargo run --no-default-features ← vain Ollama, ei GPU-tunnistusta cargo run ← oletus: GPU-tunnistus mukana (nvml + wgpu) Feature flag "gpu-detect" kontrolloi nvml-wrapper ja wgpu -riippuvuuksia. Co-Authored-By: Claude Opus 4.6 (1M context) --- network-poc/native-node/Cargo.toml | 8 ++++++-- network-poc/native-node/src/main.rs | 26 ++++++++++++++++++-------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/network-poc/native-node/Cargo.toml b/network-poc/native-node/Cargo.toml index ebdae1b..452a33f 100644 --- a/network-poc/native-node/Cargo.toml +++ b/network-poc/native-node/Cargo.toml @@ -3,6 +3,10 @@ name = "native-node" version = "0.2.2" edition = "2024" +[features] +default = ["gpu-detect"] +gpu-detect = ["nvml-wrapper", "wgpu"] + [dependencies] tokio = { version = "1.36", features = ["full"] } tokio-tungstenite = { version = "0.21", features = ["native-tls"] } @@ -10,8 +14,8 @@ futures-util = "0.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" sysinfo = "0.30" -nvml-wrapper = "0.10" -wgpu = "24" +nvml-wrapper = { version = "0.10", optional = true } +wgpu = { version = "24", optional = true } reqwest = { version = "0.12", features = ["json"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/network-poc/native-node/src/main.rs b/network-poc/native-node/src/main.rs index ffc7154..718b15b 100644 --- a/network-poc/native-node/src/main.rs +++ b/network-poc/native-node/src/main.rs @@ -33,6 +33,7 @@ impl GpuInfo { } } +#[cfg(feature = "gpu-detect")] /// Tunnistaa kaikki GPU:t wgpu:lla (NVIDIA/AMD/Apple/Intel) fn collect_gpus_wgpu() -> Vec { let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor { @@ -84,6 +85,7 @@ fn collect_gpus_wgpu() -> Vec { gpus } +#[cfg(feature = "gpu-detect")] /// Täydentää NVIDIA-GPU:iden tiedot NVML:llä (VRAM, lämpötila, kuormitus) fn enrich_nvidia_gpus(gpus: &mut [GpuInfo]) { let Ok(nvml) = nvml_wrapper::Nvml::init() else { return }; @@ -109,6 +111,7 @@ fn enrich_nvidia_gpus(gpus: &mut [GpuInfo]) { } } +#[cfg(feature = "gpu-detect")] /// AMD GPU-tiedot Linuxin sysfs:stä (/sys/class/drm/) fn enrich_amd_gpus(gpus: &mut [GpuInfo]) { let Ok(entries) = std::fs::read_dir("/sys/class/drm") else { return }; @@ -150,10 +153,12 @@ fn enrich_amd_gpus(gpus: &mut [GpuInfo]) { } } +#[cfg(feature = "gpu-detect")] fn read_sysfs_u64(path: &std::path::Path) -> Option { std::fs::read_to_string(path).ok()?.trim().parse().ok() } +#[cfg(feature = "gpu-detect")] fn find_hwmon_temp(device_path: &std::path::Path) -> Option { let hwmon_dir = device_path.join("hwmon"); let entries = std::fs::read_dir(&hwmon_dir).ok()?; @@ -166,8 +171,8 @@ fn find_hwmon_temp(device_path: &std::path::Path) -> Option { None } +#[cfg(feature = "gpu-detect")] /// Apple GPU-tiedot — wgpu/Metal antaa nimen, tarkempaa dataa ei saa ilman IOKit:ia -/// mutta Metal adapter_info sisältää jo olennaiset tiedot fn enrich_apple_gpus(gpus: &mut [GpuInfo]) { // Apple Silicon -koneiden unified memory: koko RAM on GPU:n käytettävissä // Arvioidaan system RAM:sta @@ -187,13 +192,18 @@ fn enrich_apple_gpus(gpus: &mut [GpuInfo]) { /// Kerää kaikki GPU:t ja täydentää valmistajakohtaiset tiedot fn collect_all_gpus() -> Vec { - let mut gpus = collect_gpus_wgpu(); - - enrich_nvidia_gpus(&mut gpus); - enrich_amd_gpus(&mut gpus); - enrich_apple_gpus(&mut gpus); - - gpus + #[cfg(feature = "gpu-detect")] + { + let mut gpus = collect_gpus_wgpu(); + enrich_nvidia_gpus(&mut gpus); + enrich_amd_gpus(&mut gpus); + enrich_apple_gpus(&mut gpus); + return gpus; + } + #[cfg(not(feature = "gpu-detect"))] + { + Vec::new() + } } /// Kerää järjestelmätiedot (CPU, RAM, OS)