Ginkgo  Generated from pipelines/1478841010 branch based on develop. Ginkgo version 1.9.0
A numerical linear algebra library targeting many-core architectures
exception.hpp
1 // SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_BASE_EXCEPTION_HPP_
6 #define GKO_PUBLIC_CORE_BASE_EXCEPTION_HPP_
7 
8 
9 #include <exception>
10 #include <string>
11 
12 #include <ginkgo/core/base/types.hpp>
13 
14 
15 namespace gko {
16 
17 
57 class Error : public std::exception {
58 public:
66  Error(const std::string& file, int line, const std::string& what)
67  : what_(file + ":" + std::to_string(line) + ": " + what)
68  {}
69 
74  virtual const char* what() const noexcept override { return what_.c_str(); }
75 
76 private:
77  const std::string what_;
78 };
79 
80 
85 class NotImplemented : public Error {
86 public:
94  NotImplemented(const std::string& file, int line, const std::string& func)
95  : Error(file, line, func + " is not implemented")
96  {}
97 };
98 
99 
104 class NotCompiled : public Error {
105 public:
114  NotCompiled(const std::string& file, int line, const std::string& func,
115  const std::string& module)
116  : Error(file, line,
117  "feature " + func + " is part of the " + module +
118  " module, which is not compiled on this system")
119  {}
120 };
121 
122 
127 class NotSupported : public Error {
128 public:
138  NotSupported(const std::string& file, int line, const std::string& func,
139  const std::string& obj_type)
140  : Error(file, line,
141  "Operation " + func + " does not support parameters of type " +
142  obj_type)
143  {}
144 };
145 
146 
150 class MpiError : public Error {
151 public:
159  MpiError(const std::string& file, int line, const std::string& func,
160  int64 error_code)
161  : Error(file, line, func + ": " + get_error(error_code))
162  {}
163 
164 private:
165  static std::string get_error(int64 error_code);
166 };
167 
168 
172 class CudaError : public Error {
173 public:
182  CudaError(const std::string& file, int line, const std::string& func,
183  int64 error_code)
184  : Error(file, line, func + ": " + get_error(error_code))
185  {}
186 
187 private:
188  static std::string get_error(int64 error_code);
189 };
190 
191 
195 class CublasError : public Error {
196 public:
205  CublasError(const std::string& file, int line, const std::string& func,
206  int64 error_code)
207  : Error(file, line, func + ": " + get_error(error_code))
208  {}
209 
210 private:
211  static std::string get_error(int64 error_code);
212 };
213 
214 
218 class CurandError : public Error {
219 public:
228  CurandError(const std::string& file, int line, const std::string& func,
229  int64 error_code)
230  : Error(file, line, func + ": " + get_error(error_code))
231  {}
232 
233 private:
234  static std::string get_error(int64 error_code);
235 };
236 
237 
241 class CusparseError : public Error {
242 public:
251  CusparseError(const std::string& file, int line, const std::string& func,
252  int64 error_code)
253  : Error(file, line, func + ": " + get_error(error_code))
254  {}
255 
256 private:
257  static std::string get_error(int64 error_code);
258 };
259 
260 
264 class CufftError : public Error {
265 public:
274  CufftError(const std::string& file, int line, const std::string& func,
275  int64 error_code)
276  : Error(file, line, func + ": " + get_error(error_code))
277  {}
278 
279 private:
280  static std::string get_error(int64 error_code);
281 };
282 
283 
287 class HipError : public Error {
288 public:
297  HipError(const std::string& file, int line, const std::string& func,
298  int64 error_code)
299  : Error(file, line, func + ": " + get_error(error_code))
300  {}
301 
302 private:
303  static std::string get_error(int64 error_code);
304 };
305 
306 
310 class HipblasError : public Error {
311 public:
320  HipblasError(const std::string& file, int line, const std::string& func,
321  int64 error_code)
322  : Error(file, line, func + ": " + get_error(error_code))
323  {}
324 
325 private:
326  static std::string get_error(int64 error_code);
327 };
328 
329 
333 class HiprandError : public Error {
334 public:
343  HiprandError(const std::string& file, int line, const std::string& func,
344  int64 error_code)
345  : Error(file, line, func + ": " + get_error(error_code))
346  {}
347 
348 private:
349  static std::string get_error(int64 error_code);
350 };
351 
352 
357 class HipsparseError : public Error {
358 public:
367  HipsparseError(const std::string& file, int line, const std::string& func,
368  int64 error_code)
369  : Error(file, line, func + ": " + get_error(error_code))
370  {}
371 
372 private:
373  static std::string get_error(int64 error_code);
374 };
375 
376 
380 class HipfftError : public Error {
381 public:
390  HipfftError(const std::string& file, int line, const std::string& func,
391  int64 error_code)
392  : Error(file, line, func + ": " + get_error(error_code))
393  {}
394 
395 private:
396  static std::string get_error(int64 error_code);
397 };
398 
399 
403 class MetisError : public Error {
404 public:
413  MetisError(const std::string& file, int line, const std::string& func,
414  const std::string& error)
415  : Error(file, line, func + ": " + error)
416  {}
417 };
418 
419 
424 class DimensionMismatch : public Error {
425 public:
440  DimensionMismatch(const std::string& file, int line,
441  const std::string& func, const std::string& first_name,
442  size_type first_rows, size_type first_cols,
443  const std::string& second_name, size_type second_rows,
444  size_type second_cols, const std::string& clarification)
445  : Error(file, line,
446  func + ": attempting to combine operators " + first_name +
447  " [" + std::to_string(first_rows) + " x " +
448  std::to_string(first_cols) + "] and " + second_name + " [" +
449  std::to_string(second_rows) + " x " +
450  std::to_string(second_cols) + "]: " + clarification)
451  {}
452 };
453 
454 
459 class BadDimension : public Error {
460 public:
472  BadDimension(const std::string& file, int line, const std::string& func,
473  const std::string& op_name, size_type op_num_rows,
474  size_type op_num_cols, const std::string& clarification)
475  : Error(file, line,
476  func + ": Object " + op_name + " has dimensions [" +
477  std::to_string(op_num_rows) + " x " +
478  std::to_string(op_num_cols) + "]: " + clarification)
479  {}
480 };
481 
482 
489 template <typename IndexType>
490 class BlockSizeError : public Error {
491 public:
498  BlockSizeError(const std::string& file, const int line,
499  const int block_size, const IndexType size)
500  : Error(file, line,
501  "block size = " + std::to_string(block_size) +
502  ", size = " + std::to_string(size))
503  {}
504 };
505 
506 
510 class ValueMismatch : public Error {
511 public:
522  ValueMismatch(const std::string& file, int line, const std::string& func,
523  size_type val1, size_type val2,
524  const std::string& clarification)
525  : Error(file, line,
526  func + ": Value mismatch : " + std::to_string(val1) + " and " +
527  std::to_string(val2) + " : " + clarification)
528  {}
529 };
530 
531 
535 class AllocationError : public Error {
536 public:
545  AllocationError(const std::string& file, int line,
546  const std::string& device, size_type bytes)
547  : Error(file, line,
548  device + ": failed to allocate memory block of " +
549  std::to_string(bytes) + "B")
550  {}
551 };
552 
553 
558 class OutOfBoundsError : public Error {
559 public:
568  OutOfBoundsError(const std::string& file, int line, size_type index,
569  size_type bound)
570  : Error(file, line,
571  "trying to access index " + std::to_string(index) +
572  " in a memory block of " + std::to_string(bound) +
573  " elements")
574  {}
575 };
576 
577 
582 class OverflowError : public Error {
583 public:
589  OverflowError(const std::string& file, const int line,
590  const std::string& index_type)
591  : Error(file, line, "Overflowing " + index_type)
592  {}
593 };
594 
595 
599 class StreamError : public Error {
600 public:
609  StreamError(const std::string& file, int line, const std::string& func,
610  const std::string& message)
611  : Error(file, line, func + ": " + message)
612  {}
613 };
614 
615 
620 class KernelNotFound : public Error {
621 public:
629  KernelNotFound(const std::string& file, int line, const std::string& func)
630  : Error(file, line, func + ": unable to find an eligible kernel")
631  {}
632 };
633 
634 
642 public:
650  UnsupportedMatrixProperty(const std::string& file, const int line,
651  const std::string& msg)
652  : Error(file, line, msg)
653  {}
654 };
655 
656 
658 class InvalidStateError : public Error {
659 public:
668  InvalidStateError(const std::string& file, int line,
669  const std::string& func, const std::string& clarification)
670  : Error(file, line,
671  func + ": Invalid state encountered : " + clarification)
672  {}
673 };
674 
675 
676 } // namespace gko
677 
678 
679 #endif // GKO_PUBLIC_CORE_BASE_EXCEPTION_HPP_
gko::CudaError
CudaError is thrown when a CUDA routine throws a non-zero error code.
Definition: exception.hpp:172
gko::ValueMismatch
ValueMismatch is thrown if two values are not equal.
Definition: exception.hpp:510
gko::Error::what
virtual const char * what() const noexcept override
Returns a human-readable string with a more detailed description of the error.
Definition: exception.hpp:74
gko::BlockSizeError
Error that denotes issues between block sizes and matrix dimensions.
Definition: exception.hpp:490
gko::NotCompiled::NotCompiled
NotCompiled(const std::string &file, int line, const std::string &func, const std::string &module)
Initializes a NotCompiled error.
Definition: exception.hpp:114
gko::KernelNotFound::KernelNotFound
KernelNotFound(const std::string &file, int line, const std::string &func)
Initializes a KernelNotFound error.
Definition: exception.hpp:629
gko::KernelNotFound
KernelNotFound is thrown if Ginkgo cannot find a kernel which satisfies the criteria imposed by the i...
Definition: exception.hpp:620
gko::HipblasError
HipblasError is thrown when a hipBLAS routine throws a non-zero error code.
Definition: exception.hpp:310
gko::OutOfBoundsError
OutOfBoundsError is thrown if a memory access is detected to be out-of-bounds.
Definition: exception.hpp:558
gko::NotImplemented
NotImplemented is thrown in case an operation has not yet been implemented (but will be implemented i...
Definition: exception.hpp:85
gko::AllocationError::AllocationError
AllocationError(const std::string &file, int line, const std::string &device, size_type bytes)
Initializes an allocation error.
Definition: exception.hpp:545
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:86
gko::OutOfBoundsError::OutOfBoundsError
OutOfBoundsError(const std::string &file, int line, size_type index, size_type bound)
Initializes an OutOfBoundsError.
Definition: exception.hpp:568
gko::InvalidStateError
Exception thrown if an object is in an invalid state.
Definition: exception.hpp:658
gko::UnsupportedMatrixProperty
Exception throws if a matrix does not have a property required by a numerical method.
Definition: exception.hpp:641
gko::NotCompiled
NotCompiled is thrown when attempting to call an operation which is a part of a module that was not c...
Definition: exception.hpp:104
gko::NotSupported::NotSupported
NotSupported(const std::string &file, int line, const std::string &func, const std::string &obj_type)
Initializes a NotSupported error.
Definition: exception.hpp:138
gko::HiprandError::HiprandError
HiprandError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a hipRAND error.
Definition: exception.hpp:343
gko::NotSupported
NotSupported is thrown in case it is not possible to perform the requested operation on the given obj...
Definition: exception.hpp:127
gko::CublasError
CublasError is thrown when a cuBLAS routine throws a non-zero error code.
Definition: exception.hpp:195
gko::MetisError::MetisError
MetisError(const std::string &file, int line, const std::string &func, const std::string &error)
Initializes a METIS error.
Definition: exception.hpp:413
gko::CublasError::CublasError
CublasError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a cuBLAS error.
Definition: exception.hpp:205
gko::MpiError
MpiError is thrown when a MPI routine throws a non-zero error code.
Definition: exception.hpp:150
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
gko::UnsupportedMatrixProperty::UnsupportedMatrixProperty
UnsupportedMatrixProperty(const std::string &file, const int line, const std::string &msg)
Initializes the UnsupportedMatrixProperty error.
Definition: exception.hpp:650
gko::CudaError::CudaError
CudaError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a CUDA error.
Definition: exception.hpp:182
gko::StreamError::StreamError
StreamError(const std::string &file, int line, const std::string &func, const std::string &message)
Initializes a file access error.
Definition: exception.hpp:609
gko::AllocationError
AllocationError is thrown if a memory allocation fails.
Definition: exception.hpp:535
gko::CurandError::CurandError
CurandError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a cuRAND error.
Definition: exception.hpp:228
gko::HipfftError::HipfftError
HipfftError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a hipFFT error.
Definition: exception.hpp:390
gko::BadDimension::BadDimension
BadDimension(const std::string &file, int line, const std::string &func, const std::string &op_name, size_type op_num_rows, size_type op_num_cols, const std::string &clarification)
Initializes a bad dimension error.
Definition: exception.hpp:472
gko::MpiError::MpiError
MpiError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a MPI error.
Definition: exception.hpp:159
gko::OverflowError::OverflowError
OverflowError(const std::string &file, const int line, const std::string &index_type)
Definition: exception.hpp:589
gko::InvalidStateError::InvalidStateError
InvalidStateError(const std::string &file, int line, const std::string &func, const std::string &clarification)
Initializes an invalid state error.
Definition: exception.hpp:668
gko::StreamError
StreamError is thrown if accessing a stream failed.
Definition: exception.hpp:599
gko::CufftError::CufftError
CufftError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a cuFFT error.
Definition: exception.hpp:274
gko::DimensionMismatch
DimensionMismatch is thrown if an operation is being applied to LinOps of incompatible size.
Definition: exception.hpp:424
gko::CusparseError::CusparseError
CusparseError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a cuSPARSE error.
Definition: exception.hpp:251
gko::HipError
HipError is thrown when a HIP routine throws a non-zero error code.
Definition: exception.hpp:287
gko::BadDimension
BadDimension is thrown if an operation is being applied to a LinOp with bad dimensions.
Definition: exception.hpp:459
gko::CufftError
CufftError is thrown when a cuFFT routine throws a non-zero error code.
Definition: exception.hpp:264
gko::OverflowError
OverflowError is thrown when an index calculation for storage requirements overflows.
Definition: exception.hpp:582
gko::Error::Error
Error(const std::string &file, int line, const std::string &what)
Initializes an error.
Definition: exception.hpp:66
gko::int64
std::int64_t int64
64-bit signed integral type.
Definition: types.hpp:109
gko::HipblasError::HipblasError
HipblasError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a hipBLAS error.
Definition: exception.hpp:320
gko::HipError::HipError
HipError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a HIP error.
Definition: exception.hpp:297
gko::CurandError
CurandError is thrown when a cuRAND routine throws a non-zero error code.
Definition: exception.hpp:218
gko::HiprandError
HiprandError is thrown when a hipRAND routine throws a non-zero error code.
Definition: exception.hpp:333
gko::BlockSizeError::BlockSizeError
BlockSizeError(const std::string &file, const int line, const int block_size, const IndexType size)
Definition: exception.hpp:498
gko::HipsparseError
HipsparseError is thrown when a hipSPARSE routine throws a non-zero error code.
Definition: exception.hpp:357
gko::DimensionMismatch::DimensionMismatch
DimensionMismatch(const std::string &file, int line, const std::string &func, const std::string &first_name, size_type first_rows, size_type first_cols, const std::string &second_name, size_type second_rows, size_type second_cols, const std::string &clarification)
Initializes a dimension mismatch error.
Definition: exception.hpp:440
gko::HipfftError
HipfftError is thrown when a hipFFT routine throws a non-zero error code.
Definition: exception.hpp:380
gko::ValueMismatch::ValueMismatch
ValueMismatch(const std::string &file, int line, const std::string &func, size_type val1, size_type val2, const std::string &clarification)
Initializes a value mismatch error.
Definition: exception.hpp:522
gko::CusparseError
CusparseError is thrown when a cuSPARSE routine throws a non-zero error code.
Definition: exception.hpp:241
gko::HipsparseError::HipsparseError
HipsparseError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a hipSPARSE error.
Definition: exception.hpp:367
gko::MetisError
MetisError is thrown when METIS routine throws an error code.
Definition: exception.hpp:403
gko::Error
The Error class is used to report exceptional behaviour in library functions.
Definition: exception.hpp:57
gko::NotImplemented::NotImplemented
NotImplemented(const std::string &file, int line, const std::string &func)
Initializes a NotImplemented error.
Definition: exception.hpp:94