From d4c6dbd7cda10bfdbc72e76a937dc448292e838f Mon Sep 17 00:00:00 2001 From: Johan Gunnarsson Date: Wed, 15 Jan 2025 16:20:38 +0100 Subject: [PATCH] MLBEDSW-10260: Don't allocate memory for CPU-only tensors Tensors that are only accessed from CPU ops have no need for an allocated address in scratch area, since the command stream is not referencing them at all. Instead, let the runtime allocate memory for these tensors. All tensors in the output graph will still be in the OfflineMemoryAllocation table, but these CPU only tensors will have offset "-1" in their entries. Signed-off-by: Johan Gunnarsson Change-Id: I353ee9590dd4268f97559ef927cfde4673005337 --- ethosu/regor/architecture/architecture.cpp | 5 +++++ ethosu/regor/architecture/architecture.hpp | 1 + ethosu/regor/compiler/scheduler.cpp | 6 +++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ethosu/regor/architecture/architecture.cpp b/ethosu/regor/architecture/architecture.cpp index baf21599..57a257ee 100644 --- a/ethosu/regor/architecture/architecture.cpp +++ b/ethosu/regor/architecture/architecture.cpp @@ -90,6 +90,11 @@ MemArea Architecture::OutputFeatureMapMemory() return MemArea(_featuremapMemory, usage); } +MemArea Architecture::CPUMemory() +{ + return MemArea(_featuremapMemory, MemUsage::None); +} + IniParseResult Architecture::ParseSection(const std::string §ion, IniReader *reader) { // Parse the architecture config (must happen first in INI file ). diff --git a/ethosu/regor/architecture/architecture.hpp b/ethosu/regor/architecture/architecture.hpp index 5967770e..c188d833 100644 --- a/ethosu/regor/architecture/architecture.hpp +++ b/ethosu/regor/architecture/architecture.hpp @@ -372,6 +372,7 @@ public: MemArea StagingMemory(); MemArea InputFeatureMapMemory(); MemArea OutputFeatureMapMemory(); + MemArea CPUMemory(); IniParseResult ParseSection(const std::string §ion, IniReader *reader); // Select named memories diff --git a/ethosu/regor/compiler/scheduler.cpp b/ethosu/regor/compiler/scheduler.cpp index e2cd127a..6a69f559 100644 --- a/ethosu/regor/compiler/scheduler.cpp +++ b/ethosu/regor/compiler/scheduler.cpp @@ -333,7 +333,11 @@ int Scheduler::UpdateSchedulerTensor(TensorUsage usage, SchedulerConnection *con conn->requireFullTensor = conn->requireFullTensor || cpuTensor; tensor->needsLinearFormat = tensor->needsLinearFormat || cpuTensor || CheckLinearFormatForConcatSplit(tensor); - if ( _options.separateIORegions && !tensor->IsConstant() && cpuTensor && tensor->hasNPUReaders ) + if ( cpuTensor && !tensor->hasNPUWriters && !tensor->hasNPUReaders ) + { + tensor->memArea = _arch->CPUMemory(); + } + else if ( _options.separateIORegions && !tensor->IsConstant() && cpuTensor && tensor->hasNPUReaders ) { tensor->memArea = _arch->InputFeatureMapMemory(); } -- GitLab