hpt_common/error/
kernel.rs

1use std::panic::Location;
2
3use thiserror::Error;
4
5/// Errors that can occur during kernel operations (compilation, execution)
6#[derive(Debug, Error)]
7pub enum KernelError {
8    /// Error that occurs when kernel compilation fails
9    #[error("Kernel compilation failed: {message} at {location}")]
10    CompilationFailed {
11        /// Message describing the compilation failure
12        message: String,
13        /// Location where the error occurred
14        location: &'static Location<'static>,
15    },
16
17    /// Error that occurs when kernel execution fails
18    #[error("Kernel execution failed: {message} at {location}")]
19    ExecutionFailed {
20        /// Message describing the execution failure
21        message: String,
22        /// Location where the error occurred
23        location: &'static Location<'static>,
24    },
25
26    /// Error that occurs when CUDA kernel region info is not found
27    #[error("CUDA kernel region info not found for module: {module}, func_name: {func_name}")]
28    CudaKernelRegInfoNotFound {
29        /// Module name
30        module: String,
31        /// Function name
32        func_name: String,
33        /// Location where the error occurred
34        location: &'static Location<'static>,
35    },
36
37    /// Error that occurs when CUDA kernel meta data is not found
38    #[error(
39        "CUDA kernel meta data not found for module: {module}, func_name: {func_name}, cap: {cap}"
40    )]
41    CudaKernelMetaNotFound {
42        /// cap
43        cap: usize,
44        /// Module name
45        module: String,
46        /// Function name
47        func_name: String,
48        /// Location where the error occurred
49        location: &'static Location<'static>,
50    },
51
52    /// Error that occurs when CUDA kernel launch config is too large
53    #[error("CUDA kernel launch config error: {msg}")]
54    LaunchConfigError {
55        /// Message
56        msg: String,
57        /// Location where the error occurred
58        location: &'static Location<'static>,
59    },
60}
61
62#[cfg(feature = "cuda")]
63mod impls {
64    use crate::error::base::TensorError;
65    use crate::error::kernel::KernelError;
66    use std::panic::Location;
67    impl From<cudarc::nvrtc::CompileError> for TensorError {
68        fn from(source: cudarc::nvrtc::CompileError) -> Self {
69            Self::Kernel(KernelError::CompilationFailed {
70                message: source.to_string(),
71                location: Location::caller(),
72            })
73        }
74    }
75}