test case for function "rotate"
authorHomer Hsing <homer.xing@intel.com>
Thu, 27 Jun 2013 02:58:16 +0000 (10:58 +0800)
committerZhigang Gong <zhigang.gong@linux.intel.com>
Thu, 27 Jun 2013 03:39:08 +0000 (11:39 +0800)
Signed-off-by: Homer Hsing <homer.xing@intel.com>
Reviewed-by: He Junyan <junyan.he@inbox.com>
Reviewed-by: Song, Ruiling <ruiling.song@intel.com>
kernels/compiler_rotate.cl [new file with mode: 0644]
utests/CMakeLists.txt
utests/compiler_rotate.cpp [new file with mode: 0644]

diff --git a/kernels/compiler_rotate.cl b/kernels/compiler_rotate.cl
new file mode 100644 (file)
index 0000000..8d0dd0f
--- /dev/null
@@ -0,0 +1,5 @@
+kernel void compiler_rotate(global int *src, global int *dst, global int *y) {
+  int i = get_global_id(0);
+  dst[i] = rotate(src[i], y[i]);
+}
+
index fa36277..c0908ea 100644 (file)
@@ -54,6 +54,7 @@ set (utests_sources
   compiler_lower_return1.cpp
   compiler_lower_return2.cpp
   compiler_multiple_kernels.cpp
+  compiler_rotate.cpp
   compiler_saturate.cpp
   compiler_saturate_sub.cpp
   compiler_shift_right.cpp
diff --git a/utests/compiler_rotate.cpp b/utests/compiler_rotate.cpp
new file mode 100644 (file)
index 0000000..bf52ca4
--- /dev/null
@@ -0,0 +1,40 @@
+#include "utest_helper.hpp"
+
+int cpu(int src, int y) {
+  return (src << y) | (src >> (32 - y));
+}
+
+void compiler_rotate(void)
+{
+  const int n = 32;
+  int src[n], y[n];
+
+  // Setup kernel and buffers
+  OCL_CREATE_KERNEL("compiler_rotate");
+  OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(int), NULL);
+  OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(int), NULL);
+  OCL_CREATE_BUFFER(buf[2], 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]);
+  globals[0] = n;
+  locals[0] = 16;
+
+  OCL_MAP_BUFFER(0);
+  OCL_MAP_BUFFER(2);
+  for (int i = 0; i < n; ++i) {
+    src[i] = ((int*)buf_data[0])[i] = rand();
+    y[i] = ((int*)buf_data[2])[i] = rand() & 31;
+  }
+  OCL_UNMAP_BUFFER(0);
+  OCL_UNMAP_BUFFER(2);
+
+  OCL_NDRANGE(1);
+
+  OCL_MAP_BUFFER(1);
+  for (int i = 0; i < n; ++i)
+    OCL_ASSERT(((int*)buf_data[1])[i] == cpu(src[i], y[i]));
+  OCL_UNMAP_BUFFER(1);
+}
+
+MAKE_UTEST_FROM_FUNCTION(compiler_rotate);