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
use {BoxContext, Context, Error, ExtensionPackage, Framework, Hardware, HardwareKind, Result};
use std::marker::{PhantomData, Unsize};
use super::NativeContext;
use utility::TryDefault;

const NATIVE: &'static str = "Native";

/// The native framework
///
/// # Example
///
/// ```rust
/// use parenchyma::{Backend, Native, SharedTensor};
///
/// let ref host: Backend = Backend::new::<Native>().unwrap();
///
/// let sh: SharedTensor = SharedTensor::with(host, [2, 2], vec![1., 2., 3., 4.]).unwrap();
///
/// let tensor = sh.read(host).unwrap();
///
/// println!("{:#?}", tensor);
/// ```
#[derive(Debug)]
pub struct Native;

impl Framework for Native {

    const FRAMEWORK_NAME: &'static str = NATIVE;

    fn available_hardware(&self) -> Vec<Hardware> {
        vec![Hardware {
            id: 0,
            framework: NATIVE,
            kind: HardwareKind::Central,
            name: String::from("HOST CPU"),
            compute_units: 1,
        }]
    }
}

impl<X> BoxContext<X> for Native 
    where X: ExtensionPackage, 
          NativeContext<X>: Unsize<X::Extension> 
          {

    fn enclose(&self, _: Vec<Hardware>) -> Result<Box<Context<Package = X>>> {
        Ok(Box::new(NativeContext(PhantomData)))
    }
}

impl TryDefault for Native {
    type Err = Error;

    fn try_default() -> Result<Native> {
        Ok(Native)
    }
}