From 8b1d9ded33ec59545897ff45019d05403dba7eee Mon Sep 17 00:00:00 2001 From: Jens Elofsson Date: Thu, 27 May 2021 16:03:20 +0200 Subject: README for the Ethos-U Monitor. Change-Id: I17b9c0d176e1f2532661107381d641c970e63f3c --- lib/ethosu_monitor/README.md | 76 ++++++++++++++++++++++ .../docs/ethosu_monitor_example_usage.puml | 61 +++++++++++++++++ .../docs/ethosu_monitor_example_usage.svg | 74 +++++++++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 lib/ethosu_monitor/README.md create mode 100644 lib/ethosu_monitor/docs/ethosu_monitor_example_usage.puml create mode 100644 lib/ethosu_monitor/docs/ethosu_monitor_example_usage.svg diff --git a/lib/ethosu_monitor/README.md b/lib/ethosu_monitor/README.md new file mode 100644 index 0000000..98230ef --- /dev/null +++ b/lib/ethosu_monitor/README.md @@ -0,0 +1,76 @@ +# Arm(R) Ethos(TM)-U Monitor + +Ethos-U monitor is a library that provides an example of how to extract the +values of the PMU registers on the Arm Ethos-U55 NPU during an ongoing +inference, using an arbitrary timer source to trigger interrupts at a set +interval. It implements two backends, +[EventRecorder](https://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html) +and printf. An example application showing how to use Ethos-U monitor is +included. + +## Usage +When the Ethos-U monitor constructor is called, the user specifies which backend +to use, as well as the +[```EventIDs```](https://www.keil.com/pack/doc/compiler/EventRecorder/html/group__EventRecorder__Data.html#ga44fa52e2007e535753fd4ba59b84d55d) +for the EventRecorder entries. In the second step, ``configure`` is used to +configure which PMU registers that is to be recorded. A list of available PMU +registers can be found in [pmu_ethosu.h](https://git.mlplatform.org/ml/ethos-u/ethos-u-core-driver.git/tree/include/pmu_ethosu.h?h=21.05-rc3#n55) +in the core-driver repository. ```monitorSample``` is then used to record the +values of the registers on the selected backend. Lastly, ```release``` +disables the PMU. + +### Functions +| Function name | Description | +| ----------- | ----------- | +|```EthosUMonitor(eventRecordIds, backend)``` | ```eventRecordIds``` lists the [```EventIDs```](https://www.keil.com/pack/doc/compiler/EventRecorder/html/group__EventRecorder__Data.html#ga44fa52e2007e535753fd4ba59b84d55d) that will be associated with the list of PMU registers configured in ```configure``` when using ```EVENT_RECORDER``` as backend.
```backend``` describes which backend to use, and can be either ```PRINTF``` or ```EVENT_RECORDER``` | +|```configure(driver, eventIds)``` | Configures the PMU to monitor the PMU registers listed in ```eventIds```. The maximum number of PMU registers to monitor is 4.| +| ```release(driver)``` | Disables the PMU. | +|```monitorSample(driver)``` | Samples the PMU registers configured in ```configure``` and logs them using the selected backend. | + +### Example +An example on how to use Ethos-U monitor can be found in the +[baremetal](https://git.mlplatform.org/ml/ethos-u/ethos-u-core-platform.git/tree/applications/baremetal/main.cpp?id=afadfc1ccb22fee7463c0f7b4daf467dabe98534) +application in the [ethosu-core-platform](https://git.mlplatform.org/ml/ethos-u/ethos-u-core-platform.git) repository. + +The functions ```ethosu_inference_begin``` and ```ethosu_inference_end``` are +defined as weak symbols in +[ethosu_driver.c](https://git.mlplatform.org/ml/ethos-u/ethos-u-core-driver.git/tree/src/ethosu_driver.c?h=21.05-rc3#n265). + + They are called by the Ethos-U driver before and after the Ethos-U custom + operator is executed. In the + [example application](https://git.mlplatform.org/ml/ethos-u/ethos-u-core-platform.git/tree/applications/baremetal/main.cpp?id=afadfc1ccb22fee7463c0f7b4daf467dabe98534) + a timer source is configured to periodically trigger an interrupt, on which the + the configured PMU registers are sampled one by one and recorded using + [EventRecorder](https://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html) + as backend. Note that the events in this example are logged from an interrupt + context which will impact the execution time. + + Below is a sequence diagram showing a simplified version of how the different + components interact. + +![ethosu monitor](docs/ethosu_monitor_example_usage.svg "ethosu monitor sequence diagram"). + +### Output format +#### EventRecorder +For each of the configured PMU registers, an event is recorded using the +[EventRecord2](https://www.keil.com/pack/doc/compiler/EventRecorder/html/group__EventRecorder__Data.html#gab91eb760432ad0a10652a2c922db9566) +function. Each event consists of two int32-values and an id. + +In the example application, the following PMU registers are recorded: +| EventID | Value 1 | Value 2 | +| ------- | ------- | ------- | +| Id1 | ETHOSU_PMU_CYCLE | Register value | +| Id2 | ETHOSU_PMU_NPU_ACTIVE | Register value | + +```Id1``` and ```Id2``` are defined by the ```eventRecordIds``` parameter in the +constructor of Ethos-U monitor. ```Value 1``` is the PMU register number, as +represented by the [ethosu_pmu_event_type enum](https://git.mlplatform.org/ml/ethos-u/ethos-u-core-driver.git/tree/include/pmu_ethosu.h?h=21.05-rc3#n55). +```Value 2``` is the value of the PMU register when read by the +```monitorSample``` function. + +#### printf +When using +```printf``` the register values are printed on the format +```ethosu_pmu_cntr : ```, where ```counter_no``` is +the index (0-3) of the configured PMU register, and ```register_value``` is the +value of the PMU register. diff --git a/lib/ethosu_monitor/docs/ethosu_monitor_example_usage.puml b/lib/ethosu_monitor/docs/ethosu_monitor_example_usage.puml new file mode 100644 index 0000000..868ac4d --- /dev/null +++ b/lib/ethosu_monitor/docs/ethosu_monitor_example_usage.puml @@ -0,0 +1,61 @@ +@startuml +skinparam backgroundColor #FEFEFE + +box "Application" #Orange +participant "Application" as app +end box + +box "PMU monitor" #Orange +participant "PMU monitor" as pmumon +end box + +box "Tensorflow" #LightGreen +participant "TFLu" as tflu +end box + +box "Ethos-U" #LightBlue +participant "Ethos-U driver" as driver +end box + +box "EventRecorder" #LightBlue +participant EventRecorder as event +end box + +box "Timer source" +participant "Timer source" as timer +end box + +app -> event: EventRecorderInitialize() + +app -> tflu: Invoke() +tflu -> driver: ethosu_invoke() + +driver -> app ++: ethosu_inference_begin(inference data, driver) [weak] +app -> pmumon: ethosu_monitor.configure() +pmumon -> driver: 'Configure PMU' +pmumon -> timer: Enable timer events +return + +group While the Ethos-U custom op is executing +group Recurrent: PMU-monitor log events + ... + timer -> app++: Timer event + app -> pmumon: ethosu_monitor.monitorSample() + pmumon -> driver: 'Sample PMU registers' + driver --> pmumon + pmumon -> event : EventRecord2() +... +end +end + +driver -> app++: ethosu_inference_end(inference data, driver) [weak] +app -> timer: 'Disable timer events' +app -> pmumon: ethosu_monitor.monitorSample() +pmumon -> driver: 'Sample PMU registers' +driver --> pmumon +pmumon -> event : EventRecord2() +app -> pmumon: ethosu_monitor.release() +pmumon -> driver: 'Disable PMU' +return + +@enduml diff --git a/lib/ethosu_monitor/docs/ethosu_monitor_example_usage.svg b/lib/ethosu_monitor/docs/ethosu_monitor_example_usage.svg new file mode 100644 index 0000000..42ba808 --- /dev/null +++ b/lib/ethosu_monitor/docs/ethosu_monitor_example_usage.svg @@ -0,0 +1,74 @@ +ApplicationPMU monitorTensorflowEthos-UEventRecorderTimer sourceApplicationApplicationPMU monitorPMU monitorTFLuTFLuEthos-U driverEthos-U driverEventRecorderEventRecorderTimer sourceTimer sourceEventRecorderInitialize()Invoke()ethosu_invoke()ethosu_inference_begin(inference data, driver) [weak]ethosu_monitor.configure()'Configure PMU'Enable timer eventsWhile the Ethos-U custom op is executingRecurrent: PMU-monitor log eventsTimer eventethosu_monitor.monitorSample()'Sample PMU registers'EventRecord2()ethosu_inference_end(inference data, driver) [weak]'Disable timer events'ethosu_monitor.monitorSample()'Sample PMU registers'EventRecord2()ethosu_monitor.release()'Disable PMU' \ No newline at end of file -- cgit v1.2.1