fix CL_KERNEL_GLOBAL_WORK_SIZE bug.

Submitted by Luo, Xionghu on Sept. 27, 2014, 10:26 p.m.

Details

Message ID 1411856768-15904-1-git-send-email-xionghu.luo@intel.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Luo, Xionghu Sept. 27, 2014, 10:26 p.m.
From: Luo <xionghu.luo@intel.com>

the option  CL_KERNEL_GLOBAL_WORK_SIZE for clGetKernelWorkGroupInfo
should call built in kernel or custom device according to the spec,
this patch calls the built in kernel to query the GLOBAL_WORK_SIZE.

v2: use built in kernel to qury the GLOBAL_WORK_SIZE if exist, dummy
kernel for other options, handle the case when no built in kernel is
provided.

v3: fix indent issue; loop CL_KERNEL_GLOBAL_WORK_SIZE out, test it with the platform supports opencl-1.2.

Signed-off-by: Luo <xionghu.luo@intel.com>
---
 tests/cl/api/get-kernel-work-group-info.c |  127 +++++++++++++++++++++++++++++
 1 file changed, 127 insertions(+)

Patch hide | download patch | download mbox

diff --git a/tests/cl/api/get-kernel-work-group-info.c b/tests/cl/api/get-kernel-work-group-info.c
index 47d09da..f3fd6e5 100644
--- a/tests/cl/api/get-kernel-work-group-info.c
+++ b/tests/cl/api/get-kernel-work-group-info.c
@@ -61,6 +61,11 @@  piglit_cl_test(const int argc,
 	int i;
 	cl_int errNo;
 	cl_kernel kernel;
+#ifdef CL_VERSION_1_2
+	cl_program built_in_prog = NULL;
+	cl_kernel built_in_kernel = NULL;
+	size_t built_in_kernels_size;
+#endif
 
 	size_t param_value_size;
 	void* param_value;
@@ -84,6 +89,17 @@  piglit_cl_test(const int argc,
 	for(i = 0; i < num_kernel_work_group_infos; i++) {
 		printf("%s ", piglit_cl_get_enum_name(kernel_work_group_infos[i]));
 
+#ifdef CL_VERSION_1_2
+		if(kernel_work_group_infos[i] == CL_KERNEL_GLOBAL_WORK_SIZE){
+			if(env->version >= 12) {
+				continue;
+			}else{
+				fprintf(stderr, "Could not query CL_KERNEL_GLOBAL_WORK_SIZE. Piglit was compiled against OpenCL version >= 1.2 and cannot run this test for versions < 1.2 because CL_KERNEL_GLOBAL_WORK_SIZE option is not present.\n");
+				piglit_merge_result(&result, PIGLIT_FAIL);
+			}
+		}
+#endif
+
 		errNo = clGetKernelWorkGroupInfo(kernel,
 		                                 env->device_id,
 		                                 kernel_work_group_infos[i],
@@ -187,6 +203,117 @@  piglit_cl_test(const int argc,
 		piglit_merge_result(&result, PIGLIT_FAIL);
 	}
 
+#ifdef CL_VERSION_1_2
+	if(env->version < 12){
+		    fprintf(stderr, "Could not query CL_KERNEL_GLOBAL_WORK_SIZE. Piglit was compiled against OpenCL version >= 1.2 and cannot run this test for versions < 1.2 because CL_KERNEL_GLOBAL_WORK_SIZE option is not present.\n");
+		    piglit_merge_result(&result, PIGLIT_FAIL);
+	}
+
+	//use builtin kernel to test CL_KERNEL_GLOBAL_WORK_SIZE.
+	errNo = clGetDeviceInfo(env->device_id, CL_DEVICE_BUILT_IN_KERNELS, 0, 0, &built_in_kernels_size);
+	if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
+		fprintf(stderr,
+		        "Failed (error code: %s): Get Device Info.\n",
+		        piglit_cl_get_error_name(errNo));
+		piglit_merge_result(&result, PIGLIT_FAIL);
+	}
+
+	if(built_in_kernels_size != 0)
+	{
+		char* built_in_kernel_names;
+		char* kernel_name;
+		size_t ret_sz;
+		built_in_kernel_names = (char* )malloc(built_in_kernels_size * sizeof(char) );
+
+		errNo = clGetDeviceInfo(env->device_id, CL_DEVICE_BUILT_IN_KERNELS, built_in_kernels_size, (void*)built_in_kernel_names, &ret_sz);
+		if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
+			fprintf(stderr,
+		        "Failed (error code: %s): Get Device Info.\n",
+		        piglit_cl_get_error_name(errNo));
+			piglit_merge_result(&result, PIGLIT_FAIL);
+		}
+
+		built_in_prog = clCreateProgramWithBuiltInKernels(env->context->cl_ctx, 1, &env->device_id, built_in_kernel_names, &errNo);
+		if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
+			fprintf(stderr,
+		        "Failed (error code: %s): Create BuiltIn Program.\n",
+		        piglit_cl_get_error_name(errNo));
+			piglit_merge_result(&result, PIGLIT_FAIL);
+		}
+
+		kernel_name = strtok(built_in_kernel_names, ";");
+
+		built_in_kernel = clCreateKernel(built_in_prog, kernel_name,  &errNo);
+		if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
+			fprintf(stderr,
+		        "Failed (error code: %s): Create kernel.\n",
+		        piglit_cl_get_error_name(errNo));
+			piglit_merge_result(&result, PIGLIT_FAIL);
+		}
+		free(built_in_kernel_names);
+	/*
+	 * CL_INVALID_VALUE if kernel is not a built in kernel.
+	 */
+		errNo = clGetKernelWorkGroupInfo(kernel,
+		                                 env->device_id,
+		                                 CL_KERNEL_GLOBAL_WORK_SIZE,
+		                                 0,
+		                                 NULL,
+		                                 &param_value_size);
+		if(!piglit_cl_check_error(errNo, CL_INVALID_VALUE)) {
+			fprintf(stderr,
+			        "Failed (error code: %s): Trigger CL_INVALID_VALUE if kernel is not a builtin kernel for CL_KERNEL_GLOBAL_WORK_SIZE.\n",
+			        piglit_cl_get_error_name(errNo));
+			piglit_merge_result(&result, PIGLIT_FAIL);
+		}
+
+		if(built_in_kernel != NULL) {
+			errNo = clGetKernelWorkGroupInfo(built_in_kernel,
+			                                 env->device_id,
+			                                 CL_KERNEL_GLOBAL_WORK_SIZE,
+			                                 0,
+			                                 NULL,
+			                                 &param_value_size);
+			if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
+				fprintf(stderr,
+				        "Failed (error code: %s): Get size of %s.\n",
+				        piglit_cl_get_error_name(errNo),
+				        piglit_cl_get_enum_name(kernel_work_group_infos[i]));
+				piglit_merge_result(&result, PIGLIT_FAIL);
+			}
+
+			param_value = malloc(param_value_size);
+			errNo = clGetKernelWorkGroupInfo(built_in_kernel,
+			                                 env->device_id,
+			                                 CL_KERNEL_GLOBAL_WORK_SIZE,
+			                                 param_value_size,
+			                                 param_value,
+			                                 NULL);
+			if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
+				fprintf(stderr,
+				        "Failed (error code: %s): Get value of %s.\n",
+				        piglit_cl_get_error_name(errNo),
+				        piglit_cl_get_enum_name(kernel_work_group_infos[i]));
+				piglit_merge_result(&result, PIGLIT_FAIL);
+			}
+
+			//TODO: output returned values
+			printf("\n");
+			free(param_value);
+		}else{
+			fprintf(stderr,
+			        "built in kernel create failed.\n");
+			piglit_merge_result(&result, PIGLIT_FAIL);
+		}
+		clReleaseKernel(built_in_kernel);
+		clReleaseProgram(built_in_prog);
+	}else{
+		fprintf(stderr,
+		        "no built in kernel provided.\n");
+		piglit_merge_result(&result, PIGLIT_WARN);
+	}
+#endif
+
 	clReleaseKernel(kernel);
 
 	return result;