MLBEDSW-5629: MLCE: Model falling when creating explicit_padding

 - Issue was due to a previous patch to fix MLBEDSW-4350
 - Manually reverted that fix 5fabfcaa2b636b02899b4d6e0ccf95d853986475
 - Made a new fix for MLBEDSW-4350 that calculates the padding and
skirt by taking into account the split read offsets and shapes

Signed-off-by: Tim Hall <tim.hall@arm.com>
Change-Id: I96010c1b977011aecbc411a3c91ab3e61af22db4
diff --git a/ethosu/vela/graph_optimiser_util.py b/ethosu/vela/graph_optimiser_util.py
index 3e15f12..57fd7db 100644
--- a/ethosu/vela/graph_optimiser_util.py
+++ b/ethosu/vela/graph_optimiser_util.py
@@ -235,10 +235,6 @@
         cons_op.set_input_tensor(op.ifm, cons_op.type.info.indices.ifms[1])
         cons_op.ifm_shapes[1] = op.ifm_shapes[0]
 
-    if "skirt" in cons_op.attrs:
-        assert cons_op.attrs["explicit_padding"] == cons_op.attrs["skirt"]
-        cons_op.attrs["skirt"] = None
-        cons_op.attrs["force_padding"] = True
     op.ofm.consumer_list.remove(cons_op)
     op.ofm.ops = []
     op.ifm.consumer_list.remove(op)
diff --git a/ethosu/vela/high_level_command_stream.py b/ethosu/vela/high_level_command_stream.py
index ddb2482..abf6d83 100644
--- a/ethosu/vela/high_level_command_stream.py
+++ b/ethosu/vela/high_level_command_stream.py
@@ -78,8 +78,14 @@
         if strides is not None and skirt is not None:
             if len(new_start_coord) >= 2:
                 stride = strides[2]
-                new_start_coord[-2] = max(new_start_coord[-2] * stride - skirt[1], 0)
-                new_end_coord[-2] = min(new_end_coord[-2] * stride + skirt[3], ifm_shape.width)
+                # if the current op was combined with a split slice read then the valid ifm range is given by the output
+                # of the split op
+                if split_offset is None:
+                    new_start_coord[-2] = max(new_start_coord[-2] * stride - skirt[1], 0)
+                    new_end_coord[-2] = min(new_end_coord[-2] * stride + skirt[3], ifm_shape.width)
+                else:
+                    new_start_coord[-2] = max(new_start_coord[-2] * stride - skirt[1], split_offset[-2])
+                    new_end_coord[-2] = min(new_end_coord[-2] * stride + skirt[3], split_shape[-2])
 
             if len(new_start_coord) >= 3:
                 stride = strides[1]
diff --git a/ethosu/vela/high_level_command_to_npu_op.py b/ethosu/vela/high_level_command_to_npu_op.py
index 318960e..9abfbd4 100644
--- a/ethosu/vela/high_level_command_to_npu_op.py
+++ b/ethosu/vela/high_level_command_to_npu_op.py
@@ -147,13 +147,22 @@
         top = cmd.pad_top
         bottom = cmd.pad_bottom
 
+    # the ifm box coordinate range depends upon whether the primary op was combined with a split slice read
+    ifm_read_offset = primary_op.read_offsets[0]
+    ifm_read_shape = primary_op.read_shapes[0]
+    if ifm_read_offset is None or len(ifm_read_offset) < 2:
+        box_start_coord_min = 0
+        box_end_coord_max = cmd.ps.ifm_shapes[0].width
+    else:
+        box_start_coord_min = ifm_read_offset[-2]
+        box_end_coord_max = ifm_read_shape[-2]
+
     # Indexing from end since a 1x1 Avgpool might have been added with non 4-dimensional input/output,
     # because of activation function needed to be fused.
-    if not primary_op.attrs.get("force_padding"):
-        if len(cmd.ifm_box.start_coord) >= 2 and cmd.ifm_box.start_coord[-2] > 0:
-            left = 0
-        if len(cmd.ifm_box.end_coord) >= 2 and cmd.ifm_box.end_coord[-2] < cmd.ps.ifm_shapes[0].width:
-            right = 0
+    if len(cmd.ifm_box.start_coord) >= 2 and cmd.ifm_box.start_coord[-2] > box_start_coord_min:
+        left = 0
+    if len(cmd.ifm_box.end_coord) >= 2 and cmd.ifm_box.end_coord[-2] < box_end_coord_max:
+        right = 0
     return NpuPadding(top=top, left=left, bottom=bottom, right=right)