blob: c1308a58ab80d42df4442d51594061b691241723 [file] [log] [blame]
Jens Elofssona9817a12021-05-18 11:30:35 +02001/*
2 * Copyright (c) 2021 Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#ifndef ETHOSU_MONITOR_H
20#define ETHOSU_MONITOR_H
21
22#include "EventRecorder.h"
23#include "EventRecorderConf.h"
24#include <algorithm>
25#include <ethosu_driver.h>
26#include <pmu_ethosu.h>
27#include <stdint.h>
28
29class EthosUMonitor {
30
31public:
32 enum Backend { PRINTF, EVENT_RECORDER };
33
34 EthosUMonitor(int32_t __id = EventID(EventLevelError, EvtStatistics_No, EventRecordNone), Backend backend = PRINTF);
35
36 template <typename T>
37 void configure(ethosu_driver *drv, const T &eventIds) {
38 // Set event ids
39 numEvents = std::min(static_cast<size_t>(ETHOSU_PMU_NCOUNTERS), eventIds.size());
40 for (size_t i = 0; i < numEvents; i++) {
41 ethosuEventIds[i] = eventIds[i];
42 }
43
44 // config pmu and set driver
45 ETHOSU_PMU_Enable(drv);
46
47 for (size_t i = 0; i < ETHOSU_PMU_NCOUNTERS; i++) {
48 ETHOSU_PMU_Set_EVTYPER(drv, i, static_cast<ethosu_pmu_event_type>(ethosuEventIds[i]));
49 ETHOSU_PMU_CNTR_Enable(drv, 1 << i);
50 }
51
52 ETHOSU_PMU_EVCNTR_ALL_Reset(drv);
53 }
54
55 void release(ethosu_driver *drv);
56
57 void monitorSample(ethosu_driver *drv);
58
59private:
60 ethosu_pmu_event_type ethosuEventIds[ETHOSU_PMU_NCOUNTERS];
61 size_t numEvents;
62 int32_t eventRecordId;
63 Backend backend;
64};
65
66#endif