Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
BHbean opened this issue Mar 31, 2024 · 3 comments
Open
2 tasks done

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

BHbean opened this issue Mar 31, 2024 · 3 comments

Comments

@BHbean
Copy link
Contributor

BHbean commented Mar 31, 2024

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

  • I want to contribute the above guidance to existing docs, what should I do?
  • I want to make PRs for the oneDNN repo to adapt the above changes, but there are a upstream repo and a fork made by openvinotoolkit. Which one should I contribute to?
  • Someone is also bothered by FlatBuffers (see this issue). It does not seem to be elegant to copy some head files. How to solve this issue?

Build scrip or step-by-step to reproduce

No response

Relevant log output

No response

Issue submission checklist

  • I'm reporting an issue. It's not a question.
  • I checked the problem with the documentation, FAQ, open issues, Stack Overflow, etc., and have not found a solution.
@ilya-lavrenov
Copy link
Contributor

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
Copy link
Contributor Author

BHbean commented Apr 1, 2024

@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 <RISCV_TOOLCHAIN_ROOT>/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
Copy link
Contributor

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.

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

  • we use flatc to compile .fs files to .cpp
  • headers (either on build or host system) are used during compilation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants