[Beignet] [PATCH] utest: add new test that trigger an assignment operation bug in if.

Chuanbo Weng chuanbo.weng at intel.com
Mon Nov 3 00:15:39 PST 2014


This test case shows that assignment operation in if block seems
does not affect lvalue.

Signed-off-by: Chuanbo Weng <chuanbo.weng at intel.com>
---
 kernels/compiler_assignment_operation_in_if.cl | 12 +++++++
 utests/CMakeLists.txt                          |  1 +
 utests/compiler_assignment_operation_in_if.cpp | 45 ++++++++++++++++++++++++++
 3 files changed, 58 insertions(+)
 create mode 100644 kernels/compiler_assignment_operation_in_if.cl
 create mode 100644 utests/compiler_assignment_operation_in_if.cpp

diff --git a/kernels/compiler_assignment_operation_in_if.cl b/kernels/compiler_assignment_operation_in_if.cl
new file mode 100644
index 0000000..d05a663
--- /dev/null
+++ b/kernels/compiler_assignment_operation_in_if.cl
@@ -0,0 +1,12 @@
+__kernel
+void compiler_assignment_operation_in_if(__global int *dst){
+  int gidx = (int)get_global_id(0);
+
+  int3 d1 = (int3) (gidx, gidx-1, gidx-3);
+  int k = gidx % 5;
+  if (k == 1){
+    d1.x = d1.y;
+  }
+  global int * addr = dst + gidx;
+  *addr = d1.x;
+}
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index bd1c65f..86e9989 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -191,6 +191,7 @@ set (utests_sources
   compiler_fill_image_1d_array.cpp
   compiler_fill_image_2d_array.cpp
   compiler_constant_expr.cpp
+  compiler_assignment_operation_in_if.cpp
   vload_bench.cpp
   utest_assert.cpp
   utest.cpp
diff --git a/utests/compiler_assignment_operation_in_if.cpp b/utests/compiler_assignment_operation_in_if.cpp
new file mode 100644
index 0000000..676c222
--- /dev/null
+++ b/utests/compiler_assignment_operation_in_if.cpp
@@ -0,0 +1,45 @@
+#include "utest_helper.hpp"
+
+typedef struct cpu_int3{
+	int x;
+	int y;
+	int z;
+}cpu_int3;
+
+static void cpu(int gidx, int *dst) {
+  cpu_int3 d1 = {gidx, gidx-1, gidx-3};
+  int k = gidx % 5;
+  if (k == 1){
+    d1.x = d1.y;
+  }
+  int * addr = dst + gidx;
+  *addr = d1.x;
+}
+
+void compiler_assignment_operation_in_if(void){
+  const size_t n = 16;
+  int cpu_dst[16];
+	
+  // Setup kernel and buffers
+  OCL_CREATE_KERNEL("compiler_assignment_operation_in_if");
+  OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(int), NULL);
+  OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+  globals[0] = 16;
+  locals[0] = 16;
+
+  // Run the kernel on GPU
+  OCL_NDRANGE(1);
+
+  // Run on CPU
+  for (int32_t i = 0; i < (int32_t) n; ++i)
+    cpu(i, cpu_dst);
+
+  // Compare
+  OCL_MAP_BUFFER(0);
+  for (int32_t i = 0; i < (int32_t) n; ++i)
+    OCL_ASSERT(((int *)buf_data[0])[i] == cpu_dst[i]);
+  OCL_UNMAP_BUFFER(0);
+
+}
+
+MAKE_UTEST_FROM_FUNCTION(compiler_assignment_operation_in_if)
-- 
1.9.1



More information about the Beignet mailing list