[Beignet] [PATCH] make utests maths ULP values consistent with specification

Zhigang Gong zhigang.gong at linux.intel.com
Sun Nov 30 23:08:22 PST 2014


On Thu, Nov 27, 2014 at 09:45:26AM +0800, Meng Mengmeng wrote:
> Signed-off-by: Meng Mengmeng <mengmeng.meng at intel.com>
> ---
>  utests/builtin_pow.cpp    |   2 +-
>  utests/builtin_tgamma.cpp |   2 +-
>  utests/utest_generator.py | 100 +++++++++++++++++++++++++++++++++++++++++++---
>  3 files changed, 96 insertions(+), 8 deletions(-)
> 
> diff --git a/utests/builtin_pow.cpp b/utests/builtin_pow.cpp
> index c0361e1..a18f31e 100644
> --- a/utests/builtin_pow.cpp
> +++ b/utests/builtin_pow.cpp
> @@ -38,7 +38,7 @@ static void builtin_pow(void)
>      }
>  
>    const char* env_strict = getenv("OCL_STRICT_CONFORMANCE");
> -  float ULPSIZE_FACTOR = 1.0;
> +  float ULPSIZE_FACTOR = 16.0;
>    if (env_strict == NULL || strcmp(env_strict, "0") == 0)
>      ULPSIZE_FACTOR = 10000.;
>  
> diff --git a/utests/builtin_tgamma.cpp b/utests/builtin_tgamma.cpp
> index 16dac97..47cc5f4 100644
> --- a/utests/builtin_tgamma.cpp
> +++ b/utests/builtin_tgamma.cpp
> @@ -16,7 +16,7 @@ void builtin_tgamma(void)
>    globals[0] = n;
>    locals[0] = 16;
>    const char* env_strict = getenv("OCL_STRICT_CONFORMANCE");
> -  float ULPSIZE_FACTOR = 1.0;
> +  float ULPSIZE_FACTOR = 16.0;
>    if (env_strict == NULL || strcmp(env_strict, "0") == 0)
>      ULPSIZE_FACTOR = 10000.;
>  
> diff --git a/utests/utest_generator.py b/utests/utest_generator.py
> index 5da2752..20309fc 100644
> --- a/utests/utest_generator.py
> +++ b/utests/utest_generator.py
> @@ -8,6 +8,91 @@ FLT_MAX_NEGA='-0x1.0p-126f'
>  
>  paraTypeList={'float':'%e','int':'%d','double':'%lf','uint':'%d','string':'%s'}
>  
> +Single_Precision_ULPs={'acos' : '4' ,
> +                      'acospi' : '5' ,
> +                      'asin' : '4' ,
> +                      'asinpi' : '5' ,
> +                      'atan' : '5' ,
> +                      'atan2' : '6' ,
> +                      'atanpi' : '5' ,
> +                      'atan2pi' : '6' ,
> +                      'acosh' : '4' ,
> +                      'asinh' : '4' ,
> +                      'atanh' : '5' ,
> +                      'cbrt' : '2' ,
> +                      'ceil' : '-1' ,
> +                      'copysign' : '0' ,
> +                      'cos' : '4' ,
> +                      'cosh' : '4' ,
> +                      'cospi' : '4' ,
> +                      'erfc' : '16' ,
> +                      'erf' : '16' ,
> +                      'exp' : '3' ,
> +                      'exp2' : '3' ,
> +                      'exp10' : '3' ,
> +                      'expm1' : '3' ,
> +                      'fabs' : '0' ,
> +                      'fdim' : '-1' ,
> +                      'floor' : '-1' ,
> +                      'fma' : '-1' ,
> +                      'fmax' : '0' ,
> +                      'fmin' : '0' ,
> +                      'fmod' : '0' ,
> +                      'fract' : '-1' ,
> +                      'frexp' : '0' ,
> +                      'hypot' : '4' ,
> +                      'ilogb' : '0' ,
> +                      'ldexp' : '-1' ,
> +                      'log' : '3' ,
> +                      'log2' : '3' ,
> +                      'log10' : '3' ,
> +                      'log1p' : '2' ,
> +                      'logb' : '0' ,
> +                      'maxmag' : '0' ,
> +                      'minmag' : '0' ,
> +                      'modf' : '0' ,
> +                      'nan' : '0' ,
> +                      'nextafter' : '0' ,
> +                      'pow' : '16' ,
> +                      'pown,' : '16' ,
> +                      'powr,' : '16' ,
> +                      'remainder' : '0' ,
> +                      'remquo' : '0' ,
> +                      'rint' : '-1' ,
> +                      'rootn' : '16' ,
> +                      'round' : '-1' ,
> +                      'rsqrt' : '2' ,
> +                      'sin' : '4' ,
> +                      'sincos' : '4' ,
> +                      'sinh' : '4' ,
> +                      'sinpi' : '4' ,
> +                      'sqrt' : '3' ,
> +                      'tan' : '5' ,
> +                      'tanh' : '5' ,
> +                      'tanpi' : '6' ,
> +                      'tgamma' : '16' ,
> +                      'trunc' : '-1' ,
> +                      'half_cos' : '8192' ,
> +                      'half_divide' : '8192' ,
> +                      'half_exp' : '8192' ,
> +                      'half_exp2' : '8192' ,
> +                      'half_exp10' : '8192' ,
> +                      'half_log2' : '8192' ,
> +                      'half_log10' : '8192' ,
> +                      'half_powr' : '8192' ,
> +                      'half_recip' : '8192' ,
> +                      'half_rsqrt' : '8192' ,
> +                      'half_sin' : '8192' ,
> +                      'half_sqrt' : '8192' ,
> +                      'half_tan' : '8192' }
> +
> +def Min_ulp(function):
> +    if function in Single_Precision_ULPs.keys():
> +         ulpValues = Single_Precision_ULPs[function]
> +    else:
> +         ulpValues = 1
> +    return ulpValues
> +
>  
>  def ulpUnit(ulpSize):
>    return re.findall(r"([a-zA-Z_]+)",ulpSize)[0]
> @@ -15,7 +100,7 @@ def ulpUnit(ulpSize):
>  def ulpNum(ulpSize):
>    return re.findall(r"([0-9]+)",ulpSize)[0]
>  
> -def udebug(ulpSize,returnType):
> +def udebug(ulpSize,returnType,function):
>    #ulpUnit=re.findall(r"([a-zA-Z_]+)",ulpSize)[0]
>    #ulpNum=re.findall(r"([0-9]+)",ulpSize)[0]
>    text='''
> @@ -27,7 +112,7 @@ def udebug(ulpSize,returnType):
>      if (env_strict == NULL || strcmp(env_strict, "0") == 0)
>        ULPSIZE_FACTOR = 1000;
>      else
> -      ULPSIZE_FACTOR = 1;
> +      ULPSIZE_FACTOR = %s;
>      
>      if (isinf(cpu_data[index])){
>        INFORNAN="INF";
> @@ -53,7 +138,7 @@ def udebug(ulpSize,returnType):
>        else
>          printf_c("%s expect:%s\\n", log, INFORNAN);
>        }
> -    else if (diff <= ULPSIZE){
> +    else if (ULPSIZE != -1 && diff <= ULPSIZE){
>        printf("%s expect:%s\\n", log, ULPSIZE);
>        }
>      else
> @@ -69,11 +154,14 @@ def udebug(ulpSize,returnType):
>        }
>      else{
>        sprintf(log, "%s expect:%s\\n", log, ULPSIZE);
> -      OCL_ASSERTM(fabs(gpu_data[index]-cpu_data[index]) <= ULPSIZE, log);
> +      if (ULPSIZE == -1)
Should use ULPSIZE < 0 in the above condition check. As the ULPSIZE is calculated from origin ULPSIZE and ULPFACTOR.
ULPFACTOR is -1 but the origin ULPSIZE is not 1. So you need to use ULPSIZE < 0 here.

Should fix the same issue in the udebug enabled code block.

Thanks,
Zhigang Gong.


More information about the Beignet mailing list