|
21 | 21 | #include <cuda_runtime_api.h>
|
22 | 22 |
|
23 | 23 | #include <cassert>
|
| 24 | +#include <exception> |
24 | 25 | #include <iostream>
|
25 | 26 | #include <string>
|
| 27 | +#include <type_traits> |
26 | 28 |
|
27 | 29 | #define STRINGIFY_DETAIL(x) #x
|
28 | 30 | #define RMM_STRINGIFY(x) STRINGIFY_DETAIL(x)
|
|
55 | 57 | GET_RMM_EXPECTS_MACRO(__VA_ARGS__, RMM_EXPECTS_3, RMM_EXPECTS_2) \
|
56 | 58 | (__VA_ARGS__)
|
57 | 59 | #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 /*NOLINT(bugprone-macro-parentheses)*/ \ |
61 |
| - { \ |
62 |
| - std::string("RMM failure at: " __FILE__ ":" RMM_STRINGIFY(__LINE__) ": ") + _reason \ |
63 |
| - } |
| 60 | +#define RMM_EXPECTS_3(_condition, _reason, _exception_type) \ |
| 61 | + do { \ |
| 62 | + static_assert(std::is_base_of_v<std::exception, _exception_type>); \ |
| 63 | + /*NOLINTNEXTLINE(bugprone-macro-parentheses)*/ \ |
| 64 | + (!!(_condition)) ? static_cast<void>(0) \ |
| 65 | + : throw _exception_type{std::string{"RMM failure at: "} + __FILE__ + ":" + \ |
| 66 | + RMM_STRINGIFY(__LINE__) + ": " + _reason}; \ |
| 67 | + } while (0) |
64 | 68 | #define RMM_EXPECTS_2(_condition, _reason) RMM_EXPECTS_3(_condition, _reason, rmm::logic_error)
|
65 | 69 |
|
66 | 70 | /**
|
|
79 | 83 | GET_RMM_FAIL_MACRO(__VA_ARGS__, RMM_FAIL_2, RMM_FAIL_1) \
|
80 | 84 | (__VA_ARGS__)
|
81 | 85 | #define GET_RMM_FAIL_MACRO(_1, _2, NAME, ...) NAME
|
82 |
| -#define RMM_FAIL_2(_what, _exception_type) \ |
83 |
| - /*NOLINTNEXTLINE(bugprone-macro-parentheses)*/ \ |
84 |
| - throw _exception_type{std::string{"RMM failure at:" __FILE__ ":" RMM_STRINGIFY(__LINE__) ": "} + \ |
85 |
| - _what}; |
| 86 | +#define RMM_FAIL_2(_what, _exception_type) \ |
| 87 | + /*NOLINTNEXTLINE(bugprone-macro-parentheses)*/ \ |
| 88 | + throw _exception_type \ |
| 89 | + { \ |
| 90 | + std::string{"RMM failure at:"} + __FILE__ + ":" + RMM_STRINGIFY(__LINE__) + ": " + _what \ |
| 91 | + } |
86 | 92 | #define RMM_FAIL_1(_what) RMM_FAIL_2(_what, rmm::logic_error)
|
87 | 93 |
|
88 | 94 | /**
|
|
0 commit comments