1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
/// An error that occurred in TensorRT.
#[derive(Debug, Clone)]
pub enum Error {
/// TensorRT error described by error message.
TensorRt { message: String },
/// Error in CUDA backend.
Cuda(async_cuda::Error),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Error::TensorRt { message } => write!(f, "{message}"),
Error::Cuda(err) => write!(f, "{err}"),
}
}
}
impl std::error::Error for Error {}
impl From<async_cuda::Error> for Error {
#[inline]
fn from(err: async_cuda::Error) -> Self {
Error::Cuda(err)
}
}
/// Create a TensorRT error from the last recorded error produced by the logger.
///
/// # Thread-safety
///
/// This function might return an error that was produced by an invocation to some TensorRT function
/// in a different thread.
///
/// # Return value
///
/// TensorRT error with corresponding error message.
#[inline]
pub(crate) fn last_error() -> Error {
Error::TensorRt {
message: crate::ffi::error::get_last_error_message(),
}
}