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 OpSqrt, QNN_OP_PACKAGE_NAME_QTI_AISW 14 15 16@register_node_visitor 17class SQRT(NodeVisitor): 18 target = ["aten.sqrt.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 # tensor input 29 input_node = node.args[0] 30 input_tensor = self.get_tensor(input_node, node) 31 32 input_tensor_wrapper = self.define_tensor( 33 input_node, 34 input_tensor, 35 PyQnnWrapper.Qnn_TensorType_t.QNN_TENSOR_TYPE_NATIVE, 36 nodes_to_wrappers, 37 is_input_tensor=True, 38 ) 39 sqrt_input_tensors = [input_tensor_wrapper] 40 41 out_tensor = self.get_tensor(node, node) 42 output_tensor_wrapper = self.define_tensor( 43 node, 44 out_tensor, 45 PyQnnWrapper.Qnn_TensorType_t.QNN_TENSOR_TYPE_NATIVE, 46 nodes_to_wrappers, 47 is_input_tensor=False, 48 ) 49 sqrt_output_tensors = [output_tensor_wrapper] 50 51 sqrt_op = PyQnnWrapper.PyQnnOpWrapper( 52 node.name, 53 QNN_OP_PACKAGE_NAME_QTI_AISW, 54 OpSqrt.op_name, 55 ) 56 sqrt_op.AddInputTensors(sqrt_input_tensors) 57 sqrt_op.AddOutputTensors(sqrt_output_tensors) 58 59 return sqrt_op 60