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
- Orange Pi RV2 with RVV 1.0
- CMake 3.13 or higher
- GCC 7.5 or higher (for non-RVV) / riscv-gnu-toolchain (for RVV)
- Python 3.10 for OpenVINO Runtime Python API
Currently, there are two ways to build OpenVINO Runtime for 64-bit RISC-V platforms:
- The build with RVV intrinsics using
riscv-gnu-toolchain. This GNU Compiler Toolchain supports RVV 0.7.1 and ratified RVV 1.0. The vector intrinsics use the common prefix__riscv_. - The build without optimized primitives using installed Linux packages. The compilers in these packages don't support RVV intrinsics.
NOTE: Currently CPU Plugin in OpenVINO supports Just-In-Time (JIT) code generation for limited scope of operations on devices with RVV 1.0. All three described above ways to build OpenVINO Runtime for 64-bit RISC-V supports JIT code generation.
- Prerequisite:
- For target with RVV intrinsics using
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-qemutarget is optional, as it is used to build theqemusimulator. However, it is recommended to build theqemusimulator, since it is much more convenient to validate the software on your host than on your devices. More information can be seen here. - For target without optimized primitives using installed Linux packages:
apt-get update apt-get install -y gcc-riscv64-linux-gnu g++-riscv64-linux-gnu binutils-riscv64-linux-gnu
-
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.shscript 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
cmakewith specifiedCMAKE_TOOLCHAIN_FILEandRISCV_TOOLCHAIN_ROOT(the last one is needed only for build using GNU toolchain).
-
For target with RVV intrinsics using
riscv-gnu-toolchain: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-toolchainis 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_COMPILERandCMAKE_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. -
For target without optimized primitives using installed Linux packages:
cmake .. \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=<openvino_install_path> \ -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/riscv64.linux.toolchain.cmake
Then run
maketo 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:riscv64usingapt-get:apt-get install -y --no-install-recommends libpython3-dev:riscv64
Create symbolink to allow python to find
riscv64-linux-gnu/python3.10/pyconfig.hin/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=ONto 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:
<riscv_toolchain_root>/bin/qemu-riscv64 -cpu=<target_cpu> <executable_file_path><riscv_toolchain_root> matches the RISCV_TOOLCHAIN_ROOT used during the build (for example, /opt/riscv), or use qemu-riscv64 from your system PATH.
For example, to emulate RVV 0.7.1:
<riscv_toolchain_root>/bin/qemu-riscv64 -cpu rv64,x-v=true,vext_spec=v0.7.1 <executable_file_path>Or to emulate RVV 1.0:
<riscv_toolchain_root>/bin/qemu-riscv64 -cpu rv64,x-v=true,vext_spec=v1.0 <executable_file_path>