public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* Fwd: gfortran fp16
       [not found] <13b127cf.c856.180cb531986.Coremail.cglwdm@scu.edu.cn>
@ 2022-05-16  7:51 ` Toon Moene
  2022-05-16 10:50   ` Tobias Burnus
  0 siblings, 1 reply; 5+ messages in thread
From: Toon Moene @ 2022-05-16  7:51 UTC (permalink / raw)
  To: fortran; +Cc: cglwdm

Interesting question. We don't do that yet, as far as I know.


-------- Forwarded Message --------
Subject: gfortran fp16
Date: Mon, 16 May 2022 13:24:22 +0800 (GMT+08:00)
From: 陈刚 <cglwdm@scu.edu.cn>
To: gcc-help@gcc.gnu.org

Dear experts,




I want to use fp16 in fortran, does gfortran support the fp16?




I didn't find the fp16 in gfortran but in C language.




Is there any solutions?




Best




Gang Chen




School of Mathematics



Sichuan University, China

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Fwd: gfortran fp16
  2022-05-16  7:51 ` Fwd: gfortran fp16 Toon Moene
@ 2022-05-16 10:50   ` Tobias Burnus
  2022-05-17 10:09     ` Thomas König
  0 siblings, 1 reply; 5+ messages in thread
From: Tobias Burnus @ 2022-05-16 10:50 UTC (permalink / raw)
  To: Toon Moene, cglwdm; +Cc: fortran

On 16.05.22 09:51, Toon Moene wrote:
> Interesting question. We don't do that yet, as far as I know.
> -------- Forwarded Message --------
> From: 陈刚 <cglwdm@scu.edu.cn>
>
> I want to use fp16 in fortran, does gfortran support the fp16?

I think adding fp16 to the compiler itself is not that difficult – it is
"just" handling 'HF' mode via 'REAL(kind=2)'; this can be done rather
quickly.

@陈刚: If you want to volunteer to add it (know someone who does), I can
give some pointers.*

Additionally support in the libgfortran run-time library should be added
and some testcases written to ensure it works. – I think that is also a
smaller task, but has to be done in addition.

Tobias

*See https://gcc.gnu.org/contribute.html for a starter – but if
interested, I will give explicit hints what needs to be changed how.


-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gfortran fp16
  2022-05-16 10:50   ` Tobias Burnus
@ 2022-05-17 10:09     ` Thomas König
  2022-05-17 10:26       ` Tobias Burnus
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas König @ 2022-05-17 10:09 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: Toon Moene, cglwdm, fortran

Hi,

be might complement to the QP support for POWER in gcc 12, and I have actually thought about doing. The library has its gotchas, though - I do not suppose we can count on fp16 support for trigonometrics and similar, for example, so we would probably have to use fp32 and convert (or imlement a lookup table, which would be cache-unfriendly) Plus, there appears to be more than one format on ARM, but we should probably restrict ourselves to IEEE.

So, not a really small project, but an interesting one.

Best regards

Thomas
> Am 16.05.2022 um 12: 50 schrieb Tobias Burnus <Tobias_Burnus@mentor.com>:
> On 16.05.22 09:51, nkToon Moene wrote:
>> Interesting question. We don't do that yet, as far as I know.
>> -------- Forwarded Message --------
>> From: 陈刚 <cglwdm@scu.edu.cn>
>> 
>> I want to use fp16 in fortran, does gfortran support the fp16?
> 
> I think adding fp16 to the compiler itself is not that difficult – it is
> "just" handling 'HF' mode via 'REAL(kind=2)'; this can be done rather
> quickly.
> 
> @陈刚: If you want to volunteer to add it (know someone who does), I can
> give some pointers.*
> 
> Additionally support in the libgfortran run-time library should be added
> and some testcases written to ensure it works. – I think that is also a
> smaller task, but has to be done in addition.
> 
> Tobias
> 
> *See https://gcc.gnu.org/contribute.html for a starter – but if
> interested, I will give explicit hints what needs to be changed how.
> 
> 
> -----------------
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gfortran fp16
  2022-05-17 10:09     ` Thomas König
@ 2022-05-17 10:26       ` Tobias Burnus
  2022-05-17 18:33         ` James Cloos
  0 siblings, 1 reply; 5+ messages in thread
From: Tobias Burnus @ 2022-05-17 10:26 UTC (permalink / raw)
  To: Thomas König; +Cc: Toon Moene, cglwdm, fortran

On 17.05.22 12:09, Thomas König wrote:
> be might complement to the QP support for POWER in gcc 12, and I have actually thought about doing. The library has its gotchas, though - I do not suppose we can count on fp16 support for trigonometrics and similar, for example,

I think that mostly depends on what the hardware supports and what
has been implemented in the target code.

For instance nvptx supports tanh and ex2 (ex2(a) := 2**a)) for .f16 –
and nvidia.md also contains, e.g. '(define_insn "exp2hf2"' which operates on "HF".

And there is also the following in gcc/builtins.def:

DEF_C99_BUILTIN        (BUILT_IN_ACOSHF, "acoshf", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO)
DEF_C99_BUILTIN        (BUILT_IN_ASINHF, "asinhf", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING)
DEF_C99_BUILTIN        (BUILT_IN_ATANHF, "atanhf", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO)
DEF_C99_C90RES_BUILTIN (BUILT_IN_COSHF, "coshf", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO)
DEF_C99_C90RES_BUILTIN (BUILT_IN_SINHF, "sinhf", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO)
DEF_C99_C90RES_BUILTIN (BUILT_IN_TANHF, "tanhf", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING)
DEF_C99_COMPL_BUILTIN        (BUILT_IN_CACOSHF, "cacoshf", BT_FN_COMPLEX_FLOAT_COMPLEX_FLOAT, ATTR_MATHFN_FPROUNDING)
DEF_C99_COMPL_BUILTIN        (BUILT_IN_CASINHF, "casinhf", BT_FN_COMPLEX_FLOAT_COMPLEX_FLOAT, ATTR_MATHFN_FPROUNDING)
DEF_C99_COMPL_BUILTIN        (BUILT_IN_CATANHF, "catanhf", BT_FN_COMPLEX_FLOAT_COMPLEX_FLOAT, ATTR_MATHFN_FPROUNDING)
DEF_C99_COMPL_BUILTIN        (BUILT_IN_CCOSHF, "ccoshf", BT_FN_COMPLEX_FLOAT_COMPLEX_FLOAT, ATTR_MATHFN_FPROUNDING)
DEF_C99_COMPL_BUILTIN        (BUILT_IN_CSINHF, "csinhf", BT_FN_COMPLEX_FLOAT_COMPLEX_FLOAT, ATTR_MATHFN_FPROUNDING)
DEF_C99_COMPL_BUILTIN        (BUILT_IN_CTANHF, "ctanhf", BT_FN_COMPLEX_FLOAT_COMPLEX_FLOAT, ATTR_MATHFN_FPROUNDING)

But as said: the basic support for HF-supporting target should be simple,
supporting all the library is more difficult. But the question is whether
full support is needed or not. For 'acoshf' - if it is not available but
used, it is mostly a user problem - which can be fixed by a suitable libm.
I assume that on systems where HF is relevant, libm can be compiled such
that it works.

And in the compiler, you can use '#ifdef HAVE_HFmode' to check whether it exists.

Tobias

-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gfortran fp16
  2022-05-17 10:26       ` Tobias Burnus
@ 2022-05-17 18:33         ` James Cloos
  0 siblings, 0 replies; 5+ messages in thread
From: James Cloos @ 2022-05-17 18:33 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: Thomas König, fortran, cglwdm

>>>>> "TB" == Tobias Burnus <tobias@codesourcery.com> writes:

TB> DEF_C99_BUILTIN        (BUILT_IN_ACOSHF, "acoshf", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO)

those are more likely trigh_f than trig_hf.

ie hyperbolic.

-JimC
-- 
James Cloos <cloos@jhcloos.com>         OpenPGP: 0x997A9F17ED7DAEA6

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-05-17 18:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <13b127cf.c856.180cb531986.Coremail.cglwdm@scu.edu.cn>
2022-05-16  7:51 ` Fwd: gfortran fp16 Toon Moene
2022-05-16 10:50   ` Tobias Burnus
2022-05-17 10:09     ` Thomas König
2022-05-17 10:26       ` Tobias Burnus
2022-05-17 18:33         ` James Cloos

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).