1use baracuda_cuda_sys::{driver, CUresult};
4
5pub type Error = baracuda_core::Error<CUresult>;
8
9pub type Result<T, E = Error> = core::result::Result<T, E>;
11
12#[inline]
14pub(crate) fn check(status: CUresult) -> Result<()> {
15 Error::check(status)
16}
17
18pub fn error_name(status: CUresult) -> Result<&'static str> {
21 let d = driver()?;
22 let cu = d.cu_get_error_name()?;
23 let mut p: *const core::ffi::c_char = core::ptr::null();
24 check(unsafe { cu(status, &mut p) })?;
25 if p.is_null() {
26 return Ok("CUDA_UNKNOWN_ERROR");
27 }
28 Ok(unsafe { core::ffi::CStr::from_ptr(p) }
29 .to_str()
30 .unwrap_or("CUDA_UNKNOWN_ERROR"))
31}
32
33pub fn error_string(status: CUresult) -> Result<&'static str> {
35 let d = driver()?;
36 let cu = d.cu_get_error_string()?;
37 let mut p: *const core::ffi::c_char = core::ptr::null();
38 check(unsafe { cu(status, &mut p) })?;
39 if p.is_null() {
40 return Ok("unknown error");
41 }
42 Ok(unsafe { core::ffi::CStr::from_ptr(p) }
43 .to_str()
44 .unwrap_or("unknown error"))
45}