cuDDL
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Enumerations | Functions
error.hpp File Reference
#include <cuda_runtime.h>
#include <cuda/std/expected>
#include <cuda/stream>
#include <concepts>
#include <cstdint>
#include <cstdio>
#include <format>
#include <source_location>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <utility>
#include <variant>
Include dependency graph for error.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cuddl::SourceLocation
 File, line, and column for a C++ call site or FASTX input position. More...
 
struct  cuddl::CudaError
 CUDA failure payload: status code, call site, and formatted message. More...
 
struct  cuddl::InvalidArgumentError
 Invalid-argument failure payload. More...
 
struct  cuddl::ResourceError
 Resource failure payload: allocation, I/O, or capacity errors. More...
 
struct  cuddl::Error
 Error payload carried in Result on failure. More...
 
struct  cuddl::Result< T >
 Fallible API result: cuda::std::expected<T, Error> with cuDDL factories. More...
 
struct  cuddl::Result< void >
 

Namespaces

namespace  cuddl
 Batch operations over contiguous device rows.
 
namespace  cuddl::detail
 

Macros

#define CUDDL_TRY(expr)
 Propagates a cuddl::Result failure from the enclosing function (GNU statement expression).
 
#define CUDDL_UNWRAP(expr)
 Unwraps a cuddl::Result or throws std::runtime_error on failure (tests and apps).
 
#define CUDDL_CUDA_ABORT(expr)   ::cuddl::cuda_abort_on_error((expr))
 Checks a CUDA call and aborts on failure (destructors and RAII only).
 
#define CUDDL_CUDA_TRY(...)   CUDDL_TRY(::cuddl::cuda_try([&] { return (__VA_ARGS__); }))
 Propagates a CUDA error wrapped in cuddl::Result<void>.
 

Enumerations

enum class  cuddl::ErrorCategory : uint8_t { cuddl::cuda , cuddl::invalid_argument , cuddl::resource }
 Error category for Result failures. More...
 

Functions

void cuddl::cuda_abort_on_error (cudaError_t error, std::source_location location=std::source_location::current())
 Terminates the process when error is not cudaSuccess (for RAII teardown only).
 
template<typename T >
T cuddl::detail::try_unwrap_success (Result< T > &result)
 
void cuddl::detail::try_unwrap_success (Result< void > &result)
 
cuda::std::unexpected< Error > cuddl::detail::propagate_error (const Error &error)
 Copies error for propagation (avoids moving out of expected::error()).
 
cuda::std::unexpected< Error > cuddl::Err (Error error)
 Failure return; converts to any Result<T> via cuda::std::unexpected.
 
Result< void > cuddl::Ok () noexcept
 Success return for Result<void>; same as return {}.
 
Result< void > cuddl::cuda_try (cudaError_t error, std::source_location location=std::source_location::current())
 Checks a CUDA runtime call and returns an error on failure.
 
template<std::invocable Operation>
auto cuddl::cuda_try (Operation &&operation, std::source_location location=std::source_location::current())
 Converts CCCL exceptions to the same Result errors as CUDA status-returning APIs.
 

Macro Definition Documentation

◆ CUDDL_CUDA_ABORT

#define CUDDL_CUDA_ABORT (   expr)    ::cuddl::cuda_abort_on_error((expr))

Checks a CUDA call and aborts on failure (destructors and RAII only).

Definition at line 245 of file error.hpp.

◆ CUDDL_CUDA_TRY

#define CUDDL_CUDA_TRY (   ...)    CUDDL_TRY(::cuddl::cuda_try([&] { return (__VA_ARGS__); }))

Propagates a CUDA error wrapped in cuddl::Result<void>.

Definition at line 248 of file error.hpp.

◆ CUDDL_TRY

#define CUDDL_TRY (   expr)
Value:
({ \
auto _cuddl_result = (expr); \
if (!_cuddl_result) { \
return ::cuddl::detail::propagate_error(_cuddl_result.error()); \
} \
::cuddl::detail::try_unwrap_success(_cuddl_result); \
})

Propagates a cuddl::Result failure from the enclosing function (GNU statement expression).

On failure, copies the error then returns cuda::std::unexpected<Error> (does not move out of the source expected). On success, yields the value for valued results, or nothing for Result<void>. Usable as a statement (CUDDL_TRY(expr);) or in initializers (auto x = CUDDL_TRY(expr);).

Definition at line 225 of file error.hpp.

226 { \
227 auto _cuddl_result = (expr); \
228 if (!_cuddl_result) { \
229 return ::cuddl::detail::propagate_error(_cuddl_result.error()); \
230 } \
231 ::cuddl::detail::try_unwrap_success(_cuddl_result); \
232 })

◆ CUDDL_UNWRAP

#define CUDDL_UNWRAP (   expr)
Value:
({ \
auto _cuddl_result = (expr); \
if (!_cuddl_result) { \
throw std::runtime_error(_cuddl_result.error().message()); \
} \
::cuddl::detail::try_unwrap_success(_cuddl_result); \
})

Unwraps a cuddl::Result or throws std::runtime_error on failure (tests and apps).

Definition at line 235 of file error.hpp.

236 { \
237 auto _cuddl_result = (expr); \
238 if (!_cuddl_result) { \
239 throw std::runtime_error(_cuddl_result.error().message()); \
240 } \
241 ::cuddl::detail::try_unwrap_success(_cuddl_result); \
242 })