The shuffle primitive shuffles data along the shuffle axis (here is designated as \(C\)) with the group parameter \(G\). Namely, the shuffle axis is thought to be a 2D tensor of size \((\frac{C}{G} \times G)\) and it is being transposed to \((G \times \frac{C}{G})\).
The formal definition is shown below:
\[ dst(\overline{ou}, c, \overline{in}) = src(\overline{ou}, c', \overline{in}) \]
where
group_size
,\(c'\) and \(c\) relate to each other as define by the system:
\[ \begin{cases} c &= u + v\frac{C}{G}, \\ c' &= uG + v, \\ \end{cases} \]
Here, \(u \in [0, \frac{C}{G})\) and \(v \in [0, G)\).
There is no difference between the mkldnn_forward_training and mkldnn_forward_inference propagation kinds.
The backward propagation computes \(diff\_src(ou, c, in)\), based on \(diff\_dst(ou, c, in)\).
Essentially, backward propagation is the same as forward propagation with \(g\) replaced by \(C / g\).
src
and dst
are assumed to be the same, and in the API are typically referred as data
(e.g., see data_desc
in mkldnn::shuffle_forward::desc::desc()). The same holds for diff_src
and diff_dst
. The corresponding memory descriptors are referred to as diff_data_desc
.The shuffle primitive supports the following combinations of data types:
Propagation | Sou |
---|---|
forward / backward | f32 |
forward | s32, s8, u8 |
The shuffle primitive works with arbitrary data tensors. There is no special meaning associated with any logical dimensions. However, the shuffle axis is typically referred to as channels (hence in formulas we use \(c\)).
Shuffle operation typically appear in CNN topologies. Hence, in the library the shuffle primitive is optimized for the corresponding memory formats:
Spatial | Logical tensor | Shuffle Axis | Implementations optimized for memory formats |
---|---|---|---|
2D | NCHW | 1 (C) | mkldnn_nchw (mkldnn_abcd), mkldnn_nhwc (mkldnn_acdb), optimized^ |
3D | NCDHW | 1 (C) | mkldnn_ncdhw (mkldnn_abcde), mkldnn_ndhwc (mkldnn_acdeb), optimized^ |
Here optimized^ means the format that comes out of any preceding compute-intensive primitive.
The shuffle primitive doesn't support any post-ops or attributes.
N/A