JayBeams  0.1
Another project to have fun coding.
error.cpp
Go to the documentation of this file.
1 #include "jb/clfft/error.hpp"
2 
3 #include <boost/compute/exception/opencl_error.hpp>
4 #include <clFFT.h>
5 #include <sstream>
6 #include <utility>
7 
8 jb::clfft::clfft_error::clfft_error(cl_int error, char const* msg)
9  : std::runtime_error(to_what(error, msg))
10  , error_(error) {
11 }
12 
13 std::string jb::clfft::clfft_error::to_string(cl_int error) {
14  // This is a bit ugly, we cheat and use implementation details for
15  // the clFFT library to "know" that error codes below CLFFT_BUGCHECK
16  // are just regular OpenCL error codes. It is less ugly than
17  // reproducting the code from
18  // boost::compute::opencl_error::to_string() though.
19  if (error < CLFFT_BUGCHECK) {
20  return boost::compute::opencl_error::to_string(error);
21  }
22  //
23  switch (error) {
24  case CLFFT_BUGCHECK:
25  return "bugcheck";
26  case CLFFT_NOTIMPLEMENTED:
27  return "functionality is not implemented yet";
28  case CLFFT_TRANSPOSED_NOTIMPLEMENTED:
29  return "transposed functionality is not implemented"
30  " for this transformation";
31  case CLFFT_FILE_NOT_FOUND:
32  return "tried to open an existing file on the host system, but failed";
33  case CLFFT_FILE_CREATE_FAILURE:
34  return "tried to create a file on the host system, but failed";
35  case CLFFT_VERSION_MISMATCH:
36  return "version conflict between client and library";
37  case CLFFT_INVALID_PLAN:
38  return "requested plan could not be found";
39  case CLFFT_DEVICE_NO_DOUBLE:
40  return "double precision not supported on this device";
41  case CLFFT_DEVICE_MISMATCH:
42  return "attempt to run on a device using a plan"
43  " baked for a different device";
44  case CLFFT_ENDSTATUS:
45  return "ENDSTATUS - first error code out of range";
46  }
47  return "unknown error code";
48 }
49 
50 std::string jb::clfft::clfft_error::to_what(cl_int error, char const* msg) {
51  std::ostringstream os;
52  os << msg << ": " << to_string(error) << " (" << error << ")";
53  return os.str();
54 }
std::string to_what(cl_int error, char const *msg)
Generate a what() string given an error code and message.
Definition: error.cpp:50
STL namespace.
static std::string to_string(cl_int error)
Convert error code to a string.
Definition: error.cpp:13
clfft_error(cl_int error, char const *msg)
Constructor from a clFFT error code and a message.
Definition: error.cpp:8