Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated MLEK to Corstone-320 and removed AVH #1529

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ title: Build and run the Arm Machine Learning Evaluation Kit examples

minutes_to_complete: 30

who_is_this_for: This is an introductory topic for embedded software developers interested in learning about machine learning.
who_is_this_for: This is an introductory topic for embedded software developers interested machine learning applications.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interested in machine learning applications

"in" is missing here


learning_objectives:
- Build examples from Machine Learning Evaluation Kit (MLEK)
- Run the examples on Corstone-320 FVP or Virtual Hardware
- Run the examples on Arm Ecosystem FVP

prerequisites:
- Some familiarity with embedded programming
- Either a Linux machine running Ubuntu, or an AWS account to use [Arm Virtual Hardware](https://www.arm.com/products/development-tools/simulation/virtual-hardware)
- Linux host machine running Ubuntu
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Linux host machine...


author_primary: Ronan Synnott

### RS: Learning Path hidden until AWS instance updated
draft: true
draft: false
cascade:
draft: true
draft: false


### Tags
Expand Down
75 changes: 14 additions & 61 deletions content/learning-paths/embedded-and-microcontrollers/mlek/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ You can use the MLEK source code to build sample applications and run them on th

## Before you begin

You can use your own Ubuntu Linux host machine or use [Arm Virtual Hardware (AVH)](https://www.arm.com/products/development-tools/simulation/virtual-hardware) for this Learning Path.

The Ubuntu version should be 20.04 or 22.04. These instructions have been tested on the `x86_64` architecture. You will need a way to interact visually with your machine to run the FVP, because it opens graphical windows for input and output from the software applications.

If you want to use Arm Virtual Hardware the [Arm Virtual Hardware install guide](/install-guides/avh#corstone) provides setup instructions.
It is recommended to use an Ubuntu Linux host machine. The Ubuntu version should be 20.04 or 22.04. These instructions have been tested on the `x86_64` architecture.

## Build the example application

Expand Down Expand Up @@ -52,9 +48,6 @@ You can review the installation guides for further details.

{{% /notice %}}


Both compilers are pre-installed in Arm Virtual Hardware.

### Clone the repository

Clone the ML Evaluation Kit repository, and navigate into the new directory:
Expand All @@ -69,76 +62,36 @@ git submodule update --init

The default build is Ethos-U55 and Corstone-300. The default build for Ethos-U85 is Corstone-320. Use the `npu-config-name` flag to set Ethos-U85.

The default compiler is `gcc`, but `armclang` can also be used. Number after `ethos-u85-*` is number of MACs, 128-2048 (2^n).
The default compiler is `gcc`, but `armclang` can also be used. Number after `ethos-u85-*` is the number of MACs, 128-2048 (2^n).

Use `--make-jobs` to specify `make -j` value.

You can select either compiler to build applications. You can also try them both and compare the results.

- Build with Arm GNU Toolchain (`gcc`)
- Build with Arm GNU Toolchain (`gcc`):

```
./build_default.py --npu-config-name ethos-u85-256 --toolchain gnu
./build_default.py --npu-config-name ethos-u85-256 --toolchain gnu --make-jobs 8
```

- Build with Arm Compiler for Embedded (`armclang`)
- Build with Arm Compiler for Embedded (`armclang`):

```console
./build_default.py --npu-config-name ethos-u85-256 --toolchain arm
```

The build will take a few minutes.

When the build is complete, you will find the examples (`.axf` files) in the `cmake-build-*/bin` directory. The `cmake-build` directory names are specific to the compiler used and Ethos-U85 configuration. Verify that the files have been created by observing the output of the `ls` command

```bash
ls cmake-build-mps4-sse-320-ethos-u85-256-gnu/bin/
./build_default.py --npu-config-name ethos-u85-256 --toolchain arm --make-jobs 8
```

The next step is to install the FVP and run it with these example audio clips.


## Corstone-320 FVP {#fvp}

This section describes installation of the Corstone-320 to run on your local machine. If you are using Arm Virtual Hardware, that comes with the Corstone-300 FVP pre-installed, and you can move on to the next section. You can review Arm's full FVP offer and general installation steps in the [Fast Model and Fixed Virtual Platform](/install-guides/fm_fvp) install guides.
{{% notice Tip %}}
Use `./build_default.py --help` for additional information.

{{% notice Note %}}
The rest of the steps for the Corstone-320 need to be run in a new terminal window.
{{% /notice %}}

Open a **new terminal window** and download the Corstone-320 archive.

```bash
cd $HOME
wget https://developer.arm.com/-/cdn-downloads/permalink/FVPs-Corstone-IoT/Corstone-320/FVP_Corstone_SSE-320_11.27_25_Linux64.tgz
```

Unpack it with `tar`, run the setup script and export the binary paths to the `PATH` environment variable.

```bash
tar -xf FVP_Corstone_SSE-320_11.27_25_Linux64.tgz
./FVP_Corstone_SSE-320.sh --i-agree-to-the-contained-eula --no-interactive -q
export PATH=$HOME/FVP_Corstone_SSE-320/models/Linux64_GCC-9.3:$PATH
```

The FVP requires an additional dependency, `libpython3.9.so.1.0`, which can be installed using a script. Note that this will tinkle with the python installation for the current terminal window, so make sure to open a new one for the next step.

```bash
source $HOME/FVP_Corstone_SSE-320/scripts/runtime.sh
```
The build will take a few minutes.

Verify that the FVP was successfully installed by comparing your output from below command.
When the build is complete, you will find the examples (`.axf` files) in the `cmake-build-*/bin` directory. The `cmake-build` directory names are specific to the compiler used and Ethos-U85 configuration. Verify that the files have been created by observing the output of the `ls` command

```bash
FVP_Corstone_SSE-320
```

```output
telnetterminal0: Listening for serial connection on port 5000
telnetterminal1: Listening for serial connection on port 5001
telnetterminal2: Listening for serial connection on port 5002
telnetterminal5: Listening for serial connection on port 5003

ls cmake-build-mps4-sse-320-ethos-u85-256-gnu/bin/
```


Now you are ready to test the application with the FVP.
The next step is to install the FVP and run the built example applications.

70 changes: 70 additions & 0 deletions content/learning-paths/embedded-and-microcontrollers/mlek/fvp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
# User change
title: "Install Arm Ecosystem FVP"

weight: 3 # 1 is first, 2 is second, etc.

# Do not modify these elements
layout: "learningpathall"
---
## Corstone-320 FVP {#fvp}

This section describes installation of the [Corstone-320 FVP](https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms/IoT%20FVPs) to run on your local machine. Similar instructions would apply for other platforms.

Arm provides a selection of free to use Fixed Virtual Platforms (FVPs) that can be downloaded from the [Arm Developer](https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms#Downloads) website.

You can review Arm's full FVP offering and general installation steps in the [Fast Model and Fixed Virtual Platform](/install-guides/fm_fvp) install guide.

{{% notice Note %}}
It is recommended to perform these steps in a new terminal window.
{{% /notice %}}

Download the Corstone-320 Ecosystem FVP archive:

```bash
cd $HOME
wget https://developer.arm.com/-/cdn-downloads/permalink/FVPs-Corstone-IoT/Corstone-320/FVP_Corstone_SSE-320_11.27_25_Linux64.tgz
```

Unpack it with `tar`, run the installation script, and add the path to the FVP executable to the `PATH` environment variable.

```bash
tar -xf FVP_Corstone_SSE-320_11.27_25_Linux64.tgz

./FVP_Corstone_SSE-320.sh --i-agree-to-the-contained-eula --no-interactive -q

export PATH=$HOME/FVP_Corstone_SSE-320/models/Linux64_GCC-9.3:$PATH
```

The FVP requires an additional dependency, `libpython3.9.so.1.0`, which can be installed using a supplied script.

```bash
source $HOME/FVP_Corstone_SSE-320/scripts/runtime.sh
```

Run the executable:

```bash
FVP_Corstone_SSE-320
```

You will observe output similar to the following:

```output
telnetterminal0: Listening for serial connection on port 5000
telnetterminal1: Listening for serial connection on port 5001
telnetterminal2: Listening for serial connection on port 5002
telnetterminal5: Listening for serial connection on port 5003
```

If you encounter graphics driver errors, you can disable the development board and LCD visualization with additional command options:

```bash
FVP_Corstone_SSE-320 \
-C mps4_board.visualisation.disable-visualisation=1 \
-C vis_hdlcd.disable_visualisation=1
```

Stop the executable with `Ctrl+C`.

Now you are ready to run the MLEK applications on the FVP.
122 changes: 63 additions & 59 deletions content/learning-paths/embedded-and-microcontrollers/mlek/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,32 @@
# User change
title: "Run the examples on the FVP"

weight: 3 # 1 is first, 2 is second, etc.
weight: 4 # 1 is first, 2 is second, etc.

# Do not modify these elements
layout: "learningpathall"
---
## Run an example

Now you are ready to combine the FVP installation and the example application. Navigate to the evaluation kit repository.
Navigate to the evaluation kit repository.

```bash
cd ml-embedded-evaluation-kit/
```

To run an example on the Corstone-320 FVP target, launch the FVP executable with `-a` to specify the software application.
The built examples (`.axf` files) will be located in a `cmake-*/bin` folder based on the build configuration used.

To run the key word spotting example `ethos-u-kws.axf` compiled with `gcc` use one of the two options below.
Navigate into that folder, and list the images. For example:

## Option 1: On your computer with the FVP installed
```bash
cd cmake-build-mps4-sse-320-ethos-u85-256-gnu/bin/

ls *.axf
```

Run the FVP.
Use `-a` to specify the application to load to the FVP.

```console
FVP_Corstone_SSE-320 \
-C mps4_board.subsystem.ethosu.num_macs=256 \
-C mps4_board.visualisation.disable-visualisation=1 \
-C vis_hdlcd.disable_visualisation=1 \
-a cmake-build-mps4-sse-320-ethos-u85-256-gnu/bin/ethos-u-kws.axf
```
Use `-C mps4_board.subsystem.ethosu.num_macs` to configure the Ethos-U component of the model.

{{% notice Note %}}
The number of NPU MACs specified in the build MUST match the number specified in the FVP. Else an error similar to the below will be emitted.
Expand All @@ -39,81 +37,87 @@ E: NPU config mismatch. npu.macs_per_cc=E: NPU config mismatch..
```
{{% /notice %}}

## Option 2: On Arm Virtual Hardware
You can list all available parameters by running the FVP executable with the `--list-params` option, for example:

```console
VHT_Corstone_SSE-300_Ethos-U55 -a cmake-build-mps3-sse-300-ethos-u55-128-gnu/bin/ethos-u-kws.axf
FVP_Corstone_SSE-320 --list-params > parameters.txt
```
When the example is running, a telnet instance will open allowing you to interact with the example.

{{% notice Note %}}
It may take some time to initialize the terminal, please be patient.

If you see warnings regarding loading the image, these can likely be ignored.
{{% /notice %}}
### Run the application

## Interact with the application
```console
FVP_Corstone_SSE-320 \
-C mps4_board.subsystem.ethosu.num_macs=256 \
-C mps4_board.visualisation.disable-visualisation=1 \
-C vis_hdlcd.disable_visualisation=1 \
-a ethos-u-kws.axf
```

Use the menu to control the application. For the key word spotting application enter 1 to classify the next audio clip.
If adding configuration options becomes cumbersome, it can be easier to specify them in a configuration file (remove the `-C` option) and then use that on the command line (`-f`).

![terminal #center](term.png)
#### config.txt
```
mps4_board.subsystem.ethosu.num_macs=256
mps4_board.visualisation.disable-visualisation=1
vis_hdlcd.disable_visualisation=1
```

The results of the classification will appear in the visualization window of the FVP.
The command line becomes:
```console
FVP_Corstone_SSE-320 -f config.txt -a ethos-u-kws.axf
```

The display shows a 98% chance of the audio clips sound was down.
The application executes and identifies words spoken within audio files.

![visualization #center](vis.png)
Repeat with any of the other built applications.

End the simulation by pressing Control-C in the terminal where to started the FVP.
Full instructions are provided in the evaluation kit [documentation](https://review.mlplatform.org/plugins/gitiles/ml/ethos-u/ml-embedded-evaluation-kit/+/HEAD/docs/quick_start.md).

You now have the ML Evaluation Kit examples running. Experiment with the different examples provided.

## Addendum: Setting model parameters
## Addendum: Speed up FVP execution

You can specify additional parameters to configure certain aspects of the simulated Corstone-300.
By default, the examples are built with Ethos-U timing enabled. This provides benchmarking information, but the result is that the FVP executes relatively slowly.

### List parameters
The build system has a macro `-DETHOS_U_NPU_TIMING_ADAPTER_ENABLED` defined to control this.

List the available parameters by running the FVP executable with the `--list-params` option, for example:
Modify the command `build_default.py` passes to `cmake` to include this setting (`OFF`). Search for `cmake_command` and modify as follows:

```console
FVP_Corstone_SSE-320 --list-params > parameters.txt
#### build_default.py
```

{{% notice Note %}}
If you are running with Arm Virtual Hardware substitute `VHT_Corstone_SSE-300_Ethos-U55` as the executable name.
{{% /notice %}}

Open the file `parameters.txt` to see all of the possible parameters and the default values.

### Set parameters

Individual parameters can be set with the `-C` command option.

For example, to put the Ethos-U component into fast execution mode:

```console
FVP_Corstone_SSE-320 -a cmake-build-mps4-sse-320-ethos-u85-256-gnu/bin/ethos-u-kws.axf -C mps4_board.subsystem.ethosu.extra_args="--fast"
cmake_command = (
f"{cmake_path} -B {build_dir} -DTARGET_PLATFORM={target_platform}"
f" -DTARGET_SUBSYSTEM={target_subsystem}"
f" -DCMAKE_TOOLCHAIN_FILE={cmake_toolchain_file}"
f" -DETHOS_U_NPU_ID={ethos_u_cfg.processor_id}"
f" -DETHOS_U_NPU_CONFIG_ID={ethos_u_cfg.config_id}"
" -DTENSORFLOW_LITE_MICRO_CLEAN_DOWNLOADS=ON"
" -DETHOS_U_NPU_TIMING_ADAPTER_ENABLED=OFF"
)
```
{{% notice Note %}}
Do not use fast execution mode whilst benchmarking performance.
{{% /notice %}}

To set multiple parameters it may be easier to list them in a text file (without `-C`) and use `-f` to specify the file.
Rebuild the applications as before, for example:
```
./build_default.py --npu-config-name ethos-u85-256 --toolchain gnu --make-jobs 8
```

For example, use a text editor to create a file named `options.txt` with the contents:
Add additional configuration option (`mps4_board.subsystem.ethosu.extra_args`) to the FVP command line:

```console
#### config.txt
```
mps4_board.subsystem.ethosu.num_macs=256
mps4_board.visualisation.disable-visualisation=1
vis_hdlcd.disable_visualisation=1
mps4_board.subsystem.ethosu.extra_args="--fast"
```

Run the FVP with the `-f` option and the `options.txt` file:
Run the application again, and notice how much faster execution completes.

```console
FVP_Corstone_SSE-320 -a cmake-build-mps4-sse-320-ethos-u85-256-gnu/bin/ethos-u-kws.axf -f options.txt
FVP_Corstone_SSE-320 -f config.txt -a ethos-u-kws.axf
```

Full instructions are provided in the evaluation kit [documentation](https://review.mlplatform.org/plugins/gitiles/ml/ethos-u/ml-embedded-evaluation-kit/+/HEAD/docs/quick_start.md).
{{% notice Note %}}
Do not use fast execution mode whilst benchmarking performance.
{{% /notice %}}

You have now run an example application on an Arm Fixed Virtual Platform.