• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2013 Francisco Jerez
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 // OTHER DEALINGS IN THE SOFTWARE.
21 //
22 
23 #ifndef CLOVER_CORE_ERROR_HPP
24 #define CLOVER_CORE_ERROR_HPP
25 
26 #include "CL/cl.h"
27 #if defined(__ALTIVEC__) && !defined(__APPLE_ALTIVEC__)
28    #undef vector
29    #undef pixel
30    #undef bool
31 #endif
32 
33 #include <stdexcept>
34 #include <string>
35 
36 namespace clover {
37    class command_queue;
38    class context;
39    class device;
40    class event;
41    class hard_event;
42    class soft_event;
43    class kernel;
44    class memory_obj;
45    class buffer;
46    class root_buffer;
47    class sub_buffer;
48    class image;
49    class image2d;
50    class image3d;
51    class platform;
52    class program;
53    class sampler;
54 
55    ///
56    /// Class that represents an error that can be converted to an
57    /// OpenCL status code.
58    ///
59    class error : public std::runtime_error {
60    public:
error(cl_int code,std::string what="")61       error(cl_int code, std::string what = "") :
62          std::runtime_error(what), code(code) {
63       }
64 
get() const65       cl_int get() const {
66          return code;
67       }
68 
69    protected:
70       cl_int code;
71    };
72 
73    class invalid_build_options_error : public error {
74    public:
invalid_build_options_error(const std::string & what="")75       invalid_build_options_error(const std::string &what = "") :
76          error(CL_INVALID_BUILD_OPTIONS, what) {}
77    };
78 
79    class build_error : public error {
80    public:
build_error(const std::string & what="")81       build_error(const std::string &what = "") :
82          error(CL_BUILD_PROGRAM_FAILURE, what) {}
83    };
84 
85    template<typename O>
86    class invalid_object_error;
87 
88    template<>
89    class invalid_object_error<command_queue> : public error {
90    public:
invalid_object_error(std::string what="")91       invalid_object_error(std::string what = "") :
92          error(CL_INVALID_COMMAND_QUEUE, what) {}
93    };
94 
95    template<>
96    class invalid_object_error<context> : public error {
97    public:
invalid_object_error(std::string what="")98       invalid_object_error(std::string what = "") :
99          error(CL_INVALID_CONTEXT, what) {}
100    };
101 
102    template<>
103    class invalid_object_error<device> : public error {
104    public:
invalid_object_error(std::string what="")105       invalid_object_error(std::string what = "") :
106          error(CL_INVALID_DEVICE, what) {}
107    };
108 
109    template<>
110    class invalid_object_error<event> : public error {
111    public:
invalid_object_error(std::string what="")112       invalid_object_error(std::string what = "") :
113          error(CL_INVALID_EVENT, what) {}
114    };
115 
116    template<>
117    class invalid_object_error<soft_event> : public error {
118    public:
invalid_object_error(std::string what="")119       invalid_object_error(std::string what = "") :
120          error(CL_INVALID_EVENT, what) {}
121    };
122 
123    template<>
124    class invalid_object_error<kernel> : public error {
125    public:
invalid_object_error(std::string what="")126       invalid_object_error(std::string what = "") :
127          error(CL_INVALID_KERNEL, what) {}
128    };
129 
130    template<>
131    class invalid_object_error<memory_obj> : public error {
132    public:
invalid_object_error(std::string what="")133       invalid_object_error(std::string what = "") :
134          error(CL_INVALID_MEM_OBJECT, what) {}
135    };
136 
137    template<>
138    class invalid_object_error<buffer> : public error {
139    public:
invalid_object_error(std::string what="")140       invalid_object_error(std::string what = "") :
141          error(CL_INVALID_MEM_OBJECT, what) {}
142    };
143 
144    template<>
145    class invalid_object_error<root_buffer> : public error {
146    public:
invalid_object_error(std::string what="")147       invalid_object_error(std::string what = "") :
148          error(CL_INVALID_MEM_OBJECT, what) {}
149    };
150 
151    template<>
152    class invalid_object_error<sub_buffer> : public error {
153    public:
invalid_object_error(std::string what="")154       invalid_object_error(std::string what = "") :
155          error(CL_INVALID_MEM_OBJECT, what) {}
156    };
157 
158    template<>
159    class invalid_object_error<image> : public error {
160    public:
invalid_object_error(std::string what="")161       invalid_object_error(std::string what = "") :
162          error(CL_INVALID_MEM_OBJECT, what) {}
163    };
164 
165    template<>
166    class invalid_object_error<image2d> : public error {
167    public:
invalid_object_error(std::string what="")168       invalid_object_error(std::string what = "") :
169          error(CL_INVALID_MEM_OBJECT, what) {}
170    };
171 
172    template<>
173    class invalid_object_error<image3d> : public error {
174    public:
invalid_object_error(std::string what="")175       invalid_object_error(std::string what = "") :
176          error(CL_INVALID_MEM_OBJECT, what) {}
177    };
178 
179    template<>
180    class invalid_object_error<platform> : public error {
181    public:
invalid_object_error(std::string what="")182       invalid_object_error(std::string what = "") :
183          error(CL_INVALID_PLATFORM, what) {}
184    };
185 
186    template<>
187    class invalid_object_error<program> : public error {
188    public:
invalid_object_error(std::string what="")189       invalid_object_error(std::string what = "") :
190          error(CL_INVALID_PROGRAM, what) {}
191    };
192 
193    template<>
194    class invalid_object_error<sampler> : public error {
195    public:
invalid_object_error(std::string what="")196       invalid_object_error(std::string what = "") :
197          error(CL_INVALID_SAMPLER, what) {}
198    };
199 
200    class invalid_wait_list_error : public error {
201    public:
invalid_wait_list_error(std::string what="")202       invalid_wait_list_error(std::string what = "") :
203          error(CL_INVALID_EVENT_WAIT_LIST, what) {}
204    };
205 }
206 
207 #endif
208