public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Theodore Papadopoulo <Theodore.Papadopoulo@sophia.inria.fr>
To: Gabriel Dos Reis <gdr@codesourcery.com>
Cc: dewar@gnat.com, amylaar@redhat.com, aoliva@redhat.com,
	gcc@gcc.gnu.org, moshier@moshier.ne.mediaone.net,
	torvalds@transmeta.com, tprince@computer.org
Subject: Re: What is acceptable for -ffast-math? (Was: associative law in combine)
Date: Wed, 01 Aug 2001 08:55:00 -0000	[thread overview]
Message-ID: <200108011555.f71Ft4q07786@mururoa.inria.fr> (raw)
In-Reply-To: <flu1zt7m4b.fsf@jambon.cmla.ens-cachan.fr>

While I agree that by default the compiler must follow "good rules", I 
think that always disallowing optimisations which may lose some bits of 
accuracy (when specified with a option switch of course) just because 
it may hurt someone, somewhere, sometime is a little too strong.
Full safety is IMHO impossible with floating point... Only the 
programmer knows the accuracy of its input data (Linus called that 
noise) and the accuracy he expects on its result.

Since the example has been given, let us speak about image processing.
The data (when using real images) are often 'char' based so you have 
basically 8 bits or less of information per channel.  Then converting
these images to float and working with them, there is usually little risk of 
introducing some error due to some bad rounding. float is enough for 
most image analysis and computation, and lots of people are even 
using double (which sometimes are also faster). In such cases, I 
would argue that absolute floating point accuracy is not worth. To be 
meaningful the results have to be robust to errors (in the input and 
thus in the subsequent calculations that are many orders of magnitude 
higher than the machine accuracy). If they are not, then the approach 
is certainly not valid.

gdr@codesourcery.com said:
> That doesn't mean I don't want optimization.  I do love optimization.
> By optimization, I really mean optimization. 

No by optimisation, you mean mathematically provable safe optimisation and 
unfortunately, the provability of such things by mathematics is usually
very difficult. I agree that sometimes you have to rely only on such 
optimisations, so that, by default, the compiler should only allow them.
But, you have to allow for people:

- for whom provably has an experimental meaning. There are a lot of 
fields where computationnal difficulty is avoided by addind some 
random noise over the existing values just because doing so usually
removes some degeneracies (with 99.999999% of the cases) in the computation
that are just too difficult to deal with and that can be considered
as artifacts of a configuration that will not impact the result (a 
choice between equally good solutions is just made).

- who know that the allowed input data (for their particular program) is well
within the range of the floating point range accuracy they have selected to work with.
Image analysis, games, and lots of real world problem when the data 
are corrupted with noise often enters in this category (measurement 
apparatus seldom give 24 or 53 bits of accuracy).

Proving anything with floating point computation is very difficult in 
some cases even for knowledgeable people. Often, people who really want
to deal with accuracy often go beyond simple floating point computation by
using multiple arithmetics with increasing accuracy or even better, range arithmetic.

> Moreover, if the drawbacks of some optimizations are too dangerous
> (very reduced domain, etc), a solution could be (yes, I realize there
> are too many already) to allow the user to specify how hard one wants
> the compiler to try and speed up the code using -ffast-math-<N>, as in
> -O<N>, or adding --fmath-allow-domain-shrinking, or -fmath-ignore-nans
> or whatever could be used by the programmer to tell the compiler what
> is important to him/her and what can be sacrificed for sped. 

I like the -ffast-math-<N> idea.
By default -ffast-math (equivalent to eg -ffast-math-0) would be very conservative.
Then with N increasing you would allow optimisations that lose more and 
more bits of accuracy.

While I agree that it would only be useful to add things that indeed 
increase the speed by more than a few percents, this is something 
very difficult to state with modern machines, all the more that things 
may add up in a complex fashion, if multiple small optimisations are 
added.

wolfgang.bangerth@iwr.uni-heidelberg.de said:
> - denormals: if you run into the risk of getting NaNs one way but not
>   the other, you most certainly already have gone beyond the limits of
>   your program, i.e. your linear solver diverged, you have chosen an
>   inherently unstable formulation for your problem, etc. In practice,

I totally agree.
All the more that denormals is certainly something that can cost a lot in term of 
computation time since often this is not really implemented in the 
hardware (trap to microcode or to library code). I remember having 
seen decreases in speed by a factor of at least 10, for things that 
would have been equally well be treated as zero.

Often, when using floating point in some tricky situations, I wonder 
whether it would not be better to have very fragile floating point 
arithmetic by default, so that each potential problematic spot is 
easily located as one generating a NaN or an obviously bad result.
I certainly go too far here, but I'm not sure it would not be good in 
the long run...

--------------------------------------------------------------------
Theodore Papadopoulo
Email: Theodore.Papadopoulo@sophia.inria.fr Tel: (33) 04 92 38 76 01
 --------------------------------------------------------------------


-- 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Exmh version 2.2 06/23/2000

iD8DBQE7aCZYIzTj8qrxOU4RAtXKAJ4zEqZKrUYxF+8rsk4+KVJA1hvAjgCg4KZk
0uhEmXIpS200Azv/xR+bQxM=
=TwfB
-----END PGP SIGNATURE-----

  parent reply	other threads:[~2001-08-01  8:55 UTC|newest]

Thread overview: 120+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-30 21:13 dewar
2001-07-30 21:34 ` Gabriel Dos Reis
2001-07-30 21:43   ` Joern Rennecke
2001-07-30 21:53     ` Gabriel Dos Reis
2001-08-03  7:12       ` Nick Ing-Simmons
2001-07-31 18:12     ` What is acceptable for -ffast-math? (Was: associative law incombine) Linus Torvalds
2001-08-01  8:55   ` Theodore Papadopoulo [this message]
2001-08-01  9:15     ` What is acceptable for -ffast-math? (Was: associative law in combine) Gabriel Dos Reis
2001-08-01 11:21       ` Theodore Papadopoulo
2001-08-01 11:44         ` Gabriel Dos Reis
2001-08-01 11:58           ` What is acceptable for -ffast-math? (Was: associative law incombine) Linus Torvalds
2001-08-01  9:24     ` What is acceptable for -ffast-math? (Was: associative law in combine) Tim Hollebeek
2001-08-01  9:54       ` What is acceptable for -ffast-math? (Was: associative law incombine) Linus Torvalds
2001-08-01 10:26         ` Gabriel Dos_Reis
2001-08-01 10:35           ` Linus Torvalds
2001-08-01 10:45             ` Gabriel Dos_Reis
2001-08-01 11:13           ` What is acceptable for -ffast-math? (Was: associative law in combine) Alexandre Oliva
2001-08-01 11:36             ` Gabriel Dos Reis
2001-08-01 12:07               ` Alexandre Oliva
2001-08-01 13:21                 ` Gabriel Dos_Reis
2001-08-01 14:20                   ` Toon Moene
  -- strict thread matches above, loose matches on Subject: below --
2001-08-03 14:48 dewar
2001-08-02  3:37 Vincent Penquerc'h
2001-08-01 19:04 Carlo Wood
2001-08-01 12:06 Phil Edwards
2001-08-01 10:39 dewar
2001-08-01 10:38 dewar
2001-08-01 10:13 dewar
2001-08-01 10:05 dewar
2001-08-01 10:04 dewar
2001-08-01 10:28 ` Gabriel Dos_Reis
2001-08-01  9:59 dewar
2001-08-01  9:58 What is acceptable for -ffast-math? (Was: associative law incombine) Gabriel Dos_Reis
2001-08-01 10:08 ` Wolfgang Bangerth
2001-08-01 11:12   ` Gabriel Dos_Reis
2001-08-01 11:27     ` What is acceptable for -ffast-math? (Was: associative law in combine) Theodore Papadopoulo
2001-08-01 11:47       ` Gabriel Dos_Reis
2001-08-03  7:32         ` Nick Ing-Simmons
2001-08-03  6:01     ` Per Abrahamsen
2001-08-01  6:52 dewar
2001-08-01  6:04 dewar
2001-08-01  6:48 ` Vincent Penquerc'h
2001-08-03  0:46 ` Eric W. Biederman
2001-08-01  3:02 Vincent Penquerc'h
2001-07-31 19:10 dewar
2001-07-31 18:23 dewar
2001-07-31 18:20 dewar
2001-07-31 18:50 ` Joern Rennecke
2001-07-31 21:27   ` Tim Prince
2001-07-31 18:15 dewar
2001-07-31 18:12 What is acceptable for -ffast-math? (Was: associative law incombine) Linus Torvalds
2001-07-31 20:55 ` What is acceptable for -ffast-math? (Was: associative law in combine) Gabriel Dos Reis
2001-07-31 17:37 dewar
2001-07-31 16:38 dewar
2001-07-31  9:22 mike stump
2001-07-31  8:37 dewar
2001-07-31  8:36 dewar
2001-07-31  8:36 mike stump
2001-07-31  8:35 dewar
2001-07-31  8:19 mike stump
2001-07-31  7:59 mike stump
2001-07-31  7:26 dewar
2001-07-31 15:57 ` Toon Moene
2001-07-31 21:55   ` Tim Prince
2001-08-03  6:12 ` Per Abrahamsen
2001-07-30 20:54 dewar
2001-07-30 21:11 ` Gabriel Dos Reis
2001-07-30 21:39 ` Joern Rennecke
2001-07-30 19:46 dewar
2001-07-30 20:00 ` Gabriel Dos Reis
2001-07-30 20:20   ` Alexandre Oliva
2001-07-30 20:25     ` Gabriel Dos Reis
2001-07-30 18:39 dewar
2001-07-30 18:38 dewar
2001-07-30 18:08 dewar
2001-07-30 18:02 dewar
2001-07-30 18:00 dewar
2001-07-30 18:25 ` Joe Buck
2001-07-30 16:11 dewar
2001-07-30 16:29 ` Alexandre Oliva
2001-07-31  8:13   ` Kevin Handy
2001-07-30 15:29 dewar
2001-07-30 15:39 ` Toon Moene
2001-07-30 13:10 dewar
2001-07-30 12:26 dewar
2001-07-30 11:52 dewar
2001-07-30 11:37 What is acceptable for -ffast-math? (Was: associative law incombine) Linus Torvalds
2001-07-30 11:53 ` What is acceptable for -ffast-math? (Was: associative law in combine) Gabriel Dos Reis
2001-07-30 18:40   ` Olivier Galibert
2001-07-30 19:06     ` Gabriel Dos Reis
2001-07-31  1:35   ` Linus Torvalds
2001-07-31  2:04     ` Gabriel Dos Reis
2001-07-31  2:35       ` Olivier Galibert
2001-07-31  2:58         ` Gabriel Dos Reis
2001-07-31 18:10       ` Linus Torvalds
2001-07-30  8:59 mike stump
2001-07-30  6:14 dewar
2001-07-30  8:30 ` Kevin Handy
2001-07-30  6:01 dewar
2001-07-30  6:53 ` Tim Hollebeek
2001-07-30  6:00 dewar
2001-07-30 13:08 ` Toon Moene
2001-07-30  5:57 dewar
2001-07-29 21:33 What is acceptable for -ffast-math? (Was: associative law incombine) Linus Torvalds
2001-07-30 14:43 ` What is acceptable for -ffast-math? (Was: associative law in combine) Alexandre Oliva
2001-07-30 15:45   ` Neil Booth
2001-07-30 16:03     ` Alexandre Oliva
2001-07-30 16:11       ` Neil Booth
2001-07-30 16:28         ` Alexandre Oliva
2001-07-30 19:08   ` Joern Rennecke
2001-07-30 19:22     ` Alexandre Oliva
2001-07-30 19:29       ` Gabriel Dos Reis
2001-07-30 19:34         ` Alexandre Oliva
2001-07-30 19:54           ` Gabriel Dos Reis
2001-07-30 19:27     ` Gabriel Dos Reis
2001-07-29 14:22 dewar
2001-07-29 12:52 * Re: What is acceptable for -ffast-math? (Was: associative lawin combine) Linus Torvalds
2001-07-29 14:03 ` What is acceptable for -ffast-math? (Was: associative law incombine) Stephen L Moshier
2001-07-29 21:17   ` What is acceptable for -ffast-math? (Was: associative law in combine) Fergus Henderson
2001-07-30  0:23     ` Gabriel Dos Reis
2001-07-17 15:59 associative law in combine Joern Rennecke
2001-07-18  1:01 ` Toon Moene
2001-07-18  1:47   ` What is acceptable for -ffast-math? (Was: associative law in combine) Jan Hubicka
2001-07-28 23:04     ` Tim Prince
2001-07-29  6:33       ` Jan Hubicka
2001-07-29 10:18         ` Tim Prince
2001-07-29 10:26           ` Jan Hubicka
2001-07-29 12:11             ` Tim Prince
2001-07-29 12:17               ` Jan Hubicka
2001-07-29 10:50       ` Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200108011555.f71Ft4q07786@mururoa.inria.fr \
    --to=theodore.papadopoulo@sophia.inria.fr \
    --cc=amylaar@redhat.com \
    --cc=aoliva@redhat.com \
    --cc=dewar@gnat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=gdr@codesourcery.com \
    --cc=moshier@moshier.ne.mediaone.net \
    --cc=torvalds@transmeta.com \
    --cc=tprince@computer.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).