|
| 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. |
| 6 | +import warnings |
| 7 | +from typing import Dict |
| 8 | + |
| 9 | +import executorch.backends.qualcomm.python.PyQnnManagerAdaptor as PyQnnManager |
| 10 | + |
| 11 | +import torch |
| 12 | +from executorch.backends.qualcomm.utils.constants import QCOM_DATA |
| 13 | + |
| 14 | +from .node_visitor import NodeVisitor |
| 15 | +from .node_visitor_manager import register_node_visitor |
| 16 | +from .qnn_constants import OpIsInf, QNN_OP_PACKAGE_NAME_QTI_AISW |
| 17 | + |
| 18 | + |
| 19 | +@register_node_visitor |
| 20 | +class IsInf(NodeVisitor): |
| 21 | + target = ["aten.isinf.default"] |
| 22 | + |
| 23 | + def __init__(self, *args) -> None: |
| 24 | + super().__init__(*args) |
| 25 | + |
| 26 | + def define_node( |
| 27 | + self, |
| 28 | + node: torch.fx.Node, |
| 29 | + nodes_to_wrappers: Dict[torch.fx.Node, PyQnnManager.TensorWrapper], |
| 30 | + ) -> PyQnnManager.PyQnnOpWrapper: |
| 31 | + input_node = self.get_node(node.args[0]) |
| 32 | + input_tensor = self.get_tensor(input_node, node) |
| 33 | + |
| 34 | + if input_tensor.dtype != torch.float16: |
| 35 | + warnings.warn( |
| 36 | + "[QNN Delegate Op Builder]: QNN IsInf only supports FP16 inputs.", |
| 37 | + stacklevel=1, |
| 38 | + ) |
| 39 | + return None |
| 40 | + |
| 41 | + input_tensor_wrapper = self.define_tensor( |
| 42 | + input_node, |
| 43 | + node, |
| 44 | + self.get_tensor(input_node, node), |
| 45 | + PyQnnManager.Qnn_TensorType_t.QNN_TENSOR_TYPE_NATIVE, |
| 46 | + nodes_to_wrappers, |
| 47 | + ) |
| 48 | + |
| 49 | + input_tensors = [input_tensor_wrapper] |
| 50 | + |
| 51 | + out_tensor = self.get_tensor(node, node) |
| 52 | + output_tensor_wrapper = self.define_tensor( |
| 53 | + node, |
| 54 | + node, |
| 55 | + out_tensor, |
| 56 | + PyQnnManager.Qnn_TensorType_t.QNN_TENSOR_TYPE_NATIVE, |
| 57 | + nodes_to_wrappers, |
| 58 | + ) |
| 59 | + output_tensors = [output_tensor_wrapper] |
| 60 | + |
| 61 | + isinf_op = PyQnnManager.PyQnnOpWrapper( |
| 62 | + node.name, |
| 63 | + QNN_OP_PACKAGE_NAME_QTI_AISW, |
| 64 | + OpIsInf.op_name, |
| 65 | + ) |
| 66 | + isinf_op.AddInputTensors(input_tensors) |
| 67 | + isinf_op.AddOutputTensors(output_tensors) |
| 68 | + |
| 69 | + isinf_op.AddScalarParam( |
| 70 | + OpIsInf.param_detect_negative, |
| 71 | + PyQnnManager.Qnn_DataType_t.QNN_DATATYPE_BOOL_8, |
| 72 | + {QCOM_DATA: True}, |
| 73 | + ) |
| 74 | + isinf_op.AddScalarParam( |
| 75 | + OpIsInf.param_detect_positive, |
| 76 | + PyQnnManager.Qnn_DataType_t.QNN_DATATYPE_BOOL_8, |
| 77 | + {QCOM_DATA: True}, |
| 78 | + ) |
| 79 | + |
| 80 | + return isinf_op |
0 commit comments