ArmNN
 24.08
SingleAxisPriorityList Class Reference

SingleAxisPriorityList sorts the MemBlocks according to some priority, then trys to place them into as few bins as possible. More...

#include <SingleAxisPriorityList.hpp>

Inheritance diagram for SingleAxisPriorityList:
[legend]
Collaboration diagram for SingleAxisPriorityList:
[legend]

Public Member Functions

 SingleAxisPriorityList ()
 
std::string GetName () const override
 
MemBlockStrategyType GetMemBlockStrategyType () const override
 
std::vector< MemBinOptimize (std::vector< MemBlock > &memBlocks) override
 
- Public Member Functions inherited from IMemoryOptimizerStrategy
virtual ~IMemoryOptimizerStrategy ()
 

Detailed Description

SingleAxisPriorityList sorts the MemBlocks according to some priority, then trys to place them into as few bins as possible.

Definition at line 20 of file SingleAxisPriorityList.hpp.

Constructor & Destructor Documentation

◆ SingleAxisPriorityList()

Definition at line 23 of file SingleAxisPriorityList.hpp.

24  : m_Name(std::string("SingleAxisPriorityList"))
25  , m_MemBlockStrategyType(MemBlockStrategyType::SingleAxisPacking) {}

References armnn::SingleAxisPacking.

Member Function Documentation

◆ GetMemBlockStrategyType()

MemBlockStrategyType GetMemBlockStrategyType ( ) const
overridevirtual

Implements IMemoryOptimizerStrategy.

Definition at line 28 of file SingleAxisPriorityList.cpp.

28  {
29  return m_MemBlockStrategyType;
30 }

◆ GetName()

std::string GetName ( ) const
overridevirtual

Implements IMemoryOptimizerStrategy.

Definition at line 24 of file SingleAxisPriorityList.cpp.

24  {
25  return m_Name;
26 }

◆ Optimize()

std::vector< MemBin > Optimize ( std::vector< MemBlock > &  memBlocks)
overridevirtual

Implements IMemoryOptimizerStrategy.

Definition at line 214 of file SingleAxisPriorityList.cpp.

215 {
216  unsigned int maxLifetime = 0;
217  std::list<MemBlock*> priorityList;
218  for (auto& block: blocks)
219  {
220  maxLifetime = std::max(maxLifetime, block.m_EndOfLife);
221  priorityList.emplace_back(&block);
222  }
223  maxLifetime++;
224 
225  // From testing ordering by m_MemSize in non-descending order gives the best results overall
226  priorityList.sort([](const MemBlock* lhs, const MemBlock* rhs)
227  {
228  return lhs->m_MemSize > rhs->m_MemSize ;
229  });
230 
231 
232  std::vector<BinTracker> placedBlocks;
233  placedBlocks.reserve(maxLifetime);
234  PlaceBlocks(priorityList, placedBlocks, maxLifetime);
235 
236  std::vector<MemBin> bins;
237  bins.reserve(placedBlocks.size());
238  for (auto blockList: placedBlocks)
239  {
240  MemBin bin;
241  bin.m_MemBlocks.reserve(blockList.m_PlacedBlocks.size());
242  bin.m_MemSize = blockList.m_MemSize;
243 
244  for (auto block : blockList.m_PlacedBlocks)
245  {
246  bin.m_MemBlocks.emplace_back(MemBlock{block->m_StartOfLife,
247  block->m_EndOfLife,
248  block->m_MemSize,
249  0,
250  block->m_Index,});
251  }
252  bins.push_back(std::move(bin));
253  }
254 
255  return bins;
256 }

References MemBin::m_MemBlocks, MemBlock::m_MemSize, MemBin::m_MemSize, and MemBlock::m_StartOfLife.


The documentation for this class was generated from the following files:
armnn::MemBlockStrategyType::SingleAxisPacking
@ SingleAxisPacking