Deep Neural Network Library (DNNL)  1.1.3
Performance library for Deep Learning
Modules | Functions

An extension for controlling primitive behavior. More...

Modules

 Sequence of post operations
 An extension for performing extra operations after a base operation.
 

Functions

dnnl_status_t DNNL_API dnnl_primitive_attr_create (dnnl_primitive_attr_t *attr)
 Creates an empty (default) attr attribute. More...
 
dnnl_status_t DNNL_API dnnl_primitive_attr_clone (dnnl_primitive_attr_t *attr, const_dnnl_primitive_attr_t existing_attr)
 Makes a copy of an existing_attr.
 
dnnl_status_t DNNL_API dnnl_primitive_attr_destroy (dnnl_primitive_attr_t attr)
 Deletes an attr.
 
dnnl_status_t DNNL_API dnnl_primitive_attr_get_scratchpad_mode (const_dnnl_primitive_attr_t attr, dnnl_scratchpad_mode_t *mode)
 Returns the scratchpad mode set in the attribute attr.
 
dnnl_status_t DNNL_API dnnl_primitive_attr_set_scratchpad_mode (dnnl_primitive_attr_t attr, dnnl_scratchpad_mode_t mode)
 Sets scratchpad mode. More...
 
dnnl_status_t DNNL_API dnnl_primitive_attr_get_output_scales (const_dnnl_primitive_attr_t attr, dnnl_dim_t *count, int *mask, const float **scales)
 Returns count, correspondence scale mask, and a pointer to a constant floating point array of output scales for given attr, previously set by dnnl_primitive_attr_set_output_scales. More...
 
dnnl_status_t DNNL_API dnnl_primitive_attr_set_output_scales (dnnl_primitive_attr_t attr, dnnl_dim_t count, int mask, const float *scales)
 Sets output scales for primitive operations. More...
 
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 post_ops for given attr. More...
 
dnnl_status_t DNNL_API dnnl_primitive_attr_set_post_ops (dnnl_primitive_attr_t attr, const_dnnl_post_ops_t post_ops)
 Sets configured post_ops to an attribute attr for future use (when primitive descriptor is being created). More...
 

Detailed Description

An extension for controlling primitive behavior.

Function Documentation

◆ dnnl_primitive_attr_create()

dnnl_status_t DNNL_API dnnl_primitive_attr_create ( dnnl_primitive_attr_t attr)

Creates an empty (default) attr attribute.

All the parameters are set to default values.

An empty attribute is used in primitive descriptor creation whenever it is not passed explicitly, e.g. in dnnl_primitive_desc_create.

◆ dnnl_primitive_attr_set_scratchpad_mode()

dnnl_status_t DNNL_API dnnl_primitive_attr_set_scratchpad_mode ( dnnl_primitive_attr_t  attr,
dnnl_scratchpad_mode_t  mode 
)

Sets scratchpad mode.

The possible values are: dnnl_scratchpad_mode_library (default) and dnnl_scratchpad_mode_user.

◆ dnnl_primitive_attr_get_output_scales()

dnnl_status_t DNNL_API dnnl_primitive_attr_get_output_scales ( const_dnnl_primitive_attr_t  attr,
dnnl_dim_t count,
int *  mask,
const float **  scales 
)

Returns count, correspondence scale mask, and a pointer to a constant floating point array of output scales for given attr, previously set by dnnl_primitive_attr_set_output_scales.

Warning
The scales array points to the internal attr field, so the user should not modify or destroy scales.
The lifetime of scales is the same as that of the attr to which it belongs, so it is illegal to use scales after attr is destroyed.

◆ dnnl_primitive_attr_set_output_scales()

dnnl_status_t DNNL_API dnnl_primitive_attr_set_output_scales ( dnnl_primitive_attr_t  attr,
dnnl_dim_t  count,
int  mask,
const float *  scales 
)

Sets output scales for primitive operations.

The number of elements count and correspondence scale mask are stored for future use.

The mask argument defines the correspondence between the output tensor dimensions and the scales array. Set the i-th bit of mask to 1 to use a dedicated scaling factor for each slice of the output tensor over the i-th dimension. Set mask to 0 to use a common scaling factor for the whole output tensor.

Note
The dimension order is always native and does not depend on the actual layout used. Examples:
  • 2D dimensional data the order of dimensions is always: (n, c)
  • 4D dimensional data the order is always: (n, c, h, w)
  • 5D dimensional weights the order is always: (g, oc, ic, kh, kw)

Example usage:

int mb = 32, oc = 32, oh = 14, ow = 14; // convolution output params
float scales[oc] = { ... }; // unique output scales per output channel
int oc_dim = 1; // mb_dim = 0, channel_dim = 1, height_dim = 2, ...
dnnl_convolution_desc_t cd; // create & configure convolution op_desc
dnnl_primitive_attr_create(&attr); // create default attributes
dnnl_primitive_attr_set_output_scales(attr, oc, 1 << oc_dim, scales);
dnnl_primitive_desc_create(&cpd, &cd, attr, NULL);
Note
There is no way to check that count corresponds to mask until an actual primitive descriptor is created, so it is the user's responsibility to set proper values. The following formula must hold:

\[count = \prod\limits_{d \in mask} output.dims[d]\]

◆ dnnl_primitive_attr_get_post_ops()

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 post_ops for given attr.

Warning
post_ops points to the internal attr field, so the user should not modify or destroy post_ops. Also, the lifetime of post_ops is the same as that of the attr it belongs to, so it is illegal to use post_ops after attr has been destroyed.

◆ dnnl_primitive_attr_set_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 
)

Sets configured post_ops to an attribute attr for future use (when primitive descriptor is being created).

Note
At this point in time, there is no way to check whether the primitive descriptor does or does not support a given sequence of post operations. Therefore the user should handle an error that might occur at the dnnl_primitive_desc_create call.