This guide shows how to build OpenVINO Runtime for 64-bit RISC-V devices. Due to limited resources, cross compilation is used now for building OpenVINO targeting RISC-V development boards.
Cross compilation was tested on the following hosts:
- Ubuntu 22.04 (64-bit), x64
The software was validated on the following devices:
- Lichee Pi 4A with RVV 0.7.1
- Banana Pi BPI-F3 with RVV 1.0
- CMake 3.13 or higher
- GCC 7.5 or higher (for non-RVV) / xuantie-gnu-toolchain (for RVV)
- Python 3.10 for OpenVINO Runtime Python API
- Prerequisite:
- For target with RVV - build
xuantie-gnu-toolchain
andqemu
:git clone https://github.com/XUANTIE-RV/xuantie-gnu-toolchain.git cd xuantie-gnu-toolchain ./configure --prefix=<xuantie_install_path> make linux build-qemu -j$(nproc)
- For target without RVV - build
riscv-gnu-toolchain
:git clone https://github.com/riscv-collab/riscv-gnu-toolchain.git cd riscv-gnu-toolchain ./configure --prefix=/opt/riscv make linux build-qemu -j$(nproc)
NOTE: The
build-qemu
target is optional, as it is used to build theqemu
simulator. However, it is recommended to build theqemu
simulator, since it is much more convenient to validate the software on your host than on your devices. More information can be seen here.
-
Clone OpenVINO repository and init submodules:
git clone --recursive https://github.com/openvinotoolkit/openvino.git cd openvino
-
Install build dependencies using the
install_build_dependencies.sh
script in the project root folder.sudo ./install_build_dependencies.sh
-
Create a build folder:
mkdir build && cd build
-
To cross compile OpenVINO Runtime for RISC-V devices, run
cmake
with specifiedCMAKE_TOOLCHAIN_FILE
andRISCV_TOOLCHAIN_ROOT
.
-
For target with RVV:
cmake .. \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=<openvino_install_path> \ -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/<toolchain_file> \ -DRISCV_TOOLCHAIN_ROOT=<xuantie_install_path>
NOTE: To build OpenVINO Runtime for different versions of RVV, you just need to specify corresponding toolchain files. For exmaple, you can replace
<toolchain_file>
withriscv64-071-thead-gnu.toolchain.cmake
for RVV 0.7.1 andriscv64-100-thead-gnu.toolchain.cmake
for RVV 1.0 respectively. -
For target without RVV:
cmake .. \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=<openvino_install_path> \ -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/riscv64-gnu.toolchain.cmake \ -DRISCV_TOOLCHAIN_ROOT=/opt/riscv
NOTE: The
riscv-gnu-toolchain
is build as there are essential files used for cross compilation under/opt/riscv/sysroot
. The latest stable versions of Clang or GCC both support compiling source code into RISC-V instructions, so it is acceptable to choose your preferable compilers by specifying-DCMAKE_C_COMPILER
andCMAKE_CXX_COMPILER
. But remember to add the key-DCMAKE_SYSROOT=/opt/riscv/sysroot
, otherwise many fundamental headers and libs could not be found during cross compilation.NOTE: By default OpenVINO is built with OpenMP support on RISC-V devices.
Then run
make
to build the project:make install -j$(nproc)
To enable cross-compilation with python, the library libpython3-dev:riscv64
should be on the host machine.
When installing packages using the utilities apt
or apt-get
the packages are downloaded from apt software repositories. On Ubuntu the apt software repositories are defined in the /etc/apt/sources.list
file or in separate files under the /etc/apt/sources.list.d/
directory. Host machine contains host-specific repositories (for example, x86-x64) in these files.
-
Add riscv64 repositories to download riscv64-specific packages:
echo deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports/ jammy main >> riscv64-sources.list echo deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports/ jammy universe >> riscv64-sources.list echo deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports/ jammy-updates main >> riscv64-sources.list echo deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports/ jammy-security main >> riscv64-sources.list mv riscv64-sources.list /etc/apt/sources.list.d/ dpkg --add-architecture riscv64 apt-get update -o Dir::Etc::sourcelist=/etc/apt/sources.list.d/riscv64-sources.list
-
Install
libpython3-dev:riscv64
usingapt-get
:apt-get install -y --no-install-recommends libpython3-dev:riscv64
Create symbolink to allow python to find
riscv64-linux-gnu/python3.10/pyconfig.h
in/usr/include/python3.10/
(this header is initially stored in/usr/include/riscv64-linux-gnu/
)ln -s /usr/include/riscv64-linux-gnu/ /usr/include/python3.10/
-
Add the keys
-DENABLE_PYTHON=ON -DENABLE_WHEEL=ON
to cmake command during OpenVINO build.
Note: Currently only Python 3.10 on Ubuntu 22.04 is verified. So the target device must have Python 3.10 in this case.
In order to test applications without hardware one can use emulation software. The command line example to launch executable file with riscv64 emulation:
<xuantie_install_path>/bin/qemu-riscv64 -cpu=<target_cpu> <executable_file_path>
For example, to emulate RVV 0.7.1:
<xuantie_install_path>/bin/qemu-riscv64 -cpu rv64,x-v=true,vext_spec=v0.7.1 <executable_file_path>
Or to emulate RVV 1.0:
<xuantie_install_path>/bin/qemu-riscv64 -cpu rv64,x-v=true,vext_spec=v1.0 <executable_file_path>
Note: If you are using official
qemu
instead of modified version by Xuantie, you should specify the CPU model with-cpu rv64,v=true,vext_spec=v1.0
(forqemu
version greater than8.0
).