From 9c53a0db19c8a113329d924cf6c02ce4759c4113 Mon Sep 17 00:00:00 2001 From: Yi Sun Date: Mon, 9 Sep 2013 16:55:47 +0800 Subject: [PATCH] utest: Add test case for built-in function pow. Signed-off-by: Yi Sun Reviewed-by: Zhigang Gong --- kernels/builtin_pow.cl | 7 ++++ utests/CMakeLists.txt | 1 + utests/builtin_pow.cpp | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 kernels/builtin_pow.cl create mode 100644 utests/builtin_pow.cpp diff --git a/kernels/builtin_pow.cl b/kernels/builtin_pow.cl new file mode 100644 index 0000000..17d753e --- /dev/null +++ b/kernels/builtin_pow.cl @@ -0,0 +1,7 @@ +kernel void builtin_pow(global float *dst, global float *src1, global float *src2, global int *max_func) { + + int i = get_global_id(0); + dst[i * (*max_func) + 0] = pow(src1[i], src2[i]); + dst[i * (*max_func) + 1] = src1[i]; + +} diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt index 37240fe..b619d52 100644 --- a/utests/CMakeLists.txt +++ b/utests/CMakeLists.txt @@ -129,6 +129,7 @@ set (utests_sources builtin_num_groups.cpp builtin_local_id.cpp builtin_acos_asin.cpp + builtin_pow.cpp builtin_convert_sat.cpp runtime_createcontext.cpp runtime_null_kernel_arg.cpp diff --git a/utests/builtin_pow.cpp b/utests/builtin_pow.cpp new file mode 100644 index 0000000..8ed17ed --- /dev/null +++ b/utests/builtin_pow.cpp @@ -0,0 +1,92 @@ +#include "utest_helper.hpp" +#include +#include + +#define udebug 0 +#define printf_c(...) \ +{\ + printf("\033[1m\033[40;31m");\ + printf( __VA_ARGS__ );\ + printf("\033[0m");\ +} +const float ori_data[] = {-20.5, -1, -0.9, -0.01, 0, 0.01, 0.9, 1.0, 20.5}; +const int count_input_ori = sizeof(ori_data) / sizeof(ori_data[0]); +const int count_input = count_input_ori * count_input_ori; + +float input_data1[count_input]; +float input_data2[count_input]; +const int max_function = 1; + +static void cpu_compiler_math(const float *src1, const float *src2, float *dst) +{ + dst[0] = powf(src1[0], src2[0]); +// dst[1] = src1[0]; +} + +static void builtin_pow(void) +{ + // Setup kernel and buffers + int k, i, index_cur; + float gpu_data[max_function * count_input] = {0}, cpu_data[max_function * count_input] = {0}; + + for(i=0; i 1e-5f) ) + { + printf_c("%d/%d: x:%f, y:%f -> gpu:%f cpu:%f\n", k, i, input_data1[k], input_data2[k], gpu_data[index_cur], cpu_data[index_cur]); + } + else + printf("%d/%d: x:%f, y:%f -> gpu:%f cpu:%f\n", k, i, input_data1[k], input_data2[k], gpu_data[index_cur], cpu_data[index_cur]); +#else + if (isinf(cpu_data[index_cur])) + OCL_ASSERT(isinf(gpu_data[index_cur])); + else if (isnan(cpu_data[index_cur])) + OCL_ASSERT(isnan(gpu_data[index_cur])); + else + { + OCL_ASSERT(fabs(gpu_data[index_cur] - cpu_data[index_cur]) < 1e-3f); + } +#endif + } + } +} + +MAKE_UTEST_FROM_FUNCTION_WITH_ISSUE(builtin_pow) -- 2.7.4