Static-const-ify ICD loader info strings
[ocl-icd] / ocl_test_icdl.c
1 /**
2 Copyright (c) 2012, Brice Videau <brice.videau@imag.fr>
3 All rights reserved.
4       
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7     
8 1. Redistributions of source code must retain the above copyright notice, this
9    list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11    this list of conditions and the following disclaimer in the documentation
12    and/or other materials provided with the distribution.
13         
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #define CL_USE_DEPRECATED_OPENCL_1_1_APIS
27 #pragma GCC diagnostic push
28 #  pragma GCC diagnostic ignored "-Wcpp"
29 #  if defined(__APPLE__) || defined(__MACOSX)
30 #    include <OpenCL/cl.h>
31 #  else
32 #    include <CL/cl.h>
33 #  endif
34 #pragma GCC diagnostic pop
35
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39
40 typedef enum {
41   CL_ICDL_OCL_VERSION=1,
42   CL_ICDL_VERSION=2,
43   CL_ICDL_NAME=3,
44   CL_ICDL_VENDOR=4,
45 } cl_icdl_info;
46
47 typedef cl_int (*clGetICDLoaderInfoOCLICD_fn)(
48   cl_icdl_info     param_name,
49   size_t           param_value_size, 
50   void *           param_value,
51   size_t *         param_value_size_ret);
52
53 int main(int argc, char* argv[]) {
54   cl_int error;
55
56   clGetICDLoaderInfoOCLICD_fn clGetICDLoaderInfoOCLICD=NULL;
57 #pragma GCC diagnostic push
58 #  pragma GCC diagnostic ignored "-Wdeprecated-declarations"
59   clGetICDLoaderInfoOCLICD = clGetExtensionFunctionAddress("clGetICDLoaderInfoOCLICD");
60 #pragma GCC diagnostic pop
61
62   if (clGetICDLoaderInfoOCLICD == NULL) {
63     printf("No clGetICDLoaderInfoOCLICD function available\n");
64     return 2;
65   }
66   {
67     char *param_value=NULL;
68     size_t param_value_size_ret=0;
69
70 #define show(name,NAME) \
71   do { \
72     error = clGetICDLoaderInfoOCLICD(CL_ICDL_##NAME, 0, NULL, &param_value_size_ret ); \
73     if (error) { exit(4); } \
74     param_value = (char *)malloc(param_value_size_ret); \
75     clGetICDLoaderInfoOCLICD(CL_ICDL_##NAME, param_value_size_ret, param_value, NULL); \
76     printf(#name ": %s\n",param_value); \
77     free(param_value); \
78     param_value=NULL; \
79   } while (0)
80
81     show(ocl_version,OCL_VERSION);
82     show(version,VERSION);
83     show(name,NAME);
84     show(vendor,VENDOR);
85   }
86   return 0;
87 }