struct dnnl::post_ops

Overview

Post-ops. More…

#include <dnnl.hpp>

struct post_ops: public dnnl::handle
{
    // methods

    int len() const;
    primitive::kind kind(int index) const;

    void append_sum(
        float scale = 1.f,
        memory::data_type data_type = memory::data_type::undef
        );

    void get_params_sum(int index, float& scale) const;
    void get_params_sum(int index, float& scale, memory::data_type& data_type) const;
    void append_eltwise(float scale, algorithm aalgorithm, float alpha, float beta);

    void get_params_eltwise(
        int index,
        float& scale,
        algorithm& aalgorithm,
        float& alpha,
        float& beta
        ) const;

    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
        );

    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;

    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
        );

    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;

    void append_binary(algorithm aalgorithm, const memory::desc& src1_desc);

    void get_params_binary(
        int index,
        algorithm& aalgorithm,
        memory::desc& src1_desc
        ) const;
};

Inherited Members

public:
    // methods

    handle<T, traits>& operator = (const handle<T, traits>&);
    handle<T, traits>& operator = (handle<T, traits>&&);
    void reset(T t, bool weak = false);
    T get(bool allow_empty = false) const;
    operator T () const;
    operator bool () const;
    bool operator == (const handle<T, traits>& other) const;
    bool operator != (const handle& other) const;

Detailed Documentation

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

Methods

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.

Parameters:

index

Index of the post-op to return the kind for.

Returns:

Primitive kind of the post-op at the specified index.

void append_sum(
    float scale = 1.f,
    memory::data_type data_type = memory::data_type::undef
    )

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:

scale

Scaling factor.

data_type

Data type.

void get_params_sum(int index, float& scale) const

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

Parameters:

index

Index of the sum post-op.

scale

Scaling factor of the sum post-op.

void get_params_sum(int index, float& scale, memory::data_type& data_type) const

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

Parameters:

index

Index of the sum post-op.

scale

Scaling factor of the sum post-op.

data_type

Data type of the sum post-op.

void append_eltwise(float scale, algorithm aalgorithm, float alpha, float beta)

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:

scale

Scaling factor.

aalgorithm

Elementwise algorithm.

alpha

Alpha parameter for the elementwise algorithm.

beta

Beta parameter for the elementwise algorithm.

void get_params_eltwise(
    int index,
    float& scale,
    algorithm& aalgorithm,
    float& alpha,
    float& beta
    ) const

Returns parameters of an elementwise post-op.

Parameters:

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.

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.

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

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.

Parameters:

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.

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.

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

Returns:

dnnl_success on success and a status describing the error otherwise

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.

Parameters:

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.

void append_binary(algorithm aalgorithm, const memory::desc& src1_desc)

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:

aalgorithm

Binary algorithm for the post-op.

src1_desc

Memory descriptor of a second operand.

void get_params_binary(
    int index,
    algorithm& aalgorithm,
    memory::desc& src1_desc
    ) const

Returns the parameters of a binary post-op.

Parameters:

index

Index of the binary post-op.

aalgorithm

Output binary algorithm kind.

src1_desc

Output memory descriptor of a second operand.