From 92689d5ad0dd19a3249e71dd0563731d4c6527c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Alfv=C3=A9n?= Date: Tue, 6 Dec 2022 11:16:19 +0100 Subject: MLBEDSW-6716: Updates to estimate op SRAM usage - The cascade builder estimates how much SRAM usage an operator takes when calculating the cascades. If an elementwise operator is included in a cascade the IFM2 will always be a constant/scalar and the IFM2 will be in permanent memory and the size of the IFM2 should not be included in the SRAM estimate. - The scheduler did not take into account that IFM can be reused for the OFM when calculating the op memory usage resulting in a negative number for non-local memory usage. Corrected the calculation and added assert to detect future problems. Change-Id: Id7ec8fe1ec5560290f34579a7b9203a75067aba2 Signed-off-by: Johan Alfven --- ethosu/vela/cascade_builder.py | 6 +++++- ethosu/vela/scheduler.py | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'ethosu') diff --git a/ethosu/vela/cascade_builder.py b/ethosu/vela/cascade_builder.py index 7baa3a83..ba210032 100644 --- a/ethosu/vela/cascade_builder.py +++ b/ethosu/vela/cascade_builder.py @@ -105,7 +105,11 @@ class CascadeBuilder: def _estimate_sram_usage(self, sched_op, cost) -> int: """Estimate the SRAM required for the Op if all FeatureMaps are in SRAM""" - ifm2_size = sched_op.ifm2_size_in_bytes() + if sched_op.parent_op.type.is_binary_elementwise_op(): + # ifm2 is scalar or constant and will always persist in permanent memory + ifm2_size = 0 + else: + ifm2_size = sched_op.ifm2_size_in_bytes() if sched_op.requires_full_ifm: ifm_size = sched_op.ifm_size_in_bytes() else: diff --git a/ethosu/vela/scheduler.py b/ethosu/vela/scheduler.py index 73eb8b42..c7d08fbb 100644 --- a/ethosu/vela/scheduler.py +++ b/ethosu/vela/scheduler.py @@ -57,6 +57,7 @@ from .nn_graph import Pass from .nn_graph import PassPlacement from .nn_graph import SchedulingStrategy from .nn_graph import Subgraph +from .live_range import ofm_can_reuse_ifm from .numeric_util import round_down from .numeric_util import round_up from .operation import NpuBlockType @@ -974,9 +975,11 @@ class Scheduler: op_mem_usage = 0 else: # Min schedule only have ifm and ofm in SRAM (no buffered weigth tensors) - op_mem_usage = sched_op.ifm_size_in_bytes() + sched_op.ofm_size_in_bytes() + ofm_size = 0 if ofm_can_reuse_ifm(sched_op) else sched_op.ofm_size_in_bytes() + op_mem_usage = sched_op.ifm_size_in_bytes() + ofm_size non_local_mem_usage[sched_op] = min_schedule.memory_snapshot[time_index] - op_mem_usage + assert non_local_mem_usage[sched_op] >= 0 # Crate cascades for Min schedule cascade_builder = CascadeBuilder(self.sched_ops, self.arch.is_spilling_enabled(), non_local_mem_usage) -- cgit v1.2.1