Ginkgo  Generated from pipelines/1330831941 branch based on master. Ginkgo version 1.8.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 
13 #include <ginkgo/core/base/types.hpp>
14 
15 
16 namespace gko {
17 
18 
58 class Error : public std::exception {
59 public:
67  Error(const std::string& file, int line, const std::string& what)
68  : what_(file + ":" + std::to_string(line) + ": " + what)
69  {}
70 
75  virtual const char* what() const noexcept override { return what_.c_str(); }
76 
77 private:
78  const std::string what_;
79 };
80 
81 
86 class NotImplemented : public Error {
87 public:
95  NotImplemented(const std::string& file, int line, const std::string& func)
96  : Error(file, line, func + " is not implemented")
97  {}
98 };
99 
100 
105 class NotCompiled : public Error {
106 public:
115  NotCompiled(const std::string& file, int line, const std::string& func,
116  const std::string& module)
117  : Error(file, line,
118  "feature " + func + " is part of the " + module +
119  " module, which is not compiled on this system")
120  {}
121 };
122 
123 
128 class NotSupported : public Error {
129 public:
139  NotSupported(const std::string& file, int line, const std::string& func,
140  const std::string& obj_type)
141  : Error(file, line,
142  "Operation " + func + " does not support parameters of type " +
143  obj_type)
144  {}
145 };
146 
147 
151 class MpiError : public Error {
152 public:
160  MpiError(const std::string& file, int line, const std::string& func,
161  int64 error_code)
162  : Error(file, line, func + ": " + get_error(error_code))
163  {}
164 
165 private:
166  static std::string get_error(int64 error_code);
167 };
168 
169 
173 class CudaError : public Error {
174 public:
183  CudaError(const std::string& file, int line, const std::string& func,
184  int64 error_code)
185  : Error(file, line, func + ": " + get_error(error_code))
186  {}
187 
188 private:
189  static std::string get_error(int64 error_code);
190 };
191 
192 
196 class CublasError : public Error {
197 public:
206  CublasError(const std::string& file, int line, const std::string& func,
207  int64 error_code)
208  : Error(file, line, func + ": " + get_error(error_code))
209  {}
210 
211 private:
212  static std::string get_error(int64 error_code);
213 };
214 
215 
219 class CurandError : public Error {
220 public:
229  CurandError(const std::string& file, int line, const std::string& func,
230  int64 error_code)
231  : Error(file, line, func + ": " + get_error(error_code))
232  {}
233 
234 private:
235  static std::string get_error(int64 error_code);
236 };
237 
238 
242 class CusparseError : public Error {
243 public:
252  CusparseError(const std::string& file, int line, const std::string& func,
253  int64 error_code)
254  : Error(file, line, func + ": " + get_error(error_code))
255  {}
256 
257 private:
258  static std::string get_error(int64 error_code);
259 };
260 
261 
265 class CufftError : public Error {
266 public:
275  CufftError(const std::string& file, int line, const std::string& func,
276  int64 error_code)
277  : Error(file, line, func + ": " + get_error(error_code))
278  {}
279 
280 private:
281  static std::string get_error(int64 error_code);
282 };
283 
284 
288 class HipError : public Error {
289 public:
298  HipError(const std::string& file, int line, const std::string& func,
299  int64 error_code)
300  : Error(file, line, func + ": " + get_error(error_code))
301  {}
302 
303 private:
304  static std::string get_error(int64 error_code);
305 };
306 
307 
311 class HipblasError : public Error {
312 public:
321  HipblasError(const std::string& file, int line, const std::string& func,
322  int64 error_code)
323  : Error(file, line, func + ": " + get_error(error_code))
324  {}
325 
326 private:
327  static std::string get_error(int64 error_code);
328 };
329 
330 
334 class HiprandError : public Error {
335 public:
344  HiprandError(const std::string& file, int line, const std::string& func,
345  int64 error_code)
346  : Error(file, line, func + ": " + get_error(error_code))
347  {}
348 
349 private:
350  static std::string get_error(int64 error_code);
351 };
352 
353 
358 class HipsparseError : public Error {
359 public:
368  HipsparseError(const std::string& file, int line, const std::string& func,
369  int64 error_code)
370  : Error(file, line, func + ": " + get_error(error_code))
371  {}
372 
373 private:
374  static std::string get_error(int64 error_code);
375 };
376 
377 
381 class HipfftError : public Error {
382 public:
391  HipfftError(const std::string& file, int line, const std::string& func,
392  int64 error_code)
393  : Error(file, line, func + ": " + get_error(error_code))
394  {}
395 
396 private:
397  static std::string get_error(int64 error_code);
398 };
399 
400 
404 class MetisError : public Error {
405 public:
414  MetisError(const std::string& file, int line, const std::string& func,
415  const std::string& error)
416  : Error(file, line, func + ": " + error)
417  {}
418 };
419 
420 
425 class DimensionMismatch : public Error {
426 public:
441  DimensionMismatch(const std::string& file, int line,
442  const std::string& func, const std::string& first_name,
443  size_type first_rows, size_type first_cols,
444  const std::string& second_name, size_type second_rows,
445  size_type second_cols, const std::string& clarification)
446  : Error(file, line,
447  func + ": attempting to combine operators " + first_name +
448  " [" + std::to_string(first_rows) + " x " +
449  std::to_string(first_cols) + "] and " + second_name + " [" +
450  std::to_string(second_rows) + " x " +
451  std::to_string(second_cols) + "]: " + clarification)
452  {}
453 };
454 
455 
460 class BadDimension : public Error {
461 public:
473  BadDimension(const std::string& file, int line, const std::string& func,
474  const std::string& op_name, size_type op_num_rows,
475  size_type op_num_cols, const std::string& clarification)
476  : Error(file, line,
477  func + ": Object " + op_name + " has dimensions [" +
478  std::to_string(op_num_rows) + " x " +
479  std::to_string(op_num_cols) + "]: " + clarification)
480  {}
481 };
482 
483 
490 template <typename IndexType>
491 class BlockSizeError : public Error {
492 public:
499  BlockSizeError(const std::string& file, const int line,
500  const int block_size, const IndexType size)
501  : Error(file, line,
502  "block size = " + std::to_string(block_size) +
503  ", size = " + std::to_string(size))
504  {}
505 };
506 
507 
511 class ValueMismatch : public Error {
512 public:
523  ValueMismatch(const std::string& file, int line, const std::string& func,
524  size_type val1, size_type val2,
525  const std::string& clarification)
526  : Error(file, line,
527  func + ": Value mismatch : " + std::to_string(val1) + " and " +
528  std::to_string(val2) + " : " + clarification)
529  {}
530 };
531 
532 
536 class AllocationError : public Error {
537 public:
546  AllocationError(const std::string& file, int line,
547  const std::string& device, size_type bytes)
548  : Error(file, line,
549  device + ": failed to allocate memory block of " +
550  std::to_string(bytes) + "B")
551  {}
552 };
553 
554 
559 class OutOfBoundsError : public Error {
560 public:
569  OutOfBoundsError(const std::string& file, int line, size_type index,
570  size_type bound)
571  : Error(file, line,
572  "trying to access index " + std::to_string(index) +
573  " in a memory block of " + std::to_string(bound) +
574  " elements")
575  {}
576 };
577 
578 
583 class OverflowError : public Error {
584 public:
590  OverflowError(const std::string& file, const int line,
591  const std::string& index_type)
592  : Error(file, line, "Overflowing " + index_type)
593  {}
594 };
595 
596 
600 class StreamError : public Error {
601 public:
610  StreamError(const std::string& file, int line, const std::string& func,
611  const std::string& message)
612  : Error(file, line, func + ": " + message)
613  {}
614 };
615 
616 
621 class KernelNotFound : public Error {
622 public:
630  KernelNotFound(const std::string& file, int line, const std::string& func)
631  : Error(file, line, func + ": unable to find an eligible kernel")
632  {}
633 };
634 
635 
643 public:
651  UnsupportedMatrixProperty(const std::string& file, const int line,
652  const std::string& msg)
653  : Error(file, line, msg)
654  {}
655 };
656 
657 
659 class InvalidStateError : public Error {
660 public:
669  InvalidStateError(const std::string& file, int line,
670  const std::string& func, const std::string& clarification)
671  : Error(file, line,
672  func + ": Invalid state encountered : " + clarification)
673  {}
674 };
675 
676 
677 } // namespace gko
678 
679 
680 #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:173
gko::ValueMismatch
ValueMismatch is thrown if two values are not equal.
Definition: exception.hpp:511
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:75
gko::BlockSizeError
Error that denotes issues between block sizes and matrix dimensions.
Definition: exception.hpp:491
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:115
gko::KernelNotFound::KernelNotFound
KernelNotFound(const std::string &file, int line, const std::string &func)
Initializes a KernelNotFound error.
Definition: exception.hpp:630
gko::KernelNotFound
KernelNotFound is thrown if Ginkgo cannot find a kernel which satisfies the criteria imposed by the i...
Definition: exception.hpp:621
gko::HipblasError
HipblasError is thrown when a hipBLAS routine throws a non-zero error code.
Definition: exception.hpp:311
gko::OutOfBoundsError
OutOfBoundsError is thrown if a memory access is detected to be out-of-bounds.
Definition: exception.hpp:559
gko::NotImplemented
NotImplemented is thrown in case an operation has not yet been implemented (but will be implemented i...
Definition: exception.hpp:86
gko::AllocationError::AllocationError
AllocationError(const std::string &file, int line, const std::string &device, size_type bytes)
Initializes an allocation error.
Definition: exception.hpp:546
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:108
gko::OutOfBoundsError::OutOfBoundsError
OutOfBoundsError(const std::string &file, int line, size_type index, size_type bound)
Initializes an OutOfBoundsError.
Definition: exception.hpp:569
gko::InvalidStateError
Exception thrown if an object is in an invalid state.
Definition: exception.hpp:659
gko::UnsupportedMatrixProperty
Exception throws if a matrix does not have a property required by a numerical method.
Definition: exception.hpp:642
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:105
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:139
gko::HiprandError::HiprandError
HiprandError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a hipRAND error.
Definition: exception.hpp:344
gko::NotSupported
NotSupported is thrown in case it is not possible to perform the requested operation on the given obj...
Definition: exception.hpp:128
gko::CublasError
CublasError is thrown when a cuBLAS routine throws a non-zero error code.
Definition: exception.hpp:196
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:414
gko::CublasError::CublasError
CublasError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a cuBLAS error.
Definition: exception.hpp:206
gko::MpiError
MpiError is thrown when a MPI routine throws a non-zero error code.
Definition: exception.hpp:151
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:651
gko::CudaError::CudaError
CudaError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a CUDA error.
Definition: exception.hpp:183
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:610
gko::AllocationError
AllocationError is thrown if a memory allocation fails.
Definition: exception.hpp:536
gko::CurandError::CurandError
CurandError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a cuRAND error.
Definition: exception.hpp:229
gko::HipfftError::HipfftError
HipfftError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a hipFFT error.
Definition: exception.hpp:391
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:473
gko::MpiError::MpiError
MpiError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a MPI error.
Definition: exception.hpp:160
gko::OverflowError::OverflowError
OverflowError(const std::string &file, const int line, const std::string &index_type)
Definition: exception.hpp:590
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:669
gko::StreamError
StreamError is thrown if accessing a stream failed.
Definition: exception.hpp:600
gko::CufftError::CufftError
CufftError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a cuFFT error.
Definition: exception.hpp:275
gko::DimensionMismatch
DimensionMismatch is thrown if an operation is being applied to LinOps of incompatible size.
Definition: exception.hpp:425
gko::CusparseError::CusparseError
CusparseError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a cuSPARSE error.
Definition: exception.hpp:252
gko::HipError
HipError is thrown when a HIP routine throws a non-zero error code.
Definition: exception.hpp:288
gko::BadDimension
BadDimension is thrown if an operation is being applied to a LinOp with bad dimensions.
Definition: exception.hpp:460
gko::CufftError
CufftError is thrown when a cuFFT routine throws a non-zero error code.
Definition: exception.hpp:265
gko::OverflowError
OverflowError is thrown when an index calculation for storage requirements overflows.
Definition: exception.hpp:583
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:131
gko::HipblasError::HipblasError
HipblasError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a hipBLAS error.
Definition: exception.hpp:321
gko::HipError::HipError
HipError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a HIP error.
Definition: exception.hpp:298
gko::CurandError
CurandError is thrown when a cuRAND routine throws a non-zero error code.
Definition: exception.hpp:219
gko::HiprandError
HiprandError is thrown when a hipRAND routine throws a non-zero error code.
Definition: exception.hpp:334
gko::BlockSizeError::BlockSizeError
BlockSizeError(const std::string &file, const int line, const int block_size, const IndexType size)
Definition: exception.hpp:499
gko::HipsparseError
HipsparseError is thrown when a hipSPARSE routine throws a non-zero error code.
Definition: exception.hpp:358
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:441
gko::HipfftError
HipfftError is thrown when a hipFFT routine throws a non-zero error code.
Definition: exception.hpp:381
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:523
gko::CusparseError
CusparseError is thrown when a cuSPARSE routine throws a non-zero error code.
Definition: exception.hpp:242
gko::HipsparseError::HipsparseError
HipsparseError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a hipSPARSE error.
Definition: exception.hpp:368
gko::MetisError
MetisError is thrown when METIS routine throws an error code.
Definition: exception.hpp:404
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:95