[Beignet] [PATCH 2/2] test cases for "mul24", "mad24"

Homer Hsing homer.xing at intel.com
Wed Jul 3 20:19:02 PDT 2013


Signed-off-by: Homer Hsing <homer.xing at intel.com>
---
 kernels/compiler_mad24.cl |  4 ++++
 kernels/compiler_mul24.cl |  4 ++++
 utests/CMakeLists.txt     |  2 ++
 utests/compiler_mad24.cpp | 41 +++++++++++++++++++++++++++++++++++++++++
 utests/compiler_mul24.cpp | 36 ++++++++++++++++++++++++++++++++++++
 5 files changed, 87 insertions(+)
 create mode 100644 kernels/compiler_mad24.cl
 create mode 100644 kernels/compiler_mul24.cl
 create mode 100644 utests/compiler_mad24.cpp
 create mode 100644 utests/compiler_mul24.cpp

diff --git a/kernels/compiler_mad24.cl b/kernels/compiler_mad24.cl
new file mode 100644
index 0000000..04bb2c5
--- /dev/null
+++ b/kernels/compiler_mad24.cl
@@ -0,0 +1,4 @@
+kernel void compiler_mad24(global int *src1, global int *src2, global int *src3, global int *dst) {
+  int i = get_global_id(0);
+  dst[i] = mad24(src1[i], src2[i], src3[i]);
+}
diff --git a/kernels/compiler_mul24.cl b/kernels/compiler_mul24.cl
new file mode 100644
index 0000000..b69dda0
--- /dev/null
+++ b/kernels/compiler_mul24.cl
@@ -0,0 +1,4 @@
+kernel void compiler_mul24(global int *src1, global int *src2, global int *dst) {
+  int i = get_global_id(0);
+  dst[i] = mul24(src1[i], src2[i]);
+}
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index 0863071..56189f9 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -55,6 +55,8 @@ set (utests_sources
   compiler_lower_return2.cpp
   compiler_mad_hi.cpp
   compiler_mul_hi.cpp
+  compiler_mad24.cpp
+  compiler_mul24.cpp
   compiler_multiple_kernels.cpp
   compiler_rhadd.cpp
   compiler_rotate.cpp
diff --git a/utests/compiler_mad24.cpp b/utests/compiler_mad24.cpp
new file mode 100644
index 0000000..a3890a1
--- /dev/null
+++ b/utests/compiler_mad24.cpp
@@ -0,0 +1,41 @@
+#include "utest_helper.hpp"
+
+void compiler_mad24(void)
+{
+  const int n = 32;
+  int src1[n], src2[n], src3[n];
+
+  // Setup kernel and buffers
+  OCL_CREATE_KERNEL("compiler_mad24");
+  OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(int), NULL);
+  OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(int), NULL);
+  OCL_CREATE_BUFFER(buf[2], 0, n * sizeof(int), NULL);
+  OCL_CREATE_BUFFER(buf[3], 0, n * sizeof(int), 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]);
+  OCL_SET_ARG(3, sizeof(cl_mem), &buf[3]);
+  globals[0] = n;
+  locals[0] = 16;
+
+  OCL_MAP_BUFFER(0);
+  OCL_MAP_BUFFER(1);
+  OCL_MAP_BUFFER(2);
+  for (int i = 0; i < n; ++i) {
+    src1[i] = ((int*)buf_data[0])[i] = rand();
+    src2[i] = ((int*)buf_data[1])[i] = rand();
+    src3[i] = ((int*)buf_data[2])[i] = rand();
+  }
+  OCL_UNMAP_BUFFER(0);
+  OCL_UNMAP_BUFFER(1);
+  OCL_UNMAP_BUFFER(2);
+
+  OCL_NDRANGE(1);
+
+  OCL_MAP_BUFFER(3);
+  for (int i = 0; i < n; ++i)
+    OCL_ASSERT(((int*)buf_data[3])[i] == ((src1[i] << 8) >> 8) * ((src2[i] << 8) >> 8) + src3[i]);
+  OCL_UNMAP_BUFFER(3);
+}
+
+MAKE_UTEST_FROM_FUNCTION(compiler_mad24);
diff --git a/utests/compiler_mul24.cpp b/utests/compiler_mul24.cpp
new file mode 100644
index 0000000..8a36947
--- /dev/null
+++ b/utests/compiler_mul24.cpp
@@ -0,0 +1,36 @@
+#include "utest_helper.hpp"
+
+void compiler_mul24(void)
+{
+  const int n = 32;
+  int src1[n], src2[n];
+
+  // Setup kernel and buffers
+  OCL_CREATE_KERNEL("compiler_mul24");
+  OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(int), NULL);
+  OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(int), NULL);
+  OCL_CREATE_BUFFER(buf[2], 0, n * sizeof(int), 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;
+
+  OCL_MAP_BUFFER(0);
+  OCL_MAP_BUFFER(1);
+  for (int i = 0; i < n; ++i) {
+    src1[i] = ((int*)buf_data[0])[i] = rand();
+    src2[i] = ((int*)buf_data[1])[i] = rand();
+  }
+  OCL_UNMAP_BUFFER(0);
+  OCL_UNMAP_BUFFER(1);
+
+  OCL_NDRANGE(1);
+
+  OCL_MAP_BUFFER(2);
+  for (int i = 0; i < n; ++i)
+    OCL_ASSERT(((int*)buf_data[2])[i] == ((src1[i] << 8) >> 8) * ((src2[i] << 8) >> 8));
+  OCL_UNMAP_BUFFER(2);
+}
+
+MAKE_UTEST_FROM_FUNCTION(compiler_mul24);
-- 
1.8.1.2



More information about the Beignet mailing list