openvinotoolkit / openvino

OpenVINO™ is an open-source toolkit for optimizing and deploying AI inference
https://docs.openvino.ai
Apache License 2.0
6.68k stars 2.15k forks source link

[Build] [RISC-V]: issues on cross-compiling for RISC-V target #23784

Open BHbean opened 4 months ago

BHbean commented 4 months ago

OpenVINO Version

tag 2024.0.0

Operating System

Ubuntu 22.04 (LTS)

Hardware Architecture

RISC-V

Target Platform

No response

Build issue description

Hi there!

I have been trying to cross-compile openvino for RISC-V target with rv64gcv arch recently, and I finally succeeded. However, it took me much effort due to unexpected issues on its submodules. Therefore, I want to open a new issue here to discuss the problems I met and give basic guidance for those who have the same problems.

Modification Guidance

The problems mainly lie in two submodules: oneDNN and FlatBuffers.

oneDNN

  1. Due to the evolution of the RVV intrinsic spec, the new compilers DO NOT support the old definitions of RVV intrinsics, presented in src/plugins/intel_cpu/thirdparty/onednn/src/cpu/rv64/rvv_nchw_pooling.cpp. Therefore. it is a must to add compatible headers to make old ones effective again. These headers can take OpenCV as a reference and be added to the afore-mentioned file.

  2. When the compiling process meets the src/plugins/intel_cpu/thirdparty/onednn/src/cpu/rv64/rvv_nchw_pooling.hpp file, it will prompt an error: error: base class has incomplete type. This problem can be solved by introducing the header file containing the definition of primitive_t class, like the following:

    // src/plugins/intel_cpu/thirdparty/onednn/src/cpu/rv64/rvv_nchw_pooling.hpp
    
    #ifndef RV64_NCHW_POOLING_HPP
    #define RV64_NCHW_POOLING_HPP
    
    #include "cpu/cpu_pooling_pd.hpp"
    #include "common/primitive.hpp"   // <== add here
    
    ...

FlatBuffers

  1. The newest version of FlatBuffers compiler will generate some files under the build dir automatically, like build/src/frontends/tensorflow_lite/src/schema_generated.h. Inside these files, the flatbuffers/flatbuffers.h head file is included, which can be easily found under /usr/include path in common linux systems. However, it does not exsit in the target sysroot, so we have to copy the whole /usr/include/flatbuffers dir into our target sysroot:
    $ sudo cp /usr/include/flatbuffers <RISCV_TOOLCHAIN_ROOT>/sysroot/usr/include -r

Following the above steps, openvino can be successfully build for RISC-V target using this toolchain file.

Discussion

Build scrip or step-by-step to reproduce

No response

Relevant log output

No response

Issue submission checklist

ilya-lavrenov commented 4 months ago

Hi @BHbean Could you please send those suggestions as PR to https://github.com/oneapi-src/oneDNN ?

Inside these files, the flatbuffers/flatbuffers.h head file is included, which can be easily found under /usr/include path in common linux systems

I did not quite follow this problem, it was an intention that even during cross-compilation we use headers from native system (e.g. /usr/include), see https://github.com/openvinotoolkit/openvino/blob/master/thirdparty/dependencies.cmake#L397. Why do you need to copy to <RISCV_TOOLCHAIN_ROOT>/sysroot/usr/include if it can work with /usr/include ?

BHbean commented 4 months ago

@ilya-lavrenov Thanks for your reply!

Could you please send those suggestions as PR to https://github.com/oneapi-src/oneDNN ?

Of course! I will propose a PR to https://github.com/oneapi-src/oneDNN later.

I did not quite follow this problem, it was an intention that even during cross-compilation we use headers from native system (e.g. /usr/include), see https://github.com/openvinotoolkit/openvino/blob/master/thirdparty/dependencies.cmake#L397. Why do you need to copy to /sysroot/usr/include if it can work with /usr/include ?

I am not so sure why this was happening, probably due to the sysroot set in the toolchain file? The command used for my build is:

$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=<openvino_repo>/cmake/toolchains/riscv64-gnu.toolchain.cmake ..

_Note: BTW, simply cross-compiling the thirdparty/flatbuffers/flatbuffers lib and installing it under <RISCV_TOOLCHAIN_ROOT>/sysroot/usr/include does not work, due to mismatch of versions._

ilya-lavrenov commented 4 months ago

Note: BTW, simply cross-compiling the thirdparty/flatbuffers/flatbuffers lib and installing it under /sysroot/usr/include does not work, due to mismatch of versions.

We don't need to cross-compile flatbuffers, because it's used as build system tool: