blob: 8e8dc0fc73b866395f11aa68c9471b6b3feebdf5 [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
Jens Elofsson701a63b2021-05-23 17:37:07 +020019#ifndef LAYER_BY_LAYER_PROFILER_H
20#define LAYER_BY_LAYER_PROFILER_H
Jens Elofsson955288a2021-04-22 20:57:15 +020021
Jens Elofsson701a63b2021-05-23 17:37:07 +020022#include "EventRecorder.h"
Jens Elofsson955288a2021-04-22 20:57:15 +020023#include "tensorflow/lite/kernels/internal/compatibility.h"
24#include <memory>
25#include <pmu_ethosu.h>
26
27// NOTE: This profiler only works on systems with 1 NPU due to the use of
28// ethosu_reserve_driver().
29namespace tflite {
Jens Elofsson701a63b2021-05-23 17:37:07 +020030class LayerByLayerProfiler : public MicroProfiler {
Jens Elofsson955288a2021-04-22 20:57:15 +020031public:
Jens Elofsson701a63b2021-05-23 17:37:07 +020032 enum Backend { PRINTF, EVENT_RECORDER };
33 LayerByLayerProfiler(size_t max_events = 200,
34 Backend backend = PRINTF,
35 int32_t event_id = EventID(EventLevelError, EvtStatistics_No, EventRecordNone));
Jens Elofsson955288a2021-04-22 20:57:15 +020036 uint32_t BeginEvent(const char *tag);
37 void EndEvent(uint32_t event_handle);
38 uint64_t GetTotalTicks() const;
39 void Log() const;
Jens Elofsson955288a2021-04-22 20:57:15 +020040
41private:
Jens Elofsson955288a2021-04-22 20:57:15 +020042 size_t max_events_;
43 std::unique_ptr<const char *[]> tags_;
44 std::unique_ptr<uint64_t[]> start_ticks_;
45 std::unique_ptr<uint64_t[]> end_ticks_;
Jens Elofsson701a63b2021-05-23 17:37:07 +020046
47 Backend backend_;
48 int32_t event_id_;
Kristofer Jonsson44d6e222021-05-21 18:59:18 +020049 size_t num_events_;
Jens Elofsson955288a2021-04-22 20:57:15 +020050
Jens Elofsson955288a2021-04-22 20:57:15 +020051 TF_LITE_REMOVE_VIRTUAL_DELETE;
52};
53
54} // namespace tflite
55
56#endif