use frameworks::native::NativeDevice;
use frameworks::opencl::OpenCLDevice;
use super::{Memory, Result, Shape};
pub trait Device:
'static
+ Alloc<u8> + Alloc<f32> + Alloc<f64>
+ Synch<u8> + Synch<f32> + Synch<f64>
+ Viewable {
}
impl<D> Device for D where D:
'static
+ Alloc<u8> + Alloc<f32> + Alloc<f64>
+ Synch<u8> + Synch<f32> + Synch<f64>
+ Viewable {
}
pub trait Viewable {
fn view(&self) -> ComputeDevice;
}
#[derive(Debug, Eq, PartialEq)]
pub enum ComputeDevice {
Native(NativeDevice),
OpenCL(OpenCLDevice),
}
impl ComputeDevice {
pub fn device(&self) -> &Device {
match *self {
ComputeDevice::Native(ref d) => d,
ComputeDevice::OpenCL(ref d) => d,
}
}
}
pub trait Alloc<T> {
fn alloc(&self, shape: &Shape) -> Result<Memory<T>>;
fn allocwrite(&self, shape: &Shape, data: Vec<T>) -> Result<Memory<T>>;
}
pub trait Synch<T> {
fn write(&self, memory: &mut Memory<T>, s_location: &ComputeDevice, s: &Memory<T>) -> Result;
fn read(&self, memory: &Memory<T>, d_location: &mut ComputeDevice, d: &mut Memory<T>) -> Result;
}
#[derive(Clone, Debug)]
pub struct Hardware {
pub id: usize,
pub framework: &'static str,
pub kind: HardwareKind,
pub name: String,
pub compute_units: usize,
}
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub enum HardwareKind {
Accelerator,
CPU,
GPU,
Other,
}