cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / cl / api / get-device-info.c
blob9e7123525da6df41849d9e3099f2045b71e15fc6
1 /*
2 * Copyright © 2012 Blaž Tomažič <blaz.tomazic@gmail.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 /**
25 * @file get-device-info.c
27 * Test API function:
29 * cl_int clGetDeviceInfo(cl_device_id device,
30 * cl_device_info param_name,
31 * size_t param_value_size,
32 * void *param_value,
33 * size_t *param_value_size_ret)
36 #include "piglit-framework-cl-api.h"
39 PIGLIT_CL_API_TEST_CONFIG_BEGIN
41 config.name = "clGetDeviceInfo";
42 config.version_min = 10;
44 config.run_per_device = true;
46 PIGLIT_CL_API_TEST_CONFIG_END
48 struct device_config {
49 cl_uint max_unit;
50 cl_ulong mem_size;
51 bool is_full_profile;
52 cl_device_type type;
53 bool has_double;
54 bool has_image;
55 } device_config_t;
57 static bool
58 check_size(size_t expected_size, size_t actual_size, enum piglit_result *result) {
59 if (expected_size != actual_size) {
60 printf(": failed, expected and actual size differ. Expect %lu, got %lu",
61 (unsigned long) expected_size, (unsigned long) actual_size);
62 piglit_merge_result(result, PIGLIT_FAIL);
63 return false;
66 return true;
69 static bool
70 check_fp_config(cl_device_info kind, cl_device_fp_config value,
71 enum piglit_result *result) {
72 cl_device_fp_config allowed_flags = CL_FP_DENORM|
73 CL_FP_INF_NAN|CL_FP_ROUND_TO_NEAREST|
74 CL_FP_ROUND_TO_ZERO|CL_FP_ROUND_TO_INF|
75 CL_FP_FMA|CL_FP_SOFT_FLOAT;
77 if (kind == CL_DEVICE_SINGLE_FP_CONFIG) {
78 allowed_flags |= CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT;
81 if (value & ~(allowed_flags)) {
82 printf(": failed, expected a combination of CL_FP_*. Got %lx", value);
83 piglit_merge_result(result, PIGLIT_FAIL);
84 printf("\n %lx", value);
85 return false;
88 return true;
91 static bool
92 check_string_not_empty(size_t actual_size, char* actual_value, enum piglit_result *result) {
93 if (actual_size && !actual_value) {
94 printf(": failed, actual size is %zu, but string is NULL", actual_size);
95 piglit_merge_result(result, PIGLIT_FAIL);
96 return false;
99 if (!actual_size || !actual_value || actual_value[0] == '\0') {
100 printf(": failed, string should not be empty");
101 piglit_merge_result(result, PIGLIT_FAIL);
102 return false;
105 return true;
108 static bool
109 check_sub_string(char* expected_sub, char* actual_value, enum piglit_result *result) {
110 if (strstr(actual_value, expected_sub) == 0) {
111 printf(": failed, '%s' should contains '%s'", actual_value, expected_sub);
112 piglit_merge_result(result, PIGLIT_FAIL);
113 return false;
116 return true;
119 static bool
120 check_min_int(size_t expected, size_t actual_value, enum piglit_result *result) {
121 if (actual_value < expected) {
122 printf(": failed, expected at least %lu, got %lu ", (unsigned long) expected, (unsigned long) actual_value);
123 piglit_merge_result(result, PIGLIT_FAIL);
124 return false;
127 return true;
130 static bool
131 check_max_int(size_t expected, size_t actual_value, enum piglit_result *result) {
132 if (actual_value > expected) {
133 printf(": failed, expected at most %lu, got %lu ", (unsigned long) expected, (unsigned long) actual_value);
134 piglit_merge_result(result, PIGLIT_FAIL);
135 return false;
138 return true;
141 static void
142 print_s(const char* str) {
143 if (str) {
144 printf(": '%s'", str);
145 } else {
146 printf(": (null)");
150 static void
151 print_u(size_t i) {
152 printf(": %zu", i);
155 static void
156 print_b(cl_bool b) {
157 if (b) {
158 printf(": CL_TRUE");
159 } else {
160 printf(": CL_FALSE");
164 static void
165 check_info(const struct piglit_cl_api_test_env* env,
166 struct device_config* device_config,
167 cl_device_info kind, void* param_value, size_t param_value_size,
168 enum piglit_result *result) {
169 bool valid = true;
171 switch (kind) {
172 case CL_DEVICE_NAME:
173 case CL_DEVICE_VENDOR:
174 case CL_DRIVER_VERSION:
175 case CL_DEVICE_BUILT_IN_KERNELS:
176 print_s(param_value);
177 break;
178 case CL_DEVICE_PROFILE:
179 if (check_string_not_empty(param_value_size, param_value, result)) {
180 if (strcmp("FULL_PROFILE", param_value) &&
181 strcmp("EMBEDDED_PROFILE", param_value)) {
182 printf(": failed, expected and actual string differ. Expect '%s', got '%s'",
183 "FULL_PROFILE or EMBEDDED_PROFILE", (char*)param_value);
184 piglit_merge_result(result, PIGLIT_FAIL);
185 } else {
186 device_config->is_full_profile = strcmp("FULL_PROFILE", param_value) == 0;
187 print_s(param_value);
190 break;
191 case CL_DEVICE_VERSION:
192 if (
193 check_string_not_empty(param_value_size, param_value, result) &&
195 (env->version == 30 && check_sub_string("OpenCL 3.0", param_value, result)) ||
196 (env->version == 12 && check_sub_string("OpenCL 1.2", param_value, result)) ||
197 check_sub_string("OpenCL 1.1", param_value, result)
200 print_s(param_value);
202 break;
203 case CL_DEVICE_OPENCL_C_VERSION:
204 if (
205 check_string_not_empty(param_value_size, param_value, result) &&
207 (env->version == 30 && check_sub_string("OpenCL C 1.2 ", param_value, result)) || /* TODO: vendor part after space */
208 (env->version == 12 && check_sub_string("OpenCL C 1.2", param_value, result)) ||
209 check_sub_string("OpenCL C 1.1", param_value, result)
212 print_s(param_value);
214 break;
215 case CL_DEVICE_IMAGE_SUPPORT:
216 if (check_size(sizeof(cl_bool), param_value_size, result)) {
217 device_config->has_image = *(cl_bool*)param_value;
218 print_b(*(cl_bool*)param_value);
220 break;
221 case CL_DEVICE_EXTENSIONS:
222 if (env->version == 12) {
223 valid = check_sub_string("cl_khr_global_int32_base_atomics", param_value, result);
224 valid &= check_sub_string("cl_khr_global_int32_extended_atomics", param_value, result);
225 valid &= check_sub_string("cl_khr_local_int32_base_atomics", param_value, result);
226 valid &= check_sub_string("cl_khr_local_int32_extended_atomics", param_value, result);
227 valid &= check_sub_string("cl_khr_byte_addressable_store", param_value, result);
228 if (device_config->has_double) {
229 valid &= check_sub_string("cl_khr_fp64", param_value, result);
233 if (valid) {
234 print_s(param_value);
236 break;
237 case CL_DEVICE_TYPE:
238 if (check_size(sizeof(cl_device_type), param_value_size, result)) {
239 valid = false;
241 int num_type = PIGLIT_CL_ENUM_NUM(cl_device_type, env->version);
242 const cl_device_type *type = PIGLIT_CL_ENUM_ARRAY(cl_device_type);
243 for(int i = 0; i < num_type; i++) {
244 valid |= type[i] & *(cl_device_type*)param_value;
247 if (!valid) {
248 printf(": failed, unexpected value");
249 piglit_merge_result(result, PIGLIT_FAIL);
252 break;
253 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE:
254 if (check_size(sizeof(cl_uint), param_value_size, result)) {
255 if (*(cl_uint*)param_value) {
256 device_config->has_double = true;
258 print_u(*(cl_uint*)param_value);
260 break;
261 case CL_DEVICE_VENDOR_ID:
262 case CL_DEVICE_ADDRESS_BITS:
263 case CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS:
264 case CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE:
265 case CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE:
266 case CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR:
267 case CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT:
268 case CL_DEVICE_NATIVE_VECTOR_WIDTH_INT:
269 case CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG:
270 case CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF:
271 case CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT:
272 case CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE:
273 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR:
274 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT:
275 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT:
276 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG:
277 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF:
278 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT:
279 if (check_size(sizeof(cl_uint), param_value_size, result)) {
280 print_u(*(cl_uint*)param_value);
282 break;
283 case CL_DEVICE_MAX_WORK_GROUP_SIZE:
284 case CL_DEVICE_MAX_PARAMETER_SIZE:
285 case CL_DEVICE_PROFILING_TIMER_RESOLUTION:
286 if (check_size(sizeof(size_t), param_value_size, result)) {
287 print_u(*(size_t*)param_value);
289 break;
290 case CL_DEVICE_MAX_WORK_ITEM_SIZES:
291 if (check_size(sizeof(size_t) * 3, param_value_size, result)) {
292 printf(": (%zu, %zu, %zu)",
293 ((size_t*)param_value)[0],
294 ((size_t*)param_value)[1],
295 ((size_t*)param_value)[2]);
297 break;
298 case CL_DEVICE_MAX_CLOCK_FREQUENCY:
299 if (check_size(sizeof(cl_uint), param_value_size, result)) {
300 printf(": %u MHz", *(cl_uint*)param_value);
302 break;
303 case CL_DEVICE_MAX_COMPUTE_UNITS:
304 valid = check_size(sizeof(cl_uint), param_value_size, result) &&
305 check_min_int(1, *(cl_uint*)param_value, result);
307 if (valid) {
308 device_config->max_unit = *(cl_uint*)param_value;
309 print_u(*(cl_uint*)param_value);
311 break;
312 case CL_DEVICE_MAX_WRITE_IMAGE_ARGS:
313 valid = check_size(sizeof(cl_uint), param_value_size, result);
314 if (valid && device_config->has_image) {
315 valid = check_min_int(8, *(cl_uint*)param_value, result);
318 if (valid) {
319 print_u(*(cl_uint*)param_value);
321 break;
322 case CL_DEVICE_MAX_MEM_ALLOC_SIZE:
323 valid = check_size(sizeof(cl_ulong), param_value_size, result);
324 if (valid && device_config->type != CL_DEVICE_TYPE_CUSTOM) {
325 valid = check_min_int(MAX2(device_config->mem_size/4, 128*1024*1024),
326 *(cl_ulong*)param_value,
327 result);
330 if (valid) {
331 print_u(*(cl_ulong*)param_value);
333 break;
334 case CL_DEVICE_IMAGE_MAX_BUFFER_SIZE:
335 valid = check_size(sizeof(size_t), param_value_size, result);
336 if (valid && device_config->has_image) {
337 valid = check_min_int(65536, *(size_t*)param_value, result);
340 if (valid) {
341 print_u(*(size_t*)param_value);
343 break;
344 case CL_DEVICE_IMAGE2D_MAX_WIDTH:
345 case CL_DEVICE_IMAGE2D_MAX_HEIGHT:
346 valid = check_size(sizeof(size_t), param_value_size, result);
347 if (valid && device_config->has_image) {
348 valid = check_min_int(8192, *(size_t*)param_value, result);
351 if (valid) {
352 print_u(*(size_t*)param_value);
354 break;
355 case CL_DEVICE_IMAGE_MAX_ARRAY_SIZE:
356 case CL_DEVICE_IMAGE3D_MAX_WIDTH:
357 case CL_DEVICE_IMAGE3D_MAX_HEIGHT:
358 case CL_DEVICE_IMAGE3D_MAX_DEPTH:
359 valid = check_size(sizeof(size_t), param_value_size, result);
360 if (valid && device_config->has_image) {
361 valid = check_min_int(2048, *(size_t*)param_value, result);
364 if (valid) {
365 print_u(*(size_t*)param_value);
367 break;
368 case CL_DEVICE_MAX_READ_IMAGE_ARGS:
369 valid = check_size(sizeof(cl_uint), param_value_size, result);
370 if (valid && device_config->has_image) {
371 valid = check_min_int(128, *(cl_uint*)param_value, result);
374 if (valid) {
375 print_u(*(cl_uint*)param_value);
377 break;
378 case CL_DEVICE_MAX_SAMPLERS:
379 valid = check_size(sizeof(cl_uint), param_value_size, result);
380 if (valid && device_config->has_image) {
381 valid = check_min_int(16, *(cl_uint*)param_value, result);
384 if (valid) {
385 print_u(*(cl_uint*)param_value);
387 break;
388 case CL_DEVICE_MEM_BASE_ADDR_ALIGN:
389 valid = check_size(sizeof(cl_uint), param_value_size, result);
390 if (valid && device_config->is_full_profile) {
391 valid = check_min_int(sizeof(cl_long16), *(cl_uint*)param_value, result);
394 if (valid) {
395 print_u(*(cl_uint*)param_value);
397 break;
398 case CL_DEVICE_SINGLE_FP_CONFIG:
399 if (check_size(sizeof(cl_device_fp_config), param_value_size, result) &&
400 check_fp_config(kind, *(cl_device_fp_config*)param_value, result)) {
401 cl_device_fp_config value = *(cl_device_fp_config*)param_value;
402 if (device_config->type != CL_DEVICE_TYPE_CUSTOM &&
403 !(value & (CL_FP_ROUND_TO_ZERO|CL_FP_ROUND_TO_NEAREST))) {
404 printf(": failed, expected at least CL_FP_ROUND_TO_ZERO or CL_FP_ROUND_TO_NEAREST. Got %lx", value);
405 piglit_merge_result(result, PIGLIT_FAIL);
406 } else {
407 printf(": %lx", value);
410 break;
411 case CL_DEVICE_DOUBLE_FP_CONFIG:
412 if (check_size(sizeof(cl_device_fp_config), param_value_size, result) &&
413 check_fp_config(kind, *(cl_device_fp_config*)param_value, result)) {
414 cl_device_fp_config value = *(cl_device_fp_config*)param_value;
415 if (device_config->type != CL_DEVICE_TYPE_CUSTOM &&
416 device_config->has_double) {
417 if (env->version <= 12 && !(value & (CL_FP_FMA|CL_FP_ROUND_TO_NEAREST|CL_FP_ROUND_TO_ZERO|
418 CL_FP_ROUND_TO_INF|CL_FP_INF_NAN|CL_FP_DENORM))) {
419 printf(": failed, expected CL_FP_FMA|CL_FP_ROUND_TO_NEAREST|CL_FP_ROUND_TO_ZERO|" \
420 "CL_FP_ROUND_TO_INF|CL_FP_INF_NAN|CL_FP_DENORM. Got %lx", value);
421 piglit_merge_result(result, PIGLIT_FAIL);
422 } else if /* OpenCL >= 2.0 */ (!(value & (CL_FP_FMA|CL_FP_ROUND_TO_NEAREST|CL_FP_INF_NAN|CL_FP_DENORM))) {
423 printf(": failed, expected CL_FP_FMA|CL_FP_ROUND_TO_NEAREST|CL_FP_INF_NAN|CL_FP_DENORM. Got %lx", value);
424 piglit_merge_result(result, PIGLIT_FAIL);
426 } else {
427 printf(": %lx", value);
430 break;
431 case CL_DEVICE_GLOBAL_MEM_CACHE_TYPE:
432 if (check_size(sizeof(cl_device_mem_cache_type), param_value_size, result)) {
433 if (*(cl_device_mem_cache_type*)param_value & ~(CL_READ_ONLY_CACHE|CL_READ_WRITE_CACHE)) {
434 printf(": failed, expected CL_READ_ONLY_CACHE or CL_READ_WRITE_CACHE. Got %x",
435 *(cl_device_mem_cache_type*)param_value);
436 piglit_merge_result(result, PIGLIT_FAIL);
437 } else {
438 printf(": %x", *(cl_device_mem_cache_type*)param_value);
441 break;
442 case CL_DEVICE_GLOBAL_MEM_CACHE_SIZE:
443 if (check_size(sizeof(cl_ulong), param_value_size, result)) {
444 print_u(*(cl_ulong*)param_value);
446 break;
447 case CL_DEVICE_GLOBAL_MEM_SIZE:
448 if (check_size(sizeof(cl_ulong), param_value_size, result)) {
449 device_config->mem_size = *(cl_ulong*)param_value;
450 print_u(*(cl_ulong*)param_value);
452 break;
453 case CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE:
454 valid = check_size(sizeof(cl_ulong), param_value_size, result);
455 if (valid && device_config->type != CL_DEVICE_TYPE_CUSTOM) {
456 valid = check_min_int(64 * 1024, *(cl_ulong*)param_value, result);
459 if (valid) {
460 print_u(*(cl_ulong*)param_value);
462 break;
463 case CL_DEVICE_MAX_CONSTANT_ARGS:
464 valid = check_size(sizeof(cl_uint), param_value_size, result);
465 if (valid && device_config->type != CL_DEVICE_TYPE_CUSTOM) {
466 valid = check_min_int(8, *(cl_uint*)param_value, result);
469 if (valid) {
470 print_u(*(cl_uint*)param_value);
472 break;
473 case CL_DEVICE_LOCAL_MEM_TYPE:
474 if (check_size(sizeof(cl_device_local_mem_type), param_value_size, result)) {
475 if (*(cl_device_local_mem_type*)param_value & ~(CL_LOCAL|CL_GLOBAL)) {
476 printf(": failed, expected CL_LOCAL or CL_GLOBAL. Got %x",
477 *(cl_device_local_mem_type*)param_value);
478 piglit_merge_result(result, PIGLIT_FAIL);
481 break;
482 case CL_DEVICE_LOCAL_MEM_SIZE:
483 valid = check_size(sizeof(cl_ulong), param_value_size, result);
484 if (valid && device_config->type != CL_DEVICE_TYPE_CUSTOM) {
485 valid = check_min_int(32 * 1024, *(cl_ulong*)param_value, result);
488 if (valid) {
489 print_u(*(cl_ulong*)param_value);
491 break;
492 case CL_DEVICE_PREFERRED_INTEROP_USER_SYNC:
493 case CL_DEVICE_ERROR_CORRECTION_SUPPORT:
494 case CL_DEVICE_HOST_UNIFIED_MEMORY:
495 case CL_DEVICE_ENDIAN_LITTLE:
496 case CL_DEVICE_AVAILABLE:
497 if (check_size(sizeof(cl_bool), param_value_size, result)) {
498 print_b(*(cl_bool*)param_value);
500 break;
501 case CL_DEVICE_COMPILER_AVAILABLE:
502 case CL_DEVICE_LINKER_AVAILABLE:
503 valid = check_size(sizeof(cl_bool), param_value_size, result);
504 if (valid && device_config->is_full_profile) {
505 valid = check_min_int(1, *(cl_bool*)param_value, result);
508 if (valid) {
509 print_b(*(cl_bool*)param_value);
511 break;
512 case CL_DEVICE_EXECUTION_CAPABILITIES:
513 if (check_size(sizeof(cl_device_exec_capabilities), param_value_size, result)) {
514 cl_device_exec_capabilities value =
515 *(cl_device_exec_capabilities*)param_value;
517 if ((value & ~(CL_EXEC_KERNEL|CL_EXEC_NATIVE_KERNEL)) ||
518 !(value & CL_EXEC_KERNEL)) {
519 printf(": failed, expected CL_EXEC_KERNEL and optional CL_EXEC_NATIVE_KERNEL");
520 piglit_merge_result(result, PIGLIT_FAIL);
521 } else {
522 printf (": CL_EXEC_KERNEL");
523 if (value & CL_EXEC_NATIVE_KERNEL) {
524 printf(", CL_EXEC_NATIVE_KERNEL");
528 break;
529 case CL_DEVICE_QUEUE_PROPERTIES:
530 if (check_size(sizeof(cl_command_queue_properties), param_value_size, result)) {
531 cl_command_queue_properties value =
532 *(cl_command_queue_properties*)param_value;
534 if ((value & ~(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE|CL_QUEUE_PROFILING_ENABLE)) ||
535 !(value & CL_QUEUE_PROFILING_ENABLE)) {
536 printf(": failed, expected CL_QUEUE_PROFILING_ENABLE and optional CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE");
537 piglit_merge_result(result, PIGLIT_FAIL);
538 } else {
539 printf (": CL_QUEUE_PROFILING_ENABLE");
540 if (value & CL_EXEC_NATIVE_KERNEL) {
541 printf(", CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE");
545 break;
546 case CL_DEVICE_PLATFORM:
547 if (check_size(sizeof(cl_platform_id), param_value_size, result)) {
548 if (*(cl_platform_id*)param_value != env->platform_id) {
549 printf(": failed, unexpected cl_platform_id value");
550 piglit_merge_result(result, PIGLIT_FAIL);
551 } else {
552 printf(": %p", param_value);
555 break;
556 case CL_DEVICE_PARENT_DEVICE:
557 if (check_size(sizeof(cl_device_id), param_value_size, result)) {
558 if (*(cl_device_id*)param_value) {
559 printf(": failed, parent device should be null, got %p", *(cl_device_id*)param_value);
560 piglit_merge_result(result, PIGLIT_FAIL);
561 } else {
562 printf(": %p", *(cl_device_id*)param_value);
565 break;
566 case CL_DEVICE_PARTITION_MAX_SUB_DEVICES:
567 if (check_size(sizeof(cl_uint), param_value_size, result) &&
568 check_max_int(device_config->max_unit, *(cl_uint*)param_value, result)) {
569 print_u(*(cl_uint*)param_value);
571 break;
572 case CL_DEVICE_PARTITION_PROPERTIES:
573 if (param_value_size < sizeof(cl_device_partition_property)) {
574 printf(": failed, expected and actual size differ. Expect >=%lu, got %lu",
575 (unsigned long) sizeof(cl_device_partition_property), (unsigned long) param_value_size);
576 piglit_merge_result(result, PIGLIT_FAIL);
577 } else {
578 // TODO this a array of cl_device_partition_property
579 // Only the first value is checked here.
580 if ((*(cl_device_partition_property*)param_value &
581 ~(CL_DEVICE_PARTITION_EQUALLY|
582 CL_DEVICE_PARTITION_BY_COUNTS|
583 CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN))) {
584 printf(": failed, expected a cl_device_partition_property valid value. Got %lx",
585 *(cl_device_partition_property*)param_value);
586 piglit_merge_result(result, PIGLIT_FAIL);
587 } else {
588 printf(": %lx", *(cl_device_partition_property*)param_value);
591 break;
592 case CL_DEVICE_PARTITION_AFFINITY_DOMAIN:
593 if ((*(cl_device_affinity_domain*)param_value &
594 ~(CL_DEVICE_AFFINITY_DOMAIN_NUMA|
595 CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE|
596 CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE|
597 CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE|
598 CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE|
599 CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE))) {
600 printf(": failed, expected a cl_device_affinity_domain valid value. Got %lx",
601 *(cl_device_affinity_domain*)param_value);
602 piglit_merge_result(result, PIGLIT_FAIL);
603 } else {
604 printf(": %lx", *(cl_device_affinity_domain*)param_value);
606 break;
607 case CL_DEVICE_PARTITION_TYPE:
608 if (param_value_size) {
609 if (param_value_size < sizeof(cl_device_affinity_domain)) {
610 printf(": failed, expected and actual size differ. Expect >=%lu, got %lu",
611 (unsigned long) sizeof(cl_device_affinity_domain), (unsigned long) param_value_size);
612 piglit_merge_result(result, PIGLIT_FAIL);
613 } else {
614 printf(": %lx", *(cl_device_affinity_domain*)param_value);
616 } else {
617 printf(": (empty)");
619 break;
620 case CL_DEVICE_REFERENCE_COUNT:
621 if (check_size(sizeof(cl_uint), param_value_size, result) &&
622 check_min_int(1, *(cl_uint*)param_value, result)) {
623 print_u(*(cl_uint*)param_value);
625 break;
626 case CL_DEVICE_PRINTF_BUFFER_SIZE:
627 valid = check_size(sizeof(size_t), param_value_size, result);
628 if (valid && device_config->is_full_profile) {
629 valid = check_min_int(1024 * 1024, *(cl_uint*)param_value, result);
630 } else {
631 valid = check_min_int(1024, *(cl_uint*)param_value, result);
634 if (valid) {
635 print_u(*(size_t*)param_value);
637 break;
639 default:
640 printf(": WARN unchecked value");
641 piglit_merge_result(result, PIGLIT_WARN);
645 enum piglit_result
646 piglit_cl_test(const int argc,
647 const char** argv,
648 const struct piglit_cl_api_test_config* config,
649 const struct piglit_cl_api_test_env* env)
651 enum piglit_result result = PIGLIT_PASS;
653 struct device_config device_config = {0};
655 int i;
656 cl_int errNo;
658 size_t param_value_size;
659 void* param_value;
661 int num_device_infos = PIGLIT_CL_ENUM_NUM(cl_device_info, env->version);
662 const cl_device_info *device_infos_enum = PIGLIT_CL_ENUM_ARRAY(cl_device_info);
664 const cl_device_info *device_infos = device_infos_enum;
666 if (num_device_infos && env->version >= 12) {
667 // for some check we need some infos to be read before others
668 // piglit-util-cl-enum could be re ordered partially
669 // the first 10 elements are ok,
670 // after that we want to start with dependent stuff
671 int sorted_idx;
672 cl_device_info *sorted_infos = malloc(sizeof(cl_device_info) * num_device_infos);
673 memcpy(sorted_infos, device_infos_enum, sizeof(cl_device_info) * 10);
675 sorted_infos[10] = CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE;
676 sorted_idx = 11;
678 for(i = 10; i < num_device_infos; i++) {
679 if (device_infos_enum[i] == CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE) {
680 continue;
682 sorted_infos[sorted_idx] = device_infos_enum[i];
683 sorted_idx++;
685 device_infos = sorted_infos;
688 /*** Normal usage ***/
690 for(i = 0; i < num_device_infos; i++) {
691 printf("%s", piglit_cl_get_enum_name(device_infos[i]));
693 errNo = clGetDeviceInfo(env->device_id,
694 device_infos[i],
696 NULL,
697 &param_value_size);
698 if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
699 fprintf(stderr,
700 ": failed (error code: %s): Get size of %s.\n",
701 piglit_cl_get_error_name(errNo),
702 piglit_cl_get_enum_name(device_infos[i]));
703 piglit_merge_result(&result, PIGLIT_FAIL);
704 continue;
707 param_value = malloc(param_value_size);
708 errNo = clGetDeviceInfo(env->device_id,
709 device_infos[i],
710 param_value_size,
711 param_value,
712 NULL);
713 if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
714 fprintf(stderr,
715 ": failed (error code: %s): Get value of %s.\n",
716 piglit_cl_get_error_name(errNo),
717 piglit_cl_get_enum_name(device_infos[i]));
718 piglit_merge_result(&result, PIGLIT_FAIL);
721 check_info(env, &device_config,
722 device_infos[i], param_value, param_value_size, &result);
724 printf("\n");
725 free(param_value);
728 /*** Errors ***/
731 * CL_INVALID_VALUE if param_name is not one of the supported
732 * values or if size in bytes specified by param_value_size is
733 * less than size of return type and param_value is not a NULL
734 * value.
736 errNo = clGetDeviceInfo(env->device_id,
737 CL_DEVICE_VERSION,
739 param_value,
740 NULL);
741 if(!piglit_cl_check_error(errNo, CL_INVALID_VALUE)) {
742 fprintf(stderr,
743 "Failed (error code: %s): Trigger CL_INVALID_VALUE if param_name is not one of the supported values.\n",
744 piglit_cl_get_error_name(errNo));
745 piglit_merge_result(&result, PIGLIT_FAIL);
748 errNo = clGetDeviceInfo(env->device_id,
749 CL_PLATFORM_NAME,
751 NULL,
752 &param_value_size);
753 if(!piglit_cl_check_error(errNo, CL_INVALID_VALUE)) {
754 fprintf(stderr,
755 "Failed (error code: %s): Trigger CL_INVALID_VALUE if size in bytes specified by param_value is less than size of return type and param_value is not a NULL value.\n",
756 piglit_cl_get_error_name(errNo));
757 piglit_merge_result(&result, PIGLIT_FAIL);
761 * CL_INVALID_DEVICE if device is not a valid device.
763 errNo = clGetDeviceInfo(NULL,
764 CL_DEVICE_NAME,
766 NULL,
767 &param_value_size);
768 if(!piglit_cl_check_error(errNo, CL_INVALID_DEVICE)) {
769 fprintf(stderr,
770 "Failed (error code: %s): Trigger CL_INVALID_DEVICE if device is not a valid device.\n",
771 piglit_cl_get_error_name(errNo));
772 piglit_merge_result(&result, PIGLIT_FAIL);
775 if (num_device_infos && env->version >= 12) {
776 free((void*)device_infos);
779 return result;