Skip to main content

oxicuda_ptx/
error.rs

1//! Error types for PTX code generation.
2//!
3//! Provides the [`PtxGenError`] enum which covers all failure modes
4//! encountered during PTX kernel construction and text emission.
5
6/// Errors that can occur during PTX code generation.
7///
8/// This enum covers validation failures during kernel building, register
9/// allocation issues, missing required fields, and I/O or formatting errors
10/// encountered while emitting PTX text.
11#[derive(Debug, thiserror::Error)]
12pub enum PtxGenError {
13    /// General PTX generation failure with a descriptive message.
14    #[error("PTX generation failed: {0}")]
15    GenerationFailed(String),
16
17    /// An invalid or unsupported PTX type was encountered.
18    #[error("invalid PTX type: {0}")]
19    InvalidType(String),
20
21    /// A register allocation error (e.g. exceeding limits).
22    #[error("register allocation failed: {0}")]
23    RegisterError(String),
24
25    /// The kernel builder was finalized without a body function.
26    #[error("missing body function")]
27    MissingBody,
28
29    /// A `std::fmt::Write` formatting error during PTX text emission.
30    #[error("format error: {0}")]
31    FormatError(#[from] std::fmt::Error),
32
33    /// An I/O error during PTX text emission or file writing.
34    #[error("I/O error: {0}")]
35    IoError(#[from] std::io::Error),
36
37    /// A required kernel parameter was referenced but not declared.
38    #[error("unknown parameter: {0}")]
39    UnknownParam(String),
40
41    /// The target architecture does not support the requested feature.
42    #[error("unsupported on {arch}: {feature}")]
43    UnsupportedFeature {
44        /// The target architecture name.
45        arch: String,
46        /// The feature that is not supported.
47        feature: String,
48    },
49}