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/config.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/config.py')
-rw-r--r-- | src/mlia/target/config.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/mlia/target/config.py b/src/mlia/target/config.py index 7ab6b43..f257784 100644 --- a/src/mlia/target/config.py +++ b/src/mlia/target/config.py @@ -1,6 +1,12 @@ # SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates. # SPDX-License-Identifier: Apache-2.0 """IP configuration module.""" +from __future__ import annotations + +from dataclasses import dataclass + +from mlia.backend.registry import registry as backend_registry +from mlia.core.common import AdviceCategory class IPConfiguration: # pylint: disable=too-few-public-methods @@ -9,3 +15,33 @@ class IPConfiguration: # pylint: disable=too-few-public-methods def __init__(self, target: str) -> None: """Init IP configuration instance.""" self.target = target + + +@dataclass +class TargetInfo: + """Collect information about supported targets.""" + + supported_backends: list[str] + + def __str__(self) -> str: + """List supported backends.""" + return ", ".join(sorted(self.supported_backends)) + + def is_supported( + self, advice: AdviceCategory | None = None, check_system: bool = False + ) -> bool: + """Check if any of the supported backends support this kind of advice.""" + return any( + backend_registry.items[name].is_supported(advice, check_system) + for name in self.supported_backends + ) + + def filter_supported_backends( + self, advice: AdviceCategory | None = None, check_system: bool = False + ) -> list[str]: + """Get the list of supported backends filtered by the given arguments.""" + return [ + name + for name in self.supported_backends + if backend_registry.items[name].is_supported(advice, check_system) + ] |