[Beignet] [PATCH 2/2] Add test case for group size

Zhigang Gong zhigang.gong at linux.intel.com
Fri May 31 01:57:56 PDT 2013


Pushed, Thanks.
On Fri, May 31, 2013 at 03:58:31PM +0800, Ruiling Song wrote:
> Signed-off-by: Ruiling Song <ruiling.song at intel.com>
> ---
>  kernels/compiler_group_size.cl |   12 ++++++
>  utests/CMakeLists.txt          |    1 +
>  utests/compiler_group_size.cpp |   86 ++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 99 insertions(+)
>  create mode 100644 kernels/compiler_group_size.cl
>  create mode 100644 utests/compiler_group_size.cpp
> 
> diff --git a/kernels/compiler_group_size.cl b/kernels/compiler_group_size.cl
> new file mode 100644
> index 0000000..9dba236
> --- /dev/null
> +++ b/kernels/compiler_group_size.cl
> @@ -0,0 +1,12 @@
> +__kernel void
> +compiler_group_size(__global unsigned int *dst)
> +{
> +  uint idx = (uint)get_global_id(0);
> +  uint idy = (uint)get_global_id(1);
> +  uint idz = (uint)get_global_id(2);
> +  uint size_x = (uint)get_global_size(0);
> +  uint size_y = (uint)get_global_size(1);
> +
> +  dst[idz*size_x*size_y + idy*size_x + idx] = idz*size_x*size_y + idy*size_x +idx;
> +}
> +
> diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
> index cde8612..322b727 100644
> --- a/utests/CMakeLists.txt
> +++ b/utests/CMakeLists.txt
> @@ -39,6 +39,7 @@ set (utests_sources
>    compiler_function_constant.cpp
>    compiler_global_constant.cpp
>    compiler_global_constant_2.cpp
> +  compiler_group_size.cpp
>    compiler_if_else.cpp
>    compiler_integer_division.cpp
>    compiler_integer_remainder.cpp
> diff --git a/utests/compiler_group_size.cpp b/utests/compiler_group_size.cpp
> new file mode 100644
> index 0000000..6d59aed
> --- /dev/null
> +++ b/utests/compiler_group_size.cpp
> @@ -0,0 +1,86 @@
> +#include "utest_helper.hpp"
> +
> +void compiler_group_size1(void)
> +{
> +  const size_t n = 7*32*17;
> +
> +  int group_size[] = {7, 17, 32};
> +  // Setup kernel and buffers
> +  OCL_CREATE_KERNEL("compiler_group_size");
> +  OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(uint32_t), NULL);
> +  OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
> +
> +  for(int i = 0; i < 3; i++) {
> +    // Run the kernel
> +    globals[0] = n;
> +    locals[0] = group_size[i];
> +    OCL_NDRANGE(1);
> +    OCL_MAP_BUFFER(0);
> +
> +    // Check results
> +    for (uint32_t i = 0; i < n; ++i)
> +      OCL_ASSERT(((uint32_t*)buf_data[0])[i] == i);
> +    OCL_UNMAP_BUFFER(0);
> +  }
> +}
> +
> +void compiler_group_size2(void)
> +{
> +  const uint32_t n = 4*17*8;
> +  int size_x[] = {2, 4, 17};
> +  int size_y[] = {2, 4, 4};
> +
> +  // Setup kernel and buffers
> +  OCL_CREATE_KERNEL("compiler_group_size");
> +  OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(uint32_t), NULL);
> +  OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
> +
> +  for(int i = 0; i < 3; i++) {
> +    // Run the kernel
> +    globals[0] = 4*17;
> +    globals[1] = 8;
> +    locals[0] = size_x[i];
> +    locals[1] = size_y[i];
> +    OCL_NDRANGE(2);
> +    OCL_MAP_BUFFER(0);
> +
> +    // Check results
> +    for (uint32_t i = 0; i < n; ++i)
> +      OCL_ASSERT(((uint32_t*)buf_data[0])[i] == i);
> +    OCL_UNMAP_BUFFER(0);
> +  }
> +}
> +
> +void compiler_group_size3(void)
> +{
> +  const uint32_t n = 4*17*8*4;
> +  int size_x[] = {2, 4, 17};
> +  int size_y[] = {2, 4, 4};
> +  int size_z[] = {2, 1, 2};
> +
> +  // Setup kernel and buffers
> +  OCL_CREATE_KERNEL("compiler_group_size");
> +  OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(uint32_t), NULL);
> +  OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
> +
> +  for(int i = 0; i < 3; i++) {
> +    // Run the kernel
> +    globals[0] = 4*17;
> +    globals[1] = 8;
> +    globals[2] = 4;
> +    locals[0] = size_x[i];
> +    locals[1] = size_y[i];
> +    locals[2] = size_z[i];
> +    OCL_NDRANGE(3);
> +    OCL_MAP_BUFFER(0);
> +
> +    // Check results
> +    for (uint32_t i = 0; i < n; ++i)
> +      OCL_ASSERT(((uint32_t*)buf_data[0])[i] == i);
> +    OCL_UNMAP_BUFFER(0);
> +  }
> +}
> +MAKE_UTEST_FROM_FUNCTION(compiler_group_size1);
> +MAKE_UTEST_FROM_FUNCTION(compiler_group_size2);
> +MAKE_UTEST_FROM_FUNCTION(compiler_group_size3);
> +
> -- 
> 1.7.9.5
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list