NSPC memory layout for weights and setting defaults
Hi, I am struggling to understand why the memory tag for weights is what it is in this case: https://github.com/oneapi-src/oneDNN/blob/6bbc076ad32be82dae23cc1cd37da6323a305544/src/cpu/gemm_convolution_utils.cpp#L1079-L1083
Because according to ./include/dnnl_types.h, the correspondence is:
dnnl_ohwi = dnnl_acdb
dnnl_hwio = dnnl_cdba
dnnl_oihw = dnnl_abcd
dnnl_nhwc = dnnl_acdb
dnnl_nchw = dnnl_abcd
... and therefore it seems to me that the weights layout when is_nspc=true should be owi/ohwi instead of wio/hwio? What am I missing?
I ended up here from looking into changing the default memory layout when using Arm Compute Library:
https://github.com/oneapi-src/oneDNN/blob/6bbc076ad32be82dae23cc1cd37da6323a305544/src/cpu/aarch64/acl_gemm_convolution_utils.cpp#L161-L165
Should this be as easy as changing default_dat_tag to utils::pick(ndims - 3, format_tag::nwc, format_tag::nhwc)? If yes, I might be missing something else as it this change causes lots of troubles for the benchdnn test suite.
Thank you!
Hi @diaena,
Picking the "default" memory formats is in a sense a grey area of oneDNN :)
First of all, let me clarify that src and weights are independent. So, there is no requirement for weights to have the same tag as source. It is just a coincidence, that for nchw src memory format we pick oihw weights memory format that both happen to be abcd (natural order).
The reason we pick hwio for weights when the src is nhwc is because:
- For our gemm-based implementation
hwioworks "good" in terms of performance (there might be other formats that work good too); hwiois a default memory format of weights in TensorFlow. Given thathwioworks good we pick exactly it to avoid extra conversions on TF side.
The same logic applies for oihw weights format in case of nchw src format: that were the default formats in Caffe (historical reasons).
In general, each implementation is free to pick whatever it wants as long as a user has set the format tag any. So, if Arm implementation would benefit more from using weights in ohwi format, that's perfectly fine to pick it there.