CSRFunctions
#include <poplar/CSRFunctions.hpp>
-
namespace poplar
Poplar classes and functions.
Functions
-
void setFloatingPointBehaviour(poplar::Graph &graph, poplar::program::Sequence &prog, const FloatingPointBehaviour &behaviour, const DebugContext &debugContext = {})
Set the floating point behaviour of a tile.
Configures the floating point behaviour of a tile, affecting the treatment of exceptions and selecting stochastic rounding according to the passed
behaviour
structure.Note that, in Poplar, stochastic rounding is disabled by default until either this function, setStochasticRounding() or the Engine options are used to enable it.
- Parameters
graph – The Poplar graph.
prog – The program to be extended.
behaviour – A structure of type floatingPointBehaviour.
debugPrefix – The prefix prepended to debugging info.
-
void setFloatingPointBehaviour(poplar::Graph &graph, poplar::program::Sequence &prog, const poplar::Tensor &behaviour, const DebugContext &debugContext = {})
Set the floating point behaviour of a tile.
Configures the floating point behaviour of a tile, affecting the treatment of exceptions and selecting stochastic rounding according to the passed
behaviour
tensor.The behaviour tensor must be one returned by getAndModifyFloatingPointBehaviour().
- Parameters
graph – The Poplar graph.
prog – The program to be extended.
behaviour – A tensor containing representation of floatingPointBehaviour.
debugPrefix – The prefix prepended to debugging info.
-
void setStochasticRounding(poplar::Graph &graph, poplar::program::Sequence &prog, bool behaviour, const DebugContext &debugContext = {})
Set stochastic rounding on or off for the selected tile.
Configures the stochastic rounding operation of a tile according to the passed
behaviour
parameter.Note that, in Poplar, stochastic rounding is disabled by default until either this function, setFloatingPointBehaviour() or the Engine options are used to enable it.
- Parameters
graph – The Poplar graph.
prog – The program to be extended.
behaviour – Select stochastic rounding: true or false.
debugPrefix – The prefix prepended to debugging info.
-
poplar::Tensor getAndModifyFloatingPointBehaviour(poplar::Graph &graph, poplar::program::Sequence &prog, const FloatingPointBehaviour &clear, const FloatingPointBehaviour &set, const DebugContext &debugContext = {})
Get the current state and modify the floating-point behaviour on every tile that belongs to the target in the graph.
Returns the previous state and modifies the behaviour. Behaviour modification first clears the behaviours set in
clear
followed by setting the behaviours set inset
.This can be used to set the behaviour for a section of code, and then restore the original behaviour afterwards. The recommended usage of this function should be as follows to avoid unexpected numerical behaviour:
... auto state = getAndModifyFloatingPointBehaviour(...) // operations that require the modified FP behaviour ... setFloatingPointBehaviour(state)
- Parameters
graph – The Poplar graph.
prog – The program to be extended.
clear – Select the behaviours to clear. If a field in
clear
is set to true, then that behaviour will be cleared. If a field is false then the behaviour is unchanged.set – Select behaviours to set. If a field in
set
is set to true, then that behaviour will be set. The values inset
are applied after the values inclear
. So if a field is set to true in bothclear
andset
, then the behaviour will be set.debugPrefix – The prefix prepended to debugging info.
- Returns
The state before the floating-point behaviour is modified.
-
struct FloatingPointBehaviour
- #include <CSRFunctions.hpp>
Structure to specify floating point behaviour.
- Param inv
If true, a floating-point invalid operation (defined by IEEE 754) will cause an exception.
The invalid operations are:
Addition or subtraction where the operands are + or - infinity (inf) and the operation results in the subtraction of two infs; for example: (-inf)+(+inf) or (+inf)-(+inf).
Divisions: (+/-0)/(+/-0) and (+/-inf)/(+/-inf).
Multiplications: (+/-0)*(+/-inf) and (+/-inf)*(+/-0).
Remainder: x REM y where y=0 or x=(+/-inf).
Real operations with complex results such as the square root or logarithm of a negative number.
Operations with Not-a-Number as at least one operand.
Comparisons where one of the operands is Not-a-Number.
See also nanoo below. It can also be set in the environment variable
POPLAR_ENGINE_OPTIONS
by settingdebug.floatPointOpException
to true.
- Param div
If true a floating point divide by zero operation will cause an exception.
- Param oflo
If true a floating point overflow will cause an exception.
- Param esr
Enable stochastic rounding.
- Param nanoo
Enable Not-a-Number on overflow mode. When enabled, half precision calculations that have overflowed will produce a Not-a-Number result, rather than saturating to the half precision max/min value, and the invalid operation (
inv
) flag will be set. It can also be enabled in the environment variablePOPLAR_ENGINE_OPTIONS
by settingdebug.nanOverflowMode
to true.
Public Functions
-
inline FloatingPointBehaviour(bool inv, bool div0, bool oflo, bool esr, bool nanoo)
-
FloatingPointBehaviour() = default
-
inline FloatingPointBehaviour operator!() const
-
void setFloatingPointBehaviour(poplar::Graph &graph, poplar::program::Sequence &prog, const FloatingPointBehaviour &behaviour, const DebugContext &debugContext = {})