[Beignet] [PATCH v2 2/2] test builtin function "remquo"
Homer Hsing
homer.xing at intel.com
Tue Jul 16 23:22:02 PDT 2013
Signed-off-by: Homer Hsing <homer.xing at intel.com>
---
kernels/builtin_remquo.cl | 6 +++++
utests/CMakeLists.txt | 1 +
utests/builtin_remquo.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 70 insertions(+)
create mode 100644 kernels/builtin_remquo.cl
create mode 100644 utests/builtin_remquo.cpp
diff --git a/kernels/builtin_remquo.cl b/kernels/builtin_remquo.cl
new file mode 100644
index 0000000..d66c164
--- /dev/null
+++ b/kernels/builtin_remquo.cl
@@ -0,0 +1,6 @@
+kernel void builtin_remquo(global float *x, global float *y, global float *dst, global int *quo) {
+ int i = get_global_id(0);
+ int q;
+ dst[i] = remquo(x[i], y[i], & q);
+ quo[i] = q;
+}
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index ee64e8d..5dbae30 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -105,6 +105,7 @@ set (utests_sources
builtin_mad_sat.cpp
builtin_modf.cpp
builtin_nextafter.cpp
+ builtin_remquo.cpp
builtin_sign.cpp
buildin_work_dim.cpp
builtin_global_size.cpp
diff --git a/utests/builtin_remquo.cpp b/utests/builtin_remquo.cpp
new file mode 100644
index 0000000..f9131f9
--- /dev/null
+++ b/utests/builtin_remquo.cpp
@@ -0,0 +1,63 @@
+#include <cmath>
+#include <cstring>
+#include "utest_helper.hpp"
+
+void builtin_remquo(void)
+{
+ const int n = 16;
+ float src1[n], src2[n];
+
+ // Setup kernel and buffers
+ OCL_CREATE_KERNEL("builtin_remquo");
+ OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(float), NULL);
+ OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(float), NULL);
+ OCL_CREATE_BUFFER(buf[2], 0, n * sizeof(float), NULL);
+ OCL_CREATE_BUFFER(buf[3], 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]);
+ OCL_SET_ARG(3, sizeof(cl_mem), &buf[3]);
+ globals[0] = n;
+ locals[0] = 16;
+
+ src1[0] = 1, src2[0] = 0;
+ src1[1] = 1, src2[1] = -0.f;
+ src1[2] = INFINITY, src2[2] = 1;
+ src1[3] = -INFINITY, src2[3] = 1;
+ src1[4] = nanf(""), src2[4] = nanf("");
+ src1[5] = 1.625f, src2[5] = 1;
+ src1[6] = -1.625f, src2[6] = 1;
+ src1[7] = 1.625f, src2[7] = -1;
+ src1[8] = -1.625f, src2[8] = -1;
+ src1[9] = 5, src2[9] = 2;
+ src1[10] = 3, src2[10] = 2;
+
+ OCL_MAP_BUFFER(0);
+ OCL_MAP_BUFFER(1);
+ memcpy(buf_data[0], src1, n * sizeof(float));
+ memcpy(buf_data[1], src2, n * sizeof(float));
+ OCL_UNMAP_BUFFER(0);
+ OCL_UNMAP_BUFFER(1);
+
+ OCL_NDRANGE(1);
+
+ OCL_MAP_BUFFER(2);
+ OCL_MAP_BUFFER(3);
+ float *dest = (float *)buf_data[2];
+ int *quo = (int *)buf_data[3];
+ OCL_ASSERT(isnanf(dest[0]));
+ OCL_ASSERT(isnanf(dest[1]));
+ OCL_ASSERT(isnanf(dest[2]));
+ OCL_ASSERT(isnanf(dest[3]));
+ OCL_ASSERT(isnanf(dest[4]));
+ OCL_ASSERT(dest[5] == -0.375f && quo[5] == 2);
+ OCL_ASSERT(dest[6] == 0.375f && quo[6] == -2);
+ OCL_ASSERT(dest[7] == -0.375f && quo[7] == -2);
+ OCL_ASSERT(dest[8] == 0.375f && quo[8] == 2);
+ OCL_ASSERT(dest[9] == 1 && quo[9] == 2);
+ OCL_ASSERT(dest[10] == -1 && quo[10] == 2);
+ OCL_UNMAP_BUFFER(2);
+ OCL_UNMAP_BUFFER(3);
+}
+
+MAKE_UTEST_FROM_FUNCTION(builtin_remquo);
--
1.8.1.2
More information about the Beignet
mailing list