COMPMID-934: Asymmetric padding support.

Change-Id: Ibe7a679e4c053a088b8c893e495c97cb24bf7272
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/121298
Tested-by: Jenkins <bsgcomp@arm.com>
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
diff --git a/src/core/NEON/kernels/NEDirectConvolutionLayerKernel.cpp b/src/core/NEON/kernels/NEDirectConvolutionLayerKernel.cpp
index 536a667..4dc186a 100644
--- a/src/core/NEON/kernels/NEDirectConvolutionLayerKernel.cpp
+++ b/src/core/NEON/kernels/NEDirectConvolutionLayerKernel.cpp
@@ -274,6 +274,7 @@
         ARM_COMPUTE_ERROR_ON(input->info()->dimension(Window::DimX) > small_tensor_size_optim);
         ARM_COMPUTE_ERROR_ON(input->info()->dimension(Window::DimY) > small_tensor_size_optim);
 
+        const int          input_stride_x  = input->info()->strides_in_bytes().x();
         const int          input_stride_y  = input->info()->strides_in_bytes().y();
         const int          input_stride_z  = input->info()->strides_in_bytes().z();
         const int          output_stride_y = output->info()->strides_in_bytes().y();
@@ -284,6 +285,8 @@
         const int          range_z         = window.z().end() - window.z().start();
         const int          kernel_depth    = weights->info()->dimension(Window::DimZ);
         const unsigned int conv_stride_y   = std::get<1>(conv_info.stride());
+        const unsigned int conv_pad_left   = conv_info.pad_left();
+        const unsigned int conv_pad_top    = conv_info.pad_top();
 
         // setup output window for the iterator
         Window window_out = window;
@@ -307,7 +310,7 @@
 
         execute_window_loop(window_out, [&](const Coordinates & id)
         {
-            const uint8_t *input_ptr                       = in.ptr();
+            const uint8_t *input_ptr                       = in.ptr() - conv_pad_left * input_stride_x - conv_pad_top * input_stride_y;
             uint8_t       *out_ptr                         = out.ptr();
             int            ih                              = 0;
             int            oh                              = 0;
@@ -351,6 +354,7 @@
     static void convolve(const Window &window, unsigned int num_elems_read_per_iteration, unsigned int num_elems_written_per_iteration,
                          const ITensor *input, const ITensor *weights, ITensor *output, const PadStrideInfo &conv_info)
     {
+        const int          input_stride_x       = input->info()->strides_in_bytes().x();
         const int          input_stride_y       = input->info()->strides_in_bytes().y();
         const int          input_stride_z       = input->info()->strides_in_bytes().z();
         const int          output_stride_y      = output->info()->strides_in_bytes().y();
@@ -362,6 +366,8 @@
         const int          range_z              = window.z().end() - window.z().start();
         const int          kernel_depth         = weights->info()->dimension(Window::DimZ);
         const unsigned int conv_stride_y        = std::get<1>(conv_info.stride());
+        const unsigned int conv_pad_left        = conv_info.pad_left();
+        const unsigned int conv_pad_top         = conv_info.pad_top();
         const int          fixed_point_position = input->info()->fixed_point_position();
 
         // setup output window for the iterator
@@ -389,7 +395,7 @@
             /*
                 For a detailed explanation on how the algorithm works refer to template <> class convolver_3x3<1>
             */
-            const uint8_t *input_ptr = in.ptr();
+            const uint8_t *input_ptr = in.ptr() - conv_pad_left * input_stride_x - conv_pad_top * input_stride_y;
             uint8_t       *out_ptr   = out.ptr();
             int            ih        = 0;
             int            oh        = 0;
@@ -680,8 +686,8 @@
         const int          delta_input          = get_input_num_elems_processed<stridex>(num_elems_written_per_iteration);
         const int          kernel_depth         = weights->info()->dimension(Window::DimZ);
         const unsigned int conv_stride_y        = std::get<1>(conv_info.stride());
-        const unsigned int conv_pad_x           = std::get<0>(conv_info.pad());
-        const unsigned int conv_pad_y           = std::get<1>(conv_info.pad());
+        const unsigned int conv_pad_left        = conv_info.pad_left();
+        const unsigned int conv_pad_top         = conv_info.pad_top();
         const int          fixed_point_position = input->info()->fixed_point_position();
 
         // setup output window for the iterator
@@ -707,7 +713,7 @@
 
         execute_window_loop(window_out, [&](const Coordinates & id)
         {
-            const uint8_t *input_ptr = in.ptr() - conv_pad_x * input_stride_x - conv_pad_y * input_stride_y;
+            const uint8_t *input_ptr = in.ptr() - conv_pad_left * input_stride_x - conv_pad_top * input_stride_y;
             uint8_t       *out_ptr   = out.ptr();
             int            ih        = 0;
             int            oh        = 0;
@@ -804,8 +810,8 @@
         const int          delta_input          = get_input_num_elems_processed<stridex>(num_elems_written_per_iteration);
         const int          kernel_depth         = weights->info()->dimension(Window::DimZ);
         const unsigned int conv_stride_y        = std::get<1>(conv_info.stride());
-        const unsigned int conv_pad_x           = std::get<0>(conv_info.pad());
-        const unsigned int conv_pad_y           = std::get<1>(conv_info.pad());
+        const unsigned int conv_pad_left        = conv_info.pad_left();
+        const unsigned int conv_pad_top         = conv_info.pad_top();
         const int          fixed_point_position = input->info()->fixed_point_position();
 
         // setup output window for the iterator
@@ -831,7 +837,7 @@
 
         execute_window_loop(window_out, [&](const Coordinates & id)
         {
-            const uint8_t *input_ptr = in.ptr() - conv_pad_x * input_stride_x - conv_pad_y * input_stride_y;
+            const uint8_t *input_ptr = in.ptr() - conv_pad_left * input_stride_x - conv_pad_top * input_stride_y;
             uint8_t       *out_ptr   = out.ptr();
             int            ih        = 0;
             int            oh        = 0;
@@ -1016,13 +1022,6 @@
     ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, weights, output);
     ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QS8, DataType::QS16, DataType::F16, DataType::F32);
     ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights);
-    ARM_COMPUTE_RETURN_ERROR_ON(!conv_info.padding_is_symmetric());
-    ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(0) == 1 && (std::get<0>(conv_info.pad()) || std::get<1>(conv_info.pad())),
-                                    "Pad > 0 not supported for 1x1 weights");
-    ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(0) == 3 && (std::get<0>(conv_info.pad()) > 1 || std::get<1>(conv_info.pad()) > 1),
-                                    "Pad > 1 not supported for 3x3 weights");
-    ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(0) == 5 && (std::get<0>(conv_info.pad()) > 2 || std::get<1>(conv_info.pad()) > 2),
-                                    "Pad > 2 not supported for 5x5 weights");
 
     ARM_COMPUTE_RETURN_ERROR_ON_MSG(std::get<0>(conv_info.stride()) > 3, "Strides larger than 3 not supported.");
     ARM_COMPUTE_RETURN_ERROR_ON(weights->dimension(2) != input->dimension(2));
@@ -1204,7 +1203,7 @@
     unsigned int num_weight_elems_read_per_row   = 0;
     unsigned int num_elems_read_per_iteration    = 0;
     unsigned int num_elems_written_per_iteration = 0;
-    BorderSize   border_size(conv_info.pad().first, conv_info.pad().second);
+    BorderSize   border_size                     = {};
     ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, weights, output, conv_info));
     ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(),
                                                               weights->clone().get(),