Utest: Add check for OpenCL 2.0 extension

Submitted by Pan Xiuli on July 19, 2016, 2:55 a.m.

Details

Message ID 1468896932-26479-1-git-send-email-xiuli.pan@intel.com
State New
Headers show
Series "Utest: Add check for OpenCL 2.0 extension" ( rev: 1 ) in Beignet

Not browsing as part of any series.

Commit Message

Pan Xiuli July 19, 2016, 2:55 a.m.
From: Pan Xiuli <xiuli.pan@intel.com>

Beignet has some opencl2.0 builtin functions, add check for OpenCL 2.0
or Beignet for these test cases.

Signed-off-by: Pan Xiuli <xiuli.pan@intel.com>
---
 utests/builtin_global_linear_id.cpp |  2 ++
 utests/builtin_local_linear_id.cpp  |  2 ++
 utests/utest_helper.cpp             | 29 +++++++++++++++++++++++++++++
 utests/utest_helper.hpp             |  3 +++
 4 files changed, 36 insertions(+)

Patch hide | download patch | download mbox

diff --git a/utests/builtin_global_linear_id.cpp b/utests/builtin_global_linear_id.cpp
index 06807c2..cda7e84 100644
--- a/utests/builtin_global_linear_id.cpp
+++ b/utests/builtin_global_linear_id.cpp
@@ -29,6 +29,8 @@  dimension:3
 #include "utest_helper.hpp"
 static void builtin_global_linear_id(void)
 {
+  if (!cl_check_ocl20())
+    return;
 
   // Setup kernel and buffers
   int dim, err, i, buf_len=1;
diff --git a/utests/builtin_local_linear_id.cpp b/utests/builtin_local_linear_id.cpp
index 8d706d0..88cb357 100644
--- a/utests/builtin_local_linear_id.cpp
+++ b/utests/builtin_local_linear_id.cpp
@@ -30,6 +30,8 @@  dimension:3
 #include "utest_helper.hpp"
 static void builtin_local_linear_id(void)
 {
+  if (!cl_check_ocl20())
+    return;
 
   // Setup kernel and buffers
   int dim, i, buf_len=1;
diff --git a/utests/utest_helper.cpp b/utests/utest_helper.cpp
index 0ecbea3..da4cfbf 100644
--- a/utests/utest_helper.cpp
+++ b/utests/utest_helper.cpp
@@ -896,3 +896,32 @@  int cl_check_subgroups(void)
   return 1;
 }
 
+int cl_check_ocl20(void)
+{
+  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(cl_check_beignet()) {
+      printf("Beignet extension test!");
+      return 1;
+    }
+    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);
+  OCL_ASSERT(ret_sz == param_value_size);
+
+  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;
+    }
+    return 0;
+  }
+  free(device_version_str);
+  return 1;
+}
diff --git a/utests/utest_helper.hpp b/utests/utest_helper.hpp
index 7d05056..421e356 100644
--- a/utests/utest_helper.hpp
+++ b/utests/utest_helper.hpp
@@ -296,4 +296,7 @@  typedef cl_int(clGetKernelSubGroupInfoKHR_cb)(cl_kernel, cl_device_id,
                                               const void *, size_t, void *,
                                               size_t *);
 extern clGetKernelSubGroupInfoKHR_cb* utestclGetKernelSubGroupInfoKHR;
+
+/* Check is cl version 2.0. */
+extern int cl_check_ocl20(void);
 #endif /* __UTEST_HELPER_HPP__ */