Sadik Armagan | 932cf3f | 2021-09-15 09:22:11 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2021 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Jim Flynn | e1fdd28 | 2021-10-26 21:26:10 +0100 | [diff] [blame^] | 6 | #include "ConstantMemoryStrategy.hpp" |
Sadik Armagan | 932cf3f | 2021-09-15 09:22:11 +0100 | [diff] [blame] | 7 | |
| 8 | namespace armnn |
| 9 | { |
| 10 | |
Jim Flynn | e1fdd28 | 2021-10-26 21:26:10 +0100 | [diff] [blame^] | 11 | std::string ConstantMemoryStrategy::GetName() const |
Sadik Armagan | 932cf3f | 2021-09-15 09:22:11 +0100 | [diff] [blame] | 12 | { |
| 13 | return m_Name; |
| 14 | } |
| 15 | |
Jim Flynn | e1fdd28 | 2021-10-26 21:26:10 +0100 | [diff] [blame^] | 16 | MemBlockStrategyType ConstantMemoryStrategy::GetMemBlockStrategyType() const |
Sadik Armagan | 932cf3f | 2021-09-15 09:22:11 +0100 | [diff] [blame] | 17 | { |
| 18 | return m_MemBlockStrategyType; |
| 19 | } |
| 20 | |
| 21 | // A IMemoryOptimizerStrategy must ensure that |
| 22 | // 1: All MemBlocks have been assigned to a MemBin |
| 23 | // 2: No MemBlock is assigned to multiple MemBins |
Francis Murtagh | ca49a24 | 2021-09-28 15:30:31 +0100 | [diff] [blame] | 24 | // 3: No two Memblocks in a MemBin overlap in both the X and Y axis |
Jim Flynn | e1fdd28 | 2021-10-26 21:26:10 +0100 | [diff] [blame^] | 25 | std::vector<MemBin> ConstantMemoryStrategy::Optimize(std::vector<MemBlock>& memBlocks) |
Sadik Armagan | 932cf3f | 2021-09-15 09:22:11 +0100 | [diff] [blame] | 26 | { |
| 27 | std::vector<MemBin> memBins; |
| 28 | memBins.reserve(memBlocks.size()); |
| 29 | |
| 30 | for (auto& memBlock : memBlocks) |
| 31 | { |
| 32 | MemBin memBin; |
| 33 | memBin.m_MemSize = memBlock.m_MemSize; |
| 34 | memBin.m_MemBlocks.reserve(1); |
| 35 | memBlock.m_Offset = 0; |
| 36 | memBin.m_MemBlocks.push_back(memBlock); |
| 37 | memBins.push_back(memBin); |
| 38 | } |
| 39 | |
| 40 | return memBins; |
| 41 | } |
| 42 | |
| 43 | } // namespace armnn |