[Beignet] [PATCH] utest: add test case for built-in function get_global_id.
Yi Sun
yi.sun at intel.com
Wed Jul 17 23:15:37 PDT 2013
Signed-off-by: Yi Sun <yi.sun at intel.com>
diff --git a/kernels/builtin_global_id.cl b/kernels/builtin_global_id.cl
new file mode 100644
index 0000000..6a2957d
--- /dev/null
+++ b/kernels/builtin_global_id.cl
@@ -0,0 +1,4 @@
+kernel void builtin_global_id( __global int *ret, __global int *i_dim ) {
+ int id = get_global_id(0) + get_global_id(1)*3 + get_global_id(2)*3*4;
+ ret[id] = id;
+}
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index 1cdbd24..97d1506 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -104,6 +104,7 @@ set (utests_sources
builtin_mad_sat.cpp
buildin_work_dim.cpp
builtin_global_size.cpp
+ builtin_global_id.cpp
runtime_createcontext.cpp
runtime_null_kernel_arg.cpp
compiler_double.cpp
diff --git a/utests/builtin_global_id.cpp b/utests/builtin_global_id.cpp
new file mode 100644
index 0000000..27cb7af
--- /dev/null
+++ b/utests/builtin_global_id.cpp
@@ -0,0 +1,88 @@
+/*
+According to the OpenCL v1.1 & v1.2 chapter 6.11.
+Now define global size as following:
+ globals[0] = 3;
+ globals[1] = 4;
+ globals[2] = 5;
+
+Kernel:
+id = get_global_id(0) + get_global_id(1)*3 + get_global_id(2)*3*4
+
+dimension:1
+ 0 1 2
+dimension:2
+ 0 1 2
+ 3 4 5
+ 6 7 8
+ 9 10 11
+dimension:3
+ 0 1 2 12 13 14 24 25 26 36 37 38 48 49 50
+ 3 4 5 15 16 17 27 28 29 39 40 41 51 52 53
+ 6 7 8 18 19 20 30 31 32 42 43 44 54 55 56
+ 9 10 11 21 22 23 33 34 35 45 46 47 57 58 59
+*/
+
+#define udebug 0
+#include "utest_helper.hpp"
+static void builtin_global_id(void)
+{
+
+ // Setup kernel and buffers
+ int dim, dim_arg_global=0, global_id[80], err, i, buf_len=1;
+ OCL_CREATE_KERNEL("builtin_global_id");
+
+ OCL_CREATE_BUFFER(buf[0], CL_MEM_READ_WRITE, sizeof(int)*80, 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]);
+
+ for( dim=1; dim <= 3; dim++ )
+ {
+ buf_len = 1;
+ for(i=1; i <= dim; i++)
+ {
+ globals[i - 1] = 2 + i;
+ locals[i - 1] = 2 + i;
+ buf_len *= 2 + i;
+ }
+ for(i=dim+1; i <= 3; i++)
+ {
+ globals[i - 1] = 0;
+ locals[i - 1] = 0;
+ }
+
+ dim_arg_global = dim - 1;
+
+ 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 );
+ clFinish(queue);
+
+ err = clEnqueueReadBuffer( queue, buf[0], CL_TRUE, 0, sizeof(int) * buf_len, &global_id, 0, NULL, NULL);
+
+ if (err != CL_SUCCESS)
+ {
+ printf("Error: Failed to read output array! %d\n", err);
+ exit(1);
+ }
+
+#if udebug
+ for(i = 0; i < buf_len; i++)
+ {
+ printf("%2d ", global_id[i]);
+ if ((i + 1) % 3 == 0) printf("\n");
+ }
+#endif
+
+ for( i = 0; i < buf_len; i++)
+ OCL_ASSERT( global_id[i] == i);
+ }
+}
+
+MAKE_UTEST_FROM_FUNCTION(builtin_global_id);
--
1.7.6.4
More information about the Beignet
mailing list