David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | #include "CounterIdMap.hpp" |
| 6 | #include "armnn/BackendId.hpp" |
| 7 | #include <map> |
| 8 | #include <armnn/Exceptions.hpp> |
| 9 | |
| 10 | namespace armnn |
| 11 | { |
| 12 | namespace profiling |
| 13 | { |
| 14 | |
| 15 | void CounterIdMap::RegisterMapping(uint16_t globalCounterId, |
| 16 | uint16_t backendCounterId, |
| 17 | const armnn::BackendId& backendId) |
| 18 | { |
| 19 | std::pair<uint16_t, armnn::BackendId> backendIdPair(backendCounterId, backendId); |
| 20 | m_GlobalCounterIdMap[globalCounterId] = backendIdPair; |
| 21 | m_BackendCounterIdMap[backendIdPair] = globalCounterId; |
| 22 | } |
| 23 | |
| 24 | uint16_t CounterIdMap::GetGlobalId(uint16_t backendCounterId, const armnn::BackendId& backendId) |
| 25 | { |
| 26 | std::pair<uint16_t, armnn::BackendId> backendIdPair(backendCounterId, backendId); |
| 27 | auto it = m_BackendCounterIdMap.find(backendIdPair); |
| 28 | if (it == m_BackendCounterIdMap.end()) |
| 29 | { |
| 30 | std::stringstream ss; |
| 31 | ss << "No Backend Counter [" << backendIdPair.second << ":" << backendIdPair.first << "] registered"; |
| 32 | throw armnn::Exception(ss.str()); |
| 33 | } |
| 34 | return it->second; |
| 35 | } |
| 36 | |
| 37 | const std::pair<uint16_t, armnn::BackendId>& CounterIdMap::GetBackendId(uint16_t globalCounterId) |
| 38 | { |
| 39 | auto it = m_GlobalCounterIdMap.find(globalCounterId); |
| 40 | if (it == m_GlobalCounterIdMap.end()) |
| 41 | { |
| 42 | std::stringstream ss; |
| 43 | ss << "No Global Counter ID [" << globalCounterId << "] registered"; |
| 44 | throw armnn::Exception(ss.str()); |
| 45 | } |
| 46 | return it->second; |
| 47 | } |
| 48 | |
| 49 | } // namespace profiling |
| 50 | } // namespace armnn |