[Beignet] [PATCH v2 2/2] test case for function "rotate"

Zhigang Gong zhigang.gong at linux.intel.com
Wed Jun 26 20:40:38 PDT 2013


Thanks for the patch.
Pushed with Junyan and Ruiling's review tags. Thanks.

On Thu, Jun 27, 2013 at 10:58:16AM +0800, Homer Hsing wrote:
> 
> Signed-off-by: Homer Hsing <homer.xing at intel.com>
> ---
>  kernels/compiler_rotate.cl |  5 +++++
>  utests/CMakeLists.txt      |  1 +
>  utests/compiler_rotate.cpp | 40 ++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 46 insertions(+)
>  create mode 100644 kernels/compiler_rotate.cl
>  create mode 100644 utests/compiler_rotate.cpp
> 
> diff --git a/kernels/compiler_rotate.cl b/kernels/compiler_rotate.cl
> new file mode 100644
> index 0000000..8d0dd0f
> --- /dev/null
> +++ b/kernels/compiler_rotate.cl
> @@ -0,0 +1,5 @@
> +kernel void compiler_rotate(global int *src, global int *dst, global int *y) {
> +  int i = get_global_id(0);
> +  dst[i] = rotate(src[i], y[i]);
> +}
> +
> diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
> index 8d6d9e3..ec371e9 100644
> --- a/utests/CMakeLists.txt
> +++ b/utests/CMakeLists.txt
> @@ -53,6 +53,7 @@ set (utests_sources
>    compiler_lower_return1.cpp
>    compiler_lower_return2.cpp
>    compiler_multiple_kernels.cpp
> +  compiler_rotate.cpp
>    compiler_saturate.cpp
>    compiler_saturate_sub.cpp
>    compiler_shift_right.cpp
> diff --git a/utests/compiler_rotate.cpp b/utests/compiler_rotate.cpp
> new file mode 100644
> index 0000000..bf52ca4
> --- /dev/null
> +++ b/utests/compiler_rotate.cpp
> @@ -0,0 +1,40 @@
> +#include "utest_helper.hpp"
> +
> +int cpu(int src, int y) {
> +  return (src << y) | (src >> (32 - y));
> +}
> +
> +void compiler_rotate(void)
> +{
> +  const int n = 32;
> +  int src[n], y[n];
> +
> +  // Setup kernel and buffers
> +  OCL_CREATE_KERNEL("compiler_rotate");
> +  OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(int), NULL);
> +  OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(int), NULL);
> +  OCL_CREATE_BUFFER(buf[2], 0, n * sizeof(int), NULL);
> +  OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
> +  OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);
> +  OCL_SET_ARG(2, sizeof(cl_mem), &buf[2]);
> +  globals[0] = n;
> +  locals[0] = 16;
> +
> +  OCL_MAP_BUFFER(0);
> +  OCL_MAP_BUFFER(2);
> +  for (int i = 0; i < n; ++i) {
> +    src[i] = ((int*)buf_data[0])[i] = rand();
> +    y[i] = ((int*)buf_data[2])[i] = rand() & 31;
> +  }
> +  OCL_UNMAP_BUFFER(0);
> +  OCL_UNMAP_BUFFER(2);
> +
> +  OCL_NDRANGE(1);
> +
> +  OCL_MAP_BUFFER(1);
> +  for (int i = 0; i < n; ++i)
> +    OCL_ASSERT(((int*)buf_data[1])[i] == cpu(src[i], y[i]));
> +  OCL_UNMAP_BUFFER(1);
> +}
> +
> +MAKE_UTEST_FROM_FUNCTION(compiler_rotate);
> -- 
> 1.8.1.2
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list