19 #include <cudf/detail/utilities/stacktrace.hpp>
20 #include <cudf/utilities/export.hpp>
23 #include <cuda_runtime_api.h>
27 #include <type_traits>
29 namespace CUDF_EXPORT
cudf {
42 : _stacktrace{cudf::detail::get_stacktrace(cudf::detail::capture_last_stackframe::NO)}
52 [[nodiscard]]
char const*
stacktrace()
const {
return _stacktrace.c_str(); }
99 cuda_error(std::string
const& message, cudaError_t
const& error)
100 : std::runtime_error(message), _cudaError(error)
110 [[nodiscard]] cudaError_t
error_code()
const {
return _cudaError; }
117 using cuda_error::cuda_error;
146 #define STRINGIFY_DETAIL(x) #x
147 #define CUDF_STRINGIFY(x) STRINGIFY_DETAIL(x)
178 #define CUDF_EXPECTS(...) \
179 GET_CUDF_EXPECTS_MACRO(__VA_ARGS__, CUDF_EXPECTS_3, CUDF_EXPECTS_2) \
184 #define GET_CUDF_EXPECTS_MACRO(_1, _2, _3, NAME, ...) NAME
186 #define CUDF_EXPECTS_3(_condition, _reason, _exception_type) \
188 static_assert(std::is_base_of_v<std::exception, _exception_type>); \
189 (_condition) ? static_cast<void>(0) \
190 : throw _exception_type \
191 {"CUDF failure at: " __FILE__ ":" CUDF_STRINGIFY(__LINE__) ": " _reason}; \
194 #define CUDF_EXPECTS_2(_condition, _reason) CUDF_EXPECTS_3(_condition, _reason, cudf::logic_error)
217 #define CUDF_FAIL(...) \
218 GET_CUDF_FAIL_MACRO(__VA_ARGS__, CUDF_FAIL_2, CUDF_FAIL_1) \
223 #define GET_CUDF_FAIL_MACRO(_1, _2, NAME, ...) NAME
225 #define CUDF_FAIL_2(_what, _exception_type) \
227 throw _exception_type { "CUDF failure at:" __FILE__ ":" CUDF_STRINGIFY(__LINE__) ": " _what }
229 #define CUDF_FAIL_1(_what) CUDF_FAIL_2(_what, cudf::logic_error)
233 namespace CUDF_EXPORT
cudf {
236 inline void throw_cuda_error(cudaError_t error,
char const* file,
unsigned int line)
241 auto const last = cudaFree(
nullptr);
242 auto const msg = std::string{
"CUDA error encountered at: " + std::string{file} +
":" +
243 std::to_string(line) +
": " + std::to_string(error) +
" " +
244 cudaGetErrorName(error) +
" " + cudaGetErrorString(error)};
247 if (error == last && last == cudaDeviceSynchronize()) {
248 throw fatal_cuda_error{
"Fatal " + msg, error};
250 throw cuda_error{msg, error};
264 #define CUDF_CUDA_TRY(call) \
266 cudaError_t const status = (call); \
267 if (cudaSuccess != status) { cudf::detail::throw_cuda_error(status, __FILE__, __LINE__); } \
284 #define CUDF_CHECK_CUDA(stream) \
286 CUDF_CUDA_TRY(cudaStreamSynchronize(stream)); \
287 CUDF_CUDA_TRY(cudaPeekAtLastError()); \
290 #define CUDF_CHECK_CUDA(stream) CUDF_CUDA_TRY(cudaPeekAtLastError());
Exception thrown when a CUDA error is encountered.
cuda_error(std::string const &message, cudaError_t const &error)
Construct a new cuda error object with error message and code.
cudaError_t _cudaError
CUDA error code.
cudaError_t error_code() const
Returns the CUDA error code associated with the exception.
Exception thrown when an operation is attempted on an unsupported dtype.
data_type_error(std::string const &message)
Construct a new data_type_error object with error message.
data_type_error(char const *const message)
Constructs a data_type_error with the error message.
Exception thrown when logical precondition is violated.
logic_error(char const *const message)
Constructs a logic_error with the error message.
logic_error(std::string const &message)
Construct a new logic error object with error message.
The struct to store the current stacktrace upon its construction.
std::string const _stacktrace
The whole stacktrace stored as one string.
char const * stacktrace() const
Get the stored stacktrace captured during object construction.