CUTLASS
CUDA Templates for Linear Algebra Subroutines and Solvers
exceptions.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (c) 2011-2019, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are not permitted.
6  *
7  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
8  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
10  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
11  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
12  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
13  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
14  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
16  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17  *
18  ******************************************************************************/
19 
20 #pragma once
21 
27 #include <cuda_runtime.h>
28 #include <iosfwd>
29 #include <stdexcept>
30 
32 
33 namespace cutlass {
34 
36 class cuda_exception : public std::exception {
37  public:
39  cuda_exception(const char* msg = "", cudaError_t err = cudaErrorUnknown) : msg(msg), err(err) {}
40 
42  cudaError_t cudaError() const { return err; }
43 
44  protected:
46  const char* msg;
47 
49  cudaError_t err;
50 };
51 
53 inline std::ostream& operator<<(std::ostream& out, cudaError_t result) {
54  return out << cudaGetErrorString(result);
55 }
56 
58 inline std::ostream& operator<<(std::ostream& out, cuda_exception const& e) {
59  return out << e.what() << ": " << e.cudaError();
60 }
61 
62 } // namespace cutlass
Definition: aligned_buffer.h:35
cudaError_t cudaError() const
Returns the underlying CUDA cudaError_t.
Definition: exceptions.h:42
cuda_exception(const char *msg="", cudaError_t err=cudaErrorUnknown)
Constructor.
Definition: exceptions.h:39
C++ features that may be otherwise unimplemented for CUDA device functions.
const char * msg
Explanatory string.
Definition: exceptions.h:46
std::ostream & operator<<(std::ostream &out, complex< T > const &z)
Definition: complex.h:291
C++ exception wrapper for CUDA cudaError_t.
Definition: exceptions.h:36
cudaError_t err
Underlying CUDA cudaError_t.
Definition: exceptions.h:49