Ginkgo Generated from branch based on master. Ginkgo version 1.7.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
exception.hpp
1/*******************************<GINKGO LICENSE>******************************
2Copyright (c) 2017-2023, the Ginkgo authors
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions
7are met:
8
91. Redistributions of source code must retain the above copyright
10notice, this list of conditions and the following disclaimer.
11
122. Redistributions in binary form must reproduce the above copyright
13notice, this list of conditions and the following disclaimer in the
14documentation and/or other materials provided with the distribution.
15
163. Neither the name of the copyright holder nor the names of its
17contributors may be used to endorse or promote products derived from
18this software without specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31******************************<GINKGO LICENSE>*******************************/
32
33#ifndef GKO_PUBLIC_CORE_BASE_EXCEPTION_HPP_
34#define GKO_PUBLIC_CORE_BASE_EXCEPTION_HPP_
35
36
37#include <exception>
38#include <string>
39
40
41#include <ginkgo/core/base/types.hpp>
42
43
44namespace gko {
45
46
86class Error : public std::exception {
87public:
95 Error(const std::string& file, int line, const std::string& what)
96 : what_(file + ":" + std::to_string(line) + ": " + what)
97 {}
98
103 virtual const char* what() const noexcept override { return what_.c_str(); }
104
105private:
106 const std::string what_;
107};
108
109
114class NotImplemented : public Error {
115public:
123 NotImplemented(const std::string& file, int line, const std::string& func)
124 : Error(file, line, func + " is not implemented")
125 {}
126};
127
128
133class NotCompiled : public Error {
134public:
143 NotCompiled(const std::string& file, int line, const std::string& func,
144 const std::string& module)
145 : Error(file, line,
146 "feature " + func + " is part of the " + module +
147 " module, which is not compiled on this system")
148 {}
149};
150
151
156class NotSupported : public Error {
157public:
167 NotSupported(const std::string& file, int line, const std::string& func,
168 const std::string& obj_type)
169 : Error(file, line,
170 "Operation " + func + " does not support parameters of type " +
171 obj_type)
172 {}
173};
174
175
179class MpiError : public Error {
180public:
188 MpiError(const std::string& file, int line, const std::string& func,
189 int64 error_code)
190 : Error(file, line, func + ": " + get_error(error_code))
191 {}
192
193private:
194 static std::string get_error(int64 error_code);
195};
196
197
201class CudaError : public Error {
202public:
211 CudaError(const std::string& file, int line, const std::string& func,
212 int64 error_code)
213 : Error(file, line, func + ": " + get_error(error_code))
214 {}
215
216private:
217 static std::string get_error(int64 error_code);
218};
219
220
224class CublasError : public Error {
225public:
234 CublasError(const std::string& file, int line, const std::string& func,
235 int64 error_code)
236 : Error(file, line, func + ": " + get_error(error_code))
237 {}
238
239private:
240 static std::string get_error(int64 error_code);
241};
242
243
247class CurandError : public Error {
248public:
257 CurandError(const std::string& file, int line, const std::string& func,
258 int64 error_code)
259 : Error(file, line, func + ": " + get_error(error_code))
260 {}
261
262private:
263 static std::string get_error(int64 error_code);
264};
265
266
270class CusparseError : public Error {
271public:
280 CusparseError(const std::string& file, int line, const std::string& func,
281 int64 error_code)
282 : Error(file, line, func + ": " + get_error(error_code))
283 {}
284
285private:
286 static std::string get_error(int64 error_code);
287};
288
289
293class CufftError : public Error {
294public:
303 CufftError(const std::string& file, int line, const std::string& func,
304 int64 error_code)
305 : Error(file, line, func + ": " + get_error(error_code))
306 {}
307
308private:
309 static std::string get_error(int64 error_code);
310};
311
312
316class HipError : public Error {
317public:
326 HipError(const std::string& file, int line, const std::string& func,
327 int64 error_code)
328 : Error(file, line, func + ": " + get_error(error_code))
329 {}
330
331private:
332 static std::string get_error(int64 error_code);
333};
334
335
339class HipblasError : public Error {
340public:
349 HipblasError(const std::string& file, int line, const std::string& func,
350 int64 error_code)
351 : Error(file, line, func + ": " + get_error(error_code))
352 {}
353
354private:
355 static std::string get_error(int64 error_code);
356};
357
358
362class HiprandError : public Error {
363public:
372 HiprandError(const std::string& file, int line, const std::string& func,
373 int64 error_code)
374 : Error(file, line, func + ": " + get_error(error_code))
375 {}
376
377private:
378 static std::string get_error(int64 error_code);
379};
380
381
386class HipsparseError : public Error {
387public:
396 HipsparseError(const std::string& file, int line, const std::string& func,
397 int64 error_code)
398 : Error(file, line, func + ": " + get_error(error_code))
399 {}
400
401private:
402 static std::string get_error(int64 error_code);
403};
404
405
409class HipfftError : public Error {
410public:
419 HipfftError(const std::string& file, int line, const std::string& func,
420 int64 error_code)
421 : Error(file, line, func + ": " + get_error(error_code))
422 {}
423
424private:
425 static std::string get_error(int64 error_code);
426};
427
428
432class MetisError : public Error {
433public:
442 MetisError(const std::string& file, int line, const std::string& func,
443 const std::string& error)
444 : Error(file, line, func + ": " + error)
445 {}
446};
447
448
453class DimensionMismatch : public Error {
454public:
469 DimensionMismatch(const std::string& file, int line,
470 const std::string& func, const std::string& first_name,
472 const std::string& second_name, size_type second_rows,
473 size_type second_cols, const std::string& clarification)
474 : Error(file, line,
475 func + ": attempting to combine operators " + first_name +
476 " [" + std::to_string(first_rows) + " x " +
477 std::to_string(first_cols) + "] and " + second_name + " [" +
478 std::to_string(second_rows) + " x " +
479 std::to_string(second_cols) + "]: " + clarification)
480 {}
481};
482
483
488class BadDimension : public Error {
489public:
501 BadDimension(const std::string& file, int line, const std::string& func,
502 const std::string& op_name, size_type op_num_rows,
503 size_type op_num_cols, const std::string& clarification)
504 : Error(file, line,
505 func + ": Object " + op_name + " has dimensions [" +
506 std::to_string(op_num_rows) + " x " +
507 std::to_string(op_num_cols) + "]: " + clarification)
508 {}
509};
510
511
518template <typename IndexType>
519class BlockSizeError : public Error {
520public:
527 BlockSizeError(const std::string& file, const int line,
528 const int block_size, const IndexType size)
529 : Error(file, line,
530 "block size = " + std::to_string(block_size) +
531 ", size = " + std::to_string(size))
532 {}
533};
534
535
539class ValueMismatch : public Error {
540public:
551 ValueMismatch(const std::string& file, int line, const std::string& func,
553 const std::string& clarification)
554 : Error(file, line,
555 func + ": Value mismatch : " + std::to_string(val1) + " and " +
556 std::to_string(val2) + " : " + clarification)
557 {}
558};
559
560
564class AllocationError : public Error {
565public:
574 AllocationError(const std::string& file, int line,
575 const std::string& device, size_type bytes)
576 : Error(file, line,
577 device + ": failed to allocate memory block of " +
578 std::to_string(bytes) + "B")
579 {}
580};
581
582
587class OutOfBoundsError : public Error {
588public:
597 OutOfBoundsError(const std::string& file, int line, size_type index,
599 : Error(file, line,
600 "trying to access index " + std::to_string(index) +
601 " in a memory block of " + std::to_string(bound) +
602 " elements")
603 {}
604};
605
606
611class OverflowError : public Error {
612public:
618 OverflowError(const std::string& file, const int line,
619 const std::string& index_type)
620 : Error(file, line, "Overflowing " + index_type)
621 {}
622};
623
624
628class StreamError : public Error {
629public:
638 StreamError(const std::string& file, int line, const std::string& func,
639 const std::string& message)
640 : Error(file, line, func + ": " + message)
641 {}
642};
643
644
649class KernelNotFound : public Error {
650public:
658 KernelNotFound(const std::string& file, int line, const std::string& func)
659 : Error(file, line, func + ": unable to find an eligible kernel")
660 {}
661};
662
663
671public:
679 UnsupportedMatrixProperty(const std::string& file, const int line,
680 const std::string& msg)
681 : Error(file, line, msg)
682 {}
683};
684
685
687class InvalidStateError : public Error {
688public:
697 InvalidStateError(const std::string& file, int line,
698 const std::string& func, const std::string& clarification)
699 : Error(file, line,
700 func + ": Invalid state encountered : " + clarification)
701 {}
702};
703
704
705} // namespace gko
706
707
708#endif // GKO_PUBLIC_CORE_BASE_EXCEPTION_HPP_
AllocationError is thrown if a memory allocation fails.
Definition exception.hpp:564
AllocationError(const std::string &file, int line, const std::string &device, size_type bytes)
Initializes an allocation error.
Definition exception.hpp:574
BadDimension is thrown if an operation is being applied to a LinOp with bad dimensions.
Definition exception.hpp:488
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:501
Error that denotes issues between block sizes and matrix dimensions.
Definition exception.hpp:519
BlockSizeError(const std::string &file, const int line, const int block_size, const IndexType size)
Definition exception.hpp:527
CublasError is thrown when a cuBLAS routine throws a non-zero error code.
Definition exception.hpp:224
CublasError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a cuBLAS error.
Definition exception.hpp:234
CudaError is thrown when a CUDA routine throws a non-zero error code.
Definition exception.hpp:201
CudaError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a CUDA error.
Definition exception.hpp:211
CufftError is thrown when a cuFFT routine throws a non-zero error code.
Definition exception.hpp:293
CufftError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a cuFFT error.
Definition exception.hpp:303
CurandError is thrown when a cuRAND routine throws a non-zero error code.
Definition exception.hpp:247
CurandError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a cuRAND error.
Definition exception.hpp:257
CusparseError is thrown when a cuSPARSE routine throws a non-zero error code.
Definition exception.hpp:270
CusparseError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a cuSPARSE error.
Definition exception.hpp:280
DimensionMismatch is thrown if an operation is being applied to LinOps of incompatible size.
Definition exception.hpp:453
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:469
The Error class is used to report exceptional behaviour in library functions.
Definition exception.hpp:86
Error(const std::string &file, int line, const std::string &what)
Initializes an error.
Definition exception.hpp:95
virtual const char * what() const noexcept override
Returns a human-readable string with a more detailed description of the error.
Definition exception.hpp:103
HipError is thrown when a HIP routine throws a non-zero error code.
Definition exception.hpp:316
HipError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a HIP error.
Definition exception.hpp:326
HipblasError is thrown when a hipBLAS routine throws a non-zero error code.
Definition exception.hpp:339
HipblasError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a hipBLAS error.
Definition exception.hpp:349
HipfftError is thrown when a hipFFT routine throws a non-zero error code.
Definition exception.hpp:409
HipfftError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a hipFFT error.
Definition exception.hpp:419
HiprandError is thrown when a hipRAND routine throws a non-zero error code.
Definition exception.hpp:362
HiprandError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a hipRAND error.
Definition exception.hpp:372
HipsparseError is thrown when a hipSPARSE routine throws a non-zero error code.
Definition exception.hpp:386
HipsparseError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a hipSPARSE error.
Definition exception.hpp:396
Exception thrown if an object is in an invalid state.
Definition exception.hpp:687
InvalidStateError(const std::string &file, int line, const std::string &func, const std::string &clarification)
Initializes an invalid state error.
Definition exception.hpp:697
KernelNotFound is thrown if Ginkgo cannot find a kernel which satisfies the criteria imposed by the i...
Definition exception.hpp:649
KernelNotFound(const std::string &file, int line, const std::string &func)
Initializes a KernelNotFound error.
Definition exception.hpp:658
MetisError is thrown when METIS routine throws an error code.
Definition exception.hpp:432
MetisError(const std::string &file, int line, const std::string &func, const std::string &error)
Initializes a METIS error.
Definition exception.hpp:442
MpiError is thrown when a MPI routine throws a non-zero error code.
Definition exception.hpp:179
MpiError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a MPI error.
Definition exception.hpp:188
NotCompiled is thrown when attempting to call an operation which is a part of a module that was not c...
Definition exception.hpp:133
NotCompiled(const std::string &file, int line, const std::string &func, const std::string &module)
Initializes a NotCompiled error.
Definition exception.hpp:143
NotImplemented is thrown in case an operation has not yet been implemented (but will be implemented i...
Definition exception.hpp:114
NotImplemented(const std::string &file, int line, const std::string &func)
Initializes a NotImplemented error.
Definition exception.hpp:123
NotSupported is thrown in case it is not possible to perform the requested operation on the given obj...
Definition exception.hpp:156
NotSupported(const std::string &file, int line, const std::string &func, const std::string &obj_type)
Initializes a NotSupported error.
Definition exception.hpp:167
OutOfBoundsError is thrown if a memory access is detected to be out-of-bounds.
Definition exception.hpp:587
OutOfBoundsError(const std::string &file, int line, size_type index, size_type bound)
Initializes an OutOfBoundsError.
Definition exception.hpp:597
OverflowError is thrown when an index calculation for storage requirements overflows.
Definition exception.hpp:611
OverflowError(const std::string &file, const int line, const std::string &index_type)
Definition exception.hpp:618
StreamError is thrown if accessing a stream failed.
Definition exception.hpp:628
StreamError(const std::string &file, int line, const std::string &func, const std::string &message)
Initializes a file access error.
Definition exception.hpp:638
Exception throws if a matrix does not have a property required by a numerical method.
Definition exception.hpp:670
UnsupportedMatrixProperty(const std::string &file, const int line, const std::string &msg)
Initializes the UnsupportedMatrixProperty error.
Definition exception.hpp:679
ValueMismatch is thrown if two values are not equal.
Definition exception.hpp:539
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:551
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
std::int64_t int64
64-bit signed integral type.
Definition types.hpp:143
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:120