use ::{API, Error};
use ffi::*;
use std::ptr;
impl API {
pub fn init() -> Result<cudnnHandle_t, Error> {
Ok(try!( unsafe { API::ffi_create() }))
}
pub fn destroy(handle: cudnnHandle_t) -> Result<(), Error> {
unsafe { API::ffi_destroy(handle) }
}
pub fn get_version() -> usize {
unsafe { API::ffi_get_version() }
}
unsafe fn ffi_get_version() -> ::libc::size_t {
cudnnGetVersion()
}
unsafe fn ffi_create() -> Result<cudnnHandle_t, Error> {
let mut handle: cudnnHandle_t = ptr::null_mut();
match cudnnCreate(&mut handle) {
cudnnStatus_t::CUDNN_STATUS_SUCCESS => Ok(handle),
cudnnStatus_t::CUDNN_STATUS_NOT_INITIALIZED => Err(Error::NotInitialized("CUDA Driver/Runtime API not initialized.")),
cudnnStatus_t::CUDNN_STATUS_ARCH_MISMATCH => Err(Error::ArchMismatch("cuDNN only supports devices with compute capabilities greater than or equal to 3.0.")),
cudnnStatus_t::CUDNN_STATUS_ALLOC_FAILED => Err(Error::AllocFailed("The resources could not be allocated.")),
_ => Err(Error::Unknown("Unable to create the CUDA cuDNN context/resources."))
}
}
unsafe fn ffi_destroy(handle: cudnnHandle_t) -> Result<(), Error> {
match cudnnDestroy(handle) {
cudnnStatus_t::CUDNN_STATUS_SUCCESS => Ok(()),
cudnnStatus_t::CUDNN_STATUS_NOT_INITIALIZED => Err(Error::NotInitialized("CUDA Driver/Runtime API not initialized.")),
_ => Err(Error::Unknown("Unable to destroy the CUDA cuDNN context/resources.")),
}
}
}