Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / common / tensor_type.cpp
index 555ca1e..4773448 100644 (file)
@@ -1,5 +1,5 @@
 /*
-// Copyright (c) 2016 Intel Corporation
+// Copyright (c) 2016-2019 Intel Corporation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -30,45 +30,54 @@ namespace kernel_selector
             //X, Y, F, R, B
             {-1,-1, 0,-1, 1 }, // DataLayout::bf
             {-1,-1, 1,-1, 0 }, // DataLayout::fb
-            { 0, 1, 2,-1, 3 },  // DataLayout::bfyx
-            { 2, 3, 1,-1, 0 },  // DataLayout::yxfb
-            { 1, 2, 0,-1, 3 },  // DataLayout::byxf
-            { 1, 2, 3,-1, 0 },  // DataLayout::fyxb
-            {-1,-1, 0,-1, 1 },  // DataLayout::bs_f_bsv8__af8
-            {-1,-1, 0,-1, 1 },  // DataLayout::bs_f_bsv16__af8
-            { 0, 1, 2,-1, 3 },  // DataLayout::bf8_xy16
-            { 0, 1, 2, 3, 4 },  // DataLayout::brfyx
-            { 2, 1, 0,-1, 3 },  // DataLayout::winograd_2x3_s1_data
-            { 1, 2, 0,-1, 3 },  // DataLayout::byxf_af32
-            { 0, 1, 3,-1, 2 },  // DataLayout::fs_bs_yx_bsv4_fsv32
+            { 0, 1, 2,-1, 3 }, // DataLayout::bfyx
+            { 2, 3, 1,-1, 0 }, // DataLayout::yxfb
+            { 1, 2, 0,-1, 3 }, // DataLayout::byxf
+            { 1, 2, 3,-1, 0 }, // DataLayout::fyxb
+            {-1,-1, 0,-1, 1 }, // DataLayout::bs_f_bsv8__af8
+            {-1,-1, 0,-1, 1 }, // DataLayout::bs_f_bsv16__af8
+            { 0, 1, 2,-1, 3 }, // DataLayout::bf8_xy16
+            { 0, 1, 2, 3, 4 }, // DataLayout::brfyx
+            { 2, 1, 0,-1, 3 }, // DataLayout::winograd_2x3_s1_data
+            { 1, 2, 0,-1, 3 }, // DataLayout::byxf_af32
+            { 1, 2, 0,-1, 3 }, // DataLayout::byx8_f8
+            { 0, 1, 3,-1, 2 }, // DataLayout::fs_bs_yx_bsv4_fsv32
+            { 0, 1, 2, -1, 3 },// DataLayout::b_fs_yx_fsv4
         } };
 
-        std::array<std::array<int, 4>, WeightsLayout::WeightsLayoutCount> WeightsTensor::weightsChannelArray
+        std::array<std::array<int, 6>, WeightsLayout::WeightsLayoutCount> WeightsTensor::weightsChannelArray
         { {
-            //X, Y, I, O
-            {-1,-1, 0, 1 },  // WeightsLayout::oi
-            {-1,-1, 1, 0 },  // WeightsLayout::io
-            { 0, 1, 2, 3 },  // WeightsLayout::oiyx
-            { 1, 2, 0, 3 },  // WeightsLayout::oyxi
-            { 1, 2, 3, 0 },  // WeightsLayout::iyxo
-            { 2, 3, 1, 0 },  // WeightsLayout::yxio
-            { 0, 1, 2, 3 },  // WeightsLayout::os_iyx_osv16
-            { 0, 1, 2, 3 },  // WeightsLayout::os_iyx_osv16_rotate_180
-            {-1,-1, 0, 1 },  // WeightsLayout::os_i_osv8__ai8
-            {-1,-1, 0, 1 },  // WeightsLayout::os_i_osv16__ai8
-            {-1,-1, 0, 1 },  // WeightsLayout::os_i_osv16            
-            { 1, 2, 3, 0 },  // WeightsLayout::i_yxs_os_yxsv2_osv16
-            { 1, 2, 3, 0 },  // WeightsLayout::iy_xs_os_xsv2_osv16__ao32
-            { 1, 2, 3, 0 },  // WeightsLayout::iy_xs_os_xsv2_osv8__ao32
-            { 0, 1, 2, 3 },  // WeightsLayout::image_2d_weights_c4_fyx_b
-            { 0, 1, 2, 3 },  // WeightsLayout::image_2d_weights_c1_b_fyx
-            { 3, 2, 1, 0 },  // WeightsLayout::winograd_2x3_s1_weights
-            { 0, 1, 2, 3 },  // WeightsLayout::winograd_2x3_s1_fused_weights
-            { 0, 1, 2, 3 },  // WeightsLayout::winograd_6x3_s1_fused_weights
-            { 0, 1, 2, 3 },  // WeightsLayout::image_2d_weights_winograd_6x3_s1_fbxyb
-            { 0, 1, 2, 3 },  // WeightsLayout::image_2d_weights_winograd_6x3_s1_xfbyb
-            { 0, 1, 2, 3 },  // WeightsLayout::os_is_yx_isa8_osv8_isv4
-            { 1, 2, 0, 3 },  // WeightsLayout::is_o_yx_isv32
+            // X, Y,   I,  O, LX, LY,
+            { -1, -1,  0,  1, -1, -1 }, // WeightsLayout::oi
+            { -1, -1,  1,  0, -1, -1 }, // WeightsLayout::io
+            {  0,  1,  2,  3, -1, -1 }, // WeightsLayout::oiyx
+            {  1,  2,  0,  3, -1, -1 }, // WeightsLayout::oyxi
+            {  1,  2,  3,  0, -1, -1 }, // WeightsLayout::iyxo
+            {  2,  3,  1,  0, -1, -1 }, // WeightsLayout::yxio
+            {  0,  1,  2,  3, -1, -1 }, // WeightsLayout::os_iyx_osv16
+            {  0,  1,  2,  3, -1, -1 }, // WeightsLayout::os_iyx_osv32
+            {  0,  1,  2,  3, -1, -1 }, // WeightsLayout::os_iyx_osv64
+            {  0,  1,  2,  3, -1, -1 }, // WeightsLayout::os_iyx_osv16_rotate_180
+            { -1, -1,  0,  1, -1, -1 }, // WeightsLayout::os_i_osv8__ai8
+            { -1, -1,  0,  1, -1, -1 }, // WeightsLayout::os_i_osv16__ai8
+            { -1, -1,  0,  1, -1, -1 }, // WeightsLayout::os_i_osv16
+            {  1,  2,  3,  0, -1, -1 }, // WeightsLayout::i_yxs_os_yxsv2_osv16
+            {  1,  2,  3,  0, -1, -1 }, // WeightsLayout::iy_xs_os_xsv2_osv16__ao32
+            {  1,  2,  3,  0, -1, -1 }, // WeightsLayout::iy_xs_os_xsv2_osv8__ao32
+            {  0,  1,  2,  3, -1, -1 }, // WeightsLayout::image_2d_weights_c4_fyx_b
+            {  0,  1,  2,  3, -1, -1 }, // WeightsLayout::image_2d_weights_c1_b_fyx
+            {  3,  2,  1,  0, -1, -1 }, // WeightsLayout::winograd_2x3_s1_weights
+            {  0,  1,  2,  3, -1, -1 }, // WeightsLayout::winograd_2x3_s1_fused_weights
+            {  0,  1,  2,  3, -1, -1 }, // WeightsLayout::winograd_6x3_s1_fused_weights
+            {  0,  1,  2,  3, -1, -1 }, // WeightsLayout::image_2d_weights_winograd_6x3_s1_fbxyb
+            {  0,  1,  2,  3, -1, -1 }, // WeightsLayout::image_2d_weights_winograd_6x3_s1_xfbyb
+            {  0,  1,  2,  3, -1, -1 }, // WeightsLayout::os_is_yx_isa8_osv8_isv4
+            {  0,  1,  2,  3, -1, -1 }, // WeightsLayout::os_is_yx_isa8_osv8_isv4_swizzled_by_4
+            {  1,  2,  0,  3, -1, -1 }, // WeightsLayout::is_o_yx_isv32
+            {  1,  2,  0,  3, -1, -1 }, // WeightsLayout::is_o32_yx_isv32_swizzled_by_4
+            {  0,  1,  2,  3, -1, -1 }, // WeightsLayout::os_is_y_x8_osv8_isv4
+            {  0,  1,  2,  3,  4,  5 }, // WeightsLayout::bf_lyx_yx
+            {  0,  1,  2,  3, -1, -1 }, // WeightsLayout::os_is_yx_osv16_isv4
         } };
 
         NDims DataTensor::GetSimpleDims(const std::vector<size_t>& d, DataLayout l)
@@ -98,6 +107,11 @@ namespace kernel_selector
                 assert(newDims.size() == 4);
                 newDims[0] = RoundUp(newDims[0], 32);
                 break;
+            case byx8_f4:
+                assert(newDims.size() == 4);
+                newDims[0] = RoundUp(newDims[0], 4);
+                newDims[1] = RoundUp(newDims[1], 8);
+                break;
             case fs_bs_yx_bsv4_fsv32:
                 assert(newDims.size() == 4);
                 newDims[3] = RoundUp(newDims[3], 32);
@@ -117,7 +131,7 @@ namespace kernel_selector
                 pitch *= newDims[i];
             }
 
-            if (l == byxf_af32 || l == fs_bs_yx_bsv4_fsv32)
+            if (l == byxf_af32 || l == fs_bs_yx_bsv4_fsv32 || l == byx8_f4)
             {
                 ret[0].pitch = 1;
                 ret[1].pitch = ret[0].pitch * newDims[0];
@@ -266,6 +280,14 @@ namespace kernel_selector
                 assert(newDims.size() == 4);
                 newDims[3] = RoundUp(newDims[3], 16);
                 break;
+            case os_iyx_osv32:
+                assert(newDims.size() == 4);
+                newDims[3] = RoundUp(newDims[3], 32);
+                break;
+            case os_iyx_osv64:
+                assert(newDims.size() == 4);
+                newDims[3] = RoundUp(newDims[3], 64);
+                break;
             case os_i_osv8__ai8:
                 assert(newDims.size() == 2);
                 newDims[0] = RoundUp(newDims[0], 8);
@@ -294,10 +316,31 @@ namespace kernel_selector
                 newDims[3] = RoundUp(newDims[3], 8);
                 newDims[2] = RoundUp(newDims[2], 32);
                 break;
+            case os_is_yx_isa8_osv8_isv4_swizzled_by_4:
+                assert(newDims.size() == 4);
+                newDims[3] = RoundUp(newDims[3], 32);
+                newDims[2] = RoundUp(newDims[2], 32);
+                break;
             case is_o_yx_isv32:
                 assert(newDims.size() == 4);
                 newDims[0] = RoundUp(newDims[0], 32);
                 break;
+            case is_o32_yx_isv32_swizzled_by_4:
+                assert(newDims.size() == 4);
+                newDims[0] = RoundUp(newDims[0], 32);
+                newDims[3] = RoundUp(newDims[3], 32);
+                break;
+            case os_is_y_x8_osv8_isv4:
+                assert(newDims.size() == 4);
+                newDims[2] = RoundUp(newDims[2], 4);
+                newDims[3] = RoundUp(newDims[3], 8);
+                newDims[0] = RoundUp(newDims[0], 8);
+                break;
+            case os_is_yx_osv16_isv4:
+                assert(newDims.size() == 4);
+                newDims[2] = RoundUp(newDims[2], 4);
+                newDims[3] = RoundUp(newDims[3], 16);
+                break;
             default:
                 break;
             }
@@ -322,15 +365,20 @@ namespace kernel_selector
             {
                 ret[2].pitch     = RoundUp(ret[1].v, 2) * ret[1].pitch;
                 ret[1].pad.after = newDims[1] - ret[1].v;
-                
+
                 ret[3].pitch     = ret[2].v * ret[2].pitch;
                 ret[2].pad.after = newDims[2] - ret[2].v;
             }
-            else if (l == os_is_yx_isa8_osv8_isv4)
+            else if (l == os_is_yx_isa8_osv8_isv4 || l == os_is_yx_isa8_osv8_isv4_swizzled_by_4)
             {
                 ret[0].pitch = 256;
                 ret[1].pitch = ret[0].pitch * ret[0].v;
             }
+            else if (l == bf_lyx_yx)
+            {
+                ret[2].pitch = ret[0].v * ret[1].v * ret[2].v * ret[3].v;
+                ret[3].pitch = ret[2].pitch * ret[5].v;
+            }
 
             return ret;
         }
@@ -385,6 +433,15 @@ namespace kernel_selector
                 vec[Channelndex(l, WeightsChannelName::IFM)] = dst_ifm;
                 vec[Channelndex(l, WeightsChannelName::OFM)] = OFM().v;
             }
+            else if (src_channels == 6 && dst_channels == 6)
+            {
+                vec[Channelndex(l, WeightsChannelName::X)] = IFM().v;
+                vec[Channelndex(l, WeightsChannelName::Y)] = OFM().v;
+                vec[Channelndex(l, WeightsChannelName::IFM)] = LX().v;
+                vec[Channelndex(l, WeightsChannelName::OFM)] = LY().v;
+                vec[Channelndex(l, WeightsChannelName::LX)] = X().v;
+                vec[Channelndex(l, WeightsChannelName::LY)] = Y().v;
+            }
             else
             {
                 assert(0);