[Beignet] [PATCH] test cases for global constant arrays

Homer Hsing homer.xing at intel.com
Wed May 1 20:12:20 PDT 2013


version 4

Signed-off-by: Homer Hsing <homer.xing at intel.com>
---
 kernels/compiler_global_constant.cl   |  8 ++++++++
 kernels/compiler_global_constant_2.cl |  9 +++++++++
 utests/CMakeLists.txt                 |  2 ++
 utests/compiler_global_constant.cpp   | 29 +++++++++++++++++++++++++++++
 utests/compiler_global_constant_2.cpp | 30 ++++++++++++++++++++++++++++++
 5 files changed, 78 insertions(+)
 create mode 100644 kernels/compiler_global_constant.cl
 create mode 100644 kernels/compiler_global_constant_2.cl
 create mode 100644 utests/compiler_global_constant.cpp
 create mode 100644 utests/compiler_global_constant_2.cpp

diff --git a/kernels/compiler_global_constant.cl b/kernels/compiler_global_constant.cl
new file mode 100644
index 0000000..af3c7b1
--- /dev/null
+++ b/kernels/compiler_global_constant.cl
@@ -0,0 +1,8 @@
+constant int m[3] = {71,72,73};
+
+__kernel void
+compiler_global_constant(__global int *dst, int e, int r)
+{
+  int id = (int)get_global_id(0);
+  dst[id] = m[id%3] + e + r;
+}
diff --git a/kernels/compiler_global_constant_2.cl b/kernels/compiler_global_constant_2.cl
new file mode 100644
index 0000000..353ebd7
--- /dev/null
+++ b/kernels/compiler_global_constant_2.cl
@@ -0,0 +1,9 @@
+constant int m[3] = {0x15b,0x25b,0x35b};
+constant int t[5] = {0x45b,0x55b,0x65b,0x75b,0x85b};
+
+__kernel void
+compiler_global_constant_2(__global int *dst, int e, int r)
+{
+  int id = (int)get_global_id(0);
+  dst[id] = m[id%3] + t[id%5] + e + r;
+}
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index b2e3c97..dbc8abe 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -32,6 +32,8 @@ set (utests_sources
   compiler_function_constant0.cpp
   compiler_function_constant1.cpp
   compiler_function_constant.cpp
+  compiler_global_constant.cpp
+  compiler_global_constant_2.cpp
   compiler_if_else.cpp
   compiler_integer_division.cpp
   compiler_integer_remainder.cpp
diff --git a/utests/compiler_global_constant.cpp b/utests/compiler_global_constant.cpp
new file mode 100644
index 0000000..1547020
--- /dev/null
+++ b/utests/compiler_global_constant.cpp
@@ -0,0 +1,29 @@
+#include "utest_helper.hpp"
+
+void compiler_global_constant(void)
+{
+  const size_t n = 2048;
+  const uint32_t e = 34, r = 77;
+
+  // Setup kernel and buffers
+  OCL_CREATE_KERNEL("compiler_global_constant");
+  OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(uint32_t), NULL);
+  OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+  OCL_SET_ARG(1, sizeof(uint32_t), &e);
+  OCL_SET_ARG(2, sizeof(uint32_t), &r);
+
+  // Run the kernel
+  globals[0] = n;
+  locals[0] = 16;
+  OCL_NDRANGE(1);
+
+  unsigned int m[3] = {71,72,73};
+
+  // Check results
+  OCL_MAP_BUFFER(0);
+  for (uint32_t i = 0; i < n; ++i)
+    OCL_ASSERT(((uint32_t *)buf_data[0])[i] == m[i%3] + e + r);
+  OCL_UNMAP_BUFFER(0);
+}
+
+MAKE_UTEST_FROM_FUNCTION(compiler_global_constant);
diff --git a/utests/compiler_global_constant_2.cpp b/utests/compiler_global_constant_2.cpp
new file mode 100644
index 0000000..56fccb5
--- /dev/null
+++ b/utests/compiler_global_constant_2.cpp
@@ -0,0 +1,30 @@
+#include "utest_helper.hpp"
+
+void compiler_global_constant_2(void)
+{
+  const size_t n = 2048;
+  const uint32_t e = 34, r = 77;
+
+  // Setup kernel and buffers
+  OCL_CREATE_KERNEL("compiler_global_constant_2");
+  OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(uint32_t), NULL);
+  OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+  OCL_SET_ARG(1, sizeof(uint32_t), &e);
+  OCL_SET_ARG(2, sizeof(uint32_t), &r);
+
+  // Run the kernel
+  globals[0] = n;
+  locals[0] = 16;
+  OCL_NDRANGE(1);
+
+  unsigned int m[3] = {0x15b,0x25b,0x35b};
+  unsigned int t[5] = {0x45b,0x55b,0x65b,0x75b,0x85b};
+
+  // Check results
+  OCL_MAP_BUFFER(0);
+  for (uint32_t i = 0; i < n; ++i)
+    OCL_ASSERT(((uint32_t *)buf_data[0])[i] == m[i%3] + t[i%5] + e + r);
+  OCL_UNMAP_BUFFER(0);
+}
+
+MAKE_UTEST_FROM_FUNCTION(compiler_global_constant_2);
-- 
1.8.1.2



More information about the Beignet mailing list