|
| 1 | +# Cross compile OpenVINO™ Runtime for RISCV64 systems |
| 2 | +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. |
| 3 | + |
| 4 | +Cross compilation was tested on the following hosts: |
| 5 | +- Ubuntu 22.04 (64-bit), x64 |
| 6 | + |
| 7 | +The software was validated on the following devices: |
| 8 | +- [Lichee Pi 4A](https://wiki.sipeed.com/hardware/en/lichee/th1520/lp4a.html) with RVV 0.7.1 |
| 9 | +- [Banana Pi BPI-F3](https://www.banana-pi.org/en/banana-pi-sbcs/175.html) with RVV 1.0 |
| 10 | + |
| 11 | + |
| 12 | +## Software requirements |
| 13 | + |
| 14 | +- [CMake](https://cmake.org/download/) 3.13 or higher |
| 15 | +- GCC 7.5 or higher (for non-RVV) / [xuantie-gnu-toolchain](https://github.com/XUANTIE-RV/xuantie-gnu-toolchain) (for RVV) |
| 16 | +- Python 3.10 for OpenVINO Runtime Python API |
| 17 | + |
| 18 | +## How to build |
| 19 | +0. Prerequisite: |
| 20 | +- For target with RVV - build `xuantie-gnu-toolchain` and `qemu`: |
| 21 | + ```sh |
| 22 | + git clone https://github.com/XUANTIE-RV/xuantie-gnu-toolchain.git |
| 23 | + cd xuantie-gnu-toolchain |
| 24 | + ./configure --prefix=<xuantie_install_path> |
| 25 | + make linux build-qemu -j$(nproc) |
| 26 | + ``` |
| 27 | +- For target without RVV - build `riscv-gnu-toolchain`: |
| 28 | + ```sh |
| 29 | + git clone https://github.com/riscv-collab/riscv-gnu-toolchain.git |
| 30 | + cd riscv-gnu-toolchain |
| 31 | + ./configure --prefix=/opt/riscv |
| 32 | + make linux build-qemu -j$(nproc) |
| 33 | + ``` |
| 34 | + > **NOTE**: The `build-qemu` target is optional, as it is used to build the `qemu` simulator. However, it is recommended to build the `qemu` simulator, since it is much more convenient to validate the software on your host than on your devices. More information can be seen [here](https://github.com/riscv-collab/riscv-gnu-toolchain). |
| 35 | +
|
| 36 | +1. Clone OpenVINO repository and init submodules: |
| 37 | + ```sh |
| 38 | + git clone --recursive https://github.com/openvinotoolkit/openvino.git |
| 39 | + cd openvino |
| 40 | + ``` |
| 41 | + |
| 42 | +2. Install build dependencies using the `install_build_dependencies.sh` script in the |
| 43 | + project root folder. |
| 44 | + ```sh |
| 45 | + sudo ./install_build_dependencies.sh |
| 46 | + ``` |
| 47 | + |
| 48 | +3. Create a build folder: |
| 49 | + ```sh |
| 50 | + mkdir build && cd build |
| 51 | + ``` |
| 52 | + |
| 53 | +4. To cross compile OpenVINO Runtime for RISC-V devices, run `cmake` with specified `CMAKE_TOOLCHAIN_FILE` and `RISCV_TOOLCHAIN_ROOT`. |
| 54 | +- For target with RVV: |
| 55 | + ```sh |
| 56 | + cmake .. \ |
| 57 | + -DCMAKE_BUILD_TYPE=Release \ |
| 58 | + -DCMAKE_INSTALL_PREFIX=<openvino_install_path> \ |
| 59 | + -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/<toolchain_file> \ |
| 60 | + -DRISCV_TOOLCHAIN_ROOT=<xuantie_install_path> |
| 61 | + ``` |
| 62 | + > **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>` with `riscv64-071-thead-gnu.toolchain.cmake` for RVV 0.7.1 and `riscv64-100-thead-gnu.toolchain.cmake` for RVV 1.0 respectively. |
| 63 | +- For target without RVV: |
| 64 | + ```sh |
| 65 | + cmake .. \ |
| 66 | + -DCMAKE_BUILD_TYPE=Release \ |
| 67 | + -DCMAKE_INSTALL_PREFIX=<openvino_install_path> \ |
| 68 | + -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/riscv64-gnu.toolchain.cmake \ |
| 69 | + -DRISCV_TOOLCHAIN_ROOT=/opt/riscv |
| 70 | + ``` |
| 71 | + > **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` and `CMAKE_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. |
| 72 | + |
| 73 | + Then run `make` to build the project: |
| 74 | + ```sh |
| 75 | + make install -j$(nproc) |
| 76 | + ``` |
| 77 | + |
| 78 | +### (Optional) Build the OpenVINO Runtime Python API |
| 79 | +To enable cross-compilation with python, the library `libpython3-dev:riscv64` should be on the host machine. |
| 80 | + |
| 81 | +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. |
| 82 | + |
| 83 | +1. Add riscv64 repositories to download riscv64-specific packages: |
| 84 | + ```sh |
| 85 | + echo deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports/ jammy main >> riscv64-sources.list |
| 86 | + echo deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports/ jammy universe >> riscv64-sources.list |
| 87 | + echo deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports/ jammy-updates main >> riscv64-sources.list |
| 88 | + echo deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports/ jammy-security main >> riscv64-sources.list |
| 89 | + mv riscv64-sources.list /etc/apt/sources.list.d/ |
| 90 | + dpkg --add-architecture riscv64 |
| 91 | + apt-get update -o Dir::Etc::sourcelist=/etc/apt/sources.list.d/riscv64-sources.list |
| 92 | + ``` |
| 93 | + |
| 94 | +2. Install `libpython3-dev:riscv64` using `apt-get`: |
| 95 | + ```sh |
| 96 | + apt-get install -y --no-install-recommends libpython3-dev:riscv64 |
| 97 | + ``` |
| 98 | + 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/`) |
| 99 | + ```sh |
| 100 | + ln -s /usr/include/riscv64-linux-gnu/ /usr/include/python3.10/ |
| 101 | + ``` |
| 102 | + |
| 103 | +3. Add the keys `-DENABLE_PYTHON=ON -DENABLE_WHEEL=ON` to cmake command during OpenVINO build. |
| 104 | + |
| 105 | +> **Note**: Currently only Python 3.10 on Ubuntu 22.04 is verified. So the target device must have Python 3.10 in this case. |
| 106 | + |
| 107 | +### RISC-V Emulation software |
| 108 | +In order to test applications without hardware one can use emulation software. The command line example to launch executable file with riscv64 emulation: |
| 109 | +```sh |
| 110 | +<xuantie_install_path>/bin/qemu-riscv64 -cpu=<target_cpu> <executable_file_path> |
| 111 | +``` |
| 112 | + |
| 113 | +For example, to emulate RVV 0.7.1: |
| 114 | +```sh |
| 115 | +<xuantie_install_path>/bin/qemu-riscv64 -cpu rv64,x-v=true,vext_spec=v0.7.1 <executable_file_path> |
| 116 | +``` |
| 117 | + |
| 118 | +Or to emulate RVV 1.0: |
| 119 | +```sh |
| 120 | +<xuantie_install_path>/bin/qemu-riscv64 -cpu rv64,x-v=true,vext_spec=v1.0 <executable_file_path> |
| 121 | +``` |
| 122 | + |
| 123 | +> **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` (for `qemu` version greater than `8.0`). |
| 124 | + |
| 125 | +## See also |
| 126 | + |
| 127 | + * [OpenVINO README](../../README.md) |
| 128 | + * [OpenVINO Developer Documentation](index.md) |
| 129 | + * [OpenVINO Get Started](./get_started.md) |
| 130 | + * [How to build OpenVINO](build.md) |
| 131 | + |
0 commit comments