[Beignet] [PATCH 10/10 OpenCL-2.0] Add test case for work group reduce min.
junyan.he at inbox.com
junyan.he at inbox.com
Wed Apr 22 20:26:51 PDT 2015
From: Junyan He <junyan.he at linux.intel.com>
Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
kernels/compiler_workgroup_reduce.cl | 5 ++++
utests/CMakeLists.txt | 1 +
utests/compiler_workgroup_reduce.cpp | 44 ++++++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+)
create mode 100644 kernels/compiler_workgroup_reduce.cl
create mode 100644 utests/compiler_workgroup_reduce.cpp
diff --git a/kernels/compiler_workgroup_reduce.cl b/kernels/compiler_workgroup_reduce.cl
new file mode 100644
index 0000000..89d30f1
--- /dev/null
+++ b/kernels/compiler_workgroup_reduce.cl
@@ -0,0 +1,5 @@
+kernel void compiler_workgroup_reduce(global uint *src, global uint *dst) {
+ uint val = src[get_local_id(0)];
+ uint min_val = work_group_reduce_min(val);
+ dst[get_local_id(0)] = min_val;
+}
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index 93cbffa..559dafa 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -118,6 +118,7 @@ set (utests_sources
compiler_atomic_functions.cpp
compiler_async_copy.cpp
compiler_workgroup_broadcast.cpp
+ compiler_workgroup_reduce.cpp
compiler_async_stride_copy.cpp
compiler_insn_selection_min.cpp
compiler_insn_selection_max.cpp
diff --git a/utests/compiler_workgroup_reduce.cpp b/utests/compiler_workgroup_reduce.cpp
new file mode 100644
index 0000000..628b439
--- /dev/null
+++ b/utests/compiler_workgroup_reduce.cpp
@@ -0,0 +1,44 @@
+#include <cstdint>
+#include <cstring>
+#include <iostream>
+#include "utest_helper.hpp"
+
+static uint32_t test_array[64] = {23, 34, 12, 91, 5, 133, 7787, 134, 987, 9853, 33, 21, 865, 1441, 9083, 812,
+ 12, 43435, 63, 44545, 253, 65, 24, 30, 76, 989, 120 ,113 ,12, 41, 18, 91,
+ 8321, 6712, 881, 911, 5, 788, 8991, 88, 19, 1110, 1231, 1341, 1983, 1983, 91, 212,
+ 712, 31, 881, 963, 6801, 651, 9810, 77, 98, 13, 16, 1888, 141, 1613, 1771, 16};
+
+void compiler_workgroup_reduce(void)
+{
+ const size_t n = 64;
+ uint32_t* src = test_array;
+
+ // Setup kernel and buffers
+ OCL_CREATE_KERNEL("compiler_workgroup_reduce");
+ OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(uint32_t), NULL);
+ OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(uint32_t), NULL);
+ OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+ OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);
+ globals[0] = n;
+ locals[0] = n;
+
+// for (int32_t i = 0; i < (int32_t) n; ++i) {
+// src[i] = n - i;
+// }
+ OCL_MAP_BUFFER(0);
+ memcpy(buf_data[0], src, n * sizeof(uint32_t));
+ OCL_UNMAP_BUFFER(0);
+
+ // Run the kernel on GPU
+ OCL_NDRANGE(1);
+
+ // Compare
+ OCL_MAP_BUFFER(1);
+ for (int32_t i = 0; i < (int32_t) n; ++i) {
+ //printf("%u ", ((uint32_t *)buf_data[1])[i]);
+ OCL_ASSERT(((uint32_t *)buf_data[1])[i] == 5);
+ }
+ OCL_UNMAP_BUFFER(1);
+}
+
+MAKE_UTEST_FROM_FUNCTION(compiler_workgroup_reduce);
--
1.7.9.5
More information about the Beignet
mailing list