oneAPI Deep Neural Network Library (oneDNN)
Performance library for Deep Learning
1.96.0
dnnl::post_ops Struct Reference

Post-ops. More...

#include <dnnl.hpp>

Inheritance diagram for dnnl::post_ops:
Collaboration diagram for dnnl::post_ops:

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...
 

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:
binary.cpp, cnn_inference_int8.cpp, convolution.cpp, cpu_sgemm_and_matmul.cpp, inference_int8_matmul.cpp, inner_product.cpp, 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.f,
memory::data_type  data_type = memory::data_type::undef 
)
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(...).

Note
This post-op executes in-place and does not change the destination layout.
Parameters
scaleScaling factor.
data_typeData type.
Examples:
cpu_sgemm_and_matmul.cpp.

◆ get_params_sum() [1/2]

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.

◆ get_params_sum() [2/2]

void dnnl::post_ops::get_params_sum ( int  index,
float &  scale,
memory::data_type data_type 
) 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.
data_typeData type of the sum post-op.

◆ append_eltwise()

void dnnl::post_ops::append_eltwise ( float  scale,
algorithm  aalgorithm,
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.
aalgorithmElementwise algorithm.
alphaAlpha parameter for the elementwise algorithm.
betaBeta parameter for the elementwise algorithm.
Examples:
binary.cpp, cnn_inference_int8.cpp, convolution.cpp, inference_int8_matmul.cpp, inner_product.cpp, matmul.cpp, and performance_profiling.cpp.

◆ get_params_eltwise()

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

Returns parameters of an elementwise post-op.

Parameters
indexIndex of the post-op.
scaleOutput scaling factor.
aalgorithmOutput 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.

◆ append_binary()

void dnnl::post_ops::append_binary ( algorithm  aalgorithm,
const memory::desc src1_desc 
)
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.

Parameters
aalgorithmBinary algorithm for the post-op.
src1_descMemory descriptor of a second operand.

◆ get_params_binary()

void dnnl::post_ops::get_params_binary ( int  index,
algorithm aalgorithm,
memory::desc src1_desc 
) const
inline

Returns the parameters of a binary post-op.

Parameters
indexIndex of the binary post-op.
aalgorithmOutput binary algorithm kind.
src1_descOutput memory descriptor of a second operand.

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