Skip to content

Commit 806c8e8

Browse files
Qualcomm AI Engine Direct - fix optrace demo script and remove redundant flags from QNN tool (#16487)
Qualcomm AI Engine Direct - Fix OpTrace Profiling demo script ### Summary - Fix OpTrace Profiling demo script - remove redundant flags from QNN tool ### Test plan ``` bash python -m examples.qualcomm.util_scripts.qairt_visualizer_demo -s {SERIAL_NUM} -m ${SOC_MODEL} -b build-android -a ${path_to_output_folder} ``` ``` bash python -m examples.qualcomm.util_scripts.qairt_visualizer_demo -s {SERIAL_NUM} -m ${SOC_MODEL} -b build-android -a ${path_to_output_folder} --online_prepare ``` ``` bash python -m backends.qualcomm.tests.test_qnn_delegate.TestUtilsScript.test_debugger_generate_optrace -s {SERIAL_NUM} -m ${SOC_MODEL} -b build-android --executorch_root . -a . ```
1 parent 41491c0 commit 806c8e8

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

backends/qualcomm/debugger/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pip install qairt-visualizer
1313
## Quick start
1414
This command launches an interactive GUI interface to visualize the `optrace` and `QHAS` results.
1515
```
16-
python -m examples.qualcomm.util_scripts.qairt_visualizer_demo -H ${host} -s {device} -b build-android -a ${path_to_output_folder} --online_prepare
16+
python -m examples.qualcomm.util_scripts.qairt_visualizer_demo -H ${host} -s {device} -m ${SOC_MODEL} -b build-android -a ${path_to_output_folder} --online_prepare
1717
```
1818
- If online prepare mode is `enabled`, the following artifacts will be generated:
1919
- `model`.dlc

backends/qualcomm/debugger/utils.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import subprocess
66
import tempfile
77
from pathlib import Path
8-
from typing import Tuple
8+
from typing import Sequence, Tuple
99

1010
import executorch.backends.qualcomm.python.PyQnnManagerAdaptor as PyQnnManager
1111
import pandas as pd
@@ -217,9 +217,6 @@ def __init__(
217217
"backend_extensions": {
218218
"config_file_path": "config.json",
219219
},
220-
"features": {
221-
"qhas_json": True,
222-
},
223220
},
224221
"config": {
225222
"devices": [
@@ -316,9 +313,6 @@ def qnn_net_run(self, graph_name="forward.serialized"):
316313
), f"Error: qnn-profiling-data_0.log not found in {self.tmp_dir}"
317314

318315
def qnn_profile_viewer(self, graph_name="forward_schematic", graph_idx=0):
319-
self.config["backend_extension_config"]["backend_extensions"][
320-
"shared_library_path"
321-
] = "./libQnnHtpNetRunExtensions.so"
322316
self.config["backend_extension_config"] = {"features": {"qhas_json": True}}
323317
for file_name, data in self.config.items():
324318
with open(f"{self.tmp_dir}/{file_name}.json", "w") as json_file:
@@ -398,7 +392,11 @@ def generate_optrace(
398392

399393

400394
def generate_optrace(
401-
artifact, soc_id: QcomChipset, adb, pte_path: str, inputs: Tuple[torch.Tensor]
395+
artifact,
396+
soc_id: QcomChipset,
397+
adb,
398+
pte_path: str,
399+
inputs: Sequence[Tuple[torch.Tensor]],
402400
):
403401
"""
404402
Generate optrace and QHAS (QNN HTP Analysis Summary) JSON files.
@@ -407,7 +405,7 @@ def generate_optrace(
407405
artifact (str): Path to the artifact folder.
408406
adb (SimpleADB): An object for communicating with Android device
409407
pte_path (str): The path to the generated PTE file, including the file extension (e.g., model.pte).
410-
inputs (Tuple[torch.Tensor]): The input tensors for the model.
408+
inputs Sequence((Tuple[torch.Tensor])): The input tensors for the model.
411409
412410
413411
Returns:

backends/qualcomm/tests/test_qnn_delegate.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8206,7 +8206,17 @@ def test_debugger_generate_optrace(self):
82068206
for _, (optrace, qhas) in msg["binaries_trace"].items():
82078207
with open(optrace, "r") as optrace_file:
82088208
optrace_data = json.load(optrace_file)
8209-
for row in optrace_data:
8209+
# {
8210+
# header:
8211+
# {
8212+
# 'header_version': {'major': x, 'minor': y, 'patch': z},
8213+
# 'version': {'major': x, 'minor': y, 'patch': z},
8214+
# 'artifact_type': 'OP_TRACE'
8215+
# }
8216+
# traceEvents:
8217+
# {...}
8218+
# }
8219+
for row in optrace_data["traceEvents"]:
82108220
self.assertIn("pid", row)
82118221
with open(qhas, "r") as qhas_file:
82128222
qhas_data = json.load(qhas_file)

examples/qualcomm/util_scripts/qairt_visualizer_demo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323

2424
def main(args) -> None:
2525
model = SimpleModel()
26-
example_input = (torch.ones(1, 32, 28, 28), torch.ones(1, 32, 28, 28))
26+
example_inputs = [(torch.ones(1, 32, 28, 28), torch.ones(1, 32, 28, 28))]
2727

2828
pte_filename = "qnn_simple_model"
2929
os.makedirs(args.artifact, exist_ok=True)
3030

3131
# lower to QNN
3232
build_executorch_binary(
3333
model,
34-
example_input,
34+
example_inputs[0],
3535
args.model,
3636
f"{args.artifact}/{pte_filename}",
37-
[example_input],
37+
example_inputs,
3838
quant_dtype=QuantDtype.use_8a8w,
3939
online_prepare=args.online_prepare,
4040
optrace=True,
@@ -56,7 +56,7 @@ def main(args) -> None:
5656
get_soc_to_chipset_map()[args.model],
5757
adb,
5858
f"{args.artifact}/{pte_filename}.pte",
59-
example_input,
59+
example_inputs,
6060
)
6161

6262
if args.ip and args.port != -1:

0 commit comments

Comments
 (0)