summaryrefslogtreecommitdiff
path: root/utests/builtin_tgamma.cpp
diff options
context:
space:
mode:
authorRebecca N. Palmer <rebecca_palmer@zoho.com>2015-04-29 16:25:47 +0100
committerZhigang Gong <zhigang.gong@intel.com>2015-04-30 10:31:55 +0800
commitb54e684ee459639fb7b24fc72c9fe0497f45ce35 (patch)
tree7349db830b79c736f1afcf7b857c2e74b6a9b65d /utests/builtin_tgamma.cpp
parent2b0208daa72e271a7b6c7374a6ae744075259d13 (diff)
downloadbeignet-b54e684ee459639fb7b24fc72c9fe0497f45ce35.tar.gz
utests: fix test case builtin_tgamma.
Compare with tgamma instead of tgammaf for better accuracy. Include negative inputs, and handle the resulting denormals. Print maximum error found. Signed-off-by: Rebecca Palmer <rebecca_palmer@zoho.com> Reviewed-by: "Song, Ruiling" <ruiling.song@intel.com> Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
Diffstat (limited to 'utests/builtin_tgamma.cpp')
-rw-r--r--utests/builtin_tgamma.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/utests/builtin_tgamma.cpp b/utests/builtin_tgamma.cpp
index 47cc5f42..b7db69b0 100644
--- a/utests/builtin_tgamma.cpp
+++ b/utests/builtin_tgamma.cpp
@@ -20,10 +20,15 @@ void builtin_tgamma(void)
if (env_strict == NULL || strcmp(env_strict, "0") == 0)
ULPSIZE_FACTOR = 10000.;
- for (int j = 0; j < 1024; j ++) {
+ cl_device_fp_config fp_config;
+ clGetDeviceInfo(device, CL_DEVICE_SINGLE_FP_CONFIG, sizeof(cl_device_fp_config), &fp_config, 0);
+ bool denormals_supported = fp_config & CL_FP_DENORM;
+ float max_ulp = 0, max_ulp_at = 0;
+
+ for (int j = 0; j < 128; j ++) {
OCL_MAP_BUFFER(0);
for (int i = 0; i < n; ++i) {
- src[i] = ((float*)buf_data[0])[i] = (j*n+i+1) * 0.001f;
+ src[i] = ((float*)buf_data[0])[i] = j - 64 + i*0.001f;
}
OCL_UNMAP_BUFFER(0);
@@ -32,7 +37,14 @@ void builtin_tgamma(void)
OCL_MAP_BUFFER(1);
float *dst = (float*)buf_data[1];
for (int i = 0; i < n; ++i) {
- float cpu = tgammaf(src[i]);
+ float cpu = tgamma(src[i]);
+ if (!denormals_supported && std::fpclassify(cpu)==FP_SUBNORMAL && dst[i]==0) {
+ cpu = 0;
+ }
+ if (fabsf(cpu - dst[i]) > cl_FLT_ULP(cpu) * max_ulp) {
+ max_ulp = fabsf(cpu - dst[i]) / cl_FLT_ULP(cpu);
+ max_ulp_at = src[i];
+ }
if (isinf(cpu)) {
OCL_ASSERT(isinf(dst[i]));
} else if (fabsf(cpu - dst[i]) >= cl_FLT_ULP(cpu) * ULPSIZE_FACTOR) {
@@ -42,6 +54,7 @@ void builtin_tgamma(void)
}
OCL_UNMAP_BUFFER(1);
}
+ printf("max error=%f ulp at x=%f ", max_ulp, max_ulp_at);
}
MAKE_UTEST_FROM_FUNCTION(builtin_tgamma);