Coverage for / home / jenkins / .local / lib / python3.10 / site-packages / hyper_multicore / _build / soc_selection.py: 0%
31 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-15 05:03 +0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-15 05:03 +0800
1# Copyright 2026 Huawei Technologies Co., Ltd
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ============================================================================
15"""Resolve build SoCs and their device architecture groups."""
17import argparse
19ARCHITECTURES = {
20 "arch22": {"npu_arch": 2201, "compile_soc": "ascend910b", "sdk_soc_type": "Ascend910B",
21 "soc_series": ["ascend910b", "ascend910_93"]},
22 "arch35": {"npu_arch": 3510, "compile_soc": "ascend950", "sdk_soc_type": "Ascend950",
23 "soc_series": ["ascend950"]},
24}
25SOC_ARCHITECTURES = {soc: name for name, spec in ARCHITECTURES.items() for soc in spec["soc_series"]}
26SUPPORTED_SOCS = frozenset(SOC_ARCHITECTURES)
27DEFAULT_SOC_LIST = ",".join(SOC_ARCHITECTURES)
30def resolve_soc_selection(value: str) -> tuple[list[str], dict[str, list[str]]]:
31 """Preserve requested order and group SoCs sharing one device architecture."""
32 socs = [soc.strip() for soc in value.split(",")]
33 if any(soc not in SUPPORTED_SOCS for soc in socs):
34 raise ValueError("--soc-list must contain only ascend910b, ascend910_93, or ascend950; "
35 "empty entries are invalid")
36 if len(set(socs)) != len(socs):
37 raise ValueError("--soc-list must contain unique SoCs")
38 groups = {}
39 for soc in socs:
40 groups.setdefault(SOC_ARCHITECTURES[soc], []).append(soc)
41 return socs, groups
44def main() -> None:
45 """Print normalized selection or one backend group per line for Shell callers."""
46 parser = argparse.ArgumentParser(description=__doc__)
47 parser.add_argument("soc_list", nargs="?", default=DEFAULT_SOC_LIST)
48 parser.add_argument("--groups", action="store_true")
49 args = parser.parse_args()
50 try:
51 socs, groups = resolve_soc_selection(args.soc_list)
52 except ValueError as error:
53 parser.error(str(error))
54 if args.groups:
55 for backend, selected in groups.items():
56 spec = ARCHITECTURES[backend]
57 print(backend, spec["sdk_soc_type"], spec["compile_soc"],
58 ",".join(spec["soc_series"]), ",".join(selected))
59 else:
60 print(",".join(socs), ",".join(ARCHITECTURES[name]["sdk_soc_type"] for name in groups))
63if __name__ == "__main__":
64 main()