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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#[cfg(feature = "native")]
use frameworks::native::flatbox::FlatBox;
#[cfg(feature = "opencl")]
use frameworks::opencl::memory::Memory as OpenCLMemory;
#[cfg(feature = "cuda")]
use frameworks::cuda::memory::Memory as CudaMemory;
pub trait IMemory { }
#[derive(Debug)]
pub enum MemoryType {
#[cfg(feature = "native")]
Native(FlatBox),
#[cfg(feature = "opencl")]
OpenCL(OpenCLMemory),
#[cfg(feature = "cuda")]
Cuda(CudaMemory),
}
impl MemoryType {
#[cfg(feature = "native")]
pub fn as_native(&self) -> Option<&FlatBox> {
match *self {
MemoryType::Native(ref ret) => Some(ret),
#[cfg(any(feature = "cuda", feature = "opencl"))]
_ => None,
}
}
#[cfg(feature = "native")]
pub fn as_mut_native(&mut self) -> Option<&mut FlatBox> {
match *self {
MemoryType::Native(ref mut ret) => Some(ret),
#[cfg(any(feature = "cuda", feature = "opencl"))]
_ => None,
}
}
#[cfg(feature = "native")]
pub fn into_native(self) -> Option<FlatBox> {
match self {
MemoryType::Native(ret) => Some(ret),
#[cfg(any(feature = "cuda", feature = "opencl"))]
_ => None,
}
}
#[cfg(feature = "opencl")]
pub fn as_opencl(&self) -> Option<&OpenCLMemory> {
match *self {
MemoryType::OpenCL(ref ret) => Some(ret),
#[cfg(any(feature = "cuda", feature = "native"))]
_ => None,
}
}
#[cfg(feature = "opencl")]
pub fn as_mut_opencl(&mut self) -> Option<&mut OpenCLMemory> {
match *self {
MemoryType::OpenCL(ref mut ret) => Some(ret),
#[cfg(any(feature = "cuda", feature = "native"))]
_ => None,
}
}
#[cfg(feature = "opencl")]
pub fn into_opencl(self) -> Option<OpenCLMemory> {
match self {
MemoryType::OpenCL(ret) => Some(ret),
#[cfg(any(feature = "cuda", feature = "native"))]
_ => None,
}
}
#[cfg(feature = "cuda")]
pub fn as_cuda(&self) -> Option<&CudaMemory> {
match *self {
MemoryType::Cuda(ref ret) => Some(ret),
#[cfg(any(feature = "opencl", feature = "native"))]
_ => None,
}
}
#[cfg(feature = "cuda")]
pub fn as_mut_cuda(&mut self) -> Option<&mut CudaMemory> {
match *self {
MemoryType::Cuda(ref mut ret) => Some(ret),
#[cfg(any(feature = "opencl", feature = "native"))]
_ => None,
}
}
#[cfg(feature = "cuda")]
pub fn into_cuda(self) -> Option<CudaMemory> {
match self {
MemoryType::Cuda(ret) => Some(ret),
#[cfg(any(feature = "opencl", feature = "native"))]
_ => None,
}
}
}