[Beignet] [PATCH 2/2] add utest popcount_int and popcount_short.

xionghu.luo at intel.com xionghu.luo at intel.com
Thu Oct 9 20:05:05 PDT 2014


From: Luo Xionghu <xionghu.luo at intel.com>

Signed-off-by: Luo Xionghu <xionghu.luo at intel.com>
---
 kernels/compiler_popcount_int.cl   |    4 ++++
 kernels/compiler_popcount_short.cl |    4 ++++
 utests/CMakeLists.txt              |    2 ++
 utests/compiler_popcount_int.cpp   |   32 ++++++++++++++++++++++++++++++++
 utests/compiler_popcount_short.cpp |   32 ++++++++++++++++++++++++++++++++
 5 files changed, 74 insertions(+)
 create mode 100644 kernels/compiler_popcount_int.cl
 create mode 100644 kernels/compiler_popcount_short.cl
 create mode 100644 utests/compiler_popcount_int.cpp
 create mode 100644 utests/compiler_popcount_short.cpp

diff --git a/kernels/compiler_popcount_int.cl b/kernels/compiler_popcount_int.cl
new file mode 100644
index 0000000..b972dbc
--- /dev/null
+++ b/kernels/compiler_popcount_int.cl
@@ -0,0 +1,4 @@
+kernel void compiler_popcount_int(global int *src, global int *dst) {
+  int i = get_global_id(0);
+  dst[i] = popcount(src[i]);
+}
diff --git a/kernels/compiler_popcount_short.cl b/kernels/compiler_popcount_short.cl
new file mode 100644
index 0000000..e4204c5
--- /dev/null
+++ b/kernels/compiler_popcount_short.cl
@@ -0,0 +1,4 @@
+kernel void compiler_popcount_short(global short *src, global short *dst) {
+  int i = get_global_id(0);
+  dst[i] = popcount(src[i]);
+}
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index b45ecf9..2fe6243 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -41,6 +41,8 @@ set (utests_sources
   compiler_ceil.cpp
   compiler_clz_short.cpp
   compiler_clz_int.cpp
+  compiler_popcount_short.cpp
+  compiler_popcount_int.cpp
   compiler_convert_uchar_sat.cpp
   compiler_copy_buffer.cpp
   compiler_copy_image.cpp
diff --git a/utests/compiler_popcount_int.cpp b/utests/compiler_popcount_int.cpp
new file mode 100644
index 0000000..a3f675e
--- /dev/null
+++ b/utests/compiler_popcount_int.cpp
@@ -0,0 +1,32 @@
+#include "utest_helper.hpp"
+
+void compiler_popcount_int(void)
+{
+  const int n = 32;
+
+  // Setup kernel and buffers
+  OCL_CREATE_KERNEL("compiler_popcount_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] == 0);
+  for (int i = 1; i < n; ++i){
+    OCL_ASSERT(((int*)buf_data[1])[i] == n-i);
+  }
+  OCL_UNMAP_BUFFER(1);
+}
+
+MAKE_UTEST_FROM_FUNCTION(compiler_popcount_int);
diff --git a/utests/compiler_popcount_short.cpp b/utests/compiler_popcount_short.cpp
new file mode 100644
index 0000000..7aa1ebf
--- /dev/null
+++ b/utests/compiler_popcount_short.cpp
@@ -0,0 +1,32 @@
+#include "utest_helper.hpp"
+
+void compiler_popcount_short(void)
+{
+  const int n = 16;
+
+  // Setup kernel and buffers
+  OCL_CREATE_KERNEL("compiler_popcount_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] == 0);
+  for (int i = 1; i < n; ++i){
+    OCL_ASSERT(((short*)buf_data[1])[i] == short(n-i) );
+  }
+  OCL_UNMAP_BUFFER(1);
+}
+
+MAKE_UTEST_FROM_FUNCTION(compiler_popcount_short);
-- 
1.7.9.5



More information about the Beignet mailing list