Skip to main content

baracuda_cuda_sys/runtime/
status.rs

1//! `cudaError_t` — the Runtime API status enum — plus its `CudaStatus` impl.
2
3use baracuda_types::CudaStatus;
4
5/// Return code from a CUDA Runtime API call.
6///
7/// Modelled as `#[repr(transparent)] struct cudaError_t(pub i32)` — same
8/// reasoning as [`crate::CUresult`]: the runtime may return codes we don't
9/// yet recognize, and we must not transmute into an exhaustive enum.
10#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
11#[repr(transparent)]
12pub struct cudaError_t(pub i32);
13
14#[allow(non_upper_case_globals)]
15impl cudaError_t {
16    pub const Success: Self = Self(0);
17    pub const InvalidValue: Self = Self(1);
18    pub const MemoryAllocation: Self = Self(2);
19    pub const InitializationError: Self = Self(3);
20    pub const CudartUnloading: Self = Self(4);
21    pub const ProfilerDisabled: Self = Self(5);
22    pub const InvalidConfiguration: Self = Self(9);
23    pub const InvalidPitchValue: Self = Self(12);
24    pub const InvalidSymbol: Self = Self(13);
25    pub const InvalidHostPointer: Self = Self(16);
26    pub const InvalidDevicePointer: Self = Self(17);
27    pub const InvalidTexture: Self = Self(18);
28    pub const InvalidDeviceFunction: Self = Self(98);
29    pub const NoDevice: Self = Self(100);
30    pub const InvalidDevice: Self = Self(101);
31    pub const DeviceNotLicensed: Self = Self(102);
32    pub const SoftwareValidityNotEstablished: Self = Self(103);
33    pub const StartupFailure: Self = Self(127);
34    pub const InvalidKernelImage: Self = Self(200);
35    pub const DeviceUninitialized: Self = Self(201);
36    pub const MapBufferObjectFailed: Self = Self(205);
37    pub const UnmapBufferObjectFailed: Self = Self(206);
38    pub const ArrayIsMapped: Self = Self(207);
39    pub const AlreadyMapped: Self = Self(208);
40    pub const NoKernelImageForDevice: Self = Self(209);
41    pub const AlreadyAcquired: Self = Self(210);
42    pub const NotMapped: Self = Self(211);
43    pub const ECCUncorrectable: Self = Self(214);
44    pub const UnsupportedLimit: Self = Self(215);
45    pub const DeviceAlreadyInUse: Self = Self(216);
46    pub const PeerAccessUnsupported: Self = Self(217);
47    pub const InvalidPtx: Self = Self(218);
48    pub const InvalidGraphicsContext: Self = Self(219);
49    pub const NvlinkUncorrectable: Self = Self(220);
50    pub const JitCompilerNotFound: Self = Self(221);
51    pub const UnsupportedPtxVersion: Self = Self(222);
52    pub const InvalidSource: Self = Self(300);
53    pub const FileNotFound: Self = Self(301);
54    pub const SharedObjectSymbolNotFound: Self = Self(302);
55    pub const SharedObjectInitFailed: Self = Self(303);
56    pub const OperatingSystem: Self = Self(304);
57    pub const InvalidResourceHandle: Self = Self(400);
58    pub const IllegalState: Self = Self(401);
59    pub const SymbolNotFound: Self = Self(500);
60    pub const NotReady: Self = Self(600);
61    pub const IllegalAddress: Self = Self(700);
62    pub const LaunchOutOfResources: Self = Self(701);
63    pub const LaunchTimeout: Self = Self(702);
64    pub const PrimaryContextActive: Self = Self(708);
65    pub const ContextIsDestroyed: Self = Self(709);
66    pub const Assert: Self = Self(710);
67    pub const MisalignedAddress: Self = Self(716);
68    pub const LaunchFailure: Self = Self(719);
69    pub const CooperativeLaunchTooLarge: Self = Self(720);
70    pub const NotPermitted: Self = Self(800);
71    pub const NotSupported: Self = Self(801);
72    pub const SystemNotReady: Self = Self(802);
73    pub const SystemDriverMismatch: Self = Self(803);
74    pub const CompatNotSupportedOnDevice: Self = Self(804);
75    pub const StreamCaptureUnsupported: Self = Self(900);
76    pub const StreamCaptureInvalidated: Self = Self(901);
77    pub const StreamCaptureMerge: Self = Self(902);
78    pub const StreamCaptureUnmatched: Self = Self(903);
79    pub const StreamCaptureUnjoined: Self = Self(904);
80    pub const StreamCaptureIsolation: Self = Self(905);
81    pub const StreamCaptureImplicit: Self = Self(906);
82    pub const CapturedEvent: Self = Self(907);
83    pub const StreamCaptureWrongThread: Self = Self(908);
84    pub const Timeout: Self = Self(909);
85    pub const GraphExecUpdateFailure: Self = Self(910);
86    pub const Unknown: Self = Self(999);
87
88    pub const fn is_success(self) -> bool {
89        self.0 == 0
90    }
91}
92
93impl CudaStatus for cudaError_t {
94    fn code(self) -> i32 {
95        self.0
96    }
97
98    fn name(self) -> &'static str {
99        match self.0 {
100            0 => "cudaSuccess",
101            1 => "cudaErrorInvalidValue",
102            2 => "cudaErrorMemoryAllocation",
103            3 => "cudaErrorInitializationError",
104            4 => "cudaErrorCudartUnloading",
105            9 => "cudaErrorInvalidConfiguration",
106            98 => "cudaErrorInvalidDeviceFunction",
107            100 => "cudaErrorNoDevice",
108            101 => "cudaErrorInvalidDevice",
109            200 => "cudaErrorInvalidKernelImage",
110            201 => "cudaErrorDeviceUninitialized",
111            209 => "cudaErrorNoKernelImageForDevice",
112            214 => "cudaErrorECCUncorrectable",
113            218 => "cudaErrorInvalidPtx",
114            220 => "cudaErrorNvlinkUncorrectable",
115            400 => "cudaErrorInvalidResourceHandle",
116            500 => "cudaErrorSymbolNotFound",
117            600 => "cudaErrorNotReady",
118            700 => "cudaErrorIllegalAddress",
119            701 => "cudaErrorLaunchOutOfResources",
120            709 => "cudaErrorContextIsDestroyed",
121            716 => "cudaErrorMisalignedAddress",
122            719 => "cudaErrorLaunchFailure",
123            800 => "cudaErrorNotPermitted",
124            801 => "cudaErrorNotSupported",
125            999 => "cudaErrorUnknown",
126            _ => "cudaErrorUnrecognized",
127        }
128    }
129
130    fn description(self) -> &'static str {
131        match self.0 {
132            0 => "no error",
133            1 => "invalid argument",
134            2 => "out of memory",
135            3 => "initialization error",
136            4 => "CUDA runtime is shutting down",
137            98 => "invalid device function",
138            100 => "no CUDA-capable device detected",
139            101 => "invalid device ordinal",
140            200 => "invalid kernel image",
141            201 => "CUDA device has not been initialized",
142            209 => "no kernel image available for this device",
143            214 => "uncorrectable ECC error",
144            218 => "invalid PTX",
145            400 => "invalid resource handle",
146            500 => "named symbol not found",
147            600 => "operation not yet complete",
148            700 => "illegal memory access",
149            701 => "launch requires more resources than the device can provide",
150            716 => "misaligned address",
151            719 => "unspecified launch failure",
152            800 => "operation not permitted",
153            801 => "operation not supported",
154            _ => "unrecognized CUDA runtime error code",
155        }
156    }
157
158    fn is_success(self) -> bool {
159        cudaError_t::is_success(self)
160    }
161
162    fn library(self) -> &'static str {
163        "cuda-runtime"
164    }
165}