Voxel
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Macros Pages
opencl_exception.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifndef OPENCL_EXCEPTION_H
4 #define OPENCL_EXCEPTION_H
5 
6 
7 /**
8  \file
9  \brief Contains OpenCL::Exception class.
10 */
11 
12 
13 
14 
15 #include "settings.h"
16 
17 
18 
19 
20 #if ( SETTING_OPENCL != 0 )
21 
22 
23 
24 
25 #include <CL/cl.h>
26 
27 #include <string>
28 #include <stdexcept>
29 
30 
31 
32 
33 /*==============================================================================
34  THROW_OPENCL_EXCEPTION macros
35 ==============================================================================*/
36 
37 
38 /// \brief Throws an OpenCL::Exception labeled with the file, line, string \p what and OpenCL error code \p hResult.
39 #define THROW_OPENCL_EXCEPTION( what, result ) \
40  throw ::OpenCL::Exception( __FILE__, __LINE__, ( what ), ( result ) )
41 
42 
43 /// \brief Evaluates \p what, and if it returns an OpenCL failure code, throws an OpenCL::Exception.
44 #define CHECK_OPENCL( what ) { \
45  cl_int result = ( what ); \
46  if ( result != CL_SUCCESS ) \
47  THROW_OPENCL_EXCEPTION( #what, result ); \
48 }
49 
50 
51 
52 
53 namespace OpenCL {
54 
55 
56 
57 
58 /*==============================================================================
59  Exception class
60 ==============================================================================*/
61 
62 
63 /**
64  \brief OpenCL exception class.
65 
66  OpenCL Exceptions should not be constructed explicitly. Instead, use the
67  THROW_OPENCL_EXCEPTION() macro, which will construct and throw an exception
68  annotated with the filename and line number of the failure.
69 
70  The difference between this class and the "default" exception class is that
71  an OpenCL exception converts OpenCL error codes into error strings.
72 
73  The error message returned by what() has the following components:
74 
75  1. Filename and line number at which the exception was thrown.
76  2. Description string \p what passed to the constructor.
77  3. Description of the OpenCL error code passed to the constructor.
78 */
79 struct Exception : public std::exception {
80 
81  Exception( char const* const file, unsigned int const line, std::string const& what, cl_int const result );
82 
83 
84  virtual ~Exception() throw();
85 
86 
87  virtual const char* what() const throw(); ///< Returns text (UTF-8) error message for this exception.
88 
89 
90 private:
91 
92  std::string m_what;
93 };
94 
95 
96 
97 
98 } // namespace OpenCL
99 
100 
101 
102 
103 #endif // SETTING_OPENCL
104 
105 
106 
107 
108 #endif // OPENCL_EXCEPTION_H