rstsr_core/device_faer/
device.rs1use crate::prelude_dev::*;
2use num::{complex::ComplexFloat, Num};
3use rstsr_dtype_traits::DTypeIntoFloatAPI;
4
5#[derive(Clone, Debug)]
6pub struct DeviceFaer {
7 base: DeviceCpuRayon,
8}
9
10pub(crate) use DeviceFaer as DeviceRayonAutoImpl;
11
12impl DeviceFaer {
13 pub fn new(num_threads: usize) -> Self {
14 DeviceFaer { base: DeviceCpuRayon::new(num_threads) }
15 }
16}
17
18impl DeviceRayonAPI for DeviceFaer {
19 #[inline]
20 fn set_num_threads(&mut self, num_threads: usize) {
21 self.base.set_num_threads(num_threads);
22 }
23
24 #[inline]
25 fn get_num_threads(&self) -> usize {
26 self.base.get_num_threads()
27 }
28
29 #[inline]
30 fn get_pool(&self) -> &ThreadPool {
31 self.base.get_pool()
32 }
33
34 #[inline]
35 fn get_current_pool(&self) -> Option<&ThreadPool> {
36 self.base.get_current_pool()
37 }
38}
39
40impl Default for DeviceFaer {
41 fn default() -> Self {
42 DeviceFaer::new(0)
43 }
44}
45
46impl DeviceBaseAPI for DeviceFaer {
47 fn same_device(&self, other: &Self) -> bool {
48 let same_num_threads = self.get_num_threads() == other.get_num_threads();
49 let same_default_order = self.default_order() == other.default_order();
50 same_num_threads && same_default_order
51 }
52
53 fn default_order(&self) -> FlagOrder {
54 self.base.default_order()
55 }
56
57 fn set_default_order(&mut self, order: FlagOrder) {
58 self.base.set_default_order(order);
59 }
60}
61
62impl<T> DeviceRawAPI<T> for DeviceFaer {
63 type Raw = Vec<T>;
64}
65
66impl<T> DeviceStorageAPI<T> for DeviceFaer {
67 fn len<R>(storage: &Storage<R, T, Self>) -> usize
68 where
69 R: DataAPI<Data = Self::Raw>,
70 {
71 storage.raw().len()
72 }
73
74 fn to_cpu_vec<R>(storage: &Storage<R, T, Self>) -> Result<Vec<T>>
75 where
76 Self::Raw: Clone,
77 R: DataAPI<Data = Self::Raw>,
78 {
79 Ok(storage.raw().clone())
80 }
81
82 fn into_cpu_vec<R>(storage: Storage<R, T, Self>) -> Result<Vec<T>>
83 where
84 Self::Raw: Clone,
85 R: DataCloneAPI<Data = Self::Raw>,
86 {
87 let (raw, _) = storage.into_raw_parts();
88 Ok(raw.into_owned().into_raw())
89 }
90
91 #[inline]
92 fn get_index<R>(storage: &Storage<R, T, Self>, index: usize) -> T
93 where
94 T: Clone,
95 R: DataAPI<Data = Self::Raw>,
96 {
97 storage.raw()[index].clone()
98 }
99
100 #[inline]
101 fn get_index_ptr<R>(storage: &Storage<R, T, Self>, index: usize) -> *const T
102 where
103 R: DataAPI<Data = Self::Raw>,
104 {
105 &storage.raw()[index] as *const T
106 }
107
108 #[inline]
109 fn get_index_mut_ptr<R>(storage: &mut Storage<R, T, Self>, index: usize) -> *mut T
110 where
111 R: DataMutAPI<Data = Self::Raw>,
112 {
113 storage.raw_mut().get_mut(index).unwrap() as *mut T
114 }
115
116 #[inline]
117 fn set_index<R>(storage: &mut Storage<R, T, Self>, index: usize, value: T)
118 where
119 R: DataMutAPI<Data = Self::Raw>,
120 {
121 storage.raw_mut()[index] = value;
122 }
123}
124
125impl<T> DeviceAPI<T> for DeviceFaer {}
126
127impl<T, D> DeviceComplexFloatAPI<T, D> for DeviceFaer
128where
129 T: ComplexFloat + DTypeIntoFloatAPI<FloatType = T> + Send + Sync,
130 T::Real: DTypeIntoFloatAPI<FloatType = T::Real> + Send + Sync,
131 D: DimAPI,
132{
133}
134
135impl<T, D> DeviceNumAPI<T, D> for DeviceFaer
136where
137 T: Clone + Num + Send + Sync,
138 D: DimAPI,
139{
140}