ScaledAdd
#include <popops/ScaledAdd.hpp>
Functions for scaling and adding tensors.

namespace popops
Common functions, such as elementwise and reductions.
map
Map an expression across tensors.
Elementwise Options
enableGenerateCodelet
(true, false) [=true]When true and the following conditions are met, poplar will generate a codelet to execute the map operation. Otherwise, it will sequence poplibs codelets to create the expression.
All of the inputs are of the same size
Inputs do not alias
Multiple operations are being performed
mapInPlace
Update the input tensors with the result of map().
mapWithOutput
Write the result of map() to the given output tensor.
checkTypes
Check that the host compiletime type
constType
is compatible with the runtime IPU typeelementType
. param elementType
The runtime IPU type.
 param constant
Unused.
 tparam constType
The host compiletime type.
 throws std::runtime_error
If the types are not compatible.
varianceToInvStdDev
Convert variance to inverse standard deviation.
Each element in the output tensor is the result of
1 / sqrt(variance_value + epsilon)
, wherevariance_value
is the corresponding element invariance
.Warning
If
variance_value + epsilon
is zero then the result will be invalid and this operation could generate a dividebyzero floatingpoint exception (if enabled). param graph
The graph to update.
 param variance
A tensor of variance values.
 param epsilon
A (typically small) scalar to add to the variance values, to avoid numerical issues (for example, divide by zero).
 param prog
The sequence of programs to append this conversion operation to.
 param debugContext
Optional debug information.
 return
A tensor where each element is the inverse standard deviation.
invStdDevToVariance
Convert inverse standard deviation to variance.
Each element in the output tensor is the result of
1 / (invStdDev_value + epsilon)^2
, whereinvStdDev_value
is the corresponding element ininvStdDev
.Warning
If
invStdDev_value + epsilon
is zero then the result will be invalid and this operation could generate a dividebyzero floatingpoint exception (if enabled). param graph
The graph to update.
 param invStdDev
A tensor of inverse standard deviation values.
 param epsilon
A (typically small) scalar to add to the variance values, to avoid numerical issues (for example, divide by zero).
 param prog
The sequence of programs to append this conversion operation to.
 param debugContext
Optional debug information.
 param options
A list of flags to pass to the expression evaluator.
 return
A tensor where each element is the variance.
add
Add each element in
A
to the corresponding element inB
. param graph
The graph to update.
 param A
A tensor of elements.
 param B
A tensor of elements.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information
 param options
Elementwise options. See map().
 return
A tensor where each element is the result of
a + b
, wherea
andb
are the corresponding elements ofA
andB
tensors respectively.
addInPlace
Update the tensor
A
with the result of add().See add() for parameter descriptions.
addWithOutput
Write the result of add() to the given output tensor,
out
.See add() for the remaining parameter descriptions.
 param out
The tensor to write the results to.
sub
Subtract the elements of
B
fromA
and return the result in a new tensor. param graph
The graph to update.
 param A
The tensor of elements which will be subtracted from.
 param B
The tensor of elements to subtract from
A
. param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information.
 param options
Elementwise options. See map().
 return
A tensor where each element is equal to a  b, where
a
andb
are the corresponding elements ofA
andB
tensors respectively.
subInPlace
Update the tensor
A
with the result of sub().See sub() for parameter descriptions.
subWithOutput
Write the result of sub() to the given output tensor,
out
.See sub() for the remaining parameter descriptions.
 param out
The tensor to write the results to.
mul
Multiply each element in
A
by the corresponding element inB
. param graph
The graph to update.
 param A
A tensor of elements.
 param B
A tensor of elements.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information.
 param options
Elementwise options. See map().
 return
A tensor where each element is the result of
a * b
, wherea
andb
are the corresponding elements ofA
andB
tensors respectively.
mulInPlace
Update the tensor
A
with the result of mul().See mul() for parameter descriptions.
mulWithOutput
Write the result of mul() to the given output tensor,
out
.See mul() for the remaining parameter descriptions.
 param out
The tensor to write the results to.
div
Divide each element in
A
by the corresponding element inB
. param graph
The graph to update.
 param A
The tensor of dividends.
 param B
The tensor of divisors.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information
 param options
Elementwise options. See map().
 return
A tensor where each element is the result of
a / b
, wherea
andb
are the corresponding elements ofA
andB
tensors respectively.
divInPlace
Update the tensor
A
with the result of div().See div() for parameter descriptions.
divWithOutput
Write the result of div() to the given output tensor,
out
.See div() for the remaining parameter descriptions.
 param out
The tensor to write the results to.
pow
Compute each element in
A
to the power of the corresponding element inB
. param graph
The graph to update.
 param A
The tensor of bases.
 param B
The tensor of exponents.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information.
 param options
Elementwise options. See map().
 return
A tensor where each element is equal to
pow(a, b)
, wherea
andb
are the corresponding elements ofA
andB
tensors respectively.
powInPlace
Update the tensor
A
with the result of pow().See pow() for parameter descriptions.
powWithOutput
Write the result of pow() to the given output tensor,
out
.See pow() for the remaining parameter descriptions.
 param out
The tensor to write the results to.
rem
Compute the remainder of each element in
A
divided by the corresponding element inB
. param graph
The graph to update.
 param A
The tensor of dividends.
 param B
The tensor of divisors.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information.
 param options
Elementwise options. See map().
 return
A tensor where each element is equal to a % b, where
a
andb
are the corresponding elements ofA
andB
tensors respectively.
remInPlace
Update the tensor
A
with the result of rem().See rem() for parameter descriptions.
remWithOutput
Write the result of rem() to the given output tensor,
out
.See rem() for the remaining parameter descriptions.
 param out
The tensor to write the results to.
bitwiseAnd
Compute the bitwise AND of each element in
A
with the corresponding element inB
. param graph
The graph to update.
 param A
A tensor of elements.
 param B
A tensor of elements.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information
 param options
Elementwise options. See map().
 return
A tensor where each element is the result of
a & b
, wherea
andbare
the corresponding elements ofA
andB
tensors respectively.
bitwiseAndInPlace
Update the tensor
A
with the result of bitwiseAnd().See bitwiseAnd() for parameter descriptions.
bitwiseAndWithOutput
Write the result of bitwiseAnd() to the given output tensor,
out
.See bitwiseAnd() for the remaining parameter descriptions.
 param out
The tensor to write the results to.
bitwiseOr
Compute the bitwise OR of each element in
A
with the corresponding element inB
. param graph
The graph to update.
 param A
A tensor of elements.
 param B
A tensor of elements.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information
 param options
Elementwise options. See map().
 return
A tensor where each element is the result of
a  b
, wherea
andb
are the corresponding elements ofA
andB
tensors respectively.
bitwiseOrInPlace
Update the tensor
A
with the result of bitwiseOr().See bitwiseOr() for parameter descriptions.
bitwiseOrWithOutput
Write the result of bitwiseOr() to the given output tensor,
out
.See bitwiseOr() for the remaining parameter descriptions.
 param out
The tensor to write the results to.
bitwiseXor
Compute the bitwise XOR of each element in
A
with the corresponding element inB
. param graph
The graph to update.
 param A
A tensor of elements.
 param B
A tensor of elements.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information
 param options
Elementwise options. See map().
 return
A tensor where each element is the result of
a ^ b
, wherea
andb
are the corresponding elements ofA
andB
tensors respectively.
bitwiseXorInPlace
Update the tensor
A
with the result of bitwiseXor().See bitwiseXnor() for parameter descriptions.
bitwiseXorWithOutput
Write the result of bitwiseXor() to the given output tensor,
out
.See bitwiseXor() for the remaining parameter descriptions.
 param out
The tensor to write the results to.
bitwiseXnor
Compute the bitwise XNOR of each element in
A
with the corresponding element inB
. param graph
The graph to update.
 param A
A tensor of elements.
 param B
A tensor of elements.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information
 param options
Elementwise options. See map().
 return
A tensor where each element is the result of
!(a ^ b)
, wherea
andb
are the corresponding elements ofA
andB
tensors respectively.
bitwiseXnorInPlace
Update the tensor
A
with the result of bitwiseXnor().See bitwiseXnor() for parameter descriptions.
bitwiseXnorWithOutput
Write the result of bitwiseXnor() to the given output tensor,
out
.See bitwiseXnor() for the remaining parameter descriptions.
 param out
The tensor to write the results to.
shiftLeft
Shift the elements of
A
left by the corresponding elements ofB
. param graph
The graph to update.
 param A
The tensor of elements which to leftshift.
 param B
The tensor of elements that describe the amount to leftshift
A
by. param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information.
 param options
Elementwise options. See map().
 return
A tensor where each element is equal to a << b, where
a
andb
are the corresponding elements ofA
andB
tensors respectively.
shiftLeftInPlace
Update the tensor
A
with the result of shiftLeft().See shiftLeft() for parameter descriptions.
shiftLeftWithOutput
Write the result of shiftLeft() to the given output tensor,
out
.See shiftLeft() for the remaining parameter descriptions.
 param out
The tensor to write the results to.
shiftRight
Shift the elements of
A
right by the corresponding elements ofB
. param graph
The graph to update.
 param A
The tensor of elements which to rightshift.
 param B
The tensor of elements that describe the amount to rightshift by.
A
. param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information.
 param options
Elementwise options. See map().
 return
A tensor where each element is equal to a >> b (without sign extension), where
a
andb
are the corresponding elements ofA
andB
tensors respectively.
shiftRightInPlace
Update the tensor
A
with the result of shiftRight().See shiftRight() for parameter descriptions.
shiftRightWithOutput
Write the result of shiftRight() to the given output tensor,
out
.See shiftRight() for the remaining parameter descriptions.
 param out
The tensor to write the results to.
shiftRightSignExtend
Shift the elements of
A
right with sign extension by the corresponding elements ofB
. param graph
The graph to update.
 param A
The tensor of elements which to rightshift.
 param B
The tensor of elements that describe the amount to rightshift
A
by. param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information.
 param options
Elementwise options. See map().
 return
A tensor where each element is equal to
a >> b
with sign extension, wherea
andb
are the corresponding elements ofA
andB
tensors respectively.
shiftRightSignExtendInPlace
Update the tensor
A
with the result of shiftRightSignExtend().See shiftRightSignExtend() for parameter descriptions.
shiftRightSignExtendWithOutput
Write the result of shiftRightSignExtend() to the given output tensor,
out
.See shiftRightSignExtend() for the remaining parameter descriptions.
 param out
The tensor to write the results to.
logicalAnd
Compute the logical AND (
&&
) of each element inA
with the corresponding element inB
. param graph
The graph to update.
 param A
A tensor of elements.
 param B
A tensor of elements.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information.
 param options
Elementwise options. See map().
 return
A tensor where each element is the result of
a && b
, wherea
andb
are the corresponding elements ofA
andB
tensors respectively.
logicalAndInPlace
Update the tensor
A
with the result of logicalAnd().See logicalAnd() for parameter descriptions.
logicalAndWithOutput
Write the result of logicalAnd() to the given output tensor,
out
.See logicalAnd() for the remaining parameter descriptions.
 param out
The tensor to write the booleans to.
logicalOr
Compute the logical OR (

) of each element inA
with the corresponding element inB
. param graph
The graph to update.
 param A
A tensor of elements.
 param B
A tensor of elements.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information.
 param options
Elementwise options. See map().
 return
A tensor where each element is the result of
a  b
, wherea
andb
are the corresponding elements ofA
andB
tensors respectively.
logicalOrInPlace
Update the tensor
A
with the result of logicalOr().See logicalOr() for parameter descriptions.
logicalOrWithOutput
Write the result of logicalOr() to the given output tensor,
out
.See logicalOr() for the remaining parameter descriptions.
 param out
The tensor to write the booleans to.
eq
Check if each element in
A
is equal to the corresponding element inB
. param graph
The graph to update.
 param A
A tensor of elements.
 param B
A tensor of elements.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information
 param options
Elementwise options. See map().
 return
A tensor where each element is the result of
a == b
, wherea
andb
are the corresponding elements ofA
andB
tensors respectively.
eqInPlace
Update the tensor
A
with the result of eq().See eq() for parameter descriptions.
eqWithOutput
Write the result of eq() to the given output tensor,
out
.See eq() for the remaining parameter descriptions.
 param out
The tensor to write the booleans to.
neq
Check if each element in
A
is not equal to the corresponding element inB
. param graph
The graph to update.
 param A
A tensor of elements.
 param B
A tensor of elements.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information.
 param options
Elementwise options. See map().
 return
A tensor where each element is the result of
a != b
, wherea
andb
are the corresponding elements ofA
andB
tensors respectively.
neqInPlace
Update the tensor
A
with the result of neq().See neq() for parameter descriptions.
neqWithOutput
Write the result of neq() to the given output tensor,
out
.See neq() for the remaining parameter descriptions.
 param out
The tensor to write the booleans to.
gteq
Check if each element in
A
is greater than or equal to the corresponding element inB
. param graph
The graph to update.
 param A
A tensor of elements.
 param B
A tensor of elements.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information
 param options
Elementwise options. See map().
 return
A tensor where each element is the result of
a >= b
, wherea
andb
are the corresponding elements ofA
andB
tensors respectively.
gteqInPlace
Update the tensor
A
with the result of gteq().See gteq() for parameter descriptions.
gteqWithOutput
Write the result of gteq() to the given output tensor,
out
.See gteq() for the remaining parameter descriptions.
 param out
The tensor to write the booleans to.
gt
Check if each element in
A
is greater than the corresponding element inB
. param graph
The graph to update.
 param A
A tensor of elements.
 param B
A tensor of elements.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information
 param options
Elementwise options. See map().
 return
A tensor where each element is the result of
a > b
, wherea
andb
are the corresponding elements ofA
andB
tensors respectively.
gtInPlace
Update the tensor
A
with the result of gt().See gt() for parameter descriptions.
gtWithOutput
Write the result of gt() to the given output tensor,
out
.See gt() for the remaining parameter descriptions.
 param out
The tensor to write the booleans to.
lteq
Check if each element in
A
is less than or equal to the corresponding element inB
. param graph
The graph to update.
 param A
A tensor of elements.
 param B
A tensor of elements.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information.
 param options
Elementwise options. See map().
 return
A tensor where each element is the result of
a <= b
, wherea
andb
are the corresponding elements ofA
andB
tensors respectively.
lteqInPlace
Update the
A
with the result of lteq().See lteq() for parameter descriptions.
lteqWithOutput
Write the result of lteq() to the given output tensor,
out
.See lteq() for the remaining parameter descriptions.
 param out
The tensor to write the booleans to.
lt
Check if each element in
A
is less than the corresponding element inB
. param graph
The graph to update.
 param A
A tensor of elements.
 param B
A tensor of elements.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information.
 param options
Elementwise options. See map().
 return
A tensor where each element is the result of
a < b
, wherea
andb
are the corresponding elements ofA
andB
tensors respectively.
ltInPlace
Update the
A
with the result of lt().See lt() for parameter descriptions.
ltWithOutput
Write the result of lt() to the given output tensor,
out
.See lt() for the remaining parameter descriptions.
 param out
The tensor to write the boolean results to.
max
Compute the maximum of each element in
A
with the corresponding element inB
. param graph
The graph to update.
 param A
A tensor of elements.
 param B
A tensor of elements.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information.
 param options
Elementwise options. See map().
 return
A tensor where each element is the result of
max(a, b)
, wherea
andb
are the corresponding elements ofA
andB
tensors respectively.
maxWithOutput
Write the result of max() to the given output tensor,
out
.See max() for the remaining parameter descriptions.
 param out
The tensor to write the maximums to.
min
Compute the minimum of each element in
A
with the corresponding element inB
. param graph
The graph to update.
 param A
A tensor of elements.
 param B
A tensor of elements.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information.
 param options
Elementwise options. See map().
 return
A tensor where each element is the result of
min(a, b)
, wherea
andb
are the corresponding elements ofA
andB
tensors respectively.
minWithOutput
Write the result of min() to the given output tensor,
out
.See min() for the remaining parameter descriptions.
 param out
The tensor to write the minimums to.
atan2
Compute the elementwise arctangent of
A / B
. param graph
The graph to update.
 param A
A tensor of elements.
 param B
A tensor of elements.
 param prog
The sequence to extend with the execution of the expression evaluation.
 param debugContext
Optional debug information
 param options
Elementwise options. See map().
 return
A tensor where each element is the result of
arctan(a / b)
;a
andb
are the corresponding elements ofA
andB
tensors respectively.
atan2InPlace
Update the tensor
A
with the result of atan2().See atan2() for parameter descriptions.
atan2WithOutput
Write the result of atan2() to the given output tensor,
out
.See atan2() for the remaining parameter descriptions.
 param out
The tensor to write the result to.
invStdDevToVarianceInPlace
Update the
invStdDev
tensor with the result of invStdDevToVariance().See invStdDevToVariance() for parameter descriptions.
invStdDevToVarianceWithOutput
Write the result of invStdDevToVariance() to the given output tensor,
out
.See invStdDevToVariance() for the remaining parameter descriptions.
 param out
The tensor to write the variance to.
varianceToInvStdDevInPlace
Update the
variance
tensor with the result of varianceToInvStdDev().See varianceToInvStdDev() for parameter descriptions.
varianceToInvStdDevWithOutput
Write the result of varianceToInvStdDev() to the given output tensor,
out
.See varianceToInvStdDev() for the remaining parameter descriptions.
 param out
The tensor to write inverse standard deviation to.
Enums
Functions

void scaledAddTo(poplar::Graph &graph, poplar::Tensor A, poplar::Tensor B, float scaleB, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {}, const poplar::OptionFlags &options = {})
Add the elements of one tensor multiplied by a scalar to another tensor.
Performs the calculations
A
+=scaleB
*B
The operation is performed after casting
B
to the type ofA
.Scaled add options
optimizeForSpeed
(true, false) [=false]The scaledAdd vertices default to being optimized to aid memory allocation. To optimise them for speed instead, set this option to true.
scaleFloatToHalfTolerance
(double) [=1e6]Where the tensors
A
,B
are of type half and ascaleB
is provided as a float or a tensor of type float, it is possible to to implement the scaledAddTo in half precision ifscaleB
can be cast to half precision with acceptable accuracy. Otherwise full precision arithmetic can be used internally, but at the cost of speed. Floating point arithmetic will be selected if the relative error in casting is greater than the relative tolerance.
Only applies to
scaledAddTo()
withscaleB
.
 Parameters
graph – The Poplar graph.
A – The destination tensor.
B – The second tensor to add elements from (must be of the same shape as
A
).scaleB – The scalar to multiply elements of
B
with before addition.prog – A sequence program to which the code performing the add will be appended.
debugContext – Optional debug information.
options – A list of flags to control optimizations.

void scaledAddTo(poplar::Graph &graph, poplar::Tensor A, poplar::Tensor B, poplar::Tensor scaleB, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {}, const poplar::OptionFlags &options = {})
Add the elements of one tensor each multiplied by a (scalar) tensor to another tensor.
Performs the calculations
A
+=scaleB
*B
The operation is performed after casting
scaleB
andB
to the type ofA
. Parameters
graph – The Poplar graph.
A – The destination tensor.
B – The second tensor to add elements from (must be of the same shape as
A
).scaleB – The scalar tensor to multiply elements of
B
with before addition.prog – A sequence program to which the code performing the add will be appended.
debugContext – Optional debug information.
options – A list of flags to control optimizations. See scaledAddTo().

void scaledSubtractFrom(poplar::Graph &graph, poplar::Tensor A, poplar::Tensor B, float scaleB, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {}, const poplar::OptionFlags &options = {})
Subtract the elements of one tensor multiplied by a scalar from another tensor.
Performs the calculations
A
=scaleB
*B
The operation is performed after casting
B
to typeA
. Parameters
graph – The Poplar graph.
A – The destination tensor.
B – The second tensor providing the elements to subtract (must be of the same shape as
A
).scaleB – The scalar to multiply elements of
B
with before subtraction.prog – A sequence program to which the code performing the add will be appended.
debugContext – Optional debug information.
options – A list of flags to control optimizations. See scaledAddTo().

void scaledSubtractFrom(poplar::Graph &graph, poplar::Tensor A, poplar::Tensor B, poplar::Tensor scaleB, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {}, const poplar::OptionFlags &options = {})
Subtract the elements of one tensor each multiplied by a (scalar) tensor from another tensor.
Performs the calculations
A
=scaleB
*B
The operation is performed after casting
scaleB
, andB
to the type ofA
. Parameters
graph – The Poplar graph.
A – The destination tensor.
B – The second tensor providing the elements to subtract (must be of the same shape as
A
).scaleB – The scalar tensor to multiply elements of
B
with before subtraction.prog – A sequence program to which the code performing the add will be appended.
debugContext – Optional debug information.
options – A list of flags to control optimizations. See scaledAddTo().

void scaledAddTo(poplar::Graph &graph, poplar::Tensor A, poplar::Tensor scaleA, poplar::Tensor B, poplar::Tensor scaleB, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {}, const poplar::OptionFlags &options = {})
Scale the elements of one tensor and add the scaled elements of another tensor to it.
The two scaling factors are (scalar) tensors.
Performs the calculations
A
=scaleA
*A
+scaleB
*B
The operation is performed after casting
scaleA
,scaleB
andB
to the type ofA
. Parameters
graph – The Poplar graph.
A – The destination tensor.
scaleA – The scalar tensor to multiply elements of
A
with before addition.B – The second tensor to add elements from (must be of the same shape as
A
).scaleB – The scalar tensor to multiply elements of
B
with before addition.prog – A sequence program to which the code performing the add will be appended.
debugContext – Optional debug information.
options – A list of flags to control optimizations. See scaledAddTo().

void scaledAddTo(poplar::Graph &graph, poplar::Tensor A, poplar::Tensor scaleA, poplar::Tensor B, poplar::Tensor scaleB, poplar::program::Sequence &prog, const ScaledAddSpecialisation speciality, const poplar::DebugContext &debugContext = {}, const poplar::OptionFlags &options = {})
Scale the elements of one tensor and add the scaled elements of another tensor to it.
The two scaling factors are (scalar) tensors.
Performs the calculations
A
=scaleA'
*A
+scaleB
*B
where scaleA’ is a function of scaleA specified by the “speciality” option.The operation is performed after casting
scaleA
,scaleB
andB
to the type ofA
. Parameters
graph – The Poplar graph.
A – The destination tensor.
scaleA – The scalar tensor to multiply elements of
A
with before addition.B – The second tensor to add elements from (must be of the same shape as
A
).scaleB – The scalar tensor to multiply elements of
B
with before addition.prog – A sequence program to which the code performing the add will be appended.
speciality – Choice of ScaledAdd expression formulation
debugContext – Optional debug information.
options – A list of flags to control optimizations. See scaledAddTo().

void scaledAddTo(poplar::Graph &graph, poplar::Tensor A, float scaleA, poplar::Tensor B, float scaleB, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {}, const poplar::OptionFlags &options = {})
Scale the elements of one tensor and add the scaled elements of another tensor to it.
The two scaling factors are constants.
Performs the calculations
A
=scaleA
*A
+scaleB
*B
If
A
andB
are of different types,B
is first cast to the type ofA
and the operation performed. Parameters
graph – The Poplar graph.
A – The destination tensor.
scaleA – The constant to multiply elements of
A
with before addition.B – The second tensor to add elements from (must be of the same shape as
A
).scaleB – The constant to multiply elements of
B
with before addition.prog – A sequence program to which the code performing the add will be appended.
debugContext – Optional debug information.
options – A list of flags to control optimizations. See scaledAddTo().

void scaledAddTo(poplar::Graph &graph, poplar::Tensor A, float scaleA, poplar::Tensor B, float scaleB, poplar::program::Sequence &prog, const ScaledAddSpecialisation speciality, const poplar::DebugContext &debugContext = {}, const poplar::OptionFlags &options = {})
Scale the elements of one tensor and add the scaled elements of another tensor to it.
The two scaling factors are constants.
Performs the calculations
A
=scaleA'
*A
+scaleB
*B
where scaleA’ is a function of scaleA specified by the “speciality” option.If
A
andB
are of different types,B
is first cast to the type ofA
and the operation performed. Parameters
graph – The Poplar graph.
A – The destination tensor.
scaleA – The constant to multiply elements of
A
with before addition.B – The second tensor to add elements from (must be of the same shape as
A
).scaleB – The constant to multiply elements of
B
with before addition.prog – A sequence program to which the code performing the add will be appended.
speciality – Choice of ScaledAdd expression formulation
debugContext – Optional debug information.
options – A list of flags to control optimizations. See scaledAddTo().

void scaledSubtractFrom(poplar::Graph &graph, poplar::Tensor A, poplar::Tensor scaleA, poplar::Tensor B, poplar::Tensor scaleB, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {}, const poplar::OptionFlags &options = {})
Scale the elements of one tensor and subtract the scaled elements of another tensor to it.
The two scaling factors are (scalar) tensors.
Performs the calculations
A
=scaleA
*A
scaleB
*B
The operation is performed after casting
scaleA
,scaleB
andB
to the type ofA
. Parameters
graph – The Poplar graph.
A – The destination tensor.
scaleA – The scalar tensor to multiply elements of
A
with before subtraction.B – The second tensor to subtract elements from (must be of the same shape as
A
).scaleB – The scalar tensor to multiply elements of
B
with before subtraction.prog – A sequence program to which the code performing the subtract will be appended.
debugContext – Optional debug information.
options – A list of flags to control optimizations. See scaledAddTo().

void scaledSubtractFrom(poplar::Graph &graph, poplar::Tensor A, float scaleA, poplar::Tensor B, float scaleB, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {}, const poplar::OptionFlags &options = {})
Scale the elements of one tensor and subtract the scaled elements of another tensor to it.
The two scaling factors are constants.
Performs the calculations
A
=scaleA
*A
scaleB
*B
If
A
andB
are of different types,B
is first cast to the type ofA
and the operation performed. Parameters
graph – The Poplar graph.
A – The destination tensor.
scaleA – The constant to multiply elements of
A
with before subtraction.B – The second tensor to subtract elements from (must be of the same shape as
A
).scaleB – The constant to multiply elements of
B
with before subtraction.prog – A sequence program to which the code performing the subtract will be appended.
debugContext – Optional debug information.
options – A list of flags to control optimizations. See scaledAddTo().