fix the spelling in whole piglit
[piglit.git] / tests / cl / api / get-kernel-work-group-info.c
blobefcc20351eab04abac2bd169f29316114f16f02d
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-kernel-work-group-info.c
27 * Test API function:
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,
33 * void *param_value,
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
52 static bool
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);
58 return false;
61 return true;
64 static void
65 print_u(size_t i) {
66 printf(": %zu", i);
69 static void
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) {
75 switch (kind) {
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);
80 break;
81 case CL_KERNEL_COMPILE_WORK_GROUP_SIZE:
82 if (check_size(sizeof(size_t) * 3, param_value_size, result)) {
83 printf(": ");
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]);
91 break;
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);
96 break;
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);
101 break;
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);
106 break;
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]);
113 break;
114 default:
115 printf(": WARN unchecked value");
116 piglit_merge_result(result, PIGLIT_WARN);
120 enum piglit_result
121 piglit_cl_test(const int argc,
122 const char** argv,
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;
128 int i;
129 cl_int errNo;
130 cl_kernel kernel;
131 cl_uint* dev_count_ptr;
133 cl_bool is_custom_device = false;
135 size_t param_value_size;
136 void* param_value;
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,
144 "dummy_kernel",
145 &errNo);
146 if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
147 fprintf(stderr,
148 "Failed (error code: %s): Create kernel.\n",
149 piglit_cl_get_error_name(errNo));
150 return PIGLIT_FAIL;
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;
168 free(dev_type_ptr);
170 #endif
172 printf("%s", piglit_cl_get_enum_name(kernel_work_group_infos[i]));
174 errNo = clGetKernelWorkGroupInfo(kernel,
175 env->device_id,
176 kernel_work_group_infos[i],
178 NULL,
179 &param_value_size);
180 if(!piglit_cl_check_error(errNo, success_code)) {
181 fprintf(stderr,
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);
186 continue;
189 param_value = malloc(param_value_size);
190 errNo = clGetKernelWorkGroupInfo(kernel,
191 env->device_id,
192 kernel_work_group_infos[i],
193 param_value_size,
194 param_value,
195 NULL);
196 if(!piglit_cl_check_error(errNo, success_code)) {
197 fprintf(stderr,
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);
206 printf("\n");
207 free(param_value);
210 /*** Errors ***/
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
216 * value.
218 errNo = clGetKernelWorkGroupInfo(kernel,
219 env->device_id,
220 CL_DEVICE_NAME,
222 NULL,
223 &param_value_size);
224 if(!piglit_cl_check_error(errNo, CL_INVALID_VALUE)) {
225 fprintf(stderr,
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,
232 env->device_id,
233 CL_KERNEL_WORK_GROUP_SIZE,
235 param_value,
236 NULL);
237 if(!piglit_cl_check_error(errNo, CL_INVALID_VALUE)) {
238 fprintf(stderr,
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,
248 env->device_id,
249 CL_KERNEL_WORK_GROUP_SIZE,
251 NULL,
252 &param_value_size);
253 if(!piglit_cl_check_error(errNo, CL_INVALID_KERNEL)) {
254 fprintf(stderr,
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
263 * with kernel
264 * or
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,
269 NULL,
270 CL_KERNEL_WORK_GROUP_SIZE,
272 NULL,
273 &param_value_size);
274 if (*dev_count_ptr == 1) {
275 if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
276 fprintf(stderr,
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);
281 } else {
282 if(!piglit_cl_check_error(errNo, CL_INVALID_DEVICE)) {
283 fprintf(stderr,
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);
289 free(dev_count_ptr);
291 clReleaseKernel(kernel);
293 return result;