From: Homer Hsing Date: Thu, 27 Jun 2013 02:58:16 +0000 (+0800) Subject: test case for function "rotate" X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=39b63774f847f477c8637896e00008c591cbc4cd;p=contrib%2Fbeignet.git test case for function "rotate" Signed-off-by: Homer Hsing Reviewed-by: He Junyan Reviewed-by: Song, Ruiling --- diff --git a/kernels/compiler_rotate.cl b/kernels/compiler_rotate.cl new file mode 100644 index 0000000..8d0dd0f --- /dev/null +++ b/kernels/compiler_rotate.cl @@ -0,0 +1,5 @@ +kernel void compiler_rotate(global int *src, global int *dst, global int *y) { + int i = get_global_id(0); + dst[i] = rotate(src[i], y[i]); +} + diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt index fa36277..c0908ea 100644 --- a/utests/CMakeLists.txt +++ b/utests/CMakeLists.txt @@ -54,6 +54,7 @@ set (utests_sources compiler_lower_return1.cpp compiler_lower_return2.cpp compiler_multiple_kernels.cpp + compiler_rotate.cpp compiler_saturate.cpp compiler_saturate_sub.cpp compiler_shift_right.cpp diff --git a/utests/compiler_rotate.cpp b/utests/compiler_rotate.cpp new file mode 100644 index 0000000..bf52ca4 --- /dev/null +++ b/utests/compiler_rotate.cpp @@ -0,0 +1,40 @@ +#include "utest_helper.hpp" + +int cpu(int src, int y) { + return (src << y) | (src >> (32 - y)); +} + +void compiler_rotate(void) +{ + const int n = 32; + int src[n], y[n]; + + // Setup kernel and buffers + OCL_CREATE_KERNEL("compiler_rotate"); + 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(2); + for (int i = 0; i < n; ++i) { + src[i] = ((int*)buf_data[0])[i] = rand(); + y[i] = ((int*)buf_data[2])[i] = rand() & 31; + } + OCL_UNMAP_BUFFER(0); + OCL_UNMAP_BUFFER(2); + + OCL_NDRANGE(1); + + OCL_MAP_BUFFER(1); + for (int i = 0; i < n; ++i) + OCL_ASSERT(((int*)buf_data[1])[i] == cpu(src[i], y[i])); + OCL_UNMAP_BUFFER(1); +} + +MAKE_UTEST_FROM_FUNCTION(compiler_rotate);