candle_core/
dummy_cuda_backend.rs

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