[Beignet] [PATCH 2/2] test built-in function "sign"

Xing, Homer homer.xing at intel.com
Thu Jul 11 18:58:12 PDT 2013


Okay. I will check it.

-----Original Message-----
From: Zhigang Gong [mailto:zhigang.gong at linux.intel.com] 
Sent: Friday, July 12, 2013 9:39 AM
To: Xing, Homer
Cc: beignet at lists.freedesktop.org
Subject: Re: [Beignet] [PATCH 2/2] test built-in function "sign"

I just found when run the complete utest cases, this case fails.
Homer, could you check it again? Thanks.

On Wed, Jul 10, 2013 at 12:42:03PM +0800, Homer Hsing wrote:
> 
> Signed-off-by: Homer Hsing <homer.xing at intel.com>
> ---
>  kernels/builtin_sign.cl |  4 ++++
>  utests/CMakeLists.txt   |  1 +
>  utests/builtin_sign.cpp | 45 
> +++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 50 insertions(+)
>  create mode 100644 kernels/builtin_sign.cl  create mode 100644 
> utests/builtin_sign.cpp
> 
> diff --git a/kernels/builtin_sign.cl b/kernels/builtin_sign.cl new 
> file mode 100644 index 0000000..ff9a66b
> --- /dev/null
> +++ b/kernels/builtin_sign.cl
> @@ -0,0 +1,4 @@
> +kernel void builtin_sign(global float *src, global float *dst) {
> +  int i = get_global_id(0);
> +  dst[i] = sign(src[i]);
> +}
> diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt index 
> 1cdbd24..14ff6b1 100644
> --- a/utests/CMakeLists.txt
> +++ b/utests/CMakeLists.txt
> @@ -102,6 +102,7 @@ set (utests_sources
>    get_cl_info.cpp
>    builtin_bitselect.cpp
>    builtin_mad_sat.cpp
> +  builtin_sign.cpp
>    buildin_work_dim.cpp
>    builtin_global_size.cpp
>    runtime_createcontext.cpp
> diff --git a/utests/builtin_sign.cpp b/utests/builtin_sign.cpp new 
> file mode 100644 index 0000000..7014790
> --- /dev/null
> +++ b/utests/builtin_sign.cpp
> @@ -0,0 +1,45 @@
> +#include <cmath>
> +#include "utest_helper.hpp"
> +
> +void builtin_sign(void)
> +{
> +  const int n = 32;
> +  float src[n];
> +
> +  // Setup kernel and buffers
> +  OCL_CREATE_KERNEL("builtin_sign");
> +  OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(float), NULL);  
> + OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(float), NULL);  
> + OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);  OCL_SET_ARG(1, 
> + sizeof(cl_mem), &buf[1]);  globals[0] = n;  locals[0] = 16;
> +
> +  OCL_MAP_BUFFER(0);
> +  src[0] = nanf("");
> +  src[1] = 0.f;
> +  src[2] = -0.f;
> +  for (int i = 3; i < n; ++i) {
> +    src[i] = ((float*)buf_data[0])[i] = (rand() & 15) * 0.1 - 0.75;  
> + }  OCL_UNMAP_BUFFER(0);
> +
> +  OCL_NDRANGE(1);
> +
> +  OCL_MAP_BUFFER(1);
> +  float *dst = (float*)buf_data[1];
> +  OCL_ASSERT(dst[0] == 0);
> +  OCL_ASSERT(dst[1] == 0.f);
> +  OCL_ASSERT(dst[2] == -0.f);
> +  for (int i = 3; i < n; ++i) {
> +    if (src[i] == 0.f)
> +      OCL_ASSERT(dst[i] == 0.f);
> +    else if (src[i] == -0.f)
> +      OCL_ASSERT(dst[i] == -0.f);
> +    else
> +      OCL_ASSERT(dst[i] == (src[i] > 0 ? 1 : -1));
> +  }
> +  OCL_UNMAP_BUFFER(1);
> +}
> +
> +MAKE_UTEST_FROM_FUNCTION(builtin_sign);
> --
> 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