ArmNN
 22.05
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 
52  virtual MemBlockStrategyType GetMemBlockStrategyType() const = 0;
53 
54  virtual std::vector<MemBin> Optimize(std::vector<MemBlock>& memBlocks) = 0;
55 };
56 
57 } // namespace armnn
const unsigned int m_StartOfLife
std::vector< MemBlock > m_MemBlocks
Copyright (c) 2021 ARM Limited and Contributors.
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
Create an optimized version of the network.
Definition: Network.cpp:1847
MemBlockStrategyType
Definition: Types.hpp:239
MemBlock(const unsigned int startOfLife, const unsigned int endOfLife, const size_t memSize, size_t offset, const unsigned int index)
const unsigned int m_EndOfLife
const unsigned int m_Index