aboutsummaryrefslogtreecommitdiff
path: root/src/mlia/target/ethos_u
diff options
context:
space:
mode:
authorBenjamin Klimczak <benjamin.klimczak@arm.com>2023-02-08 16:00:34 +0000
committerBenjamin Klimczak <benjamin.klimczak@arm.com>2023-02-10 13:45:18 +0000
commitfa1fad9332e2912f12a44a1b07716ee434174308 (patch)
tree246dfdb4ec9c495faaa55d73e061bcb4f8171d98 /src/mlia/target/ethos_u
parent7a661257b6adad0c8f53e32b42ced56a1e7d952f (diff)
downloadmlia-fa1fad9332e2912f12a44a1b07716ee434174308.tar.gz
MLIA-769 Replace use of 'device' with 'target'
Term 'device' can be ambiguous and is replaced with 'target'. Change-Id: I5e5108d033a13b98e4c2997713e1c32bce63ae62
Diffstat (limited to 'src/mlia/target/ethos_u')
-rw-r--r--src/mlia/target/ethos_u/advisor.py18
-rw-r--r--src/mlia/target/ethos_u/config.py2
-rw-r--r--src/mlia/target/ethos_u/data_collection.py20
-rw-r--r--src/mlia/target/ethos_u/events.py4
-rw-r--r--src/mlia/target/ethos_u/handlers.py2
-rw-r--r--src/mlia/target/ethos_u/performance.py34
-rw-r--r--src/mlia/target/ethos_u/reporters.py18
7 files changed, 49 insertions, 49 deletions
diff --git a/src/mlia/target/ethos_u/advisor.py b/src/mlia/target/ethos_u/advisor.py
index 5f23fdd..b34d1e0 100644
--- a/src/mlia/target/ethos_u/advisor.py
+++ b/src/mlia/target/ethos_u/advisor.py
@@ -41,13 +41,13 @@ class EthosUInferenceAdvisor(DefaultInferenceAdvisor):
def get_collectors(self, context: Context) -> list[DataCollector]:
"""Return list of the data collectors."""
model = self.get_model(context)
- device = self._get_device_cfg(context)
+ target = self._get_target_cfg(context)
backends = self._get_backends(context)
collectors: list[DataCollector] = []
if context.category_enabled(AdviceCategory.COMPATIBILITY):
- collectors.append(EthosUOperatorCompatibility(model, device))
+ collectors.append(EthosUOperatorCompatibility(model, target))
# Performance and optimization are mutually exclusive.
# Decide which one to use (taking into account the model format).
@@ -58,18 +58,18 @@ class EthosUInferenceAdvisor(DefaultInferenceAdvisor):
"Command 'optimization' is not supported for TensorFlow Lite files."
)
if context.category_enabled(AdviceCategory.PERFORMANCE):
- collectors.append(EthosUPerformance(model, device, backends))
+ collectors.append(EthosUPerformance(model, target, backends))
else:
# Keras/SavedModel: Prefer optimization
if context.category_enabled(AdviceCategory.OPTIMIZATION):
optimization_settings = self._get_optimization_settings(context)
collectors.append(
EthosUOptimizationPerformance(
- model, device, optimization_settings, backends
+ model, target, optimization_settings, backends
)
)
elif context.category_enabled(AdviceCategory.PERFORMANCE):
- collectors.append(EthosUPerformance(model, device, backends))
+ collectors.append(EthosUPerformance(model, target, backends))
return collectors
@@ -89,14 +89,14 @@ class EthosUInferenceAdvisor(DefaultInferenceAdvisor):
def get_events(self, context: Context) -> list[Event]:
"""Return list of the startup events."""
model = self.get_model(context)
- device = self._get_device_cfg(context)
+ target = self._get_target_cfg(context)
return [
- EthosUAdvisorStartedEvent(device=device, model=model),
+ EthosUAdvisorStartedEvent(target=target, model=model),
]
- def _get_device_cfg(self, context: Context) -> EthosUConfiguration:
- """Get device configuration."""
+ def _get_target_cfg(self, context: Context) -> EthosUConfiguration:
+ """Get target configuration."""
target_profile = self.get_target_profile(context)
return cast(EthosUConfiguration, profile(target_profile))
diff --git a/src/mlia/target/ethos_u/config.py b/src/mlia/target/ethos_u/config.py
index d1a2c7a..73baa61 100644
--- a/src/mlia/target/ethos_u/config.py
+++ b/src/mlia/target/ethos_u/config.py
@@ -49,7 +49,7 @@ class EthosUConfiguration(TargetProfile):
target_mac_range = target_mac_ranges[self.target]
if self.mac not in target_mac_range:
raise ValueError(
- f"Mac value for selected device should be in {target_mac_range}."
+ f"Mac value for selected target should be in {target_mac_range}."
)
@property
diff --git a/src/mlia/target/ethos_u/data_collection.py b/src/mlia/target/ethos_u/data_collection.py
index 258876d..96fe240 100644
--- a/src/mlia/target/ethos_u/data_collection.py
+++ b/src/mlia/target/ethos_u/data_collection.py
@@ -1,4 +1,4 @@
-# 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
"""Data collection module for Ethos-U."""
from __future__ import annotations
@@ -31,10 +31,10 @@ logger = logging.getLogger(__name__)
class EthosUOperatorCompatibility(ContextAwareDataCollector):
"""Collect operator compatibility information."""
- def __init__(self, model: Path, device: EthosUConfiguration) -> None:
+ def __init__(self, model: Path, target: EthosUConfiguration) -> None:
"""Init operator compatibility data collector."""
self.model = model
- self.device = device
+ self.target = target
def collect_data(self) -> Operators:
"""Collect operator compatibility information."""
@@ -42,7 +42,7 @@ class EthosUOperatorCompatibility(ContextAwareDataCollector):
with log_action("Checking operator compatibility ..."):
return supported_operators(
- Path(tflite_model.model_path), self.device.compiler_options
+ Path(tflite_model.model_path), self.target.compiler_options
)
@classmethod
@@ -57,12 +57,12 @@ class EthosUPerformance(ContextAwareDataCollector):
def __init__(
self,
model: Path,
- device: EthosUConfiguration,
+ target: EthosUConfiguration,
backends: list[str] | None = None,
) -> None:
"""Init performance data collector."""
self.model = model
- self.device = device
+ self.target = target
self.backends = backends
def collect_data(self) -> PerformanceMetrics:
@@ -70,7 +70,7 @@ class EthosUPerformance(ContextAwareDataCollector):
tflite_model = get_tflite_model(self.model, self.context)
estimator = EthosUPerformanceEstimator(
self.context,
- self.device,
+ self.target,
self.backends,
)
@@ -113,13 +113,13 @@ class EthosUOptimizationPerformance(ContextAwareDataCollector):
def __init__(
self,
model: Path,
- device: EthosUConfiguration,
+ target: EthosUConfiguration,
optimizations: list[list[dict]],
backends: list[str] | None = None,
) -> None:
"""Init performance optimizations data collector."""
self.model = model
- self.device = device
+ self.target = target
self.optimizations = optimizations
self.backends = backends
@@ -148,7 +148,7 @@ class EthosUOptimizationPerformance(ContextAwareDataCollector):
estimator = EthosUPerformanceEstimator(
self.context,
- self.device,
+ self.target,
self.backends,
)
original_metrics, *optimized_metrics = estimate_performance(
diff --git a/src/mlia/target/ethos_u/events.py b/src/mlia/target/ethos_u/events.py
index 37cc1a9..8060382 100644
--- a/src/mlia/target/ethos_u/events.py
+++ b/src/mlia/target/ethos_u/events.py
@@ -1,4 +1,4 @@
-# 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
"""Ethos-U MLIA module events."""
from dataclasses import dataclass
@@ -14,7 +14,7 @@ class EthosUAdvisorStartedEvent(Event):
"""Event with Ethos-U advisor parameters."""
model: Path
- device: EthosUConfiguration
+ target: EthosUConfiguration
class EthosUAdvisorEventHandler(EventDispatcher):
diff --git a/src/mlia/target/ethos_u/handlers.py b/src/mlia/target/ethos_u/handlers.py
index 9873014..c9d0dc7 100644
--- a/src/mlia/target/ethos_u/handlers.py
+++ b/src/mlia/target/ethos_u/handlers.py
@@ -51,4 +51,4 @@ class EthosUEventHandler(WorkflowEventsHandler, EthosUAdvisorEventHandler):
def on_ethos_u_advisor_started(self, event: EthosUAdvisorStartedEvent) -> None:
"""Handle EthosUAdvisorStarted event."""
- self.reporter.submit(event.device)
+ self.reporter.submit(event.target)
diff --git a/src/mlia/target/ethos_u/performance.py b/src/mlia/target/ethos_u/performance.py
index be1a287..5bcafab 100644
--- a/src/mlia/target/ethos_u/performance.py
+++ b/src/mlia/target/ethos_u/performance.py
@@ -92,17 +92,17 @@ class MemoryUsage:
class PerformanceMetrics:
"""Performance metrics."""
- device: EthosUConfiguration
+ target: EthosUConfiguration
npu_cycles: NPUCycles | None
memory_usage: MemoryUsage | None
def in_kilobytes(self) -> PerformanceMetrics:
"""Return metrics with memory usage in KiB."""
if self.memory_usage is None:
- return PerformanceMetrics(self.device, self.npu_cycles, self.memory_usage)
+ return PerformanceMetrics(self.target, self.npu_cycles, self.memory_usage)
return PerformanceMetrics(
- self.device, self.npu_cycles, self.memory_usage.in_kilobytes()
+ self.target, self.npu_cycles, self.memory_usage.in_kilobytes()
)
@@ -121,10 +121,10 @@ class VelaPerformanceEstimator(
):
"""Vela based performance estimator."""
- def __init__(self, context: Context, device: EthosUConfiguration) -> None:
+ def __init__(self, context: Context, target: EthosUConfiguration) -> None:
"""Init Vela based performance estimator."""
self.context = context
- self.device = device
+ self.target = target
def estimate(self, model: Path | ModelConfiguration) -> MemoryUsage:
"""Estimate performance."""
@@ -136,7 +136,7 @@ class VelaPerformanceEstimator(
)
vela_perf_metrics = vela_perf.estimate_performance(
- model_path, self.device.compiler_options
+ model_path, self.target.compiler_options
)
return MemoryUsage(
@@ -154,11 +154,11 @@ class CorstonePerformanceEstimator(
"""Corstone-based performance estimator."""
def __init__(
- self, context: Context, device: EthosUConfiguration, backend: str
+ self, context: Context, target: EthosUConfiguration, backend: str
) -> None:
"""Init Corstone-based performance estimator."""
self.context = context
- self.device = device
+ self.target = target
self.backend = backend
def estimate(self, model: Path | ModelConfiguration) -> NPUCycles:
@@ -180,12 +180,12 @@ class CorstonePerformanceEstimator(
)
vela_comp.optimize_model(
- model_path, self.device.compiler_options, optimized_model_path
+ model_path, self.target.compiler_options, optimized_model_path
)
corstone_perf_metrics = estimate_performance(
- self.device.target,
- self.device.mac,
+ self.target.target,
+ self.target.mac,
optimized_model_path,
self.backend,
)
@@ -208,15 +208,15 @@ class EthosUPerformanceEstimator(
def __init__(
self,
context: Context,
- device: EthosUConfiguration,
+ target: EthosUConfiguration,
backends: list[str] | None = None,
) -> None:
"""Init performance estimator."""
self.context = context
- self.device = device
+ self.target = target
if backends is None:
backends = ["Vela"] # Only Vela is always available as default
- ethos_u_backends = supported_backends(device.target)
+ ethos_u_backends = supported_backends(target.target)
for backend in backends:
if backend != "Vela" and backend not in ethos_u_backends:
raise ValueError(
@@ -238,11 +238,11 @@ class EthosUPerformanceEstimator(
npu_cycles = None
for backend in self.backends:
if backend == "Vela":
- vela_estimator = VelaPerformanceEstimator(self.context, self.device)
+ vela_estimator = VelaPerformanceEstimator(self.context, self.target)
memory_usage = vela_estimator.estimate(tflite_model)
elif is_corstone_backend(backend):
corstone_estimator = CorstonePerformanceEstimator(
- self.context, self.device, backend
+ self.context, self.target, backend
)
npu_cycles = corstone_estimator.estimate(tflite_model)
else:
@@ -252,4 +252,4 @@ class EthosUPerformanceEstimator(
backend,
)
- return PerformanceMetrics(self.device, npu_cycles, memory_usage)
+ return PerformanceMetrics(self.target, npu_cycles, memory_usage)
diff --git a/src/mlia/target/ethos_u/reporters.py b/src/mlia/target/ethos_u/reporters.py
index dbc6f4a..4de60bb 100644
--- a/src/mlia/target/ethos_u/reporters.py
+++ b/src/mlia/target/ethos_u/reporters.py
@@ -1,4 +1,4 @@
-# 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
"""Reports module."""
from __future__ import annotations
@@ -110,9 +110,9 @@ def report_operators(ops: list[Operator]) -> Report:
return Table(columns, rows, name="Operators", alias="operators")
-def report_device_details(device: EthosUConfiguration) -> Report:
- """Return table representation for the device."""
- compiler_config = device.resolved_compiler_config
+def report_target_details(target: EthosUConfiguration) -> Report:
+ """Return table representation for the target."""
+ compiler_config = target.resolved_compiler_config
memory_settings = [
ReportItem(
@@ -208,11 +208,11 @@ def report_device_details(device: EthosUConfiguration) -> Report:
]
return NestedReport(
- "Device information",
- "device",
+ "Target information",
+ "target",
[
- ReportItem("Target", alias="target", value=device.target),
- ReportItem("MAC", alias="mac", value=device.mac),
+ ReportItem("Target", alias="target", value=target.target),
+ ReportItem("MAC", alias="mac", value=target.mac),
ReportItem(
"Memory mode",
alias="memory_mode",
@@ -376,7 +376,7 @@ def ethos_u_formatters(data: Any) -> Callable[[Any], Report]:
return report_operators_stat
if isinstance(data, EthosUConfiguration):
- return report_device_details
+ return report_target_details
if isinstance(data, (list, tuple)):
formatters = [ethos_u_formatters(item) for item in data]