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

junyan.he at inbox.com junyan.he at inbox.com
Tue Sep 15 04:15:27 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 |  5 +++++
 utests/CMakeLists.txt          |  1 +
 utests/compiler_double_4.cpp   | 40 ----------------------------------------
 utests/compiler_double_div.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 48 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..3758e65
--- /dev/null
+++ b/kernels/compiler_double_div.cl
@@ -0,0 +1,5 @@
+#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);
+  dst[i] = src1[i] / src2[i];
+}
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index e7a9e26..aeae3d6 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -194,6 +194,7 @@ set (utests_sources
   compiler_sub_group_all.cpp
   compiler_time_stamp.cpp
   compiler_double_precision.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..f3a21df
--- /dev/null
+++ b/utests/compiler_double_div.cpp
@@ -0,0 +1,42 @@
+#include <cmath>
+#include "utest_helper.hpp"
+
+void compiler_double_div(void)
+{
+  const size_t n = 16;
+  double cpu_src0[n], cpu_src1[n];
+
+  // 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) {
+    OCL_ASSERT(fabs(((double*)buf_data[2])[i] - cpu_src0[i]/cpu_src1[i]) < 1e-32);
+    //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);
-- 
1.9.1





More information about the Beignet mailing list