diff options
author | Benjamin Klimczak <benjamin.klimczak@arm.com> | 2022-12-14 11:20:11 +0000 |
---|---|---|
committer | Benjamin Klimczak <benjamin.klimczak@arm.com> | 2023-01-04 10:11:33 +0000 |
commit | dcd0bd31985c27e1d07333351b26cf8ad12ad1fd (patch) | |
tree | a3388ff5f91e7cdc7ec41271a1a76cdbfae38ece /src/mlia/target/registry.py | |
parent | 4b4cf29cb1e7d917ae001e258ff01f7846c34778 (diff) | |
download | mlia-dcd0bd31985c27e1d07333351b26cf8ad12ad1fd.tar.gz |
MLIA-589 Create an API to get target information
Change-Id: Ieeaa9188ea1e29e2ccaad7475d457bce71e3140d
Diffstat (limited to 'src/mlia/target/registry.py')
-rw-r--r-- | src/mlia/target/registry.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/mlia/target/registry.py b/src/mlia/target/registry.py new file mode 100644 index 0000000..6b33084 --- /dev/null +++ b/src/mlia/target/registry.py @@ -0,0 +1,34 @@ +# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates. +# SPDX-License-Identifier: Apache-2.0 +"""Target module.""" +from __future__ import annotations + +from mlia.backend.registry import registry as backend_registry +from mlia.core.common import AdviceCategory +from mlia.target.config import TargetInfo +from mlia.utils.registry import Registry + +# All supported targets are required to be registered here. +registry = Registry[TargetInfo]() + + +def supported_advice(target: str) -> list[AdviceCategory]: + """Get a list of supported advice for the given target.""" + advice: set[AdviceCategory] = set() + for supported_backend in registry.items[target].supported_backends: + advice.update(backend_registry.items[supported_backend].supported_advice) + return list(advice) + + +def supported_backends(target: str) -> list[str]: + """Get a list of backends supported by the given target.""" + return registry.items[target].filter_supported_backends(check_system=False) + + +def supported_targets(advice: AdviceCategory) -> list[str]: + """Get a list of all targets supporting the given advice category.""" + return [ + name + for name, info in registry.items.items() + if info.is_supported(advice, check_system=False) + ] |