ArmNN
 24.02
IMemoryOptimizerStrategy.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include <armnn/Types.hpp>
8 
9 namespace armnn
10 {
11 
12 // A MemBlock represents a memory usage requirement in time and space and can be seen as essentially a rectangle
13 struct MemBlock
14 {
15  MemBlock(const unsigned int startOfLife,
16  const unsigned int endOfLife,
17  const size_t memSize,
18  size_t offset,
19  const unsigned int index)
20  : m_StartOfLife(startOfLife), m_EndOfLife(endOfLife), m_MemSize(memSize), m_Offset(offset), m_Index(index) {}
21 
22  const unsigned int m_StartOfLife; // Y start inclusive
23  const unsigned int m_EndOfLife; // Y end inclusive
24 
25  const size_t m_MemSize; // Offset + Memsize = X end
26  size_t m_Offset; // X start
27 
28  const unsigned int m_Index; // Index to keep order
29 };
30 
31 // A MemBin represents a single contiguous area of memory that can store 1-n number of MemBlocks
32 struct MemBin
33 {
34  std::vector<MemBlock> m_MemBlocks;
35  size_t m_MemSize;
36 };
37 
38 // IMemoryOptimizerStrategy will set m_Offset of the MemBlocks,
39 // sort them into 1-n bins, then pair each bin of MemBlocks with an int specifying it's total size
40 // A IMemoryOptimizerStrategy must ensure that
41 // 1: All MemBlocks have been assigned to a MemBin
42 // 2: No MemBlock is assigned to multiple MemBins
43 // 3: No two Memblocks in a MemBin overlap in both the X and Y axis
44 // (a strategy cannot change the y axis or length of a MemBlock)
46 {
47 public:
49 
50  virtual std::string GetName() const = 0;
51 
53 
54  virtual std::vector<MemBin> Optimize(std::vector<MemBlock>& memBlocks) = 0;
55 };
56 
57 } // namespace armnn
armnn::MemBlock::MemBlock
MemBlock(const unsigned int startOfLife, const unsigned int endOfLife, const size_t memSize, size_t offset, const unsigned int index)
Definition: IMemoryOptimizerStrategy.hpp:15
armnn::IMemoryOptimizerStrategy::~IMemoryOptimizerStrategy
virtual ~IMemoryOptimizerStrategy()
Definition: IMemoryOptimizerStrategy.hpp:48
armnn::IMemoryOptimizerStrategy::Optimize
virtual std::vector< MemBin > Optimize(std::vector< MemBlock > &memBlocks)=0
armnn::MemBlock::m_Index
const unsigned int m_Index
Definition: IMemoryOptimizerStrategy.hpp:28
armnn::MemBlock
Definition: IMemoryOptimizerStrategy.hpp:13
armnn::MemBlock::m_StartOfLife
const unsigned int m_StartOfLife
Definition: IMemoryOptimizerStrategy.hpp:22
armnn::IMemoryOptimizerStrategy
Definition: IMemoryOptimizerStrategy.hpp:45
armnn::MemBlock::m_EndOfLife
const unsigned int m_EndOfLife
Definition: IMemoryOptimizerStrategy.hpp:23
armnn::MemBlockStrategyType
MemBlockStrategyType
Definition: Types.hpp:253
armnn::IMemoryOptimizerStrategy::GetName
virtual std::string GetName() const =0
armnn::MemBin::m_MemSize
size_t m_MemSize
Definition: IMemoryOptimizerStrategy.hpp:35
armnn::MemBlock::m_MemSize
const size_t m_MemSize
Definition: IMemoryOptimizerStrategy.hpp:25
armnn::MemBin::m_MemBlocks
std::vector< MemBlock > m_MemBlocks
Definition: IMemoryOptimizerStrategy.hpp:34
armnn::IMemoryOptimizerStrategy::GetMemBlockStrategyType
virtual MemBlockStrategyType GetMemBlockStrategyType() const =0
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
Types.hpp
armnn::MemBin
Definition: IMemoryOptimizerStrategy.hpp:32
armnn::MemBlock::m_Offset
size_t m_Offset
Definition: IMemoryOptimizerStrategy.hpp:26