33 #ifndef GKO_CORE_EXCEPTION_HELPERS_HPP_ 34 #define GKO_CORE_EXCEPTION_HELPERS_HPP_ 37 #include <ginkgo/core/base/dim.hpp> 38 #include <ginkgo/core/base/exception.hpp> 39 #include <ginkgo/core/base/name_demangling.hpp> 55 #define GKO_QUOTE(...) #__VA_ARGS__ 64 #define GKO_NOT_IMPLEMENTED \ 66 throw ::gko::NotImplemented(__FILE__, __LINE__, __func__); \ 69 "This assert is used to counter the false positive extra " \ 70 "semi-colon warnings") 81 #define GKO_NOT_COMPILED(_module) \ 83 throw ::gko::NotCompiled(__FILE__, __LINE__, __func__, \ 84 GKO_QUOTE(_module)); \ 87 "This assert is used to counter the false positive extra " \ 88 "semi-colon warnings") 100 #define GKO_NOT_SUPPORTED(_obj) \ 101 ::gko::NotSupported(__FILE__, __LINE__, __func__, \ 102 ::gko::name_demangling::get_type_name(typeid(_obj))) 108 template <
typename T>
109 inline dim<2> get_size(
const T &op)
111 return op->get_size();
114 inline dim<2> get_size(
const dim<2> &size) {
return size; }
126 #define GKO_ASSERT_IS_SQUARE_MATRIX(_op1) \ 127 if (::gko::detail::get_size(_op1)[0] != \ 128 ::gko::detail::get_size(_op1)[1]) { \ 129 throw ::gko::DimensionMismatch( \ 130 __FILE__, __LINE__, __func__, #_op1, \ 131 ::gko::detail::get_size(_op1)[0], \ 132 ::gko::detail::get_size(_op1)[1], #_op1, \ 133 ::gko::detail::get_size(_op1)[0], \ 134 ::gko::detail::get_size(_op1)[1], "expected square matrix"); \ 143 #define GKO_ASSERT_CONFORMANT(_op1, _op2) \ 144 if (::gko::detail::get_size(_op1)[1] != \ 145 ::gko::detail::get_size(_op2)[0]) { \ 146 throw ::gko::DimensionMismatch(__FILE__, __LINE__, __func__, #_op1, \ 147 ::gko::detail::get_size(_op1)[0], \ 148 ::gko::detail::get_size(_op1)[1], \ 150 ::gko::detail::get_size(_op2)[0], \ 151 ::gko::detail::get_size(_op2)[1], \ 152 "expected matching inner dimensions"); \ 161 #define GKO_ASSERT_EQUAL_ROWS(_op1, _op2) \ 162 if (::gko::detail::get_size(_op1)[0] != \ 163 ::gko::detail::get_size(_op2)[0]) { \ 164 throw ::gko::DimensionMismatch( \ 165 __FILE__, __LINE__, __func__, #_op1, \ 166 ::gko::detail::get_size(_op1)[0], \ 167 ::gko::detail::get_size(_op1)[1], #_op2, \ 168 ::gko::detail::get_size(_op2)[0], \ 169 ::gko::detail::get_size(_op2)[1], "expected matching row length"); \ 179 #define GKO_ASSERT_EQUAL_COLS(_op1, _op2) \ 180 if (::gko::detail::get_size(_op1)[1] != \ 181 ::gko::detail::get_size(_op2)[1]) { \ 182 throw ::gko::DimensionMismatch(__FILE__, __LINE__, __func__, #_op1, \ 183 ::gko::detail::get_size(_op1)[0], \ 184 ::gko::detail::get_size(_op1)[1], \ 186 ::gko::detail::get_size(_op2)[0], \ 187 ::gko::detail::get_size(_op2)[1], \ 188 "expected matching column length"); \ 198 #define GKO_ASSERT_EQUAL_DIMENSIONS(_op1, _op2) \ 199 if (::gko::detail::get_size(_op1) != ::gko::detail::get_size(_op2)) { \ 200 throw ::gko::DimensionMismatch( \ 201 __FILE__, __LINE__, __func__, #_op1, \ 202 ::gko::detail::get_size(_op1)[0], \ 203 ::gko::detail::get_size(_op1)[1], #_op2, \ 204 ::gko::detail::get_size(_op2)[0], \ 205 ::gko::detail::get_size(_op2)[1], "expected equal dimensions"); \ 214 #define GKO_CUDA_ERROR(_errcode) \ 215 ::gko::CudaError(__FILE__, __LINE__, __func__, _errcode) 223 #define GKO_CUBLAS_ERROR(_errcode) \ 224 ::gko::CublasError(__FILE__, __LINE__, __func__, _errcode) 232 #define GKO_CUSPARSE_ERROR(_errcode) \ 233 ::gko::CusparseError(__FILE__, __LINE__, __func__, _errcode) 241 #define GKO_ASSERT_NO_CUDA_ERRORS(_cuda_call) \ 243 auto _errcode = _cuda_call; \ 244 if (_errcode != cudaSuccess) { \ 245 throw GKO_CUDA_ERROR(_errcode); \ 255 #define GKO_ASSERT_NO_CUBLAS_ERRORS(_cublas_call) \ 257 auto _errcode = _cublas_call; \ 258 if (_errcode != CUBLAS_STATUS_SUCCESS) { \ 259 throw GKO_CUBLAS_ERROR(_errcode); \ 269 #define GKO_ASSERT_NO_CUSPARSE_ERRORS(_cusparse_call) \ 271 auto _errcode = _cusparse_call; \ 272 if (_errcode != CUSPARSE_STATUS_SUCCESS) { \ 273 throw GKO_CUSPARSE_ERROR(_errcode); \ 281 template <
typename T>
282 inline T ensure_allocated_impl(T ptr,
const std::string &file,
int line,
285 if (ptr ==
nullptr) {
286 throw AllocationError(file, line, dev, size);
309 #define GKO_ENSURE_ALLOCATED(_ptr, _dev, _size) \ 310 ::gko::detail::ensure_allocated_impl(_ptr, __FILE__, __LINE__, _dev, _size) 321 #define GKO_ENSURE_IN_BOUNDS(_index, _bound) \ 322 if (_index >= _bound) { \ 323 throw ::gko::OutOfBoundsError(__FILE__, __LINE__, _index, _bound); \ 325 static_assert(true, \ 326 "This assert is used to counter the false positive extra " \ 327 "semi-colon warnings") 340 #define GKO_STREAM_ERROR(_message) \ 341 ::gko::StreamError(__FILE__, __LINE__, __func__, _message) 350 #define GKO_KERNEL_NOT_FOUND \ 352 throw ::gko::KernelNotFound(__FILE__, __LINE__, __func__); \ 354 static_assert(true, \ 355 "This assert is used to counter the false positive extra " \ 356 "semi-colon warnings") 362 #endif // GKO_CORE_EXCEPTION_HELPERS_HPP_ std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:94
The Ginkgo namespace.
Definition: abstract_factory.hpp:45