async_cuda_core/
error.rs

1use crate::ffi::error::error_description;
2
3/// An error that occurred during a CUDA operation.
4#[derive(Debug, Clone)]
5pub enum Error {
6    /// Error code as reported by the CUDA backend.
7    ///
8    /// [CUDA documentation](https://docs.nvidia.com/cuda/npp/group__typedefs__npp.html#ga1105a17b5e76381583c46ecd6a60fe21)
9    Cuda(i32),
10    /// The runtime backend unexpectedly broke down. This is usually irrecoverable because the
11    /// entire crate assumes that all backend execution will happen on the runtime thread.
12    Runtime,
13}
14
15impl std::fmt::Display for Error {
16    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
17        match self {
18            Error::Cuda(code) => {
19                let error_code = *code;
20                let error_description = error_description(error_code);
21                write!(
22                    f,
23                    "CUDA error ({}): {}",
24                    error_code,
25                    error_description.as_str(),
26                )
27            }
28            Error::Runtime => write!(f, "CUDA runtime broken"),
29        }
30    }
31}
32
33impl std::error::Error for Error {}