[Beignet] [PATCH 2/2] utests: add a test to trigger cl_float3 bug in clSetKernelArg.

Ruiling Song ruiling.song at intel.com
Wed Nov 5 23:44:49 PST 2014


Signed-off-by: Ruiling Song <ruiling.song at intel.com>
---
 kernels/set_kernel_arg.cl         |   20 ++++++++++++++++++++
 utests/CMakeLists.txt             |    1 +
 utests/runtime_set_kernel_arg.cpp |   30 ++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+)
 create mode 100644 kernels/set_kernel_arg.cl
 create mode 100644 utests/runtime_set_kernel_arg.cpp

diff --git a/kernels/set_kernel_arg.cl b/kernels/set_kernel_arg.cl
new file mode 100644
index 0000000..71cf521
--- /dev/null
+++ b/kernels/set_kernel_arg.cl
@@ -0,0 +1,20 @@
+__kernel void
+set_kernel_arg(__global unsigned int *dst, float3 src)
+{
+  size_t gid = get_global_id(0);
+
+  switch (gid%3)
+  {
+    case 0:
+        dst[gid] = src.x;
+      break;
+    case 1:
+        dst[gid] = src.y;
+      break;
+    case 2:
+        dst[gid] = src.z;
+      break;
+    default:
+      break;
+  }
+}
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index bd1c65f..d821dae 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -154,6 +154,7 @@ set (utests_sources
   builtin_convert_sat.cpp
   sub_buffer.cpp
   runtime_createcontext.cpp
+  runtime_set_kernel_arg.cpp
   runtime_null_kernel_arg.cpp
   runtime_event.cpp
   runtime_barrier_list.cpp
diff --git a/utests/runtime_set_kernel_arg.cpp b/utests/runtime_set_kernel_arg.cpp
new file mode 100644
index 0000000..d58c77e
--- /dev/null
+++ b/utests/runtime_set_kernel_arg.cpp
@@ -0,0 +1,30 @@
+#include "utest_helper.hpp"
+
+void runtime_set_kernel_arg(void)
+{
+  const size_t n = 16;
+
+  cl_float3 src;
+  src.s[0] = 1; src.s[1] =2; src.s[2] = 3;
+
+  // Setup kernel and buffers
+  OCL_CREATE_KERNEL("set_kernel_arg");
+  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(cl_float3), &src);
+
+    // Run the kernel
+  globals[0] = n;
+  locals[0] = 16;
+  OCL_NDRANGE(1);
+  OCL_MAP_BUFFER(0);
+
+  // Check results
+  for (uint32_t i = 0; i < n; ++i) {
+//    printf("%d %d\n",i, ((uint32_t*)buf_data[0])[i]);
+    OCL_ASSERT(((uint32_t*)buf_data[0])[i] == src.s[i%3]);
+  }
+  OCL_UNMAP_BUFFER(0);
+}
+
+MAKE_UTEST_FROM_FUNCTION(runtime_set_kernel_arg);
-- 
1.7.10.4



More information about the Beignet mailing list