[Beignet] [PATCH 13/13] Utest: Add double division test.

junyan.he at inbox.com junyan.he at inbox.com
Fri Sep 18 02:58:24 PDT 2015


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

Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
 kernels/compiler_double_4.cl   |  5 ---
 kernels/compiler_double_div.cl | 11 ++++++
 utests/CMakeLists.txt          |  1 +
 utests/compiler_double_4.cpp   | 40 ---------------------
 utests/compiler_double_div.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 92 insertions(+), 45 deletions(-)
 delete mode 100644 kernels/compiler_double_4.cl
 create mode 100644 kernels/compiler_double_div.cl
 delete mode 100644 utests/compiler_double_4.cpp
 create mode 100644 utests/compiler_double_div.cpp

diff --git a/kernels/compiler_double_4.cl b/kernels/compiler_double_4.cl
deleted file mode 100644
index e5e46f9..0000000
--- a/kernels/compiler_double_4.cl
+++ /dev/null
@@ -1,5 +0,0 @@
-#pragma OPENCL EXTENSION cl_khr_fp64 : enable
-kernel void compiler_double_4(global double *src1, global double *src2, global double *dst) {
-  int i = get_global_id(0);
-  dst[i] = src1[i] + src2[i];
-}
diff --git a/kernels/compiler_double_div.cl b/kernels/compiler_double_div.cl
new file mode 100644
index 0000000..4eada2d
--- /dev/null
+++ b/kernels/compiler_double_div.cl
@@ -0,0 +1,11 @@
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+kernel void compiler_double_div(global double *src1, global double *src2, global double *dst) {
+  int i = get_global_id(0);
+  if (i % 3 != 0)
+    dst[i] = src1[i] / src2[i];
+}
+
+kernel void compiler_double_div_uniform(double src1, double src2, double tmp, global double *dst) {
+  tmp = src1 / src2;
+  dst[0] = tmp;
+}
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index a17ab55..1f89fec 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -195,6 +195,7 @@ set (utests_sources
   compiler_time_stamp.cpp
   compiler_double_precision.cpp
   compiler_double.cpp
+  compiler_double_div.cpp
   load_program_from_gen_bin.cpp
   load_program_from_spir.cpp
   get_arg_info.cpp
diff --git a/utests/compiler_double_4.cpp b/utests/compiler_double_4.cpp
deleted file mode 100644
index cb25bd4..0000000
--- a/utests/compiler_double_4.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-#include <cmath>
-#include "utest_helper.hpp"
-
-void compiler_double_4(void)
-{
-  const size_t n = 16;
-  double cpu_src1[n], cpu_src2[n];
-
-  // Setup kernel and buffers
-  OCL_CREATE_KERNEL("compiler_double_4");
-  OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(double), NULL);
-  OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(double), NULL);
-  OCL_CREATE_BUFFER(buf[2], 0, n * sizeof(double), NULL);
-  OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
-  OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);
-  OCL_SET_ARG(2, sizeof(cl_mem), &buf[2]);
-  globals[0] = n;
-  locals[0] = 16;
-
-  // Run random tests
-  OCL_MAP_BUFFER(0);
-  OCL_MAP_BUFFER(1);
-  for (int32_t i = 0; i < (int32_t) n; ++i) {
-    cpu_src1[i] = ((double*)buf_data[0])[i] = rand() * 1e-2;
-    cpu_src2[i] = ((double*)buf_data[1])[i] = rand() * 1e-2;
-  }
-  OCL_UNMAP_BUFFER(0);
-  OCL_UNMAP_BUFFER(1);
-
-  // Run the kernel on GPU
-  OCL_NDRANGE(1);
-
-  // Compare
-  OCL_MAP_BUFFER(2);
-  for (int32_t i = 0; i < (int32_t) n; ++i)
-    OCL_ASSERT(fabs(((double*)buf_data[2])[i] - cpu_src1[i] - cpu_src2[i]) < 1e-4);
-  OCL_UNMAP_BUFFER(2);
-}
-
-MAKE_UTEST_FROM_FUNCTION(compiler_double_4);
diff --git a/utests/compiler_double_div.cpp b/utests/compiler_double_div.cpp
new file mode 100644
index 0000000..db763e3
--- /dev/null
+++ b/utests/compiler_double_div.cpp
@@ -0,0 +1,80 @@
+#include <cmath>
+#include "utest_helper.hpp"
+
+void compiler_double_div(void)
+{
+  const size_t n = 16;
+  double cpu_src0[n], cpu_src1[n];
+
+  if (!cl_check_double())
+    return;
+
+  // Setup kernel and buffers
+  OCL_CREATE_KERNEL("compiler_double_div");
+  OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(double), NULL);
+  OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(double), NULL);
+  OCL_CREATE_BUFFER(buf[2], 0, n * sizeof(double), NULL);
+  OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+  OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);
+  OCL_SET_ARG(2, sizeof(cl_mem), &buf[2]);
+  globals[0] = n;
+  locals[0] = 16;
+
+  // Run random tests
+  OCL_MAP_BUFFER(0);
+  OCL_MAP_BUFFER(1);
+  for (int32_t i = 0; i < (int32_t) n; ++i) {
+    cpu_src0[i] = ((double*)buf_data[0])[i] = ((double)(((i - 5)*1334) * 11105));
+    cpu_src1[i] = ((double*)buf_data[1])[i] = 499.13542123d*(i + 132.43d + 142.32*i);
+  }
+  OCL_UNMAP_BUFFER(0);
+  OCL_UNMAP_BUFFER(1);
+
+  // Run the kernel on GPU
+  OCL_NDRANGE(1);
+
+  // Compare
+  OCL_MAP_BUFFER(2);
+  for (int32_t i = 0; i < (int32_t) n; ++i) {
+    if (i % 3 != 0)
+      OCL_ASSERT(fabs(((double*)buf_data[2])[i] - cpu_src0[i]/cpu_src1[i]) < 1e-32);
+    else
+      OCL_ASSERT(((double*)buf_data[2])[i] == 0.0d);
+
+    //printf("%d :  %f        ref value: %f\n", i, ((double*)buf_data[2])[i], cpu_src0[i]/cpu_src1[i]);
+  }
+  OCL_UNMAP_BUFFER(2);
+}
+
+MAKE_UTEST_FROM_FUNCTION(compiler_double_div);
+
+void compiler_double_div_uniform(void)
+{
+  double src0 = 13234.1438786319d;
+  double src1 = 0.000134123d;
+  double tmp = 25.128d;
+
+  if (!cl_check_double())
+    return;
+
+  // Setup kernel and buffers
+  OCL_CREATE_KERNEL_FROM_FILE("compiler_double_div", "compiler_double_div_uniform");
+  OCL_CREATE_BUFFER(buf[0], 0, sizeof(double), NULL);
+  OCL_SET_ARG(0, sizeof(double), &src0);
+  OCL_SET_ARG(1, sizeof(double), &src1);
+  OCL_SET_ARG(2, sizeof(double), &tmp);
+  OCL_SET_ARG(3, sizeof(cl_mem), &buf[0]);
+  globals[0] = 16;
+  locals[0] = 16;
+
+  // Run the kernel on GPU
+  OCL_NDRANGE(1);
+
+  // Compare
+  OCL_MAP_BUFFER(0);
+  OCL_ASSERT(fabs(((double*)buf_data[0])[0] - src0/src1) < 1e-32);
+  //printf("%f        ref value: %f\n", ((double*)buf_data[0])[0], src0/src1);
+  OCL_UNMAP_BUFFER(0);
+}
+
+MAKE_UTEST_FROM_FUNCTION(compiler_double_div_uniform);
-- 
1.9.1





More information about the Beignet mailing list