Viskores  1.0
ErrorCuda.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_cont_cuda_ErrorCuda_h
19 #define viskores_cont_cuda_ErrorCuda_h
20 
21 #include <viskores/Types.h>
22 #include <viskores/cont/Error.h>
23 
24 #include <cuda.h>
25 
26 #include <sstream>
27 
31 #define VISKORES_CUDA_CHECK_ASYNCHRONOUS_ERROR() \
32  VISKORES_SWALLOW_SEMICOLON_PRE_BLOCK \
33  { \
34  const cudaError_t viskores_cuda_check_async_error = cudaGetLastError(); \
35  if (viskores_cuda_check_async_error != cudaSuccess) \
36  { \
37  throw ::viskores::cont::cuda::ErrorCuda( \
38  viskores_cuda_check_async_error, __FILE__, __LINE__, "Unchecked asynchronous error"); \
39  } \
40  } \
41  VISKORES_SWALLOW_SEMICOLON_POST_BLOCK
42 
46 #define VISKORES_CUDA_CALL(command) \
47  VISKORES_CUDA_CHECK_ASYNCHRONOUS_ERROR(); \
48  VISKORES_SWALLOW_SEMICOLON_PRE_BLOCK \
49  { \
50  const cudaError_t viskores_cuda_call_error = command; \
51  if (viskores_cuda_call_error != cudaSuccess) \
52  { \
53  throw ::viskores::cont::cuda::ErrorCuda( \
54  viskores_cuda_call_error, __FILE__, __LINE__, #command); \
55  } \
56  } \
57  VISKORES_SWALLOW_SEMICOLON_POST_BLOCK
58 
59 namespace viskores
60 {
61 namespace cont
62 {
63 namespace cuda
64 {
65 
67 
71 class VISKORES_ALWAYS_EXPORT ErrorCuda : public viskores::cont::Error
72 {
73 public:
74  ErrorCuda(cudaError_t error)
75  {
76  std::stringstream message;
77  message << "CUDA Error: " << cudaGetErrorString(error);
78  this->SetMessage(message.str());
79  }
80 
81  ErrorCuda(cudaError_t error,
82  const std::string& file,
83  viskores::Id line,
84  const std::string& description)
85  {
86  std::stringstream message;
87  message << "CUDA Error: " << cudaGetErrorString(error) << std::endl
88  << description << " @ " << file << ":" << line;
89  this->SetMessage(message.str());
90  }
91 };
92 
94 }
95 }
96 } // namespace viskores::cont:cuda
97 
98 #endif //viskores_cont_cuda_ErrorCuda_h
Types.h
viskores::cont::cuda::ErrorCuda
This error is thrown whenever an unidentified CUDA runtime error is encountered.
Definition: ErrorCuda.h:71
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
Error.h
viskores::cont::cuda::ErrorCuda::ErrorCuda
ErrorCuda(cudaError_t error)
Definition: ErrorCuda.h:74
VISKORES_SILENCE_WEAK_VTABLE_WARNING_END
#define VISKORES_SILENCE_WEAK_VTABLE_WARNING_END
Definition: ExportMacros.h:128
VISKORES_SILENCE_WEAK_VTABLE_WARNING_START
#define VISKORES_SILENCE_WEAK_VTABLE_WARNING_START
Definition: ExportMacros.h:127
viskores::cont::cuda::ErrorCuda::ErrorCuda
ErrorCuda(cudaError_t error, const std::string &file, viskores::Id line, const std::string &description)
Definition: ErrorCuda.h:81
viskores::cont::Error
The superclass of all exceptions thrown by any Viskores function or method.
Definition: Error.h:41