[Cfp-interest] functions: thoughts on reduction exceptions
David Hough CFP
pcfp at oakapple.net
Thu Aug 5 17:09:31 PDT 2010
Comments on exception handling in reductions functions
The intent is that these functions be used when the programmer does not
require that the associative operations be evaluated in any particular
order. From that point of view they are intended to be efficient.
They may be implemented as simple loops over multiple threads, unless...
The semantics of signaling NaN operands and invalid operations
(0xinf, inf-inf) are rather tightly specified.
Simple loops won't provide the correct answer.
The unscaled operations should not signal overflow or underflow unless
that indicates the quality of the final answer.
The scaled operations should not signal overflow or underflow at all.
How can that be accomplished?
The general idea is
save the exception state
set default exception state
try the fast obvious algorithm, perhaps over multiple threads
if there are no exceptions restore the exception state and return
if inexact is the only exception, restore the exception state
and signal inexact
if there were any other exceptions, restore the exception state
and recompute slowly and carefully:
if there are any signaling nans,
signal invalid and return a quiet nan
if there are any quiet nans,
return a quiet nan
if there are any 0xinf or inf-inf invalid operations,
signal invalid and return a quiet nan
if the problem was overflow or underflow,
compute a scaled result using logb/scalb,
then for scaled functions:
return the result and scale factor
for unscaled functions:
perform a final scalb operation to
signal overflow or underflow
It is not the intent that the final result be correctly rounded
or that it be reproducible across systems.
Switching from the fast to the slow algorithm can be triggered by examining
flags at the end of the fast algorithm, or by enabling alternate exception
handling in the fast algorithm to break on any exception except inexact.
More information about the Cfp-interest
mailing list