1#![allow(dead_code)]
4use crate::op::{BinaryOpT, CmpOp, ReduceOp, UnaryOpT};
5use crate::{CpuStorage, DType, Error, Layout, Result, Shape};
6
7#[derive(Debug, Clone)]
8pub struct CudaDevice;
9
10#[derive(Debug)]
11pub struct CudaStorage;
12
13impl CudaStorage {
14 pub fn transfer_to_device(&self, _dst: &CudaDevice) -> Result<Self> {
15 Err(Error::NotCompiledWithCudaSupport)
16 }
17}
18
19macro_rules! fail {
20 () => {
21 unimplemented!("cuda support has not been enabled, add `cuda` feature to enable.")
22 };
23}
24#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
25pub struct DeviceId(usize);
26
27impl CudaDevice {
28 pub fn new_with_stream(_: usize) -> Result<Self> {
29 Err(Error::NotCompiledWithCudaSupport)
30 }
31 pub fn id(&self) -> DeviceId {
32 DeviceId(0)
33 }
34}
35
36impl crate::backend::BackendStorage for CudaStorage {
37 type Device = CudaDevice;
38
39 fn try_clone(&self, _: &Layout) -> Result<Self> {
40 Err(Error::NotCompiledWithCudaSupport)
41 }
42
43 fn dtype(&self) -> DType {
44 fail!()
45 }
46
47 fn device(&self) -> &Self::Device {
48 fail!()
49 }
50
51 fn const_set(&mut self, _: crate::scalar::Scalar, _: &Layout) -> Result<()> {
52 Err(Error::NotCompiledWithCudaSupport)
53 }
54
55 fn to_cpu_storage(&self) -> Result<CpuStorage> {
56 Err(Error::NotCompiledWithCudaSupport)
57 }
58
59 fn affine(&self, _: &Layout, _: f64, _: f64) -> Result<Self> {
60 Err(Error::NotCompiledWithCudaSupport)
61 }
62
63 fn powf(&self, _: &Layout, _: f64) -> Result<Self> {
64 Err(Error::NotCompiledWithCudaSupport)
65 }
66
67 fn elu(&self, _: &Layout, _: f64) -> Result<Self> {
68 Err(Error::NotCompiledWithCudaSupport)
69 }
70
71 fn reduce_op(&self, _: ReduceOp, _: &Layout, _: &[usize]) -> Result<Self> {
72 Err(Error::NotCompiledWithCudaSupport)
73 }
74
75 fn cmp(&self, _: CmpOp, _: &Self, _: &Layout, _: &Layout) -> Result<Self> {
76 Err(Error::NotCompiledWithCudaSupport)
77 }
78
79 fn to_dtype(&self, _: &Layout, _: DType) -> Result<Self> {
80 Err(Error::NotCompiledWithCudaSupport)
81 }
82
83 fn unary_impl<B: UnaryOpT>(&self, _: &Layout) -> Result<Self> {
84 Err(Error::NotCompiledWithCudaSupport)
85 }
86
87 fn binary_impl<B: BinaryOpT>(&self, _: &Self, _: &Layout, _: &Layout) -> Result<Self> {
88 Err(Error::NotCompiledWithCudaSupport)
89 }
90
91 fn where_cond(&self, _: &Layout, _: &Self, _: &Layout, _: &Self, _: &Layout) -> Result<Self> {
92 Err(Error::NotCompiledWithCudaSupport)
93 }
94
95 fn conv1d(
96 &self,
97 _: &Layout,
98 _: &Self,
99 _: &Layout,
100 _: &crate::conv::ParamsConv1D,
101 ) -> Result<Self> {
102 Err(Error::NotCompiledWithCudaSupport)
103 }
104
105 fn conv_transpose1d(
106 &self,
107 _: &Layout,
108 _: &Self,
109 _: &Layout,
110 _: &crate::conv::ParamsConvTranspose1D,
111 ) -> Result<Self> {
112 Err(Error::NotCompiledWithCudaSupport)
113 }
114
115 fn conv2d(
116 &self,
117 _: &Layout,
118 _: &Self,
119 _: &Layout,
120 _: &crate::conv::ParamsConv2D,
121 ) -> Result<Self> {
122 Err(Error::NotCompiledWithCudaSupport)
123 }
124
125 fn conv_transpose2d(
126 &self,
127 _l: &Layout,
128 _kernel: &Self,
129 _kernel_l: &Layout,
130 _params: &crate::conv::ParamsConvTranspose2D,
131 ) -> Result<Self> {
132 Err(Error::NotCompiledWithCudaSupport)
133 }
134
135 fn index_select(&self, _: &Self, _: &Layout, _: &Layout, _: usize) -> Result<Self> {
136 Err(Error::NotCompiledWithCudaSupport)
137 }
138 fn gather(&self, _: &Layout, _: &Self, _: &Layout, _: usize) -> Result<Self> {
139 Err(Error::NotCompiledWithCudaSupport)
140 }
141
142 fn scatter_set(
143 &mut self,
144 _: &Layout,
145 _: &Self,
146 _: &Layout,
147 _: &Self,
148 _: &Layout,
149 _: usize,
150 ) -> Result<()> {
151 Err(Error::NotCompiledWithCudaSupport)
152 }
153
154 fn scatter_add_set(
155 &mut self,
156 _: &Layout,
157 _: &Self,
158 _: &Layout,
159 _: &Self,
160 _: &Layout,
161 _: usize,
162 ) -> Result<()> {
163 Err(Error::NotCompiledWithCudaSupport)
164 }
165
166 fn index_add(
167 &self,
168 _: &Layout,
169 _: &Self,
170 _: &Layout,
171 _: &Self,
172 _: &Layout,
173 _: usize,
174 ) -> Result<Self> {
175 Err(Error::NotCompiledWithCudaSupport)
176 }
177
178 fn matmul(
179 &self,
180 _: &Self,
181 _: (usize, usize, usize, usize),
182 _: &Layout,
183 _: &Layout,
184 ) -> Result<Self> {
185 Err(Error::NotCompiledWithCudaSupport)
186 }
187
188 fn copy_strided_src(&self, _: &mut Self, _: usize, _: &Layout) -> Result<()> {
189 Err(Error::NotCompiledWithCudaSupport)
190 }
191
192 fn copy2d(
193 &self,
194 _: &mut Self,
195 _: usize,
196 _: usize,
197 _: usize,
198 _: usize,
199 _: usize,
200 _: usize,
201 ) -> Result<()> {
202 Err(Error::NotCompiledWithCudaSupport)
203 }
204
205 fn avg_pool2d(&self, _: &Layout, _: (usize, usize), _: (usize, usize)) -> Result<Self> {
206 Err(Error::NotCompiledWithCudaSupport)
207 }
208
209 fn max_pool2d(&self, _: &Layout, _: (usize, usize), _: (usize, usize)) -> Result<Self> {
210 Err(Error::NotCompiledWithCudaSupport)
211 }
212
213 fn upsample_nearest1d(&self, _: &Layout, _: usize) -> Result<Self> {
214 Err(Error::NotCompiledWithCudaSupport)
215 }
216
217 fn upsample_nearest2d(&self, _: &Layout, _: usize, _: usize) -> Result<Self> {
218 Err(Error::NotCompiledWithCudaSupport)
219 }
220
221 fn upsample_bilinear2d(
222 &self,
223 _: &Layout,
224 _: usize,
225 _: usize,
226 _: bool,
227 _: Option<f64>,
228 _: Option<f64>,
229 ) -> Result<Self> {
230 Err(Error::NotCompiledWithCudaSupport)
231 }
232}
233
234impl crate::backend::BackendDevice for CudaDevice {
235 type Storage = CudaStorage;
236 fn new(_: usize) -> Result<Self> {
237 Err(Error::NotCompiledWithCudaSupport)
238 }
239
240 fn set_seed(&self, _: u64) -> Result<()> {
241 Err(Error::NotCompiledWithCudaSupport)
242 }
243
244 fn get_current_seed(&self) -> Result<u64> {
245 Err(Error::NotCompiledWithCudaSupport)
246 }
247
248 fn location(&self) -> crate::DeviceLocation {
249 fail!()
250 }
251
252 fn same_device(&self, _: &Self) -> bool {
253 fail!()
254 }
255
256 fn zeros_impl(&self, _shape: &Shape, _dtype: DType) -> Result<Self::Storage> {
257 Err(Error::NotCompiledWithCudaSupport)
258 }
259
260 unsafe fn alloc_uninit(&self, _shape: &Shape, _dtype: DType) -> Result<Self::Storage> {
261 Err(Error::NotCompiledWithCudaSupport)
262 }
263
264 fn storage_from_slice<T: crate::WithDType>(&self, _: &[T]) -> Result<Self::Storage> {
265 Err(Error::NotCompiledWithCudaSupport)
266 }
267
268 fn storage_from_cpu_storage(&self, _: &CpuStorage) -> Result<Self::Storage> {
269 Err(Error::NotCompiledWithCudaSupport)
270 }
271
272 fn storage_from_cpu_storage_owned(&self, _: CpuStorage) -> Result<Self::Storage> {
273 Err(Error::NotCompiledWithCudaSupport)
274 }
275
276 fn rand_uniform(&self, _: &Shape, _: DType, _: f64, _: f64) -> Result<Self::Storage> {
277 Err(Error::NotCompiledWithCudaSupport)
278 }
279
280 fn rand_normal(&self, _: &Shape, _: DType, _: f64, _: f64) -> Result<Self::Storage> {
281 Err(Error::NotCompiledWithCudaSupport)
282 }
283
284 fn synchronize(&self) -> Result<()> {
285 Ok(())
286 }
287}
288
289pub fn gemm_reduced_precision_f16() -> bool {
292 true
293}
294
295pub fn set_gemm_reduced_precision_f16(_: bool) {}
298
299pub fn gemm_reduced_precision_bf16() -> bool {
302 true
303}
304
305pub fn set_gemm_reduced_precision_bf16(_: bool) {}
308
309pub fn gemm_reduced_precision_f32() -> bool {
312 true
313}
314
315pub fn set_gemm_reduced_precision_f32(_b: bool) {}