Post-ops. More...
#include <dnnl.hpp>
Public Member Functions | |
post_ops () | |
Constructs an empty sequence of post-ops. | |
int | len () const |
Returns the number of post-ops entries. | |
primitive::kind | kind (int index) const |
Returns the primitive kind of post-op at entry with a certain index. More... | |
void | append_sum (float scale=1.f, memory::data_type data_type=memory::data_type::undef) |
Appends an accumulation (sum) post-op. More... | |
void | get_params_sum (int index, float &scale) const |
Returns the parameters of an accumulation (sum) post-op. More... | |
void | get_params_sum (int index, float &scale, memory::data_type &data_type) const |
Returns the parameters of an accumulation (sum) post-op. More... | |
void | append_eltwise (float scale, algorithm aalgorithm, float alpha, float beta) |
Appends an elementwise post-op. More... | |
void | get_params_eltwise (int index, float &scale, algorithm &aalgorithm, float &alpha, float &beta) const |
Returns parameters of an elementwise post-op. More... | |
void | append_dw_k3s1p1 (memory::data_type weights_data_type, memory::data_type bias_data_type, memory::data_type dst_data_type, int mask, const std::vector< float > &scales) |
Appends a depthwise post-op convolution with stride 1. More... | |
void | get_params_dw_k3s1p1 (int index, memory::data_type &weights_data_type, memory::data_type &bias_data_type, memory::data_type &dst_data_type, int &mask, std::vector< float > &scales) const |
Returns the parameters of an depthwise post-op with stride 1. More... | |
void | append_dw_k3s2p1 (memory::data_type weights_data_type, memory::data_type bias_data_type, memory::data_type dst_data_type, int mask, const std::vector< float > &scales) |
Appends a depthwise post-op convolution with stride 2. More... | |
void | get_params_dw_k3s2p1 (int index, memory::data_type &weights_data_type, memory::data_type &bias_data_type, memory::data_type &dst_data_type, int &mask, std::vector< float > &scales) const |
Returns the parameters of an depthwise post-op with stride 2. More... | |
void | append_binary (algorithm aalgorithm, const memory::desc &src1_desc) |
Appends a binary post-op. More... | |
void | get_params_binary (int index, algorithm &aalgorithm, memory::desc &src1_desc) const |
Returns the parameters of a binary post-op. More... | |
Public Member Functions inherited from dnnl::handle< dnnl_post_ops_t > | |
bool | operator== (const handle< dnnl_post_ops_t, handle_traits< dnnl_post_ops_t > > &other) const |
Equality operator. More... | |
bool | operator!= (const handle &other) const |
Inequality operator. More... | |
handle ()=default | |
Constructs an empty handle object. More... | |
handle (const handle< dnnl_post_ops_t, handle_traits< dnnl_post_ops_t > > &)=default | |
Copy constructor. | |
handle (handle< dnnl_post_ops_t, handle_traits< dnnl_post_ops_t > > &&)=default | |
Move constructor. | |
handle (dnnl_post_ops_t t, bool weak=false) | |
Constructs a handle wrapper object from a C API handle. More... | |
handle< dnnl_post_ops_t, handle_traits< dnnl_post_ops_t > > & | operator= (const handle< dnnl_post_ops_t, handle_traits< dnnl_post_ops_t > > &)=default |
Assignment operator. | |
handle< dnnl_post_ops_t, handle_traits< dnnl_post_ops_t > > & | operator= (handle< dnnl_post_ops_t, handle_traits< dnnl_post_ops_t > > &&)=default |
Move assignment operator. | |
void | reset (dnnl_post_ops_t t, bool weak=false) |
Resets the handle wrapper objects to wrap a new C API handle. More... | |
dnnl_post_ops_t | get (bool allow_empty=false) const |
Returns the underlying C API handle. More... | |
operator dnnl_post_ops_t () const | |
Converts a handle to the underlying C API handle type. More... | |
operator bool () const | |
Checks whether the object is not empty. More... | |
Post-ops.
Post-ops are computations executed after the main primitive computations and are attached to the primitive via primitive attributes.
|
inline |
Returns the primitive kind of post-op at entry with a certain index.
index | Index of the post-op to return the kind for. |
|
inline |
Appends an accumulation (sum) post-op.
Prior to accumulating the result, the previous value would be multiplied by a scaling factor scale
.
The kind of this post-op is dnnl::primitive::kind::sum.
This feature may improve performance for cases like residual learning blocks, where the result of convolution is accumulated to the previously computed activations. The parameter scale
may be used for the integer-based computations when the result and previous activations have different logical scaling factors.
In the simplest case when the accumulation is the only post-op, the computations would be dst[:] := scale * dst[:] + op(...)
instead of dst[:] := op(...)
.
If data_type
is specified, the original dst tensor will be reinterpreted as a tensor with the provided data type. Because it is a reinterpretation, data_type and dst data type should have the same size. As a result, computations would be dst[:] <- scale * as_data_type(dst[:]) + op(...)
instead of dst[:] <- op(...)
.
scale | Scaling factor. |
data_type | Data type. |
|
inline |
Returns the parameters of an accumulation (sum) post-op.
index | Index of the sum post-op. |
scale | Scaling factor of the sum post-op. |
|
inline |
Returns the parameters of an accumulation (sum) post-op.
index | Index of the sum post-op. |
scale | Scaling factor of the sum post-op. |
data_type | Data type of the sum post-op. |
|
inline |
Appends an elementwise post-op.
The kind of this post-op is dnnl::primitive::kind::eltwise.
In the simplest case when the elementwise is the only post-op, the computations would be dst[:] := scale * eltwise_op (op(...))
instead of dst[:] <- op(...)
, where eltwise_op is configured with the given parameters.
scale | Scaling factor. |
aalgorithm | Elementwise algorithm. |
alpha | Alpha parameter for the elementwise algorithm. |
beta | Beta parameter for the elementwise algorithm. |
|
inline |
Returns parameters of an elementwise post-op.
index | Index of the post-op. |
scale | Output scaling factor. |
aalgorithm | Output elementwise algorithm kind. |
alpha | Output alpha parameter for the elementwise algorithm. |
beta | Output beta parameter for the elementwise algorithm. |
|
inline |
Appends a depthwise post-op convolution with stride 1.
This post-op can only be fused with a 2D 1x1 convolution (convolution with weights spatial dimension equal to 1 i.e., kh=kw=1).
The kind of this post-op is dnnl_convolution.
The number of outputs for primitive remain same as before. The output size remain same as the original primitive due to stride=1.
The Post-op can be defined as:
dst[:] <- scales * (conv_dw(conv_1x1))
See dev_guide_attributes_post_ops_depthwise and dev_guide_attributes_post_ops_depthwise_fusion for more info.
weights_data_type | Weights data type of depthwise post-op |
bias_data_type | Bias data type of depthwise post-op |
dst_data_type | Output data type of depthwise post-op |
mask | Output scaling factors correspondence mask that defines the correspondence between the output tensor dimensions and the scales array. The set i-th bit indicates that a dedicated output scaling factor is used for each index along that dimension. The mask value of 0 implies a common scaling factor for the whole output tensor. |
scales | Output pointer to a constant array of float scaling factors. |
|
inline |
Returns the parameters of an depthwise post-op with stride 1.
index | Index of the elementwise post-op. |
weights_data_type | Weights data type of depthwise post-op |
bias_data_type | Bias data type of depthwise post-op |
dst_data_type | Output data type of depthwise post-op |
mask | Output scaling factors correspondence mask that defines the correspondence between the output tensor dimensions and the scales array. The set i-th bit indicates that a dedicated output scaling factor is used for each index along that dimension. The mask value of 0 implies a common scaling factor for the whole output tensor. |
scales | Output pointer to a constant array of float scaling factors. |
|
inline |
Appends a depthwise post-op convolution with stride 2.
This post-op can only be fused with a 2D 1x1 convolution (convolution with weights spatial dimension equal to 1 i.e., kh=kw=1).
The kind of this post-op is dnnl_convolution.
The number of outputs for primitive remain same as before. The output spatial size can be derived as below:
output_height = ceil(output_height_1x1_convolution, stride) output_width = ceil(output_width_1x1_convolution, stride)
The Post-op can be defined as:
dst[:] <- scales * (conv_dw(conv_1x1))
See dev_guide_attributes_post_ops_depthwise and dev_guide_attributes_post_ops_depthwise_fusion for more info.
weights_data_type | Weights data type of depthwise post-op |
bias_data_type | Bias data type of depthwise post-op |
dst_data_type | Output data type of depthwise post-op |
mask | Output scaling factors correspondence mask that defines the correspondence between the output tensor dimensions and the scales array. The set i-th bit indicates that a dedicated output scaling factor is used for each index along that dimension. The mask value of 0 implies a common scaling factor for the whole output tensor. |
scales | Output pointer to a constant array of float scaling factors. |
|
inline |
Returns the parameters of an depthwise post-op with stride 2.
index | Index of the elementwise post-op. |
weights_data_type | Weights data type of depthwise post-op |
bias_data_type | Bias data type of depthwise post-op |
dst_data_type | Output data type of depthwise post-op |
mask | Output scaling factors correspondence mask that defines the correspondence between the output tensor dimensions and the scales array. The set i-th bit indicates that a dedicated output scaling factor is used for each index along that dimension. The mask value of 0 implies a common scaling factor for the whole output tensor. |
scales | Output pointer to a constant array of float scaling factors. |
|
inline |
Appends a binary post-op.
The kind of this post operation is dnnl_binary.
In the simplest case when the binary is the only post operation, the computations would be:
dst[:] <- binary_op (dst[:], another_input[:])
where binary_op is configured with the given parameters. binary_op supports broadcast semantics for a second operand.
aalgorithm | Binary algorithm for the post-op. |
src1_desc | Memory descriptor of a second operand. |
|
inline |
Returns the parameters of a binary post-op.
index | Index of the binary post-op. |
aalgorithm | Output binary algorithm kind. |
src1_desc | Output memory descriptor of a second operand. |