use baracuda_cuda_sys::{driver, CUresult};
pub type Error = baracuda_core::Error<CUresult>;
pub type Result<T, E = Error> = core::result::Result<T, E>;
#[inline]
pub(crate) fn check(status: CUresult) -> Result<()> {
Error::check(status)
}
pub fn error_name(status: CUresult) -> Result<&'static str> {
let d = driver()?;
let cu = d.cu_get_error_name()?;
let mut p: *const core::ffi::c_char = core::ptr::null();
check(unsafe { cu(status, &mut p) })?;
if p.is_null() {
return Ok("CUDA_UNKNOWN_ERROR");
}
Ok(unsafe { core::ffi::CStr::from_ptr(p) }
.to_str()
.unwrap_or("CUDA_UNKNOWN_ERROR"))
}
pub fn error_string(status: CUresult) -> Result<&'static str> {
let d = driver()?;
let cu = d.cu_get_error_string()?;
let mut p: *const core::ffi::c_char = core::ptr::null();
check(unsafe { cu(status, &mut p) })?;
if p.is_null() {
return Ok("unknown error");
}
Ok(unsafe { core::ffi::CStr::from_ptr(p) }
.to_str()
.unwrap_or("unknown error"))
}