Onednn: Reorder might miss tail bytes

Created on 9 Jun 2017  路  3Comments  路  Source: oneapi-src/oneDNN

I contrived a case with shape (1, 7, 1, 5), a thin board of data can easily imagine. Which I would like to reorder it from nchw into nChw8c, might became a stick.

But from the code I have reviewed, the reorder will stop reorder it at the bold line blow because dims[2]/8 definitely equals 0.

#       pragma omp parallel for collapse(3) schedule(static)
        for (int n = 0; n < dims[0]; ++n) {
            **for (int C = 0; C < dims[1] / blksize; ++C) {**
                for (int h = 0; h < dims[2]; ++h) {
                    constexpr int i_c_mult = order_keep ? blksize : 1;
                    constexpr int o_c_mult = order_keep ? 1 : blksize;
                    auto i = &input[input_d.blk_off(n, i_c_mult * C, h)];
                    auto o = &output[output_d.blk_off(n, o_c_mult * C, h)];
                    ker(i, o);
                }
            }
        }

I also printed out the description of memory, should the padding_dims be (1, 8, 1, 5) ? Or I'm understand it wrong @emfomenk

    desc_ = {
      primitive_kind = mkldnn_memory
      ndims = 4
      dims = ([0] = 1, [1] = 7, [2] = 1, [3] = 5, [4] = 1606405408, [5] = 32767, [6] = -1858001806, [7] = 32767, [8] = 1606405424, [9] = 32767, [10] = -1858001806, [11] = 32767)
      data_type = mkldnn_f32
      format = mkldnn_nChw8c
      layout_desc = {
        blocking = {
          block_dims = ([0] = 1, [1] = 8, [2] = 1, [3] = 1, [4] = 31579992, [5] = 1, [6] = 12569776, [7] = 5, [8] = 3, [9] = 0, [10] = 5120, [11] = 0)
          strides = {
            [0] = ([0] = 1, [1] = 1, [2] = 40, [3] = 8, [4] = 4322763376, [5] = 4322763360, [6] = 140734799794168, [7] = 140734799793552, [8] = 4462111037, [9] = 4322763360, [10] = 4322763360, [11] = 0)
            [1] = ([0] = 8, [1] = 1, [2] = 1, [3] = 1, [4] = 4322763360, [5] = 140734799794168, [6] = 4322763360, [7] = 140734799794168, [8] = 140734799794168, [9] = 140734799794168, [10] = 4, [11] = 140734799794168)
          }
          **padding_dims = ([0] = 1, [1] = 7, [2] = 1, [3] = 5, [4] = 167140613, [5] = 1, [6] = 1606406136, [7] = 32767, [8] = 4, [9] = 0, [10] = 1606406136, [11] = 32767)**
          offset_padding_to_data = ([0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 167145172, [5] = 1, [6] = 1606406136, [7] = 32767, [8] = 1606406136, [9] = 32767, [10] = 4, [11] = 0)
          offset_padding = 0
mkl-dnn concepts question

Most helpful comment

Sorry for delay.

Blocked format doesn't support padded_sizes which are not multiple of block sizes. I.e. in your case if padding_dims[1] = dims[1] = 7 -- is not multiple of 8. Ideally MKL-DNN should return error at creation/initialization time... (need to fix that).

MKL-DNN would not support explicit automatic paddings. But you still may do manual padding and set padding_dims[1] = 8 and sizes[1] = 7. Do not forget to adjust the strides. In theory that should work.

Alternatively you may use view primitive descriptor to create such a memory descriptor.

So far we don't have good ideas how to support nChw8c format for the tensors with C % 8 != 0.

All 3 comments

Ok, I got it, we do not reorder tail situation. I'll ask another question, will we implement automatic padding in future?

Sorry for delay.

Blocked format doesn't support padded_sizes which are not multiple of block sizes. I.e. in your case if padding_dims[1] = dims[1] = 7 -- is not multiple of 8. Ideally MKL-DNN should return error at creation/initialization time... (need to fix that).

MKL-DNN would not support explicit automatic paddings. But you still may do manual padding and set padding_dims[1] = 8 and sizes[1] = 7. Do not forget to adjust the strides. In theory that should work.

Alternatively you may use view primitive descriptor to create such a memory descriptor.

So far we don't have good ideas how to support nChw8c format for the tensors with C % 8 != 0.

@emfomenk Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CaoZhongZ picture CaoZhongZ  路  6Comments

kruus picture kruus  路  6Comments

Gxllii picture Gxllii  路  6Comments

bhack picture bhack  路  7Comments

ratan picture ratan  路  6Comments