lib3mf_core/utils/
hardware.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Default, Serialize, Deserialize)]
5pub struct HardwareCapabilities {
6 pub architecture: String,
8 pub num_cpus: usize,
10 pub simd_features: Vec<String>,
12}
13
14pub fn detect_capabilities() -> HardwareCapabilities {
16 #[allow(unused_mut)]
17 let mut features = Vec::new();
18
19 #[cfg(target_arch = "x86_64")]
20 {
21 if std::is_x86_feature_detected!("sse") {
22 features.push("sse".to_string());
23 }
24 if std::is_x86_feature_detected!("sse2") {
25 features.push("sse2".to_string());
26 }
27 if std::is_x86_feature_detected!("sse3") {
28 features.push("sse3".to_string());
29 }
30 if std::is_x86_feature_detected!("sse4.1") {
31 features.push("sse4.1".to_string());
32 }
33 if std::is_x86_feature_detected!("sse4.2") {
34 features.push("sse4.2".to_string());
35 }
36 if std::is_x86_feature_detected!("avx") {
37 features.push("avx".to_string());
38 }
39 if std::is_x86_feature_detected!("avx2") {
40 features.push("avx2".to_string());
41 }
42 }
43
44 #[cfg(target_arch = "aarch64")]
45 {
46 features.push("neon".to_string());
49 }
50
51 HardwareCapabilities {
52 architecture: std::env::consts::ARCH.to_string(),
53 #[cfg(feature = "parallel")]
54 num_cpus: rayon::current_num_threads(),
55 #[cfg(not(feature = "parallel"))]
56 num_cpus: 1,
57 simd_features: features,
58 }
59}