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

Homer Hsing homer.xing at intel.com
Sun Jun 16 19:43:53 PDT 2013


Signed-off-by: Homer Hsing <homer.xing at intel.com>
---
 kernels/compiler_double.cl   |  7 +++++++
 kernels/compiler_double_2.cl |  7 +++++++
 utests/CMakeLists.txt        |  2 ++
 utests/compiler_double.cpp   | 46 +++++++++++++++++++++++++++++++++++++++++++
 utests/compiler_double_2.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 109 insertions(+)
 create mode 100644 kernels/compiler_double.cl
 create mode 100644 kernels/compiler_double_2.cl
 create mode 100644 utests/compiler_double.cpp
 create mode 100644 utests/compiler_double_2.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/kernels/compiler_double_2.cl b/kernels/compiler_double_2.cl
new file mode 100644
index 0000000..1d74a4e
--- /dev/null
+++ b/kernels/compiler_double_2.cl
@@ -0,0 +1,7 @@
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+kernel void compiler_double_2(global float *src, global double *dst) {
+  int i = get_global_id(0);
+  float d = 1.234567890123456789f;
+  dst[i] = d * (d + src[i]);
+}
+
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index 56685b0..cd84570 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -27,6 +27,8 @@ set (utests_sources
   compiler_copy_image.cpp
   compiler_copy_image_3d.cpp
   compiler_copy_buffer_row.cpp
+  compiler_double.cpp
+  compiler_double_2.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..9a52193
--- /dev/null
+++ b/utests/compiler_double.cpp
@@ -0,0 +1,46 @@
+#include <cmath>
+#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(fabs(((double*)buf_data[1])[i] - cpu_dst[i]) < 1e-4);
+    OCL_UNMAP_BUFFER(1);
+  }
+}
+
+MAKE_UTEST_FROM_FUNCTION(compiler_double);
diff --git a/utests/compiler_double_2.cpp b/utests/compiler_double_2.cpp
new file mode 100644
index 0000000..8c30443
--- /dev/null
+++ b/utests/compiler_double_2.cpp
@@ -0,0 +1,47 @@
+#include <cmath>
+#include "utest_helper.hpp"
+
+static void cpu(int global_id, float *src, double *dst) {
+  float f = src[global_id];
+  float d = 1.234567890123456789;
+  dst[global_id] = d * (d + f);
+}
+
+void compiler_double_2(void)
+{
+  const size_t n = 16;
+  float cpu_src[n];
+  double cpu_dst[n];
+
+  // Setup kernel and buffers
+  OCL_CREATE_KERNEL("compiler_double_2");
+  OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(float), 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] = ((float*)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(fabs(((double*)buf_data[1])[i] - cpu_dst[i]) < 1e-4);
+    OCL_UNMAP_BUFFER(1);
+  }
+}
+
+MAKE_UTEST_FROM_FUNCTION(compiler_double_2);
-- 
1.8.1.2



More information about the Beignet mailing list