aboutsummaryrefslogtreecommitdiff
path: root/src/mlia/backend
diff options
context:
space:
mode:
authorBenjamin Klimczak <benjamin.klimczak@arm.com>2022-12-14 11:20:11 +0000
committerBenjamin Klimczak <benjamin.klimczak@arm.com>2023-01-04 10:11:33 +0000
commitdcd0bd31985c27e1d07333351b26cf8ad12ad1fd (patch)
treea3388ff5f91e7cdc7ec41271a1a76cdbfae38ece /src/mlia/backend
parent4b4cf29cb1e7d917ae001e258ff01f7846c34778 (diff)
downloadmlia-dcd0bd31985c27e1d07333351b26cf8ad12ad1fd.tar.gz
MLIA-589 Create an API to get target information
Change-Id: Ieeaa9188ea1e29e2ccaad7475d457bce71e3140d
Diffstat (limited to 'src/mlia/backend')
-rw-r--r--src/mlia/backend/__init__.py9
-rw-r--r--src/mlia/backend/armnn_tflite_delegate/__init__.py16
-rw-r--r--src/mlia/backend/armnn_tflite_delegate/compat.py184
-rw-r--r--src/mlia/backend/config.py82
-rw-r--r--src/mlia/backend/corstone/__init__.py22
-rw-r--r--src/mlia/backend/registry.py8
-rw-r--r--src/mlia/backend/tosa_checker/__init__.py14
-rw-r--r--src/mlia/backend/vela/__init__.py23
8 files changed, 357 insertions, 1 deletions
diff --git a/src/mlia/backend/__init__.py b/src/mlia/backend/__init__.py
index 745aa1b..2d1da70 100644
--- a/src/mlia/backend/__init__.py
+++ b/src/mlia/backend/__init__.py
@@ -1,3 +1,10 @@
# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
-"""Backends module."""
+"""Backend module."""
+# Make sure all targets are registered with the registry by importing the
+# sub-modules
+# flake8: noqa
+from mlia.backend import armnn_tflite_delegate
+from mlia.backend import corstone
+from mlia.backend import tosa_checker
+from mlia.backend import vela
diff --git a/src/mlia/backend/armnn_tflite_delegate/__init__.py b/src/mlia/backend/armnn_tflite_delegate/__init__.py
new file mode 100644
index 0000000..6d5af42
--- /dev/null
+++ b/src/mlia/backend/armnn_tflite_delegate/__init__.py
@@ -0,0 +1,16 @@
+# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
+# SPDX-License-Identifier: Apache-2.0
+"""Arm NN TensorFlow Lite delegate backend module."""
+from mlia.backend.config import BackendConfiguration
+from mlia.backend.config import BackendType
+from mlia.backend.registry import registry
+from mlia.core.common import AdviceCategory
+
+registry.register(
+ "ArmNNTFLiteDelegate",
+ BackendConfiguration(
+ supported_advice=[AdviceCategory.OPERATORS],
+ supported_systems=None,
+ backend_type=BackendType.BUILTIN,
+ ),
+)
diff --git a/src/mlia/backend/armnn_tflite_delegate/compat.py b/src/mlia/backend/armnn_tflite_delegate/compat.py
new file mode 100644
index 0000000..c474e75
--- /dev/null
+++ b/src/mlia/backend/armnn_tflite_delegate/compat.py
@@ -0,0 +1,184 @@
+# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
+# SPDX-License-Identifier: Apache-2.0
+"""Collection of Cortex-A operator compatibility information."""
+from __future__ import annotations
+
+from typing import Any
+
+ARMNN_TFLITE_DELEGATE: dict[str, dict[str, Any]] = {
+ "metadata": {
+ "backend": "Arm NN TensorFlow Lite delegate",
+ "version": "22.08",
+ },
+ # BUILTIN OPERATORS
+ "builtin_ops": {
+ "ABS": {},
+ "ADD": {},
+ "ARG_MAX": {},
+ "ARG_MIN": {},
+ "AVERAGE_POOL_2D": {
+ "supported_fused_activation": [
+ "RELU",
+ "RELU6",
+ "RELU_N1_TO_1",
+ "SIGMOID",
+ "TANH",
+ "NONE",
+ ]
+ },
+ "BATCH_TO_SPACE_ND": {},
+ "CAST": {},
+ "CONCATENATION": {
+ "supported_fused_activation": [
+ "RELU",
+ "RELU6",
+ "RELU_N1_TO_1",
+ "SIGMOID",
+ "TANH",
+ "NONE",
+ ]
+ },
+ "CONV_2D": {
+ "supported_fused_activation": [
+ "RELU",
+ "RELU6",
+ "RELU_N1_TO_1",
+ "SIGMOID",
+ "TANH",
+ "NONE",
+ ]
+ },
+ "CONV_3D": {
+ "supported_fused_activation": [
+ "RELU",
+ "RELU6",
+ "RELU_N1_TO_1",
+ "SIGMOID",
+ "TANH",
+ "NONE",
+ ]
+ },
+ "DEPTH_TO_SPACE": {},
+ "DEPTHWISE_CONV_2D": {
+ "supported_fused_activation": [
+ "RELU",
+ "RELU6",
+ "RELU_N1_TO_1",
+ "SIGMOID",
+ "TANH",
+ "NONE",
+ ]
+ },
+ "DEQUANTIZE": {},
+ "DIV": {},
+ "EQUAL": {},
+ "ELU": {},
+ "EXP": {},
+ "EXPAND_DIMS": {},
+ "FILL": {},
+ "FLOOR": {},
+ "FLOOR_DIV": {},
+ "FULLY_CONNECTED": {
+ "supported_fused_activation": [
+ "RELU",
+ "RELU6",
+ "RELU_N1_TO_1",
+ "SIGMOID",
+ "TANH",
+ "NONE",
+ ]
+ },
+ "GATHER": {},
+ "GATHER_ND": {},
+ "GREATER": {},
+ "GREATER_EQUAL": {},
+ "HARD_SWISH": {},
+ "L2_NORMALIZATION": {},
+ "L2_POOL_2D": {},
+ "LESS": {},
+ "LESS_EQUAL": {},
+ "LOCAL_RESPONSE_NORMALIZATION": {},
+ "LOG": {},
+ "LOGICAL_AND": {},
+ "LOGICAL_NOT": {},
+ "LOGICAL_OR": {},
+ "LOGISTIC": {},
+ "LOG_SOFTMAX": {},
+ "LSTM": {},
+ "MAXIMUM": {},
+ "MAX_POOL_2D": {
+ "supported_fused_activation": [
+ "RELU",
+ "RELU6",
+ "RELU_N1_TO_1",
+ "SIGMOID",
+ "TANH",
+ "NONE",
+ ]
+ },
+ "MEAN": {},
+ "MINIMUM": {},
+ "MIRROR_PAD": {},
+ "MUL": {},
+ "NEG": {},
+ "NOT_EQUAL": {},
+ "PACK": {},
+ "PAD": {},
+ "PADV2": {},
+ "PRELU": {},
+ "QUANTIZE": {},
+ "RANK": {},
+ "REDUCE_MAX": {},
+ "REDUCE_MIN": {},
+ "REDUCE_PROD": {},
+ "RELU": {},
+ "RELU6": {},
+ "RELU_N1_TO_1": {},
+ "RESHAPE": {},
+ "RESIZE_BILINEAR": {},
+ "RESIZE_NEAREST_NEIGHBOR": {},
+ "RSQRT": {},
+ "SHAPE": {},
+ "SIN": {},
+ "SOFTMAX": {},
+ "SPACE_TO_BATCH_ND": {},
+ "SPACE_TO_DEPTH": {},
+ "SPLIT": {},
+ "SPLIT_V": {},
+ "SQRT": {},
+ "SQUEEZE": {},
+ "STRIDED_SLICE": {},
+ "SUB": {},
+ "SUM": {},
+ "TANH": {},
+ "TRANSPOSE": {},
+ "TRANSPOSE_CONV": {},
+ "UNIDIRECTIONAL_SEQUENCE_LSTM": {},
+ "UNPACK": {},
+ },
+ # CUSTOM OPERATORS
+ "custom_ops": {
+ "AveragePool3D": {
+ "supported_fused_activation": [
+ "RELU",
+ "RELU6",
+ "RELU_N1_TO_1",
+ "SIGMOID",
+ "SIGN_BIT",
+ "TANH",
+ "NONE",
+ ]
+ },
+ "MaxPool3D": {
+ "supported_fused_activation": [
+ "RELU",
+ "RELU6",
+ "RELU_N1_TO_1",
+ "SIGMOID",
+ "SIGN_BIT",
+ "TANH",
+ "NONE",
+ ]
+ },
+ },
+}
diff --git a/src/mlia/backend/config.py b/src/mlia/backend/config.py
new file mode 100644
index 0000000..8d14b28
--- /dev/null
+++ b/src/mlia/backend/config.py
@@ -0,0 +1,82 @@
+# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
+# SPDX-License-Identifier: Apache-2.0
+"""Backend config module."""
+from __future__ import annotations
+
+import platform
+from enum import auto
+from enum import Enum
+from typing import cast
+
+from mlia.core.common import AdviceCategory
+
+
+class System(Enum):
+ """Enum of system configurations (e.g. OS and architecture)."""
+
+ LINUX_AMD64 = ("Linux", "x86_64")
+ LINUX_AARCH64 = ("Linux", "aarch64")
+ WINDOWS_AMD64 = ("Windows", "AMD64")
+ WINDOWS_AARCH64 = ("Windows", "ARM64")
+ DARWIN_AARCH64 = ("Darwin", "arm64")
+ CURRENT = (platform.system(), platform.machine())
+
+ def __init__(
+ self, system: str = platform.system(), machine: str = platform.machine()
+ ) -> None:
+ """Set the system parameters (defaults to the current system)."""
+ self.system = system.lower()
+ self.machine = machine.lower()
+
+ def __eq__(self, other: object) -> bool:
+ """
+ Compare two System instances for equality.
+
+ Raises a TypeError if the input is not a System.
+ """
+ if isinstance(other, self.__class__):
+ return self.system == other.system and self.machine == other.machine
+ return False
+
+ def is_compatible(self) -> bool:
+ """Check if this system is compatible with the current system."""
+ return self == self.CURRENT
+
+
+class BackendType(Enum):
+ """Define the type of the backend (builtin, wheel file etc)."""
+
+ BUILTIN = auto()
+ WHEEL = auto()
+ CUSTOM = auto()
+
+
+class BackendConfiguration:
+ """Base class for backend configurations."""
+
+ def __init__(
+ self,
+ supported_advice: list[AdviceCategory],
+ supported_systems: list[System] | None,
+ backend_type: BackendType,
+ ) -> None:
+ """Set up basic information about the backend."""
+ self.supported_advice = supported_advice
+ self.supported_systems = supported_systems
+ self.type = backend_type
+
+ def __str__(self) -> str:
+ """List supported advice."""
+ return ", ".join(cast(str, adv.name).lower() for adv in self.supported_advice)
+
+ def is_supported(
+ self, advice: AdviceCategory | None = None, check_system: bool = False
+ ) -> bool:
+ """Check backend supports the current system and advice."""
+ is_system_supported = (
+ not self.supported_systems
+ or not check_system
+ or any(sys.is_compatible() for sys in self.supported_systems)
+ )
+ is_advice_supported = advice is None or advice in self.supported_advice
+ return is_system_supported and is_advice_supported
diff --git a/src/mlia/backend/corstone/__init__.py b/src/mlia/backend/corstone/__init__.py
index a1eac14..f89da63 100644
--- a/src/mlia/backend/corstone/__init__.py
+++ b/src/mlia/backend/corstone/__init__.py
@@ -1,3 +1,25 @@
# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
"""Corstone backend module."""
+from mlia.backend.config import BackendConfiguration
+from mlia.backend.config import BackendType
+from mlia.backend.config import System
+from mlia.backend.registry import registry
+from mlia.core.common import AdviceCategory
+
+registry.register(
+ "Corstone-300",
+ BackendConfiguration(
+ supported_advice=[AdviceCategory.PERFORMANCE, AdviceCategory.OPTIMIZATION],
+ supported_systems=[System.LINUX_AMD64],
+ backend_type=BackendType.CUSTOM,
+ ),
+)
+registry.register(
+ "Corstone-310",
+ BackendConfiguration(
+ supported_advice=[AdviceCategory.PERFORMANCE, AdviceCategory.OPTIMIZATION],
+ supported_systems=[System.LINUX_AMD64],
+ backend_type=BackendType.CUSTOM,
+ ),
+)
diff --git a/src/mlia/backend/registry.py b/src/mlia/backend/registry.py
new file mode 100644
index 0000000..6a0da74
--- /dev/null
+++ b/src/mlia/backend/registry.py
@@ -0,0 +1,8 @@
+# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
+# SPDX-License-Identifier: Apache-2.0
+"""Backend module."""
+from mlia.backend.config import BackendConfiguration
+from mlia.utils.registry import Registry
+
+# All supported targets are required to be registered here.
+registry = Registry[BackendConfiguration]()
diff --git a/src/mlia/backend/tosa_checker/__init__.py b/src/mlia/backend/tosa_checker/__init__.py
index cec210d..19fc8be 100644
--- a/src/mlia/backend/tosa_checker/__init__.py
+++ b/src/mlia/backend/tosa_checker/__init__.py
@@ -1,3 +1,17 @@
# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
"""TOSA checker backend module."""
+from mlia.backend.config import BackendConfiguration
+from mlia.backend.config import BackendType
+from mlia.backend.config import System
+from mlia.backend.registry import registry
+from mlia.core.common import AdviceCategory
+
+registry.register(
+ "TOSA-Checker",
+ BackendConfiguration(
+ supported_advice=[AdviceCategory.OPERATORS],
+ supported_systems=[System.LINUX_AMD64],
+ backend_type=BackendType.WHEEL,
+ ),
+)
diff --git a/src/mlia/backend/vela/__init__.py b/src/mlia/backend/vela/__init__.py
index 6ea0c21..38a623e 100644
--- a/src/mlia/backend/vela/__init__.py
+++ b/src/mlia/backend/vela/__init__.py
@@ -1,3 +1,26 @@
# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
"""Vela backend module."""
+from mlia.backend.config import BackendConfiguration
+from mlia.backend.config import BackendType
+from mlia.backend.config import System
+from mlia.backend.registry import registry
+from mlia.core.common import AdviceCategory
+
+registry.register(
+ "Vela",
+ BackendConfiguration(
+ supported_advice=[
+ AdviceCategory.OPERATORS,
+ AdviceCategory.PERFORMANCE,
+ AdviceCategory.OPTIMIZATION,
+ ],
+ supported_systems=[
+ System.LINUX_AMD64,
+ System.LINUX_AARCH64,
+ System.WINDOWS_AMD64,
+ System.WINDOWS_AARCH64,
+ ],
+ backend_type=BackendType.BUILTIN,
+ ),
+)