Skip to content

Commit 5f65810

Browse files
committed
fixed review item
1 parent 6f21148 commit 5f65810

File tree

3 files changed

+11
-68
lines changed

3 files changed

+11
-68
lines changed

backends/qualcomm/builders/op_custom_op.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
6+
import warnings
67
from typing import Dict, Iterable
78

89
import executorch.backends.qualcomm.python.PyQnnWrapperAdaptor as PyQnnWrapper
@@ -41,6 +42,12 @@ def define_node(
4142

4243
custom_input_tensors = []
4344
custom_attr_keys = [arg.name for arg in node.target._schema.arguments]
45+
if len(custom_attr_keys) != len(node.args):
46+
warnings.warn(
47+
f"Number of inputs ({len(node.args)}) mismatch the number of args ({len(custom_attr_keys)}) in schema for the custom node ({self.target}).",
48+
stacklevel=1,
49+
)
50+
return
4451
for arg, arg_name in zip(node.args, custom_attr_keys):
4552
if arg is None:
4653
continue

backends/qualcomm/runtime/backends/QnnBackendCommon.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ void QnnBackend::BackendRegisterOpPackage(
4343
#elif defined(__ANDROID__)
4444
current_platform = QnnExecuTorchOpPackagePlatform::AARCH64_ANDROID;
4545
#endif
46+
if (current_platform == QnnExecuTorchOpPackagePlatform::UNKNOWN)
47+
QNN_EXECUTORCH_LOG_ERROR(
48+
"Failed to detect the platform. Only support x86_64 or android.");
4649
for (const auto op_package_info : *op_packages_infos) {
4750
if (current_platform != op_package_info->platform() ||
4851
op_package_manager_.Has(op_package_info->op_package_path()->c_str()))

examples/qualcomm/custom_op/README.md

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -94,71 +94,4 @@ For now, only support one output tensors.
9494
Consult the Qualcomm AI Engine Direct documentation for information on [generation op packages](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/op_def_schema.html).
9595

9696
## Registering Op Packages
97-
After an op package library has been generated, certain information needs to be passed to the `compile_spec` in order to properly delegate the nodes. The following code example shows how to construct the `QnnExecuTorchOpPackageOptions` and register op packages with the `compile spec`.
98-
```python
99-
def prepare_op_package(
100-
workspace: str, op_package_dir: str, arch: HtpArch, build_op_package: bool
101-
):
102-
if build_op_package:
103-
_run(["rm", "-rf", "build"], cwd=op_package_dir)
104-
_run(["make", "htp_x86", "htp_aarch64", f"htp_v{arch}"], cwd=op_package_dir)
105-
_run(
106-
[
107-
"cp",
108-
f"{op_package_dir}/build/hexagon-v{arch}/libQnnExampleOpPackage.so",
109-
f"{op_package_dir}/build/hexagon-v{arch}/libQnnExampleOpPackage_HTP.so",
110-
]
111-
)
112-
113-
op_package_paths = [
114-
f"{op_package_dir}/build/hexagon-v{arch}/libQnnExampleOpPackage_HTP.so",
115-
f"{op_package_dir}/build/aarch64-android/libQnnExampleOpPackage.so",
116-
]
117-
118-
op_package_infos_HTP = QnnExecuTorchOpPackageInfo()
119-
op_package_infos_HTP.interface_provider = "ExampleOpPackageInterfaceProvider"
120-
op_package_infos_HTP.op_package_name = "ExampleOpPackage"
121-
op_package_infos_HTP.op_package_path = f"{workspace}/libQnnExampleOpPackage_HTP.so"
122-
op_package_infos_HTP.target = QnnExecuTorchOpPackageTarget.HTP
123-
op_package_infos_HTP.custom_op_name = "my_ops.mul3.default"
124-
op_package_infos_HTP.qnn_op_type_name = "ExampleCustomOp"
125-
op_package_infos_HTP.platform = QnnExecuTorchOpPackagePlatform.AARCH64_ANDROID
126-
op_package_infos_aarch64_CPU = QnnExecuTorchOpPackageInfo()
127-
op_package_infos_aarch64_CPU.interface_provider = (
128-
"ExampleOpPackageInterfaceProvider"
129-
)
130-
op_package_infos_aarch64_CPU.op_package_name = "ExampleOpPackage"
131-
op_package_infos_aarch64_CPU.op_package_path = (
132-
f"{workspace}/libQnnExampleOpPackage.so"
133-
)
134-
op_package_infos_aarch64_CPU.target = QnnExecuTorchOpPackageTarget.CPU
135-
op_package_infos_aarch64_CPU.custom_op_name = "my_ops.mul3.default"
136-
op_package_infos_aarch64_CPU.qnn_op_type_name = "ExampleCustomOp"
137-
op_package_infos_aarch64_CPU.platform = (
138-
QnnExecuTorchOpPackagePlatform.AARCH64_ANDROID
139-
)
140-
op_package_infos_x86_CPU = QnnExecuTorchOpPackageInfo()
141-
op_package_infos_x86_CPU.interface_provider = "ExampleOpPackageInterfaceProvider"
142-
op_package_infos_x86_CPU.op_package_name = "ExampleOpPackage"
143-
op_package_infos_x86_CPU.op_package_path = (
144-
f"{op_package_dir}/build/x86_64-linux-clang/libQnnExampleOpPackage.so"
145-
)
146-
op_package_infos_x86_CPU.target = QnnExecuTorchOpPackageTarget.CPU
147-
op_package_infos_x86_CPU.custom_op_name = "my_ops.mul3.default"
148-
op_package_infos_x86_CPU.qnn_op_type_name = "ExampleCustomOp"
149-
op_package_infos_x86_CPU.platform = QnnExecuTorchOpPackagePlatform.X86_64
150-
op_package_options = QnnExecuTorchOpPackageOptions()
151-
op_package_options.op_package_infos = [
152-
op_package_infos_x86_CPU,
153-
op_package_infos_aarch64_CPU,
154-
op_package_infos_HTP,
155-
]
156-
157-
return op_package_options, op_package_paths
158-
...
159-
op_package_options, op_package_paths = prepare_op_package(...)
160-
compile_spec = generate_qnn_executorch_compiler_spec(
161-
...
162-
op_package_options=op_package_options,
163-
),
164-
```
97+
After an op package library has been generated, certain information needs to be passed to the `compile_spec` in order to properly delegate the nodes. [The example script](custom_ops_1.py) shows how to construct the `QnnExecuTorchOpPackageOptions` and register op packages with the `compile spec`.

0 commit comments

Comments
 (0)