GPU-tunnistus valinnainen: cargo run --no-default-features toimii ilman nvml/wgpu
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) <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,10 @@ name = "native-node"
|
|||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["gpu-detect"]
|
||||||
|
gpu-detect = ["nvml-wrapper", "wgpu"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = { version = "1.36", features = ["full"] }
|
tokio = { version = "1.36", features = ["full"] }
|
||||||
tokio-tungstenite = { version = "0.21", features = ["native-tls"] }
|
tokio-tungstenite = { version = "0.21", features = ["native-tls"] }
|
||||||
@@ -10,8 +14,8 @@ futures-util = "0.3"
|
|||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
sysinfo = "0.30"
|
sysinfo = "0.30"
|
||||||
nvml-wrapper = "0.10"
|
nvml-wrapper = { version = "0.10", optional = true }
|
||||||
wgpu = "24"
|
wgpu = { version = "24", optional = true }
|
||||||
reqwest = { version = "0.12", features = ["json"] }
|
reqwest = { version = "0.12", features = ["json"] }
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ impl GpuInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gpu-detect")]
|
||||||
/// Tunnistaa kaikki GPU:t wgpu:lla (NVIDIA/AMD/Apple/Intel)
|
/// Tunnistaa kaikki GPU:t wgpu:lla (NVIDIA/AMD/Apple/Intel)
|
||||||
fn collect_gpus_wgpu() -> Vec<GpuInfo> {
|
fn collect_gpus_wgpu() -> Vec<GpuInfo> {
|
||||||
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
|
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
|
||||||
@@ -84,6 +85,7 @@ fn collect_gpus_wgpu() -> Vec<GpuInfo> {
|
|||||||
gpus
|
gpus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gpu-detect")]
|
||||||
/// Täydentää NVIDIA-GPU:iden tiedot NVML:llä (VRAM, lämpötila, kuormitus)
|
/// Täydentää NVIDIA-GPU:iden tiedot NVML:llä (VRAM, lämpötila, kuormitus)
|
||||||
fn enrich_nvidia_gpus(gpus: &mut [GpuInfo]) {
|
fn enrich_nvidia_gpus(gpus: &mut [GpuInfo]) {
|
||||||
let Ok(nvml) = nvml_wrapper::Nvml::init() else { return };
|
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/)
|
/// AMD GPU-tiedot Linuxin sysfs:stä (/sys/class/drm/)
|
||||||
fn enrich_amd_gpus(gpus: &mut [GpuInfo]) {
|
fn enrich_amd_gpus(gpus: &mut [GpuInfo]) {
|
||||||
let Ok(entries) = std::fs::read_dir("/sys/class/drm") else { return };
|
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<u64> {
|
fn read_sysfs_u64(path: &std::path::Path) -> Option<u64> {
|
||||||
std::fs::read_to_string(path).ok()?.trim().parse().ok()
|
std::fs::read_to_string(path).ok()?.trim().parse().ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gpu-detect")]
|
||||||
fn find_hwmon_temp(device_path: &std::path::Path) -> Option<u64> {
|
fn find_hwmon_temp(device_path: &std::path::Path) -> Option<u64> {
|
||||||
let hwmon_dir = device_path.join("hwmon");
|
let hwmon_dir = device_path.join("hwmon");
|
||||||
let entries = std::fs::read_dir(&hwmon_dir).ok()?;
|
let entries = std::fs::read_dir(&hwmon_dir).ok()?;
|
||||||
@@ -166,8 +171,8 @@ fn find_hwmon_temp(device_path: &std::path::Path) -> Option<u64> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gpu-detect")]
|
||||||
/// Apple GPU-tiedot — wgpu/Metal antaa nimen, tarkempaa dataa ei saa ilman IOKit:ia
|
/// 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]) {
|
fn enrich_apple_gpus(gpus: &mut [GpuInfo]) {
|
||||||
// Apple Silicon -koneiden unified memory: koko RAM on GPU:n käytettävissä
|
// Apple Silicon -koneiden unified memory: koko RAM on GPU:n käytettävissä
|
||||||
// Arvioidaan system RAM:sta
|
// Arvioidaan system RAM:sta
|
||||||
@@ -187,13 +192,18 @@ fn enrich_apple_gpus(gpus: &mut [GpuInfo]) {
|
|||||||
|
|
||||||
/// Kerää kaikki GPU:t ja täydentää valmistajakohtaiset tiedot
|
/// Kerää kaikki GPU:t ja täydentää valmistajakohtaiset tiedot
|
||||||
fn collect_all_gpus() -> Vec<GpuInfo> {
|
fn collect_all_gpus() -> Vec<GpuInfo> {
|
||||||
let mut gpus = collect_gpus_wgpu();
|
#[cfg(feature = "gpu-detect")]
|
||||||
|
{
|
||||||
enrich_nvidia_gpus(&mut gpus);
|
let mut gpus = collect_gpus_wgpu();
|
||||||
enrich_amd_gpus(&mut gpus);
|
enrich_nvidia_gpus(&mut gpus);
|
||||||
enrich_apple_gpus(&mut gpus);
|
enrich_amd_gpus(&mut gpus);
|
||||||
|
enrich_apple_gpus(&mut gpus);
|
||||||
gpus
|
return gpus;
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "gpu-detect"))]
|
||||||
|
{
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Kerää järjestelmätiedot (CPU, RAM, OS)
|
/// Kerää järjestelmätiedot (CPU, RAM, OS)
|
||||||
|
|||||||
Reference in New Issue
Block a user