cuda_oxide/
error.rs

1use num_enum::TryFromPrimitive;
2use std::{
3    error::Error,
4    fmt::{self, Debug},
5};
6
7/// A device-sourced or `libcuda`-sourced error code
8#[derive(Debug, Copy, Clone, TryFromPrimitive)]
9#[repr(u32)]
10pub enum ErrorCode {
11    #[doc = "The API call returned with no errors. In the case of query calls, this"]
12    #[doc = "also means that the operation being queried is complete (see"]
13    #[doc = "::cuEventQuery() and ::cuStreamQuery())."]
14    Success = 0,
15    #[doc = "This indicates that one or more of the parameters passed to the API call"]
16    #[doc = "is not within an acceptable range of values."]
17    InvalidValue = 1,
18    #[doc = "The API call failed because it was unable to allocate enough memory to"]
19    #[doc = "perform the requested operation."]
20    OutOfMemory = 2,
21    #[doc = "This indicates that the CUDA driver has not been initialized with"]
22    #[doc = "::cuInit() or that initialization has failed."]
23    NotInitialized = 3,
24    #[doc = "This indicates that the CUDA driver is in the process of shutting down."]
25    Deinitialized = 4,
26    #[doc = "This indicates profiler is not initialized for this run. This can"]
27    #[doc = "happen when the application is running with external profiling tools"]
28    #[doc = "like visual profiler."]
29    ProfilerDisabled = 5,
30    #[doc = "\\deprecated"]
31    #[doc = "This error return is deprecated as of CUDA 5.0. It is no longer an error"]
32    #[doc = "to attempt to enable/disable the profiling via ::cuProfilerStart or"]
33    #[doc = "::cuProfilerStop without initialization."]
34    ProfilerNotInitialized = 6,
35    #[doc = "\\deprecated"]
36    #[doc = "This error return is deprecated as of CUDA 5.0. It is no longer an error"]
37    #[doc = "to call cuProfilerStart() when profiling is already enabled."]
38    ProfilerAlreadyStarted = 7,
39    #[doc = "\\deprecated"]
40    #[doc = "This error return is deprecated as of CUDA 5.0. It is no longer an error"]
41    #[doc = "to call cuProfilerStop() when profiling is already disabled."]
42    ProfilerAlreadyStopped = 8,
43    #[doc = "This indicates that the CUDA driver that the application has loaded is a"]
44    #[doc = "stub library. Applications that run with the stub rather than a real"]
45    #[doc = "driver loaded will result in CUDA API returning this error."]
46    StubLibrary = 34,
47    #[doc = "This indicates that no CUDA-capable devices were detected by the installed"]
48    #[doc = "CUDA driver."]
49    NoDevice = 100,
50    #[doc = "This indicates that the device ordinal supplied by the user does not"]
51    #[doc = "correspond to a valid CUDA device."]
52    InvalidDevice = 101,
53    #[doc = "This error indicates that the Grid license is not applied."]
54    DeviceNotLicensed = 102,
55    #[doc = "This indicates that the device kernel image is invalid. This can also"]
56    #[doc = "indicate an invalid CUDA module."]
57    InvalidImage = 200,
58    #[doc = "This most frequently indicates that there is no context bound to the"]
59    #[doc = "current thread. This can also be returned if the context passed to an"]
60    #[doc = "API call is not a valid handle (such as a context that has had"]
61    #[doc = "::cuCtxDestroy() invoked on it). This can also be returned if a user"]
62    #[doc = "mixes different API versions (i.e. 3010 context with 3020 API calls)."]
63    #[doc = "See ::cuCtxGetApiVersion() for more details."]
64    InvalidContext = 201,
65    #[doc = "This indicated that the context being supplied as a parameter to the"]
66    #[doc = "API call was already the active context."]
67    #[doc = "\\deprecated"]
68    #[doc = "This error return is deprecated as of CUDA 3.2. It is no longer an"]
69    #[doc = "error to attempt to push the active context via ::cuCtxPushCurrent()."]
70    ContextAlreadyCurrent = 202,
71    #[doc = "This indicates that a map or register operation has failed."]
72    MapFailed = 205,
73    #[doc = "This indicates that an unmap or unregister operation has failed."]
74    UnmapFailed = 206,
75    #[doc = "This indicates that the specified array is currently mapped and thus"]
76    #[doc = "cannot be destroyed."]
77    ArrayIsMapped = 207,
78    #[doc = "This indicates that the resource is already mapped."]
79    AlreadyMapped = 208,
80    #[doc = "This indicates that there is no kernel image available that is suitable"]
81    #[doc = "for the device. This can occur when a user specifies code generation"]
82    #[doc = "options for a particular CUDA source file that do not include the"]
83    #[doc = "corresponding device configuration."]
84    NoBinaryForGpu = 209,
85    #[doc = "This indicates that a resource has already been acquired."]
86    AlreadyAcquired = 210,
87    #[doc = "This indicates that a resource is not mapped."]
88    NotMapped = 211,
89    #[doc = "This indicates that a mapped resource is not available for access as an"]
90    #[doc = "array."]
91    NotMappedAsArray = 212,
92    #[doc = "This indicates that a mapped resource is not available for access as a"]
93    #[doc = "pointer."]
94    NotMappedAsPointer = 213,
95    #[doc = "This indicates that an uncorrectable ECC error was detected during"]
96    #[doc = "execution."]
97    EccUncorrectable = 214,
98    #[doc = "This indicates that the ::CUlimit passed to the API call is not"]
99    #[doc = "supported by the active device."]
100    UnsupportedLimit = 215,
101    #[doc = "This indicates that the ::CUcontext passed to the API call can"]
102    #[doc = "only be bound to a single CPU thread at a time but is already"]
103    #[doc = "bound to a CPU thread."]
104    ContextAlreadyInUse = 216,
105    #[doc = "This indicates that peer access is not supported across the given"]
106    #[doc = "devices."]
107    PeerAccessUnsupported = 217,
108    #[doc = "This indicates that a PTX JIT compilation failed."]
109    InvalidPtx = 218,
110    #[doc = "This indicates an error with OpenGL or DirectX context."]
111    InvalidGraphicsContext = 219,
112    #[doc = "This indicates that an uncorrectable NVLink error was detected during the"]
113    #[doc = "execution."]
114    NvlinkUncorrectable = 220,
115    #[doc = "This indicates that the PTX JIT compiler library was not found."]
116    JitCompilerNotFound = 221,
117    #[doc = "This indicates that the provided PTX was compiled with an unsupported toolchain."]
118    UnsupportedPtxVersion = 222,
119    #[doc = "This indicates that the PTX JIT compilation was disabled."]
120    JitCompilationDisabled = 223,
121    #[doc = "This indicates that the device kernel source is invalid."]
122    InvalidSource = 300,
123    #[doc = "This indicates that the file specified was not found."]
124    FileNotFound = 301,
125    #[doc = "This indicates that a link to a shared object failed to resolve."]
126    SharedObjectSymbolNotFound = 302,
127    #[doc = "This indicates that initialization of a shared object failed."]
128    SharedObjectInitFailed = 303,
129    #[doc = "This indicates that an OS call failed."]
130    OperatingSystem = 304,
131    #[doc = "This indicates that a resource handle passed to the API call was not"]
132    #[doc = "valid. Resource handles are opaque types like ::CUstream and ::CUevent."]
133    InvalidHandle = 400,
134    #[doc = "This indicates that a resource required by the API call is not in a"]
135    #[doc = "valid state to perform the requested operation."]
136    IllegalState = 401,
137    #[doc = "This indicates that a named symbol was not found. Examples of symbols"]
138    #[doc = "are global/constant variable names, driver function names, texture names,"]
139    #[doc = "and surface names."]
140    NotFound = 500,
141    #[doc = "This indicates that asynchronous operations issued previously have not"]
142    #[doc = "completed yet. This result is not actually an error, but must be indicated"]
143    #[doc = "differently than ::CUDA_SUCCESS (which indicates completion). Calls that"]
144    #[doc = "may return this value include ::cuEventQuery() and ::cuStreamQuery()."]
145    NotReady = 600,
146    #[doc = "While executing a kernel, the device encountered a"]
147    #[doc = "load or store instruction on an invalid memory address."]
148    #[doc = "This leaves the process in an inconsistent state and any further CUDA work"]
149    #[doc = "will return the same error. To continue using CUDA, the process must be terminated"]
150    #[doc = "and relaunched."]
151    IllegalAddress = 700,
152    #[doc = "This indicates that a launch did not occur because it did not have"]
153    #[doc = "appropriate resources. This error usually indicates that the user has"]
154    #[doc = "attempted to pass too many arguments to the device kernel, or the"]
155    #[doc = "kernel launch specifies too many threads for the kernel's register"]
156    #[doc = "count. Passing arguments of the wrong size (i.e. a 64-bit pointer"]
157    #[doc = "when a 32-bit int is expected) is equivalent to passing too many"]
158    #[doc = "arguments and can also result in this error."]
159    LaunchOutOfResources = 701,
160    #[doc = "This indicates that the device kernel took too long to execute. This can"]
161    #[doc = "only occur if timeouts are enabled - see the device attribute"]
162    #[doc = "::CU_DEVICE_ATTRIBUTE_KERNEL_EXEC_TIMEOUT for more information."]
163    #[doc = "This leaves the process in an inconsistent state and any further CUDA work"]
164    #[doc = "will return the same error. To continue using CUDA, the process must be terminated"]
165    #[doc = "and relaunched."]
166    LaunchTimeout = 702,
167    #[doc = "This error indicates a kernel launch that uses an incompatible texturing"]
168    #[doc = "mode."]
169    LaunchIncompatibleTexturing = 703,
170    #[doc = "This error indicates that a call to ::cuCtxEnablePeerAccess() is"]
171    #[doc = "trying to re-enable peer access to a context which has already"]
172    #[doc = "had peer access to it enabled."]
173    PeerAccessAlreadyEnabled = 704,
174    #[doc = "This error indicates that ::cuCtxDisablePeerAccess() is"]
175    #[doc = "trying to disable peer access which has not been enabled yet"]
176    #[doc = "via ::cuCtxEnablePeerAccess()."]
177    PeerAccessNotEnabled = 705,
178    #[doc = "This error indicates that the primary context for the specified device"]
179    #[doc = "has already been initialized."]
180    PrimaryContextActive = 708,
181    #[doc = "This error indicates that the context current to the calling thread"]
182    #[doc = "has been destroyed using ::cuCtxDestroy, or is a primary context which"]
183    #[doc = "has not yet been initialized."]
184    ContextIsDestroyed = 709,
185    #[doc = "A device-side assert triggered during kernel execution. The context"]
186    #[doc = "cannot be used anymore, and must be destroyed. All existing device"]
187    #[doc = "memory allocations from this context are invalid and must be"]
188    #[doc = "reconstructed if the program is to continue using CUDA."]
189    Assert = 710,
190    #[doc = "This error indicates that the hardware resources required to enable"]
191    #[doc = "peer access have been exhausted for one or more of the devices"]
192    #[doc = "passed to ::cuCtxEnablePeerAccess()."]
193    TooManyPeers = 711,
194    #[doc = "This error indicates that the memory range passed to ::cuMemHostRegister()"]
195    #[doc = "has already been registered."]
196    HostMemoryAlreadyRegistered = 712,
197    #[doc = "This error indicates that the pointer passed to ::cuMemHostUnregister()"]
198    #[doc = "does not correspond to any currently registered memory region."]
199    HostMemoryNotRegistered = 713,
200    #[doc = "While executing a kernel, the device encountered a stack error."]
201    #[doc = "This can be due to stack corruption or exceeding the stack size limit."]
202    #[doc = "This leaves the process in an inconsistent state and any further CUDA work"]
203    #[doc = "will return the same error. To continue using CUDA, the process must be terminated"]
204    #[doc = "and relaunched."]
205    HardwareStackError = 714,
206    #[doc = "While executing a kernel, the device encountered an illegal instruction."]
207    #[doc = "This leaves the process in an inconsistent state and any further CUDA work"]
208    #[doc = "will return the same error. To continue using CUDA, the process must be terminated"]
209    #[doc = "and relaunched."]
210    IllegalInstruction = 715,
211    #[doc = "While executing a kernel, the device encountered a load or store instruction"]
212    #[doc = "on a memory address which is not aligned."]
213    #[doc = "This leaves the process in an inconsistent state and any further CUDA work"]
214    #[doc = "will return the same error. To continue using CUDA, the process must be terminated"]
215    #[doc = "and relaunched."]
216    MisalignedAddress = 716,
217    #[doc = "While executing a kernel, the device encountered an instruction"]
218    #[doc = "which can only operate on memory locations in certain address spaces"]
219    #[doc = "(global, shared, or local), but was supplied a memory address not"]
220    #[doc = "belonging to an allowed address space."]
221    #[doc = "This leaves the process in an inconsistent state and any further CUDA work"]
222    #[doc = "will return the same error. To continue using CUDA, the process must be terminated"]
223    #[doc = "and relaunched."]
224    InvalidAddressSpace = 717,
225    #[doc = "While executing a kernel, the device program counter wrapped its address space."]
226    #[doc = "This leaves the process in an inconsistent state and any further CUDA work"]
227    #[doc = "will return the same error. To continue using CUDA, the process must be terminated"]
228    #[doc = "and relaunched."]
229    InvalidPc = 718,
230    #[doc = "An exception occurred on the device while executing a kernel. Common"]
231    #[doc = "causes include dereferencing an invalid device pointer and accessing"]
232    #[doc = "out of bounds shared memory. Less common cases can be system specific - more"]
233    #[doc = "information about these cases can be found in the system specific user guide."]
234    #[doc = "This leaves the process in an inconsistent state and any further CUDA work"]
235    #[doc = "will return the same error. To continue using CUDA, the process must be terminated"]
236    #[doc = "and relaunched."]
237    LaunchFailed = 719,
238    #[doc = "This error indicates that the number of blocks launched per grid for a kernel that was"]
239    #[doc = "launched via either ::cuLaunchCooperativeKernel or ::cuLaunchCooperativeKernelMultiDevice"]
240    #[doc = "exceeds the maximum number of blocks as allowed by ::cuOccupancyMaxActiveBlocksPerMultiprocessor"]
241    #[doc = "or ::cuOccupancyMaxActiveBlocksPerMultiprocessorWithFlags times the number of multiprocessors"]
242    #[doc = "as specified by the device attribute ::CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT."]
243    CooperativeLaunchTooLarge = 720,
244    #[doc = "This error indicates that the attempted operation is not permitted."]
245    NotPermitted = 800,
246    #[doc = "This error indicates that the attempted operation is not supported"]
247    #[doc = "on the current system or device."]
248    NotSupported = 801,
249    #[doc = "This error indicates that the system is not yet ready to start any CUDA"]
250    #[doc = "work.  To continue using CUDA, verify the system configuration is in a"]
251    #[doc = "valid state and all required driver daemons are actively running."]
252    #[doc = "More information about this error can be found in the system specific"]
253    #[doc = "user guide."]
254    SystemNotReady = 802,
255    #[doc = "This error indicates that there is a mismatch between the versions of"]
256    #[doc = "the display driver and the CUDA driver. Refer to the compatibility documentation"]
257    #[doc = "for supported versions."]
258    SystemDriverMismatch = 803,
259    #[doc = "This error indicates that the system was upgraded to run with forward compatibility"]
260    #[doc = "but the visible hardware detected by CUDA does not support this configuration."]
261    #[doc = "Refer to the compatibility documentation for the supported hardware matrix or ensure"]
262    #[doc = "that only supported hardware is visible during initialization via the CUDA_VISIBLE_DEVICES"]
263    #[doc = "environment variable."]
264    CompatNotSupportedOnDevice = 804,
265    #[doc = "This error indicates that the operation is not permitted when"]
266    #[doc = "the stream is capturing."]
267    StreamCaptureUnsupported = 900,
268    #[doc = "This error indicates that the current capture sequence on the stream"]
269    #[doc = "has been invalidated due to a previous error."]
270    StreamCaptureInvalidated = 901,
271    #[doc = "This error indicates that the operation would have resulted in a merge"]
272    #[doc = "of two independent capture sequences."]
273    StreamCaptureMerge = 902,
274    #[doc = "This error indicates that the capture was not initiated in this stream."]
275    StreamCaptureUnmatched = 903,
276    #[doc = "This error indicates that the capture sequence contains a fork that was"]
277    #[doc = "not joined to the primary stream."]
278    StreamCaptureUnjoined = 904,
279    #[doc = "This error indicates that a dependency would have been created which"]
280    #[doc = "crosses the capture sequence boundary. Only implicit in-stream ordering"]
281    #[doc = "dependencies are allowed to cross the boundary."]
282    StreamCaptureIsolation = 905,
283    #[doc = "This error indicates a disallowed implicit dependency on a current capture"]
284    #[doc = "sequence from cudaStreamLegacy."]
285    StreamCaptureImplicit = 906,
286    #[doc = "This error indicates that the operation is not permitted on an event which"]
287    #[doc = "was last recorded in a capturing stream."]
288    CapturedEvent = 907,
289    #[doc = "A stream capture sequence not initiated with the ::CU_STREAM_CAPTURE_MODE_RELAXED"]
290    #[doc = "argument to ::cuStreamBeginCapture was passed to ::cuStreamEndCapture in a"]
291    #[doc = "different thread."]
292    StreamCaptureWrongThread = 908,
293    #[doc = "This error indicates that the timeout specified for the wait operation has lapsed."]
294    Timeout = 909,
295    #[doc = "This error indicates that the graph update was not performed because it included"]
296    #[doc = "changes which violated constraints specific to instantiated graph update."]
297    GraphExecUpdateFailure = 910,
298    #[doc = "This indicates that an unknown internal error has occurred."]
299    Unknown = 999,
300}
301
302impl fmt::Display for ErrorCode {
303    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
304        <Self as Debug>::fmt(self, f)
305    }
306}
307
308impl Error for ErrorCode {}
309
310pub type CudaResult<T> = Result<T, ErrorCode>;
311
312pub(crate) fn cuda_error(input: u32) -> CudaResult<()> {
313    if input == 0 {
314        Ok(())
315    } else {
316        Err(ErrorCode::try_from_primitive(input).unwrap_or(ErrorCode::Unknown))
317    }
318}