Deep Neural Network Library (DNNL)  1.3.0
Performance library for Deep Learning
Public Member Functions | List of all members
dnnl::post_ops Struct Reference

Post-ops. More...

#include <dnnl.hpp>

Inheritance diagram for dnnl::post_ops:
Inheritance graph
[legend]
Collaboration diagram for dnnl::post_ops:
Collaboration graph
[legend]

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.)
 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 append_eltwise (float scale, algorithm algorithm, float alpha, float beta)
 Appends an elementwise post-op. More...
 
void get_params_eltwise (int index, float &scale, algorithm &algorithm, float &alpha, float &beta) const
 Returns parameters of an elementwise post-up. 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...
 
- 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 empty. More...
 

Detailed Description

Post-ops.

Post-ops are computations executed after the main primitive computations and are attached to the primitive via primitive attributes.

See also
Primitive Attributes: Post-ops
Examples:
cnn_inference_int8.cpp, cpu_sgemm_and_matmul.cpp, inference_int8_matmul.cpp, and performance_profiling.cpp.

Member Function Documentation

◆ kind()

primitive::kind dnnl::post_ops::kind ( int  index) const
inline

Returns the primitive kind of post-op at entry with a certain index.

Parameters
indexIndex of the post-op to return the kind for.
Returns
Primitive kind of the post-op at the specified index.

◆ append_sum()

void dnnl::post_ops::append_sum ( float  scale = 1.)
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(...)
Note
This post-op executes in-place and does not change the destination layout.
Parameters
scaleScaling factor.
Examples:
cpu_sgemm_and_matmul.cpp.

◆ get_params_sum()

void dnnl::post_ops::get_params_sum ( int  index,
float &  scale 
) const
inline

Returns the parameters of an accumulation (sum) post-op.

Parameters
indexIndex of the sum post-op.
scaleScaling factor of the sum post-op.

◆ append_eltwise()

void dnnl::post_ops::append_eltwise ( float  scale,
algorithm  algorithm,
float  alpha,
float  beta 
)
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.

Parameters
scaleScaling factor.
algorithmElementwise algorithm.
alphaAlpha parameter for the elementwise algorithm.
betaBeta parameter for the elementwise algorithm.
Examples:
cnn_inference_int8.cpp, inference_int8_matmul.cpp, and performance_profiling.cpp.

◆ get_params_eltwise()

void dnnl::post_ops::get_params_eltwise ( int  index,
float &  scale,
algorithm algorithm,
float &  alpha,
float &  beta 
) const
inline

Returns parameters of an elementwise post-up.

Parameters
indexIndex of the post-op.
scaleOutput scaling factor.
algorithmOutput elementwise algorithm kind.
alphaOutput alpha parameter for the elementwise algorithm.
betaOutput beta parameter for the elementwise algorithm.

◆ append_dw_k3s1p1()

void dnnl::post_ops::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 
)
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.

Parameters
weights_data_typeWeights data type of depthwise post-op
bias_data_typeBias data type of depthwise post-op
dst_data_typeOutput data type of depthwise post-op
maskOutput 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.
scalesOutput pointer to a constant array of float scaling factors.

◆ get_params_dw_k3s1p1()

void dnnl::post_ops::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
inline

Returns the parameters of an depthwise post-op with stride 1.

Parameters
indexIndex of the elementwise post-op.
weights_data_typeWeights data type of depthwise post-op
bias_data_typeBias data type of depthwise post-op
dst_data_typeOutput data type of depthwise post-op
maskOutput 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.
scalesOutput pointer to a constant array of float scaling factors.

◆ append_dw_k3s2p1()

void dnnl::post_ops::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 
)
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.

Parameters
weights_data_typeWeights data type of depthwise post-op
bias_data_typeBias data type of depthwise post-op
dst_data_typeOutput data type of depthwise post-op
maskOutput 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.
scalesOutput pointer to a constant array of float scaling factors.
Returns
dnnl_success on success and a status describing the error otherwise

◆ get_params_dw_k3s2p1()

void dnnl::post_ops::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
inline

Returns the parameters of an depthwise post-op with stride 2.

Parameters
indexIndex of the elementwise post-op.
weights_data_typeWeights data type of depthwise post-op
bias_data_typeBias data type of depthwise post-op
dst_data_typeOutput data type of depthwise post-op
maskOutput 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.
scalesOutput pointer to a constant array of float scaling factors.

The documentation for this struct was generated from the following file: