19 #include <rmm/error.hpp>
21 #include <cuda_runtime_api.h>
27 #define STRINGIFY_DETAIL(x) #x
28 #define RMM_STRINGIFY(x) STRINGIFY_DETAIL(x)
54 #define RMM_EXPECTS(...) \
55 GET_RMM_EXPECTS_MACRO(__VA_ARGS__, RMM_EXPECTS_3, RMM_EXPECTS_2) \
57 #define GET_RMM_EXPECTS_MACRO(_1, _2, _3, NAME, ...) NAME
58 #define RMM_EXPECTS_3(_condition, _reason, _exception_type) \
59 (!!(_condition)) ? static_cast<void>(0) \
60 : throw _exception_type \
62 "RMM failure at: " __FILE__ ":" RMM_STRINGIFY(__LINE__) ": " _reason \
64 #define RMM_EXPECTS_2(_condition, _reason) RMM_EXPECTS_3(_condition, _reason, rmm::logic_error)
78 #define RMM_FAIL(...) \
79 GET_RMM_FAIL_MACRO(__VA_ARGS__, RMM_FAIL_2, RMM_FAIL_1) \
81 #define GET_RMM_FAIL_MACRO(_1, _2, NAME, ...) NAME
82 #define RMM_FAIL_2(_what, _exception_type) \
84 throw _exception_type{"RMM failure at:" __FILE__ ":" RMM_STRINGIFY(__LINE__) ": " _what};
85 #define RMM_FAIL_1(_what) RMM_FAIL_2(_what, rmm::logic_error)
108 #define RMM_CUDA_TRY(...) \
109 GET_RMM_CUDA_TRY_MACRO(__VA_ARGS__, RMM_CUDA_TRY_2, RMM_CUDA_TRY_1) \
111 #define GET_RMM_CUDA_TRY_MACRO(_1, _2, NAME, ...) NAME
112 #define RMM_CUDA_TRY_2(_call, _exception_type) \
114 cudaError_t const error = (_call); \
115 if (cudaSuccess != error) { \
116 cudaGetLastError(); \
118 throw _exception_type{std::string{"CUDA error at: "} + __FILE__ + ":" + \
119 RMM_STRINGIFY(__LINE__) + ": " + cudaGetErrorName(error) + " " + \
120 cudaGetErrorString(error)}; \
123 #define RMM_CUDA_TRY_1(_call) RMM_CUDA_TRY_2(_call, rmm::cuda_error)
135 #define RMM_CUDA_TRY_ALLOC(_call) \
137 cudaError_t const error = (_call); \
138 if (cudaSuccess != error) { \
139 cudaGetLastError(); \
140 auto const msg = std::string{"CUDA error at: "} + __FILE__ + ":" + RMM_STRINGIFY(__LINE__) + \
141 ": " + cudaGetErrorName(error) + " " + cudaGetErrorString(error); \
142 if (cudaErrorMemoryAllocation == error) { throw rmm::out_of_memory{msg}; } \
143 throw rmm::bad_alloc{msg}; \
173 #define RMM_ASSERT_CUDA_SUCCESS(_call) \
178 #define RMM_ASSERT_CUDA_SUCCESS(_call) \
180 cudaError_t const status__ = (_call); \
181 if (status__ != cudaSuccess) { \
182 std::cerr << "CUDA Error detected. " << cudaGetErrorName(status__) << " " \
183 << cudaGetErrorString(status__) << std::endl; \
186 assert(status__ == cudaSuccess); \