lib3mf_core/utils/
hardware.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Default, Serialize, Deserialize)]
4pub struct HardwareCapabilities {
5    pub architecture: String,
6    pub num_cpus: usize,
7    pub simd_features: Vec<String>,
8}
9
10pub fn detect_capabilities() -> HardwareCapabilities {
11    #[allow(unused_mut)]
12    let mut features = Vec::new();
13
14    #[cfg(target_arch = "x86_64")]
15    {
16        if std::is_x86_feature_detected!("sse") {
17            features.push("sse".to_string());
18        }
19        if std::is_x86_feature_detected!("sse2") {
20            features.push("sse2".to_string());
21        }
22        if std::is_x86_feature_detected!("sse3") {
23            features.push("sse3".to_string());
24        }
25        if std::is_x86_feature_detected!("sse4.1") {
26            features.push("sse4.1".to_string());
27        }
28        if std::is_x86_feature_detected!("sse4.2") {
29            features.push("sse4.2".to_string());
30        }
31        if std::is_x86_feature_detected!("avx") {
32            features.push("avx".to_string());
33        }
34        if std::is_x86_feature_detected!("avx2") {
35            features.push("avx2".to_string());
36        }
37    }
38
39    #[cfg(target_arch = "aarch64")]
40    {
41        // On AArch64 neon is usually always present, but we can check specifically if needed
42        // using the cpufeatures crate or other methods.
43        features.push("neon".to_string());
44    }
45
46    HardwareCapabilities {
47        architecture: std::env::consts::ARCH.to_string(),
48        #[cfg(feature = "parallel")]
49        num_cpus: rayon::current_num_threads(),
50        #[cfg(not(feature = "parallel"))]
51        num_cpus: 1,
52        simd_features: features,
53    }
54}