Skip to content

Example projects using TVM to run neural networks on Arduino

License

Notifications You must be signed in to change notification settings

guberti/tvm-arduino-demos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Using TVM with Arduino

This repository intends to show users how Apache TVM can be used to compile models for Arduino, and get competitive or faster performance compared to TensorFlow's built-in capabilities.

Hardware required

All we need is an Arduino-compatible board with enough flash and RAM. In theory, any board with enough flash and RAM should work, but the following boards have been tested and shown to work:

Software required

Arduino support is an official part of the TVM source tree, but it is not part of any tvm or tlcpack packages. That means you'll need to build TVM from source, with microTVM support.

There is also no tvmc support for microTVM project generation yet, though that is being worked on (see https://github.com/gromero/tvm/commits/tvmc_micro). You'll either have to write Python code to use microTVM, or just use the script generate_project.py provided in this repository.

We'll also need to install the Arduino IDE or Arduino's command line interface. You will also need to install the board-specific package for the Arduino hardware you'd like to use. On the graphical IDE, this can be done by first adding the board manager URL under File->Preferences, then adding the package by going to Tools->Board->Board Manager. For the command line interface, this can be done by running a command of the form:

arduino-cli core install arduino:mbed_nano

If you have these dependencies installed, skip the rest of this file and go to a README for your desired example project.

Building TVM with Arduino support

First, we must clone TVM and initialize its submodules:

git clone https://github.com/apache/tvm.git
git submodule init
git submodule update --recursive

You can then follow the official instructions for building TVM from source. Make sure to add the following lines to your config.cmake to build with support for microTVM, which is necessary to use Arduino.

set(BUILD_STATIC_RUNTIME OFF)
set(USE_SORT ON)
set(USE_MICRO ON)
set(USE_LLVM ON)
set(CMAKE_CXX_COMPILER g++)
set(CMAKE_CXX_FLAGS -Werror)
set(HIDE_PRIVATE_SYMBOLS ON)

Installing Arduino environments

Follow the instructions for installing the Arduino IDE on your operating system, and install the packages for your boards like normal.

Note that the Sony SPRESENSE library has a major bug that will cause TVM to fail. This issue should be fixed in version 2.3.0 of the library, but until that occurs, you can use the develop branch for spresense-nuttx.

For the Nano 33 BLE, running out of memory will cause the board to enter a bad state, in which it will not communicate with the serial port and new code cannot be uploaded. To fix this issue, double-tap the reset button to force the board to enter the bootloader. Note that this could only be triggered by a bug - if the model detects it has run out of memory, it will usually fail gracefully and flash an error code on the LED.

About

Example projects using TVM to run neural networks on Arduino

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages