Skip to content

Commit

Permalink
[RISCV64] Added parallelism support for FC (#24352)
Browse files Browse the repository at this point in the history
### Details:
 - *Added parallelism support for FC*
 - *Enabled OpenMP on rv64 by default*
 - *PR to oneDNN: openvinotoolkit/oneDNN#260

### Tickets:
 - *N/A *

### Prerequisites:
- [x] #23901
- [x] #23964
- [x] #26175
  • Loading branch information
a-sidorova authored Aug 23, 2024
1 parent e56d7d7 commit d3096af
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
5 changes: 3 additions & 2 deletions cmake/features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 0 additions & 3 deletions cmake/toolchains/riscv64-071-thead-gnu.toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
3 changes: 0 additions & 3 deletions cmake/toolchains/riscv64-100-thead-gnu.toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 3 additions & 1 deletion docs/dev/build_riscv64.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class ShlFCExecutor : public Executor {

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>;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_cpu/thirdparty/onednn

0 comments on commit d3096af

Please sign in to comment.