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