Query supported Data formats
Hi,
Is there any API that we can use to query all the data formats supported by each layer?
And can you also explain how convolution layer picks the data format(nchw or nchw8c or nchw16c)? As i have seen convolution performing better with nchw format over nchw8c/16c on AVX2/512 for some dimensions.
Thanks, Pranathi.
Hi @pranathibl,
No there is no such API. However, for the plain formats (non-blocked, like nchw, acdb, x, etc...) we document which primitives support which data formats in Data Representation section. For instance, 4D batch normalization is optimized for nchw and nhwc memory formats, as well as for the optimized formats (which means whatever the convolution or other compute-bound primitive will return).
And can you also explain how convolution layer picks the data format(nchw or nchw8c or nchw16c)?
Typically, each platform has its favorite format that we try to use everywhere to avoid unnecessary reorders. For AVX2 and below that is nChw8c memory format, while for AVX512 and above this is nChw16c. But there might be cases when other formats will be picked. For instance, grouped convolutions for which number of channels divided by number of groups is only divisible by 4, but not 8 will most likely pick nChw4c memory format.
Also, if the number of input channels is less than 8, we might use nchw memory format for the input tensor.
As i have seen convolution performing better with nchw format over nchw8c/16c on AVX2/512 for some dimensions.
That might indicate a performance bug in the library, limitation of the approach, or something else. For instance, if the number of output channels is 2, we, by default, can still pick the blocked format, in which case there would be a huge padding (say, 16-2=14 on AVX512 platform). For such cases, it might be beneficial to use nchw.
So, more data is required. Could you please share the convolution shapes and times you observe where nchw is better than the blocked format (please also mention the hardware).
Preferably in benchdnn run-lines form, e.g.:
$ OMP_NUM_THREADS=1 ./tests/benchdnn/benchdnn --conv --mode=P --stag=any,nchw mb8_ic32oc32_ih13kh3ph1
Output template: perf,%engine%,%name%,%prb%,%Gops%,%Gfreq%,%-time%,%-Gflops%,%0time%,%0Gflops%
perf,cpu,,--conv mb8ic32ih13oc32oh13kh3ph1,0.0224297,0,0.173096,129.58,0.173971,128.928
perf,cpu,,--conv --stag=nchw mb8ic32ih13oc32oh13kh3ph1,0.0224297,0,0.652344,34.3832,0.65581,34.2015
Closing as the question seems to be addressed. Feel free to reopen or submit a new one if you have any further questions.