ScaledAdd
#include <popops/ScaledAdd.hpp>
Functions for scaling and adding tensors.
-
namespace popops
Common functions, such as elementwise and reductions.
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*BThe operation is performed after casting
Bto 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) [=1e-6]Where the tensors
A,Bare of type half and ascaleBis provided as a float or a tensor of type float, it is possible to to implement the scaledAddTo in half precision ifscaleBcan 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
Bwith 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*BThe operation is performed after casting
scaleBandBto 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
Bwith 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*BThe operation is performed after casting
Bto 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
Bwith 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*BThe operation is performed after casting
scaleB, andBto 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
Bwith 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*BThe operation is performed after casting
scaleA,scaleBandBto the type ofA.- Parameters
graph – The Poplar graph.
A – The destination tensor.
scaleA – The scalar tensor to multiply elements of
Awith 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
Bwith 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*Bwhere scaleA’ is a function of scaleA specified by the “speciality” option.The operation is performed after casting
scaleA,scaleBandBto the type ofA.- Parameters
graph – The Poplar graph.
A – The destination tensor.
scaleA – The scalar tensor to multiply elements of
Awith 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
Bwith 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*BIf
AandBare of different types,Bis first cast to the type ofAand the operation performed.- Parameters
graph – The Poplar graph.
A – The destination tensor.
scaleA – The constant to multiply elements of
Awith 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
Bwith 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*Bwhere scaleA’ is a function of scaleA specified by the “speciality” option.If
AandBare of different types,Bis first cast to the type ofAand the operation performed.- Parameters
graph – The Poplar graph.
A – The destination tensor.
scaleA – The constant to multiply elements of
Awith 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
Bwith 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*BThe operation is performed after casting
scaleA,scaleBandBto the type ofA.- Parameters
graph – The Poplar graph.
A – The destination tensor.
scaleA – The scalar tensor to multiply elements of
Awith 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
Bwith 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*BIf
AandBare of different types,Bis first cast to the type ofAand the operation performed.- Parameters
graph – The Poplar graph.
A – The destination tensor.
scaleA – The constant to multiply elements of
Awith 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
Bwith 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 scaledAddTo(poplar::Graph &graph, poplar::Tensor A, poplar::Tensor B, float scaleB, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {}, const poplar::OptionFlags &options = {})