[Beignet] [PATCH V3 2/2] test case for 64-bit float

Homer Hsing homer.xing at intel.com
Thu Jun 6 19:03:09 PDT 2013


Signed-off-by: Homer Hsing <homer.xing at intel.com>
---
 kernels/compiler_double.cl |  7 +++++++
 utests/CMakeLists.txt      |  1 +
 utests/compiler_double.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+)
 create mode 100644 kernels/compiler_double.cl
 create mode 100644 utests/compiler_double.cpp

diff --git a/kernels/compiler_double.cl b/kernels/compiler_double.cl
new file mode 100644
index 0000000..7fa8231
--- /dev/null
+++ b/kernels/compiler_double.cl
@@ -0,0 +1,7 @@
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+kernel void compiler_double(global double *src, global double *dst) {
+  int i = get_global_id(0);
+  double d = 1.234567890123456789;
+  dst[i] = d * (src[i] + d);
+}
+
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index 56685b0..63fef84 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -27,6 +27,7 @@ set (utests_sources
   compiler_copy_image.cpp
   compiler_copy_image_3d.cpp
   compiler_copy_buffer_row.cpp
+  compiler_double.cpp
   compiler_fabs.cpp
   compiler_fill_image.cpp
   compiler_fill_image0.cpp
diff --git a/utests/compiler_double.cpp b/utests/compiler_double.cpp
new file mode 100644
index 0000000..8ac7948
--- /dev/null
+++ b/utests/compiler_double.cpp
@@ -0,0 +1,45 @@
+#include "utest_helper.hpp"
+
+static void cpu(int global_id, double *src, double *dst) {
+  double f = src[global_id];
+  double d = 1.234567890123456789;
+  dst[global_id] = d * (f + d);
+}
+
+void compiler_double(void)
+{
+  const size_t n = 16;
+  double cpu_dst[n], cpu_src[n];
+
+  // Setup kernel and buffers
+  OCL_CREATE_KERNEL("compiler_double");
+  OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(double), NULL);
+  OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(double), NULL);
+  OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+  OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);
+  globals[0] = n;
+  locals[0] = 16;
+
+  // Run random tests
+  for (uint32_t pass = 0; pass < 1; ++pass) {
+    OCL_MAP_BUFFER(0);
+    for (int32_t i = 0; i < (int32_t) n; ++i)
+      cpu_src[i] = ((double*)buf_data[0])[i] = .1f * (rand() & 15) - .75f;
+    OCL_UNMAP_BUFFER(0);
+
+    // Run the kernel on GPU
+    OCL_NDRANGE(1);
+
+    // Run on CPU
+    for (int32_t i = 0; i < (int32_t) n; ++i)
+      cpu(i, cpu_src, cpu_dst);
+
+    // Compare
+    OCL_MAP_BUFFER(1);
+    for (int32_t i = 0; i < (int32_t) n; ++i)
+      OCL_ASSERT(((double*)buf_data[1])[i] == cpu_dst[i]);
+    OCL_UNMAP_BUFFER(1);
+  }
+}
+
+MAKE_UTEST_FROM_FUNCTION(compiler_double);
-- 
1.8.1.2



More information about the Beignet mailing list