coaster/frameworks/native/
mod.rs1pub use self::binary::Binary;
8pub use self::device::Cpu;
9pub use self::error::Error;
10pub use self::function::Function;
11use self::hardware::Hardware;
12#[cfg(not(feature = "unstable_alloc"))]
13pub use self::stable_alloc::allocate_boxed_slice;
14#[cfg(feature = "unstable_alloc")]
15pub use self::unstable_alloc::allocate_boxed_slice;
16use crate::backend::{Backend, IBackend};
17use crate::framework::IFramework;
18use crate::hardware::{HardwareType, IHardware};
19
20pub mod binary;
21pub mod device;
22mod error;
23pub mod flatbox;
24pub mod function;
25pub mod hardware;
26#[cfg(not(feature = "unstable_alloc"))]
27mod stable_alloc;
28#[cfg(feature = "unstable_alloc")]
29mod unstable_alloc;
30
31pub fn get_native_backend() -> Backend<Native> {
33 Backend::<Native>::default().unwrap()
34}
35
36#[derive(Debug, Clone)]
37pub struct Native {
41 hardwares: Vec<Hardware>,
42 binary: Binary,
43}
44
45pub trait INative {}
49
50impl INative for Native {}
51
52impl IFramework for Native {
53 type H = Hardware;
54 type D = Cpu;
55 type B = Binary;
56
57 fn ID() -> &'static str {
58 "NATIVE"
59 }
60
61 fn new() -> Native {
62 let hardwares = Native::load_hardwares().expect("Native hardwares are always ok. qed");
63 Self {
64 hardwares,
65 binary: Binary::new(),
66 }
67 }
68
69 fn load_hardwares() -> Result<Vec<Hardware>, crate::framework::Error> {
70 let cpu = Hardware::new(1)
71 .set_name(Some(String::from("Host CPU")))
72 .set_hardware_type(Some(HardwareType::CPU))
73 .set_compute_units(Some(1))
74 .build();
75 Ok(vec![cpu])
76 }
77
78 fn hardwares(&self) -> &[Hardware] {
79 &self.hardwares
80 }
81
82 fn binary(&self) -> &Binary {
83 &self.binary
84 }
85
86 fn new_device(&self, devices: &[Hardware]) -> Result<Self::D, crate::framework::Error> {
87 Ok(Cpu::new(devices.to_vec()))
88 }
89}
90
91impl IBackend for Backend<Native> {
92 type F = Native;
93
94 fn device(&self) -> &Cpu {
95 &self.device()
96 }
97}