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