#include "utest_helper.hpp" #include #include #include #define udebug 0 #define printf_c(...) \ {\ printf("\033[1m\033[40;31m");\ printf( __VA_ARGS__ );\ printf("\033[0m");\ } namespace { 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 = 2; // builtin_pow.cl has 2 outputs: pow(src1,src2) and src1 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 ULPSIZE_NO_FAST_MATH = 16.0; float gpu_data[max_function * count_input] = {0}, cpu_data[max_function * count_input] = {0}; for(i=0; i cl_FLT_ULP(cpu_data[index_cur]) * ULPSIZE_FACTOR && (denormals_supported || gpu_data[index_cur]!=0 || std::fpclassify(cpu_data[index_cur])!=FP_SUBNORMAL) ) ) { 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 (std::isinf(cpu_data[index_cur])) OCL_ASSERT(std::isinf(gpu_data[index_cur])); else if (std::isnan(cpu_data[index_cur])) OCL_ASSERT(std::isnan(gpu_data[index_cur])); else { OCL_ASSERT((fabs(gpu_data[index_cur] - cpu_data[index_cur]) < cl_FLT_ULP(cpu_data[index_cur]) * ULPSIZE_FACTOR) || (!denormals_supported && gpu_data[index_cur]==0 && std::fpclassify(cpu_data[index_cur])==FP_SUBNORMAL) ); } #endif } } } MAKE_UTEST_FROM_FUNCTION(builtin_pow) }