Ginkgo  Generated from tags/v1.0.0^0 branch based on master. Ginkgo version 1.0.0
A numerical linear algebra library targeting many-core architectures
exception.hpp
1 /*******************************<GINKGO LICENSE>******************************
2 Copyright (c) 2017-2019, the Ginkgo authors
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 
16 3. Neither the name of the copyright holder nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19 
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 ******************************<GINKGO LICENSE>*******************************/
32 
33 #ifndef GKO_CORE_EXCEPTION_HPP_
34 #define GKO_CORE_EXCEPTION_HPP_
35 
36 
37 #include <ginkgo/core/base/types.hpp>
38 
39 
40 #include <exception>
41 #include <string>
42 
43 
44 namespace gko {
45 
46 
86 class Error : public std::exception {
87 public:
94  Error(const std::string &file, int line, const std::string &what)
95  : what_(file + ":" + std::to_string(line) + ": " + what)
96  {}
97 
102  virtual const char *what() const noexcept override { return what_.c_str(); }
103 
104 private:
105  const std::string what_;
106 };
107 
108 
113 class NotImplemented : public Error {
114 public:
121  NotImplemented(const std::string &file, int line, const std::string &func)
122  : Error(file, line, func + " is not implemented")
123  {}
124 };
125 
126 
131 class NotCompiled : public Error {
132 public:
140  NotCompiled(const std::string &file, int line, const std::string &func,
141  const std::string &module)
142  : Error(file, line,
143  "feature " + func + " is part of the " + module +
144  " module, which is not compiled on this system")
145  {}
146 };
147 
148 
153 class NotSupported : public Error {
154 public:
163  NotSupported(const std::string &file, int line, const std::string &func,
164  const std::string &obj_type)
165  : Error(file, line,
166  "Operation " + func + " does not support parameters of type " +
167  obj_type)
168  {}
169 };
170 
171 
175 class CudaError : public Error {
176 public:
184  CudaError(const std::string &file, int line, const std::string &func,
185  int64 error_code)
186  : Error(file, line, func + ": " + get_error(error_code))
187  {}
188 
189 private:
190  static std::string get_error(int64 error_code);
191 };
192 
193 
197 class CublasError : public Error {
198 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 CusparseError : public Error {
220 public:
228  CusparseError(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 
242 class DimensionMismatch : public Error {
243 public:
257  DimensionMismatch(const std::string &file, int line,
258  const std::string &func, const std::string &first_name,
259  size_type first_rows, size_type first_cols,
260  const std::string &second_name, size_type second_rows,
261  size_type second_cols, const std::string &clarification)
262  : Error(file, line,
263  func + ": attempting to combine operators " + first_name +
264  " [" + std::to_string(first_rows) + " x " +
265  std::to_string(first_cols) + "] and " + second_name + " [" +
266  std::to_string(second_rows) + " x " +
267  std::to_string(second_cols) + "]: " + clarification)
268  {}
269 };
270 
271 
275 class AllocationError : public Error {
276 public:
284  AllocationError(const std::string &file, int line,
285  const std::string &device, size_type bytes)
286  : Error(file, line,
287  device + ": failed to allocate memory block of " +
288  std::to_string(bytes) + "B")
289  {}
290 };
291 
292 
297 class OutOfBoundsError : public Error {
298 public:
306  OutOfBoundsError(const std::string &file, int line, size_type index,
307  size_type bound)
308  : Error(file, line,
309  "trying to access index " + std::to_string(index) +
310  " in a memory block of " + std::to_string(bound) +
311  " elements")
312  {}
313 };
314 
315 
319 class StreamError : public Error {
320 public:
328  StreamError(const std::string &file, int line, const std::string &func,
329  const std::string &message)
330  : Error(file, line, func + ": " + message)
331  {}
332 };
333 
334 
339 class KernelNotFound : public Error {
340 public:
347  KernelNotFound(const std::string &file, int line, const std::string &func)
348  : Error(file, line, func + ": unable to find an eligible kernel")
349  {}
350 };
351 
352 
353 } // namespace gko
354 
355 
356 #endif // GKO_CORE_EXCEPTION_HPP_
NotImplemented is thrown in case an operation has not yet been implemented (but will be implemented i...
Definition: exception.hpp:113
The Error class is used to report exceptional behaviour in library functions.
Definition: exception.hpp:86
STL namespace.
OutOfBoundsError(const std::string &file, int line, size_type index, size_type bound)
Initializes an OutOfBoundsError.
Definition: exception.hpp:306
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:94
KernelNotFound is thrown if Ginkgo cannot find a kernel which satisfies the criteria imposed by the i...
Definition: exception.hpp:339
NotCompiled is thrown when attempting to call an operation which is a part of a module that was not c...
Definition: exception.hpp:131
CublasError is thrown when a cuBLAS routine throws a non-zero error code.
Definition: exception.hpp:197
The Ginkgo namespace.
Definition: abstract_factory.hpp:45
StreamError(const std::string &file, int line, const std::string &func, const std::string &message)
Initializes a file access error.
Definition: exception.hpp:328
KernelNotFound(const std::string &file, int line, const std::string &func)
Initializes a KernelNotFound error.
Definition: exception.hpp:347
CudaError is thrown when a CUDA routine throws a non-zero error code.
Definition: exception.hpp:175
OutOfBoundsError is thrown if a memory access is detected to be out-of-bounds.
Definition: exception.hpp:297
CusparseError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a cuSPARSE error.
Definition: exception.hpp:228
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:257
std::int64_t int64
64-bit signed integral type.
Definition: types.hpp:117
CusparseError is thrown when a cuSPARSE routine throws a non-zero error code.
Definition: exception.hpp:219
CublasError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a cuBLAS error.
Definition: exception.hpp:206
NotSupported(const std::string &file, int line, const std::string &func, const std::string &obj_type)
Initializes a NotSupported error.
Definition: exception.hpp:163
StreamError is thrown if accessing a stream failed.
Definition: exception.hpp:319
CudaError(const std::string &file, int line, const std::string &func, int64 error_code)
Initializes a CUDA error.
Definition: exception.hpp:184
DimensionMismatch is thrown if an operation is being applied to LinOps of incompatible size...
Definition: exception.hpp:242
virtual const char * what() const noexcept override
Returns a human-readable string with a more detailed description of the error.
Definition: exception.hpp:102
NotImplemented(const std::string &file, int line, const std::string &func)
Initializes a NotImplemented error.
Definition: exception.hpp:121
NotSupported is thrown in case it is not possible to perform the requested operation on the given obj...
Definition: exception.hpp:153
AllocationError is thrown if a memory allocation fails.
Definition: exception.hpp:275
AllocationError(const std::string &file, int line, const std::string &device, size_type bytes)
Initializes an allocation error.
Definition: exception.hpp:284
Error(const std::string &file, int line, const std::string &what)
Initializes an error.
Definition: exception.hpp:94
NotCompiled(const std::string &file, int line, const std::string &func, const std::string &module)
Initializes a NotCompiled error.
Definition: exception.hpp:140