blob: 0c50bc85e17a921407f2b3a11458dfa52ed4e2e2 [file] [log] [blame]
Jens Elofsson955288a2021-04-22 20:57:15 +02001/*
Kristofer Jonsson5a15bf42022-01-27 17:36:55 +01002 * Copyright (c) 2021-2022 Arm Limited. All rights reserved.
Jens Elofsson955288a2021-04-22 20:57:15 +02003 *
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>
Jonny Svärd4c11a482021-12-17 17:04:08 +010025#include <vector>
Jens Elofsson955288a2021-04-22 20:57:15 +020026
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 };
Kristofer Jonsson5a15bf42022-01-27 17:36:55 +010033
34 LayerByLayerProfiler(size_t max_events = 200,
35 Backend backend = PRINTF,
36 int32_t event_id = EventID(EventLevelError, EvtStatistics_No, EventRecordNone));
37
Jens Elofsson955288a2021-04-22 20:57:15 +020038 uint32_t BeginEvent(const char *tag);
39 void EndEvent(uint32_t event_handle);
Kristofer Jonssondcc1ce02021-12-21 16:25:19 +010040 int32_t GetTotalTicks() const;
Jens Elofsson955288a2021-04-22 20:57:15 +020041 void Log() const;
Jens Elofsson955288a2021-04-22 20:57:15 +020042
43private:
Jens Elofsson955288a2021-04-22 20:57:15 +020044 std::unique_ptr<const char *[]> tags_;
45 std::unique_ptr<uint64_t[]> start_ticks_;
46 std::unique_ptr<uint64_t[]> end_ticks_;
Jens Elofsson701a63b2021-05-23 17:37:07 +020047
Jonny Svärd4c11a482021-12-17 17:04:08 +010048 size_t max_events_;
49 Backend backend;
50 int32_t event_id;
Kristofer Jonsson44d6e222021-05-21 18:59:18 +020051 size_t num_events_;
Jens Elofsson955288a2021-04-22 20:57:15 +020052
Jens Elofsson955288a2021-04-22 20:57:15 +020053 TF_LITE_REMOVE_VIRTUAL_DELETE;
54};
55
56} // namespace tflite
57
58#endif