Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 1 | /* |
| 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 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" |
Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 23 | #include "tensorflow/lite/kernels/internal/compatibility.h" |
| 24 | #include <memory> |
| 25 | #include <pmu_ethosu.h> |
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 { |
Jens Elofsson | 701a63b | 2021-05-23 17:37:07 +0200 | [diff] [blame] | 31 | class LayerByLayerProfiler : public MicroProfiler { |
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 }; |
Jonny Svärd | 4c11a48 | 2021-12-17 17:04:08 +0100 | [diff] [blame^] | 34 | LayerByLayerProfiler(const std::vector<uint8_t> &event_config = {}, |
| 35 | bool pmu_cycle_counter_enable = true, |
| 36 | size_t max_events = 200, |
| 37 | Backend backend = PRINTF, |
| 38 | int32_t event_id = EventID(EventLevelError, EvtStatistics_No, EventRecordNone)); |
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); |
| 41 | uint64_t GetTotalTicks() const; |
| 42 | void Log() const; |
Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 43 | |
Jonny Svärd | 4c11a48 | 2021-12-17 17:04:08 +0100 | [diff] [blame^] | 44 | uint64_t GetPmuCycleCounterCount() const; |
| 45 | const std::vector<uint32_t> &GetPmuEventCount() const; |
| 46 | |
Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 47 | private: |
Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 48 | std::unique_ptr<const char *[]> tags_; |
| 49 | std::unique_ptr<uint64_t[]> start_ticks_; |
| 50 | std::unique_ptr<uint64_t[]> end_ticks_; |
Jens Elofsson | 701a63b | 2021-05-23 17:37:07 +0200 | [diff] [blame] | 51 | |
Jonny Svärd | 4c11a48 | 2021-12-17 17:04:08 +0100 | [diff] [blame^] | 52 | std::vector<uint8_t> pmu_event_config; |
| 53 | std::vector<uint32_t> pmu_event_count; |
| 54 | bool pmu_cycle_counter_enable; |
| 55 | uint64_t pmu_cycle_counter_count; |
| 56 | |
| 57 | size_t max_events_; |
| 58 | Backend backend; |
| 59 | int32_t event_id; |
Kristofer Jonsson | 44d6e22 | 2021-05-21 18:59:18 +0200 | [diff] [blame] | 60 | size_t num_events_; |
Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 61 | |
Jens Elofsson | 955288a | 2021-04-22 20:57:15 +0200 | [diff] [blame] | 62 | TF_LITE_REMOVE_VIRTUAL_DELETE; |
| 63 | }; |
| 64 | |
| 65 | } // namespace tflite |
| 66 | |
| 67 | #endif |