From 4fa21325ec498adbf467876c2413c054d0e85c5b Mon Sep 17 00:00:00 2001 From: Raul Farkas Date: Wed, 12 Oct 2022 10:48:35 +0100 Subject: MLIA-409 Create new Cortex-A device skeleton * Add Cortex-A device skeleton * Add unit tests for the Cortex-A device skeleton * Update profiles.json by adding the new "cortex-a" profile * Add new cortex-a factory to the get_advisor method in api.py * Disable performance and optimization commands for the cortex-a profile. * Update trademarks section in README.md * Update pyproject.toml to not run similarity check in imports Change-Id: I2e228aaada1e2d3c5cc329d70572b51962ff517f --- tests/test_devices_cortex_a_advice_generation.py | 56 ++++++++++++++++++++++++ tests/test_devices_cortex_a_data_analysis.py | 35 +++++++++++++++ tests/test_devices_cortex_a_data_collection.py | 28 ++++++++++++ tests/test_devices_cortexa_advisor.py | 34 ++++++++++++++ tests/test_utils_filesystem.py | 2 + 5 files changed, 155 insertions(+) create mode 100644 tests/test_devices_cortex_a_advice_generation.py create mode 100644 tests/test_devices_cortex_a_data_analysis.py create mode 100644 tests/test_devices_cortex_a_data_collection.py create mode 100644 tests/test_devices_cortexa_advisor.py (limited to 'tests') diff --git a/tests/test_devices_cortex_a_advice_generation.py b/tests/test_devices_cortex_a_advice_generation.py new file mode 100644 index 0000000..69529d4 --- /dev/null +++ b/tests/test_devices_cortex_a_advice_generation.py @@ -0,0 +1,56 @@ +# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates. +# SPDX-License-Identifier: Apache-2.0 +"""Tests for advice generation.""" +from __future__ import annotations + +import pytest + +from mlia.core.advice_generation import Advice +from mlia.core.common import AdviceCategory +from mlia.core.common import DataItem +from mlia.core.context import ExecutionContext +from mlia.devices.cortexa.advice_generation import CortexAAdviceProducer +from mlia.devices.cortexa.data_analysis import ModelIsCortexACompatible +from mlia.devices.cortexa.data_analysis import ModelIsNotCortexACompatible + + +@pytest.mark.parametrize( + "input_data, advice_category, expected_advice", + [ + [ + ModelIsNotCortexACompatible(), + AdviceCategory.OPERATORS, + [ + Advice( + [ + "Some operators in the model are not compatible with Cortex-A. " + "Please, refer to the operators table for more information." + ] + ) + ], + ], + [ + ModelIsCortexACompatible(), + AdviceCategory.OPERATORS, + [Advice(["Model is fully compatible with Cortex-A."])], + ], + ], +) +def test_cortex_a_advice_producer( + tmpdir: str, + input_data: DataItem, + advice_category: AdviceCategory, + expected_advice: list[Advice], +) -> None: + """Test Cortex-A advice producer.""" + producer = CortexAAdviceProducer() + + context = ExecutionContext( + advice_category=advice_category, + working_dir=tmpdir, + ) + + producer.set_context(context) + producer.produce_advice(input_data) + + assert producer.get_advice() == expected_advice diff --git a/tests/test_devices_cortex_a_data_analysis.py b/tests/test_devices_cortex_a_data_analysis.py new file mode 100644 index 0000000..4724c81 --- /dev/null +++ b/tests/test_devices_cortex_a_data_analysis.py @@ -0,0 +1,35 @@ +# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates. +# SPDX-License-Identifier: Apache-2.0 +"""Tests for Cortex-A data analysis module.""" +from __future__ import annotations + +import pytest + +from mlia.core.common import DataItem +from mlia.core.data_analysis import Fact +from mlia.devices.cortexa.data_analysis import CortexADataAnalyzer +from mlia.devices.cortexa.data_analysis import ModelIsCortexACompatible +from mlia.devices.cortexa.data_analysis import ModelIsNotCortexACompatible +from mlia.devices.cortexa.operators import CortexACompatibilityInfo + + +@pytest.mark.parametrize( + "input_data, expected_facts", + [ + [ + CortexACompatibilityInfo(True, []), + [ModelIsCortexACompatible()], + ], + [ + CortexACompatibilityInfo(False, []), + [ModelIsNotCortexACompatible()], + ], + ], +) +def test_cortex_a_data_analyzer( + input_data: DataItem, expected_facts: list[Fact] +) -> None: + """Test Cortex-A data analyzer.""" + analyzer = CortexADataAnalyzer() + analyzer.analyze_data(input_data) + assert analyzer.get_analyzed_data() == expected_facts diff --git a/tests/test_devices_cortex_a_data_collection.py b/tests/test_devices_cortex_a_data_collection.py new file mode 100644 index 0000000..7ea3e52 --- /dev/null +++ b/tests/test_devices_cortex_a_data_collection.py @@ -0,0 +1,28 @@ +# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates. +# SPDX-License-Identifier: Apache-2.0 +"""Tests for Cortex-A data collection module.""" +from pathlib import Path +from unittest.mock import MagicMock + +import pytest + +from mlia.core.context import ExecutionContext +from mlia.devices.cortexa.data_collection import CortexAOperatorCompatibility +from mlia.devices.cortexa.operators import CortexACompatibilityInfo + + +def test_cortex_a_data_collection( + monkeypatch: pytest.MonkeyPatch, test_tflite_model: Path, tmpdir: str +) -> None: + """Test Cortex-A data collection.""" + monkeypatch.setattr( + "mlia.devices.cortexa.data_collection.get_cortex_a_compatibility_info", + MagicMock(return_value=CortexACompatibilityInfo(True, [])), + ) + context = ExecutionContext(working_dir=tmpdir) + collector = CortexAOperatorCompatibility(test_tflite_model) + collector.set_context(context) + + data_item = collector.collect_data() + + assert isinstance(data_item, CortexACompatibilityInfo) diff --git a/tests/test_devices_cortexa_advisor.py b/tests/test_devices_cortexa_advisor.py new file mode 100644 index 0000000..8cd60d6 --- /dev/null +++ b/tests/test_devices_cortexa_advisor.py @@ -0,0 +1,34 @@ +# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates. +# SPDX-License-Identifier: Apache-2.0 +"""Tests for Cortex-A MLIA module.""" +from pathlib import Path + +from mlia.core.context import ExecutionContext +from mlia.core.workflow import DefaultWorkflowExecutor +from mlia.devices.cortexa.advisor import configure_and_get_cortexa_advisor +from mlia.devices.cortexa.advisor import CortexAInferenceAdvisor + + +def test_advisor_metadata() -> None: + """Test advisor metadata.""" + assert CortexAInferenceAdvisor.name() == "cortex_a_inference_advisor" + + +def test_configure_and_get_cortex_a_advisor(test_tflite_model: Path) -> None: + """Test Cortex-A advisor configuration.""" + ctx = ExecutionContext() + + advisor = configure_and_get_cortexa_advisor(ctx, "cortex-a", test_tflite_model) + workflow = advisor.configure(ctx) + + assert isinstance(advisor, CortexAInferenceAdvisor) + + assert ctx.event_handlers is not None + assert ctx.config_parameters == { + "cortex_a_inference_advisor": { + "model": str(test_tflite_model), + "target_profile": "cortex-a", + } + } + + assert isinstance(workflow, DefaultWorkflowExecutor) diff --git a/tests/test_utils_filesystem.py b/tests/test_utils_filesystem.py index b31b4ff..9dd51e1 100644 --- a/tests/test_utils_filesystem.py +++ b/tests/test_utils_filesystem.py @@ -48,6 +48,7 @@ def test_profiles_data() -> None: "ethos-u65-512", "ethos-u65-256", "tosa", + "cortex-a", ] @@ -76,6 +77,7 @@ def test_get_supported_profile_names() -> None: "ethos-u65-512", "ethos-u65-256", "tosa", + "cortex-a", ] -- cgit v1.2.1