IVGCVSW-6303 Create a SingleAxisPacking strategy
* add fsrcnn and mobilebert memory profiles to the strategy benchmark
Signed-off-by: Finn Williams <finn.williams@arm.com>
Change-Id: Ibd8b26f2153c561e5c5bec477f6246d0e8ffa4af
diff --git a/src/backends/backendsCommon/memoryOptimizerStrategyLibrary/strategies/SingleAxisPriorityList.hpp b/src/backends/backendsCommon/memoryOptimizerStrategyLibrary/strategies/SingleAxisPriorityList.hpp
new file mode 100644
index 0000000..c765c31
--- /dev/null
+++ b/src/backends/backendsCommon/memoryOptimizerStrategyLibrary/strategies/SingleAxisPriorityList.hpp
@@ -0,0 +1,50 @@
+//
+// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+#pragma once
+
+#include <armnn/Types.hpp>
+#include <armnn/backends/IMemoryOptimizerStrategy.hpp>
+#include <tuple>
+#include <utility>
+#include <algorithm>
+
+#include <list>
+
+namespace armnn
+{
+
+ /// SingleAxisPriorityList sorts the MemBlocks according to some priority,
+ /// then trys to place them into as few bins as possible
+ class SingleAxisPriorityList : public IMemoryOptimizerStrategy
+ {
+ public:
+ SingleAxisPriorityList()
+ : m_Name(std::string("SingleAxisPriorityList"))
+ , m_MemBlockStrategyType(MemBlockStrategyType::SingleAxisPacking) {}
+
+ std::string GetName() const override;
+
+ MemBlockStrategyType GetMemBlockStrategyType() const override;
+
+ std::vector<MemBin> Optimize(std::vector<MemBlock>& memBlocks) override;
+
+ private:
+
+ // Tracks all memBlocks and their positions in a bin as well as their maximum memSize
+ struct BinTracker;
+
+ // PlaceBlocks takes a list of MemBlock* and fits them into n bins.
+ // A block can only fit into an existing bin if it's lifetime does not overlap with the lifetime of the
+ // blocks already in a bin.
+ // If no appropriate bin is available a new one is created.
+ void PlaceBlocks(const std::list<MemBlock*>& priorityList,
+ std::vector<BinTracker>& placedBlocks,
+ const unsigned int maxLifetime);
+
+ std::string m_Name;
+ MemBlockStrategyType m_MemBlockStrategyType;
+ };
+
+} // namespace armnn
\ No newline at end of file