9 #include <cudf/utilities/export.hpp>
12 #include <cuda_runtime_api.h>
16 #include <type_traits>
23 namespace CUDF_EXPORT
cudf {
70 explicit cuda_error(std::string
const& message, cudaError_t
const& error)
71 : std::runtime_error(message), _cudaError(error)
80 [[nodiscard]] cudaError_t
error_code()
const {
return _cudaError; }
87 using cuda_error::cuda_error;
103 explicit data_type_error(
char const*
const message) : std::invalid_argument(message) {}
110 explicit data_type_error(std::string
const& message) : std::invalid_argument(message) {}
131 [[nodiscard]]
char const*
what() const noexcept
override {
return message_.c_str(); }
141 std::string message_;
148 #define STRINGIFY_DETAIL(x) #x
149 #define CUDF_STRINGIFY(x) STRINGIFY_DETAIL(x)
182 #define CUDF_EXPECTS(...) \
183 GET_CUDF_EXPECTS_MACRO(__VA_ARGS__, CUDF_EXPECTS_3, CUDF_EXPECTS_2) \
188 #define GET_CUDF_EXPECTS_MACRO(_1, _2, _3, NAME, ...) NAME
190 #define CUDF_EXPECTS_3(_condition, _reason, _exception_type) \
192 static_assert(std::is_base_of_v<std::exception, _exception_type>); \
193 if (!(_condition)) { \
194 cudf::detail::cudf_fail<_exception_type>( \
195 [&]() -> std::string { return _reason; }, __LINE__, __FILE__); \
199 #define CUDF_EXPECTS_2(_condition, _reason) CUDF_EXPECTS_3(_condition, _reason, cudf::logic_error)
223 #define CUDF_FAIL(...) \
224 GET_CUDF_FAIL_MACRO(__VA_ARGS__, CUDF_FAIL_2, CUDF_FAIL_1) \
229 #define GET_CUDF_FAIL_MACRO(_1, _2, NAME, ...) NAME
231 #define CUDF_FAIL_2(_what, _exception_type) \
232 cudf::detail::cudf_fail<_exception_type>( \
233 [&]() -> std::string { return _what; }, __LINE__, __FILE__)
235 #define CUDF_FAIL_1(_what) CUDF_FAIL_2(_what, cudf::logic_error)
239 namespace CUDF_EXPORT
cudf {
242 inline void throw_cuda_error(cudaError_t error,
char const* file,
unsigned int line)
247 auto const last = cudaFree(
nullptr);
248 auto const msg = std::string{
"CUDA error encountered at: " + std::string{file} +
":" +
250 cudaGetErrorName(error) +
" " + cudaGetErrorString(error)};
253 if (error == last && last == cudaDeviceSynchronize()) {
254 throw fatal_cuda_error{
"Fatal " + msg, error};
256 throw cuda_error{msg, error};
262 template <
typename Exception,
typename MsgFunc>
263 [[noreturn]]
void cudf_fail(MsgFunc&& msg_func,
int line_number,
char const* filename)
265 std::string
const msg = std::forward<MsgFunc>(msg_func)();
266 throw Exception{std::string{
"CUDF failure at: "} + filename +
":" +
std::to_string(line_number) +
267 ": " + (msg.empty() ?
"(no message)" : msg)};
280 #define CUDF_CUDA_TRY(call) \
282 cudaError_t const status = (call); \
283 if (cudaSuccess != status) { cudf::detail::throw_cuda_error(status, __FILE__, __LINE__); } \
300 #define CUDF_CHECK_CUDA(stream) \
302 CUDF_CUDA_TRY(cudaStreamSynchronize(stream)); \
303 CUDF_CUDA_TRY(cudaPeekAtLastError()); \
306 #define CUDF_CHECK_CUDA(stream) CUDF_CUDA_TRY(cudaPeekAtLastError());
Error codes for libcudf operations.
constexpr char const * to_string(errc error)
Convert an errc error code to a human-readable string.
errc
An enumeration of error codes that can occur during operations.
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 type thrown when evaluating an operator function results in an error (e....
char const * what() const noexcept override
Get the error message.
evaluation_error(errc error, std::string message)
Construct a new evaluation error object.
errc error_code() const
Get the error code that occurred during evaluation.
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.