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
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.
25 * @file get-kernel-work-group-info.c
29 * cl_int clGetKernelWorkGroupInfo (cl_kernel kernel,
30 * cl_device_id device,
31 * cl_kernel_work_group_info param_name,
32 * size_t param_value_size,
34 * size_t *param_value_size_ret)
37 #include "piglit-framework-cl-api.h"
40 PIGLIT_CL_API_TEST_CONFIG_BEGIN
42 config
.name
= "clGetKernelWorkGroupInfo";
43 config
.version_min
= 10;
45 config
.run_per_device
= true;
46 config
.create_context
= true;
48 config
.program_source
= "kernel __attribute__((reqd_work_group_size(1, 1, 1))) void dummy_kernel() {}\n";
50 PIGLIT_CL_API_TEST_CONFIG_END
53 check_size(size_t expected_size
, size_t actual_size
, enum piglit_result
*result
) {
54 if (expected_size
!= actual_size
) {
55 printf(": failed, expected and actual size differ. Expect %lu, got %lu",
56 expected_size
, actual_size
);
57 piglit_merge_result(result
, PIGLIT_FAIL
);
70 check_info(cl_bool is_custom_device
,
71 cl_kernel_work_group_info kind
,
72 void* param_value
, size_t param_value_size
,
73 enum piglit_result
*result
) {
76 case CL_KERNEL_WORK_GROUP_SIZE
:
77 if (check_size(sizeof(size_t), param_value_size
, result
)) {
78 print_u(*(size_t*)param_value
);
81 case CL_KERNEL_COMPILE_WORK_GROUP_SIZE
:
82 if (check_size(sizeof(size_t) * 3, param_value_size
, result
)) {
84 size_t* v
= (size_t*)param_value
;
85 if (v
[0] != 1 && v
[1] != 1 && v
[2] != 1) {
86 printf("failed, expected and actual value differ. Expect (1,1,1), got ");
87 piglit_merge_result(result
, PIGLIT_FAIL
);
89 printf("(%zu,%zu,%zu)", v
[0], v
[1], v
[2]);
92 case CL_KERNEL_LOCAL_MEM_SIZE
:
93 if (check_size(sizeof(cl_ulong
), param_value_size
, result
)) {
94 print_u(*(cl_ulong
*)param_value
);
97 case CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE
:
98 if (check_size(sizeof(size_t), param_value_size
, result
)) {
99 print_u(*(size_t*)param_value
);
102 case CL_KERNEL_PRIVATE_MEM_SIZE
:
103 if (check_size(sizeof(cl_ulong
), param_value_size
, result
)) {
104 print_u(*(cl_ulong
*)param_value
);
107 case CL_KERNEL_GLOBAL_WORK_SIZE
:
108 if (is_custom_device
&&
109 check_size(sizeof(size_t) * 3, param_value_size
, result
)) {
110 size_t* v
= (size_t*)param_value
;
111 printf(": (%zu,%zu,%zu)", v
[0], v
[1], v
[2]);
115 printf(": WARN unchecked value");
116 piglit_merge_result(result
, PIGLIT_WARN
);
121 piglit_cl_test(const int argc
,
123 const struct piglit_cl_api_test_config
* config
,
124 const struct piglit_cl_api_test_env
* env
)
126 enum piglit_result result
= PIGLIT_PASS
;
131 cl_uint
* dev_count_ptr
;
133 cl_bool is_custom_device
= false;
135 size_t param_value_size
;
138 int num_kernel_work_group_infos
=
139 PIGLIT_CL_ENUM_NUM(cl_kernel_work_group_info
, env
->version
);
140 const cl_kernel_work_group_info
* kernel_work_group_infos
=
141 PIGLIT_CL_ENUM_ARRAY(cl_kernel_work_group_info
);
143 kernel
= clCreateKernel(env
->program
,
146 if(!piglit_cl_check_error(errNo
, CL_SUCCESS
)) {
148 "Failed (error code: %s): Create kernel.\n",
149 piglit_cl_get_error_name(errNo
));
153 /*** Normal usage ***/
154 for(i
= 0; i
< num_kernel_work_group_infos
; i
++) {
155 cl_int success_code
= CL_SUCCESS
;
156 param_value_size
= 0;
158 #if defined(CL_VERSION_1_2)
159 /* CL_KERNEL_GLOBAL_WORK_SIZE query
160 * is valid for custom device or built-in kernel
162 if (kernel_work_group_infos
[i
] == CL_KERNEL_GLOBAL_WORK_SIZE
) {
163 cl_device_type
* dev_type_ptr
=
164 piglit_cl_get_device_info(env
->device_id
, CL_DEVICE_TYPE
);
165 is_custom_device
= *dev_type_ptr
== CL_DEVICE_TYPE_CUSTOM
;
166 if (!is_custom_device
)
167 success_code
= CL_INVALID_VALUE
;
172 printf("%s", piglit_cl_get_enum_name(kernel_work_group_infos
[i
]));
174 errNo
= clGetKernelWorkGroupInfo(kernel
,
176 kernel_work_group_infos
[i
],
180 if(!piglit_cl_check_error(errNo
, success_code
)) {
182 ": Failed (error code: %s): Get size of %s.\n",
183 piglit_cl_get_error_name(errNo
),
184 piglit_cl_get_enum_name(kernel_work_group_infos
[i
]));
185 piglit_merge_result(&result
, PIGLIT_FAIL
);
189 param_value
= malloc(param_value_size
);
190 errNo
= clGetKernelWorkGroupInfo(kernel
,
192 kernel_work_group_infos
[i
],
196 if(!piglit_cl_check_error(errNo
, success_code
)) {
198 ": Failed (error code: %s): Get value of %s.\n",
199 piglit_cl_get_error_name(errNo
),
200 piglit_cl_get_enum_name(kernel_work_group_infos
[i
]));
201 piglit_merge_result(&result
, PIGLIT_FAIL
);
204 check_info(is_custom_device
, kernel_work_group_infos
[i
], param_value
, param_value_size
, &result
);
213 * CL_INVALID_VALUE if param_name is not one of the supported
214 * values or if size in bytes specified by param_value_size is
215 * less than size of return type and param_value is not a NULL
218 errNo
= clGetKernelWorkGroupInfo(kernel
,
224 if(!piglit_cl_check_error(errNo
, CL_INVALID_VALUE
)) {
226 "Failed (error code: %s): Trigger CL_INVALID_VALUE if param_name is not one of the supported values.\n",
227 piglit_cl_get_error_name(errNo
));
228 piglit_merge_result(&result
, PIGLIT_FAIL
);
231 errNo
= clGetKernelWorkGroupInfo(kernel
,
233 CL_KERNEL_WORK_GROUP_SIZE
,
237 if(!piglit_cl_check_error(errNo
, CL_INVALID_VALUE
)) {
239 "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",
240 piglit_cl_get_error_name(errNo
));
241 piglit_merge_result(&result
, PIGLIT_FAIL
);
245 * CL_INVALID_KERNEL if kernel is a not a valid kernel object.
247 errNo
= clGetKernelWorkGroupInfo(NULL
,
249 CL_KERNEL_WORK_GROUP_SIZE
,
253 if(!piglit_cl_check_error(errNo
, CL_INVALID_KERNEL
)) {
255 "Failed (error code: %s): Trigger CL_INVALID_KERNEL if kernel is not a valid kernel object.\n",
256 piglit_cl_get_error_name(errNo
));
257 piglit_merge_result(&result
, PIGLIT_FAIL
);
261 * CL_INVALID_DEVICE if device is not in the list of devices associated with
262 * kernel or if device is NULL but there is more than one device associated
265 * CL_SUCCESS if device is NULL but there is only one device associated with kernel.
267 dev_count_ptr
= piglit_cl_get_program_info(env
->program
, CL_PROGRAM_NUM_DEVICES
);
268 errNo
= clGetKernelWorkGroupInfo(kernel
,
270 CL_KERNEL_WORK_GROUP_SIZE
,
274 if (*dev_count_ptr
== 1) {
275 if(!piglit_cl_check_error(errNo
, CL_SUCCESS
)) {
277 "Failed (error code: %s): Trigger CL_SUCCESS if device is NULL but there is only one device associated with kernel.\n",
278 piglit_cl_get_error_name(errNo
));
279 piglit_merge_result(&result
, PIGLIT_FAIL
);
282 if(!piglit_cl_check_error(errNo
, CL_INVALID_DEVICE
)) {
284 "Failed (error code: %s): Trigger CL_INVALID_DEVICE if device is NULL but there is more than one device associated with kernel.\n",
285 piglit_cl_get_error_name(errNo
));
286 piglit_merge_result(&result
, PIGLIT_FAIL
);
291 clReleaseKernel(kernel
);