Skip to content

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

[RISCV64] Added parallelism support for FC (#24352)

Alexandra Sidorovad3096afb11b9
diff --git a/cmake/features.cmake b/cmake/features.cmake
index d37c113e866..8709c48cc1c 100644
--- a/cmake/features.cmake
+++ b/cmake/features.cmake
@@ -85,10 +85,11 @@ ov_dependent_option (ENABLE_PKGCONFIG_GEN "Enable openvino.pc pkg-config file ge
#
# "OneDNN library based on OMP or TBB or Sequential implementation: TBB|OMP|SEQ"
-if(RISCV64 OR ANDROID)
- # oneDNN does not support non-SEQ for RISC-V architecture
+if(ANDROID)
# on Android we experience SEGFAULT during compilation
set(THREADING_DEFAULT "SEQ")
+elseif(RISCV64)
+ set(THREADING_DEFAULT "OMP")
else()
set(THREADING_DEFAULT "TBB")
endif()
diff --git a/cmake/toolchains/riscv64-071-thead-gnu.toolchain.cmake b/cmake/toolchains/riscv64-071-thead-gnu.toolchain.cmake
index 5062350a9e4..f5e9e68aabe 100644
--- a/cmake/toolchains/riscv64-071-thead-gnu.toolchain.cmake
+++ b/cmake/toolchains/riscv64-071-thead-gnu.toolchain.cmake
@@ -33,9 +33,6 @@ set(CMAKE_CXX_COMPILER ${RISCV_TOOLCHAIN_ROOT}/bin/riscv64-unknown-linux-gnu-g++
set(CMAKE_STRIP ${RISCV_TOOLCHAIN_ROOT}/bin/riscv64-unknown-linux-gnu-strip)
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_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} -march=rv64gcv0p7_zfh_xtheadc -mabi=lp64d")
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -march=rv64gcv0p7_zfh_xtheadc -mabi=lp64d")
diff --git a/cmake/toolchains/riscv64-100-thead-gnu.toolchain.cmake b/cmake/toolchains/riscv64-100-thead-gnu.toolchain.cmake
index 02b1cacd4fc..e00e30f9755 100644
--- a/cmake/toolchains/riscv64-100-thead-gnu.toolchain.cmake
+++ b/cmake/toolchains/riscv64-100-thead-gnu.toolchain.cmake
@@ -33,9 +33,6 @@ set(CMAKE_CXX_COMPILER ${RISCV_TOOLCHAIN_ROOT}/bin/riscv64-unknown-linux-gnu-g++
set(CMAKE_STRIP ${RISCV_TOOLCHAIN_ROOT}/bin/riscv64-unknown-linux-gnu-strip)
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_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} -march=rv64gcv1p0_zfh -mabi=lp64d")
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -march=rv64gcv1p0_zfh -mabi=lp64d")
diff --git a/docs/dev/build_riscv64.md b/docs/dev/build_riscv64.md
index 75d3782004f..13ab9e98d56 100644
--- a/docs/dev/build_riscv64.md
+++ b/docs/dev/build_riscv64.md
@@ -69,7 +69,9 @@ 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.
-
+
+ > **NOTE**: By default OpenVINO is built with OpenMP support on RISC-V devices.
+
Then run `make` to build the project:
```sh
make install -j$(nproc)
diff --git a/src/plugins/intel_cpu/src/nodes/executors/shl/shl_fullyconnected.cpp b/src/plugins/intel_cpu/src/nodes/executors/shl/shl_fullyconnected.cpp
index ede6d7511cc..ceb50d89830 100644
--- a/src/plugins/intel_cpu/src/nodes/executors/shl/shl_fullyconnected.cpp
+++ b/src/plugins/intel_cpu/src/nodes/executors/shl/shl_fullyconnected.cpp
@@ -121,19 +121,37 @@ bool ShlFCExecutor::update(const MemoryArgs& memory) {
src = src.cloneWithNewShape(memory.at(ARG_SRC)->getDescPtr()->getShape().getStaticDims());
dst = dst.cloneWithNewShape(memory.at(ARG_DST)->getDescPtr()->getShape().getStaticDims());
+ const auto src_shape = src.getShape();
+ const auto dst_shape = dst.getShape();
+ dim_M = std::accumulate(dst_shape.rbegin() + 1, dst_shape.rend(), size_t(1), std::multiplies<size_t>());
+ dim_In = src_shape.back();
+ dim_Out = dst_shape.back();
+ LDA = dim_In * memory.at(ARG_SRC)->getPrecision().size();
+ LDC = dim_Out * memory.at(ARG_DST)->getPrecision().size();
+
return true;
}
void ShlFCExecutor::execute(const MemoryArgs& memory) {
- src.setData(memory.at(ARG_SRC)->getData());
wei.setData(packedWeights->getData());
- dst.setData(memory.at(ARG_DST)->getData());
if (with_bias) {
bias.setData(memory.at(ARG_BIAS)->getData());
}
- OPENVINO_ASSERT(csinn_fullyconnected(src.get(), dst.get(), wei.get(), bias.get(), static_cast<csinn_fc_params*>(params.get())) == CSINN_TRUE,
- "ShlFCExecutor: failed to execute");
+ const auto nthreads = std::min(static_cast<int>(dim_M), parallel_get_max_threads());
+ parallel_nt(nthreads, [&](const int ithr, const int nthr) {
+ size_t dim_M0 = 0, dim_M1 = 0;
+ splitter(dim_M, nthr, ithr, dim_M0, dim_M1);
+
+ const auto M = dim_M1 - dim_M0;
+ auto src_tensor = src.cloneWithNewShape(ov::Shape{ M, dim_In });
+ auto dst_tensor = dst.cloneWithNewShape(ov::Shape{ M, dim_Out });
+ src_tensor.setData(reinterpret_cast<uint8_t*>(memory.at(ARG_SRC)->getData()) + dim_M0 * LDA);
+ dst_tensor.setData(reinterpret_cast<uint8_t*>(memory.at(ARG_DST)->getData()) + dim_M0 * LDC);
+
+ OPENVINO_ASSERT(csinn_fullyconnected(src_tensor.get(), dst_tensor.get(), wei.get(), bias.get(), static_cast<csinn_fc_params*>(params.get())) == CSINN_TRUE,
+ "ShlFCExecutor: failed to execute");
+ });
}
} // namespace intel_cpu
diff --git a/src/plugins/intel_cpu/src/nodes/executors/shl/shl_fullyconnected.hpp b/src/plugins/intel_cpu/src/nodes/executors/shl/shl_fullyconnected.hpp
index 129b2e35867..370ddb3d28c 100644
--- a/src/plugins/intel_cpu/src/nodes/executors/shl/shl_fullyconnected.hpp
+++ b/src/plugins/intel_cpu/src/nodes/executors/shl/shl_fullyconnected.hpp
@@ -38,6 +38,12 @@ private:
const MemoryCPtr packedWeights;
+ size_t dim_M = 0;
+ size_t dim_In = 0;
+ size_t dim_Out = 0;
+ size_t LDA = 0;
+ size_t LDC = 0;
+
bool with_bias = false;
};
using ShlFCExecutorPtr = std::shared_ptr<ShlFCExecutor>;
diff --git a/src/plugins/intel_cpu/thirdparty/onednn b/src/plugins/intel_cpu/thirdparty/onednn
index 6237cb7cc6d..740efd8194f 160000
--- a/src/plugins/intel_cpu/thirdparty/onednn
+++ b/src/plugins/intel_cpu/thirdparty/onednn
@@ -1 +1 @@
-Subproject commit 6237cb7cc6df3591bf0113fdc546fab724d4d55b
+Subproject commit 740efd8194fbc72ba4e495c7fe57c3cf51361048