Skip to content

Commit

Permalink
feat/cudnn: add cudnn ffi
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHirn authored and hobofan committed Dec 4, 2015
1 parent 13cd090 commit 0bbbff8
Show file tree
Hide file tree
Showing 22 changed files with 1,029 additions and 2,740 deletions.
77 changes: 77 additions & 0 deletions src/frameworks/cuda/api/dnn/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//! Provides Rust Errors for CUDA's cuDNN status.

use std::{fmt, error};

#[derive(Debug, Copy, Clone)]
/// Defines CUDA's cuDNN errors.
pub enum Error {
/// Failure with CUDA cuDNN initialization.
NotInitialized(&'static str),
/// Failure with allocation.
AllocFailed(&'static str),
/// Failure with a provided parameter.
BadParam(&'static str),
/// Failure with cuDNN.
InternalError(&'static str),
/// Failure with provided value.
InvalidValue(&'static str),
/// Failure with the hardware architecture.
ArchMismatch(&'static str),
/// Failure with memory access or internal error/bug.
MappingError(&'static str),
/// Failure with Kernel execution.
ExecutionFailed(&'static str),
/// Failure with an unsupported request.
NotSupported(&'static str),
/// Failure Cuda License.
LicenseError(&'static str),
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::NotInitialized(ref err) => write!(f, "{:?}", err),
Error::AllocFailed(ref err) => write!(f, "{:?}", err),
Error::BadParam(ref err) => write!(f, "{:?}", err),
Error::InternalError(ref err) => write!(f, "{:?}", err),
Error::InvalidValue(ref err) => write!(f, "{:?}", err),
Error::ArchMismatch(ref err) => write!(f, "{:?}", err),
Error::MappingError(ref err) => write!(f, "{:?}", err),
Error::ExecutionFailed(ref err) => write!(f, "{:?}", err),
Error::NotSupported(ref err) => write!(f, "{:?}", err),
Error::LicenseError(ref err) => write!(f, "{:?}", err),
}
}
}

impl error::Error for Error {
fn description(&self) -> &str {
match *self {
Error::NotInitialized(ref err) => err,
Error::AllocFailed(ref err) => err,
Error::BadParam(ref err) => err,
Error::InternalError(ref err) => err,
Error::InvalidValue(ref err) => err,
Error::ArchMismatch(ref err) => err,
Error::MappingError(ref err) => err,
Error::ExecutionFailed(ref err) => err,
Error::NotSupported(ref err) => err,
Error::LicenseError(ref err) => err,
}
}

fn cause(&self) -> Option<&error::Error> {
match *self {
Error::NotInitialized(_) => None,
Error::AllocFailed(_) => None,
Error::BadParam(_) => None,
Error::InternalError(_) => None,
Error::InvalidValue(_) => None,
Error::ArchMismatch(_) => None,
Error::MappingError(_) => None,
Error::ExecutionFailed(_) => None,
Error::NotSupported(_) => None,
Error::LicenseError(_) => None,
}
}
}
Loading

0 comments on commit 0bbbff8

Please sign in to comment.