[Beignet] [PATCH] utests: add utests for relation functions of double type
rander
rander.wang at intel.com
Mon Mar 13 02:22:57 UTC 2017
Signed-off-by: rander <rander.wang at intel.com>
---
kernels/builtin_relation_fp64.cl | 52 +++++++++++++++
utests/CMakeLists.txt | 3 +-
utests/builtin_relation_fp64.cpp | 140 +++++++++++++++++++++++++++++++++++++++
3 files changed, 194 insertions(+), 1 deletion(-)
create mode 100644 kernels/builtin_relation_fp64.cl
create mode 100644 utests/builtin_relation_fp64.cpp
diff --git a/kernels/builtin_relation_fp64.cl b/kernels/builtin_relation_fp64.cl
new file mode 100644
index 0000000..321a692
--- /dev/null
+++ b/kernels/builtin_relation_fp64.cl
@@ -0,0 +1,52 @@
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+__kernel void builtin_relation_fp64(__global double *X, __global double *Y, __global int *Z, int max_input)
+{
+ int i = get_global_id(0);
+ int j;
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = isequal(X[j], Y[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = isnotequal(X[j], Y[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = isgreater(X[j], Y[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = isgreaterequal(X[j], Y[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = isless(X[j], Y[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = islessequal(X[j], Y[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = islessgreater(X[j], Y[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = isfinite(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = isinf(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = isnan(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ {
+ Z[i++] = isnormal(X[j]);
+ }
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = isordered(X[j], Y[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = isunordered(X[j], Y[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = signbit(X[j]);
+}
+
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index 43cf7f3..6e731af 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -297,7 +297,8 @@ set (utests_sources
compiler_generic_pointer.cpp
runtime_pipe_query.cpp
compiler_pipe_builtin.cpp
- compiler_device_enqueue.cpp)
+ compiler_device_enqueue.cpp
+ builtin_relation_fp64)
if (LLVM_VERSION_NODOT VERSION_GREATER 34)
SET(utests_sources
diff --git a/utests/builtin_relation_fp64.cpp b/utests/builtin_relation_fp64.cpp
new file mode 100644
index 0000000..c9c6783
--- /dev/null
+++ b/utests/builtin_relation_fp64.cpp
@@ -0,0 +1,140 @@
+#include "utest_helper.hpp"
+#include <cmath>
+#include <algorithm>
+
+#define udebug 0
+
+#define FLT_MAX 0x1.fffffep127f
+#define FLT_MIN ldexpf(1.0,-126)
+#define FLT_ULP (1.0e-6f)
+
+#define printf_c(...) \
+{\
+ printf("\033[1m\033[40;31m");\
+ printf( __VA_ARGS__ );\
+ printf("\033[0m");\
+}
+
+namespace{
+unsigned long doubleBinaryX[] = {
+ 0x0UL, //+0
+ 0x8000000000000000UL, //-0
+ 0x7FFFFFFFFFFFFFFFUL, //NAN
+ 0x0000000000000001UL, // DENORM
+ 0x8000000000000001UL, //-DENORM
+ 0x7FE0000000000001UL, // normal
+ 0x7FE0000000000002UL, // normal
+ 0xFFF0000000000000UL, //-INFINITY
+ 0xFFE0000000000001UL, // normal
+ 0x3F80000000000000UL, // normal
+ 0x7FF0000000000000UL, //+INFINITY
+ 0x5671230000000000UL, // normal
+ 0x1234560000000000UL, // normal
+ 0xA120234000000000UL, // normal
+ 0xC451200088771111UL, // normal
+ 0x1000241234110000UL // normal
+};
+
+unsigned long doubleBinaryY[] = {
+ 0x7FF0000000000000UL, //+INFINITY
+ 0x0UL, //+0
+ 0xFFF0000000000000UL, //-INFINITY
+ 0x0000000000000001UL, // DENORM
+ 0x7FE0000000000001UL, // normal
+ 0x3F80000000000000UL, // normal
+ 0x7FE0000000000002UL, // normal
+ 0x8000000000000001UL, //-DENORM
+ 0xFFE0000000000001UL, // normal
+ 0x1000241234110000, // normal
+ 0x7FFFFFFFFFFFFFFFUL, //NAN
+ 0x5671230000000000UL, // normal
+ 0xA120234000000000UL, // normal
+ 0x8000000000000000UL, //-0
+ 0xC451200088771111UL, // normal
+ 0x1234560000000000UL, // normal
+};
+
+const char* testFunc[] =
+{
+ " isequal(float x, float y)",
+ " isnotequal(float x, float y)",
+ " isgreater(float x, float y)",
+ " isgreaterequal(float x, float y)",
+ " isless(float x, float y)",
+ " islessequal(float x, float y)",
+ " islessgreater(float x, float y)",
+ " isfinite(float x)",
+ " isinf(float x)",
+ " isnan(float x)",
+ " isnormal(float x)",
+ " isordered(float x, float y)",
+ " isunordered(float x, float y)",
+ " signbit(float x)"
+};
+
+int expectResult[] = {
+ 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0,
+ 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0,
+ 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0,
+ 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1,
+ 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1,
+ 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1,
+ 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1,
+ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0,
+ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1,
+ 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
+ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
+ 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0
+
+};
+
+double *input_data;
+const int count_input = 16;
+const int max_function = 14;
+
+static void builtin_relation_fp64(void)
+{
+ // Setup kernel and buffers
+ int k, i, index_cur;
+ int gpu_data[max_function * count_input] = {0};
+ float diff;
+ char log[256] = {0};
+
+ OCL_CREATE_KERNEL("builtin_relation_fp64");
+
+ OCL_CREATE_BUFFER(buf[0], CL_MEM_READ_WRITE, count_input * max_function * sizeof(double), NULL);
+ OCL_CREATE_BUFFER(buf[1], CL_MEM_READ_WRITE, count_input * max_function * sizeof(double), NULL);
+ OCL_CREATE_BUFFER(buf[2], CL_MEM_READ_WRITE, count_input * max_function * 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]);
+ OCL_SET_ARG(3, sizeof(int), &count_input);
+
+ globals[0] = 1;
+ locals[0] = 1;
+
+ input_data = (double *)doubleBinaryX;
+ clEnqueueWriteBuffer( queue, buf[0], CL_TRUE, 0, count_input * max_function * sizeof(double), input_data, 0, NULL, NULL);
+ input_data = (double *)doubleBinaryY;
+ clEnqueueWriteBuffer( queue, buf[1], CL_TRUE, 0, count_input * max_function * sizeof(double), input_data, 0, NULL, NULL);
+
+ // Run the kernel
+ OCL_NDRANGE( 1 );
+
+ clEnqueueReadBuffer( queue, buf[2], CL_TRUE, 0, sizeof(int) * max_function * count_input, gpu_data, 0, NULL, NULL);
+
+ printf("\n");
+
+ for (k = 0; (uint)k < count_input*max_function; k++)
+ {
+ if(gpu_data[k] != expectResult[k])
+ {
+ printf("failed at function:%s, expect value: %d, but get :%d \n", testFunc[k/count_input], expectResult[k], gpu_data[k]);
+ }
+ }
+}
+
+MAKE_UTEST_FROM_FUNCTION(builtin_relation_fp64)
+}
--
2.7.4
More information about the Beignet
mailing list