Skip to main content

NPU Acceleration from C++

This tutorial provides a quick walkthrough for building embedded AI applications for Synaptics Astra using the SyNAP C++ Framework. It covers setting up an environment on your host machine that mirrors Synaptics Astra™ Machina™'s environment, so you can easily build C++ apps that will run on the board with Yocto Linux. The setup includes all necessary libraries and dependencies, such as the SyNAP framework, CMake, and more, to ensure smooth development and deployment.

You can build any C++ application. For this tutorial, you will be guided to build the synap_cli application.

About the SyNAP Framework

The SyNAP Framework provides methods to execute precompiled neural networks on Synaptics Astra hardware, as well as perform various pre-processing and post-processing functions for popular models like YOLOv5 and YOLOv8. The inference can take place on various hardware units - NPU, GPU, CPU, or a combination of them, depending on how the model has been compiled.

tip

If you want to build or modify the whole SyNAP framework, which allows you to make changes in preprocessing or postprocessing code, follow the Modifying SyNAP Framework tutorial.

Step 1: Set Up Toolchain Environment

First, extract and set up the toolchain in your development environment. On your host development machine, download the pre-built toolchain for your specific SL16xx chip from here.

In this tutorial, you will use the SL1680 chip and a pre-built image, so download the pre-built toolchain for SL1680. Once downloaded, execute it using the bash command.

bash poky-glibc-x86_64-astra-media-cortexa73-sl1680-toolchain-4.0.17.sh

The toolchain environment includes everything needed to compile C++ applications on Yocto Linux. To activate the environment:

. /opt/poky/4.0.17/environment-setup-cortexa73-poky-linux
warning

With future releases, toolchain file names might change, so adjust the above commands accordingly.

tip

To check if the environment is active, use the following command in your Ubuntu terminal:

echo $CC

Step 2: Create a Simple C++ Project

Since in this tutorial you want to build the synap_cli application, you need the source code of the synap_cli and the CMake file for building the application.

You can download the SyNAP framework and check out the latest branch version (here we are using v1.3.0). You just need the synap_cli folder inside the synap-framework/app.

git clone https://github.com/synaptics-astra/synap-framework.git
git fetch --all
git checkout v1.3.0
tip

If you are building your own C++ application that does not require SyNAP, you can skip Step 2. You will need to create a CMakeLists.txt file for your project. This CMakeLists.txt should reference all the required libraries for your code, including those provided by the toolchain (e.g., synap_app, synap_img, etc.).

Step 3: Compile the C++ Application

Once you have the source code of SyNAP, navigate to the synap-framework/app/synap_cli folder and add the synap_img library to the target link inside the CMakeLists.txt file.

target_link_libraries(${name} PRIVATE synap_app synap_preprocess synapnb synap_postprocess synap_img)

With the toolchain and project set up, create a build folder and compile the application:

cd app/synap_cli/
mkdir build && cd build
cmake .. -G Ninja
ninja

Step 4: Deploy Your App on Machina

You can find the synap_cli binary inside the build folder. Next, copy this to /usr/bin of your Synaptics Astra Board:

scp synap_cli root@10.3.10.132:/usr/bin

Congratulations! You've successfully compiled and run a C++ application on Machina using the provided toolchain. This process can be easily adapted for more complex projects, thanks to the libraries and tools included in the toolchain.

Follow the next tutorial to modify the whole SyNAP framework, which allows you to make changes in preprocessing or postprocessing according to your needs.