|
| 1 | +# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. |
| 2 | + |
| 3 | +# pyre-strict |
| 4 | +from typing import Optional |
| 5 | + |
| 6 | +from executorch import exir |
| 7 | +from executorch.backends.qualcomm.quantizer.quantizer import QuantDtype |
| 8 | + |
| 9 | +from executorch.examples.qualcomm.utils import make_quantizer |
| 10 | +from executorch.exir import EdgeCompileConfig, ExecutorchBackendConfig, ExportRecipe |
| 11 | +from executorch.exir.passes import MemoryPlanningPass |
| 12 | +from torch.ao.quantization.quantizer import Quantizer |
| 13 | + |
| 14 | +def get_qualcomm_htp_et_recipe( |
| 15 | + name: str, |
| 16 | + soc_model: str = "SM8650", |
| 17 | + qnn_version: str = "2.25", |
| 18 | + quant_dtype: Optional[QuantDtype] = None, |
| 19 | + shared_buffer=False, |
| 20 | + skip_node_id_set: set[int] = set(), |
| 21 | + skip_node_op_set: set[str] = set(), |
| 22 | +) -> ExportRecipe: |
| 23 | + from executorch.backends.qualcomm.partition.qnn_partitioner import QnnPartitioner |
| 24 | + from executorch.backends.qualcomm.serialization.qc_schema import QcomChipset |
| 25 | + |
| 26 | + from executorch.backends.qualcomm.utils.utils import ( |
| 27 | + _transform, |
| 28 | + generate_htp_compiler_spec, |
| 29 | + generate_qnn_executorch_compiler_spec, |
| 30 | + ) |
| 31 | + |
| 32 | + if quant_dtype: |
| 33 | + qnn_quantizer: Quantizer = make_quantizer(quant_dtype=quant_dtype) |
| 34 | + else: |
| 35 | + qnn_quantizer = make_quantizer() |
| 36 | + |
| 37 | + qnn_partitioner = QnnPartitioner( |
| 38 | + generate_qnn_executorch_compiler_spec( |
| 39 | + soc_model=getattr(QcomChipset, soc_model), |
| 40 | + backend_options=generate_htp_compiler_spec( |
| 41 | + use_fp16=False if quant_dtype else True |
| 42 | + ), |
| 43 | + ), |
| 44 | + skip_node_id_set=skip_node_id_set, |
| 45 | + skip_node_op_set=skip_node_op_set, |
| 46 | + ) |
| 47 | + |
| 48 | + executorch_config = ExecutorchBackendConfig( |
| 49 | + # For shared buffer, user must pass the memory address |
| 50 | + # which is allocated by RPC memory to executor runner. |
| 51 | + # Therefore, won't want to pre-allocate |
| 52 | + # by memory manager in runtime. |
| 53 | + memory_planning_pass=MemoryPlanningPass( |
| 54 | + alloc_graph_input=not shared_buffer, |
| 55 | + alloc_graph_output=not shared_buffer, |
| 56 | + ), |
| 57 | + ) |
| 58 | + |
| 59 | + return ExportRecipe( |
| 60 | + name, |
| 61 | + quantizer=qnn_quantizer, |
| 62 | + partitioners=[qnn_partitioner], |
| 63 | + pre_edge_transform_passes=_transform, |
| 64 | + edge_compile_config=EdgeCompileConfig( |
| 65 | + _check_ir_validity=False, |
| 66 | + _skip_dim_order=True, |
| 67 | + ), |
| 68 | + edge_transform_passes=[], |
| 69 | + transform_check_ir_validity=True, |
| 70 | + executorch_backend_config=executorch_config, |
| 71 | + ) |
0 commit comments