cuSBF
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Enumerations | Functions
error.hpp File Reference
#include <cuda_runtime.h>
#include <cuda/std/expected>
#include <cstdint>
#include <cstdio>
#include <format>
#include <source_location>
#include <stdexcept>
#include <string>
#include <string_view>
#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  cusbf::SourceLocation
 File, line, and column for a C++ call site or FASTX input position. More...
 
struct  cusbf::CudaError
 
struct  cusbf::IoError
 
struct  cusbf::FastxParseError
 
struct  cusbf::InvalidArgumentError
 
struct  cusbf::ResourceError
 
struct  cusbf::Error
 Error payload carried in Result on failure. More...
 
struct  cusbf::Result< T >
 Fallible API result: cuda::std::expected<T, Error> with cuSBF factories. More...
 
struct  cusbf::Result< void >
 

Namespaces

namespace  cusbf
 
namespace  cusbf::detail
 

Macros

#define CUSBF_TRY(expr)
 Propagates a cusbf::Result failure from the enclosing function (GNU statement expression).
 
#define CUSBF_UNWRAP(expr)
 Unwraps a cusbf::Result or throws std::runtime_error on failure (tests and apps).
 
#define CUSBF_CUDA_ABORT(expr)   ::cusbf::cuda_abort_on_error((expr))
 Checks a CUDA call and aborts on failure (destructors and RAII only).
 
#define CUSBF_CUDA_TRY(expr)   CUSBF_TRY(::cusbf::cuda_try((expr)))
 Propagates a CUDA error wrapped in cusbf::Result<void>.
 

Enumerations

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

Functions

void cusbf::require_void (const Result< void > &result)
 Aborts when a Result is unsuccessful (benchmarks and tests).
 
void cusbf::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 cusbf::detail::try_unwrap_success (Result< T > &result)
 
void cusbf::detail::try_unwrap_success (Result< void > &result)
 
cuda::std::unexpected< Errorcusbf::detail::propagate_error (const Error &error)
 Copies error for propagation (avoids moving out of expected::error()).
 
cuda::std::unexpected< Errorcusbf::Err (Error error)
 Failure return; converts to any Result<T> via cuda::std::unexpected.
 
Result< void > cusbf::Ok () noexcept
 Success return for Result<void>; same as return {}.
 
Result< void > cusbf::cuda_try (cudaError_t error, std::source_location location=std::source_location::current())
 Checks a CUDA runtime call and returns an error on failure.
 

Macro Definition Documentation

◆ CUSBF_CUDA_ABORT

#define CUSBF_CUDA_ABORT (   expr)    ::cusbf::cuda_abort_on_error((expr))

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

Definition at line 266 of file error.hpp.

◆ CUSBF_CUDA_TRY

#define CUSBF_CUDA_TRY (   expr)    CUSBF_TRY(::cusbf::cuda_try((expr)))

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

Definition at line 269 of file error.hpp.

◆ CUSBF_TRY

#define CUSBF_TRY (   expr)
Value:
({ \
auto _cusbf_result = (expr); \
if (!_cusbf_result) { \
return ::cusbf::detail::propagate_error(_cusbf_result.error()); \
} \
::cusbf::detail::try_unwrap_success(_cusbf_result); \
})

Propagates a cusbf::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 (CUSBF_TRY(expr);) or in initializers (auto x = CUSBF_TRY(expr);).

Definition at line 246 of file error.hpp.

247 { \
248 auto _cusbf_result = (expr); \
249 if (!_cusbf_result) { \
250 return ::cusbf::detail::propagate_error(_cusbf_result.error()); \
251 } \
252 ::cusbf::detail::try_unwrap_success(_cusbf_result); \
253 })

◆ CUSBF_UNWRAP

#define CUSBF_UNWRAP (   expr)
Value:
({ \
auto _cusbf_result = (expr); \
if (!_cusbf_result) { \
throw std::runtime_error(_cusbf_result.error().message()); \
} \
::cusbf::detail::try_unwrap_success(_cusbf_result); \
})

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

Definition at line 256 of file error.hpp.

257 { \
258 auto _cusbf_result = (expr); \
259 if (!_cusbf_result) { \
260 throw std::runtime_error(_cusbf_result.error().message()); \
261 } \
262 ::cusbf::detail::try_unwrap_success(_cusbf_result); \
263 })