[Beignet] [PATCH] correct ULP value in utests

Yang, Rong R rong.r.yang at intel.com
Wed Jul 15 01:44:23 PDT 2015


LGTM, thanks, pushed.

> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> Meng Mengmeng
> Sent: Wednesday, July 15, 2015 01:23
> To: beignet at lists.freedesktop.org
> Cc: Meng, Mengmeng
> Subject: [Beignet] [PATCH] correct ULP value in utests
> 
> Set a global function in utests to get the right ULP value.
> ---
>  utests/builtin_pow.cpp    |  6 ++----
>  utests/builtin_tgamma.cpp |  6 ++----
>  utests/utest_generator.py | 12 ++++--------
>  utests/utest_helper.cpp   | 12 ++++++++++++
>  utests/utest_helper.hpp   |  4 ++++
>  5 files changed, 24 insertions(+), 16 deletions(-)
> 
> diff --git a/utests/builtin_pow.cpp b/utests/builtin_pow.cpp index
> a8523d3..f586448 100644
> --- a/utests/builtin_pow.cpp
> +++ b/utests/builtin_pow.cpp
> @@ -28,6 +28,7 @@ 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<count_input_ori;i++)
> @@ -40,10 +41,7 @@ static void builtin_pow(void)
>    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;
> -  const char* env_strict = getenv("OCL_STRICT_CONFORMANCE");
> -  float ULPSIZE_FACTOR = 16.0;
> -  if (env_strict == NULL || strcmp(env_strict, "0") == 0)
> -    ULPSIZE_FACTOR = 10000.;
> +  float ULPSIZE_FACTOR =
> + select_ulpsize(ULPSIZE_FAST_MATH,ULPSIZE_NO_FAST_MATH);
> 
>    OCL_CREATE_KERNEL("builtin_pow");
> 
> diff --git a/utests/builtin_tgamma.cpp b/utests/builtin_tgamma.cpp index
> b7db69b..db9ab3c 100644
> --- a/utests/builtin_tgamma.cpp
> +++ b/utests/builtin_tgamma.cpp
> @@ -6,6 +6,7 @@ void builtin_tgamma(void)  {
>    const int n = 1024;
>    float src[n];
> +  float ULPSIZE_NO_FAST_MATH = 16.0;
> 
>    // Setup kernel and buffers
>    OCL_CREATE_KERNEL("builtin_tgamma");
> @@ -15,10 +16,7 @@ void builtin_tgamma(void)
>    OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);
>    globals[0] = n;
>    locals[0] = 16;
> -  const char* env_strict = getenv("OCL_STRICT_CONFORMANCE");
> -  float ULPSIZE_FACTOR = 16.0;
> -  if (env_strict == NULL || strcmp(env_strict, "0") == 0)
> -    ULPSIZE_FACTOR = 10000.;
> +  float ULPSIZE_FACTOR =
> + select_ulpsize(ULPSIZE_FAST_MATH,ULPSIZE_NO_FAST_MATH);
> 
>    cl_device_fp_config fp_config;
>    clGetDeviceInfo(device, CL_DEVICE_SINGLE_FP_CONFIG,
> sizeof(cl_device_fp_config), &fp_config, 0); diff --git
> a/utests/utest_generator.py b/utests/utest_generator.py index
> 7d2d3a0..c220575 100644
> --- a/utests/utest_generator.py
> +++ b/utests/utest_generator.py
> @@ -108,12 +108,8 @@ def udebug(ulpSize,returnType,function):
>      static const char* INFORNAN;
>      static %s ULPSIZE, ULPSIZE_FACTOR;
> 
> -    const char* env_strict = getenv("OCL_STRICT_CONFORMANCE");
> -
> -    if (env_strict == NULL || strcmp(env_strict, "0") == 0)
> -      ULPSIZE_FACTOR = 1000;
> -    else
> -      ULPSIZE_FACTOR = %s;
> +    float ULPSIZE_NO_FAST_MATH = %s;
> +    ULPSIZE_FACTOR =
> + select_ulpsize(ULPSIZE_FAST_MATH,ULPSIZE_NO_FAST_MATH);
> 
>      if (isinf(cpu_data[index])){
>        INFORNAN="INF";
> @@ -147,11 +143,11 @@ def udebug(ulpSize,returnType,function):
>  #else
>      if (isinf(cpu_data[index])){
>        sprintf(log, "%s expect:%s\\n", log, INFORNAN);
> -      OCL_ASSERTM(isinf(gpu_data[index]) || !env_strict,log);
> +      OCL_ASSERTM(isinf(gpu_data[index]),log);
>        }
>      else if (isnan(cpu_data[index])){
>        sprintf(log, "%s expect:%s\\n", log, INFORNAN);
> -      OCL_ASSERTM(isnan(gpu_data[index]) || !env_strict,log);
> +      OCL_ASSERTM(isnan(gpu_data[index]),log);
>        }
>      else{
>        sprintf(log, "%s expect:%s\\n", log, ULPSIZE); diff --git
> a/utests/utest_helper.cpp b/utests/utest_helper.cpp index
> d3c378e..8f772fd 100644
> --- a/utests/utest_helper.cpp
> +++ b/utests/utest_helper.cpp
> @@ -53,6 +53,7 @@ cl_mem buf[MAX_BUFFER_N] = {};  void
> *buf_data[MAX_BUFFER_N] = {};  size_t globals[3] = {};  size_t locals[3] = {};
> +float ULPSIZE_FAST_MATH = 10000.;
> 
>  #ifdef HAS_EGL
>  Display    *xDisplay;
> @@ -702,3 +703,14 @@ double time_subtract(struct timeval *y, struct
> timeval *x, struct timeval *resul
>    double msec = 1000.0*(y->tv_sec - x->tv_sec) + (y->tv_usec - x-
> >tv_usec)/1000.0;
>    return msec;
>  }
> +
> +float select_ulpsize(float ULPSIZE_FAST_MATH, float
> +ULPSIZE_NO_FAST_MATH) {
> +  const char* env_strict = getenv("OCL_STRICT_CONFORMANCE");
> +
> +  float ULPSIZE_FACTOR = ULPSIZE_NO_FAST_MATH;  if (env_strict != NULL
> + && strcmp(env_strict, "0") == 0 )
> +        ULPSIZE_FACTOR = ULPSIZE_FAST_MATH;
> +
> +  return ULPSIZE_FACTOR;
> +}
> diff --git a/utests/utest_helper.hpp b/utests/utest_helper.hpp index
> 6d09766..3b17606 100644
> --- a/utests/utest_helper.hpp
> +++ b/utests/utest_helper.hpp
> @@ -165,6 +165,7 @@ extern cl_mem buf[MAX_BUFFER_N];  extern void*
> buf_data[MAX_BUFFER_N];  extern size_t globals[3];  extern size_t locals[3];
> +extern float ULPSIZE_FAST_MATH;
> 
>  enum {
>    SOURCE = 0,
> @@ -233,5 +234,8 @@ extern int cl_INT_ULP(int int_number);
>  /* subtract the time */
>  double time_subtract(struct timeval *y, struct timeval *x, struct timeval
> *result);
> 
> +/* check ulpsize */
> +float select_ulpsize(float ULPSIZE_FAST_MATH, float
> +ULPSIZE_NO_FAST_MATH);
> +
>  #endif /* __UTEST_HELPER_HPP__ */
> 
> --
> 1.9.1
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list