error.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cuda.h>
4 #include <cuda_runtime_api.h>
5 #include <stdexcept>
6 #include <string>
7 
8 namespace cudf {
21 struct logic_error : public std::logic_error {
22  logic_error(char const* const message) : std::logic_error(message) {}
23 
24  logic_error(std::string const& message) : std::logic_error(message) {}
25 
26  // TODO Add an error code member? This would be useful for translating an
27  // exception to an error code in a pure-C API
28 };
32 struct cuda_error : public std::runtime_error {
33  cuda_error(std::string const& message) : std::runtime_error(message) {}
34 };
37 } // namespace cudf
38 
39 #define STRINGIFY_DETAIL(x) #x
40 #define CUDF_STRINGIFY(x) STRINGIFY_DETAIL(x)
41 
62 #define CUDF_EXPECTS(cond, reason) \
63  (!!(cond)) ? static_cast<void>(0) \
64  : throw cudf::logic_error("cuDF failure at: " __FILE__ \
65  ":" CUDF_STRINGIFY(__LINE__) ": " reason)
66 
80 #define CUDF_FAIL(reason) \
81  throw cudf::logic_error("cuDF failure at: " __FILE__ ":" CUDF_STRINGIFY(__LINE__) ": " reason)
82 
83 namespace cudf {
84 namespace detail {
85 
86 inline void throw_cuda_error(cudaError_t error, const char* file, unsigned int line)
87 {
88  throw cudf::cuda_error(std::string{"CUDA error encountered at: " + std::string{file} + ":" +
89  std::to_string(line) + ": " + std::to_string(error) + " " +
90  cudaGetErrorName(error) + " " + cudaGetErrorString(error)});
91 }
92 } // namespace detail
93 } // namespace cudf
94 
102 #define CUDA_TRY(call) \
103  do { \
104  cudaError_t const status = (call); \
105  if (cudaSuccess != status) { \
106  cudaGetLastError(); \
107  cudf::detail::throw_cuda_error(status, __FILE__, __LINE__); \
108  } \
109  } while (0);
110 
124 #ifndef NDEBUG
125 #define CHECK_CUDA(stream) \
126  do { \
127  CUDA_TRY(cudaStreamSynchronize(stream)); \
128  CUDA_TRY(cudaPeekAtLastError()); \
129  } while (0);
130 #else
131 #define CHECK_CUDA(stream) CUDA_TRY(cudaPeekAtLastError());
132 #endif
133 
cudf::cuda_error
Exception thrown when a CUDA error is encountered.
Definition: error.hpp:32
cudf
cuDF interfaces
Definition: aggregation.hpp:34
cudf::logic_error
Exception thrown when logical precondition is violated.
Definition: error.hpp:21