-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add Initial Cross-Compilation Documentation for RISC-V Support #19239
Add Initial Cross-Compilation Documentation for RISC-V Support #19239
Conversation
#19238) ### Description This pull request introduces the necessary changes to enable RISC-V 64-bit cross-compiling support for the ONNX Runtime on Linux. The RISC-V architecture has gained popularity as an open standard instruction set architecture, and this contribution aims to extend ONNX Runtime's compatibility to include RISC-V, thereby broadening the reach of ONNX models to a wider range of devices. ### Motivation and Context RISC-V is a free and open-source instruction set architecture (ISA) based on established RISC principles. It is provided under open licenses without fees. Due to its extensibility and freedom in both software and hardware, RISC-V is poised for widespread adoption in the future, especially in applications related to AI, parallel computing, and data centers. ### Example Build Command ``` ./build.sh --parallel --config Debug --rv64 --riscv_toolchain_root=/path/to/toolchain/root --skip_tests ``` ### Documentation Updates Relevant sections of the documentation will be updated to reflect the newly supported RISC-V 64-bit cross-compilation feature. #19239 --------- Signed-off-by: Phoebe Chen <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@phoebesv I followed the instructions but encounter the error message
[ 51%] Building CXX object CMakeFiles/onnxruntime_providers_xnnpack.dir/home/yilyu/onnxruntime/onnxruntime/core/providers/shared/node_unit/node_unit.cc.o
/home/yilyu/risc-v/riscv/bin/riscv64-unknown-linux-gnu-g++ --sysroot=/home/yilyu/risc-v/riscv/sysroot -DEIGEN_MPL2_ONLY -DEIGEN_USE_THREADS -DNSYNC_ATOMIC_CPP11 -DONNX_ML=1 -DONNX_NAMESPACE=onnx -DONNX_USE_LITE_PROTO=1 -DORT_ENABLE_STREAM -DPLATFORM_POSIX -DUSE_XNNPACK=1 -D_GNU_SOURCE -D__ONNX_NO_DOC_STRINGS -I/home/yilyu/onnxruntime/build/Linux/RelWithDebInfo/risc-v/RelWithDebInfo/_deps/utf8_range-src -I/home/yilyu/onnxruntime/include/onnxruntime -I/home/yilyu/onnxruntime/include/onnxruntime/core/session -I/home/yilyu/onnxruntime/build/Linux/RelWithDebInfo/risc-v/RelWithDebInfo/_deps/google_nsync-src/public -I/home/yilyu/onnxruntime/build/Linux/RelWithDebInfo/risc-v/RelWithDebInfo -I/home/yilyu/onnxruntime/onnxruntime -I/home/yilyu/onnxruntime/build/Linux/RelWithDebInfo/risc-v/RelWithDebInfo/_deps/abseil_cpp-src -I/home/yilyu/onnxruntime/build/Linux/RelWithDebInfo/risc-v/RelWithDebInfo/_deps/safeint-src -I/home/yilyu/onnxruntime/build/Linux/RelWithDebInfo/risc-v/RelWithDebInfo/_deps/gsl-src/include -I/home/yilyu/onnxruntime/build/Linux/RelWithDebInfo/risc-v/RelWithDebInfo/_deps/onnx-src -I/home/yilyu/onnxruntime/build/Linux/RelWithDebInfo/risc-v/RelWithDebInfo/_deps/onnx-build -I/home/yilyu/onnxruntime/build/Linux/RelWithDebInfo/risc-v/RelWithDebInfo/_deps/protobuf-src/src -I/home/yilyu/onnxruntime/build/Linux/RelWithDebInfo/risc-v/RelWithDebInfo/_deps/googlexnnpack-src/include -I/home/yilyu/onnxruntime/build/Linux/RelWithDebInfo/risc-v/RelWithDebInfo/_deps/pthreadpool-src/include -I/home/yilyu/onnxruntime/build/Linux/RelWithDebInfo/risc-v/RelWithDebInfo/_deps/flatbuffers-src/include -I/home/yilyu/onnxruntime/build/Linux/RelWithDebInfo/risc-v/RelWithDebInfo/_deps/mp11-src/include -DNDEBUG -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -O3 -pipe -ggdb3 -fstack-clash-protection -ffunction-sections -fdata-sections -Wno-error=attributes -Wno-restrict -O2 -g -DNDEBUG -fPIC -Wall -Wextra -Wno-deprecated-copy -Wno-nonnull-compare -Werror -MD -MT CMakeFiles/onnxruntime_providers_xnnpack.dir/home/yilyu/onnxruntime/onnxruntime/core/providers/shared/node_unit/node_unit.cc.o -MF CMakeFiles/onnxruntime_providers_xnnpack.dir/home/yilyu/onnxruntime/onnxruntime/core/providers/shared/node_unit/node_unit.cc.o.d -o CMakeFiles/onnxruntime_providers_xnnpack.dir/home/yilyu/onnxruntime/onnxruntime/core/providers/shared/node_unit/node_unit.cc.o -c /home/yilyu/onnxruntime/onnxruntime/core/providers/shared/node_unit/node_unit.cc
In file included from /home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/string:51,
from /home/yilyu/onnxruntime/onnxruntime/core/providers/shared/node_unit/node_unit.h:6,
from /home/yilyu/onnxruntime/onnxruntime/core/providers/shared/node_unit/node_unit.cc:4:
In static member function 'static _Up* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp = const onnxruntime::Node* const; _Up = const onnxruntime::Node*; bool _IsMove = false]',
inlined from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = const onnxruntime::Node* const*; _OI = const onnxruntime::Node**]' at /home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/bits/stl_algobase.h:506:30,
inlined from '_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II = const onnxruntime::Node* const*; _OI = const onnxruntime::Node**]' at /home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/bits/stl_algobase.h:533:42,
inlined from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = __gnu_cxx::__normal_iterator<const onnxruntime::Node* const*, vector<const onnxruntime::Node*> >; _OI = const onnxruntime::Node**]' at /home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/bits/stl_algobase.h:540:31,
inlined from '_OI std::copy(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<const onnxruntime::Node* const*, vector<const onnxruntime::Node*> >; _OI = const onnxruntime::Node**]' at /home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/bits/stl_algobase.h:633:7,
inlined from 'static _ForwardIterator std::__uninitialized_copy::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const onnxruntime::Node* const*, std::vector<const onnxruntime::Node*> >; _ForwardIterator = const onnxruntime::Node**]' at /home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/bits/stl_uninitialized.h:147:27,
inlined from '_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const onnxruntime::Node* const*, vector<const onnxruntime::Node*> >; _ForwardIterator = const onnxruntime::Node**]' at /home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/bits/stl_uninitialized.h:185:15,
inlined from '_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<const onnxruntime::Node* const*, vector<const onnxruntime::Node*> >; _ForwardIterator = const onnxruntime::Node**; _Tp = const onnxruntime::Node*]' at /home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/bits/stl_uninitialized.h:373:37,
inlined from 'void std::vector<_Tp, _Alloc>::_M_range_insert(iterator, _ForwardIterator, _ForwardIterator, std::forward_iterator_tag) [with _ForwardIterator = __gnu_cxx::__normal_iterator<const onnxruntime::Node* const*, std::vector<const onnxruntime::Node*> >; _Tp = const onnxruntime::Node*; _Alloc = std::allocator<const onnxruntime::Node*>]' at /home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/bits/vector.tcc:814:38,
inlined from 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, _InputIterator, _InputIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const onnxruntime::Node* const*, std::vector<const onnxruntime::Node*> >; = void; _Tp = const onnxruntime::Node*; _Alloc = std::allocator<const onnxruntime::Node*>]' at /home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/bits/stl_vector.h:1483:19,
inlined from 'std::vector<const onnxruntime::Node*> onnxruntime::NodeUnit::GetAllNodesInGroup() const' at /home/yilyu/onnxruntime/onnxruntime/core/providers/shared/node_unit/node_unit.cc:271:19:
/home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/bits/stl_algobase.h:437:30: error: 'void* __builtin_memmove(void*, const void*, long unsigned int)' writing between 9 and 9223372036854775800 bytes into a region of size 0 overflows the destination [-Werror=stringop-overflow=]
437 | __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/riscv64-unknown-linux-gnu/bits/c++allocator.h:33,
from /home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/bits/allocator.h:46,
from /home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/string:43:
In member function '_Tp* std::__new_allocator<_Tp>::allocate(size_type, const void*) [with _Tp = const onnxruntime::Node*]',
inlined from 'static _Tp* std::allocator_traits<std::allocator<_CharT> >::allocate(allocator_type&, size_type) [with _Tp = const onnxruntime::Node*]' at /home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/bits/alloc_traits.h:482:28,
inlined from 'std::_Vector_base<_Tp, _Alloc>::pointer std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp = const onnxruntime::Node*; _Alloc = std::allocator<const onnxruntime::Node*>]' at /home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/bits/stl_vector.h:378:33,
inlined from 'std::_Vector_base<_Tp, _Alloc>::pointer std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp = const onnxruntime::Node*; _Alloc = std::allocator<const onnxruntime::Node*>]' at /home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/bits/stl_vector.h:375:7,
inlined from 'void std::vector<_Tp, _Alloc>::_M_range_insert(iterator, _ForwardIterator, _ForwardIterator, std::forward_iterator_tag) [with _ForwardIterator = __gnu_cxx::__normal_iterator<const onnxruntime::Node* const*, std::vector<const onnxruntime::Node*> >; _Tp = const onnxruntime::Node*; _Alloc = std::allocator<const onnxruntime::Node*>]' at /home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/bits/vector.tcc:805:40,
inlined from 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, _InputIterator, _InputIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const onnxruntime::Node* const*, std::vector<const onnxruntime::Node*> >; = void; _Tp = const onnxruntime::Node*; _Alloc = std::allocator<const onnxruntime::Node*>]' at /home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/bits/stl_vector.h:1483:19,
inlined from 'std::vector<const onnxruntime::Node*> onnxruntime::NodeUnit::GetAllNodesInGroup() const' at /home/yilyu/onnxruntime/onnxruntime/core/providers/shared/node_unit/node_unit.cc:271:19:
/home/yilyu/risc-v/riscv/riscv64-unknown-linux-gnu/include/c++/13.2.0/bits/new_allocator.h:147:55: note: at offset [-9223372036854775808, -1] into destination object of size [8, 9223372036854775800] allocated by 'operator new'
147 | return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n * sizeof(_Tp)));
| ^
cc1plus: all warnings being treated as errors
@yihonglyu
Could you try using the default ORT compile option to build it? |
I also found that there would be no flatbuffer issue by using config debug. I will update the documentation to use the Debug configuration until the FlatBuffers issue is resolved. I think this will provide a more stable build. |
a6dc816
to
9e7be4e
Compare
That is really weird that it would work with Debug option but fail on other option. Could you possibly explain why this is happening? |
The compiler optimization levels for Debug and RelWithDebInfo are different, so it is possible that this problem only affects Rel. |
In general we do not treat warnings from third-party libraries as errors, since there is very little thing we can do. Therefore, we may remove "-Werror" from the patch file. |
Thanks for informing me about this. I will submit a separate pull request to address the issue with the flatbuffer. |
xnnpack is optional, I added optional annotations in the document, hoping to provide a better understanding that xnnpack is not a mandatory option. |
9e7be4e
to
97f267d
Compare
97f267d
to
ff27131
Compare
Signed-off-by: Phoebe Chen <[email protected]>
ff27131
to
db06b1a
Compare
@phoebesv, I’ve checkout out the branch at #19296 and attempted to build and test it using the command |
@yihonglyu Our initial RISC-V PR focused on adding cross-compilation support to ORT, not all tests are enabled yet, so we've included 'skip_tests' in the build command. Considering the large number of onnx test cases and the complexities of supporting RISC-V, an initial pull request cannot possibly cover every test scenario. By enabling cross-compilation, we hope to encourage contributions to gradually enhance RISC-V support for more scenarios. |
### Description Building on g++ 13.2.0 results in -Wstringop-overread errors on Linux. This commit addresses the flatbuffer build issue with the following changes: 1. Remove the Werror flag in the flarbuffer patch. 2. Add a compilation option to suppress the 'stringop-overflow' error in the Flatbuffers within the xnnpack provider. ### Motivation and Context google/flatbuffers#8119 #19239 Signed-off-by: Phoebe Chen <[email protected]>
@phoebesv Thanks for supporting compiling onnxruntime for riscv64. I have successfully compiled onnxruntime for riscv64. Is that expected? Does it only support cross-compiling onnxruntime for riscv64 but the correctness has not been tested yet? |
@csukuangfj Yes. We currently have test scalar code by UT onnxruntime_test_all on qemu (using xnnpack EP), with multiple failed test cases. Unfortunately, we do not have enough resources to clean up all of the failed test instances. |
Is it possible to use the default CPU provider instead of the |
Is there a place to find the failed tests and find whom working on which failed test? |
Update the document for PR: Enable Cross-Compiling Support for ONNX Runtime on Linux for RISC-V 64-bit.
#19238