[Beignet] [PATCH v2 2/2] test built-in function "sign"
Zhigang Gong
zhigang.gong at linux.intel.com
Mon Jul 15 23:09:26 PDT 2013
Tested OK, pushed, thanks.
On Fri, Jul 12, 2013 at 12:10:26PM +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 | 47 +++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 52 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..426de36
> --- /dev/null
> +++ b/utests/builtin_sign.cpp
> @@ -0,0 +1,47 @@
> +#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] = ((float*)buf_data[0])[0] = nanf("");
> + src[1] = ((float*)buf_data[0])[1] = INFINITY;
> + src[2] = ((float*)buf_data[0])[2] = 0.f;
> + src[3] = ((float*)buf_data[0])[3] = -0.f;
> + for (int i = 4; 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] == 1.f);
> + OCL_ASSERT(dst[2] == 0.f);
> + OCL_ASSERT(dst[3] == -0.f);
> + for (int i = 4; 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