[2/2] cl: Add test for reqd_group_work_size attribute

Submitted by Tom Stellard on March 24, 2015, 3:25 p.m.

Details

Message ID 1427210748-26907-3-git-send-email-thomas.stellard@amd.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Tom Stellard March 24, 2015, 3:25 p.m.
---
 tests/cl.py                            |   1 +
 tests/cl/api/CMakeLists.cl.txt         |   1 +
 tests/cl/api/enqueue-nd-range-kernel.c | 121 +++++++++++++++++++++++++++++++++
 3 files changed, 123 insertions(+)
 create mode 100644 tests/cl/api/enqueue-nd-range-kernel.c

Patch hide | download patch | download mbox

diff --git a/tests/cl.py b/tests/cl.py
index 1578297..ea9179a 100644
--- a/tests/cl.py
+++ b/tests/cl.py
@@ -95,6 +95,7 @@  add_plain_test(api, 'clCreateKernelsInProgram',
                ['cl-api-create-kernels-in-program'])
 add_plain_test(api, 'clGetProgramInfo', ['cl-api-get-program-info'])
 add_plain_test(api, 'clGetProgramBuildInfo', ['cl-api-get-program-build-info'])
+add_plain_test(api, 'clEnqueueNDRangeKernel', ['cl-api-enqueue-nd-range-kernel'])
 add_plain_test(api, 'clRetainProgram and clReleaseProgram',
                ['cl-api-retain_release-program'])
 add_plain_test(api, 'clUnloadCompiler', ['cl-api-unload-compiler'])
diff --git a/tests/cl/api/CMakeLists.cl.txt b/tests/cl/api/CMakeLists.cl.txt
index 7e78491..377992d 100644
--- a/tests/cl/api/CMakeLists.cl.txt
+++ b/tests/cl/api/CMakeLists.cl.txt
@@ -34,6 +34,7 @@  piglit_cl_add_api_test (compile-program compile-program.c)
 piglit_cl_add_api_test (unload-compiler unload-compiler.c)
 piglit_cl_add_api_test (get-program-info get-program-info.c)
 piglit_cl_add_api_test (get-program-build-info get-program-build-info.c)
+piglit_cl_add_api_test (enqueue-nd-range-kernel enqueue-nd-range-kernel.c)
 
 # Kernels
 piglit_cl_add_api_test (create-kernel create-kernel.c)
diff --git a/tests/cl/api/enqueue-nd-range-kernel.c b/tests/cl/api/enqueue-nd-range-kernel.c
new file mode 100644
index 0000000..766d393
--- /dev/null
+++ b/tests/cl/api/enqueue-nd-range-kernel.c
@@ -0,0 +1,121 @@ 
+/*
+ * Copyright © 2012 Blaž Tomažič <blaz.tomazic@gmail.com>
+ * Copyright © 2015 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * @file enqueue-nd-range-kernel.c
+ *
+ * Test API function:
+ *
+ *
+ * cl_int clEnqueueNDRangeKernel(cl_command_queue command_queue,
+ *                               cl_kernel kernel,
+ *                               cl_uint work_dim,
+ *                               const size_t *global_work_offset,
+ *                               const size_t *global_work_size,
+ *                               const size_t *local_work_size,
+ *                               cl_uint num_events_in_wait_list,
+ *                               const cl_event *event_wait_list,
+ *                               cl_event *event) 
+ */
+
+#include "piglit-framework-cl-api.h"
+
+
+PIGLIT_CL_API_TEST_CONFIG_BEGIN
+
+	config.name = "clCreateProgramWithSource";
+	config.version_min = 10;
+
+	config.run_per_device = true;
+	config.create_context = true;
+
+PIGLIT_CL_API_TEST_CONFIG_END
+
+
+char* reqd_wgs_kernel =
+	"__attribute__((reqd_work_group_size(2, 2, 2)))  kernel void read_wqs() { }";
+
+
+enum piglit_result
+piglit_cl_test(const int argc,
+               const char** argv,
+               const struct piglit_cl_api_test_config* config,
+               const struct piglit_cl_api_test_env* env)
+{
+	enum piglit_result result = PIGLIT_PASS;
+	size_t work_size_4_4_4[3] = {4, 4, 4};
+	size_t work_size_2_2_2[3] = {2, 2, 2};
+	cl_int err;
+	size_t *reqd_wgs;
+
+	cl_command_queue queue = env->context->command_queues[0];
+	cl_program program =
+		piglit_cl_build_program_with_source(
+			env->context, 1, &reqd_wgs_kernel, "");
+
+	if (!program) {
+		fprintf(stderr, "Failed to create program");
+		return PIGLIT_FAIL;
+	}
+
+	cl_kernel kernel =
+		piglit_cl_create_kernel(program, "read_wqs");
+
+	if (!kernel) {
+		fprintf(stderr, "Failed to create kernel.");
+		return PIGLIT_FAIL;
+	}
+
+	reqd_wgs = piglit_cl_get_kernel_work_group_info(kernel, env->device_id,
+			CL_KERNEL_COMPILE_WORK_GROUP_SIZE);
+
+	if (memcmp(reqd_wgs, work_size_2_2_2, sizeof(work_size_2_2_2))) {
+		fprintf(stderr, "Invalid value for "
+				"CL_KERNEL_COMPILE_WORK_GROUP_SIZE. Expected: "
+				"{2, 2, 2}, but got: {%d, %d, %d}",
+				reqd_wgs[0], reqd_wgs[1], reqd_wgs[2]);
+	}
+
+	/* Enqueue kernel with the correct local_work_size */
+	err = clEnqueueNDRangeKernel(queue, kernel, 3, NULL, work_size_4_4_4,
+					work_size_2_2_2, 0, NULL, NULL);
+
+	if (!piglit_cl_check_error(err, CL_SUCCESS)) {
+		fprintf(stderr, "Failed to enqueue kernel.\n");
+		piglit_merge_result(&result, PIGLIT_FAIL);
+	}
+
+	/* Enqueue kernel with the incorrect local_work_size */
+	err = clEnqueueNDRangeKernel(queue, kernel, 3, NULL, work_size_4_4_4,
+					work_size_4_4_4, 0, NULL, NULL);
+
+	if (!piglit_cl_check_error(err, CL_INVALID_WORK_GROUP_SIZE)) {
+		fprintf(stderr, "Expected CL_INVALID_WORK_GROUP_SIZE when "
+				"local_work_size does not match "
+				"reqd_work_group_size attribute.");
+		piglit_merge_result(&result, PIGLIT_FAIL);
+	}
+
+	return result;
+}

Comments

On Tue, 2015-03-24 at 15:25 +0000, Tom Stellard wrote:
> ---
>  tests/cl.py                            |   1 +
>  tests/cl/api/CMakeLists.cl.txt         |   1 +
>  tests/cl/api/enqueue-nd-range-kernel.c | 121 +++++++++++++++++++++++++++++++++
>  3 files changed, 123 insertions(+)
>  create mode 100644 tests/cl/api/enqueue-nd-range-kernel.c
> 
> diff --git a/tests/cl.py b/tests/cl.py
> index 1578297..ea9179a 100644
> --- a/tests/cl.py
> +++ b/tests/cl.py
> @@ -95,6 +95,7 @@ add_plain_test(api, 'clCreateKernelsInProgram',
>                 ['cl-api-create-kernels-in-program'])
>  add_plain_test(api, 'clGetProgramInfo', ['cl-api-get-program-info'])
>  add_plain_test(api, 'clGetProgramBuildInfo', ['cl-api-get-program-build-info'])
> +add_plain_test(api, 'clEnqueueNDRangeKernel', ['cl-api-enqueue-nd-range-kernel'])
>  add_plain_test(api, 'clRetainProgram and clReleaseProgram',
>                 ['cl-api-retain_release-program'])
>  add_plain_test(api, 'clUnloadCompiler', ['cl-api-unload-compiler'])
> diff --git a/tests/cl/api/CMakeLists.cl.txt b/tests/cl/api/CMakeLists.cl.txt
> index 7e78491..377992d 100644
> --- a/tests/cl/api/CMakeLists.cl.txt
> +++ b/tests/cl/api/CMakeLists.cl.txt
> @@ -34,6 +34,7 @@ piglit_cl_add_api_test (compile-program compile-program.c)
>  piglit_cl_add_api_test (unload-compiler unload-compiler.c)
>  piglit_cl_add_api_test (get-program-info get-program-info.c)
>  piglit_cl_add_api_test (get-program-build-info get-program-build-info.c)
> +piglit_cl_add_api_test (enqueue-nd-range-kernel enqueue-nd-range-kernel.c)
>  
>  # Kernels
>  piglit_cl_add_api_test (create-kernel create-kernel.c)
> diff --git a/tests/cl/api/enqueue-nd-range-kernel.c b/tests/cl/api/enqueue-nd-range-kernel.c
> new file mode 100644
> index 0000000..766d393
> --- /dev/null
> +++ b/tests/cl/api/enqueue-nd-range-kernel.c
> @@ -0,0 +1,121 @@
> +/*
> + * Copyright © 2012 Blaž Tomažič <blaz.tomazic@gmail.com>
> + * Copyright © 2015 Advanced Micro Devices, Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> + * DEALINGS IN THE SOFTWARE.
> + */
> +
> +/**
> + * @file enqueue-nd-range-kernel.c
> + *
> + * Test API function:
> + *
> + *
> + * cl_int clEnqueueNDRangeKernel(cl_command_queue command_queue,
> + *                               cl_kernel kernel,
> + *                               cl_uint work_dim,
> + *                               const size_t *global_work_offset,
> + *                               const size_t *global_work_size,
> + *                               const size_t *local_work_size,
> + *                               cl_uint num_events_in_wait_list,
> + *                               const cl_event *event_wait_list,
> + *                               cl_event *event) 
> + */
> +
> +#include "piglit-framework-cl-api.h"
> +
> +
> +PIGLIT_CL_API_TEST_CONFIG_BEGIN
> +
> +	config.name = "clCreateProgramWithSource";
> +	config.version_min = 10;
> +
> +	config.run_per_device = true;
> +	config.create_context = true;
> +
> +PIGLIT_CL_API_TEST_CONFIG_END
> +
> +
> +char* reqd_wgs_kernel =
> +	"__attribute__((reqd_work_group_size(2, 2, 2)))  kernel void read_wqs() { }";
> +
> +
> +enum piglit_result
> +piglit_cl_test(const int argc,
> +               const char** argv,
> +               const struct piglit_cl_api_test_config* config,
> +               const struct piglit_cl_api_test_env* env)
> +{
> +	enum piglit_result result = PIGLIT_PASS;
> +	size_t work_size_4_4_4[3] = {4, 4, 4};
> +	size_t work_size_2_2_2[3] = {2, 2, 2};
> +	cl_int err;
> +	size_t *reqd_wgs;
> +
> +	cl_command_queue queue = env->context->command_queues[0];
> +	cl_program program =
> +		piglit_cl_build_program_with_source(
> +			env->context, 1, &reqd_wgs_kernel, "");
> +
> +	if (!program) {
> +		fprintf(stderr, "Failed to create program");
> +		return PIGLIT_FAIL;
> +	}
> +
> +	cl_kernel kernel =
> +		piglit_cl_create_kernel(program, "read_wqs");
> +
> +	if (!kernel) {
> +		fprintf(stderr, "Failed to create kernel.");
> +		return PIGLIT_FAIL;
> +	}
> +
> +	reqd_wgs = piglit_cl_get_kernel_work_group_info(kernel, env->device_id,
> +			CL_KERNEL_COMPILE_WORK_GROUP_SIZE);
> +
> +	if (memcmp(reqd_wgs, work_size_2_2_2, sizeof(work_size_2_2_2))) {
> +		fprintf(stderr, "Invalid value for "
> +				"CL_KERNEL_COMPILE_WORK_GROUP_SIZE. Expected: "
> +				"{2, 2, 2}, but got: {%d, %d, %d}",
> +				reqd_wgs[0], reqd_wgs[1], reqd_wgs[2]);
> +	}
> +
> +	/* Enqueue kernel with the correct local_work_size */
> +	err = clEnqueueNDRangeKernel(queue, kernel, 3, NULL, work_size_4_4_4,
> +					work_size_2_2_2, 0, NULL, NULL);
> +
> +	if (!piglit_cl_check_error(err, CL_SUCCESS)) {
> +		fprintf(stderr, "Failed to enqueue kernel.\n");
> +		piglit_merge_result(&result, PIGLIT_FAIL);
> +	}
> +
> +	/* Enqueue kernel with the incorrect local_work_size */
> +	err = clEnqueueNDRangeKernel(queue, kernel, 3, NULL, work_size_4_4_4,
> +					work_size_4_4_4, 0, NULL, NULL);
> +
> +	if (!piglit_cl_check_error(err, CL_INVALID_WORK_GROUP_SIZE)) {
> +		fprintf(stderr, "Expected CL_INVALID_WORK_GROUP_SIZE when "
> +				"local_work_size does not match "
> +				"reqd_work_group_size attribute.");
> +		piglit_merge_result(&result, PIGLIT_FAIL);
> +	}
> +
> +	return result;
> +}

I think the test should also include passing NULL as local_work_size,
but that can be added later.

Reviewed-by: Jan Vesely <jan.vesely@rutgers.edu>