1 /* OpenCL error handling */
10 #include "fmtmacros.h"
14 check_ocl_error(cl_int err, const char *what, const char *func, int line)
16 if (err != CL_SUCCESS) {
19 fprintf(stderr, "%s:%u: %s : error %d\n",
20 func, line, what, err);
27 report_ocl_error_basic(struct _strbuf *str, cl_int err, const char *what, const char *func, int line)
29 if (err != CL_SUCCESS) {
30 snprintf(str->buf, str->sz, "<%s:%d: %s : error %d>",
31 func, line, what, err);
38 report_ocl_error_loc(struct _strbuf *str, cl_int err, const char *fmt,
39 const struct info_loc *loc)
41 static char full_fmt[1024];
42 if (err != CL_SUCCESS) {
43 snprintf(full_fmt, 1024, "<%s:%" PRIuS ": %s : error %d>",
44 loc->function, loc->line, fmt, err);
45 snprintf(str->buf, str->sz, full_fmt, loc->sname);
47 return err != CL_SUCCESS;
51 report_size_mismatch(struct _strbuf *str, size_t req, size_t ours,
52 const struct info_loc *loc)
54 snprintf(str->buf, str->sz, "<%s:%" PRIuS ": %s : size mismatch "
55 "(requested %" PRIuS ", we offer %" PRIuS ")>",
56 loc->function, loc->line, loc->sname,
60 #define CHECK_ERROR(error, what) if (check_ocl_error(error, what, __func__, __LINE__)) exit(1)
62 #define REPORT_ERROR(str, err, what) report_ocl_error_basic(str, err, what, __func__, __LINE__)
63 #define REPORT_ERROR_LOC(ret, err, loc, what) report_ocl_error_loc(&((ret)->err_str), err, what, loc)
64 #define REPORT_SIZE_MISMATCH(str, loc, req, ours) report_size_mismatch(str, req, ours, loc)