aboutsummaryrefslogtreecommitdiff
path: root/ethosu/vela/architecture_features.py
diff options
context:
space:
mode:
authorLouis Verhaard <louis.verhaard@arm.com>2020-11-17 09:45:20 +0100
committerLouis Verhaard <louis.verhaard@arm.com>2020-11-17 14:30:52 +0100
commit69b3176127ff8522903e087d56e2d2f4ec557d62 (patch)
treeeafccbe6d44fe7b73e657cc462d8770da69ea0a2 /ethosu/vela/architecture_features.py
parent0411edb8947bc2993b1f9498ef43d5b40a2a6305 (diff)
downloadethos-u-vela-69b3176127ff8522903e087d56e2d2f4ec557d62.tar.gz
MLBEDSW-3491: Fix index out of range in code gen
Usage of shape[-2] could cause index out of range. Signed-off-by: Louis Verhaard <louis.verhaard@arm.com> Change-Id: I1b64b117f8236ce9ba321ca03bdb25e5a03a6589
Diffstat (limited to 'ethosu/vela/architecture_features.py')
-rw-r--r--ethosu/vela/architecture_features.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/ethosu/vela/architecture_features.py b/ethosu/vela/architecture_features.py
index 6a02a4e9..1eae79a2 100644
--- a/ethosu/vela/architecture_features.py
+++ b/ethosu/vela/architecture_features.py
@@ -23,6 +23,7 @@ import numpy as np
from .errors import OptionError
from .ethos_u55_regs.ethos_u55_regs import resampling_mode
+from .numeric_util import full_shape
from .numeric_util import round_up
from .numeric_util import round_up_divide
from .operation import Kernel
@@ -55,6 +56,13 @@ class Block:
w, h, c = (int(v) for v in s.split("x"))
return cls(w, h, c)
+ @classmethod
+ def from_shape(cls, shape) -> "Block":
+ """Converts the shape to a Block"""
+ shp = full_shape(3, shape, 1)
+ # Note: index from end, as len(shp) may be > 3
+ return Block(shp[-2], shp[-3], shp[-1])
+
class Rect:
def __init__(self, x, y, z, x2, y2, z2):