PageRenderTime 28ms CodeModel.GetById 16ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/src/gallium/state_trackers/clover/core/error.hpp

https://github.com/dscharrer/black_mesa
C++ Header | 196 lines | 144 code | 27 blank | 25 comment | 0 complexity | 6e425f088e8746d2614f940063c28005 MD5 | raw file
  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
 28#include "util/compat.hpp"
 29
 30namespace clover {
 31   class command_queue;
 32   class context;
 33   class device;
 34   class event;
 35   class hard_event;
 36   class soft_event;
 37   class kernel;
 38   class memory_obj;
 39   class buffer;
 40   class root_buffer;
 41   class sub_buffer;
 42   class image;
 43   class image2d;
 44   class image3d;
 45   class platform;
 46   class program;
 47   class sampler;
 48
 49   ///
 50   /// Class that represents an error that can be converted to an
 51   /// OpenCL status code.
 52   ///
 53   class error : public compat::runtime_error {
 54   public:
 55      error(cl_int code, compat::string what = "") :
 56         compat::runtime_error(what), code(code) {
 57      }
 58
 59      cl_int get() const {
 60         return code;
 61      }
 62
 63   protected:
 64      cl_int code;
 65   };
 66
 67   class build_error : public error {
 68   public:
 69      build_error(const compat::string &log) :
 70         error(CL_BUILD_PROGRAM_FAILURE, log) {
 71      }
 72   };
 73
 74   template<typename O>
 75   class invalid_object_error;
 76
 77   template<>
 78   class invalid_object_error<command_queue> : public error {
 79   public:
 80      invalid_object_error(std::string what = "") :
 81         error(CL_INVALID_COMMAND_QUEUE, what) {}
 82   };
 83
 84   template<>
 85   class invalid_object_error<context> : public error {
 86   public:
 87      invalid_object_error(std::string what = "") :
 88         error(CL_INVALID_CONTEXT, what) {}
 89   };
 90
 91   template<>
 92   class invalid_object_error<device> : public error {
 93   public:
 94      invalid_object_error(std::string what = "") :
 95         error(CL_INVALID_DEVICE, what) {}
 96   };
 97
 98   template<>
 99   class invalid_object_error<event> : public error {
100   public:
101      invalid_object_error(std::string what = "") :
102         error(CL_INVALID_EVENT, what) {}
103   };
104
105   template<>
106   class invalid_object_error<soft_event> : public error {
107   public:
108      invalid_object_error(std::string what = "") :
109         error(CL_INVALID_EVENT, what) {}
110   };
111
112   template<>
113   class invalid_object_error<kernel> : public error {
114   public:
115      invalid_object_error(std::string what = "") :
116         error(CL_INVALID_KERNEL, what) {}
117   };
118
119   template<>
120   class invalid_object_error<memory_obj> : public error {
121   public:
122      invalid_object_error(std::string what = "") :
123         error(CL_INVALID_MEM_OBJECT, what) {}
124   };
125
126   template<>
127   class invalid_object_error<buffer> : public error {
128   public:
129      invalid_object_error(std::string what = "") :
130         error(CL_INVALID_MEM_OBJECT, what) {}
131   };
132
133   template<>
134   class invalid_object_error<root_buffer> : public error {
135   public:
136      invalid_object_error(std::string what = "") :
137         error(CL_INVALID_MEM_OBJECT, what) {}
138   };
139
140   template<>
141   class invalid_object_error<sub_buffer> : public error {
142   public:
143      invalid_object_error(std::string what = "") :
144         error(CL_INVALID_MEM_OBJECT, what) {}
145   };
146
147   template<>
148   class invalid_object_error<image> : public error {
149   public:
150      invalid_object_error(std::string what = "") :
151         error(CL_INVALID_MEM_OBJECT, what) {}
152   };
153
154   template<>
155   class invalid_object_error<image2d> : public error {
156   public:
157      invalid_object_error(std::string what = "") :
158         error(CL_INVALID_MEM_OBJECT, what) {}
159   };
160
161   template<>
162   class invalid_object_error<image3d> : public error {
163   public:
164      invalid_object_error(std::string what = "") :
165         error(CL_INVALID_MEM_OBJECT, what) {}
166   };
167
168   template<>
169   class invalid_object_error<platform> : public error {
170   public:
171      invalid_object_error(std::string what = "") :
172         error(CL_INVALID_PLATFORM, what) {}
173   };
174
175   template<>
176   class invalid_object_error<program> : public error {
177   public:
178      invalid_object_error(std::string what = "") :
179         error(CL_INVALID_PROGRAM, what) {}
180   };
181
182   template<>
183   class invalid_object_error<sampler> : public error {
184   public:
185      invalid_object_error(std::string what = "") :
186         error(CL_INVALID_SAMPLER, what) {}
187   };
188
189   class invalid_wait_list_error : public error {
190   public:
191      invalid_wait_list_error(std::string what = "") :
192         error(CL_INVALID_EVENT_WAIT_LIST, what) {}
193   };
194}
195
196#endif