diff options
author | Jens Elofsson <jens.elofsson@arm.com> | 2021-05-23 17:37:07 +0200 |
---|---|---|
committer | Måns Nilsson <mans.nilsson@arm.com> | 2021-05-27 15:50:35 +0200 |
commit | 701a63b693bc877fc44abd802a9b2a431d81cfbe (patch) | |
tree | 5cfe3fb1c63b083b749c61af25c3b39e6a314907 /lib | |
parent | 036d1a89dffa4628f8d5b9a5b44ba9673ca2e3b4 (diff) | |
download | ethos-u-core-software-701a63b693bc877fc44abd802a9b2a431d81cfbe.tar.gz |
Add Event Recorder Profiling
* Add event recorded profiling to ethosu_profiler.
* Rename ethosu_profiler to layer_by_layer_profiler.
Change-Id: Ie39c29845b2d1eb6d9d72e3fce68bf373e9dc888
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CMakeLists.txt | 5 | ||||
-rw-r--r-- | lib/layer_by_layer_profiler/CMakeLists.txt (renamed from lib/ethosu_profiler/CMakeLists.txt) | 8 | ||||
-rw-r--r-- | lib/layer_by_layer_profiler/include/layer_by_layer_profiler.hpp (renamed from lib/ethosu_profiler/include/ethosu_profiler.hpp) | 15 | ||||
-rw-r--r-- | lib/layer_by_layer_profiler/src/layer_by_layer_profiler.cpp (renamed from lib/ethosu_profiler/src/ethosu_profiler.cpp) | 33 | ||||
-rw-r--r-- | lib/rte_component/include/RTE_Components.h (renamed from lib/ethosu_monitor/include/RTE_Components.h) | 3 |
5 files changed, 40 insertions, 24 deletions
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index ae18806..5536949 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -16,12 +16,11 @@ # limitations under the License. # -# Build ethosu_profiler -add_subdirectory(ethosu_profiler) +# Build layer_by_layer_profiler +add_subdirectory(layer_by_layer_profiler) # Build arm_profiler add_subdirectory(arm_profiler) # Build ethosu_monitor add_subdirectory(ethosu_monitor) - diff --git a/lib/ethosu_profiler/CMakeLists.txt b/lib/layer_by_layer_profiler/CMakeLists.txt index 336a696..9774685 100644 --- a/lib/ethosu_profiler/CMakeLists.txt +++ b/lib/layer_by_layer_profiler/CMakeLists.txt @@ -19,8 +19,8 @@ if (NOT TARGET ethosu_core_driver) return() endif() -add_library(ethosu_profiler INTERFACE) -target_link_libraries(ethosu_profiler INTERFACE ethosu_core_driver tflu) -target_include_directories(ethosu_profiler INTERFACE include) -target_sources(ethosu_profiler INTERFACE src/ethosu_profiler.cpp) +add_library(layer_by_layer_profiler INTERFACE) +target_link_libraries(layer_by_layer_profiler INTERFACE ethosu_core_driver tflu event_recorder) +target_include_directories(layer_by_layer_profiler INTERFACE include) +target_sources(layer_by_layer_profiler INTERFACE src/layer_by_layer_profiler.cpp) diff --git a/lib/ethosu_profiler/include/ethosu_profiler.hpp b/lib/layer_by_layer_profiler/include/layer_by_layer_profiler.hpp index 12c337c..8e8dc0f 100644 --- a/lib/ethosu_profiler/include/ethosu_profiler.hpp +++ b/lib/layer_by_layer_profiler/include/layer_by_layer_profiler.hpp @@ -16,9 +16,10 @@ * limitations under the License. */ -#ifndef ETHOSU_PROFILER_H -#define ETHOSU_PROFILER_H +#ifndef LAYER_BY_LAYER_PROFILER_H +#define LAYER_BY_LAYER_PROFILER_H +#include "EventRecorder.h" #include "tensorflow/lite/kernels/internal/compatibility.h" #include <memory> #include <pmu_ethosu.h> @@ -26,9 +27,12 @@ // NOTE: This profiler only works on systems with 1 NPU due to the use of // ethosu_reserve_driver(). namespace tflite { -class EthosUProfiler : public MicroProfiler { +class LayerByLayerProfiler : public MicroProfiler { public: - EthosUProfiler(size_t max_events = 200); + enum Backend { PRINTF, EVENT_RECORDER }; + LayerByLayerProfiler(size_t max_events = 200, + Backend backend = PRINTF, + int32_t event_id = EventID(EventLevelError, EvtStatistics_No, EventRecordNone)); uint32_t BeginEvent(const char *tag); void EndEvent(uint32_t event_handle); uint64_t GetTotalTicks() const; @@ -39,6 +43,9 @@ private: std::unique_ptr<const char *[]> tags_; std::unique_ptr<uint64_t[]> start_ticks_; std::unique_ptr<uint64_t[]> end_ticks_; + + Backend backend_; + int32_t event_id_; size_t num_events_; TF_LITE_REMOVE_VIRTUAL_DELETE; diff --git a/lib/ethosu_profiler/src/ethosu_profiler.cpp b/lib/layer_by_layer_profiler/src/layer_by_layer_profiler.cpp index 50b65f0..f7922cb 100644 --- a/lib/ethosu_profiler/src/ethosu_profiler.cpp +++ b/lib/layer_by_layer_profiler/src/layer_by_layer_profiler.cpp @@ -23,7 +23,7 @@ #include <string.h> -#include "ethosu_profiler.hpp" +#include "layer_by_layer_profiler.hpp" #include <ethosu_driver.h> #include <inttypes.h> #include <stdio.h> @@ -38,7 +38,9 @@ uint64_t GetCurrentEthosuTicks(struct ethosu_driver *drv) { namespace tflite { -EthosUProfiler::EthosUProfiler(size_t max_events) : max_events_(max_events), num_events_(0) { +LayerByLayerProfiler::LayerByLayerProfiler(size_t max_events, Backend backend, int32_t event_id) : + max_events_(max_events), backend_(backend), event_id_(event_id), num_events_(0) { + tags_ = std::make_unique<const char *[]>(max_events_); start_ticks_ = std::make_unique<uint64_t[]>(max_events_); end_ticks_ = std::make_unique<uint64_t[]>(max_events_); @@ -50,7 +52,7 @@ EthosUProfiler::EthosUProfiler(size_t max_events) : max_events_(max_events), num } // NOTE: THIS PROFILER ONLY WORKS ON SYSTEMS WITH 1 NPU -uint32_t EthosUProfiler::BeginEvent(const char *tag) { +uint32_t LayerByLayerProfiler::BeginEvent(const char *tag) { if (num_events_ == max_events_) { tflite::GetMicroErrorReporter()->Report("Profiling event overflow, max: %u events", max_events_); num_events_ = 0; @@ -74,7 +76,7 @@ uint32_t EthosUProfiler::BeginEvent(const char *tag) { } // NOTE: THIS PROFILER ONLY WORKS ON SYSTEMS WITH 1 NPU -void EthosUProfiler::EndEvent(uint32_t event_handle) { +void LayerByLayerProfiler::EndEvent(uint32_t event_handle) { TFLITE_DCHECK(event_handle < max_events_); if (strcmp("ethos-u", tags_[event_handle]) == 0) { @@ -85,12 +87,16 @@ void EthosUProfiler::EndEvent(uint32_t event_handle) { end_ticks_[event_handle] = GetCurrentTimeTicks(); } - printf("%s : cycle_cnt : %" PRIu64 " cycles\n", - tags_[event_handle], - end_ticks_[event_handle] - start_ticks_[event_handle]); + if (backend_ == PRINTF) { + printf("%s : cycle_cnt : %" PRIu64 " cycles\n", + tags_[event_handle], + end_ticks_[event_handle] - start_ticks_[event_handle]); + } else { + EventRecord2(event_id_, (int32_t)event_handle, end_ticks_[event_handle] - start_ticks_[event_handle]); + } } -uint64_t EthosUProfiler::GetTotalTicks() const { +uint64_t LayerByLayerProfiler::GetTotalTicks() const { uint64_t ticks = 0; for (size_t i = 0; i < num_events_; ++i) { @@ -100,11 +106,14 @@ uint64_t EthosUProfiler::GetTotalTicks() const { return ticks; } -void EthosUProfiler::Log() const { +void LayerByLayerProfiler::Log() const { + #if !defined(TF_LITE_STRIP_ERROR_STRINGS) - for (int i = 0; i < num_events_; ++i) { - uint64_t ticks = end_ticks_[i] - start_ticks_[i]; - printf("%s took %" PRIu64 " cycles\n", tags_[i], ticks); + if (backend_ == PRINTF) { + for (size_t i = 0; i < num_events_; ++i) { + uint64_t ticks = end_ticks_[i] - start_ticks_[i]; + printf("%s took %" PRIu64 " cycles\n", tags_[i], ticks); + } } #endif } diff --git a/lib/ethosu_monitor/include/RTE_Components.h b/lib/rte_component/include/RTE_Components.h index 97b6624..024f52b 100644 --- a/lib/ethosu_monitor/include/RTE_Components.h +++ b/lib/rte_component/include/RTE_Components.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Arm Limited. All rights reserved. + * Copyright (c) 2020-2021 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef RTE_COMPONENTS_H #define RTE_COMPONENTS_H |