10 #include <rapidsmpf/utils.hpp>
21 using std::runtime_error::runtime_error;
52 [[nodiscard]]
const char*
what() const noexcept
override {
109 #define RAPIDSMPF_EXPECTS(...) \
110 GET_RAPIDSMPF_EXPECTS_MACRO(__VA_ARGS__, RAPIDSMPF_EXPECTS_3, RAPIDSMPF_EXPECTS_2) \
113 #define GET_RAPIDSMPF_EXPECTS_MACRO(_1, _2, _3, NAME, ...) NAME
115 #define RAPIDSMPF_EXPECTS_3(_condition, _reason, _exception_type) \
117 static_assert(std::is_base_of_v<std::exception, _exception_type>); \
118 (_condition) ? static_cast<void>(0) \
119 : throw _exception_type \
120 {"RAPIDSMPF failure at: " __FILE__ \
121 ":" RAPIDSMPF_STRINGIFY(__LINE__) ": " _reason}; \
124 #define RAPIDSMPF_EXPECTS_2(_condition, _reason) \
125 RAPIDSMPF_EXPECTS_3(_condition, _reason, std::logic_error)
148 #define RAPIDSMPF_FAIL(...) \
149 GET_RAPIDSMPF_FAIL_MACRO(__VA_ARGS__, RAPIDSMPF_FAIL_2, RAPIDSMPF_FAIL_1) \
152 #define GET_RAPIDSMPF_FAIL_MACRO(_1, _2, NAME, ...) NAME
154 #define RAPIDSMPF_FAIL_2(_what, _exception_type) \
156 throw _exception_type { \
157 "RAPIDSMPF failure at:" __FILE__ ":" RAPIDSMPF_STRINGIFY(__LINE__) ": " _what \
160 #define RAPIDSMPF_FAIL_1(_what) RAPIDSMPF_FAIL_2(_what, std::logic_error)
183 #define RAPIDSMPF_CUDA_TRY(...) \
184 GET_RAPIDSMPF_CUDA_TRY_MACRO( \
185 __VA_ARGS__, RAPIDSMPF_CUDA_TRY_2, RAPIDSMPF_CUDA_TRY_1 \
188 #define GET_RAPIDSMPF_CUDA_TRY_MACRO(_1, _2, NAME, ...) NAME
189 #define RAPIDSMPF_CUDA_TRY_2(_call, _exception_type) \
191 cudaError_t const error = (_call); \
192 if (cudaSuccess != error) { \
193 cudaGetLastError(); \
195 throw _exception_type{ \
196 std::string{"CUDA error at: "} + __FILE__ + ":" \
197 + RAPIDSMPF_STRINGIFY(__LINE__) + ": " + cudaGetErrorName(error) + " " \
198 + cudaGetErrorString(error) \
202 #define RAPIDSMPF_CUDA_TRY_1(_call) RAPIDSMPF_CUDA_TRY_2(_call, rapidsmpf::cuda_error)
219 #define RAPIDSMPF_CUDA_TRY_ALLOC(...) \
220 GET_RAPIDSMPF_CUDA_TRY_ALLOC_MACRO( \
221 __VA_ARGS__, RAPIDSMPF_CUDA_TRY_ALLOC_2, RAPIDSMPF_CUDA_TRY_ALLOC_1 \
224 #define GET_RAPIDSMPF_CUDA_TRY_ALLOC_MACRO(_1, _2, NAME, ...) NAME
226 #define RAPIDSMPF_CUDA_TRY_ALLOC_2(_call, num_bytes) \
228 cudaError_t const error = (_call); \
229 if (cudaSuccess != error) { \
230 cudaGetLastError(); \
231 auto const msg = std::string{"CUDA error (failed to allocate "} \
232 + std::to_string(num_bytes) + " bytes) at: " + __FILE__ \
233 + ":" + RAPIDSMPF_STRINGIFY(__LINE__) + ": " \
234 + cudaGetErrorName(error) + " " \
235 + cudaGetErrorString(error); \
236 if (cudaErrorMemoryAllocation == error) { \
237 throw rapidsmpf::out_of_memory{msg}; \
239 throw rapidsmpf::bad_alloc{msg}; \
243 #define RAPIDSMPF_CUDA_TRY_ALLOC_1(_call) \
245 cudaError_t const error = (_call); \
246 if (cudaSuccess != error) { \
247 cudaGetLastError(); \
248 auto const msg = std::string{"CUDA error at: "} + __FILE__ + ":" \
249 + RAPIDSMPF_STRINGIFY(__LINE__) + ": " \
250 + cudaGetErrorName(error) + " " \
251 + cudaGetErrorString(error); \
252 if (cudaErrorMemoryAllocation == error) { \
253 throw rapidsmpf::out_of_memory{msg}; \
255 throw rapidsmpf::bad_alloc{msg}; \
285 #define RAPIDSMPF_ASSERT_CUDA_SUCCESS(_call) \
290 #define RAPIDSMPF_ASSERT_CUDA_SUCCESS(_call) \
292 cudaError_t const status__ = (_call); \
293 if (status__ != cudaSuccess) { \
294 std::cerr << "CUDA Error detected. " << cudaGetErrorName(status__) << " " \
295 << cudaGetErrorString(status__) << std::endl; \
298 assert(status__ == cudaSuccess); \
Exception thrown when an RapidsMPF allocation fails.
const char * what() const noexcept override
Returns the explanatory string.
bad_alloc(std::string const &msg)
Constructs a bad_alloc with the error message.
bad_alloc(const char *msg)
Constructs a bad_alloc with the error message.
Exception thrown when RapidsMPF runs out of memory.
out_of_memory(std::string const &msg)
Constructs an out_of_memory with the error message.
out_of_memory(const char *msg)
Constructs an out_of_memory with the error message.
Exception thrown when a CUDA error is encountered.