-
Notifications
You must be signed in to change notification settings - Fork 511
/
Copy pathop_tanh.py
47 lines (39 loc) · 1.54 KB
/
op_tanh.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
# Copyright 2024-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.
# pyre-unsafe
from typing import List
import serializer.tosa_serializer as ts # type: ignore
from executorch.backends.arm.operators.node_visitor import (
NodeVisitor,
register_node_visitor,
)
from executorch.backends.arm.tosa_mapping import TosaArg
from executorch.backends.arm.tosa_specification import TosaSpecification
from serializer.tosa_serializer import TosaOp
from torch.fx import Node
@register_node_visitor
class TanhVisitor_080_MI(NodeVisitor):
target = "aten.tanh.default"
# BI case should be handled by op_table
tosa_specs = [TosaSpecification.create_from_string("TOSA-0.80+MI")]
def __init__(self, *args):
super().__init__(*args)
def define_node(
self,
node: Node,
tosa_graph: ts.TosaSerializer,
inputs: List[TosaArg],
output: TosaArg,
) -> None:
if len(node.all_input_nodes) != 1:
raise ValueError(
f"Expected 1 input for {self.target}, got {len(node.all_input_nodes)}"
)
if inputs[0].dtype != ts.DType.FP32 or output.dtype != ts.DType.FP32:
raise ValueError(
f"Input and output for {self.target} need to be FP32, got input_dtype: "
f"{inputs[0].dtype} and output_dtype: {output.dtype}"
)
tosa_graph.addOperator(TosaOp.Op().TANH, [inputs[0].name], [output.name])