[Beignet] [PATCH] add utest function bswap.
xionghu.luo at intel.com
xionghu.luo at intel.com
Wed Oct 29 20:54:07 PDT 2014
From: Luo Xionghu <xionghu.luo at intel.com>
Signed-off-by: Luo Xionghu <xionghu.luo at intel.com>
---
kernels/compiler_bswap.cl | 7 +++++++
utests/CMakeLists.txt | 1 +
utests/compiler_bswap.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 52 insertions(+)
create mode 100644 kernels/compiler_bswap.cl
create mode 100644 utests/compiler_bswap.cpp
diff --git a/kernels/compiler_bswap.cl b/kernels/compiler_bswap.cl
new file mode 100644
index 0000000..d6ed91a
--- /dev/null
+++ b/kernels/compiler_bswap.cl
@@ -0,0 +1,7 @@
+kernel void compiler_bswap_short(global short* src, global short* dst){
+ dst[get_global_id(0)]= __builtin_bswap16(src[get_global_id(0)]);
+}
+
+kernel void compiler_bswap_int(global int* src, global int* dst){
+ dst[get_global_id(0)]= __builtin_bswap32(src[get_global_id(0)]);
+}
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index bd1c65f..872fd7f 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -105,6 +105,7 @@ set (utests_sources
compiler_write_only_shorts.cpp
compiler_switch.cpp
compiler_overflow.cpp
+ compiler_bswap.cpp
compiler_math.cpp
compiler_atomic_functions.cpp
compiler_async_copy.cpp
diff --git a/utests/compiler_bswap.cpp b/utests/compiler_bswap.cpp
new file mode 100644
index 0000000..2a70c36
--- /dev/null
+++ b/utests/compiler_bswap.cpp
@@ -0,0 +1,44 @@
+#include "utest_helper.hpp"
+
+namespace {
+
+template<typename T>
+void test(const char *kernel_name)
+{
+ const size_t n = 16;
+
+ // Setup kernel and buffers
+ OCL_CREATE_KERNEL_FROM_FILE("compiler_bswap", kernel_name);
+ OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(T), NULL);
+ OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(T), NULL);
+ OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+ OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);
+
+ OCL_MAP_BUFFER(0);
+ for (uint32_t i = 0; i < n; ++i) {
+ ((T*)buf_data[0])[i] = 0x1234;
+ }
+ OCL_UNMAP_BUFFER(0);
+
+ globals[0] = n;
+ locals[0] = 16;
+ OCL_NDRANGE(1);
+
+ OCL_MAP_BUFFER(1);
+ for (uint32_t i = 0; i < 16; ++i) {
+ OCL_ASSERT(((T*)buf_data[1])[i] == 0x3412);
+ }
+ OCL_UNMAP_BUFFER(1);
+}
+
+}
+
+#define compiler_bswap(type, kernel) \
+static void compiler_bswap_ ##type(void)\
+{\
+ test<type>(# kernel);\
+}\
+MAKE_UTEST_FROM_FUNCTION(compiler_bswap_ ## type);
+
+compiler_bswap(short, compiler_bswap_short)
+compiler_bswap(int, compiler_bswap_int)
--
1.7.9.5
More information about the Beignet
mailing list