3.4. Install SDK

注解

Development environment and operation environment:

Development environment refers to the environment used for development processes such as model transformation or validation and program compilation; The running environment refers to the running environment in which the Sophon device is used to deploy algorithm applications on a platform with Sophon devices. The development and run environments may be unified (e.g., x86 hosts with SC5 accelerator cards, which are both development and run environments), or they may be separate (e.g., x86 hosts as development environment transform models and compilers, and SE5 box deployments run the final algorithm applications).

However, whether you are using a product in SoC mode or PCIe mode, you will need an x86 host as your development environment, and your environment can be any system platform we have tested and supported.

In PCIe mode, you need to insert the PCIe accelerator card into the host. If you need to compile and quantify the model, you can configure the docker environment according to the instructions and compile and quantify the model in the docker environment. If you need to perform model verification, program compilation, and algorithm application deployment, install libsophon and sophon-mw in sequence as instructed. You can also add the library packages and other programming code you need to build your own production environment.

注意

PCIe users check whether the PCIe accelerator card is properly identified by the system:

Open a terminal performs lspci | grep Sophon check card can be identified. In normal cases, the following information should be displayed:

101:00.0 Processing accelerators: Bitmain Technologies Inc. BM1684, Sophon Series Deep Learning Accelerator (rev 01)

If the PCIe accelerator card cannot be identified by the system, rectify the fault. The possible causes are as follows:

  • The PCIe accelerator card is not tightly inserted in the socket.

  • Check whether the card is installed in a standard X16 slot. The X8 slot supports a maximum power of 45W.

  • The PCIe acceleration card directly supplies power from the PCIe and does not require an external power supply. If an external power supply is connected, the card cannot be identified.

  • A PCIe acceleration card with more than three chips must be equipped with sufficient heat dissipation conditions. If the air duct and air volume cannot meet the passive heat dissipation requirements of the PCIe acceleration card, set the fan speed to a high enough speed in the BIOS or install additional fans for heat dissipation. (Recommended fan purchase link1, Recommended fan purchase link2, Recommended fan purchase link3)

If it is SoC mode, you need to configure the docker environment on an x86 host according to the instructions, and conduct compilation and quantification of the model in the docker environment, or install libsophon and sophon-mw according to the instructions, and conduct cross-compilation of the program. After the program is compiled, You need to manually copy the compiled program to the target system (SE5/SM5) for execution.

Typical development environment:

  • Linux development environment

    1. An x86 host with Ubuntu16.04/18.04/20.04 installed has at least 12GB of memory

    2. Install Docker: refer to Official Tutorial

    3. Download the SophonSDK development kit

注解

Attention: If you are developing on a host other than x86 architecture, the model transformation will also need to be done on an x86 host, and development and deployment can be done directly on the bare metal. If you have any questions, please contact us for technical support. The rest of this tutorial, unless otherwise specified, will be done in the ubuntu development environment on an x86 host.

3.4.1. Environment Configuration -Linux

We provide tpu-nntc environment for users to compile and quantify the model on x86 host, and libsophon environment for users to develop and deploy applications. PCIe users can compile, quantify and deploy the model based on tpu-nntc and libsophon. SoC users can compile and quantify the model and cross-compile programs based on tpu-nntc and libsophon on x86 hosts, and copy the compiled programs to the SoC platform (SE microserver /SM module) for execution during deployment. For configuration of relevant running environment, please refer to the section of Environment Configuration. You can also customize your own development environment based on the one we provide.

注意

Note that the following steps apply to the SDK Release_<date>-public.zip, where <date> indicates the SDK Release date, which changes with the SDK upgrade.

Users of other platforms also need to use the x86 host as the development environment to complete the model conversion, and then cross-compile to generate the corresponding platform of the program copy to run on the target platform.

3.4.1.1. Decompress the SDK package

1sudo apt-get install p7zip
2sudo apt-get install p7zip-full
37z x Release_<date>-public.zip
4cd Release_<date>-public

注解

Hint: <date> refers to the date

3.4.1.2. tpu-nntc environment initialization

  1. Docker install

If docker is installed, skip this section.

 1# install docker
 2sudo apt-get install docker.io
 3# The docker command is executed without root permission
 4# Create a docker user group. If there is a docker group, an error will be reported
 5sudo groupadd docker
 6# Add the current user to the docker group
 7sudo gpasswd -a ${USER} docker
 8# Restart the docker service
 9sudo service docker restart
10# Switch the current session to a new group or log in again to restart the X session
11newgrp docker

注解

Hint: You need to logout the system and then log back in again to use docker without the need for sudo.

  1. Extract the compressed package to tpu-nntc

1cd tpu-nntc_<date>_<hash>
2mkdir tpu-nntc
3tar zxvf tpu-nntc_v<x.y.z>-<hash>-<date>.tar.gz --strip-components=1 -C tpu-nntc

注解

Hint: <date> indicates the date, <x.y.z> indicates the version, and <hash> indicates the hash value. Unless otherwise specified, the following contents are subject to this rule.

  1. Create a docker container and go to Docker

1cd tpu-nntc
2#If there is no corresponding image in the current system, the image is automatically downloaded from the docker hub. Here, map the upper-level directory of tpu-nntc to the /workspace directory in docker. The mapping between ports 8001 and 8001 is used (port numbers are used when using the ufw visualization tool).
3#If the port is occupied, replace it with another port that is not occupied.
4docker run -v $PWD/..:/workspace -p 8001:8001 -it sophgo/tpuc_dev:latest
  1. Initialize the software environment

1cd /workspace/tpu-nntc
2source scripts/envsetup.sh

注意

Note that if you re-enter after docker stop, you need to re-source the environment variables.

3.4.1.3. libsophon environment construction

注意

libsophon offers different types of installation on different Linux distributions, so choose one based on your system and do not mix multiple installation methods on one machine.

  1. If you have installed an old driver of the BM1684 SDK, uninstall the driver by performing the following steps:

    1# Go to the scripts folder in the SDK installation directory and run the following command
    2sudo ./remove_driver_pcie.sh
    
  2. If you are using a Debian/Ubuntu system, the installation package consists of three files:sophon-driver_<x.y.z>_$arch.deb、sophon-libsophon_<x.y.z>_$arch.deb、sophon-libsophon-dev_<x.y.z>_$arch.deb

注解

In the preceding command, <x.y.z> indicates the version number and $arch indicates the hardware architecture of the current server. You can run the following command to obtain the arch of the current server. Generally, the hardware architecture of x86_64 machines is amd64, and that of arm64 machines is arm64. Select the installation file you want to install.

1uname -m

You can perform the following steps to install it:

1cd libsophon_<date>_<hash>
2# Install the dependency library only once
3sudo apt install dkms libncurses5
4sudo dpkg -i sophon-*.deb
5# You can run the following command on the terminal or log out and log in to the current user to run the bm-smi command
6source /etc/profile

注意

Check whether the driver is installed successfully:

Run ls /dev/bm* to see if there is /dev/bm-sohponx (X means 0-N). If there is, the installation is successful. Normally, the following information is displayed: /dev/bmdev-ctl /dev/bm-sophon0

  1. If you use other Linux systems, the installation package consists of only one file: libsophon_<x.y.z>_$arch.tar.gz. You can install it by referring to Libsophon User Manual.

For other questions, please refer to Libsophon User Manual

3.4.1.4. sophon-mw environment construction

Make sure libsophon is installed when installing sophon-mw.

  1. If you are using a Debian/Ubuntu system, the installation package consists of four files:sophon-mw-sophon-ffmpeg_<x.y.z>_$arch.deb、sophon-mw-sophon-ffmpeg-dev_<x.y.z>_$arch.deb、sophon-mw-sophon-opencv_<x.y.z>_$arch.deb、sophon-mw-sophon-opencv-dev_<x.y.z>_$arch.deb,请选择您对应的安装文件参考如下步骤进行安装:

    1cd sophon-mw_<date>_<hash>
    2# Must install sophon-mw-sophon-ffmpeg, then install sophon-mw-sophon-opencv
    3sudo dpkg -i sophon-mw-sophon-ffmpeg_<x.y.z>_*.deb sophon-mw-sophon-ffmpeg-dev_<x.y.z>_*.deb
    4sudo dpkg -i sophon-mw-sophon-opencv_<x.y.z>_*.deb sophon-mw-sophon-opencv-dev_<x.y.z>_*.deb
    5# To use the installation tool, run the following command on the terminal, or log out and log in to the current user
    6source /etc/profile
    
  2. If you use another Linux system, the installation package sophon-mw_<x.y.z>_$arch.tar.gz can be installed by referring to the Sophon-mw User Manual.

For other questions, please refer to Sophon-mw User Manual.

3.4.1.5. Cross-compilation environment construction

If you want to set up a cross-compilation environment using SophonSDK, you need to use the gcc-aarch64-linux-gnu tool chain and package the header files and libraries that your program depends on into the soc-sdk directory.

  1. First install the toolchain:

    1sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
    
  2. Decompress libsophon_soc_<x.y.z>_aarch64.tar.gz in the sophon-img package and copy everything lib and include to the soc-sdk folder.

    1cd sophon-img_<date>_<hash>
    2# Create the root directory for the dependent files
    3mkdir -p soc-sdk
    4# Decompress libsophon_soc_${x.y.z}_aarch64.tar.gz in the sophon-img release package, where x.y.z is the version number
    5tar -zxf libsophon_soc_<x.y.z>_aarch64.tar.gz
    6# Copy the relevant library directory and header directory to the dependent file root
    7cp -rf libsophon_soc_<x.y.z>_aarch64/opt/sophon/libsophon-<x.y.z>/lib ${soc-sdk}
    8cp -rf libsophon_soc_<x.y.z>_aarch64/opt/sophon/libsophon-<x.y.z>/include ${soc-sdk}
    
  3. Decompress Sophon-mw-soc _<x.y.z>_aarch64.tar.gz in sophon-mw and copy all contents lib and include in sophon-mw to the soc-sdk folder.

    1cd sophon-mw_<date>_<hash>
    2# Decompress Sophon-mw-soc_ <x.y.z>_aarch64.tar.gz in the sophon-mw package, where x.y.z is the version number
    3tar -zxf sophon-mw-soc_<x.y.z>_aarch64.tar.gz
    4# Copy the ffmpeg and opencv library and header directories to the dependent file root
    5cp -rf sophon-mw-soc_<x.y.z>_aarch64/opt/sophon/sophon-ffmpeg_<x.y.z>/lib ${soc-sdk}
    6cp -rf sophon-mw-soc_<x.y.z>_aarch64/opt/sophon/sophon-ffmpeg_<x.y.z>/include ${soc-sdk}
    7cp -rf sophon-mw-soc_<x.y.z>_aarch64/opt/sophon/sophon-opencv_<x.y.z>/lib ${soc-sdk}
    8cp -rf sophon-mw-soc_<x.y.z>_aarch64/opt/sophon/sophon-opencv_<x.y.z>/include ${soc-sdk}
    
  4. If you need to use a third-party library, you can use qemu to build a virtual environment installation on x86 and copy the header and library files into the soc-sdk directory, as shown in the sophon-mw User Manual.

3.4.1.6. Verification

You can run the following command to verify that the cross-compilation toolchain in the development environment is configured successfully:

1which aarch64-linux-gnu-g++
2# Terminal output
3# /usr/bin/aarch64-linux-gnu-g++

If the terminal prints the path to aarch64 compilation, the cross-compilation toolchain is correct and the development environment is working.

If you need to use the SAIL module, on non-SOC platforms you need to install the pip package according to the python version you are using. Please refer to the installation instructions in the SAIL User Development Manual. If you are using the SAIL module in the SoC platform, you only need to set the environment variables.

3.4.2. Environment Configuration -SoC

3.4.2.1. Development environment configuration

For SoC mode, model transformation also needs to be completed in docker development container; C/C++ programs are recommended to be compiled on x86 hosts using the cross-compilation toolchain to generate executable files, and then copied to the SoC target platform to run. The docker development container is configured according to the previous section.

If you want to directly compile C/C++ programs on SoC, you need to install sophon-libsophon-dev_<x.y.z>_arm64.deb by running the following command:

1sudo dpkg -i sophon-libsophon-dev_<x.y.z>_arm64.deb

To install sophon-mw-soc-sophon-ffmpeg-dev_< X.Y.Z >_arm64.deb, sophon-mw-soc-sophon-opencv-dev_< X.Y.Z > _arm64.deb toolkit, use the following command to install:

1sudo dpkg -i sophon-mw-soc-sophon-ffmpeg-dev_<x.y.z>_arm64.deb
2sudo dpkg -i sophon-mw-soc-sophon-opencv-dev_<x.y.z>_arm64.deb

注意

attention

  1. SE microserver no longer presets the face capture application gate, and the gate application will not be maintained. In the future, we will also upgrade the default system of SE microserver to Ubuntu 20.04, and have a web interface for querying and configuring basic information. It also uses qt to write a simple interface for IP configuration. You can connect the HDMI interface to the display for viewing, and use the keyboard and mouse integrated suite to operate accordingly.

  2. The built-in operating system of the SE microserver does not have a desktop system. You need to use ssh to log in to the terminal of the microserver for operation development.

3.4.2.2. Operating environment configuration

For the SoC platform, the corresponding libsophon, Sophon-Opencv and Sophon-ffmpeg runtime packages have been integrated internally under /opt/sophon/. Just set the environment variables.

1# Setting environment variables
2export PYTHONPATH=$PYTHONPATH:/opt/sophon/sophon-opencv_<x.y.z>/opencv-python