1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# SPDX-FileCopyrightText: Copyright 2022-2023, Arm Limited and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
"""Tests for the target registry module."""
from __future__ import annotations
import pytest
from mlia.core.common import AdviceCategory
from mlia.target.registry import all_supported_backends
from mlia.target.registry import registry
from mlia.target.registry import supported_advice
from mlia.target.registry import supported_backends
from mlia.target.registry import supported_targets
@pytest.mark.parametrize(
"expected_target", ("cortex-a", "ethos-u55", "ethos-u65", "tosa")
)
def test_target_registry(expected_target: str) -> None:
"""Test the target registry."""
assert expected_target in registry.items, (
f"Expected target '{expected_target}' not contained in registered "
f"targets '{registry.items.keys()}'."
)
@pytest.mark.parametrize(
("target_name", "expected_advices"),
(
("cortex-a", [AdviceCategory.COMPATIBILITY]),
(
"ethos-u55",
[
AdviceCategory.COMPATIBILITY,
AdviceCategory.OPTIMIZATION,
AdviceCategory.PERFORMANCE,
],
),
(
"ethos-u65",
[
AdviceCategory.COMPATIBILITY,
AdviceCategory.OPTIMIZATION,
AdviceCategory.PERFORMANCE,
],
),
("tosa", [AdviceCategory.COMPATIBILITY]),
),
)
def test_supported_advice(
target_name: str, expected_advices: list[AdviceCategory]
) -> None:
"""Test function supported_advice()."""
supported = supported_advice(target_name)
assert all(advice in expected_advices for advice in supported)
assert all(advice in supported for advice in expected_advices)
@pytest.mark.parametrize(
("target_name", "expected_backends"),
(
("cortex-a", ["ArmNNTFLiteDelegate"]),
("ethos-u55", ["Corstone-300", "Corstone-310", "Vela"]),
("ethos-u65", ["Corstone-300", "Corstone-310", "Vela"]),
("tosa", ["tosa-checker"]),
),
)
def test_supported_backends(target_name: str, expected_backends: list[str]) -> None:
"""Test function supported_backends()."""
assert sorted(expected_backends) == sorted(supported_backends(target_name))
@pytest.mark.parametrize(
("advice", "expected_targets"),
(
(AdviceCategory.COMPATIBILITY, ["cortex-a", "ethos-u55", "ethos-u65", "tosa"]),
(AdviceCategory.OPTIMIZATION, ["ethos-u55", "ethos-u65"]),
(AdviceCategory.PERFORMANCE, ["ethos-u55", "ethos-u65"]),
),
)
def test_supported_targets(advice: AdviceCategory, expected_targets: list[str]) -> None:
"""Test function supported_targets()."""
assert sorted(expected_targets) == sorted(supported_targets(advice))
def test_all_supported_backends() -> None:
"""Test function all_supported_backends."""
assert all_supported_backends() == {
"Vela",
"tosa-checker",
"ArmNNTFLiteDelegate",
"Corstone-310",
"Corstone-300",
}
|