utest: modify compiler_if_else to not rely on compiler behaviour.

Submitted by Song, Ruiling on April 6, 2017, 11:46 a.m.

Details

Message ID 1491479195-21112-1-git-send-email-ruiling.song@intel.com
State New
Headers show
Series "utest: modify compiler_if_else to not rely on compiler behaviour." ( rev: 1 ) in Beignet

Not browsing as part of any series.

Commit Message

Song, Ruiling April 6, 2017, 11:46 a.m.
the test case modify src as well as dst.
and it introduce cross workitem memory dependency in dst[id] = src[id+1];
The compiler may order 'then' and 'else' block not as written.
If compiler order the else block first. src[3+1] will be modified in else part.
And the utest will get wrong result. If user want to get the old behaviour,
It should use two if-then and order them as required.

Signed-off-by: Ruiling Song <ruiling.song@intel.com>
---
 kernels/compiler_if_else.cl |  2 --
 utests/compiler_if_else.cpp | 15 +++++----------
 2 files changed, 5 insertions(+), 12 deletions(-)

Patch hide | download patch | download mbox

diff --git a/kernels/compiler_if_else.cl b/kernels/compiler_if_else.cl
index 7ae8f99..c8b2cb8 100644
--- a/kernels/compiler_if_else.cl
+++ b/kernels/compiler_if_else.cl
@@ -5,10 +5,8 @@  compiler_if_else(__global int *src, __global int *dst)
   dst[id] = src[id];
   if (dst[id] >= 0) {
     dst[id] = src[id+1];
-    src[id] = 1;
   } else {
     dst[id]--;
-    src[id] = 2;
   }
 }
 
diff --git a/utests/compiler_if_else.cpp b/utests/compiler_if_else.cpp
index e38b23f..d65ecd3 100644
--- a/utests/compiler_if_else.cpp
+++ b/utests/compiler_if_else.cpp
@@ -21,43 +21,38 @@  static void compiler_if_else(void)
   OCL_NDRANGE(1);
 
   // First control flow
-  OCL_MAP_BUFFER(0);
   OCL_MAP_BUFFER(1);
   for (uint32_t i = 0; i < 16; ++i) {
     OCL_ASSERT(((int32_t*)buf_data[1])[i] == 2);
-    OCL_ASSERT(((int32_t*)buf_data[0])[i] == 1);
   }
+  OCL_UNMAP_BUFFER(1);
 
   // Second control flow
+  OCL_MAP_BUFFER(0);
   for (uint32_t i = 0; i < n; ++i) ((int32_t*)buf_data[0])[i] = -1;
   OCL_UNMAP_BUFFER(0);
-  OCL_UNMAP_BUFFER(1);
   OCL_NDRANGE(1);
-  OCL_MAP_BUFFER(0);
   OCL_MAP_BUFFER(1);
   for (uint32_t i = 0; i < 16; ++i) {
     OCL_ASSERT(((int32_t*)buf_data[1])[i] == -2);
-    OCL_ASSERT(((int32_t*)buf_data[0])[i] == 2);
   }
+  OCL_UNMAP_BUFFER(1);
 
   // Third control flow
+  OCL_MAP_BUFFER(0);
   for (uint32_t i = 0; i < 4; ++i) ((int32_t*)buf_data[0])[i] = 2;
   for (uint32_t i = 4; i < n; ++i) ((int32_t*)buf_data[0])[i] = -1;
   OCL_UNMAP_BUFFER(0);
-  OCL_UNMAP_BUFFER(1);
   OCL_NDRANGE(1);
-  OCL_MAP_BUFFER(0);
   OCL_MAP_BUFFER(1);
   for (uint32_t i = 0; i < 3; ++i) {
     OCL_ASSERT(((int32_t*)buf_data[1])[i] == 2);
-    OCL_ASSERT(((int32_t*)buf_data[0])[i] == 1);
   }
   OCL_ASSERT(((int32_t*)buf_data[1])[3] == -1);
-  OCL_ASSERT(((int32_t*)buf_data[0])[3] == 1);
   for (uint32_t i = 4; i < 16; ++i) {
     OCL_ASSERT(((int32_t*)buf_data[1])[i] == -2);
-    OCL_ASSERT(((int32_t*)buf_data[0])[i] == 2);
   }
+  OCL_UNMAP_BUFFER(1);
 }
 
 MAKE_UTEST_FROM_FUNCTION(compiler_if_else);