From 304a557d8482c63265a0a28a917aefd5635aa88e Mon Sep 17 00:00:00 2001 From: laurent Date: Wed, 21 Jun 2023 21:16:00 +0100 Subject: [PATCH] Add a dummy module. --- Cargo.toml | 2 +- src/cuda_backend.rs | 2 +- src/dummy_cuda_backend.rs | 46 +++++++++++++++++++++++++++++++++++++++ src/error.rs | 2 +- src/lib.rs | 9 +++++++- 5 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 src/dummy_cuda_backend.rs diff --git a/Cargo.toml b/Cargo.toml index 5e2508b3..44d64f1a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,5 +22,5 @@ rand = "0.8.5" tokenizers = "0.13.3" [features] -default = ["cuda"] +default = [] cuda = ["dep:cudarc"] diff --git a/src/cuda_backend.rs b/src/cuda_backend.rs index 06730251..8c7f23b3 100644 --- a/src/cuda_backend.rs +++ b/src/cuda_backend.rs @@ -1,7 +1,7 @@ use crate::{CpuStorage, DType, Result, Shape}; use cudarc::driver::{CudaSlice, LaunchAsync, LaunchConfig}; -pub(crate) type Error = cudarc::driver::DriverError; +pub type CudaError = cudarc::driver::DriverError; #[derive(Debug, Clone)] pub struct CudaDevice(std::sync::Arc); diff --git a/src/dummy_cuda_backend.rs b/src/dummy_cuda_backend.rs new file mode 100644 index 00000000..8dd53b1a --- /dev/null +++ b/src/dummy_cuda_backend.rs @@ -0,0 +1,46 @@ +#![allow(dead_code)] +use crate::{CpuStorage, DType, Result, Shape}; + +pub type CudaError = std::io::Error; + +#[derive(Debug, Clone)] +pub struct CudaDevice; + +impl CudaDevice { + pub(crate) fn new(_: usize) -> Result { + unimplemented!("cuda support hasn't been enabled") + } + + pub(crate) fn ordinal(&self) -> usize { + unimplemented!("cuda support hasn't been enabled") + } + + pub(crate) fn zeros_impl(&self, _shape: &Shape, _dtype: DType) -> Result { + unimplemented!("cuda support hasn't been enabled") + } + + pub(crate) fn cuda_from_cpu_storage(&self, _: &CpuStorage) -> Result { + unimplemented!("cuda support hasn't been enabled") + } +} + +#[derive(Debug, Clone)] +pub struct CudaStorage; + +impl CudaStorage { + pub fn dtype(&self) -> DType { + unimplemented!() + } + + pub fn device(&self) -> CudaDevice { + unimplemented!() + } + + pub(crate) fn to_cpu_storage(&self) -> Result { + unimplemented!() + } + + pub(crate) fn affine_impl(&self, _: &Shape, _: &[usize], _: f64, _: f64) -> Result { + unimplemented!() + } +} diff --git a/src/error.rs b/src/error.rs index 94f5e50d..3f142960 100644 --- a/src/error.rs +++ b/src/error.rs @@ -35,7 +35,7 @@ pub enum Error { }, #[error(transparent)] - Cudarc(#[from] crate::cuda_backend::Error), + Cuda(#[from] crate::CudaError), } pub type Result = std::result::Result; diff --git a/src/lib.rs b/src/lib.rs index f09daa90..3bae1a7e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,9 @@ mod cpu_backend; +#[cfg(feature = "cuda")] mod cuda_backend; mod device; mod dtype; +mod dummy_cuda_backend; mod error; mod op; mod shape; @@ -10,7 +12,6 @@ mod strided_index; mod tensor; pub use cpu_backend::CpuStorage; -pub use cuda_backend::{CudaDevice, CudaStorage}; pub use device::{Device, DeviceLocation}; pub use dtype::{DType, WithDType}; pub use error::{Error, Result}; @@ -18,3 +19,9 @@ pub use shape::Shape; pub use storage::Storage; use strided_index::StridedIndex; pub use tensor::{Tensor, TensorId}; + +#[cfg(feature = "cuda")] +pub use cuda_backend::{CudaDevice, CudaError, CudaStorage}; + +#[cfg(not(feature = "cuda"))] +pub use dummy_cuda_backend::{CudaDevice, CudaError, CudaStorage};