From de044c3032917dd952de1eb441572c1435841b33 Mon Sep 17 00:00:00 2001 From: Jens Elofsson Date: Thu, 6 May 2021 16:21:29 +0200 Subject: Remove the PMU event register handling from EthosuProfiler. Change-Id: I8d303043806e081238067e5773e4d4125bc64cfa --- .../inference_process/src/inference_process.cpp | 19 +----- lib/ethosu_profiler/include/ethosu_profiler.hpp | 16 +---- lib/ethosu_profiler/src/ethosu_profiler.cpp | 68 +++------------------- 3 files changed, 13 insertions(+), 90 deletions(-) diff --git a/applications/inference_process/src/inference_process.cpp b/applications/inference_process/src/inference_process.cpp index fa38290..009706e 100644 --- a/applications/inference_process/src/inference_process.cpp +++ b/applications/inference_process/src/inference_process.cpp @@ -112,11 +112,7 @@ InferenceJob::InferenceJob(const string &_name, name(_name), networkModel(_networkModel), input(_input), output(_output), expectedOutput(_expectedOutput), numBytesToPrint(_numBytesToPrint), pmuEventConfig(_pmuEventConfig), pmuCycleCounterEnable(_pmuCycleCounterEnable), - pmuEventCount(), pmuCycleCounterCount(0) { -#if defined(INFERENCE_PROC_TFLU_PROFILER) && defined(ETHOSU) - pmuEventCount = vector(ETHOSU_PMU_NCOUNTERS, 0); -#endif -} + pmuEventCount(), pmuCycleCounterCount(0) {} void InferenceJob::invalidate() { networkModel.invalidate(); @@ -206,15 +202,11 @@ bool InferenceProcess::runJob(InferenceJob &job) { // Create the TFL micro interpreter tflite::AllOpsResolver resolver; #ifdef ETHOSU - vector pmu_events(ETHOSU_PMU_NCOUNTERS, ETHOSU_PMU_NO_EVENT); - - for (size_t i = 0; i < job.pmuEventConfig.size(); i++) { - pmu_events[i] = ethosu_pmu_event_type(job.pmuEventConfig[i]); - } - tflite::EthosUProfiler profiler(pmu_events[0], pmu_events[1], pmu_events[2], pmu_events[3]); + tflite::EthosUProfiler profiler; #else tflite::ArmProfiler profiler; #endif + tflite::MicroInterpreter interpreter(model, resolver, tensorArena, tensorArenaSize, reporter, &profiler); // Allocate tensors @@ -273,11 +265,6 @@ bool InferenceProcess::runJob(InferenceJob &job) { job.pmuCycleCounterCount = profiler.GetTotalTicks(); } -#ifdef ETHOSU - for (uint32_t i = 0; i < ETHOSU_PMU_NCOUNTERS; i++) { - job.pmuEventCount[i] = profiler.GetEthosuPMUCounter(i); - } -#endif #endif // Copy output data diff --git a/lib/ethosu_profiler/include/ethosu_profiler.hpp b/lib/ethosu_profiler/include/ethosu_profiler.hpp index 745c670..503ebba 100644 --- a/lib/ethosu_profiler/include/ethosu_profiler.hpp +++ b/lib/ethosu_profiler/include/ethosu_profiler.hpp @@ -28,23 +28,13 @@ namespace tflite { class EthosUProfiler : public MicroProfiler { public: - EthosUProfiler(ethosu_pmu_event_type event0 = ETHOSU_PMU_NO_EVENT, - ethosu_pmu_event_type event1 = ETHOSU_PMU_NO_EVENT, - ethosu_pmu_event_type event2 = ETHOSU_PMU_NO_EVENT, - ethosu_pmu_event_type event3 = ETHOSU_PMU_NO_EVENT, - size_t max_events = 200); + EthosUProfiler(size_t max_events = 200); uint32_t BeginEvent(const char *tag); void EndEvent(uint32_t event_handle); uint64_t GetTotalTicks() const; void Log() const; - uint32_t GetEthosuPMUCounter(int counter); private: - void MonitorEthosuPMUEvents(ethosu_pmu_event_type event0, - ethosu_pmu_event_type event1, - ethosu_pmu_event_type event2, - ethosu_pmu_event_type event3); - size_t max_events_; std::unique_ptr tags_; std::unique_ptr start_ticks_; @@ -52,10 +42,6 @@ private: int num_events_ = 0; - ethosu_pmu_event_type ethosu_pmu_cntrs[ETHOSU_PMU_NCOUNTERS]; - - uint32_t event_counters[ETHOSU_PMU_NCOUNTERS]; - TF_LITE_REMOVE_VIRTUAL_DELETE; }; diff --git a/lib/ethosu_profiler/src/ethosu_profiler.cpp b/lib/ethosu_profiler/src/ethosu_profiler.cpp index c69e6f8..9ddea13 100644 --- a/lib/ethosu_profiler/src/ethosu_profiler.cpp +++ b/lib/ethosu_profiler/src/ethosu_profiler.cpp @@ -34,42 +34,19 @@ uint64_t GetCurrentEthosuTicks(struct ethosu_driver *drv) { return ETHOSU_PMU_Get_CCNTR_v2(drv); } -void InitEthosuPMUCounters(struct ethosu_driver *drv, ethosu_pmu_event_type *ethosu_pmu_cntrs) { - ETHOSU_PMU_Enable_v2(drv); - - ETHOSU_PMU_CNTR_Enable_v2(drv, - ETHOSU_PMU_CNT1_Msk | ETHOSU_PMU_CNT2_Msk | ETHOSU_PMU_CNT3_Msk | ETHOSU_PMU_CNT4_Msk | - ETHOSU_PMU_CCNT_Msk); - - for (int i = 0; i < ETHOSU_PMU_NCOUNTERS; i++) { - ETHOSU_PMU_Set_EVTYPER_v2(drv, i, ethosu_pmu_cntrs[i]); - } - - ETHOSU_PMU_EVCNTR_ALL_Reset_v2(drv); -} - -uint32_t GetEthosuPMUEventCounter(struct ethosu_driver *drv, int counter) { - return ETHOSU_PMU_Get_EVCNTR_v2(drv, counter); -} } // namespace namespace tflite { -EthosUProfiler::EthosUProfiler(ethosu_pmu_event_type event0, - ethosu_pmu_event_type event1, - ethosu_pmu_event_type event2, - ethosu_pmu_event_type event3, - size_t max_events) : - max_events_(max_events) { +EthosUProfiler::EthosUProfiler(size_t max_events) : max_events_(max_events) { tags_ = std::make_unique(max_events_); start_ticks_ = std::make_unique(max_events_); end_ticks_ = std::make_unique(max_events_); - for (size_t i = 0; i < ETHOSU_PMU_NCOUNTERS; i++) { - event_counters[i] = 0; - } - - MonitorEthosuPMUEvents(event0, event1, event2, event3); + struct ethosu_driver *drv = ethosu_reserve_driver(); + ETHOSU_PMU_CNTR_Enable_v2(drv, ETHOSU_PMU_CCNT_Msk); + ETHOSU_PMU_CYCCNT_Reset_v2(drv); + ethosu_release_driver(drv); } // NOTE: THIS PROFILER ONLY WORKS ON SYSTEMS WITH 1 NPU @@ -87,7 +64,6 @@ uint32_t EthosUProfiler::BeginEvent(const char *tag) { ETHOSU_PMU_PMCCNTR_CFG_Set_Start_Event_v2(ethosu_drv, ETHOSU_PMU_NPU_ACTIVE); ETHOSU_PMU_PMCCNTR_CFG_Set_Stop_Event_v2(ethosu_drv, ETHOSU_PMU_NPU_IDLE); start_ticks_[num_events_] = GetCurrentEthosuTicks(ethosu_drv); - InitEthosuPMUCounters(ethosu_drv, ethosu_pmu_cntrs); ethosu_release_driver(ethosu_drv); } else { start_ticks_[num_events_] = GetCurrentTimeTicks(); @@ -104,26 +80,14 @@ void EthosUProfiler::EndEvent(uint32_t event_handle) { if (strcmp("ethos-u", tags_[event_handle]) == 0) { struct ethosu_driver *ethosu_drv = ethosu_reserve_driver(); end_ticks_[event_handle] = GetCurrentEthosuTicks(ethosu_drv); - uint32_t ethosu_pmu_counter_end[ETHOSU_PMU_NCOUNTERS]; - ETHOSU_PMU_Disable_v2(ethosu_drv); - for (size_t i = 0; i < ETHOSU_PMU_NCOUNTERS; i++) { - ethosu_pmu_counter_end[i] = GetEthosuPMUEventCounter(ethosu_drv, i); - tflite::GetMicroErrorReporter()->Report( - "%s : ethosu_pmu_cntr%d : %u", tags_[event_handle], i, ethosu_pmu_counter_end[i]); - - event_counters[i] += ethosu_pmu_counter_end[i]; - } ethosu_release_driver(ethosu_drv); - printf("%s : cycle_cnt : %" PRIu64 " cycles\n", - tags_[event_handle], - end_ticks_[event_handle] - start_ticks_[event_handle]); - } else { end_ticks_[event_handle] = GetCurrentTimeTicks(); - printf("%s : cycle_cnt : %" PRIu64 " cycles\n", - tags_[event_handle], - end_ticks_[event_handle] - start_ticks_[event_handle]); } + + printf("%s : cycle_cnt : %" PRIu64 " cycles\n", + tags_[event_handle], + end_ticks_[event_handle] - start_ticks_[event_handle]); } uint64_t EthosUProfiler::GetTotalTicks() const { @@ -144,18 +108,4 @@ void EthosUProfiler::Log() const { #endif } -void EthosUProfiler::MonitorEthosuPMUEvents(ethosu_pmu_event_type event0, - ethosu_pmu_event_type event1, - ethosu_pmu_event_type event2, - ethosu_pmu_event_type event3) { - ethosu_pmu_cntrs[0] = event0; - ethosu_pmu_cntrs[1] = event1; - ethosu_pmu_cntrs[2] = event2; - ethosu_pmu_cntrs[3] = event3; -} - -uint32_t EthosUProfiler::GetEthosuPMUCounter(int counter) { - return event_counters[counter]; -} - } // namespace tflite -- cgit v1.2.1