19 #include <cuda_runtime_api.h>
38 using std::logic_error::logic_error;
48 using std::runtime_error::runtime_error;
76 [[nodiscard]]
const char*
what() const noexcept
override {
return _what.c_str(); }
113 using std::out_of_range::out_of_range;
118 #define STRINGIFY_DETAIL(x) #x
119 #define RMM_STRINGIFY(x) STRINGIFY_DETAIL(x)
145 #define RMM_EXPECTS(...) \
146 GET_RMM_EXPECTS_MACRO(__VA_ARGS__, RMM_EXPECTS_3, RMM_EXPECTS_2) \
148 #define GET_RMM_EXPECTS_MACRO(_1, _2, _3, NAME, ...) NAME
149 #define RMM_EXPECTS_3(_condition, _reason, _exception_type) \
150 (!!(_condition)) ? static_cast<void>(0) \
151 : throw _exception_type \
153 "RMM failure at: " __FILE__ ":" RMM_STRINGIFY(__LINE__) ": " _reason \
155 #define RMM_EXPECTS_2(_condition, _reason) RMM_EXPECTS_3(_condition, _reason, rmm::logic_error)
169 #define RMM_FAIL(...) \
170 GET_RMM_FAIL_MACRO(__VA_ARGS__, RMM_FAIL_2, RMM_FAIL_1) \
172 #define GET_RMM_FAIL_MACRO(_1, _2, NAME, ...) NAME
173 #define RMM_FAIL_2(_what, _exception_type) \
175 throw _exception_type{"RMM failure at:" __FILE__ ":" RMM_STRINGIFY(__LINE__) ": " _what};
176 #define RMM_FAIL_1(_what) RMM_FAIL_2(_what, rmm::logic_error)
199 #define RMM_CUDA_TRY(...) \
200 GET_RMM_CUDA_TRY_MACRO(__VA_ARGS__, RMM_CUDA_TRY_2, RMM_CUDA_TRY_1) \
202 #define GET_RMM_CUDA_TRY_MACRO(_1, _2, NAME, ...) NAME
203 #define RMM_CUDA_TRY_2(_call, _exception_type) \
205 cudaError_t const error = (_call); \
206 if (cudaSuccess != error) { \
207 cudaGetLastError(); \
209 throw _exception_type{std::string{"CUDA error at: "} + __FILE__ + ":" + \
210 RMM_STRINGIFY(__LINE__) + ": " + cudaGetErrorName(error) + " " + \
211 cudaGetErrorString(error)}; \
214 #define RMM_CUDA_TRY_1(_call) RMM_CUDA_TRY_2(_call, rmm::cuda_error)
226 #define RMM_CUDA_TRY_ALLOC(_call) \
228 cudaError_t const error = (_call); \
229 if (cudaSuccess != error) { \
230 cudaGetLastError(); \
231 auto const msg = std::string{"CUDA error at: "} + __FILE__ + ":" + RMM_STRINGIFY(__LINE__) + \
232 ": " + cudaGetErrorName(error) + " " + cudaGetErrorString(error); \
233 if (cudaErrorMemoryAllocation == error) { \
234 throw rmm::out_of_memory{msg}; \
236 throw rmm::bad_alloc{msg}; \
267 #define RMM_ASSERT_CUDA_SUCCESS(_call) \
272 #define RMM_ASSERT_CUDA_SUCCESS(_call) \
274 cudaError_t const status__ = (_call); \
275 if (status__ != cudaSuccess) { \
276 std::cerr << "CUDA Error detected. " << cudaGetErrorName(status__) << " " \
277 << cudaGetErrorString(status__) << std::endl; \
280 assert(status__ == cudaSuccess); \
Exception thrown when an RMM allocation fails.
Definition: error.hpp:57
const char * what() const noexcept override
The explanatory string.
Definition: error.hpp:76
bad_alloc(std::string const &msg)
Constructs a bad_alloc with the error message.
Definition: error.hpp:71
bad_alloc(const char *msg)
Constructs a bad_alloc with the error message.
Definition: error.hpp:64
Exception thrown when RMM runs out of memory.
Definition: error.hpp:89
out_of_memory(std::string const &msg)
Constructs an out_of_memory with the error message.
Definition: error.hpp:103
out_of_memory(const char *msg)
Constructs an out_of_memory with the error message.
Definition: error.hpp:96
Exception thrown when attempting to access outside of a defined range.
Definition: error.hpp:112
Exception thrown when a CUDA error is encountered.
Definition: error.hpp:47
Exception thrown when logical precondition is violated.
Definition: error.hpp:37