xref: /aosp_15_r20/external/executorch/backends/qualcomm/builders/op_ceil.py (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1# Copyright (c) Qualcomm Innovation Center, Inc.
2# All rights reserved
3#
4# This source code is licensed under the BSD-style license found in the
5# LICENSE file in the root directory of this source tree.
6from typing import Dict
7
8import executorch.backends.qualcomm.python.PyQnnWrapperAdaptor as PyQnnWrapper
9
10import torch
11
12from .node_visitor import NodeVisitor, register_node_visitor
13from .qnn_constants import OpElementWiseCeil, QNN_OP_PACKAGE_NAME_QTI_AISW
14
15
16@register_node_visitor
17class Ceil(NodeVisitor):
18    target = ["aten.ceil.default"]
19
20    def __init__(self, *args) -> None:
21        super().__init__(*args)
22
23    def define_node(
24        self,
25        node: torch.fx.Node,
26        nodes_to_wrappers: Dict[torch.fx.Node, PyQnnWrapper.TensorWrapper],
27    ) -> PyQnnWrapper.PyQnnOpWrapper:
28        input_node = node.args[0]
29        input_tensor = self.get_tensor(input_node, node)
30        input_tensor_wrapper = self.define_tensor(
31            input_node,
32            input_tensor,
33            PyQnnWrapper.Qnn_TensorType_t.QNN_TENSOR_TYPE_NATIVE,
34            nodes_to_wrappers,
35            is_input_tensor=True,
36        )
37
38        output_tensor = self.get_tensor(node, node)
39        output_tensor_wrapper = self.define_tensor(
40            node,
41            output_tensor,
42            PyQnnWrapper.Qnn_TensorType_t.QNN_TENSOR_TYPE_NATIVE,
43            nodes_to_wrappers,
44            is_input_tensor=False,
45        )
46
47        ceil_op = PyQnnWrapper.PyQnnOpWrapper(
48            node.name,
49            QNN_OP_PACKAGE_NAME_QTI_AISW,
50            OpElementWiseCeil.op_name,
51        )
52        ceil_op.AddInputTensors([input_tensor_wrapper])
53        ceil_op.AddOutputTensors([output_tensor_wrapper])
54
55        return ceil_op
56