mxnet
Functions
Collaboration diagram for RNN:

Functions

mkldnn_status_t MKLDNN_API mkldnn_primitive_attr_set_rnn_data_qparams (mkldnn_primitive_attr_t attr, const float scale, const float shift)
 
mkldnn_status_t MKLDNN_API mkldnn_primitive_attr_set_rnn_weights_qparams (mkldnn_primitive_attr_t attr, mkldnn_dim_t count, int mask, const float *weights_scales)
 
mkldnn_status_t MKLDNN_API mkldnn_vanilla_rnn_forward_desc_init (mkldnn_rnn_desc_t *rnn_desc, mkldnn_prop_kind_t prop_kind, const mkldnn_alg_kind_t activation, const mkldnn_rnn_direction_t direction, const mkldnn_memory_desc_t *src_layer_desc, const mkldnn_memory_desc_t *src_iter_desc, const mkldnn_memory_desc_t *weights_layer_desc, const mkldnn_memory_desc_t *weights_iter_desc, const mkldnn_memory_desc_t *bias_desc, const mkldnn_memory_desc_t *dst_layer_desc, const mkldnn_memory_desc_t *dst_iter_desc, unsigned flags, float alpha, float beta)
 
mkldnn_status_t MKLDNN_API mkldnn_vanilla_rnn_backward_desc_init (mkldnn_rnn_desc_t *rnn_desc, mkldnn_prop_kind_t prop_kind, const mkldnn_alg_kind_t activation, const mkldnn_rnn_direction_t direction, const mkldnn_memory_desc_t *src_layer_desc, const mkldnn_memory_desc_t *src_iter_desc, const mkldnn_memory_desc_t *weights_layer_desc, const mkldnn_memory_desc_t *weights_iter_desc, const mkldnn_memory_desc_t *bias_desc, const mkldnn_memory_desc_t *dst_layer_desc, const mkldnn_memory_desc_t *dst_iter_desc, const mkldnn_memory_desc_t *diff_src_layer_desc, const mkldnn_memory_desc_t *diff_src_iter_desc, const mkldnn_memory_desc_t *diff_weights_layer_desc, const mkldnn_memory_desc_t *diff_weights_iter_desc, const mkldnn_memory_desc_t *diff_bias_desc, const mkldnn_memory_desc_t *diff_dst_layer_desc, const mkldnn_memory_desc_t *diff_dst_iter_desc, unsigned flags, float alpha, float beta)
 
mkldnn_status_t MKLDNN_API mkldnn_lstm_forward_desc_init (mkldnn_rnn_desc_t *rnn_desc, mkldnn_prop_kind_t prop_kind, mkldnn_rnn_direction_t direction, const mkldnn_memory_desc_t *src_layer_desc, const mkldnn_memory_desc_t *src_iter_desc, const mkldnn_memory_desc_t *src_iter_c_desc, const mkldnn_memory_desc_t *weights_layer_desc, const mkldnn_memory_desc_t *weights_iter_desc, const mkldnn_memory_desc_t *bias_desc, const mkldnn_memory_desc_t *dst_layer_desc, const mkldnn_memory_desc_t *dst_iter_desc, const mkldnn_memory_desc_t *dst_iter_c_desc, unsigned flags)
 
mkldnn_status_t MKLDNN_API mkldnn_lstm_backward_desc_init (mkldnn_rnn_desc_t *rnn_desc, mkldnn_prop_kind_t prop_kind, mkldnn_rnn_direction_t direction, const mkldnn_memory_desc_t *src_layer_desc, const mkldnn_memory_desc_t *src_iter_desc, const mkldnn_memory_desc_t *src_iter_c_desc, const mkldnn_memory_desc_t *weights_layer_desc, const mkldnn_memory_desc_t *weights_iter_desc, const mkldnn_memory_desc_t *bias_desc, const mkldnn_memory_desc_t *dst_layer_desc, const mkldnn_memory_desc_t *dst_iter_desc, const mkldnn_memory_desc_t *dst_iter_c_desc, const mkldnn_memory_desc_t *diff_src_layer_desc, const mkldnn_memory_desc_t *diff_src_iter_desc, const mkldnn_memory_desc_t *diff_src_iter_c_desc, const mkldnn_memory_desc_t *diff_weights_layer_desc, const mkldnn_memory_desc_t *diff_weights_iter_desc, const mkldnn_memory_desc_t *diff_bias_desc, const mkldnn_memory_desc_t *diff_dst_layer_desc, const mkldnn_memory_desc_t *diff_dst_iter_desc, const mkldnn_memory_desc_t *diff_dst_iter_c_desc, unsigned flags)
 
mkldnn_status_t MKLDNN_API mkldnn_gru_forward_desc_init (mkldnn_rnn_desc_t *rnn_desc, mkldnn_prop_kind_t prop_kind, mkldnn_rnn_direction_t direction, const mkldnn_memory_desc_t *src_layer_desc, const mkldnn_memory_desc_t *src_iter_desc, const mkldnn_memory_desc_t *weights_layer_desc, const mkldnn_memory_desc_t *weights_iter_desc, const mkldnn_memory_desc_t *bias_desc, const mkldnn_memory_desc_t *dst_layer_desc, const mkldnn_memory_desc_t *dst_iter_desc, unsigned flags)
 
mkldnn_status_t MKLDNN_API mkldnn_gru_backward_desc_init (mkldnn_rnn_desc_t *rnn_desc, mkldnn_prop_kind_t prop_kind, mkldnn_rnn_direction_t direction, const mkldnn_memory_desc_t *src_layer_desc, const mkldnn_memory_desc_t *src_iter_desc, const mkldnn_memory_desc_t *weights_layer_desc, const mkldnn_memory_desc_t *weights_iter_desc, const mkldnn_memory_desc_t *bias_desc, const mkldnn_memory_desc_t *dst_layer_desc, const mkldnn_memory_desc_t *dst_iter_desc, const mkldnn_memory_desc_t *diff_src_layer_desc, const mkldnn_memory_desc_t *diff_src_iter_desc, const mkldnn_memory_desc_t *diff_weights_layer_desc, const mkldnn_memory_desc_t *diff_weights_iter_desc, const mkldnn_memory_desc_t *diff_bias_desc, const mkldnn_memory_desc_t *diff_dst_layer_desc, const mkldnn_memory_desc_t *diff_dst_iter_desc, unsigned flags)
 
mkldnn_status_t MKLDNN_API mkldnn_lbr_gru_forward_desc_init (mkldnn_rnn_desc_t *rnn_desc, mkldnn_prop_kind_t prop_kind, mkldnn_rnn_direction_t direction, const mkldnn_memory_desc_t *src_layer_desc, const mkldnn_memory_desc_t *src_iter_desc, const mkldnn_memory_desc_t *weights_layer_desc, const mkldnn_memory_desc_t *weights_iter_desc, const mkldnn_memory_desc_t *bias_desc, const mkldnn_memory_desc_t *dst_layer_desc, const mkldnn_memory_desc_t *dst_iter_desc, unsigned flags)
 
mkldnn_status_t MKLDNN_API mkldnn_lbr_gru_backward_desc_init (mkldnn_rnn_desc_t *rnn_desc, mkldnn_prop_kind_t prop_kind, mkldnn_rnn_direction_t direction, const mkldnn_memory_desc_t *src_layer_desc, const mkldnn_memory_desc_t *src_iter_desc, const mkldnn_memory_desc_t *weights_layer_desc, const mkldnn_memory_desc_t *weights_iter_desc, const mkldnn_memory_desc_t *bias_desc, const mkldnn_memory_desc_t *dst_layer_desc, const mkldnn_memory_desc_t *dst_iter_desc, const mkldnn_memory_desc_t *diff_src_layer_desc, const mkldnn_memory_desc_t *diff_src_iter_desc, const mkldnn_memory_desc_t *diff_weights_layer_desc, const mkldnn_memory_desc_t *diff_weights_iter_desc, const mkldnn_memory_desc_t *diff_bias_desc, const mkldnn_memory_desc_t *diff_dst_layer_desc, const mkldnn_memory_desc_t *diff_dst_iter_desc, unsigned flags)
 

Detailed Description

A primitive to compute the common recurrent layer.

See also
dev_guide_rnn in developer guide
cpp_api_rnn in cpp_api

Function Documentation

mkldnn_status_t MKLDNN_API mkldnn_gru_backward_desc_init ( mkldnn_rnn_desc_t rnn_desc,
mkldnn_prop_kind_t  prop_kind,
mkldnn_rnn_direction_t  direction,
const mkldnn_memory_desc_t src_layer_desc,
const mkldnn_memory_desc_t src_iter_desc,
const mkldnn_memory_desc_t weights_layer_desc,
const mkldnn_memory_desc_t weights_iter_desc,
const mkldnn_memory_desc_t bias_desc,
const mkldnn_memory_desc_t dst_layer_desc,
const mkldnn_memory_desc_t dst_iter_desc,
const mkldnn_memory_desc_t diff_src_layer_desc,
const mkldnn_memory_desc_t diff_src_iter_desc,
const mkldnn_memory_desc_t diff_weights_layer_desc,
const mkldnn_memory_desc_t diff_weights_iter_desc,
const mkldnn_memory_desc_t diff_bias_desc,
const mkldnn_memory_desc_t diff_dst_layer_desc,
const mkldnn_memory_desc_t diff_dst_iter_desc,
unsigned  flags 
)

Initializes a GRU descriptor rnn_desc for backward propagation using prop_kind, direction, and memory descriptors.

Note
All memory descriptors are allowed to be initialized with mkldnn_format_kind_any value of format_kind.

src_iter_desc (simultaneously with diff_src_iter_desc), bias_desc (simultaneously with diff_bias_desc), and dst_iter_desc (simultaneously with diff_src_iter_desc) are allowed to either be NULL or point to a zero memory descriptor, which would indicate that the RNN primitive should not use them and will default to zero values.

Parameters:

  • flags (unused for now)

Inputs:

Outputs:

mkldnn_status_t MKLDNN_API mkldnn_gru_forward_desc_init ( mkldnn_rnn_desc_t rnn_desc,
mkldnn_prop_kind_t  prop_kind,
mkldnn_rnn_direction_t  direction,
const mkldnn_memory_desc_t src_layer_desc,
const mkldnn_memory_desc_t src_iter_desc,
const mkldnn_memory_desc_t weights_layer_desc,
const mkldnn_memory_desc_t weights_iter_desc,
const mkldnn_memory_desc_t bias_desc,
const mkldnn_memory_desc_t dst_layer_desc,
const mkldnn_memory_desc_t dst_iter_desc,
unsigned  flags 
)

Initializes a GRU descriptor rnn_desc for forward propagation using prop_kind, direction, and memory descriptors.

Note
If prop_kind equals mkldnn_forward_training, you must query a workspace memory descriptor before creating the primitive.

src_iter_desc, bias_desc, and dst_iter_desc are allowed to either be NULL or point to a zero memory descriptor, which would indicate that the RNN primitive should not use them and will default to zero values.

Note
All memory descriptors except src_iter_desc are allowed to be initialized with mkldnn_format_kind_any value of format_kind.

Parameters:

  • flags (unused for now)

Inputs:

Outputs:

mkldnn_status_t MKLDNN_API mkldnn_lbr_gru_backward_desc_init ( mkldnn_rnn_desc_t rnn_desc,
mkldnn_prop_kind_t  prop_kind,
mkldnn_rnn_direction_t  direction,
const mkldnn_memory_desc_t src_layer_desc,
const mkldnn_memory_desc_t src_iter_desc,
const mkldnn_memory_desc_t weights_layer_desc,
const mkldnn_memory_desc_t weights_iter_desc,
const mkldnn_memory_desc_t bias_desc,
const mkldnn_memory_desc_t dst_layer_desc,
const mkldnn_memory_desc_t dst_iter_desc,
const mkldnn_memory_desc_t diff_src_layer_desc,
const mkldnn_memory_desc_t diff_src_iter_desc,
const mkldnn_memory_desc_t diff_weights_layer_desc,
const mkldnn_memory_desc_t diff_weights_iter_desc,
const mkldnn_memory_desc_t diff_bias_desc,
const mkldnn_memory_desc_t diff_dst_layer_desc,
const mkldnn_memory_desc_t diff_dst_iter_desc,
unsigned  flags 
)

Initializes an LBR GRU descriptor rnn_desc for backward propagation using prop_kind, direction, and memory descriptors.

Note
All memory descriptors are allowed to be initialized with mkldnn_format_kind_any value of format_kind.

src_iter_desc (simultaneously with diff_src_iter_desc), bias_desc (simultaneously with diff_bias_desc), and dst_iter_desc (simultaneously with diff_src_iter_desc) are allowed to either be NULL or point to a zero memory descriptor, which would indicate that the RNN primitive should not use them and will default to zero values.

Parameters:

  • flags (unused for now)

Inputs:

Outputs:

mkldnn_status_t MKLDNN_API mkldnn_lbr_gru_forward_desc_init ( mkldnn_rnn_desc_t rnn_desc,
mkldnn_prop_kind_t  prop_kind,
mkldnn_rnn_direction_t  direction,
const mkldnn_memory_desc_t src_layer_desc,
const mkldnn_memory_desc_t src_iter_desc,
const mkldnn_memory_desc_t weights_layer_desc,
const mkldnn_memory_desc_t weights_iter_desc,
const mkldnn_memory_desc_t bias_desc,
const mkldnn_memory_desc_t dst_layer_desc,
const mkldnn_memory_desc_t dst_iter_desc,
unsigned  flags 
)

Initializes an LBR GRU descriptor rnn_desc for forward propagation using prop_kind, direction, and memory descriptors.

Note
If prop_kind equals mkldnn_forward_training, you must query a workspace memory descriptor before creating the primitive.

src_iter_desc, bias_desc, and dst_iter_desc are allowed to either be NULL or point to a zero memory descriptor, which would indicate that the RNN primitive should not use them and will default to zero values.

Note
All memory descriptors except src_iter_desc are allowed to be initialized with mkldnn_format_kind_any value of format_kind.

Parameters:

  • flags (unused for now)

Inputs:

Outputs:

mkldnn_status_t MKLDNN_API mkldnn_lstm_backward_desc_init ( mkldnn_rnn_desc_t rnn_desc,
mkldnn_prop_kind_t  prop_kind,
mkldnn_rnn_direction_t  direction,
const mkldnn_memory_desc_t src_layer_desc,
const mkldnn_memory_desc_t src_iter_desc,
const mkldnn_memory_desc_t src_iter_c_desc,
const mkldnn_memory_desc_t weights_layer_desc,
const mkldnn_memory_desc_t weights_iter_desc,
const mkldnn_memory_desc_t bias_desc,
const mkldnn_memory_desc_t dst_layer_desc,
const mkldnn_memory_desc_t dst_iter_desc,
const mkldnn_memory_desc_t dst_iter_c_desc,
const mkldnn_memory_desc_t diff_src_layer_desc,
const mkldnn_memory_desc_t diff_src_iter_desc,
const mkldnn_memory_desc_t diff_src_iter_c_desc,
const mkldnn_memory_desc_t diff_weights_layer_desc,
const mkldnn_memory_desc_t diff_weights_iter_desc,
const mkldnn_memory_desc_t diff_bias_desc,
const mkldnn_memory_desc_t diff_dst_layer_desc,
const mkldnn_memory_desc_t diff_dst_iter_desc,
const mkldnn_memory_desc_t diff_dst_iter_c_desc,
unsigned  flags 
)

Initializes an LSTM descriptor rnn_desc for backward propagation using prop_kind, direction, and memory descriptors.

Note
All memory descriptors are allowed to be initialized with mkldnn_format_kind_any value of format_kind.

src_iter_desc (simultaneously with diff_src_iter_desc), bias_desc (simultaneously with diff_bias_desc), and dst_iter_desc (simultaneously with diff_src_iter_desc) are allowed to either be NULL or point to a zero memory descriptor, which would indicate that the RNN primitive should not use them and will default to zero values.

Parameters:

  • flags (unused for now)

Inputs:

Outputs:

mkldnn_status_t MKLDNN_API mkldnn_lstm_forward_desc_init ( mkldnn_rnn_desc_t rnn_desc,
mkldnn_prop_kind_t  prop_kind,
mkldnn_rnn_direction_t  direction,
const mkldnn_memory_desc_t src_layer_desc,
const mkldnn_memory_desc_t src_iter_desc,
const mkldnn_memory_desc_t src_iter_c_desc,
const mkldnn_memory_desc_t weights_layer_desc,
const mkldnn_memory_desc_t weights_iter_desc,
const mkldnn_memory_desc_t bias_desc,
const mkldnn_memory_desc_t dst_layer_desc,
const mkldnn_memory_desc_t dst_iter_desc,
const mkldnn_memory_desc_t dst_iter_c_desc,
unsigned  flags 
)

Initializes an LSTM descriptor rnn_desc for forward propagation using prop_kind, direction, and memory descriptors.

Note
If prop_kind equals mkldnn_forward_training, you must query a workspace memory descriptor before creating the primitive.

src_iter_desc, bias_desc, and dst_iter_desc are allowed to either be NULL or point to a zero memory descriptor, which would indicate that the RNN primitive should not use them and will default to zero values.

Note
All memory descriptors except src_iter_desc are allowed to be initialized with mkldnn_format_kind_any value of format_kind.

Parameters:

  • flags (unused for now)

Inputs:

Outputs:

mkldnn_status_t MKLDNN_API mkldnn_primitive_attr_set_rnn_data_qparams ( mkldnn_primitive_attr_t  attr,
const float  scale,
const float  shift 
)

Sets quantization scale and shift for RNN data tensors. For performance reasons, low precision configuration of RNN primitive expects input activations to have unsigned int8 data type. Scale and shift used to quantize floating point data to unsigned integer must be passed to RNN primitive using attributes. Example usage:

1 // rnn parameters
2 int l = 2, t = 2, mb = 32, sic = 32, slc = 32, dic = 32, dlc = 32;
3 // activations quantization parameters
4 float scale = ..., shift = ..;
5 
6 mkldnn_primitive_attr_t rnn_attr;
7 // create default attributes
8 mkldnn_primitive_attr_create(&rnn_attr);
9 
10 // set scale and shift for int8 quantization of activation
11 mkldnn_primitive_attr_set_rnn_data_qparams(rnn_attr, scale, shift);
12 
13 // create & configure rnn op_desc
14 mkldnn_rnn_desc_t rnn_d;
15 mkldnn_primitive_desc_t rnn_pd;
16 mkldnn_primitive_desc_create(&rnn_pd, &rnn_d, attr, engine, NULL);
Note
Quantization scale and shift are common for src_layer, src_iter, dst_iter and dst_layer.
mkldnn_status_t MKLDNN_API mkldnn_primitive_attr_set_rnn_weights_qparams ( mkldnn_primitive_attr_t  attr,
mkldnn_dim_t  count,
int  mask,
const float *  weights_scales 
)

Sets quantization scales weights_scales for RNN weights tensors. Low precision configuration of RNN primitive expects input weights to have signed int8 data type. Scales used to quantize floating point data to signed integer must be passed to RNN primitive using attributes. The mask argument defines correspondence between output tensor dimensions and the weights_scales array. Set i-th bit of mask to 1 to use dedicated scaling factor for each slice of the output tensor over i-th dimension. Set mask to 0 to use common scaling factor for the whole output tensor. Example usage:

1 // rnn parameters
2 int l = 2, t = 2, mb = 32, sic = 32, slc = 32, dic = 32, dlc = 32;
3 // unique output scales per output channel
4 float weights_scales[dic * n_gates] = { ... };
5 // mask that specifies last two dimensions of ldigo format
6 int mask = 0x3;
7 
8 mkldnn_primitive_attr_t attr;
9 // create default attributes
10 mkldnn_primitive_attr_create(&attr);
11 
12 // set output channel-wise weights scales
13 mkldnn_primitive_attr_set_rnn_weights_qparams(attr, dic * n_gates, mask,
14  weights_scales);
15 
16 // create & configure rnn op_desc
17 mkldnn_rnn_desc_t rnn_d;
18 mkldnn_primitive_desc_t rnn_pd;
19 mkldnn_primitive_desc_create(&rnn_pd, &rnn_d, attr, engine, NULL);
Note
The dimension order is always native and does not depend on the actual layout used. For example, 5 dimensional weights always have (l, d, i, g, o) logical dimension ordering.
Quantization sales are common for weights_layer and weights_iteration
There is no way to check that count corresponds to mask until an actual primitive descriptor is created, so it is user's responsibility to set proper values. The following formula must be held:

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

mkldnn_status_t MKLDNN_API mkldnn_vanilla_rnn_backward_desc_init ( mkldnn_rnn_desc_t rnn_desc,
mkldnn_prop_kind_t  prop_kind,
const mkldnn_alg_kind_t  activation,
const mkldnn_rnn_direction_t  direction,
const mkldnn_memory_desc_t src_layer_desc,
const mkldnn_memory_desc_t src_iter_desc,
const mkldnn_memory_desc_t weights_layer_desc,
const mkldnn_memory_desc_t weights_iter_desc,
const mkldnn_memory_desc_t bias_desc,
const mkldnn_memory_desc_t dst_layer_desc,
const mkldnn_memory_desc_t dst_iter_desc,
const mkldnn_memory_desc_t diff_src_layer_desc,
const mkldnn_memory_desc_t diff_src_iter_desc,
const mkldnn_memory_desc_t diff_weights_layer_desc,
const mkldnn_memory_desc_t diff_weights_iter_desc,
const mkldnn_memory_desc_t diff_bias_desc,
const mkldnn_memory_desc_t diff_dst_layer_desc,
const mkldnn_memory_desc_t diff_dst_iter_desc,
unsigned  flags,
float  alpha,
float  beta 
)

Initializes an RNN descriptor rnn_desc for backward propagation using prop_kind, activation, direction, and memory descriptors.

Note
All memory descriptors are allowed to be initialized with mkldnn_format_kind_any value of format_kind.

src_iter_desc (simultaneously with diff_src_iter_desc), bias_desc (simultaneously with diff_bias_desc), and dst_iter_desc (simultaneously with diff_src_iter_desc) are allowed to either be NULL or point to a zero memory descriptor, which would indicate that the RNN primitive should not use them and will default to zero values.

Parameters:

Inputs:

Outputs:

mkldnn_status_t MKLDNN_API mkldnn_vanilla_rnn_forward_desc_init ( mkldnn_rnn_desc_t rnn_desc,
mkldnn_prop_kind_t  prop_kind,
const mkldnn_alg_kind_t  activation,
const mkldnn_rnn_direction_t  direction,
const mkldnn_memory_desc_t src_layer_desc,
const mkldnn_memory_desc_t src_iter_desc,
const mkldnn_memory_desc_t weights_layer_desc,
const mkldnn_memory_desc_t weights_iter_desc,
const mkldnn_memory_desc_t bias_desc,
const mkldnn_memory_desc_t dst_layer_desc,
const mkldnn_memory_desc_t dst_iter_desc,
unsigned  flags,
float  alpha,
float  beta 
)

Initializes an RNN descriptor rnn_desc for forward propagation using prop_kind, activation, direction, and memory descriptors.

Note
If prop_kind equals mkldnn_forward_training, you must query a workspace memory descriptor before creating the primitive.

src_iter_desc, bias_desc, and dst_iter_desc are allowed to either be NULL or point to a zero memory descriptor, which would indicate that the RNN primitive should not use them and will default to zero values.

Note
All memory descriptorsare allowed to be initialized with mkldnn_format_kind_any value of format_kind.

Parameters:

Inputs:

Outputs: