Commit | Line | Data |
---|---|---|
f4b8a18d KW |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
32d0add0 | 3 | Copyright 2010-2015 Free Software Foundation, Inc. |
f4b8a18d KW |
4 | |
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | Contributed by Ken Werner <ken.werner@de.ibm.com> */ | |
19 | ||
20 | /* Utility macros and functions for OpenCL applications. */ | |
21 | ||
22 | #ifndef CL_UTIL_H | |
23 | #define CL_UTIL_H | |
24 | ||
25 | #ifdef __cplusplus | |
26 | extern "C" { | |
27 | #endif | |
28 | ||
29 | #ifdef __APPLE__ | |
30 | #include <OpenCL/opencl.h> | |
31 | #else | |
32 | #include <CL/cl.h> | |
33 | #endif | |
34 | #include <stdio.h> | |
35 | ||
36 | /* Executes the given OpenCL function and checks its return value. | |
37 | In case of failure (rc != CL_SUCCESS) an error string will be | |
38 | printed to stderr and the program will be terminated. This Macro | |
39 | is only intended for OpenCL routines which return cl_int. */ | |
40 | ||
41 | #define CHK(func)\ | |
42 | {\ | |
43 | int rc = (func);\ | |
44 | CHK_ERR (#func, rc);\ | |
45 | } | |
46 | ||
47 | /* Macro that checks an OpenCL error code. In case of failure | |
48 | (err != CL_SUCCESS) an error string will be printed to stderr | |
49 | including the prefix and the program will be terminated. This | |
50 | Macro is only intended to use in conjunction with OpenCL routines | |
51 | which take a pointer to a cl_int as an argument to place their | |
52 | error code. */ | |
53 | ||
54 | #define CHK_ERR(prefix, err)\ | |
55 | if (err != CL_SUCCESS)\ | |
56 | {\ | |
57 | fprintf (stderr, "CHK_ERR (%s, %d)\n", prefix, err);\ | |
58 | fprintf (stderr, "%s:%d error: %s\n", __FILE__, __LINE__,\ | |
59 | get_clerror_string (err));\ | |
60 | exit (EXIT_FAILURE);\ | |
61 | }; | |
62 | ||
63 | /* Return a pointer to a string that describes the error code specified | |
64 | by the errcode argument. */ | |
65 | ||
66 | extern const char *get_clerror_string (int errcode); | |
67 | ||
68 | /* Prints OpenCL information to stdout. */ | |
69 | ||
70 | extern void print_clinfo (); | |
71 | ||
72 | /* Reads a given file into the memory and returns a pointer to the data or NULL | |
73 | if the file does not exist. FILENAME specifies the location of the file to | |
74 | be read. SIZE is an output parameter that returns the size of the file in | |
75 | bytes. */ | |
76 | ||
77 | extern const char *read_file (const char * const filename, size_t *size); | |
78 | ||
79 | /* Saves all program binaries of the given OpenCL PROGRAM. The file | |
80 | names are extracted from the devices. */ | |
81 | ||
82 | extern void save_program_binaries (cl_program program); | |
83 | ||
84 | #ifdef __cplusplus | |
85 | } | |
86 | #endif | |
87 | ||
88 | #endif /* CL_UTIL_H */ |