VTK-m  2.0
ErrorCuda.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_cont_cuda_ErrorCuda_h
11 #define vtk_m_cont_cuda_ErrorCuda_h
12 
13 #include <vtkm/Types.h>
14 #include <vtkm/cont/Error.h>
15 
16 #include <cuda.h>
17 
18 #include <sstream>
19 
23 #define VTKM_CUDA_CHECK_ASYNCHRONOUS_ERROR() \
24  VTKM_SWALLOW_SEMICOLON_PRE_BLOCK \
25  { \
26  const cudaError_t vtkm_cuda_check_async_error = cudaGetLastError(); \
27  if (vtkm_cuda_check_async_error != cudaSuccess) \
28  { \
29  throw ::vtkm::cont::cuda::ErrorCuda( \
30  vtkm_cuda_check_async_error, __FILE__, __LINE__, "Unchecked asynchronous error"); \
31  } \
32  } \
33  VTKM_SWALLOW_SEMICOLON_POST_BLOCK
34 
38 #define VTKM_CUDA_CALL(command) \
39  VTKM_CUDA_CHECK_ASYNCHRONOUS_ERROR(); \
40  VTKM_SWALLOW_SEMICOLON_PRE_BLOCK \
41  { \
42  const cudaError_t vtkm_cuda_call_error = command; \
43  if (vtkm_cuda_call_error != cudaSuccess) \
44  { \
45  throw ::vtkm::cont::cuda::ErrorCuda(vtkm_cuda_call_error, __FILE__, __LINE__, #command); \
46  } \
47  } \
48  VTKM_SWALLOW_SEMICOLON_POST_BLOCK
49 
50 namespace vtkm
51 {
52 namespace cont
53 {
54 namespace cuda
55 {
56 
58 
63 {
64 public:
65  ErrorCuda(cudaError_t error)
66  {
67  std::stringstream message;
68  message << "CUDA Error: " << cudaGetErrorString(error);
69  this->SetMessage(message.str());
70  }
71 
72  ErrorCuda(cudaError_t error,
73  const std::string& file,
74  vtkm::Id line,
75  const std::string& description)
76  {
77  std::stringstream message;
78  message << "CUDA Error: " << cudaGetErrorString(error) << std::endl
79  << description << " @ " << file << ":" << line;
80  this->SetMessage(message.str());
81  }
82 };
83 
85 }
86 }
87 } // namespace vtkm::cont:cuda
88 
89 #endif //vtk_m_cont_cuda_ErrorCuda_h
VTKM_SILENCE_WEAK_VTABLE_WARNING_START
#define VTKM_SILENCE_WEAK_VTABLE_WARNING_START
Definition: ExportMacros.h:119
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
Types.h
vtkm::cont::cuda::ErrorCuda::ErrorCuda
ErrorCuda(cudaError_t error)
Definition: ErrorCuda.h:65
VTKM_SILENCE_WEAK_VTABLE_WARNING_END
#define VTKM_SILENCE_WEAK_VTABLE_WARNING_END
Definition: ExportMacros.h:120
vtkm::cont::Error
The superclass of all exceptions thrown by any VTKm function or method.
Definition: Error.h:33
vtkm::cont::cuda::ErrorCuda::ErrorCuda
ErrorCuda(cudaError_t error, const std::string &file, vtkm::Id line, const std::string &description)
Definition: ErrorCuda.h:72
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::cont::cuda::ErrorCuda
This error is thrown whenever an unidentified CUDA runtime error is encountered.
Definition: ErrorCuda.h:62
Error.h
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:92