[Beignet] [PATCH 4/5] Utest: Add OCL20 into utest and check version in runtime

Xiuli Pan xiuli.pan at intel.com
Tue Jan 24 08:47:58 UTC 2017


From: Pan Xiuli <xiuli.pan at intel.com>

The utest should always be built and we can check ocl version at the
test begin.

Contributor: Rebecca N. Palmer <rebecca_palmer at zoho.com>
Signed-off-by: Pan Xiuli <xiuli.pan at intel.com>
---
 utests/CMakeLists.txt                   | 22 +++++++++-------------
 utests/compiler_atomic_functions_20.cpp |  4 +++-
 utests/compiler_device_enqueue.cpp      |  4 +++-
 utests/compiler_generic_atomic.cpp      |  2 ++
 utests/compiler_generic_pointer.cpp     |  2 ++
 utests/compiler_pipe_builtin.cpp        |  9 ++++++---
 utests/compiler_program_global.cpp      |  2 ++
 utests/compiler_sampler.cpp             |  2 ++
 utests/runtime_pipe_query.cpp           |  2 ++
 utests/utest_helper.cpp                 | 22 ++++++++++++++++------
 utests/utest_helper.hpp                 |  4 ++--
 11 files changed, 49 insertions(+), 26 deletions(-)

diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index db61844..43cf7f3 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -289,7 +289,15 @@ set (utests_sources
   compiler_mix.cpp
   compiler_math_3op.cpp
   compiler_bsort.cpp
-  builtin_kernel_block_motion_estimate_intel.cpp)
+  builtin_kernel_block_motion_estimate_intel.cpp
+  compiler_program_global.cpp
+  compiler_generic_atomic.cpp
+  compiler_atomic_functions_20.cpp
+  compiler_sampler.cpp
+  compiler_generic_pointer.cpp
+  runtime_pipe_query.cpp
+  compiler_pipe_builtin.cpp
+  compiler_device_enqueue.cpp)
 
 if (LLVM_VERSION_NODOT VERSION_GREATER 34)
   SET(utests_sources
@@ -297,18 +305,6 @@ if (LLVM_VERSION_NODOT VERSION_GREATER 34)
       compiler_overflow.cpp)
 endif (LLVM_VERSION_NODOT VERSION_GREATER 34)
 
-if (ENABLE_OPENCL_20)
-  SET(utests_sources
-      ${utests_sources}
-      compiler_program_global.cpp
-      compiler_generic_atomic.cpp
-      compiler_atomic_functions_20.cpp
-      compiler_sampler.cpp
-      compiler_generic_pointer.cpp
-      runtime_pipe_query.cpp
-      compiler_pipe_builtin.cpp
-      compiler_device_enqueue.cpp)
-endif (ENABLE_OPENCL_20)
 
 if (NOT_BUILD_STAND_ALONE_UTEST)
   if (X11_FOUND)
diff --git a/utests/compiler_atomic_functions_20.cpp b/utests/compiler_atomic_functions_20.cpp
index ea1ace5..e11d077 100644
--- a/utests/compiler_atomic_functions_20.cpp
+++ b/utests/compiler_atomic_functions_20.cpp
@@ -58,6 +58,8 @@ static void cpu_compiler_atomic(int *dst, int *src)
 
 static void compiler_atomic_functions(const char* kernel_name)
 {
+  if(!cl_check_ocl20(false))
+    return;
   const size_t n = GROUP_NUM * LOCAL_SIZE;
   int cpu_dst[24] = {0}, cpu_src[256];
 
@@ -65,7 +67,7 @@ static void compiler_atomic_functions(const char* kernel_name)
   locals[0] = LOCAL_SIZE;
 
   // Setup kernel and buffers
-  OCL_CREATE_KERNEL_FROM_FILE("compiler_atomic_functions_20", kernel_name);
+  OCL_CALL(cl_kernel_init, "compiler_atomic_functions_20.cl", kernel_name, SOURCE, "-cl-std=CL2.0");
   OCL_CREATE_BUFFER(buf[0], 0, 24 * sizeof(int), NULL);
   OCL_CREATE_BUFFER(buf[1], 0, locals[0] * sizeof(int), NULL);
   OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
diff --git a/utests/compiler_device_enqueue.cpp b/utests/compiler_device_enqueue.cpp
index a9e3e2d..698be4d 100644
--- a/utests/compiler_device_enqueue.cpp
+++ b/utests/compiler_device_enqueue.cpp
@@ -2,12 +2,14 @@
 
 void compiler_device_enqueue(void)
 {
+  if(!cl_check_ocl20(false))
+    return;
   const size_t n = 32;
   const uint32_t global_sz = 3;
   uint32_t result = 0;
 
   // Setup kernel and buffers
-  OCL_CREATE_KERNEL("compiler_device_enqueue");
+  OCL_CALL(cl_kernel_init, "compiler_device_enqueue.cl", "compiler_device_enqueue", SOURCE, "-cl-std=CL2.0");
   OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(uint32_t), NULL);
   OCL_SET_ARG(0, sizeof(uint32_t), &global_sz);
   OCL_SET_ARG(1, sizeof(cl_mem), &buf[0]);
diff --git a/utests/compiler_generic_atomic.cpp b/utests/compiler_generic_atomic.cpp
index 9ed5f53..e35e994 100644
--- a/utests/compiler_generic_atomic.cpp
+++ b/utests/compiler_generic_atomic.cpp
@@ -3,6 +3,8 @@
 template<typename T>
 void test_atomic(const char* kernelName)
 {
+  if(!cl_check_ocl20(false))
+    return;
   const int n = 16;
   T cpu_src[16];
 
diff --git a/utests/compiler_generic_pointer.cpp b/utests/compiler_generic_pointer.cpp
index 5984694..318312a 100644
--- a/utests/compiler_generic_pointer.cpp
+++ b/utests/compiler_generic_pointer.cpp
@@ -3,6 +3,8 @@
 template<typename T>
 void test(const char* kernelName)
 {
+  if(!cl_check_ocl20(false))
+    return;
   const int n = 16;
   T cpu_src[16];
 
diff --git a/utests/compiler_pipe_builtin.cpp b/utests/compiler_pipe_builtin.cpp
index c8ec077..99270d1 100644
--- a/utests/compiler_pipe_builtin.cpp
+++ b/utests/compiler_pipe_builtin.cpp
@@ -8,11 +8,13 @@ typedef struct{
 #define PIPE_BUILTIN(TYPE,GROUP) \
 static void compiler_pipe_##GROUP##_##TYPE(void) \
 { \
+  if(!cl_check_ocl20(false))\
+    return;\
   const size_t w = 16;  \
   uint32_t ans_host = 0;  \
   uint32_t ans_device = 0;  \
   /* pipe write kernel*/  \
-  OCL_CREATE_KERNEL_FROM_FILE("compiler_pipe_builtin", "compiler_pipe_"#GROUP"_write_"#TYPE);  \
+  OCL_CALL(cl_kernel_init, "compiler_pipe_builtin.cl", "compiler_pipe_"#GROUP"_write_"#TYPE, SOURCE, "-cl-std=CL2.0");\
   OCL_CALL2(clCreatePipe, buf[0], ctx, 0, sizeof(TYPE), w, NULL);\
   OCL_CREATE_BUFFER(buf[1], CL_MEM_READ_WRITE, w * sizeof(TYPE), NULL);\
   OCL_MAP_BUFFER(1);\
@@ -26,7 +28,7 @@ static void compiler_pipe_##GROUP##_##TYPE(void) \
   OCL_NDRANGE(1);\
   OCL_CALL(clReleaseKernel, kernel);\
   /* pipe read kernel */\
-  OCL_CREATE_KERNEL_FROM_FILE("compiler_pipe_builtin", "compiler_pipe_"#GROUP"_read_"#TYPE);\
+  OCL_CALL(cl_kernel_init, "compiler_pipe_builtin.cl", "compiler_pipe_"#GROUP"_read_"#TYPE, SOURCE, "-cl-std=CL2.0");\
   OCL_CREATE_BUFFER(buf[2], CL_MEM_READ_WRITE, w * sizeof(TYPE), NULL);\
   OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);\
   OCL_SET_ARG(1, sizeof(cl_mem), &buf[2]);\
@@ -52,8 +54,9 @@ PIPE_BUILTIN(mystruct, workgroup)
 static void compiler_pipe_query(void) {
   const size_t w = 32;
   const size_t sz = 16;
+  if(!cl_check_ocl20(false)){return;}
   /* pipe write kernel */
-  OCL_CREATE_KERNEL_FROM_FILE("compiler_pipe_builtin", "compiler_pipe_query");
+  OCL_CALL(cl_kernel_init, "compiler_pipe_builtin.cl", "compiler_pipe_query", SOURCE, "-cl-std=CL2.0");
   OCL_CALL2(clCreatePipe, buf[0], ctx, 0, sizeof(uint32_t), w, NULL);
   OCL_CREATE_BUFFER(buf[1], CL_MEM_READ_WRITE, sz * sizeof(uint32_t), NULL);
   OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
diff --git a/utests/compiler_program_global.cpp b/utests/compiler_program_global.cpp
index a583c60..caadf8b 100644
--- a/utests/compiler_program_global.cpp
+++ b/utests/compiler_program_global.cpp
@@ -21,6 +21,8 @@ static int init_program(const char* name, cl_context ctx, cl_program *pg )
 
 void compiler_program_global()
 {
+  if(!cl_check_ocl20(false))
+    return;
   const int n = 16;
   cl_int err;
 
diff --git a/utests/compiler_sampler.cpp b/utests/compiler_sampler.cpp
index f8bf622..853e052 100644
--- a/utests/compiler_sampler.cpp
+++ b/utests/compiler_sampler.cpp
@@ -3,6 +3,8 @@
 
 void compiler_sampler(void)
 {
+  if(!cl_check_ocl20(false))
+    return;
   OCL_CREATE_KERNEL("compiler_sampler");
 
   OCL_ASSERT(ctx != 0);
diff --git a/utests/runtime_pipe_query.cpp b/utests/runtime_pipe_query.cpp
index 3ce8258..e46f5ff 100644
--- a/utests/runtime_pipe_query.cpp
+++ b/utests/runtime_pipe_query.cpp
@@ -1,6 +1,8 @@
 #include <string.h>
 #include "utest_helper.hpp"
 static void runtime_pipe_query(void) {
+  if(!cl_check_ocl20(false))
+    return;
   const size_t w = 16;
   const size_t sz = 8;
   cl_uint retnum, retsz;
diff --git a/utests/utest_helper.cpp b/utests/utest_helper.cpp
index b57d2ad..7052a14 100644
--- a/utests/utest_helper.cpp
+++ b/utests/utest_helper.cpp
@@ -939,13 +939,14 @@ int cl_check_subgroups_short(void)
   return 1;
 }
 
-int cl_check_ocl20(void)
+int cl_check_ocl20(bool or_beignet)
 {
   size_t param_value_size;
   size_t ret_sz;
   OCL_CALL(clGetDeviceInfo, device, CL_DEVICE_OPENCL_C_VERSION, 0, 0, &param_value_size);
   if(param_value_size == 0) {
     printf("Not OpenCL 2.0 device, ");
+    if(or_beignet){
     if(cl_check_beignet()) {
       printf("Beignet extension test!");
       return 1;
@@ -953,6 +954,10 @@ int cl_check_ocl20(void)
       printf("Not beignet device , Skip!");
       return 0;
     }
+    }else{
+      printf("Skip!");
+      return 0;
+    }
   }
   char* device_version_str = (char* )malloc(param_value_size * sizeof(char) );
   OCL_CALL(clGetDeviceInfo, device, CL_DEVICE_OPENCL_C_VERSION, param_value_size, (void*)device_version_str, &ret_sz);
@@ -961,11 +966,16 @@ int cl_check_ocl20(void)
   if(!strstr(device_version_str, "2.0")) {
     free(device_version_str);
     printf("Not OpenCL 2.0 device, ");
-    if(cl_check_beignet()) {
-      printf("Beignet extension test!");
-      return 1;
-    } else {
-      printf("Not beignet device , Skip!");
+    if(or_beignet){
+      if(cl_check_beignet()) {
+        printf("Beignet extension test!");
+        return 1;
+      } else {
+        printf("Not beignet device , Skip!");
+        return 0;
+      }
+    }else{
+      printf("Skip!");
       return 0;
     }
   }
diff --git a/utests/utest_helper.hpp b/utests/utest_helper.hpp
index a761325..1bc810c 100644
--- a/utests/utest_helper.hpp
+++ b/utests/utest_helper.hpp
@@ -310,8 +310,8 @@ extern clGetKernelSubGroupInfoKHR_cb* utestclGetKernelSubGroupInfoKHR;
 /* Check if cl_intel_motion_estimation enabled. */
 extern int cl_check_motion_estimation(void);
 
-/* Check is cl version 2.0. */
-extern int cl_check_ocl20(void);
+/* Check is cl version 2.0 or Beignet extension. */
+extern int cl_check_ocl20(bool or_beignet = true);
 
 /* Check is FP16 enabled. */
 extern int cl_check_half(void);
-- 
2.7.4



More information about the Beignet mailing list