diff options
Diffstat (limited to 'src/mlia/target/registry.py')
-rw-r--r-- | src/mlia/target/registry.py | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/src/mlia/target/registry.py b/src/mlia/target/registry.py index 6b33084..2d29f1b 100644 --- a/src/mlia/target/registry.py +++ b/src/mlia/target/registry.py @@ -1,10 +1,17 @@ -# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates. +# SPDX-FileCopyrightText: Copyright 2022-2023, Arm Limited and/or its affiliates. # SPDX-License-Identifier: Apache-2.0 """Target module.""" from __future__ import annotations +from typing import cast + +from mlia.backend.config import BackendType +from mlia.backend.manager import DefaultInstallationManager from mlia.backend.registry import registry as backend_registry +from mlia.cli.config import get_installation_manager from mlia.core.common import AdviceCategory +from mlia.core.reporting import Column +from mlia.core.reporting import Table from mlia.target.config import TargetInfo from mlia.utils.registry import Registry @@ -32,3 +39,51 @@ def supported_targets(advice: AdviceCategory) -> list[str]: for name, info in registry.items.items() if info.is_supported(advice, check_system=False) ] + + +def table() -> Table: + """Get a table representation of registered targets with backends.""" + + def get_status(backend: str) -> str: + if backend_registry.items[backend].type == BackendType.BUILTIN: + return BackendType.BUILTIN.name + mgr = cast(DefaultInstallationManager, get_installation_manager()) + return "INSTALLED" if mgr.already_installed(backend) else "NOT INSTALLED" + + def get_advice(target: str) -> tuple[str, str, str]: + supported = supported_advice(target) + return tuple( # type: ignore + "YES" if advice in supported else "NO" + for advice in ( + AdviceCategory.COMPATIBILITY, + AdviceCategory.PERFORMANCE, + AdviceCategory.OPTIMIZATION, + ) + ) + + rows = [ + ( + name, + Table( + columns=[Column("Backend"), Column("Status")], + rows=[ + (backend, get_status(backend)) + for backend in info.supported_backends + ], + name="Backends", + ), + "/".join(get_advice(name)), + ) + for name, info in registry.items.items() + ] + + return Table( + columns=[ + Column("Target"), + Column("Backend(s)"), + Column("Advice: comp/perf/opt"), + ], + rows=rows, + name="Supported Targets/Backends", + notes="Comp/Perf/Opt: Advice categories compatibility/performance/optimization", + ) |