Attributes¶
Overview¶
A container for parameters that extend primitives behavior. More…
// typedefs typedef struct dnnl_primitive_attr* dnnl_primitive_attr_t; typedef const struct dnnl_primitive_attr* const_dnnl_primitive_attr_t; typedef struct dnnl_post_ops* dnnl_post_ops_t; typedef const struct dnnl_post_ops* const_dnnl_post_ops_t; // enums enum dnnl::algorithm; enum dnnl_rounding_mode_t; enum dnnl_scratchpad_mode_t; enum dnnl::prop_kind; enum dnnl::rounding_mode; enum dnnl::scratchpad_mode; // structs struct dnnl_post_ops; struct dnnl_primitive_attr; struct dnnl::post_ops; struct dnnl::primitive_attr; // global functions dnnl_scratchpad_mode_t dnnl::convert_to_c(scratchpad_mode mode); dnnl_rounding_mode_t dnnl::convert_to_c(rounding_mode mode); dnnl_prop_kind_t dnnl::convert_to_c(prop_kind akind); dnnl_alg_kind_t dnnl::convert_to_c(algorithm aalgorithm); dnnl_status_t DNNL_API dnnl_primitive_attr_create(dnnl_primitive_attr_t* attr); dnnl_status_t DNNL_API dnnl_primitive_attr_clone( dnnl_primitive_attr_t* attr, const_dnnl_primitive_attr_t existing_attr ); dnnl_status_t DNNL_API dnnl_primitive_attr_destroy(dnnl_primitive_attr_t attr); dnnl_status_t DNNL_API dnnl_primitive_attr_get_dropout( const_dnnl_primitive_attr_t attr, const_dnnl_memory_desc_t* dropout_desc ); dnnl_status_t DNNL_API dnnl_primitive_attr_set_dropout( dnnl_primitive_attr_t attr, const_dnnl_memory_desc_t dropout_desc ); dnnl_status_t DNNL_API dnnl_primitive_attr_get_fpmath_mode( const_dnnl_primitive_attr_t attr, dnnl_fpmath_mode_t* mode ); dnnl_status_t DNNL_API dnnl_primitive_attr_set_fpmath_mode( dnnl_primitive_attr_t attr, dnnl_fpmath_mode_t mode ); dnnl_status_t DNNL_API dnnl_primitive_attr_get_fpmath_mode_v2( const_dnnl_primitive_attr_t attr, dnnl_fpmath_mode_t* mode, int* apply_to_int ); dnnl_status_t DNNL_API dnnl_primitive_attr_set_fpmath_mode_v2( dnnl_primitive_attr_t attr, dnnl_fpmath_mode_t mode, int apply_to_int ); dnnl_status_t DNNL_API dnnl_primitive_attr_get_deterministic( const_dnnl_primitive_attr_t attr, int* value ); dnnl_status_t DNNL_API dnnl_primitive_attr_set_deterministic( dnnl_primitive_attr_t attr, int value ); dnnl_status_t DNNL_API dnnl_primitive_attr_get_accumulation_mode( const_dnnl_primitive_attr_t attr, dnnl_accumulation_mode_t* mode ); dnnl_status_t DNNL_API dnnl_primitive_attr_set_accumulation_mode( dnnl_primitive_attr_t attr, dnnl_accumulation_mode_t mode ); dnnl_status_t DNNL_API dnnl_primitive_attr_get_scratchpad_mode( const_dnnl_primitive_attr_t attr, dnnl_scratchpad_mode_t* mode ); dnnl_status_t DNNL_API dnnl_primitive_attr_set_scratchpad_mode( dnnl_primitive_attr_t attr, dnnl_scratchpad_mode_t mode ); dnnl_status_t DNNL_API dnnl_primitive_attr_set_scales_mask( dnnl_primitive_attr_t attr, int arg, int mask ); dnnl_status_t DNNL_API dnnl_primitive_attr_set_scales( dnnl_primitive_attr_t attr, int arg, int mask, int ndims, const dnnl_dims_t group_dims, dnnl_data_type_t data_type ); dnnl_status_t DNNL_API dnnl_primitive_attr_set_zero_points_mask( dnnl_primitive_attr_t attr, int arg, int mask ); dnnl_status_t DNNL_API dnnl_primitive_attr_set_zero_points( dnnl_primitive_attr_t attr, int arg, int mask, int ndims, const dnnl_dims_t group_dims, dnnl_data_type_t data_type ); dnnl_status_t DNNL_API dnnl_primitive_attr_set_rounding( dnnl_primitive_attr_t attr, int arg, dnnl_rounding_mode_t mode ); dnnl_status_t DNNL_API dnnl_primitive_attr_get_rounding( dnnl_primitive_attr_t attr, int arg, dnnl_rounding_mode_t* mode ); dnnl_status_t DNNL_API dnnl_primitive_attr_get_post_ops( const_dnnl_primitive_attr_t attr, const_dnnl_post_ops_t* post_ops ); dnnl_status_t DNNL_API dnnl_primitive_attr_set_post_ops( dnnl_primitive_attr_t attr, const_dnnl_post_ops_t post_ops ); dnnl_status_t DNNL_API dnnl_post_ops_create(dnnl_post_ops_t* post_ops); dnnl_status_t DNNL_API dnnl_post_ops_clone( dnnl_post_ops_t* post_ops, const_dnnl_post_ops_t existing_post_ops ); dnnl_status_t DNNL_API dnnl_post_ops_destroy(dnnl_post_ops_t post_ops); int DNNL_API dnnl_post_ops_len(const_dnnl_post_ops_t post_ops); dnnl_primitive_kind_t DNNL_API dnnl_post_ops_get_kind( const_dnnl_post_ops_t post_ops, int index ); dnnl_status_t DNNL_API dnnl_post_ops_append_sum( dnnl_post_ops_t post_ops, float scale, int32_t zero_point, dnnl_data_type_t data_type ); dnnl_status_t DNNL_API dnnl_post_ops_get_params_sum( const_dnnl_post_ops_t post_ops, int index, float* scale, int32_t* zero_point, dnnl_data_type_t* data_type ); dnnl_status_t DNNL_API dnnl_post_ops_append_eltwise( dnnl_post_ops_t post_ops, dnnl_alg_kind_t alg_kind, float alpha, float beta ); dnnl_status_t DNNL_API dnnl_post_ops_get_params_eltwise( const_dnnl_post_ops_t post_ops, int index, dnnl_alg_kind_t* alg_kind, float* alpha, float* beta ); dnnl_status_t DNNL_API dnnl_post_ops_append_dw( dnnl_post_ops_t post_ops, dnnl_data_type_t weights_data_type, dnnl_data_type_t bias_data_type, dnnl_data_type_t dst_data_type, dnnl_dim_t kernel_size, dnnl_dim_t stride_size, dnnl_dim_t padding_l_size ); dnnl_status_t DNNL_API dnnl_post_ops_get_params_dw( const_dnnl_post_ops_t post_ops, int index, dnnl_data_type_t* weights_data_type, dnnl_data_type_t* bias_data_type, dnnl_data_type_t* dst_data_type, dnnl_dim_t* kernel_size, dnnl_dim_t* stride_size, dnnl_dim_t* padding_l_size ); dnnl_status_t DNNL_API dnnl_post_ops_append_binary( dnnl_post_ops_t post_ops, dnnl_alg_kind_t alg_kind, const_dnnl_memory_desc_t src1_desc ); dnnl_status_t DNNL_API dnnl_post_ops_get_params_binary( const_dnnl_post_ops_t post_ops, int index, dnnl_alg_kind_t* alg_kind, const_dnnl_memory_desc_t* src1_desc ); dnnl_status_t DNNL_API dnnl_post_ops_append_prelu( dnnl_post_ops_t post_ops, int mask ); dnnl_status_t DNNL_API dnnl_post_ops_get_params_prelu( const_dnnl_post_ops_t post_ops, int index, int* mask ); dnnl_status_t DNNL_API dnnl_primitive_attr_set_rnn_data_qparams( dnnl_primitive_attr_t attr, const float scale, const float shift ); dnnl_status_t DNNL_API dnnl_primitive_attr_get_rnn_data_qparams( const_dnnl_primitive_attr_t attr, float* scale, float* shift ); dnnl_status_t DNNL_API dnnl_primitive_attr_set_rnn_weights_qparams( dnnl_primitive_attr_t attr, dnnl_dim_t count, int mask, const float* scales ); dnnl_status_t DNNL_API dnnl_primitive_attr_get_rnn_weights_qparams( const_dnnl_primitive_attr_t attr, dnnl_dim_t* count, int* mask, const float** scales ); dnnl_status_t DNNL_API dnnl_primitive_attr_set_rnn_weights_projection_qparams( dnnl_primitive_attr_t attr, dnnl_dim_t count, int mask, const float* scales ); dnnl_status_t DNNL_API dnnl_primitive_attr_get_rnn_weights_projection_qparams( const_dnnl_primitive_attr_t attr, dnnl_dim_t* count, int* mask, const float** scales );
Detailed Documentation¶
A container for parameters that extend primitives behavior.
Attributes can also contain Post-ops, which are computations executed after the primitive.
See also:
Primitive Attributes: Post-ops
Typedefs¶
typedef struct dnnl_primitive_attr* dnnl_primitive_attr_t
A primitive descriptor attributes handle that controls primitive behavior.
typedef const struct dnnl_primitive_attr* const_dnnl_primitive_attr_t
A constant primitive descriptor attributes handle.
typedef struct dnnl_post_ops* dnnl_post_ops_t
A post operation chain handle.
typedef const struct dnnl_post_ops* const_dnnl_post_ops_t
A constant post operation chain handle.
Global Functions¶
dnnl_scratchpad_mode_t dnnl::convert_to_c(scratchpad_mode mode)
Converts a scratchpad mode enum value from C++ API to C API type.
Parameters:
mode |
C++ API scratchpad mode enum value. |
Returns:
Corresponding C API scratchpad mode enum value.
dnnl_rounding_mode_t dnnl::convert_to_c(rounding_mode mode)
Converts a rounding mode enum value from C++ API to C API type.
Parameters:
mode |
C++ API rounding mode enum value. |
Returns:
Corresponding C API rounding mode enum value.
dnnl_prop_kind_t dnnl::convert_to_c(prop_kind akind)
Converts propagation kind enum value from C++ API to C API type.
Parameters:
akind |
C++ API propagation kind enum value. |
Returns:
Corresponding C API propagation kind enum value.
dnnl_alg_kind_t dnnl::convert_to_c(algorithm aalgorithm)
Converts algorithm kind enum value from C++ API to C API type.
Parameters:
aalgorithm |
C++ API algorithm kind enum value. |
Returns:
Corresponding C API algorithm kind enum value.
dnnl_status_t DNNL_API dnnl_primitive_attr_create(dnnl_primitive_attr_t* attr)
Creates an empty (default) primitive attributes with all the parameters set to their default values.
Empty attributes are implied whenever the respective argument is NULL.
Parameters:
attr |
Output primitive attributes. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_clone( dnnl_primitive_attr_t* attr, const_dnnl_primitive_attr_t existing_attr )
Clones primitive attributes.
Parameters:
attr |
Output primitive attributes. |
existing_attr |
Primitive attributes to clone. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_destroy(dnnl_primitive_attr_t attr)
Destroys primitive attributes.
Parameters:
attr |
Primitive attributes to destroy. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_get_dropout( const_dnnl_primitive_attr_t attr, const_dnnl_memory_desc_t* dropout_desc )
Returns probability for output dropout primitive attribute.
Parameters:
attr |
Primitive attributes. |
dropout_desc |
Output dropout memory descriptor |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_set_dropout( dnnl_primitive_attr_t attr, const_dnnl_memory_desc_t dropout_desc )
Sets probability for output dropout primitive attribute.
Parameters:
attr |
Primitive attributes. |
dropout_desc |
Output dropout memory descriptor |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_get_fpmath_mode( const_dnnl_primitive_attr_t attr, dnnl_fpmath_mode_t* mode )
Returns the floating-point math mode primitive attribute.
Parameters:
attr |
Primitive attributes. |
mode |
Output FP math mode. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_set_fpmath_mode( dnnl_primitive_attr_t attr, dnnl_fpmath_mode_t mode )
Sets the floating-point math mode primitive attributes.
Parameters:
attr |
Primitive attributes. |
mode |
FP math mode. The possible values are: dnnl_fpmath_mode_strict (default), dnnl_fpmath_mode_bf16, dnnl_fpmath_mode_f16, dnnl_fpmath_mode_tf32, dnnl_fpmath_mode_any. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_get_fpmath_mode_v2( const_dnnl_primitive_attr_t attr, dnnl_fpmath_mode_t* mode, int* apply_to_int )
Returns the floating-point math mode primitive attribute.
Parameters:
attr |
Primitive attributes. |
mode |
Output FP math mode. |
apply_to_int |
Output use floating-point arithmetic for integer primitives. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_set_fpmath_mode_v2( dnnl_primitive_attr_t attr, dnnl_fpmath_mode_t mode, int apply_to_int )
Sets the floating-point math mode primitive attributes.
Parameters:
attr |
Primitive attributes. |
mode |
FP math mode. The possible values are: dnnl_fpmath_mode_strict (default), dnnl_fpmath_mode_bf16, dnnl_fpmath_mode_f16, dnnl_fpmath_mode_tf32, dnnl_fpmath_mode_any. |
apply_to_int |
Boolean. Use of floating-point arithmetic for integer primitives. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_get_deterministic( const_dnnl_primitive_attr_t attr, int* value )
Returns the deterministic primitive attribute value.
Parameters:
attr |
Primitive attributes. |
value |
Output deterministic attribute value |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_set_deterministic( dnnl_primitive_attr_t attr, int value )
Sets the deterministic primitive attribute value.
Parameters:
attr |
Primitive attributes. |
value |
Boolean value to set deterministic attribute. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_get_accumulation_mode( const_dnnl_primitive_attr_t attr, dnnl_accumulation_mode_t* mode )
Returns the accumulation mode primitive attribute.
Parameters:
attr |
Primitive attributes. |
mode |
Output accumulation mode. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_set_accumulation_mode( dnnl_primitive_attr_t attr, dnnl_accumulation_mode_t mode )
Sets the accumulation mode primitive attribute.
Parameters:
attr |
Primitive attributes. |
mode |
Accumulation mode. The possible values are: dnnl_accumulation_mode_strict (default), which is s32 for quantized primitives, f32/f64 otherwise dnnl_accumulation_mode_relaxed, which is same as strict but allows intermediate accumulators to be in src/dst datatype dnnl_accumulation_mode_any, which allows accumulators to be src/dst datatype or any wider type. dnnl_accumulation_mode_f32, dnnl_accumulation_mode_s32, dnnl_accumulation_mode_f16. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_get_scratchpad_mode( const_dnnl_primitive_attr_t attr, dnnl_scratchpad_mode_t* mode )
Returns the primitive attributes scratchpad mode.
Parameters:
attr |
Primitive attributes. |
mode |
Output scratchpad mode. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_set_scratchpad_mode( dnnl_primitive_attr_t attr, dnnl_scratchpad_mode_t mode )
Sets primitive attributes scratchpad mode.
Parameters:
attr |
Primitive attributes. |
mode |
Scratchpad mode. The possible values are: dnnl_scratchpad_mode_library (default) and dnnl_scratchpad_mode_user. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_set_scales_mask( dnnl_primitive_attr_t attr, int arg, int mask )
Sets primitive attributes scaling factors for primitive operations for a given memory argument.
The scaling factors must be passed at execution time as an argument with index DNNL_ARG_ATTR_SCALES | arg.
Parameters:
attr |
Primitive attributes. |
arg |
Parameter argument index as passed to the dnnl_primitive_execute() call. |
mask |
Scaling factors correspondence mask that defines the correspondence between the tensor dimensions and the |
Returns:
dnnl_success on success and a status describing the error otherwise.
See also:
dnnl_primitive_attr_set_scales_mask
dnnl_status_t DNNL_API dnnl_primitive_attr_set_scales( dnnl_primitive_attr_t attr, int arg, int mask, int ndims, const dnnl_dims_t group_dims, dnnl_data_type_t data_type )
Sets primitive attributes scaling factors for primitive operations for a given memory argument.
The scaling factors must be passed at execution time as an argument with index DNNL_ARG_ATTR_SCALES | arg.
Parameters:
attr |
Primitive attributes. |
arg |
Parameter argument index as passed to the dnnl_primitive_execute() call. |
mask |
Scaling factors correspondence mask that defines the correspondence between the tensor dimensions and the |
ndims |
Number of group dimensions. |
group_dims |
Scaling factors correspondence groups that define the correspondence between the tensor dimensions and the scales array. The group dimensions should only be provided for each logical dimension that has correspondence mask |
data_type |
Scaling factors data_type. |
Returns:
dnnl_success on success and a status describing the error otherwise.
See also:
dnnl_primitive_attr_set_scales
dnnl_status_t DNNL_API dnnl_primitive_attr_set_zero_points_mask( dnnl_primitive_attr_t attr, int arg, int mask )
Sets primitive attributes zero points for primitive operations for a given memory argument.
The zero points must be passed at execution time as an argument with index DNNL_ARG_ATTR_ZERO_POINTS | arg.
Parameters:
attr |
Primitive attributes. |
arg |
Parameter argument index as passed to the dnnl_primitive_execute() call. |
mask |
Zero point correspondence mask that defines the correspondence between the tensor dimensions and the |
Returns:
dnnl_success on success and a status describing the error otherwise.
See also:
dnnl_primitive_attr_set_zero_points_mask
dnnl_status_t DNNL_API dnnl_primitive_attr_set_zero_points( dnnl_primitive_attr_t attr, int arg, int mask, int ndims, const dnnl_dims_t group_dims, dnnl_data_type_t data_type )
Sets primitive attributes zero points for primitive operations for a given memory argument.
The zero points must be passed at execution time as an argument with index DNNL_ARG_ATTR_ZERO_POINTS | arg.
Parameters:
attr |
Primitive attributes. |
arg |
Parameter argument index as passed to the dnnl_primitive_execute() call. |
mask |
Zero point correspondence mask that defines the correspondence between the tensor dimensions and the |
ndims |
Number of group dimensions. |
group_dims |
Zero point factors correspondence groups that define the correspondence between the tensor dimensions and the zero_points array. The group dimensions should be only provided for each logical dimension that has the bit set correspondence mask |
data_type |
Zero points factors data_type. |
Returns:
dnnl_success on success and a status describing the error otherwise.
See also:
dnnl_primitive_attr_set_zero_points
dnnl_status_t DNNL_API dnnl_primitive_attr_set_rounding( dnnl_primitive_attr_t attr, int arg, dnnl_rounding_mode_t mode )
Sets the rounding mode attribute value for a given argument.
Parameters:
attr |
Primitive attributes. |
arg |
Argument for which rounding mode should be set. |
mode |
Rounding mode to apply to the argument. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_get_rounding( dnnl_primitive_attr_t attr, int arg, dnnl_rounding_mode_t* mode )
Returns the rounding mode attribute value for a given argument.
Parameters:
attr |
Primitive attributes. |
arg |
Argument for which rounding mode query applies. |
mode |
Output rounding mode. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_get_post_ops( const_dnnl_primitive_attr_t attr, const_dnnl_post_ops_t* post_ops )
Returns primitive attributes post-ops.
Warning
The output post_ops
points to the internal attr
field, so it is an error to modify or destroy them. The lifetime of post_ops
is the same as that of the attr
it belongs to, so it is an error to use post_ops
after attr
has been destroyed.
Parameters:
attr |
Primitive attributes. |
post_ops |
Output post-ops. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_set_post_ops( dnnl_primitive_attr_t attr, const_dnnl_post_ops_t post_ops )
Sets primitive attributes post-ops.
Note
There is no way to check whether the post-ops would be supported by the target primitive. Any error will be reported by the dnnl_<primitive name>_[propagation kind]_primitive_desc_create() function call.
Parameters:
attr |
Primitive attributes. |
post_ops |
Post-ops to set. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_post_ops_create(dnnl_post_ops_t* post_ops)
Creates empty post-ops sequence.
Parameters:
post_ops |
Output post-ops. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_post_ops_clone( dnnl_post_ops_t* post_ops, const_dnnl_post_ops_t existing_post_ops )
Clones post-ops primitive attribute.
Parameters:
post_ops |
Output post-ops primitive attribute. |
existing_post_ops |
Post-ops primitive attribute to clone. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_post_ops_destroy(dnnl_post_ops_t post_ops)
Destroys post-ops.
Parameters:
post_ops |
Post-ops to destroy. |
Returns:
dnnl_success on success and a status describing the error otherwise.
int DNNL_API dnnl_post_ops_len(const_dnnl_post_ops_t post_ops)
Returns the length of post-ops.
Parameters:
post_ops |
Post-ops. |
Returns:
The number of post-ops entries.
dnnl_primitive_kind_t DNNL_API dnnl_post_ops_get_kind( const_dnnl_post_ops_t post_ops, int index )
Returns the kind of a post-op entry.
Parameters:
post_ops |
Post-ops. |
index |
Post-op entry index. |
Returns:
The kind of the post-op with the specified index.
dnnl_undefined_primitive if there is no post-op at the specified index.
dnnl_status_t DNNL_API dnnl_post_ops_append_sum( dnnl_post_ops_t post_ops, float scale, int32_t zero_point, dnnl_data_type_t data_type )
Appends an accumulation v3 (sum) to post-ops.
Prior to accumulating the result, a zero point is subtracted from the previous value and is multiplied by the scale.
The kind of this post-op is dnnl_sum.
This feature may improve performance for cases like dequantize the asymmetrically quantized sum’s src1 tensor to f32 domain before performing the sum operation by subtracting the zero_point
before the scaling.
In the simplest case where accumulation is the only post-op, the computations will be:
dst[:] <- scale * (dst[:] - zero_point) + op(...)
// instead of dst[:] <- op(...)
If data_type
is specified, original dst tensor will be reinterpreted as a tensor with provided data type. Since it is reinterpretation, data_type and dst data type should have the same size. As a result, computations will be:
dst[:] <- scale * (as_data_type(dst[:]) - zero_point) + op(...)
// instead of dst[:] <- op(...)
Note
This post-op executes in-place and does not change the destination layout.
Parameters:
post_ops |
Post-ops. |
scale |
Accumulation scaling factor. |
zero_point |
Single scalar int32_t value of zero point. |
data_type |
Accumulation data_type. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_post_ops_get_params_sum( const_dnnl_post_ops_t post_ops, int index, float* scale, int32_t* zero_point, dnnl_data_type_t* data_type )
Returns the parameters of an accumulation (sum) post-op with zero point and data type parameter.
Parameters:
post_ops |
Post-ops. |
index |
Index of the sum post-op. |
scale |
Output accumulation scaling factor. |
zero_point |
Zero point. |
data_type |
Data type for accumulation. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_post_ops_append_eltwise( dnnl_post_ops_t post_ops, dnnl_alg_kind_t alg_kind, float alpha, float beta )
Appends an elementwise post-op.
The kind of this post operation is dnnl_eltwise.
In the simplest case when the elementwise is the only post operation, the computations would be:
dst[:] <- eltwise_op (op(...)) // instead of dst[:] <- op(...)
where eltwise_op is configured with the given parameters.
Parameters:
post_ops |
Post-ops. |
alg_kind |
Elementwise algorithm for the post-op. |
alpha |
Alpha parameter for the elementwise algorithm. |
beta |
Beta parameter for the elementwise algorithm. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_post_ops_get_params_eltwise( const_dnnl_post_ops_t post_ops, int index, dnnl_alg_kind_t* alg_kind, float* alpha, float* beta )
Returns the parameters of an elementwise post-op.
Parameters:
post_ops |
Post-ops. |
index |
Index of the elementwise post-op. |
alg_kind |
Output elementwise algorithm kind. |
alpha |
Output alpha parameter for the elementwise algorithm. |
beta |
Output beta parameter for the elementwise algorithm. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_invalid_arguments if index
does not refer to an elementwise post-op.
dnnl_status_t DNNL_API dnnl_post_ops_append_dw( dnnl_post_ops_t post_ops, dnnl_data_type_t weights_data_type, dnnl_data_type_t bias_data_type, dnnl_data_type_t dst_data_type, dnnl_dim_t kernel_size, dnnl_dim_t stride_size, dnnl_dim_t padding_l_size )
Appends a depthwise post-op convolution.
This post-op can only be fused with a 2D 1x1 convolution (convolution with weights spatial dimensions equal to 1 i.e., kh=kw=1).
The kind of this post-op is dnnl_convolution.
The number of outputs for primitive with fusion is one. 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)
See dev_guide_attributes_post_ops_depthwise and dev_guide_attributes_post_ops_depthwise_fusion for more info.
Parameters:
post_ops |
Post-ops. |
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 |
kernel_size |
Size of kernel of depthwise post-op |
stride_size |
Size of stride of depthwise post-op |
padding_l_size |
Size of left and top paddings of depthwise post-op |
Returns:
dnnl_success on success and a status describing the error otherwise
dnnl_status_t DNNL_API dnnl_post_ops_get_params_dw( const_dnnl_post_ops_t post_ops, int index, dnnl_data_type_t* weights_data_type, dnnl_data_type_t* bias_data_type, dnnl_data_type_t* dst_data_type, dnnl_dim_t* kernel_size, dnnl_dim_t* stride_size, dnnl_dim_t* padding_l_size )
Returns the parameters of an depthwise post-op.
Parameters:
post_ops |
Post-ops. |
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 |
kernel_size |
Size of kernel of depthwise post-op |
stride_size |
Size of stride of depthwise post-op |
padding_l_size |
Size of left and top paddings of depthwise post-op |
Returns:
dnnl_success on success and a status describing the error otherwise
dnnl_status_t DNNL_API dnnl_post_ops_append_binary( dnnl_post_ops_t post_ops, dnnl_alg_kind_t alg_kind, const_dnnl_memory_desc_t 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:
post_ops |
Post-ops. |
alg_kind |
Binary algorithm for the post-op. |
src1_desc |
Memory descriptor of a second operand. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_post_ops_get_params_binary( const_dnnl_post_ops_t post_ops, int index, dnnl_alg_kind_t* alg_kind, const_dnnl_memory_desc_t* src1_desc )
Returns the parameters of a binary post-op.
Parameters:
post_ops |
Post-ops. |
index |
Index of the binary post-op. |
alg_kind |
Output binary algorithm kind. |
src1_desc |
Output memory descriptor of a second operand. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_invalid_arguments if index
does not refer to a binary post-op.
dnnl_status_t DNNL_API dnnl_post_ops_append_prelu( dnnl_post_ops_t post_ops, int mask )
Appends a prelu forward post-op.
The kind of this post-op is dnnl::primitive::kind::prelu.
The post-op can be defined as:
dst[:] <- prelu(dst[:], weights[:])
prelu:
dst[:] <- dst[:] if dst[:] > 0
dst[:] <- dst[:] * weights[:] if dst[:] <= 0
Note
The order of dimensions does not depend on how elements are laid out in memory. For example:
for a 2D CNN activations tensor the order is always (n, c)
for a 4D CNN activations tensor the order is always (n, c, h, w)
for a 5D CNN weights tensor the order is always (g, oc, ic, kh, kw)
Prelu weights tensor is passed in runtime execution phase. Prelu weights tensor data type is implicitly assumed as f32 using plain layout (a, ab, acb, acdb, acdeb)
Parameters:
post_ops |
Post-ops. |
mask |
Defines the correspondence between the output tensor dimensions and the prelu weights tensor. The set i-th bit indicates that a dedicated weights value is used for each index along that dimension. Set the mask to 0 to use a common weights value for the whole output tensor. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_post_ops_get_params_prelu( const_dnnl_post_ops_t post_ops, int index, int* mask )
Returns the parameters of a prelu post-op.
Parameters:
post_ops |
Post-ops. |
index |
Index of the prelu post-op. |
mask |
Mask of the prelu post-op. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_set_rnn_data_qparams( dnnl_primitive_attr_t attr, const float scale, const float shift )
Set quantization scale and shift parameters for RNN data tensors.
For performance reasons, the low-precision configuration of the RNN primitives expects input activations to have the unsigned 8-bit integer data type. The scale and shift parameters are used to quantize floating-point data to unsigned integer and must be passed to the RNN primitive using attributes.
The quantization formula is scale * data + shift
.
Note
Quantization scale and shift are common for src_layer, src_iter, dst_iter, and dst_layer.
Example usage:
// RNN parameters int l = 2, t = 2, mb = 32, sic = 32, slc = 32, dic = 32, dlc = 32; // Activations quantization parameters float scale = 63.f, shift = 64.f; dnnl_primitive_attr_t rnn_attr; // Create default attributes dnnl_primitive_attr_create(&rnn_attr); // Set scale and shift for int8 quantization of activation dnnl_primitive_attr_set_rnn_data_qparams(rnn_attr, scale, shift); // Create an RNN primitive descriptor. dnnl_primitive_desc_t rnn_pd; dnnl_vanilla_rnn_forward_primitive_desc_create(&rnn_pd, engine, /* arguments */, attr);
Parameters:
attr |
Primitive attributes. |
scale |
The value to scale the data by. |
shift |
The value to shift the data by. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_get_rnn_data_qparams( const_dnnl_primitive_attr_t attr, float* scale, float* shift )
Returns the quantization scale and shift parameters for RNN data tensors.
Note
Quantization scale and shift are common for src_layer, src_iter, dst_iter, and dst_layer.
Parameters:
attr |
Primitive attributes. |
scale |
The value to scale the data by. |
shift |
The value to shift the data by. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_set_rnn_weights_qparams( dnnl_primitive_attr_t attr, dnnl_dim_t count, int mask, const float* scales )
Sets quantization scaling factors for RNN weights tensors.
The low-precision configuration of the RNN primitives expects input weights to use the signed 8-bit integer data type. The scaling factors are used to quantize floating-point data to signed integer and must be passed to RNN primitives using attributes.
Note
The dimension order is always native and does not depend on the actual layout used. For example, five-dimensional weights always have (l, d, i, g, o) logical dimension ordering.
Note
Quantization scales are common for weights_layer and weights_iteration
Parameters:
attr |
Primitive attributes. |
count |
Number of elements in the |
mask |
Scaling factors correspondence mask that defines the correspondence between the output tensor dimensions and the |
scales |
Array of output scaling factors that must contain
\[count = \prod\limits_{d \in mask} weights.dims[d].\]
Violations can only be detected when the attributes are used to create a primitive descriptor. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_get_rnn_weights_qparams( const_dnnl_primitive_attr_t attr, dnnl_dim_t* count, int* mask, const float** scales )
Returns the quantization scaling factors for RNN weights tensors.
Parameters:
attr |
Primitive attributes. |
count |
Number of elements in the |
mask |
Scaling factors correspondence mask that defines the correspondence between the output tensor dimensions and the |
scales |
Array of output scaling factors that contain
\[count = \prod\limits_{d \in mask} weights.dims[d].\]
|
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_set_rnn_weights_projection_qparams( dnnl_primitive_attr_t attr, dnnl_dim_t count, int mask, const float* scales )
Sets quantization scaling factors for RNN projection weights tensors.
The low-precision configuration of the RNN primitives expects input weights to use the signed 8-bit integer data type. The scaling factors are used to quantize floating-point data to signed integer and must be passed to RNN primitives using attributes.
Note
The dimension order is always native and does not depend on the actual layout used. For example, five-dimensional weights always have (l, d, i, g, o) logical dimension ordering.
Parameters:
attr |
Primitive attributes. |
count |
Number of elements in the |
mask |
Scaling factors correspondence mask that defines the correspondence between the output tensor dimensions and the |
scales |
Array of output scaling factors that must contain
\[count = \prod\limits_{d \in mask} weights.dims[d].\]
Violations can only be detected when the attributes are used to create a primitive descriptor. |
Returns:
dnnl_success on success and a status describing the error otherwise.
dnnl_status_t DNNL_API dnnl_primitive_attr_get_rnn_weights_projection_qparams( const_dnnl_primitive_attr_t attr, dnnl_dim_t* count, int* mask, const float** scales )
Returns the quantization scaling factors for RNN projection weights tensors.
Parameters:
attr |
Primitive attributes. |
count |
Number of elements in the |
mask |
Scaling factors correspondence mask that defines the correspondence between the output tensor dimensions and the |
scales |
Array of output scaling factors that contain
\[count = \prod\limits_{d \in mask} weights.dims[d].\]
|
Returns:
dnnl_success on success and a status describing the error otherwise.