Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 1 | /* |
Måns Nilsson | 45a8a13 | 2022-09-26 08:42:10 +0200 | [diff] [blame] | 2 | * SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates <open-source-office@arm.com> |
Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 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 Elofsson | 701a63b | 2021-05-23 17:37:07 +0200 | [diff] [blame] | 19 | #ifndef LAYER_BY_LAYER_PROFILER_H |
| 20 | #define LAYER_BY_LAYER_PROFILER_H |
Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 21 | |
Jens Elofsson | 701a63b | 2021-05-23 17:37:07 +0200 | [diff] [blame] | 22 | #include "EventRecorder.h" |
Kristofer Jonsson | 1fed1d5 | 2022-11-21 13:39:45 +0100 | [diff] [blame] | 23 | #include "tensorflow/lite/micro/compatibility.h" |
Måns Nilsson | 45a8a13 | 2022-09-26 08:42:10 +0200 | [diff] [blame] | 24 | #include "tensorflow/lite/micro/micro_profiler_interface.h" |
Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 25 | #include <memory> |
Jonny Svärd | 4c11a48 | 2021-12-17 17:04:08 +0100 | [diff] [blame] | 26 | #include <vector> |
Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 27 | |
| 28 | // NOTE: This profiler only works on systems with 1 NPU due to the use of |
| 29 | // ethosu_reserve_driver(). |
| 30 | namespace tflite { |
Måns Nilsson | 45a8a13 | 2022-09-26 08:42:10 +0200 | [diff] [blame] | 31 | class LayerByLayerProfiler : public MicroProfilerInterface { |
Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 32 | public: |
Jens Elofsson | 701a63b | 2021-05-23 17:37:07 +0200 | [diff] [blame] | 33 | enum Backend { PRINTF, EVENT_RECORDER }; |
Kristofer Jonsson | 5a15bf4 | 2022-01-27 17:36:55 +0100 | [diff] [blame] | 34 | |
| 35 | LayerByLayerProfiler(size_t max_events = 200, |
| 36 | Backend backend = PRINTF, |
| 37 | int32_t event_id = EventID(EventLevelError, EvtStatistics_No, EventRecordNone)); |
| 38 | |
Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 39 | uint32_t BeginEvent(const char *tag); |
| 40 | void EndEvent(uint32_t event_handle); |
Kristofer Jonsson | dcc1ce0 | 2021-12-21 16:25:19 +0100 | [diff] [blame] | 41 | int32_t GetTotalTicks() const; |
Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 42 | void Log() const; |
Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 43 | |
| 44 | private: |
Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 45 | std::unique_ptr<const char *[]> tags_; |
| 46 | std::unique_ptr<uint64_t[]> start_ticks_; |
| 47 | std::unique_ptr<uint64_t[]> end_ticks_; |
Jens Elofsson | 701a63b | 2021-05-23 17:37:07 +0200 | [diff] [blame] | 48 | |
Jonny Svärd | 4c11a48 | 2021-12-17 17:04:08 +0100 | [diff] [blame] | 49 | size_t max_events_; |
| 50 | Backend backend; |
| 51 | int32_t event_id; |
Kristofer Jonsson | 44d6e22 | 2021-05-21 18:59:18 +0200 | [diff] [blame] | 52 | size_t num_events_; |
Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 53 | |
Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 54 | TF_LITE_REMOVE_VIRTUAL_DELETE; |
| 55 | }; |
| 56 | |
| 57 | } // namespace tflite |
| 58 | |
| 59 | #endif |