Skip to content

Commit a57853c

Browse files
cccclaifacebook-github-bot
authored andcommitted
Centralize soc_to_chipset map (#6033)
Summary: Pull Request resolved: #6033 We have multiple copy of the maps in the codebase and it's error prone. Provide a util function for the map so we can get the map from the same function Reviewed By: kirklandsign Differential Revision: D64080089 fbshipit-source-id: eb3fff31808a20e666f4a3946c550c1e11b1d961
1 parent 53f5870 commit a57853c

File tree

4 files changed

+19
-26
lines changed

4 files changed

+19
-26
lines changed

backends/qualcomm/tests/utils.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
from executorch.backends.qualcomm.serialization.qnn_compile_spec_schema import (
2727
QcomChipset,
2828
)
29-
from executorch.backends.qualcomm.utils.utils import capture_program
29+
from executorch.backends.qualcomm.utils.utils import (
30+
capture_program,
31+
get_soc_to_chipset_map,
32+
)
3033
from executorch.devtools import generate_etrecord, Inspector
3134
from executorch.examples.qualcomm.utils import (
3235
generate_inputs,
@@ -117,13 +120,7 @@ class TestQNN(unittest.TestCase):
117120
build_folder: Literal = ""
118121
model: QcomChipset = None
119122
compiler_specs: List[CompileSpec] = None
120-
arch_table = {
121-
"SSG2115P": QcomChipset.SSG2115P,
122-
"SM8650": QcomChipset.SM8650,
123-
"SM8550": QcomChipset.SM8550,
124-
"SM8475": QcomChipset.SM8475,
125-
"SM8450": QcomChipset.SM8450,
126-
}
123+
arch_table = get_soc_to_chipset_map()
127124
error_only = False
128125
ip = "localhost"
129126
port = 8080

backends/qualcomm/utils/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,3 +850,13 @@ def generate_qnn_executorch_compiler_spec(
850850
QCOM_QNN_COMPILE_SPEC, convert_to_flatbuffer(qnn_executorch_options)
851851
)
852852
]
853+
854+
855+
def get_soc_to_chipset_map():
856+
return {
857+
"SSG2115P": QcomChipset.SSG2115P,
858+
"SM8650": QcomChipset.SM8650,
859+
"SM8550": QcomChipset.SM8550,
860+
"SM8475": QcomChipset.SM8475,
861+
"SM8450": QcomChipset.SM8450,
862+
}

examples/qualcomm/oss_scripts/llama2/llama.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
convert_linear_to_conv2d,
2727
generate_htp_compiler_spec,
2828
generate_qnn_executorch_compiler_spec,
29+
get_soc_to_chipset_map,
2930
)
3031
from executorch.examples.qualcomm.oss_scripts.llama2.model.static_llama import (
3132
LlamaModel,
@@ -47,15 +48,6 @@
4748
from torch.ao.quantization.quantize_pt2e import convert_pt2e, prepare_pt2e
4849

4950

50-
soc_to_chipset_map = {
51-
"SSG2115P": QcomChipset.SSG2115P,
52-
"SM8650": QcomChipset.SM8650,
53-
"SM8550": QcomChipset.SM8550,
54-
"SM8475": QcomChipset.SM8475,
55-
"SM8450": QcomChipset.SM8450,
56-
}
57-
58-
5951
pte_filename = "llama2_qnn"
6052

6153

@@ -402,7 +394,7 @@ def compile(args):
402394
end_quantize_ts = time.time()
403395
print("single_llama.quantize(quant_dtype)", end_quantize_ts - start_quantize_ts)
404396
single_llama.lowering_modules(
405-
args.artifact, kv_type=kv_type, soc_model=soc_to_chipset_map[args.model]
397+
args.artifact, kv_type=kv_type, soc_model=get_soc_to_chipset_map[args.model]
406398
)
407399
end_lowering_ts = time.time()
408400
print("Complete Compile", end_lowering_ts - end_quantize_ts)

examples/qualcomm/utils.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
capture_program,
3131
generate_htp_compiler_spec,
3232
generate_qnn_executorch_compiler_spec,
33+
get_soc_to_chipset_map,
3334
)
3435
from executorch.exir import EdgeCompileConfig, EdgeProgramManager, to_edge
3536
from executorch.exir.backend.backend_api import to_backend
@@ -82,14 +83,7 @@ def __init__(
8283
self.dump_intermediate_outputs = dump_intermediate_outputs
8384
self.debug_output_path = f"{self.workspace}/debug_output.bin"
8485
self.output_folder = f"{self.workspace}/outputs"
85-
self.arch_table = {
86-
"SSG2115P": "73",
87-
"SM8650": "75",
88-
"SM8550": "73",
89-
"SM8475": "69",
90-
"SM8450": "69",
91-
}
92-
self.soc_model = self.arch_table[soc_model]
86+
self.soc_model = get_soc_to_chipset_map()[soc_model]
9387
self.error_only = error_only
9488
self.shared_buffer = shared_buffer
9589
self.runner = runner

0 commit comments

Comments
 (0)