aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/CounterIdMap.cpp
blob: a925fb9cb4d74ff7881196f717608f5593ccc72d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// Copyright © 2020 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//
#include "CounterIdMap.hpp"
#include "armnn/BackendId.hpp"
#include <map>
#include <armnn/Exceptions.hpp>

namespace armnn
{
namespace profiling
{

void CounterIdMap::RegisterMapping(uint16_t globalCounterId,
                                   uint16_t backendCounterId,
                                   const armnn::BackendId& backendId)
{
    std::pair<uint16_t, armnn::BackendId> backendIdPair(backendCounterId, backendId);
    m_GlobalCounterIdMap[globalCounterId] = backendIdPair;
    m_BackendCounterIdMap[backendIdPair] = globalCounterId;
}

uint16_t CounterIdMap::GetGlobalId(uint16_t backendCounterId, const armnn::BackendId& backendId)
{
    std::pair<uint16_t, armnn::BackendId> backendIdPair(backendCounterId, backendId);
    auto it = m_BackendCounterIdMap.find(backendIdPair);
    if (it == m_BackendCounterIdMap.end())
    {
        std::stringstream ss;
        ss << "No Backend Counter [" << backendIdPair.second << ":" << backendIdPair.first << "] registered";
        throw armnn::Exception(ss.str());
    }
    return it->second;
}

const std::pair<uint16_t, armnn::BackendId>& CounterIdMap::GetBackendId(uint16_t globalCounterId)
{
    auto it = m_GlobalCounterIdMap.find(globalCounterId);
    if (it == m_GlobalCounterIdMap.end())
    {
        std::stringstream ss;
        ss << "No Global Counter ID [" << globalCounterId << "] registered";
        throw armnn::Exception(ss.str());
    }
    return it->second;
}

}    // namespace profiling
}    // namespace armnn