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" |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 7 | #include <armnn/Exceptions.hpp> |
Jim Flynn | 8e0c7a6 | 2020-01-30 14:10:55 +0000 | [diff] [blame] | 8 | #include <map> |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 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 | |
Jim Flynn | 9789702 | 2020-02-02 12:52:59 +0000 | [diff] [blame] | 24 | void CounterIdMap::Reset() |
| 25 | { |
| 26 | m_GlobalCounterIdMap.clear(); |
| 27 | m_BackendCounterIdMap.clear(); |
| 28 | } |
| 29 | |
Jim Flynn | 8e0c7a6 | 2020-01-30 14:10:55 +0000 | [diff] [blame] | 30 | uint16_t CounterIdMap::GetGlobalId(uint16_t backendCounterId, const armnn::BackendId& backendId) const |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 31 | { |
| 32 | std::pair<uint16_t, armnn::BackendId> backendIdPair(backendCounterId, backendId); |
| 33 | auto it = m_BackendCounterIdMap.find(backendIdPair); |
| 34 | if (it == m_BackendCounterIdMap.end()) |
| 35 | { |
| 36 | std::stringstream ss; |
| 37 | ss << "No Backend Counter [" << backendIdPair.second << ":" << backendIdPair.first << "] registered"; |
| 38 | throw armnn::Exception(ss.str()); |
| 39 | } |
| 40 | return it->second; |
| 41 | } |
| 42 | |
Jim Flynn | 8e0c7a6 | 2020-01-30 14:10:55 +0000 | [diff] [blame] | 43 | const std::pair<uint16_t, armnn::BackendId>& CounterIdMap::GetBackendId(uint16_t globalCounterId) const |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 44 | { |
| 45 | auto it = m_GlobalCounterIdMap.find(globalCounterId); |
| 46 | if (it == m_GlobalCounterIdMap.end()) |
| 47 | { |
| 48 | std::stringstream ss; |
| 49 | ss << "No Global Counter ID [" << globalCounterId << "] registered"; |
| 50 | throw armnn::Exception(ss.str()); |
| 51 | } |
| 52 | return it->second; |
| 53 | } |
| 54 | |
| 55 | } // namespace profiling |
Jim Flynn | 8e0c7a6 | 2020-01-30 14:10:55 +0000 | [diff] [blame] | 56 | } // namespace armnn |