[Beignet] [PATCH 2/2] test case for function "clz"
Homer Hsing
homer.xing at intel.com
Tue Jun 25 22:11:54 PDT 2013
Signed-off-by: Homer Hsing <homer.xing at intel.com>
---
kernels/compiler_clz_int.cl | 5 +++++
kernels/compiler_clz_short.cl | 5 +++++
utests/CMakeLists.txt | 2 ++
utests/compiler_clz_int.cpp | 31 +++++++++++++++++++++++++++++++
utests/compiler_clz_short.cpp | 31 +++++++++++++++++++++++++++++++
5 files changed, 74 insertions(+)
create mode 100644 kernels/compiler_clz_int.cl
create mode 100644 kernels/compiler_clz_short.cl
create mode 100644 utests/compiler_clz_int.cpp
create mode 100644 utests/compiler_clz_short.cpp
diff --git a/kernels/compiler_clz_int.cl b/kernels/compiler_clz_int.cl
new file mode 100644
index 0000000..0f17f86
--- /dev/null
+++ b/kernels/compiler_clz_int.cl
@@ -0,0 +1,5 @@
+kernel void compiler_clz_int(global int *src, global int *dst) {
+ int i = get_global_id(0);
+ dst[i] = clz(src[i]);
+}
+
diff --git a/kernels/compiler_clz_short.cl b/kernels/compiler_clz_short.cl
new file mode 100644
index 0000000..1ecf7a9
--- /dev/null
+++ b/kernels/compiler_clz_short.cl
@@ -0,0 +1,5 @@
+kernel void compiler_clz_short(global short *src, global short *dst) {
+ int i = get_global_id(0);
+ dst[i] = clz(src[i]);
+}
+
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index c009d99..8d6d9e3 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -22,6 +22,8 @@ set (utests_sources
compiler_array3.cpp
compiler_byte_scatter.cpp
compiler_ceil.cpp
+ compiler_clz_short.cpp
+ compiler_clz_int.cpp
compiler_convert_uchar_sat.cpp
compiler_copy_buffer.cpp
compiler_copy_image.cpp
diff --git a/utests/compiler_clz_int.cpp b/utests/compiler_clz_int.cpp
new file mode 100644
index 0000000..c12cfc6
--- /dev/null
+++ b/utests/compiler_clz_int.cpp
@@ -0,0 +1,31 @@
+#include "utest_helper.hpp"
+
+void compiler_clz_int(void)
+{
+ const int n = 32;
+
+ // Setup kernel and buffers
+ OCL_CREATE_KERNEL("compiler_clz_int");
+ OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(int), NULL);
+ OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(int), 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);
+ ((int*)buf_data[0])[0] = 0;
+ for (int32_t i = 1; i < (int32_t) n; ++i)
+ ((int*)buf_data[0])[i] = 0xffffffffu >> i;
+ OCL_UNMAP_BUFFER(0);
+
+ OCL_NDRANGE(1);
+
+ OCL_MAP_BUFFER(1);
+ OCL_ASSERT(((int*)buf_data[1])[0] == 32);
+ for (int i = 1; i < n; ++i)
+ OCL_ASSERT(((int*)buf_data[1])[i] == i);
+ OCL_UNMAP_BUFFER(1);
+}
+
+MAKE_UTEST_FROM_FUNCTION(compiler_clz_int);
diff --git a/utests/compiler_clz_short.cpp b/utests/compiler_clz_short.cpp
new file mode 100644
index 0000000..eb3a370
--- /dev/null
+++ b/utests/compiler_clz_short.cpp
@@ -0,0 +1,31 @@
+#include "utest_helper.hpp"
+
+void compiler_clz_short(void)
+{
+ const size_t n = 16;
+
+ // Setup kernel and buffers
+ OCL_CREATE_KERNEL("compiler_clz_short");
+ OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(short), NULL);
+ OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(short), 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);
+ ((short*)buf_data[0])[0] = 0;
+ for (int32_t i = 1; i < (int32_t) n; ++i)
+ ((short*)buf_data[0])[i] = 0xffffu >> i;
+ OCL_UNMAP_BUFFER(0);
+
+ OCL_NDRANGE(1);
+
+ OCL_MAP_BUFFER(1);
+ OCL_ASSERT(((short*)buf_data[1])[0] == 16);
+ for (unsigned i = 1; i < (unsigned) n; ++i)
+ OCL_ASSERT(((short*)buf_data[1])[i] == (short)i);
+ OCL_UNMAP_BUFFER(1);
+}
+
+MAKE_UTEST_FROM_FUNCTION(compiler_clz_short);
--
1.8.1.2
More information about the Beignet
mailing list