aboutsummaryrefslogtreecommitdiff
path: root/tests/test_target_ethos_u_config.py
blob: 10258279208c1c1ce42c1606ab586fc5ca6257f3 (plain)
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
95
96
97
98
99
100
# SPDX-FileCopyrightText: Copyright 2022-2023, Arm Limited and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
"""Tests for config module."""
from __future__ import annotations

from contextlib import ExitStack as does_not_raise
from pathlib import Path
from typing import Any

import pytest

from mlia.backend.vela.compiler import VelaCompilerOptions
from mlia.target.ethos_u.config import EthosUConfiguration


def test_compiler_options_default_init() -> None:
    """Test compiler options default init."""
    opts = VelaCompilerOptions()

    assert opts.config_files is None
    assert opts.system_config == "internal-default"
    assert opts.memory_mode == "internal-default"
    assert opts.accelerator_config is None
    assert opts.max_block_dependency == 3
    assert opts.arena_cache_size is None
    assert opts.tensor_allocator == "HillClimb"
    assert opts.cpu_tensor_alignment == 16
    assert opts.optimization_strategy == "Performance"
    assert opts.output_dir == Path("output")


def test_ethosu_target() -> None:
    """Test Ethos-U target configuration init."""
    default_config = EthosUConfiguration.load_profile("ethos-u55-256")

    assert default_config.target == "ethos-u55"
    assert default_config.mac == 256
    assert default_config.compiler_options is not None


@pytest.mark.parametrize(
    "profile_data, expected_error",
    [
        [
            {},
            pytest.raises(
                KeyError,
                match=r"'target'",
            ),
        ],
        [
            {"target": "ethos-u65", "mac": 512},
            pytest.raises(
                KeyError,
                match=r"'system_config'",
            ),
        ],
        [
            {
                "target": "ethos-u65",
                "mac": 2,
                "system_config": "Ethos_U65_Embedded",
                "memory_mode": "Shared_Sram",
            },
            pytest.raises(
                Exception,
                match=r"Mac value for selected target should be in \[256, 512\]",
            ),
        ],
        [
            {
                "target": "ethos-u55",
                "mac": 1,
                "system_config": "Ethos_U55_High_End_Embedded",
                "memory_mode": "Shared_Sram",
            },
            pytest.raises(
                Exception,
                match="Mac value for selected target should be "
                r"in \[32, 64, 128, 256\]",
            ),
        ],
        [
            {
                "target": "ethos-u65",
                "mac": 512,
                "system_config": "Ethos_U65_Embedded",
                "memory_mode": "Shared_Sram",
            },
            does_not_raise(),
        ],
    ],
)
def test_ethosu_configuration(
    profile_data: dict[str, Any], expected_error: Any
) -> None:
    """Test creating Ethos-U configuration."""
    with expected_error:
        cfg = EthosUConfiguration(**profile_data)
        cfg.verify()