blob: 745c670182c632989308003bfe56aa8525617c61 [file] [log] [blame]
Jens Elofsson955288a2021-04-22 20:57:15 +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_PROFILER_H
20#define ETHOSU_PROFILER_H
21
22#include "tensorflow/lite/kernels/internal/compatibility.h"
23#include <memory>
24#include <pmu_ethosu.h>
25
26// NOTE: This profiler only works on systems with 1 NPU due to the use of
27// ethosu_reserve_driver().
28namespace tflite {
29class EthosUProfiler : public MicroProfiler {
30public:
31 EthosUProfiler(ethosu_pmu_event_type event0 = ETHOSU_PMU_NO_EVENT,
32 ethosu_pmu_event_type event1 = ETHOSU_PMU_NO_EVENT,
33 ethosu_pmu_event_type event2 = ETHOSU_PMU_NO_EVENT,
34 ethosu_pmu_event_type event3 = ETHOSU_PMU_NO_EVENT,
35 size_t max_events = 200);
36 uint32_t BeginEvent(const char *tag);
37 void EndEvent(uint32_t event_handle);
38 uint64_t GetTotalTicks() const;
39 void Log() const;
40 uint32_t GetEthosuPMUCounter(int counter);
41
42private:
43 void MonitorEthosuPMUEvents(ethosu_pmu_event_type event0,
44 ethosu_pmu_event_type event1,
45 ethosu_pmu_event_type event2,
46 ethosu_pmu_event_type event3);
47
48 size_t max_events_;
49 std::unique_ptr<const char *[]> tags_;
50 std::unique_ptr<uint64_t[]> start_ticks_;
51 std::unique_ptr<uint64_t[]> end_ticks_;
52
53 int num_events_ = 0;
54
55 ethosu_pmu_event_type ethosu_pmu_cntrs[ETHOSU_PMU_NCOUNTERS];
56
57 uint32_t event_counters[ETHOSU_PMU_NCOUNTERS];
58
59 TF_LITE_REMOVE_VIRTUAL_DELETE;
60};
61
62} // namespace tflite
63
64#endif