From 932cf3f668cd8843927667e9a9e2b15c91de4974 Mon Sep 17 00:00:00 2001 From: Sadik Armagan Date: Wed, 15 Sep 2021 09:22:11 +0100 Subject: IVGCVSW-6298 'IMemoryOptimizerStrategy Add declarations and constant layer strategy' * Added IMemoryOptimizerStrategy interface * Added ConstLayerMemoryOptimizer strategy Signed-off-by: Sadik Armagan Change-Id: I6a92e659379e5cc39c375b669678eee8a8c08c20 --- include/armnn/Types.hpp | 13 +++++ include/armnn/backends/CMakeLists.txt | 1 + .../armnn/backends/IMemoryOptimizerStrategy.hpp | 57 ++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 include/armnn/backends/IMemoryOptimizerStrategy.hpp (limited to 'include') diff --git a/include/armnn/Types.hpp b/include/armnn/Types.hpp index 19e93c3c7e..0b7b941008 100644 --- a/include/armnn/Types.hpp +++ b/include/armnn/Types.hpp @@ -213,6 +213,19 @@ enum class MemorySource : uint32_t DmaBufProtected = 4 }; +enum class MemBlockStrategyType +{ + // MemBlocks can be packed on the Y axis only. + // In other words MemBlocks with overlapping lifetimes cannot use the same MemBin, + // equivalent to blob or pooling memory management. + SingleAxisPacking = 0, + + // MemBlocks can be packed on the Y and X axis. + // In other words MemBlocks with overlapping lifetimes can use the same MemBin, + // equivalent to offset or slab memory management. + MultiAxisPacking = 1 +}; + /// Each backend should implement an IBackend. class IBackend { diff --git a/include/armnn/backends/CMakeLists.txt b/include/armnn/backends/CMakeLists.txt index 58d0abf872..19046ed977 100644 --- a/include/armnn/backends/CMakeLists.txt +++ b/include/armnn/backends/CMakeLists.txt @@ -10,6 +10,7 @@ list(APPEND armnnBackendsAPI_sources IBackendInternal.hpp IBackendContext.hpp IMemoryManager.hpp + IMemoryOptimizerStrategy.hpp ITensorHandle.hpp ITensorHandleFactory.hpp IWorkload.hpp diff --git a/include/armnn/backends/IMemoryOptimizerStrategy.hpp b/include/armnn/backends/IMemoryOptimizerStrategy.hpp new file mode 100644 index 0000000000..ec6d838aae --- /dev/null +++ b/include/armnn/backends/IMemoryOptimizerStrategy.hpp @@ -0,0 +1,57 @@ +// +// Copyright © 2021 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// +#pragma once + +#include + +namespace armnn +{ + +// A MemBlock represents a memory usage requirement in time and space and can be seen as essentially a rectangle +struct MemBlock +{ + MemBlock(const unsigned int startOfLife, + const unsigned int endOfLife, + const size_t memSize, + size_t offset, + const unsigned int index) + : m_StartOfLife(startOfLife), m_EndOfLife(endOfLife), m_MemSize(memSize), m_Offset(offset), m_Index(index) {} + + const unsigned int m_StartOfLife; // Y start + const unsigned int m_EndOfLife; // Y end + + const size_t m_MemSize; // X start + size_t m_Offset; // X end + + const unsigned int m_Index; // Index to keep order +}; + +// A MemBin represents a single contiguous area of memory that can store 1-n number of MemBlocks +struct MemBin +{ + std::vector m_MemBlocks; + size_t m_MemSize; +}; + +// IMemoryOptimizerStrategy will set m_Offset of the MemBlocks, +// sort them into 1-n bins, then pair each bin of MemBlocks with an int specifying it's total size +// A IMemoryOptimizerStrategy must ensure that +// 1: All MemBlocks have been assigned to a MemBin +// 2: No MemBlock is assigned to multiple MemBins +// 3: No two MemBlocks in a MemBin overlap in the X dimension +// (a strategy cannot change the y axis or length of a MemBlock) +class IMemoryOptimizerStrategy +{ +public: + virtual ~IMemoryOptimizerStrategy() {} + + virtual std::string GetName() const = 0; + + virtual MemBlockStrategyType GetMemBlockStrategyType() const = 0; + + virtual std::vector Optimize(std::vector& memBlocks) = 0; +}; + +} // namespace armnn \ No newline at end of file -- cgit v1.2.1