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
#![allow(non_camel_case_types)] pub use ffi::cuda::cudaError_t as cudaError; pub use ffi::cuda_runtime::cudaError_t as cudaRuntimeError; pub use ffi::cublas::cublasStatus_t as cublasError; pub type Result<T> = ::std::result::Result<T, Error>; #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, IntoEnum)] pub enum Error { cudaError(cudaError), cudaRuntimeError(cudaRuntimeError), cublasError(cublasError), } pub trait Check { fn check(self) -> Result<()>; } impl Check for cudaError { fn check(self) -> Result<()> { if self == cudaError::CUDA_SUCCESS { Ok(()) } else { Err(self.into()) } } } impl Check for cudaRuntimeError { fn check(self) -> Result<()> { if self == cudaRuntimeError::Success { Ok(()) } else { Err(self.into()) } } } impl Check for cublasError { fn check(self) -> Result<()> { if self == cublasError::SUCCESS { Ok(()) } else { Err(self.into()) } } }