-
Notifications
You must be signed in to change notification settings - Fork 509
/
Copy pathop_amin.py
52 lines (42 loc) · 1.46 KB
/
op_amin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Copyright 2025 Arm Limited and/or its affiliates.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
from typing import List
import serializer.tosa_serializer as ts
from executorch.backends.arm._passes.arm_pass_utils import get_first_fake_tensor
from executorch.backends.arm.operators.node_visitor import (
NodeVisitor,
register_node_visitor,
)
from executorch.backends.arm.tosa_mapping import TosaArg
from serializer.tosa_serializer import TosaOp
from torch.fx import Node
@register_node_visitor
class MinVisitor(NodeVisitor):
target = "aten.amin.default"
def __init__(self, *args):
super().__init__(*args)
def define_node(
self,
node: Node,
tosa_graph: ts.TosaSerializer,
inputs: List[TosaArg],
output: TosaArg,
) -> None:
input = inputs[0]
dim = inputs[1].number
if dim < 0:
tensor = get_first_fake_tensor(node)
rank = len(tensor.size())
dim = rank + dim
keep_dims = inputs[2].number
if not keep_dims:
raise RuntimeError(
"TOSA only supports keepdims == True; Did you run the convert_minmax pass?"
)
attr = ts.TosaSerializerAttribute()
attr.AxisAttribute(input.dim_order.index(dim))
tosa_graph.addOperator(
TosaOp.Op().REDUCE_MIN, [input.name], [output.name], attr
)