Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[RV64] Added build support via linux package and fix the build via GNU toolchain (#27228)

Alexandra Sidorovade5f765ca14d
diff --git a/cmake/toolchains/riscv64-071-thead-gnu.toolchain.cmake b/cmake/toolchains/riscv64-071-xuantie-gnu.toolchain.cmake
similarity index 95%
rename from cmake/toolchains/riscv64-071-thead-gnu.toolchain.cmake
rename to cmake/toolchains/riscv64-071-xuantie-gnu.toolchain.cmake
index f5e9e68aabe..5bc16de8df9 100644
--- a/cmake/toolchains/riscv64-071-thead-gnu.toolchain.cmake
+++ b/cmake/toolchains/riscv64-071-xuantie-gnu.toolchain.cmake
@@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
#
-# NOTE: use T-Head compiler:
+# NOTE: use Xuantie compiler:
# git clone https://github.com/XUANTIE-RV/xuantie-gnu-toolchain.git
# ./configure --prefix=/opt/riscv
# make linux
@@ -22,10 +22,10 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR riscv64)
-set(RISCV64_THEAD ON)
+set(RISCV64_XUANTIE ON)
set(RISCV64_RVV0p7 ON)
-set(RISCV_TOOLCHAIN_ROOT $ENV{RISCV_TOOLCHAIN_ROOT} CACHE PATH "Path to CLANG for RISC-V cross compiler build directory")
+set(RISCV_TOOLCHAIN_ROOT $ENV{RISCV_TOOLCHAIN_ROOT} CACHE PATH "Path to GCC for RISC-V cross compiler build directory")
set(CMAKE_SYSROOT "${RISCV_TOOLCHAIN_ROOT}/sysroot" CACHE PATH "RISC-V sysroot")
set(CMAKE_C_COMPILER ${RISCV_TOOLCHAIN_ROOT}/bin/riscv64-unknown-linux-gnu-gcc)
diff --git a/cmake/toolchains/riscv64-100-thead-gnu.toolchain.cmake b/cmake/toolchains/riscv64-100-xuantie-gnu.toolchain.cmake
similarity index 95%
rename from cmake/toolchains/riscv64-100-thead-gnu.toolchain.cmake
rename to cmake/toolchains/riscv64-100-xuantie-gnu.toolchain.cmake
index e00e30f9755..0664b38a9ba 100644
--- a/cmake/toolchains/riscv64-100-thead-gnu.toolchain.cmake
+++ b/cmake/toolchains/riscv64-100-xuantie-gnu.toolchain.cmake
@@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
#
-# NOTE: use T-Head compiler:
+# NOTE: use Xuantie compiler:
# git clone https://github.com/XUANTIE-RV/xuantie-gnu-toolchain.git
# ./configure --prefix=/opt/riscv
# make linux
@@ -22,10 +22,10 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR riscv64)
-set(RISCV64_THEAD ON)
+set(RISCV64_XUANTIE ON)
set(RISCV64_RVV1p0 ON)
-set(RISCV_TOOLCHAIN_ROOT $ENV{RISCV_TOOLCHAIN_ROOT} CACHE PATH "Path to CLANG for RISC-V cross compiler build directory")
+set(RISCV_TOOLCHAIN_ROOT $ENV{RISCV_TOOLCHAIN_ROOT} CACHE PATH "Path to GCC for RISC-V cross compiler build directory")
set(CMAKE_SYSROOT "${RISCV_TOOLCHAIN_ROOT}/sysroot" CACHE PATH "RISC-V sysroot")
set(CMAKE_C_COMPILER ${RISCV_TOOLCHAIN_ROOT}/bin/riscv64-unknown-linux-gnu-gcc)
diff --git a/cmake/toolchains/riscv64-gnu.toolchain.cmake b/cmake/toolchains/riscv64-gnu.toolchain.cmake
index 994b05f66b5..b58dcf169fc 100644
--- a/cmake/toolchains/riscv64-gnu.toolchain.cmake
+++ b/cmake/toolchains/riscv64-gnu.toolchain.cmake
@@ -2,12 +2,12 @@
# SPDX-License-Identifier: Apache-2.0
#
-# NOTE: use with the following docker image https://github.com/Incarnation-p-lee/riscv-docker-emulator#llvm-clang-tool-chain
+# NOTE: use with the following docker image https://github.com/Incarnation-p-lee/riscv-docker-emulator#gnu-toolchain
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR riscv64)
-set(RISCV_TOOLCHAIN_ROOT "/opt/riscv/gnu-toolchain/rv64-linux" CACHE PATH "Path to CLANG for RISC-V cross compiler build directory")
+set(RISCV_TOOLCHAIN_ROOT "/opt/riscv/gnu-toolchain/rv64-linux" CACHE PATH "Path to GCC for RISC-V cross compiler build directory")
set(CMAKE_SYSROOT "${RISCV_TOOLCHAIN_ROOT}/sysroot" CACHE PATH "RISC-V sysroot")
set(CMAKE_C_COMPILER_TARGET riscv64-unknown-linux-gnu)
@@ -26,9 +26,6 @@ set(CMAKE_OBJDUMP ${RISCV_TOOLCHAIN_ROOT}/bin/riscv64-unknown-linux-gnu-objdump)
set(CMAKE_READELF ${RISCV_TOOLCHAIN_ROOT}/bin/riscv64-unknown-linux-gnu-readelf)
set(PKG_CONFIG_EXECUTABLE "NOT-FOUND" CACHE PATH "Path to RISC-V pkg-config")
-# Don't run the linker on compiler check
-set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-L${CMAKE_SYSROOT}/lib")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-L${CMAKE_SYSROOT}/lib")
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-L${CMAKE_SYSROOT}/lib")
diff --git a/cmake/toolchains/riscv64.linux.toolchain.cmake b/cmake/toolchains/riscv64.linux.toolchain.cmake
new file mode 100644
index 00000000000..cb088f5eca5
--- /dev/null
+++ b/cmake/toolchains/riscv64.linux.toolchain.cmake
@@ -0,0 +1,13 @@
+# Copyright (C) 2018-2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+#
+
+# Install compiler on debian using:
+# apt-get install -y gcc-riscv64-linux-gnu g++-riscv64-linux-gnu binutils-riscv64-linux-gnu
+
+set(CMAKE_SYSTEM_NAME Linux)
+set(CMAKE_SYSTEM_PROCESSOR riscv64)
+
+set(CMAKE_C_COMPILER riscv64-linux-gnu-gcc)
+set(CMAKE_CXX_COMPILER riscv64-linux-gnu-g++)
+set(CMAKE_STRIP riscv64-linux-gnu-strip)
diff --git a/docs/dev/build_riscv64.md b/docs/dev/build_riscv64.md
index 13ab9e98d56..19d6e8714b4 100644
--- a/docs/dev/build_riscv64.md
+++ b/docs/dev/build_riscv64.md
@@ -16,15 +16,23 @@ The software was validated on the following devices:
- Python 3.10 for OpenVINO Runtime Python API
## How to build
+Currently, there are three ways to build OpenVINO Runtime for 64-bit RISC-V platforms:
+
+1. **Recommended**. The build with vectorized (using RVV instructions) primitives for limited scope of operations from [`SHL`](https://github.com/XUANTIE-RV/csi-nn2) using [`xuantie-gnu-toolchain`](https://github.com/XUANTIE-RV/). This GNU Compiler Toolchain supports RVV 0.7.1, ratified RVV 1.0 and Xuantie-specific instruction sets. The vector intrinsics don't use the common prefix `__riscv_`. This method provides the best performance available at the moment.
+2. The build without optimized primitives using [`riscv-gnu-toolchain`](https://github.com/riscv-collab/riscv-gnu-toolchain.git). This GNU Compiler Toolchain supports RVV 0.7.1 and ratified RVV 1.0. The vector intrinsics use the common prefix `__riscv_`. However, as mentioned earlier, this build method doesn't yet provide optimized primitives implemented using the RVV intrinsics.
+3. The build without optimized primitives using installed Linux packages. The compilers in these packages don't support RVV intrinsics.
+
+### Steps
+
0. Prerequisite:
-- For target with RVV - build `xuantie-gnu-toolchain` and `qemu`:
+- For target with vectorized primitives from `SHL` - build `xuantie-gnu-toolchain` and `qemu`:
```sh
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`:
+- For target without optimized primitives using `riscv-gnu-toolchain`:
```sh
git clone https://github.com/riscv-collab/riscv-gnu-toolchain.git
cd riscv-gnu-toolchain
@@ -32,6 +40,11 @@ The software was validated on the following devices:
make linux build-qemu -j$(nproc)
```
> **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).
+- For target without optimized primitives using installed Linux packages:
+ ```sh
+ apt-get update
+ apt-get install -y gcc-riscv64-linux-gnu g++-riscv64-linux-gnu binutils-riscv64-linux-gnu
+ ```
1. Clone OpenVINO repository and init submodules:
```sh
@@ -50,8 +63,8 @@ The software was validated on the following devices:
mkdir build && cd build
```
-4. To cross compile OpenVINO Runtime for RISC-V devices, run `cmake` with specified `CMAKE_TOOLCHAIN_FILE` and `RISCV_TOOLCHAIN_ROOT`.
-- For target with RVV:
+4. To cross compile OpenVINO Runtime for RISC-V devices, run `cmake` with specified `CMAKE_TOOLCHAIN_FILE` and `RISCV_TOOLCHAIN_ROOT` (the last one is needed only for build using GNU toolchain).
+- For target with vectorized primitives from `SHL`:
```sh
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
@@ -59,8 +72,8 @@ The software was validated on the following devices:
-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>` with `riscv64-071-thead-gnu.toolchain.cmake` for RVV 0.7.1 and `riscv64-100-thead-gnu.toolchain.cmake` for RVV 1.0 respectively.
-- For target without RVV:
+ > **NOTE**: To build OpenVINO Runtime for different versions of RVV, you just need to specify corresponding toolchain files. For example, you can replace `<toolchain_file>` with `riscv64-071-xuantie-gnu.toolchain.cmake` for RVV 0.7.1 and `riscv64-100-xuantie-gnu.toolchain.cmake` for RVV 1.0 respectively.
+- For target without optimized primitives using `riscv-gnu-toolchain`:
```sh
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
@@ -69,7 +82,13 @@ The software was validated on the following devices:
-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` 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.
-
+- For target without optimized primitives using installed Linux packages:
+ ```sh
+ cmake .. \
+ -DCMAKE_BUILD_TYPE=Release \
+ -DCMAKE_INSTALL_PREFIX=<openvino_install_path> \
+ -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/riscv64.linux.toolchain.cmake
+ ```
> **NOTE**: By default OpenVINO is built with OpenMP support on RISC-V devices.
Then run `make` to build the project:
diff --git a/src/plugins/intel_cpu/CMakeLists.txt b/src/plugins/intel_cpu/CMakeLists.txt
index 6965b7a25ce..04909c7d8f5 100644
--- a/src/plugins/intel_cpu/CMakeLists.txt
+++ b/src/plugins/intel_cpu/CMakeLists.txt
@@ -143,7 +143,7 @@ else()
endif()
ov_option(ENABLE_MLAS_FOR_CPU "Enable MLAS for OpenVINO CPU Plugin" ${ENABLE_MLAS_FOR_CPU_DEFAULT})
-if(RISCV64_THEAD)
+if(RISCV64_XUANTIE)
set(ENABLE_SHL_FOR_CPU_DEFAULT ON)
else()
set(ENABLE_SHL_FOR_CPU_DEFAULT OFF)
diff --git a/src/plugins/intel_cpu/thirdparty/onednn b/src/plugins/intel_cpu/thirdparty/onednn
index 1ce2d722922..c60a9946aa2 160000
--- a/src/plugins/intel_cpu/thirdparty/onednn
+++ b/src/plugins/intel_cpu/thirdparty/onednn
@@ -1 +1 @@
-Subproject commit 1ce2d722922efb80da52a6efe2152a9aecdddebf
+Subproject commit c60a9946aa2386890e5c9f5587974facb7624227