Branch data Line data Source code
1 : : /* StarPU --- Runtime system for heterogeneous multicore architectures.
2 : : *
3 : : * Copyright (C) 2010,2011 University of Bordeaux
4 : : *
5 : : * StarPU is free software; you can redistribute it and/or modify
6 : : * it under the terms of the GNU Lesser General Public License as published by
7 : : * the Free Software Foundation; either version 2.1 of the License, or (at
8 : : * your option) any later version.
9 : : *
10 : : * StarPU is distributed in the hope that it will be useful, but
11 : : * WITHOUT ANY WARRANTY; without even the implied warranty of
12 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 : : *
14 : : * See the GNU Lesser General Public License in COPYING.LGPL for more details.
15 : : */
16 : :
17 : :
18 : : #include <stdio.h>
19 : : #include <stdlib.h>
20 : :
21 : : #include <CL/cl.h>
22 : :
23 : : static inline void
24 : 410 : checkErr(cl_int err, const char * name) {
25 [ - + ]: 410 : if (err != CL_SUCCESS) {
26 : 0 : fprintf(stderr, "ERROR: %s (%d)\n", name, err);
27 : 0 : exit(1);
28 : : }
29 : 410 : }
30 : :
31 : : int
32 : 1 : main(void) {
33 : : cl_int err;
34 : : cl_uint num_platforms;
35 : :
36 : : // Plaform info
37 : 1 : err = clGetPlatformIDs(0, NULL, &num_platforms);
38 [ - + ]: 1 : if (num_platforms == 0) {
39 : 0 : printf("No OpenCL platform found.\n");
40 : 0 : exit(77);
41 : : }
42 : 1 : checkErr(err, "Unable to get platform count");
43 : :
44 : 1 : cl_platform_id platforms[num_platforms];
45 : 1 : err = clGetPlatformIDs(num_platforms, platforms, NULL);
46 : 1 : checkErr(err, "Unable to get platform list");
47 : :
48 : : // Iteratate over platforms
49 : 1 : printf("Number of platforms:\t\t\t\t %d\n", num_platforms);
50 : :
51 : : {
52 : : unsigned int i;
53 [ + + ]: 5 : for (i=0; i<num_platforms; i++) {
54 : : char str[4096];
55 : 4 : err = clGetPlatformInfo(platforms[i], CL_PLATFORM_PROFILE, sizeof(str), str, NULL);
56 : 4 : checkErr(err, "clGetPlatformInfo(CL_PLATFORM_PROFILE)");
57 : 4 : printf(" Plaform Profile:\t\t\t\t %s\n", str);
58 : :
59 : 4 : err= clGetPlatformInfo(platforms[i], CL_PLATFORM_VERSION, sizeof(str), str, NULL);
60 : 4 : checkErr(err, "clGetPlatformInfo(CL_PLATFORM_VERSION)");
61 : 4 : printf(" Plaform Version:\t\t\t\t %s\n", str);
62 : :
63 : 4 : err = clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, sizeof(str), str, NULL);
64 : 4 : checkErr(err, "clGetPlatformInfo(CL_PLATFORM_NAME)");
65 : 4 : printf(" Plaform Name:\t\t\t\t\t %s\n", str);
66 : :
67 : 4 : err = clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, sizeof(str), str, NULL);
68 : 4 : checkErr(err, "clGetPlatformInfo(CL_PLATFORM_VENDOR)");
69 : 4 : printf(" Plaform Vendor:\t\t\t\t %s\n", str);
70 : :
71 : 4 : err = clGetPlatformInfo(platforms[i], CL_PLATFORM_EXTENSIONS, sizeof(str), str, NULL);
72 : 4 : checkErr(err, "clGetPlatformInfo(CL_PLATFORM_EXTENSIONS)");
73 : 4 : printf(" Plaform Extensions:\t\t\t %s\n", str);
74 : : }
75 : : }
76 : :
77 : 1 : printf("\n\n");
78 : :
79 : : // Now Iteratate over each platform and its devices
80 : : {
81 : : unsigned int i;
82 [ + + ]: 5 : for (i=0; i<num_platforms; i++) {
83 : : char str[4096];
84 : : cl_uint num_devices;
85 : :
86 : 4 : err = clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, sizeof(str), &str, NULL);
87 : 4 : checkErr(err, "clGetPlatformInfo(CL_PLATFORM_NAME)");
88 : 4 : printf(" Plaform Name:\t\t\t\t\t %s\n", str);
89 : :
90 : 4 : err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
91 : 4 : checkErr(err, "clGetDeviceIds(CL_DEVICE_TYPE_ALL)");
92 [ - + ]: 4 : if (num_devices == 0) {
93 : 0 : printf(" No devices found\n");
94 : 0 : continue;
95 : : }
96 : :
97 : 4 : cl_device_id devices[num_devices];
98 : :
99 : 4 : err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, num_devices, devices, NULL);
100 : 4 : checkErr(err, "clGetDeviceIds(CL_DEVICE_TYPE_ALL)");
101 : :
102 : 4 : printf(" Number of devices:\t\t\t\t %d\n", num_devices);
103 : : {
104 : : unsigned int j;
105 [ + + ]: 12 : for (j=0; j<num_devices; j++) {
106 : : cl_device_type dev_type;
107 : 8 : printf("\n DEVICE %d\n", j);
108 : :
109 : 8 : err = clGetDeviceInfo(devices[j], CL_DEVICE_TYPE, sizeof(dev_type), &dev_type, NULL);
110 : 8 : checkErr(err, "clGetDeviceInfo(CL_DEVICE_TYPE)");
111 : :
112 : 8 : printf(" Device Type:\t\t\t\t\t ");
113 [ - + ]: 8 : if (dev_type & CL_DEVICE_TYPE_ACCELERATOR)
114 : 0 : printf("CL_DEVICE_TYPE_ACCELERATOR ");
115 [ + + ]: 8 : else if (dev_type & CL_DEVICE_TYPE_CPU)
116 : 2 : printf("CL_DEVICE_TYPE_CPU ");
117 [ + - ]: 6 : else if (dev_type & CL_DEVICE_TYPE_GPU)
118 : 6 : printf("CL_DEVICE_TYPE_GPU ");
119 [ # # ]: 0 : else if (dev_type & CL_DEVICE_TYPE_DEFAULT)
120 : 0 : printf("CL_DEVICE_TYPE_DEFAULT ");
121 : :
122 : 8 : printf("\n");
123 : :
124 : : {
125 : : cl_uint vendor_id;
126 : 8 : err = clGetDeviceInfo(devices[j], CL_DEVICE_VENDOR_ID, sizeof(vendor_id), &vendor_id, NULL);
127 : 8 : checkErr(err, "clGetDeviceInfo(CL_DEVICE_VENDOR_ID)");
128 : 8 : printf(" Device ID:\t\t\t\t\t %d\n", vendor_id);
129 : : }
130 : : {
131 : : cl_uint units;
132 : 8 : err = clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(units), &units, NULL);
133 : 8 : checkErr(err, "clGetDeviceInfo(CL_DEVICE_MAX_COMPUTE_UNITS)");
134 : 8 : printf(" Max compute units:\t\t\t\t %d\n", units);
135 : : }
136 : :
137 : : {
138 : : cl_uint dims;
139 : 8 : err = clGetDeviceInfo(devices[j], CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof(dims), &dims, NULL);
140 : 8 : checkErr(err, "clGetDeviceInfo(CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS)");
141 : 8 : printf(" Max work item dimensions:\t\t\t %d\n", dims);
142 : :
143 : 8 : size_t sizes[dims];
144 : 8 : err = clGetDeviceInfo(devices[j], CL_DEVICE_MAX_WORK_ITEM_SIZES, sizeof(size_t)*dims, sizes, NULL);
145 : 8 : checkErr(err, "clGetDeviceInfo(CL_DEVICE_MAX_WORK_ITEM_SIZES)");
146 : 8 : printf(" Max work item dimensions:\t\t\t %d\n", dims);
147 : :
148 : : {
149 : : unsigned int k;
150 : 8 : printf(" Max work items:\t\t\t\t (");
151 [ + + ]: 32 : for (k=0; k<dims; k++) {
152 : 24 : printf("%u", (unsigned int)sizes[k]);
153 [ + + ]: 24 : if (k != dims-1)
154 : 16 : printf(",");
155 : : }
156 : 8 : printf(")\n");
157 : : }
158 : : }
159 : :
160 : : #define GET_SIZET(CL_D,str) { \
161 : : size_t val; \
162 : : err = clGetDeviceInfo(devices[j], CL_D, sizeof(val), &val, NULL); \
163 : : checkErr(err, "clGetDeviceInfo(" #CL_D ")"); \
164 : : printf(str, (unsigned int)val); \
165 : : }
166 : :
167 : : #define GET_STRING(CL_D,str,size) { \
168 : : char val[size]; \
169 : : err = clGetDeviceInfo(devices[j], CL_D, sizeof(val), val, NULL); \
170 : : checkErr(err, "clGetDeviceInfo(" #CL_D ")"); \
171 : : printf(str, val); \
172 : : }
173 : :
174 : : #define GET_UINT(CL_D,str) { \
175 : : cl_uint val; \
176 : : err = clGetDeviceInfo(devices[j], CL_D, sizeof(val), &val, NULL); \
177 : : checkErr(err, "clGetDeviceInfo(" #CL_D ")"); \
178 : : printf(str, val); \
179 : : }
180 : :
181 : : #define GET_ULONG(CL_D,str) { \
182 : : cl_ulong val; \
183 : : err = clGetDeviceInfo(devices[j], CL_D, sizeof(val), &val, NULL); \
184 : : checkErr(err, "clGetDeviceInfo(" #CL_D ")"); \
185 : : printf(str, val); \
186 : : }
187 : :
188 : : #define GET_BOOL(CL_D,str) { \
189 : : cl_bool val; \
190 : : err = clGetDeviceInfo(devices[j], CL_D, sizeof(val), &val, NULL); \
191 : : checkErr(err, "clGetDeviceInfo(" #CL_D ")"); \
192 : : printf(str, (val == CL_TRUE ? "Yes" : "No")); \
193 : : }
194 : :
195 : : #define GET_BOOL_CUSTOM(CL_D,str,t,f) { \
196 : : cl_bool val; \
197 : : err = clGetDeviceInfo(devices[j], CL_D, sizeof(val), &val, NULL); \
198 : : checkErr(err, "clGetDeviceInfo(" #CL_D ")"); \
199 : : printf(str, (val == CL_TRUE ? t : f)); \
200 : : }
201 : :
202 : : #define GET_BITSET_AND(TYPE,CL_D,test,str) { \
203 : : TYPE val; \
204 : : err = clGetDeviceInfo(devices[j], CL_D, sizeof(val), &val, NULL); \
205 : : checkErr(err, "clGetDeviceInfo(" #CL_D ")"); \
206 : : printf(str, ((val & test) == CL_TRUE ? "Yes" : "No")); \
207 : : }
208 : :
209 : 8 : GET_SIZET(CL_DEVICE_MAX_WORK_GROUP_SIZE, " Max work group size:\t\t\t\t %u\n")
210 : :
211 : 8 : GET_UINT(CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, " Preferred vector width char:\t\t\t %u\n")
212 : 8 : GET_UINT(CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, " Preferred vector width short:\t\t\t %u\n")
213 : 8 : GET_UINT(CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, " Preferred vector width int:\t\t\t %u\n")
214 : 8 : GET_UINT(CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, " Preferred vector width long:\t\t\t %u\n")
215 : 8 : GET_UINT(CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, " Preferred vector width float:\t\t\t %u\n")
216 : 8 : GET_UINT(CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, " Preferred vector width double:\t\t %u\n")
217 : 8 : GET_UINT(CL_DEVICE_MAX_CLOCK_FREQUENCY, " Max clock frequency:\t\t\t\t %uMHz\n")
218 : 8 : GET_UINT(CL_DEVICE_ADDRESS_BITS, " Address bits:\t\t\t\t\t %ubits\n")
219 : 8 : GET_ULONG(CL_DEVICE_MAX_MEM_ALLOC_SIZE, " Max memory allocation:\t\t\t %lu bytes\n")
220 : :
221 [ + + ]: 8 : GET_BOOL(CL_DEVICE_IMAGE_SUPPORT, " Image support:\t\t\t\t %s\n")
222 : :
223 : 8 : GET_SIZET(CL_DEVICE_MAX_PARAMETER_SIZE, " Max size of kernel argument:\t\t\t %u\n")
224 : 8 : GET_UINT(CL_DEVICE_MEM_BASE_ADDR_ALIGN, " Alignment of base addres:\t\t\t %u bits\n")
225 : 8 : GET_UINT(CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, " Minimum alignment for any datatype:\t\t %u bytes\n")
226 : :
227 : 8 : printf(" Single precision floating point capability\n");
228 [ + + ]: 8 : GET_BITSET_AND(cl_device_fp_config,CL_DEVICE_SINGLE_FP_CONFIG, CL_FP_DENORM, " Denorms:\t\t\t\t\t %s\n")
229 : 8 : GET_BITSET_AND(cl_device_fp_config,CL_DEVICE_SINGLE_FP_CONFIG, CL_FP_INF_NAN, " Quiet NaNs:\t\t\t\t\t %s\n")
230 : 8 : GET_BITSET_AND(cl_device_fp_config,CL_DEVICE_SINGLE_FP_CONFIG, CL_FP_ROUND_TO_NEAREST, " Round to nearest even:\t\t\t %s\n")
231 : 8 : GET_BITSET_AND(cl_device_fp_config,CL_DEVICE_SINGLE_FP_CONFIG, CL_FP_ROUND_TO_ZERO, " Round to zero:\t\t\t\t %s\n")
232 : 8 : GET_BITSET_AND(cl_device_fp_config,CL_DEVICE_SINGLE_FP_CONFIG, CL_FP_ROUND_TO_INF, " Round to +ve and infinity:\t\t\t %s\n")
233 : 8 : GET_BITSET_AND(cl_device_fp_config,CL_DEVICE_SINGLE_FP_CONFIG, CL_FP_FMA, " IEEE754-2008 fused multiply-add:\t\t %s\n")
234 : :
235 : : {
236 : : cl_device_mem_cache_type cache;
237 : 8 : err = clGetDeviceInfo(devices[j], CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, sizeof(cache), &cache, NULL);
238 : 8 : checkErr(err, "clGetDeviceInfo(CL_DEVICE_GLOBAL_MEM_CACHE_TYPE)");
239 : 8 : printf(" Cache type:\t\t\t\t\t ");
240 [ + - + - ]: 8 : switch (cache) {
241 : : case CL_NONE:
242 : 6 : printf("None\n");
243 : 6 : break;
244 : : case CL_READ_ONLY_CACHE:
245 : 0 : printf("Read only\n");
246 : 0 : break;
247 : : case CL_READ_WRITE_CACHE:
248 : 2 : printf("Read/Write\n");
249 : 2 : break;
250 : : }
251 : : }
252 : :
253 : 8 : GET_UINT(CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, " Cache line size:\t\t\t\t %u bytes\n")
254 : 8 : GET_ULONG(CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, " Cache size:\t\t\t\t\t %lu bytes\n")
255 : 8 : GET_ULONG(CL_DEVICE_GLOBAL_MEM_SIZE, " Global memory size:\t\t\t\t %lu bytes\n")
256 : 8 : GET_ULONG(CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, " Constant buffer size:\t\t\t\t %lu bytes\n")
257 : 8 : GET_UINT(CL_DEVICE_MAX_CONSTANT_ARGS, " Max number of constant args:\t\t\t %u\n")
258 : :
259 : : {
260 : : cl_device_local_mem_type cache;
261 : 8 : err = clGetDeviceInfo(devices[j], CL_DEVICE_LOCAL_MEM_TYPE, sizeof(cache), &cache, NULL);
262 : 8 : checkErr(err, "clGetDeviceInfo(CL_DEVICE_LOCAL_MEM_TYPE)");
263 : 8 : printf(" Local memory type:\t\t\t\t ");
264 [ + + - ]: 8 : switch (cache) {
265 : : case CL_LOCAL:
266 : 6 : printf("Local\n");
267 : 6 : break;
268 : : case CL_GLOBAL:
269 : 2 : printf("Global\n");
270 : 2 : break;
271 : : }
272 : : }
273 : :
274 : 8 : GET_ULONG(CL_DEVICE_LOCAL_MEM_SIZE, " Local memory size:\t\t\t\t %lu bytes\n")
275 : 8 : GET_SIZET(CL_DEVICE_PROFILING_TIMER_RESOLUTION, " Profiling timer resolution:\t\t\t %u\n")
276 [ + - ]: 8 : GET_BOOL_CUSTOM(CL_DEVICE_ENDIAN_LITTLE, " Device endianess:\t\t\t\t %s\n", "Little", "Big")
277 [ + - ]: 8 : GET_BOOL(CL_DEVICE_AVAILABLE, " Available:\t\t\t\t\t %s\n")
278 [ + - ]: 8 : GET_BOOL(CL_DEVICE_COMPILER_AVAILABLE, " Compiler available:\t\t\t\t %s\n")
279 : :
280 : 8 : printf(" Execution capabilities:\t\t\t\t \n");
281 [ + - ]: 8 : GET_BITSET_AND(cl_device_exec_capabilities, CL_DEVICE_EXECUTION_CAPABILITIES, CL_EXEC_KERNEL, " Execute OpenCL kernels:\t\t\t %s\n")
282 : 8 : GET_BITSET_AND(cl_device_exec_capabilities, CL_DEVICE_EXECUTION_CAPABILITIES, CL_EXEC_NATIVE_KERNEL, " Execute native kernels:\t\t\t %s\n")
283 : :
284 : 8 : printf(" Queue properties:\t\t\t\t\n ");
285 [ + + ]: 8 : GET_BITSET_AND(cl_command_queue_properties, CL_DEVICE_QUEUE_PROPERTIES, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, " Out-of-Order:\t\t\t\t %s\n")
286 : 8 : GET_BITSET_AND(cl_command_queue_properties, CL_DEVICE_QUEUE_PROPERTIES, CL_QUEUE_PROFILING_ENABLE, " Profiling:\t\t\t\t\t %s\n")
287 : :
288 : :
289 : 8 : GET_STRING(CL_DEVICE_NAME, " Name:\t\t\t\t\t\t %s\n", 256);
290 : 8 : GET_STRING(CL_DEVICE_VENDOR, " Vendor:\t\t\t\t\t %s\n", 256);
291 : 8 : GET_STRING(CL_DRIVER_VERSION, " Driver version:\t\t\t\t %s\n", 256);
292 : 8 : GET_STRING(CL_DEVICE_PROFILE, " Profile:\t\t\t\t\t %s\n", 256);
293 : 8 : GET_STRING(CL_DEVICE_VERSION, " Version:\t\t\t\t\t %s\n", 256);
294 : 8 : GET_STRING(CL_DEVICE_EXTENSIONS, " Extensions:\t\t\t\t\t %s\n", 4096);
295 : :
296 : 8 : printf("\n");
297 : : }
298 : : }
299 : : }
300 : : }
301 : :
302 : 1 : return 0;
303 : : }
|