[Libclc-dev] [PATCH 2/2] amdgcn/fmax: Explicitly check for NaNs

Jan Vesely via Libclc-dev libclc-dev at lists.llvm.org
Sat Mar 3 13:54:39 PST 2018


On Wed, 2017-11-15 at 12:21 -0500, Jan Vesely wrote:
> v_max instruction fails to handle certain NaN values
> 
> Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
> ---
> Fixes most of fmax CTS on carrizo. It still fails on denormals, but IMO
> that's CTS bug.
> EG/NI does not seem to suffer the same problem.
> 
>  amdgcn/lib/SOURCES      |  1 +
>  amdgcn/lib/math/fmax.cl | 32 ++++++++++++++++++++++++++++++++
>  2 files changed, 33 insertions(+)
>  create mode 100644 amdgcn/lib/math/fmax.cl
> 
> diff --git a/amdgcn/lib/SOURCES b/amdgcn/lib/SOURCES
> index 5149f85..36f3397 100644
> --- a/amdgcn/lib/SOURCES
> +++ b/amdgcn/lib/SOURCES
> @@ -1,4 +1,5 @@
>  cl_khr_int64_extended_atomics/minmax_helpers.ll
> +math/fmax.cl
>  math/fmin.cl
>  math/ldexp.cl
>  mem_fence/fence.cl
> diff --git a/amdgcn/lib/math/fmax.cl b/amdgcn/lib/math/fmax.cl
> new file mode 100644
> index 0000000..204bbd6
> --- /dev/null
> +++ b/amdgcn/lib/math/fmax.cl
> @@ -0,0 +1,32 @@
> +#include <clc/clc.h>
> +
> +#include "../../../generic/lib/clcmacro.h"
> +
> +_CLC_DEF _CLC_OVERLOAD float fmax(float x, float y)
> +{
> +   if (isnan(x))
> +      return y;
> +   if (isnan(y))
> +      return x;
> +   return (x < y) ? y : x;
> +}
> +_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, fmax, float, float)
> +
> +#ifdef cl_khr_fp64
> +
> +#pragma OPENCL EXTENSION cl_khr_fp64 : enable
> +
> +_CLC_DEF _CLC_OVERLOAD double fmax(double x, double y)
> +{
> +   if (isnan(x))
> +      return y;
> +   if (isnan(y))
> +      return x;
> +   return (x < y) ? y : x;
> +}
> +_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, fmax, double, double)
> +
> +#endif
> +
> +#define __CLC_BODY <../../../generic/lib/math/fmax.inc>
> +#include <clc/math/gentype.inc>

I think we needs these patches for older LLVM. I'll add ifdef for llvm
7 when [0] (or similar solution) lands.

Jan
[0] https://reviews.llvm.org/D40514
-- 
Jan Vesely <jan.vesely at rutgers.edu>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.llvm.org/pipermail/libclc-dev/attachments/20180303/efe81691/attachment-0001.sig>


More information about the Libclc-dev mailing list