[Beignet] [PATCH V2] Utest: Add result error tolerance for float data types

Yang, Rong R rong.r.yang at intel.com
Thu Apr 14 06:38:04 UTC 2016


Tha patchset pushed, thanks.

> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> grigore.lupescu at intel.com
> Sent: Wednesday, April 13, 2016 18:29
> To: beignet at lists.freedesktop.org
> Subject: [Beignet] [PATCH V2] Utest: Add result error tolerance for float data
> types
> 
> From: Grigore Lupescu <grigore.lupescu at intel.com>
> 
> Modification affects only workgroup reduce, scan inclusive, scan exclusive,
> on non integer type In some instances results may differ slightly between
> CPU and GPU hence comparison is relaxed
> 
> Signed-off-by: Grigore Lupescu <grigore.lupescu at intel.com>
> ---
>  utests/compiler_workgroup_reduce.cpp         | 27
> ++++++++++++++++++++++-----
>  utests/compiler_workgroup_scan_exclusive.cpp | 27
> ++++++++++++++++++++++-----
> utests/compiler_workgroup_scan_inclusive.cpp | 27
> ++++++++++++++++++++++-----
>  3 files changed, 66 insertions(+), 15 deletions(-)
> 
> diff --git a/utests/compiler_workgroup_reduce.cpp
> b/utests/compiler_workgroup_reduce.cpp
> index f796d5c..1624947 100644
> --- a/utests/compiler_workgroup_reduce.cpp
> +++ b/utests/compiler_workgroup_reduce.cpp
> @@ -173,14 +173,31 @@ static void workgroup_generic(WG_FUNCTION
> wg_func,
>    for (uint32_t i = 0; i < WG_GLOBAL_SIZE; i++)
>      if(((T *)buf_data[1])[i] != *(expected + i))
>      {
> -      /* found mismatch, increment */
> -      mismatches++;
> +      /* found mismatch on integer, increment */
> +      if(numeric_limits<T>::is_integer){
> +        mismatches++;
> 
>  #if DEBUG_STDOUT
> -      /* output mismatch */
> -      cout << "Err at " << i << ", " <<
> -        ((T *)buf_data[1])[i] << " != " << *(expected + i) << endl;
> +        /* output mismatch */
> +        cout << "Err at " << i << ", " <<
> +          ((T *)buf_data[1])[i] << " != " << *(expected + i) << endl;
>  #endif
> +      }
> +      /* float error is tolerable though */
> +      else {
> +          float num_computed = ((T *)buf_data[1])[i];
> +          float num_expected = *(expected + i);
> +          float num_diff = abs(num_computed - num_expected) /
> abs(num_expected);
> +          if(num_diff > 0.01f){
> +            mismatches++;
> +
> +#if DEBUG_STDOUT
> +          /* output mismatch */
> +          cout << "Err at " << i << ", " <<
> +            ((T *)buf_data[1])[i] << " != " << *(expected + i) << endl;
> +#endif
> +        }
> +      }
>      }
> 
>  #if DEBUG_STDOUT
> diff --git a/utests/compiler_workgroup_scan_exclusive.cpp
> b/utests/compiler_workgroup_scan_exclusive.cpp
> index c44c098..4ff5442 100644
> --- a/utests/compiler_workgroup_scan_exclusive.cpp
> +++ b/utests/compiler_workgroup_scan_exclusive.cpp
> @@ -157,14 +157,31 @@ static void workgroup_generic(WG_FUNCTION
> wg_func,
>    for (uint32_t i = 0; i < WG_GLOBAL_SIZE; i++)
>      if(((T *)buf_data[1])[i] != *(expected + i))
>      {
> -      /* found mismatch, increment */
> -      mismatches++;
> +      /* found mismatch on integer, increment */
> +      if(numeric_limits<T>::is_integer){
> +        mismatches++;
> 
>  #if DEBUG_STDOUT
> -      /* output mismatch */
> -      cout << "Err at " << i << ", " <<
> -        ((T *)buf_data[1])[i] << " != " << *(expected + i) << endl;
> +        /* output mismatch */
> +        cout << "Err at " << i << ", " <<
> +          ((T *)buf_data[1])[i] << " != " << *(expected + i) << endl;
>  #endif
> +      }
> +      /* float error is tolerable though */
> +      else {
> +          float num_computed = ((T *)buf_data[1])[i];
> +          float num_expected = *(expected + i);
> +          float num_diff = abs(num_computed - num_expected) /
> abs(num_expected);
> +          if(num_diff > 0.01f){
> +            mismatches++;
> +
> +#if DEBUG_STDOUT
> +          /* output mismatch */
> +          cout << "Err at " << i << ", " <<
> +            ((T *)buf_data[1])[i] << " != " << *(expected + i) << endl;
> +#endif
> +        }
> +      }
>      }
> 
>  #if DEBUG_STDOUT
> diff --git a/utests/compiler_workgroup_scan_inclusive.cpp
> b/utests/compiler_workgroup_scan_inclusive.cpp
> index b4501b8..1a7477f 100644
> --- a/utests/compiler_workgroup_scan_inclusive.cpp
> +++ b/utests/compiler_workgroup_scan_inclusive.cpp
> @@ -147,14 +147,31 @@ static void workgroup_generic(WG_FUNCTION
> wg_func,
>    for (uint32_t i = 0; i < WG_GLOBAL_SIZE; i++)
>      if(((T *)buf_data[1])[i] != *(expected + i))
>      {
> -      /* found mismatch, increment */
> -      mismatches++;
> +      /* found mismatch on integer, increment */
> +      if(numeric_limits<T>::is_integer){
> +        mismatches++;
> 
>  #if DEBUG_STDOUT
> -      /* output mismatch */
> -      cout << "Err at " << i << ", " <<
> -        ((T *)buf_data[1])[i] << " != " << *(expected + i) << endl;
> +        /* output mismatch */
> +        cout << "Err at " << i << ", " <<
> +          ((T *)buf_data[1])[i] << " != " << *(expected + i) << endl;
>  #endif
> +      }
> +      /* float error is tolerable though */
> +      else {
> +          float num_computed = ((T *)buf_data[1])[i];
> +          float num_expected = *(expected + i);
> +          float num_diff = abs(num_computed - num_expected) /
> abs(num_expected);
> +          if(num_diff > 0.01f){
> +            mismatches++;
> +
> +#if DEBUG_STDOUT
> +          /* output mismatch */
> +          cout << "Err at " << i << ", " <<
> +            ((T *)buf_data[1])[i] << " != " << *(expected + i) << endl;
> +#endif
> +        }
> +      }
>      }
> 
>  #if DEBUG_STDOUT
> --
> 2.5.0
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list