utest: Add test for built-in function get_local_size.
authorYi Sun <yi.sun@intel.com>
Mon, 29 Jul 2013 06:52:34 +0000 (14:52 +0800)
committerZhigang Gong <zhigang.gong@linux.intel.com>
Tue, 30 Jul 2013 04:01:36 +0000 (12:01 +0800)
Signed-off-by: Yi Sun <yi.sun@intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
kernels/builtin_local_size.cl [new file with mode: 0644]
utests/CMakeLists.txt
utests/builtin_local_size.cpp [new file with mode: 0644]

diff --git a/kernels/builtin_local_size.cl b/kernels/builtin_local_size.cl
new file mode 100644 (file)
index 0000000..979d907
--- /dev/null
@@ -0,0 +1,3 @@
+kernel void builtin_local_size( __global int *ret, __global int *i_dim ) {
+  *ret = get_local_size( *i_dim);
+}
index e4c5a3c..9e64206 100644 (file)
@@ -110,6 +110,7 @@ set (utests_sources
   builtin_sign.cpp
   buildin_work_dim.cpp
   builtin_global_size.cpp
+  builtin_local_size.cpp
   builtin_global_id.cpp
   runtime_createcontext.cpp
   runtime_null_kernel_arg.cpp
diff --git a/utests/builtin_local_size.cpp b/utests/builtin_local_size.cpp
new file mode 100644 (file)
index 0000000..a9dac2e
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+According to the OpenCL v1.1 & v1.2 chapter 6.11, the behavior of function get_local_size should be as following:
+
+  globals[0] = 3;
+  globals[1] = 4;
+  globals[2] = 5;
+  locals[0] = 3;
+  locals[1] = 4;
+  locals[2] = 5;
+
+get_local_size(-1) = 1 (dimension:1)
+get_local_size(0) = 3 (dimension:1)
+get_local_size(1) = 1 (dimension:1)
+get_local_size(2) = 1 (dimension:1)
+
+get_local_size(-1) = 1 (dimension:2)
+get_local_size(0) = 3 (dimension:2)
+get_local_size(1) = 4 (dimension:2)
+get_local_size(2) = 1 (dimension:2)
+get_local_size(3) = 1 (dimension:2)
+
+get_local_size(-1) = 1 (dimension:3)
+get_local_size(0) = 3 (dimension:3)
+get_local_size(1) = 4 (dimension:3)
+get_local_size(2) = 5 (dimension:3)
+get_local_size(3) = 1 (dimension:3)
+get_local_size(4) = 1 (dimension:3)
+
+*/
+#include "utest_helper.hpp"
+#define udebug 0
+
+static void builtin_local_size(void)
+{
+
+  // Setup kernel and buffers
+  int dim, dim_arg_global, local_size, err;
+  OCL_CREATE_KERNEL("builtin_local_size");
+
+  OCL_CREATE_BUFFER(buf[0], CL_MEM_READ_WRITE, sizeof(int), NULL);
+  OCL_CREATE_BUFFER(buf[1], CL_MEM_READ_WRITE, sizeof(int), NULL);
+  OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+  OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);
+
+  globals[0] = 3;
+  globals[1] = 4;
+  globals[2] = 5;
+  locals[0] = 3;
+  locals[1] = 4;
+  locals[2] = 5;
+
+  for( dim=1; dim <= 3; dim++ )
+  {
+
+    for( dim_arg_global = -1; dim_arg_global <= dim + 1; dim_arg_global++ )
+    {
+
+      err = clEnqueueWriteBuffer( queue, buf[1], CL_TRUE, 0, sizeof(int), &dim_arg_global, 0, NULL, NULL);
+      if (err != CL_SUCCESS)
+      {
+        printf("Error: Failed to write to source array!\n");
+        exit(1);
+      }
+
+      // Run the kernel
+      OCL_NDRANGE( dim );
+
+      err = clEnqueueReadBuffer( queue, buf[0], CL_TRUE, 0, sizeof(int), &local_size, 0, NULL, NULL);
+      if (err != CL_SUCCESS)
+      {
+        printf("Error: Failed to read output array! %d\n", err);
+        exit(1);
+      }
+
+#if udebug
+      printf("get_local_size(%d) = %d (dimension:%d)\n", dim_arg_global, local_size, dim);
+#endif
+      if ( dim_arg_global >= 0 && dim_arg_global < dim)
+        OCL_ASSERT( local_size == dim_arg_global + 3);
+      else
+      {
+        OCL_ASSERT( local_size == 1);
+      }
+    }
+  }
+}
+
+MAKE_UTEST_FROM_FUNCTION(builtin_local_size);