blob: c765c31a18d95ee1360b181dea88206af22d6e18 [file] [log] [blame]
Finn Williamsf9d96e52021-10-27 11:25:02 +01001//
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#include <armnn/backends/IMemoryOptimizerStrategy.hpp>
9#include <tuple>
10#include <utility>
11#include <algorithm>
12
13#include <list>
14
15namespace armnn
16{
17
18 /// SingleAxisPriorityList sorts the MemBlocks according to some priority,
19 /// then trys to place them into as few bins as possible
20 class SingleAxisPriorityList : public IMemoryOptimizerStrategy
21 {
22 public:
23 SingleAxisPriorityList()
24 : m_Name(std::string("SingleAxisPriorityList"))
25 , m_MemBlockStrategyType(MemBlockStrategyType::SingleAxisPacking) {}
26
27 std::string GetName() const override;
28
29 MemBlockStrategyType GetMemBlockStrategyType() const override;
30
31 std::vector<MemBin> Optimize(std::vector<MemBlock>& memBlocks) override;
32
33 private:
34
35 // Tracks all memBlocks and their positions in a bin as well as their maximum memSize
36 struct BinTracker;
37
38 // PlaceBlocks takes a list of MemBlock* and fits them into n bins.
39 // A block can only fit into an existing bin if it's lifetime does not overlap with the lifetime of the
40 // blocks already in a bin.
41 // If no appropriate bin is available a new one is created.
42 void PlaceBlocks(const std::list<MemBlock*>& priorityList,
43 std::vector<BinTracker>& placedBlocks,
44 const unsigned int maxLifetime);
45
46 std::string m_Name;
47 MemBlockStrategyType m_MemBlockStrategyType;
48 };
49
50} // namespace armnn