xtap_core_lib/
hardware.rs1use crate::error::Result;
7use rayon::prelude::*;
8
9pub struct HardwareMaster;
11
12impl HardwareMaster {
13 pub fn logical_cpus() -> usize {
15 num_cpus::get()
16 }
17
18 pub fn physical_cpus() -> usize {
20 num_cpus::get_physical()
21 }
22
23 pub fn init_global_pool(threads: Option<usize>) -> Result<()> {
26 let t = threads.unwrap_or_else(Self::logical_cpus);
27 rayon::ThreadPoolBuilder::new()
28 .num_threads(t)
29 .build_global()?;
30 Ok(())
31 }
32
33 pub fn parallel_process<T, R, F>(items: Vec<T>, f: F) -> Vec<R>
36 where
37 T: Send,
38 R: Send,
39 F: Fn(T) -> R + Sync + Send,
40 {
41 items.into_par_iter().map(f).collect()
42 }
43}
44
45#[cfg(feature = "gpu")]
47pub mod gpu {
48 use wgpu;
49
50 pub async fn check_gpu_status() {
51 let instance = wgpu::Instance::default();
52 let adapters = instance.enumerate_adapters(wgpu::Backends::all());
53 for adapter in adapters {
54 println!("检测到 GPU: {:?}", adapter.get_info().name);
55 }
56 }
57}