Usenet comp.os.linux.alpha (1997-2013)
 help / color / mirror / Atom feed
From: Joachim Wesner <joachim.wesner@frankfurt.netsurf.de>
Subject: Re: Alpha's floating point performance -> single vs. double
Date: 1998/11/21	[thread overview]
Message-ID: <3656F268.F24774B@frankfurt.netsurf.de> (raw)
In-Reply-To: 731iaq$lsc$1@tesla.EECS.Berkeley.EDU

Hi,

I think I should comment on that, especially from the view of the libffm
math lib. First, I will try to summarize the thread a bit.

Peter Mardahl wrote:
> >
> >> For our simulation code, which does lots of adds and multiplies and
> >> almost no divisions, sqrts, logs, or any other complex functions,
> >> we get a 1.7 or so speedup by using single precision.  I don't
> >> think the adds and multiplies happen any faster, really.  I think
> >> the memory access is much improved:  the data cache suddenly looks twice
> >> as large, the bandwidth gives 2x as much throughput per flop.....
> >

YEP, the main performance limit for BIG problems like that is not CPU
math performance, but main memory access speed and (probably)
interaction with/perfomance of the caches. Those are immdiatelly
"doubled" when using single instead of double precision. Sometimes, when
dealing with very large matrixes, as I hit on some times, you simply
don't have enough main memory to solve the problem in double !!

> >That's some interesting results. I don't know about the Alpha hardware,
> >but I was under the impression that most modern CPU's simplify things by
> >only having the hardware for double precision operations. This usually
> >means that single precision is actually slower since the data has to be
> >converted both before and after each operation.

YES, and even K&R C defines any math operation to happen in double and
there are no float functions in that old original C (see below) !!

> Alpha has hardware instructions for dealing with single precision.
> I think you're right in that the same execution units
> are used for all precisions,
> but I suspect that the execution units are organized in such a way that
> either there is no conversion needed, or conversion is so fast that
> the ops are no slower.

Robert Harley wrote:
>
> That's about it.  Single-precision numbers are "expanded" into
> numerically equivalent double-precision ones in the floating-point
> registers.  Each f.-p. operation specifies whether the result is to be
> single or double precision, which affects rounding, exponent checking
> etc.

EXACTLY.

> 
> I'm not quite sure what happens if you ask for a single precision
> result operating on double-precision quantities that are not equal to
> expanded single-precision ones, though.
> 
Andreas Krall wrote:
> 
> The Alpha manual tells:
> 
> Single-precision operations applied to canonical single-precision values
> give single-precision results. Single-precision operations applied to
> non-canonical operands give UNPREDICTABLE results.
> 
> No conversion from single to double is needed, since both use the same
> representation in a register. A double has to be converted to a single
> and this instruction (CVTTS) can throw exeptions.
> 

However, the idea of treating a single as a special or better restricted
kind of a double even means that you usually do not need the conversion
and no time is lost, but I'm not sure (I would need to check) how the
various (DEC, gcc and egcs) compilers handle that, i.e.

You can store a canonical single in the fpu to a double memory variable
with "stt" and everything will be OK. Vice-versa, you can store a full
double using "sts" to a single memory variable, "sts" will simply
re-arrange the bits (with no extra delay) to the single prec.form, AND,
as long as the exponent was in the valid range for a single, the only
small difference compared to using cvtts will be that the very last bit
may be rounded incorrectly (chopped instead).

> >I take it your code is a "real world" application? I'm guessing that your
> >code is faster because you have to do something with the results of the
> >calculations. The bandwidth saving out-weighs any overhead to convert to
> >and from double precision.
>

And for special routines, like the function routines, when you know the
(valid) argument and or result being in a limited domain, you probably
can omit any explicit conversion at all.

Back to routines like libffm. Actually, as somebody already suggested,
it really might make sense to have an faster math library that is
probably limited to single precision (i.e. 5e-8 rel. error). Somebody
pointed me to the work Motorola did for the PowerPC resp. MkLinux, where
they brought out an alternative fast math library called libmoto, (only
including some functions, but here really NO SOURCE is available, it
seems is's mostly table based, see also below) and the BeOS people now
topped that with even faster, single precision routines (fastmath),
where part of them is only valid over a small range of arguments. (I
couldn't find any source for those either, anybody knows ????)

Actually I planned and still would love to have such single precision
equivalents of the functions in libffm, but I likely won't attack this
before libffm has majored more. libffm.0.30 should come out soon,
including also hyperbolic and other small helper functions and now
including full argument checking, so that the claims/impressions that I
read in some places, that it's only accurate over a very limited domain,
should disappear (it always was accurate over the full domain of
**valid**, **normalized** arguments, besides a small bug in atan2, if
somebody knows about something different, please mail me function,
argument and result). BTW, some limited precision functions are in the
port of Crays libfm.0.90 : exp32 and log32.

HOWEVER, I would not expect too big a speedup when going to single
precision functions. The whole arithmetic would remain in double, as it
involves nearly no penalty, and you likely will want to keep the full
range of arguments/results (up to 1e308 instead of 1e38, for example),
and you are still compatible to good old C, in that (math) functions are
all double by definition. THE ONE big difference will be that you only
need a simpler approximation for single precision. For tan, for example,
a 6th order polynomial is good enough instead of a 11th one. YET,
depending on how exactly you calculate the polynomial, this can mean a
difference of 40 clocks (if you use the straight, dumb, Horner's scheme
that can not be evaluated in parallel) down to ~ < 10 clocks if you
(unrealistically) could fully parallelize the polynomial evaluation (on
the 21164) Using something similar to Estrin's method, as it's also used
in libffm, the difference will be very likely in the range of < 20
clocks and probably meaning a reduction of only 15% to 20% for the pure
function routine. Clearly, you would keep the polynomial coefficients as
singles here, decreasing the memory "footprint" of the function routine
and reducing cache trashing and first call overhead time.

Furthermore, before really attacking single precision routines, I will
try my hands on an alternative table based , double prec. version, to be
called "libtfm", which should be as fast a DECs routines, with last bit
accuracy, and hopefully smaller memory footprint, to decrease cache
trashing problems in real-world applications (instead of only giving
fantastic numbers in benchmarks, where everything stays in the cache).
The clue is here that popular methods as IBMs "accurate tables method"
(and DEC seems to use something similar, but not identical, as a first
analysis shows) "traditionally" use pretty large tables: The general
recommendation is to use 256 table entries of up to 4 double precision
values, i.e. a table of 8kb for (nearly) any function. I will try to get
away with only 16 or 32 entries, and apply a somewhat more complicated
"interpolation" in the subdomain, as this will add only few clocks as
shown above, but could save many if cache space becomes scarse.


Hope this cleared up some points ! (Also the point that progress is
still made on libffm, it's only that due to changes in work schedule in
the company I work for, I had to travel a lot in the last 2 month and
could not continue on libffm).


Joachim



  parent reply	other threads:[~1998-11-21  5:00 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-11-06  5:00 Alpha's floating point performance Vladimir Filkov
1998-11-07  5:00 ` Greg Lindahl
1998-11-07  5:00   ` Kerstin Hoef-Emden
1998-11-09  5:00     ` Adam C. Powell, IV
1998-11-09  5:00       ` Tracy R Reed
1998-11-09  5:00         ` Adam C. Powell, IV
1998-11-10  5:00           ` bmeyer
1998-11-10  5:00           ` IX Corp.
1998-11-17  5:00             ` Randall Parker
1998-11-17  5:00               ` Joachim Wesner
1998-11-18  5:00                 ` Randall Parker
1998-11-18  5:00                   ` Peter Mardahl
1998-11-19  5:00                     ` Ian Tester
1998-11-19  5:00                       ` Peter Mardahl
1998-11-19  5:00                         ` Robert Harley
1998-11-19  5:00                           ` Andreas Krall
1998-11-19  5:00                             ` Toon Moene
     [not found]                         ` <199811200036.AA23893@tesla.EECS.Berkeley.EDU>
1998-11-20  5:00                           ` Ian Tester
1998-11-20  5:00                         ` Ian Tester
1998-11-21  5:00                         ` Joachim Wesner [this message]
1998-11-23  5:00                         ` Jack W. Crenshaw
1998-11-23  5:00                           ` Peter Mardahl
1998-11-24  5:00                             ` Jack W. Crenshaw
1998-11-24  5:00                               ` Olaf Schnapauff
1998-11-25  5:00                                 ` Jack W. Crenshaw
1998-11-25  5:00                               ` Aaron Spink
1998-11-25  5:00                                 ` Jack W. Crenshaw
1998-11-23  5:00                           ` H.W. Stockman
1998-11-10  5:00           ` Adam C. Powell, IV
1998-11-11  5:00         ` Kerstin Hoef-Emden
1998-11-13  5:00           ` Phil
1998-11-13  5:00             ` Kerstin Hoef-Emden
1998-11-13  5:00             ` Murx
1998-11-13  5:00               ` Joachim Wesner
1998-11-13  5:00                 ` Murx
1998-11-13  5:00                   ` Murx
1998-11-11  5:00       ` H.W. Stockman
1998-11-11  5:00       ` Greg Lindahl
1998-11-07  5:00 ` Nick Manka
1998-11-07  5:00 ` C.Simmendinger
1998-11-09  5:00 ` Doug Rosser
1998-11-10  5:00   ` bxfqoxog
1998-11-10  5:00     ` energized
1998-11-11  5:00     ` bmeyer
1998-11-11  5:00       ` Integer performance (was Re: Alpha's floating point performance) S S Sturrock
1998-11-12  5:00         ` Murx
1998-11-11  5:00     ` Alpha's floating point performance Conrad Sanderson
1998-11-11  5:00       ` Greg Lindahl
1998-11-11  5:00         ` Conrad Sanderson
1998-11-15  5:00     ` Andy Isaacson
1998-11-16  5:00     ` Murx
1998-11-16  5:00       ` Vinhthuy Phan
1998-11-16  5:00         ` Murx
1998-11-16  5:00       ` Joachim Wesner
1998-11-16  5:00         ` Murx
1998-11-16  5:00           ` Murx
1998-11-17  5:00           ` Joachim Wesner
1998-11-17  5:00             ` Murx
1998-11-17  5:00               ` Murx
1998-11-27  5:00                 ` Anders Blicher Petersen
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox