Ginkgo  Generated from pipelines/2837190956 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
exception.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 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 #include <typeinfo>
12 
13 #include <ginkgo/core/base/name_demangling.hpp>
14 #include <ginkgo/core/base/types.hpp>
15 
16 
17 namespace gko {
18 
19 
58 class Error : public std::runtime_error {
59 public:
67  Error(const std::string& file, int line, const std::string& what)
68  : std::runtime_error(file + ":" + std::to_string(line) + ": " + what)
69  {}
70 };
71 
72 
77 class NotImplemented : public Error {
78 public:
86  NotImplemented(const std::string& file, int line, const std::string& func)
87  : Error(file, line, func + " is not implemented")
88  {}
89 };
90 
91 
96 class NotCompiled : public Error {
97 public:
106  NotCompiled(const std::string& file, int line, const std::string& func,
107  const std::string& module)
108  : Error(file, line,
109  "feature " + func + " is part of the " + module +
110  " module, which is not compiled on this system")
111  {}
112 };
113 
114 
119 class NotSupported : public Error {
120 public:
130  NotSupported(const std::string& file, int line, const std::string& func,
131  const std::string& obj_type)
132  : Error(file, line,
133  "Operation " + func + " does not support parameters of type " +
134  obj_type)
135  {}
136 };
137 
138 
142 class MpiError : public Error {
143 public:
151  MpiError(const std::string& file, int line, const std::string& func,
152  int64 error_code)
153  : Error(file, line, func + ": " + get_error(error_code))
154  {}
155 
156 private:
157  static std::string get_error(int64 error_code);
158 };
159 
160 
164 class CudaError : public Error {
165 public:
174  CudaError(const std::string& file, int line, const std::string& func,
175  int64 error_code)
176  : Error(file, line, func + ": " + get_error(error_code))
177  {}
178 
179 private:
180  static std::string get_error(int64 error_code);
181 };
182 
183 
187 class CublasError : public Error {
188 public:
197  CublasError(const std::string& file, int line, const std::string& func,
198  int64 error_code)
199  : Error(file, line, func + ": " + get_error(error_code))
200  {}
201 
202 private:
203  static std::string get_error(int64 error_code);
204 };
205 
206 
210 class CurandError : public Error {
211 public:
220  CurandError(const std::string& file, int line, const std::string& func,
221  int64 error_code)
222  : Error(file, line, func + ": " + get_error(error_code))
223  {}
224 
225 private:
226  static std::string get_error(int64 error_code);
227 };
228 
229 
233 class CusparseError : public Error {
234 public:
243  CusparseError(const std::string& file, int line, const std::string& func,
244  int64 error_code)
245  : Error(file, line, func + ": " + get_error(error_code))
246  {}
247 
248 private:
249  static std::string get_error(int64 error_code);
250 };
251 
252 
256 class CufftError : public Error {
257 public:
266  CufftError(const std::string& file, int line, const std::string& func,
267  int64 error_code)
268  : Error(file, line, func + ": " + get_error(error_code))
269  {}
270 
271 private:
272  static std::string get_error(int64 error_code);
273 };
274 
275 
279 class HipError : public Error {
280 public:
289  HipError(const std::string& file, int line, const std::string& func,
290  int64 error_code)
291  : Error(file, line, func + ": " + get_error(error_code))
292  {}
293 
294 private:
295  static std::string get_error(int64 error_code);
296 };
297 
298 
302 class HipblasError : public Error {
303 public:
312  HipblasError(const std::string& file, int line, const std::string& func,
313  int64 error_code)
314  : Error(file, line, func + ": " + get_error(error_code))
315  {}
316 
317 private:
318  static std::string get_error(int64 error_code);
319 };
320 
321 
325 class HiprandError : public Error {
326 public:
335  HiprandError(const std::string& file, int line, const std::string& func,
336  int64 error_code)
337  : Error(file, line, func + ": " + get_error(error_code))
338  {}
339 
340 private:
341  static std::string get_error(int64 error_code);
342 };
343 
344 
349 class HipsparseError : public Error {
350 public:
359  HipsparseError(const std::string& file, int line, const std::string& func,
360  int64 error_code)
361  : Error(file, line, func + ": " + get_error(error_code))
362  {}
363 
364 private:
365  static std::string get_error(int64 error_code);
366 };
367 
368 
372 class HipfftError : public Error {
373 public:
382  HipfftError(const std::string& file, int line, const std::string& func,
383  int64 error_code)
384  : Error(file, line, func + ": " + get_error(error_code))
385  {}
386 
387 private:
388  static std::string get_error(int64 error_code);
389 };
390 
391 
395 class MetisError : public Error {
396 public:
405  MetisError(const std::string& file, int line, const std::string& func,
406  const std::string& error)
407  : Error(file, line, func + ": " + error)
408  {}
409 };
410 
411 
416 class DimensionMismatch : public Error {
417 public:
432  DimensionMismatch(const std::string& file, int line,
433  const std::string& func, const std::string& first_name,
434  size_type first_rows, size_type first_cols,
435  const std::string& second_name, size_type second_rows,
436  size_type second_cols, const std::string& clarification)
437  : Error(file, line,
438  func + ": attempting to combine operators " + first_name +
439  " [" + std::to_string(first_rows) + " x " +
440  std::to_string(first_cols) + "] and " + second_name + " [" +
441  std::to_string(second_rows) + " x " +
442  std::to_string(second_cols) + "]: " + clarification)
443  {}
444 };
445 
446 
451 class BadDimension : public Error {
452 public:
464  BadDimension(const std::string& file, int line, const std::string& func,
465  const std::string& op_name, size_type op_num_rows,
466  size_type op_num_cols, const std::string& clarification)
467  : Error(file, line,
468  func + ": Object " + op_name + " has dimensions [" +
469  std::to_string(op_num_rows) + " x " +
470  std::to_string(op_num_cols) + "]: " + clarification)
471  {}
472 };
473 
474 
481 template <typename IndexType>
482 class BlockSizeError : public Error {
483 public:
490  BlockSizeError(const std::string& file, const int line,
491  const int block_size, const IndexType size)
492  : Error(file, line,
493  "block size = " + std::to_string(block_size) +
494  ", size = " + std::to_string(size))
495  {}
496 };
497 
498 
502 class ValueMismatch : public Error {
503 public:
514  ValueMismatch(const std::string& file, int line, const std::string& func,
515  size_type val1, size_type val2,
516  const std::string& clarification)
517  : Error(file, line,
518  func + ": Value mismatch : " + std::to_string(val1) + " and " +
519  std::to_string(val2) + " : " + clarification)
520  {}
521 };
522 
523 
527 class AllocationError : public Error {
528 public:
537  AllocationError(const std::string& file, int line,
538  const std::string& device, size_type bytes)
539  : Error(file, line,
540  device + ": failed to allocate memory block of " +
541  std::to_string(bytes) + "B")
542  {}
543 };
544 
545 
550 class OutOfBoundsError : public Error {
551 public:
560  OutOfBoundsError(const std::string& file, int line, size_type index,
561  size_type bound)
562  : Error(file, line,
563  "trying to access index " + std::to_string(index) +
564  " in a memory block of " + std::to_string(bound) +
565  " elements")
566  {}
567 };
568 
569 
574 class OverflowError : public Error {
575 public:
581  OverflowError(const std::string& file, const int line,
582  const std::string& index_type)
583  : Error(file, line, "Overflowing " + index_type)
584  {}
585 };
586 
587 
591 class StreamError : public Error {
592 public:
601  StreamError(const std::string& file, int line, const std::string& func,
602  const std::string& message)
603  : Error(file, line, func + ": " + message)
604  {}
605 };
606 
607 
612 class KernelNotFound : public Error {
613 public:
621  KernelNotFound(const std::string& file, int line, const std::string& func)
622  : Error(file, line, func + ": unable to find an eligible kernel")
623  {}
624 };
625 
626 
634 public:
642  UnsupportedMatrixProperty(const std::string& file, const int line,
643  const std::string& msg)
644  : Error(file, line, msg)
645  {}
646 };
647 
648 
650 class InvalidStateError : public Error {
651 public:
660  InvalidStateError(const std::string& file, int line,
661  const std::string& func, const std::string& clarification)
662  : Error(file, line,
663  func + ": Invalid state encountered : " + clarification)
664  {}
665 };
666 
667 
673 class InvalidData : public Error {
674 public:
683  InvalidData(const std::string& file, int line, const std::type_info& type,
684  const std::string& invariant)
685  : Error(file, line,
686  "Invariant violated in " +
687  name_demangling::get_type_name(type) + ": " + invariant)
688  {}
689 };
690 
691 
692 } // namespace gko
693 
694 
695 #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:164
gko::ValueMismatch
ValueMismatch is thrown if two values are not equal.
Definition: exception.hpp:502
gko::BlockSizeError
Error that denotes issues between block sizes and matrix dimensions.
Definition: exception.hpp:482
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:106
gko::KernelNotFound::KernelNotFound
KernelNotFound(const std::string &file, int line, const std::string &func)
Initializes a KernelNotFound error.
Definition: exception.hpp:621
gko::KernelNotFound
KernelNotFound is thrown if Ginkgo cannot find a kernel which satisfies the criteria imposed by the i...
Definition: exception.hpp:612
gko::HipblasError
HipblasError is thrown when a hipBLAS routine throws a non-zero error code.
Definition: exception.hpp:302
gko::OutOfBoundsError
OutOfBoundsError is thrown if a memory access is detected to be out-of-bounds.
Definition: exception.hpp:550
gko::NotImplemented
NotImplemented is thrown in case an operation has not yet been implemented (but will be implemented i...
Definition: exception.hpp:77
gko::AllocationError::AllocationError
AllocationError(const std::string &file, int line, const std::string &device, size_type bytes)
Initializes an allocation error.
Definition: exception.hpp:537
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:101
gko::OutOfBoundsError::OutOfBoundsError
OutOfBoundsError(const std::string &file, int line, size_type index, size_type bound)
Initializes an OutOfBoundsError.
Definition: exception.hpp:560
gko::InvalidStateError
Exception thrown if an object is in an invalid state.
Definition: exception.hpp:650
gko::UnsupportedMatrixProperty
Exception throws if a matrix does not have a property required by a numerical method.
Definition: exception.hpp:633
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:96
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:130
gko::HiprandError::HiprandError
HiprandError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a hipRAND error.
Definition: exception.hpp:335
gko::NotSupported
NotSupported is thrown in case it is not possible to perform the requested operation on the given obj...
Definition: exception.hpp:119
gko::InvalidData::InvalidData
InvalidData(const std::string &file, int line, const std::type_info &type, const std::string &invariant)
Initializes an InvalidData error.
Definition: exception.hpp:683
gko::CublasError
CublasError is thrown when a cuBLAS routine throws a non-zero error code.
Definition: exception.hpp:187
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:405
gko::CublasError::CublasError
CublasError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a cuBLAS error.
Definition: exception.hpp:197
gko::MpiError
MpiError is thrown when a MPI routine throws a non-zero error code.
Definition: exception.hpp:142
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:19
gko::UnsupportedMatrixProperty::UnsupportedMatrixProperty
UnsupportedMatrixProperty(const std::string &file, const int line, const std::string &msg)
Initializes the UnsupportedMatrixProperty error.
Definition: exception.hpp:642
gko::CudaError::CudaError
CudaError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a CUDA error.
Definition: exception.hpp:174
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:601
gko::AllocationError
AllocationError is thrown if a memory allocation fails.
Definition: exception.hpp:527
gko::CurandError::CurandError
CurandError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a cuRAND error.
Definition: exception.hpp:220
gko::HipfftError::HipfftError
HipfftError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a hipFFT error.
Definition: exception.hpp:382
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:464
gko::MpiError::MpiError
MpiError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a MPI error.
Definition: exception.hpp:151
gko::OverflowError::OverflowError
OverflowError(const std::string &file, const int line, const std::string &index_type)
Definition: exception.hpp:581
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:660
gko::StreamError
StreamError is thrown if accessing a stream failed.
Definition: exception.hpp:591
gko::CufftError::CufftError
CufftError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a cuFFT error.
Definition: exception.hpp:266
gko::DimensionMismatch
DimensionMismatch is thrown if an operation is being applied to LinOps of incompatible size.
Definition: exception.hpp:416
gko::CusparseError::CusparseError
CusparseError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a cuSPARSE error.
Definition: exception.hpp:243
gko::HipError
HipError is thrown when a HIP routine throws a non-zero error code.
Definition: exception.hpp:279
gko::BadDimension
BadDimension is thrown if an operation is being applied to a LinOp with bad dimensions.
Definition: exception.hpp:451
gko::CufftError
CufftError is thrown when a cuFFT routine throws a non-zero error code.
Definition: exception.hpp:256
gko::OverflowError
OverflowError is thrown when an index calculation for storage requirements overflows.
Definition: exception.hpp:574
gko::Error::Error
Error(const std::string &file, int line, const std::string &what)
Initializes an error.
Definition: exception.hpp:67
gko::int64
std::int64_t int64
64-bit signed integral type.
Definition: types.hpp:124
gko::HipblasError::HipblasError
HipblasError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a hipBLAS error.
Definition: exception.hpp:312
gko::HipError::HipError
HipError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a HIP error.
Definition: exception.hpp:289
gko::CurandError
CurandError is thrown when a cuRAND routine throws a non-zero error code.
Definition: exception.hpp:210
gko::HiprandError
HiprandError is thrown when a hipRAND routine throws a non-zero error code.
Definition: exception.hpp:325
gko::BlockSizeError::BlockSizeError
BlockSizeError(const std::string &file, const int line, const int block_size, const IndexType size)
Definition: exception.hpp:490
gko::HipsparseError
HipsparseError is thrown when a hipSPARSE routine throws a non-zero error code.
Definition: exception.hpp:349
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:432
gko::HipfftError
HipfftError is thrown when a hipFFT routine throws a non-zero error code.
Definition: exception.hpp:372
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:514
gko::InvalidData
InvalidData is thrown in case an object in Ginkgo contains invalid data, either because the data was ...
Definition: exception.hpp:673
gko::CusparseError
CusparseError is thrown when a cuSPARSE routine throws a non-zero error code.
Definition: exception.hpp:233
gko::HipsparseError::HipsparseError
HipsparseError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a hipSPARSE error.
Definition: exception.hpp:359
gko::MetisError
MetisError is thrown when METIS routine throws an error code.
Definition: exception.hpp:395
gko::Error
The Error class is used to report exceptional behaviour in library functions.
Definition: exception.hpp:58
gko::NotImplemented::NotImplemented
NotImplemented(const std::string &file, int line, const std::string &func)
Initializes a NotImplemented error.
Definition: exception.hpp:86