[Beignet] [PATCH] utests: Add a test case for built-in functions get_num_groups.
Zhigang Gong
zhigang.gong at linux.intel.com
Mon Jul 29 23:23:45 PDT 2013
LGTM, pushed, thanks.
On Tue, Jul 30, 2013 at 01:11:04PM +0800, Yi Sun wrote:
> Signed-off-by: Yi Sun <yi.sun at intel.com>
>
> diff --git a/kernels/builtin_num_groups.cl b/kernels/builtin_num_groups.cl
> new file mode 100644
> index 0000000..719d25d
> --- /dev/null
> +++ b/kernels/builtin_num_groups.cl
> @@ -0,0 +1,3 @@
> +kernel void builtin_num_groups( __global int *ret, __global int *i_dim ) {
> + *ret = get_num_groups( *i_dim);
> +}
> diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
> index e4c5a3c..182fcaf 100644
> --- a/utests/CMakeLists.txt
> +++ b/utests/CMakeLists.txt
> @@ -111,6 +111,7 @@ set (utests_sources
> buildin_work_dim.cpp
> builtin_global_size.cpp
> builtin_global_id.cpp
> + builtin_num_groups.cpp
> runtime_createcontext.cpp
> runtime_null_kernel_arg.cpp
> compiler_double.cpp
> diff --git a/utests/builtin_num_groups.cpp b/utests/builtin_num_groups.cpp
> new file mode 100644
> index 0000000..bbff435
> --- /dev/null
> +++ b/utests/builtin_num_groups.cpp
> @@ -0,0 +1,85 @@
> +/*
> +According to the OpenCL v1.1 & v1.2 chapter 6.11, the behavior of function get_num_groups should be as following:
> +
> + globals[0] = 1;
> + globals[1] = 4;
> + globals[2] = 9;
> + locals[0] = 1;
> + locals[1] = 2;
> + locals[2] = 3;
> +
> +#ifdef CL_VERSION_1_2 | CL_VERSION_1_1:
> +get_num_groups(-1) = 1 (dimension:1)
> +get_num_groups(0) = 1 (dimension:1)
> +get_num_groups(1) = 1 (dimension:1)
> +
> +get_num_groups(-1) = 1 (dimension:2)
> +get_num_groups(0) = 1 (dimension:2)
> +get_num_groups(1) = 2 (dimension:2)
> +get_num_groups(2) = 1 (dimension:2)
> +
> +get_num_groups(-1) = 1 (dimension:3)
> +get_num_groups(0) = 1 (dimension:3)
> +get_num_groups(1) = 2 (dimension:3)
> +get_num_groups(2) = 3 (dimension:3)
> +get_num_groups(3) = 1 (dimension:3)
> +*/
> +
> +#define udebug 0
> +#include "utest_helper.hpp"
> +static void builtin_num_groups(void)
> +{
> +
> + // Setup kernel and buffers
> + int dim, dim_arg_global, num_groups, err;
> + OCL_CREATE_KERNEL("builtin_num_groups");
> +
> + OCL_CREATE_BUFFER(buf[0], CL_MEM_READ_WRITE, sizeof(int), NULL);
> + OCL_CREATE_BUFFER(buf[1], CL_MEM_READ_WRITE, sizeof(int), NULL);
> + OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
> + OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);
> +
> + globals[0] = 1;
> + globals[1] = 4;
> + globals[2] = 9;
> + locals[0] = 1;
> + locals[1] = 2;
> + locals[2] = 3;
> +
> + for( dim=1; dim <= 3; dim++ )
> + {
> +
> + for( dim_arg_global = -1; dim_arg_global <= dim + 1; dim_arg_global++ )
> + {
> +
> + err = clEnqueueWriteBuffer( queue, buf[1], CL_TRUE, 0, sizeof(int), &dim_arg_global, 0, NULL, NULL);
> + if (err != CL_SUCCESS)
> + {
> + printf("Error: Failed to write to source array!\n");
> + exit(1);
> + }
> +
> + // Run the kernel
> + OCL_NDRANGE( dim );
> +
> + err = clEnqueueReadBuffer( queue, buf[0], CL_TRUE, 0, sizeof(int), &num_groups, 0, NULL, NULL);
> + if (err != CL_SUCCESS)
> + {
> + printf("Error: Failed to read output array! %d\n", err);
> + exit(1);
> + }
> +
> +#if udebug
> + printf("get_num_groups(%d) = %d (dimension:%d)\n", dim_arg_global, num_groups, dim);
> +#endif
> + if ( dim_arg_global >= 0 && dim_arg_global < dim)
> + OCL_ASSERT( num_groups == dim_arg_global + 1 );
> + else
> + {
> + OCL_ASSERT( num_groups == 1);
> + }
> + }
> + }
> +}
> +
> +MAKE_UTEST_FROM_FUNCTION(builtin_num_groups);
> --
> 1.7.6.4
>
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list