Running a TF-Lite Model on RENODE (Litex Vexx RISC-V SoC)
In today’s embedded world, having a reliable emulation platform can drastically reduce development time and facilitate system-level testing. Renode is one such platform, and today, we’ll delve into running a TensorFlow Lite application on the LiteX Vexx RISC-V SoC under the Renode emulation environment.
Prerequisites
- Linux environment (for our steps).
- Knowledge about Zephyr, an open-source Real-Time Operating System (RTOS).
STEP 1: Setting Up Renode
Head to the Renode Github Repository.
STEP 2: Downloading Necessary Files
From the releases section, download the following files:
- renode-1.12.0–1-x86_64.pkg.tar.xz8.13 MB
- renode-1.12.0–1.f23.x86_64.rpm12.5 MB
- renode-1.12.0.linux-portable.tar.gz46.1 MB
- renode_1.12.0.dmg14.3 MB
- renode_1.12.0.msi15.7 MB
- renode_1.12.0.zip15.2 MB
- renode_1.12.0_amd64.deb12.6 MB
- Source code (zip)
- Source code (tar.gz)
STEP 3: Unpacking The Files
mkdir renode_portable
tar xf renode-*.linux-portable.tar.gz -C renode_portable --strip-components=1
STEP 4: Adding to System Path
To conveniently call Renode from any terminal:
cd renode_portable
export PATH="`pwd`:$PATH"
STEP 5: Launching Renode
Open a terminal and simply type:
renode
This will launch the Renode monitor (CLI) where the emulation environment can be controlled.
STEP 6: Loading a Script
Scripts are crucial in Renode. To load one, use:
include @/path/to/script.resc
For instance:
include @/home/mahnoor/renode/renode_portable/scripts/single-node/litex.resc
STEP 7: Installing Zephyr
Zephyr can be installed following the guidelines provided here.
STEP 8: Building the Zephyr Shell Demo Application
cd ~/zephyrproject/zephyr
source zephyr-env.sh
west build -p auto -b litex_vexriscv samples/subsys/shell/shell_module/
STEP 9: Relaunching Renode
Again, type:
renode
STEP 10: Running the Zephyr Binary on Renode
In the Renode monitor, run:
(monitor) $zephyr=@/path/to/zephyrproject/zephyr/build/zephyr/zephyr.elf
(monitor) start @scripts/single-node/litex_vexriscv_zephyr.resc
E: if you will get an error from the above command; goto: https://www.mono-project.com/download/stable/
It looks like mono can’t find the libdl.so file. Perhaps it’s the .2 postfix in the filename.
Then Run this command
sudo ln -s /usr/lib/x86_64-linux-gnu/libdl.so.2 /usr/lib/dl
E: if you get an error :
(monitor) $zephyr?=@/path/to/zephyrproject/zephyr/build/zephyr/zephyr.elf (zephyr binary)
(monitor) start @scripts/single-node/litex_vexriscv_zephyr.resc (soc/board )
STEP 11: Running an Application on Renode
The power of Renode extends beyond the basic Zephyr shell. You can also run specialized applications, like TensorFlow Lite, on the emulated LiteX Vexx RISC-V SoC. Let’s dive into the steps:
- Setting Up The Application: Navigate to the ‘hello world’ folder within Zephyr’s sample applications.
- Building the Binary: Open your command prompt or terminal and execute:
west build -b {board_name}
- As an example, if you’re using the
litex_vexriscv
board:
west build -b litex_vexriscv
- This will generate the application’s binary. Note that
litex_vexriscv
is just one of the many boards supported by Zephyr. You can replace it with any board name supported by Zephyr. - Loading the Binary in Renode: Launch Renode, and in the monitor, input:
(monitor) $zephyr?=@/path/to/zephyrproject/zephyr/samples/modules/tflite-micro/build/zephyr/zephyr.elf
- Make sure to replace the path with the exact location of your Zephyr binary.
- Starting the Emulation: Now, to initiate the emulation, enter:
(monitor) start @scripts/single-node/litex_vexriscv_zephyr.resc
- Observing the Output: Once the command is executed, Renode will bring up the UART window, showcasing the application’s output.
Congratulations!
Your TensorFlow Lite Application is now humming smoothly on the LiteX Vexx RISC-V SoC in Renode’s emulated environment.
For those deeply interested in embedded systems, the approach outlined in this blog offers a promising way to run and test applications in a risk-free environment before transferring them to real hardware. Happy coding!