Skip to content

Commit 957dc2c

Browse files
committed
Arm backend: Add TOSA Special DTYPE for shape handling
Start adding support for shapes by introducing the TOSA 1.0 CONST_SHAPE operation. Change-Id: If5e81567ccbe808b344fe3c8fd74d42109a2995c Signed-off-by: Per Åstrand <per.astrand@arm.com>
1 parent 4d3a1c8 commit 957dc2c

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎backends/arm/_passes/fuse_constant_ops_pass.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _propagate_special_dtype(self, from_nodes, to_node, data):
5858
special_dtypes = set()
5959
for input_node in from_nodes:
6060
special_type = input_node.meta.get(TosaSpecialDtype.meta_key(), None)
61-
if special_type:
61+
if special_type and special_type != TosaSpecialDtype.SHAPE:
6262
special_dtypes.add(special_type)
6363
if len(special_dtypes) > 1:
6464
logger.warning(
@@ -76,6 +76,10 @@ def _fuse_nodes(self, node) -> bool:
7676
data.
7777
"""
7878

79+
if node.meta.get(TosaSpecialDtype.meta_key(), None) == TosaSpecialDtype.SHAPE:
80+
# Skip fusing if special dtype is SHAPE
81+
return False
82+
7983
input_nodes = list(node.all_input_nodes)
8084
qparams = node.meta.get("input_qparams", None)
8185

‎backends/arm/tosa/mapping.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class TosaSpecialDtype(Enum):
3737

3838
INT48 = ts.DType.INT48
3939
INT4 = ts.DType.INT4
40+
SHAPE = ts.DType.SHAPE
4041

4142
def get_tosa_dtype(self) -> ts.DType:
4243
"""Return the underlying ``ts.DType`` enumerant.
@@ -127,6 +128,11 @@ def extract_tensor_meta(meta):
127128
ValueError: If ``meta['val']`` is not a ``FakeTensor``.
128129
129130
"""
131+
special_dtype = meta.get(TosaSpecialDtype.meta_key())
132+
if special_dtype == TosaSpecialDtype.SHAPE:
133+
shape_len = len(meta["val"])
134+
return (ts.DType.SHAPE, (shape_len,), (0,))
135+
130136
if meta.get("val") is None:
131137
raise ValueError("Expected node.meta['val'] to be set to a FakeTensor")
132138
val = meta["val"]

0 commit comments

Comments
 (0)