[Beignet] [V3 PATCH 12/13] Utests: Add double check and refine compiler_double case.

junyan.he at inbox.com junyan.he at inbox.com
Tue Oct 20 03:55:55 PDT 2015


From: Junyan He <junyan.he at linux.intel.com>

Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
 utests/CMakeLists.txt      |  2 ++
 utests/compiler_double.cpp |  5 ++++-
 utests/utest_helper.cpp    | 19 +++++++++++++++++++
 utests/utest_helper.hpp    |  3 +++
 4 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index 2f1e10f..3f30933 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -193,6 +193,8 @@ set (utests_sources
   compiler_sub_group_any.cpp
   compiler_sub_group_all.cpp
   compiler_time_stamp.cpp
+  compiler_double_precision.cpp
+  compiler_double.cpp
   load_program_from_gen_bin.cpp
   load_program_from_spir.cpp
   get_arg_info.cpp
diff --git a/utests/compiler_double.cpp b/utests/compiler_double.cpp
index 7c54ddf..fc89a0f 100644
--- a/utests/compiler_double.cpp
+++ b/utests/compiler_double.cpp
@@ -12,6 +12,9 @@ void compiler_double(void)
   const size_t n = 16;
   double cpu_dst[n], cpu_src[n];
 
+  if (!cl_check_double())
+    return;
+
   // Setup kernel and buffers
   OCL_CREATE_KERNEL("compiler_double");
   OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(double), NULL);
@@ -38,7 +41,7 @@ void compiler_double(void)
     // Compare
     OCL_MAP_BUFFER(1);
     for (int32_t i = 0; i < (int32_t) n; ++i)
-      OCL_ASSERT(fabs(((double*)buf_data[1])[i] - cpu_dst[i]) < 1e-4);
+      OCL_ASSERT(fabs(((double*)buf_data[1])[i] - cpu_dst[i]) < 1e-32);
     OCL_UNMAP_BUFFER(1);
   }
 }
diff --git a/utests/utest_helper.cpp b/utests/utest_helper.cpp
index 664046c..46ba71f 100644
--- a/utests/utest_helper.cpp
+++ b/utests/utest_helper.cpp
@@ -823,3 +823,22 @@ float select_ulpsize(float ULPSIZE_FAST_MATH, float ULPSIZE_NO_FAST_MATH)
 
   return ULPSIZE_FACTOR;
 }
+
+int cl_check_double(void)
+{
+  std::string extStr;
+  size_t param_value_size;
+  OCL_CALL(clGetDeviceInfo, device, CL_DEVICE_EXTENSIONS, 0, 0, &param_value_size);
+  std::vector<char> param_value(param_value_size);
+  OCL_CALL(clGetDeviceInfo, device, CL_DEVICE_EXTENSIONS, param_value_size,
+           param_value.empty() ? NULL : &param_value.front(), &param_value_size);
+  if (!param_value.empty())
+    extStr = std::string(&param_value.front(), param_value_size-1);
+
+  if (std::strstr(extStr.c_str(), "cl_khr_fp64") == NULL) {
+    printf("No cl_khr_fp64, Skip!");
+    return 0;
+  }
+
+  return 1;
+}
diff --git a/utests/utest_helper.hpp b/utests/utest_helper.hpp
index e6c8515..c1c761e 100644
--- a/utests/utest_helper.hpp
+++ b/utests/utest_helper.hpp
@@ -241,5 +241,8 @@ double time_subtract(struct timeval *y, struct timeval *x, struct timeval *resul
 /* check ulpsize */
 float select_ulpsize(float ULPSIZE_FAST_MATH, float ULPSIZE_NO_FAST_MATH);
 
+/* Check is FP64 enabled. */
+extern int cl_check_double(void);
+
 #endif /* __UTEST_HELPER_HPP__ */
 
-- 
1.9.1





More information about the Beignet mailing list