[Beignet] [PATCH] utests: add utest to double convert int32
rander
rander.wang at intel.com
Thu Mar 16 03:07:50 UTC 2017
Signed-off-by: rander <rander.wang at intel.com>
---
kernels/builtin_convert_double2int32.cl | 73 +++++++++
utests/CMakeLists.txt | 3 +-
utests/builtin_convert_double2int32.cpp | 263 ++++++++++++++++++++++++++++++++
3 files changed, 338 insertions(+), 1 deletion(-)
create mode 100644 kernels/builtin_convert_double2int32.cl
create mode 100644 utests/builtin_convert_double2int32.cpp
diff --git a/kernels/builtin_convert_double2int32.cl b/kernels/builtin_convert_double2int32.cl
new file mode 100644
index 0000000..0c37891
--- /dev/null
+++ b/kernels/builtin_convert_double2int32.cl
@@ -0,0 +1,73 @@
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+__kernel void builtin_convert_double2int32(__global double *X,
+ __global int *Z,
+ __global uint *uZ,
+ int max_input)
+{
+ int i = get_global_id(0);
+ int j;
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = convert_int(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = convert_int_sat(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = convert_int_rtz(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = convert_int_rtn(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = convert_int_rte(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = convert_int_rtp(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = convert_int_sat_rtz(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = convert_int_sat_rtn(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = convert_int_sat_rte(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ Z[i++] = convert_int_sat_rtp(X[j]);
+
+ i = 0;
+ for(j = 0; j < max_input; j++)
+ uZ[i++] = convert_uint(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ uZ[i++] = convert_uint_sat(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ uZ[i++] = convert_uint_rtz(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ uZ[i++] = convert_uint_rtn(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ uZ[i++] = convert_uint_rte(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ uZ[i++] = convert_uint_rtp(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ uZ[i++] = convert_uint_sat_rtz(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ uZ[i++] = convert_uint_sat_rtn(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ uZ[i++] = convert_uint_sat_rte(X[j]);
+
+ for(j = 0; j < max_input; j++)
+ uZ[i++] = convert_uint_sat_rtp(X[j]);
+
+}
+
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index c18f79d..38741c1 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -301,7 +301,8 @@ set (utests_sources
builtin_relation_fp64.cpp
builtin_commonFunc_fp64.cpp
builtin_convert_double2int8.cpp
- builtin_convert_double2int16.cpp)
+ builtin_convert_double2int16.cpp
+ builtin_convert_double2int32.cpp)
if (LLVM_VERSION_NODOT VERSION_GREATER 34)
SET(utests_sources
diff --git a/utests/builtin_convert_double2int32.cpp b/utests/builtin_convert_double2int32.cpp
new file mode 100644
index 0000000..5589d1b
--- /dev/null
+++ b/utests/builtin_convert_double2int32.cpp
@@ -0,0 +1,263 @@
+#include "utest_helper.hpp"
+#include <cmath>
+#include <algorithm>
+
+namespace{
+double doubleX[] = {
+ 0x1.0000000001p0,
+ -0x1.0000000001p2,
+ 0x1.1ffp8,
+ -0x1.1fffp8,
+ 0x1.0p7,
+ -0x1.0p7,
+ 0x1.fffp6,
+ -0x1.ffffp6,
+ 0x1.ffffp7,
+ 0x1.1p-64,
+ -0x1.ffffp7,
+ 0x1.00001p8,
+ -0x1.00001p8,
+ 0x1.00000001p5,
+ -0x1.00000001p5,
+ 0x1.0p-32,
+ -0x1.0p-32,
+ 0x1.000000001p16,
+ -0x1.000000001p16,
+ 0x1.ffffffffffp15,
+ -0x1.1p-64
+ -0x1.ffffffffffp15,
+ 0x1.fffffffffp8,
+ -0x1.fffffffffp8,
+ 0x1fffffp128,
+ -0x1ffffffp128,
+ 0x1.1000001p12,
+ -0x1.1000001p12,
+ 0x1.cp13,
+ -0x1.cp13,
+ 0x1.100001p11,
+ -0x1.100001p11,
+ 0x1.0p32,
+ -0x1.0p32,
+ 0x1.0000001p34,
+ -0x1.0000001p35,
+ 0x1.fffffffffp31,
+ -0x1.fffffffp31,
+ 0x1.1000001p40,
+ -0x1.1000001p41,
+ 0x1.c0000001p50,
+ -0x1.c0000001p51,
+ 0x1.fffffffffffffp60,
+ -0x1.fffffffffffffp61,
+ 0x1.00000001p22,
+ -0x1.00000001p23,
+ 0x1.c00000001p24,
+ -0x1.c00000001p25
+};
+
+const char* testFunc[] =
+{
+ " int convert_int(double x)",
+ " int convert_int_sat(double x)",
+ " int convert_int_rtz(double x)",
+ " int convert_int_rtn(double x)",
+ " int convert_int_rte(double x)",
+ " int convert_int_rtp(double x)",
+ " int convert_int_sat_rtz(double x)",
+ " int convert_int_sat_rtn(double x)",
+ " int convert_int_sat_rte(double x)",
+ " int convert_int_sat_rtp(double x)",
+
+ " uint convert_uint(double x)",
+ " uint convert_uint_sat(double x)",
+ " uint convert_uint_rtz(double x)",
+ " uint convert_uint_rtn(double x)",
+ " uint convert_uint_rte(double x)",
+ " uint convert_uint_rtp(double x)",
+ " uint convert_uint_sat_rtz(double x)",
+ " uint convert_uint_sat_rtn(double x)",
+ " uint convert_uint_sat_rte(double x)",
+ " uint convert_uint_sat_rtp(double x)"
+};
+
+int expectResultint[] = {
+ 1, -4, 287, -287, 128, -128, 127, -127, 255,
+ 0, -255, 256, -256, 32, -32, 0, 0,
+ 65536, -65536, 65535, -65535, 511, -511, 2147483647, -2147483648,
+ 4352, -4352, 14336, -14336, 2176, -2176, 2147483647, -2147483648,
+ 2147483647, -2147483648, 2147483647, -2147483648, 2147483647, -2147483648, 2147483647, -2147483648,
+ 2147483647, -2147483648, 4194304, -8388608, 29360128, -58720256, 0, 1,
+ -4, 287, -287, 128, -128, 127, -127, 255,
+ 0, -255, 256, -256, 32, -32, 0, 0,
+ 65536, -65536, 65535, -65535, 511, -511, 2147483647, -2147483648,
+ 4352, -4352, 14336, -14336, 2176, -2176, 2147483647, -2147483648,
+ 2147483647, -2147483648, 2147483647, -2147483648, 2147483647, -2147483648, 2147483647, -2147483648,
+ 2147483647, -2147483648, 4194304, -8388608, 29360128, -58720256, 0, 1,
+ -4, 287, -287, 128, -128, 127, -127, 255,
+ 0, -255, 256, -256, 32, -32, 0, 0,
+ 65536, -65536, 65535, -65535, 511, -511, 2097151, -33554431,
+ 4352, -4352, 14336, -14336, 2176, -2176, 0, 0,
+ 64, -128, -1, 8, 4096, -8192, 262144, -524288,
+ 0, 0, 4194304, -8388608, 29360128, -58720256, 0, 1,
+ -5, 287, -288, 128, -128, 127, -128, 255,
+ 0, -256, 256, -257, 32, -33, 0, -1,
+ 65536, -65537, 65535, -65536, 511, -512, 2097151, -33554431,
+ 4352, -4353, 14336, -14336, 2176, -2177, 0, 0,
+ 64, -128, -1, 8, 4096, -8192, 262144, -524288,
+ 0, -1, 4194304, -8388609, 29360128, -58720257, 0, 1,
+ -4, 288, -288, 128, -128, 128, -128, 256,
+ 0, -256, 256, -256, 32, -32, 0, 0,
+ 65536, -65536, 65536, -65536, 512, -512, 0, 0,
+ 4352, -4352, 14336, -14336, 2176, -2176, 0, 0,
+ 64, -128, 0, 8, 4096, -8192, 262144, -524288,
+ -256, 512, 4194304, -8388608, 29360128, -58720256, 0, 2,
+ -4, 288, -287, 128, -128, 128, -127, 256,
+ 1, -255, 257, -256, 33, -32, 1, 0,
+ 65537, -65536, 65536, -65535, 512, -511, 0, 0,
+ 4353, -4352, 14336, -14336, 2177, -2176, 0, 0,
+ 64, -128, 0, 8, 4096, -8192, 262144, -524288,
+ -256, 512, 4194305, -8388608, 29360129, -58720256, 0, 1,
+ -4, 287, -287, 128, -128, 127, -127, 255,
+ 0, -255, 256, -256, 32, -32, 0, 0,
+ 65536, -65536, 65535, -65535, 511, -511, 2147483647, -2147483648,
+ 4352, -4352, 14336, -14336, 2176, -2176, 2147483647, -2147483648,
+ 2147483647, -2147483648, 2147483647, -2147483648, 2147483647, -2147483648, 2147483647, -2147483648,
+ 2147483647, -2147483648, 4194304, -8388608, 29360128, -58720256, 0, 1,
+ -5, 287, -288, 128, -128, 127, -128, 255,
+ 0, -256, 256, -257, 32, -33, 0, -1,
+ 65536, -65537, 65535, -65536, 511, -512, 2147483647, -2147483648,
+ 4352, -4353, 14336, -14336, 2176, -2177, 2147483647, -2147483648,
+ 2147483647, -2147483648, 2147483647, -2147483648, 2147483647, -2147483648, 2147483647, -2147483648,
+ 2147483647, -2147483648, 4194304, -8388609, 29360128, -58720257, 0, 1,
+ -4, 288, -288, 128, -128, 128, -128, 256,
+ 0, -256, 256, -256, 32, -32, 0, 0,
+ 65536, -65536, 65536, -65536, 512, -512, 2147483647, -2147483648,
+ 4352, -4352, 14336, -14336, 2176, -2176, 2147483647, -2147483648,
+ 2147483647, -2147483648, 2147483647, -2147483648, 2147483647, -2147483648, 2147483647, -2147483648,
+ 2147483647, -2147483648, 4194304, -8388608, 29360128, -58720256, 0, 2,
+ -4, 288, -287, 128, -128, 128, -127, 256,
+ 1, -255, 257, -256, 33, -32, 1, 0,
+ 65537, -65536, 65536, -65535, 512, -511, 2147483647, -2147483648,
+ 4353, -4352, 14336, -14336, 2177, -2176, 2147483647, -2147483648,
+ 2147483647, -2147483648, 2147483647, -2147483648, 2147483647, -2147483648, 2147483647, -2147483648,
+ 2147483647, -2147483648, 4194305, -8388608, 29360129, -58720256, 0, 1
+};
+
+unsigned int expectResultUint[] = {
+ 1, 0, 287, 0, 128, 0, 127, 0, 255,
+ 0, 0, 256, 0, 32, 0, 0, 0,
+ 65536, 0, 65535, 0, 511, 0, 4294967295, 0,
+ 4352, 0, 14336, 0, 2176, 0, 4294967295, 0,
+ 4294967295, 0, 4294967295, 0, 4294967295, 0, 4294967295, 0,
+ 4294967295, 0, 4194304, 0, 29360128, 0, 0, 1,
+ 0, 287, 0, 128, 0, 127, 0, 255,
+ 0, 0, 256, 0, 32, 0, 0, 0,
+ 65536, 0, 65535, 0, 511, 0, 4294967295, 0,
+ 4352, 0, 14336, 0, 2176, 0, 4294967295, 0,
+ 4294967295, 0, 4294967295, 0, 4294967295, 0, 4294967295, 0,
+ 4294967295, 0, 4194304, 0, 29360128, 0, 0, 1,
+ 0, 287, 0, 128, 0, 127, 0, 255,
+ 0, 0, 256, 0, 32, 0, 0, 0,
+ 65536, 0, 65535, 0, 511, 0, 2097151, 0,
+ 4352, 0, 14336, 0, 2176, 0, 0, 0,
+ 64, 0, 4294967295, 0, 4096, 0, 262144, 0,
+ 0, 0, 4194304, 0, 29360128, 0, 0, 1,
+ 4, 287, 287, 128, 128, 127, 127, 255,
+ 0, 255, 256, 256, 32, 32, 0, 0,
+ 65536, 65536, 65535, 65535, 511, 511, 2097151, 33554431,
+ 4352, 4352, 14336, 14336, 2176, 2176, 0, 0,
+ 64, 128, 4294967295, 4294967288, 4096, 8192, 262144, 524288,
+ 0, 0, 4194304, 8388608, 29360128, 58720256, 0, 1,
+ 4294967292, 288, 4294967008, 128, 4294967168, 128, 4294967168, 256,
+ 0, 4294967040, 256, 4294967040, 32, 4294967264, 0, 0,
+ 65536, 4294901760, 65536, 4294901760, 512, 4294966784, 0, 0,
+ 4352, 4294962944, 14336, 4294952960, 2176, 4294965120, 0, 0,
+ 64, 4294967168, 0, 8, 4096, 4294959104, 262144, 4294443008,
+ 4294967040, 512, 4194304, 4286578688, 29360128, 4236247040, 0, 2,
+ 0, 288, 0, 128, 0, 128, 0, 256,
+ 1, 0, 257, 0, 33, 0, 1, 0,
+ 65537, 0, 65536, 0, 512, 0, 0, 0,
+ 4353, 0, 14336, 0, 2177, 0, 0, 0,
+ 64, 0, 0, 0, 4096, 0, 262144, 0,
+ 4294967040, 0, 4194305, 0, 29360129, 0, 0, 1,
+ 0, 287, 0, 128, 0, 127, 0, 255,
+ 0, 0, 256, 0, 32, 0, 0, 0,
+ 65536, 0, 65535, 0, 511, 0, 4294967295, 0,
+ 4352, 0, 14336, 0, 2176, 0, 4294967295, 0,
+ 4294967295, 0, 4294967295, 0, 4294967295, 0, 4294967295, 0,
+ 4294967295, 0, 4194304, 0, 29360128, 0, 0, 1,
+ 0, 287, 0, 128, 0, 127, 0, 255,
+ 0, 0, 256, 0, 32, 0, 0, 0,
+ 65536, 0, 65535, 0, 511, 0, 4294967295, 0,
+ 4352, 0, 14336, 0, 2176, 0, 4294967295, 0,
+ 4294967295, 0, 4294967295, 0, 4294967295, 0, 4294967295, 0,
+ 4294967295, 0, 4194304, 0, 29360128, 0, 0, 1,
+ 0, 288, 0, 128, 0, 128, 0, 256,
+ 0, 0, 256, 0, 32, 0, 0, 0,
+ 65536, 0, 65536, 0, 512, 0, 4294967295, 0,
+ 4352, 0, 14336, 0, 2176, 0, 4294967295, 0,
+ 4294967295, 0, 4294967295, 0, 4294967295, 0, 4294967295, 0,
+ 4294967295, 0, 4194304, 0, 29360128, 0, 0, 2,
+ 0, 288, 0, 128, 0, 128, 0, 256,
+ 1, 0, 257, 0, 33, 0, 1, 0,
+ 65537, 0, 65536, 0, 512, 0, 4294967295, 0,
+ 4353, 0, 14336, 0, 2177, 0, 4294967295, 0,
+ 4294967295, 0, 4294967295, 0, 4294967295, 0, 4294967295, 0,
+ 4294967295, 0, 4194305, 0, 29360129, 0, 0
+};
+
+double *input_data;
+const int count_input = 48;
+const int max_function = 20;
+
+static void builtin_convert_double2int32(void)
+{
+ // Setup kernel and buffers
+ int k, i, index_cur;
+ int gpu_data[max_function * count_input] = {0};
+ float diff;
+ int log[256] = {0};
+
+ OCL_CREATE_KERNEL("builtin_convert_double2int32");
+
+ 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(int), 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 *)doubleX;
+ clEnqueueWriteBuffer( queue, buf[0], CL_TRUE, 0, count_input * max_function * sizeof(double), input_data, 0, NULL, NULL);
+
+ // Run the kernel
+ OCL_NDRANGE( 1 );
+
+ clEnqueueReadBuffer( queue, buf[1], CL_TRUE, 0, sizeof(int) * max_function/2 * count_input, gpu_data, 0, NULL, NULL);
+ for (k = 0; (uint)k < count_input*max_function/2; k++)
+ {
+ OCL_ASSERT(gpu_data[k] == expectResultint[k]);
+ if(gpu_data[k] != expectResultint[k])
+ {
+ printf("failed at function:%s, expect value: %d, but get :%d \n", testFunc[k/count_input], expectResultint[k], gpu_data[k]);
+ }
+ }
+
+ clEnqueueReadBuffer( queue, buf[2], CL_TRUE, 0, sizeof(int) * max_function/2 * count_input, gpu_data, 0, NULL, NULL);
+ unsigned int *ugpu_data = (unsigned int *)gpu_data;
+ for (k = 0; (uint)k < count_input*max_function/2; k++)
+ {
+ OCL_ASSERT(ugpu_data[k] == expectResultUint[k]);
+ if(ugpu_data[k] != expectResultUint[k])
+ {
+ printf("failed at function:%s, expect value: %d, but get :%d \n", testFunc[k/count_input + max_function/2], expectResultUint[k], ugpu_data[k]);
+ }
+ }
+}
+
+MAKE_UTEST_FROM_FUNCTION(builtin_convert_double2int32)
+}
--
2.7.4
More information about the Beignet
mailing list