cuda-api-wrappers
Thin C++-flavored wrappers for the CUDA Runtime API
Classes | Macros | Enumerations | Functions
error.hpp File Reference

Facilities for exception-based handling of Runtime API errors, including a basic exception class wrapping std::runtime_error. More...

#include <cuda/api/types.hpp>
#include <cuda_runtime_api.h>
#include <type_traits>
#include <string>
#include <stdexcept>

Go to the source code of this file.

Classes

class  cuda::runtime_error
 A (base?) class for exceptions raised by CUDA code; these errors are thrown by essentially all CUDA Runtime API wrappers upon failure. More...
 

Enumerations

enum  cuda::status::named_t : std::underlying_type< status_t >::type {
  success = cudaSuccess,
  missing_configuration = cudaErrorMissingConfiguration,
  memory_allocation = cudaErrorMemoryAllocation,
  initialization_error = cudaErrorInitializationError,
  launch_failure = cudaErrorLaunchFailure,
  prior_launch_failure = cudaErrorPriorLaunchFailure,
  launch_timeout = cudaErrorLaunchTimeout,
  launch_out_of_resources = cudaErrorLaunchOutOfResources,
  invalid_kernel_function = cudaErrorInvalidDeviceFunction,
  invalid_configuration = cudaErrorInvalidConfiguration,
  invalid_device = cudaErrorInvalidDevice,
  invalid_value = cudaErrorInvalidValue,
  invalid_pitch_value = cudaErrorInvalidPitchValue,
  invalid_symbol = cudaErrorInvalidSymbol,
  map_buffer_object_failed = cudaErrorMapBufferObjectFailed,
  unmap_buffer_object_failed = cudaErrorUnmapBufferObjectFailed,
  invalid_host_pointer = cudaErrorInvalidHostPointer,
  invalid_device_pointer = cudaErrorInvalidDevicePointer,
  invalid_texture = cudaErrorInvalidTexture,
  invalid_texture_binding = cudaErrorInvalidTextureBinding,
  invalid_channel_descriptor = cudaErrorInvalidChannelDescriptor,
  invalid_memcpy_direction = cudaErrorInvalidMemcpyDirection,
  address_of_constant = cudaErrorAddressOfConstant,
  texture_fetch_failed = cudaErrorTextureFetchFailed,
  texture_not_bound = cudaErrorTextureNotBound,
  synchronization_error = cudaErrorSynchronizationError,
  invalid_filter_setting = cudaErrorInvalidFilterSetting,
  invalid_norm_setting = cudaErrorInvalidNormSetting,
  mixed_device_execution = cudaErrorMixedDeviceExecution,
  cuda_runtime_unloading = cudaErrorCudartUnloading,
  unknown = cudaErrorUnknown,
  not_yet_implemented = cudaErrorNotYetImplemented,
  memory_value_too_large = cudaErrorMemoryValueTooLarge,
  invalid_resource_handle = cudaErrorInvalidResourceHandle,
  not_ready = cudaErrorNotReady,
  insufficient_driver = cudaErrorInsufficientDriver,
  set_on_active_process = cudaErrorSetOnActiveProcess,
  invalid_surface = cudaErrorInvalidSurface,
  no_device = cudaErrorNoDevice,
  ecc_uncorrectable = cudaErrorECCUncorrectable,
  shared_object_symbol_not_found = cudaErrorSharedObjectSymbolNotFound,
  shared_object_init_failed = cudaErrorSharedObjectInitFailed,
  unsupported_limit = cudaErrorUnsupportedLimit,
  duplicate_variable_name = cudaErrorDuplicateVariableName,
  duplicate_texture_name = cudaErrorDuplicateTextureName,
  duplicate_surface_name = cudaErrorDuplicateSurfaceName,
  devices_unavailable = cudaErrorDevicesUnavailable,
  invalid_kernel_image = cudaErrorInvalidKernelImage,
  no_kernel_image_for_device = cudaErrorNoKernelImageForDevice,
  incompatible_driver_context = cudaErrorIncompatibleDriverContext,
  peer_access_already_enabled = cudaErrorPeerAccessAlreadyEnabled,
  peer_access_not_enabled = cudaErrorPeerAccessNotEnabled,
  device_already_in_use = cudaErrorDeviceAlreadyInUse,
  profiler_disabled = cudaErrorProfilerDisabled,
  profiler_not_initialized = cudaErrorProfilerNotInitialized,
  profiler_already_started = cudaErrorProfilerAlreadyStarted,
  profiler_already_stopped = cudaErrorProfilerAlreadyStopped,
  assert = cudaErrorAssert,
  too_many_peers = cudaErrorTooManyPeers,
  host_memory_already_registered = cudaErrorHostMemoryAlreadyRegistered,
  host_memory_not_registered = cudaErrorHostMemoryNotRegistered,
  operating_system = cudaErrorOperatingSystem,
  peer_access_unsupported = cudaErrorPeerAccessUnsupported,
  launch_max_depth_exceeded = cudaErrorLaunchMaxDepthExceeded,
  launch_file_scoped_tex = cudaErrorLaunchFileScopedTex,
  launch_file_scoped_surf = cudaErrorLaunchFileScopedSurf,
  sync_depth_exceeded = cudaErrorSyncDepthExceeded,
  launch_pending_count_exceeded = cudaErrorLaunchPendingCountExceeded,
  not_permitted = cudaErrorNotPermitted,
  not_supported = cudaErrorNotSupported,
  hardware_stack_error = cudaErrorHardwareStackError,
  illegal_instruction = cudaErrorIllegalInstruction,
  misaligned_address = cudaErrorMisalignedAddress,
  invalid_address_space = cudaErrorInvalidAddressSpace,
  invalid_pc = cudaErrorInvalidPc,
  illegal_address = cudaErrorIllegalAddress,
  invalid_ptx = cudaErrorInvalidPtx,
  invalid_graphics_context = cudaErrorInvalidGraphicsContext,
  nvlink_uncorrectable = cudaErrorNvlinkUncorrectable,
  startup_failure = cudaErrorStartupFailure,
  api_failure_base = cudaErrorApiFailureBase
}
 Aliases for CUDA status codes. More...
 
enum  : bool {
  dont_clear_errors = false,
  do_clear_errors = true
}
 

Functions

constexpr bool cuda::status::operator== (const status_t &lhs, const named_t &rhs)
 
constexpr bool cuda::status::operator!= (const status_t &lhs, const named_t &rhs)
 
constexpr bool cuda::status::operator== (const named_t &lhs, const status_t &rhs)
 
constexpr bool cuda::status::operator!= (const named_t &lhs, const status_t &rhs)
 
constexpr bool cuda::is_success (status_t status)
 
constexpr bool cuda::is_failure (status_t status)
 
std::string cuda::describe (status_t status)
 Obtain a brief textual explanation for a specified kind of CUDA Runtime API status or error code.
 
void cuda::throw_if_error (cuda::status_t status, std::string message) noexcept(false)
 Do nothing... More...
 
void cuda::throw_if_error (cuda::status_t status) noexcept(false)
 Does nothing - unless the status indicates an error, in which case a cuda::runtime_error exception is thrown. More...
 
status_t cuda::outstanding_error::clear () noexcept
 Reset the CUDA status to cuda::status::success.
 
status_t cuda::outstanding_error::get () noexcept
 
void cuda::outstanding_error::ensure_none (std::string message, bool clear_any_error=do_clear_errors) noexcept(false)
 Does nothing (unless throwing an exception) More...
 
void cuda::outstanding_error::ensure_none (const char *message, bool clear_any_error=do_clear_errors) noexcept(false)
 A variant of ensure_none(std::string, bool) which takes a C-style string. More...
 
void cuda::outstanding_error::ensure_none (bool clear_any_error=do_clear_errors) noexcept(false)
 Does nothing (unless throwing an exception) More...
 

Detailed Description

Facilities for exception-based handling of Runtime API errors, including a basic exception class wrapping std::runtime_error.

Enumeration Type Documentation

§ named_t

enum cuda::status::named_t : std::underlying_type< status_t >::type

Aliases for CUDA status codes.

Note
unfortunately, this enum can't inherit from status_t

Function Documentation

§ ensure_none() [1/3]

void cuda::outstanding_error::ensure_none ( std::string  message,
bool  clear_any_error = do_clear_errors 
)
inlinenoexcept

Does nothing (unless throwing an exception)

Note
similar to cuda::throw_if_error, but uses the CUDA Runtime API's internal state
Exceptions
cuda::runtime_errorif the CUDA runtime API has encountered previously encountered an (uncleared) error
Parameters
messageAdditional message to incldue in the exception thrown
clear_any_errorWhen true, clears the CUDA Runtime API's state from recalling errors arising from before this moment

§ ensure_none() [2/3]

void cuda::outstanding_error::ensure_none ( const char *  message,
bool  clear_any_error = do_clear_errors 
)
inlinenoexcept

A variant of ensure_none(std::string, bool) which takes a C-style string.

Note
exists so as to avoid incorrect overload resolution of ensure_none(my_c_string) calls.

§ ensure_none() [3/3]

void cuda::outstanding_error::ensure_none ( bool  clear_any_error = do_clear_errors)
inlinenoexcept

Does nothing (unless throwing an exception)

Note
similar to throw_if_error, but uses the CUDA Runtime API's internal state
Exceptions
cuda::runtime_errorif the CUDA runtime API has encountered previously encountered an (uncleared) error
Parameters
clear_any_errorWhen true, clears the CUDA Runtime API's state from recalling errors arising from before this oment

§ throw_if_error() [1/2]

void cuda::throw_if_error ( cuda::status_t  status,
std::string  message 
)
inlinenoexcept

Do nothing...

unless the status indicates an error, in which case a cuda::runtime_error exception is thrown

Parameters
statusshould be cuda::status::success - otherwise an exception is thrown
messageAn extra description message to add to the exception

§ throw_if_error() [2/2]

void cuda::throw_if_error ( cuda::status_t  status)
inlinenoexcept

Does nothing - unless the status indicates an error, in which case a cuda::runtime_error exception is thrown.

Parameters
statusshould be cuda::status::success - otherwise an exception is thrown