Open hgaiser opened 1 year ago
Which version of flatbuffers do you have there?
About the target names, I think the lib provides 3 cmake files that:
FlatBuffersTargets.cmake
FlatcTargets.cmake
FlatBuffersSharedTargets.cmake
We might be able to find some cmake variable names in these files to use. We can use a cmake variable to replace the hardcoded flatbuffers::flatbuffers, or we try to manually detect if the target exists.
It's in the title :p 23.3.3.
I found later that onnxruntime requires 1.12.0, however I couldn't install it easily.
But in https://github.com/microsoft/onnxruntime/blob/main/cmake/external/onnxruntime_external_deps.cmake we have:
FIND_PACKAGE_ARGS 1.12.0...<2.0.0 NAMES Flatbuffers
How could 23.3.3 fit into the 1.12.0...<2.0.0
range?
But in https://github.com/microsoft/onnxruntime/blob/main/cmake/external/onnxruntime_external_deps.cmake we have:
FIND_PACKAGE_ARGS 1.12.0...<2.0.0 NAMES Flatbuffers
How could 23.3.3 fit into the
1.12.0...<2.0.0
range?
Interesting question :). I dug a little deeper and found the following about find_package:
When a version range is specified but the package is only designed to expect a single version, the package will ignore the upper end point of the range and only take the single version at the lower end of the range into account.
My guess is that this is happening, though I'm not sure and my CMake skills aren't great :p
What I can confirm is that the call here is calling this with the following arguments:
find_package(flatbuffers QUIET 1.12.0...<2.0.0 NAMES Flatbuffers)
And after that, flatbuffers_FOUND
is equal to 1, and flatbuffers_VERSION
is set to 23.3.3
.
Additionally, I tried this CMakeLists.txt
:
project(test)
cmake_minimum_required(VERSION 3.24)
find_package(flatbuffers QUIET 1.12.0...<2.0.0 NAMES Flatbuffers)
message("Found ${flatbuffers_FOUND}")
message("Version ${flatbuffers_VERSION}")
Which outputs this:
Found 1
Version 23.3.3
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/2023-03-10-15-52-39
I read the "Config Mode Version Selection" section. I think it means that many packages' cmake scripts do not support version ranges, therefore they only pass the lower-end of the version range to the scripts. This is disappointed. Let me see if I can use if..defs to make the C/C++ code be compatible with mulitple flatbuffer versions.
ugly as F patch(?)
diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake
index 0c41945778..39e3fc89e7 100644
--- a/cmake/external/onnxruntime_external_deps.cmake
+++ b/cmake/external/onnxruntime_external_deps.cmake
@@ -288,6 +288,9 @@ namespace std { using ::getenv; }
target_compile_options(flatc PRIVATE /FI${CMAKE_BINARY_DIR}/gdk_cstdlib_wrapper.h)
endif()
endif()
+else()
+ add_executable(flatc ALIAS flatbuffers::flatc)
+ add_library(flatbuffers::flatbuffers ALIAS flatbuffers::flatbuffers_shared)
endif()
if (onnxruntime_BUILD_UNIT_TESTS)
It will only partly solve the problem, because even if it correctly sets the target, my version of flatbuffers is incompatible with onnxruntime. Meaning compilation would still fail with your patch.
i have te same version of flatbuffers and builds ok (with the patch above) onnxruntime v1.14.1
i have te same version of flatbuffers and builds ok (with the patch above) onnxruntime v1.14.1
Weird, I applied the patch, but I'm getting the following (also on v1.14.1) :
onnxruntime/core/flatbuffers/schema/ort.fbs.h:2732:33: error: no matching function for call to ‘onnxruntime::fbs::ArgTypeAndIndex::VerifyField<uint32_t>(flatbuffers::Verifier&, onnxruntime::fbs::ArgTypeAndIndex::FlatBuffersVTableOffset) const’
2732 | VerifyField<uint32_t>(verifier, VT_INDEX) &&
/usr/include/flatbuffers/table.h:115:8: note: candidate: ‘template<class T> bool flatbuffers::Table::VerifyField(const flatbuffers::Verifier&, flatbuffers::voffset_t, size_t) const’
115 | bool VerifyField(const Verifier &verifier, voffset_t field,
| ^~~~~~~~~~~
/usr/include/flatbuffers/table.h:115:8: note: candidate expects 3 arguments, 2 provided
I'm guessing that's because of some interface change, but I'm not sure.
try my pkgbuild (used the [AUR] pkgbuild as base)
python-onnxruntime-1.14.1-1.src.tar.gz
i have dissabled the tensorrt build due this issue https://github.com/microsoft/onnxruntime/issues/15131. "base" and cuda support build ok
greetings
try my pkgbuild (used the [AUR] pkgbuild as base)
python-onnxruntime-1.14.1-1.src.tar.gz
i have dissabled the tensorrt build due this issue #15131. "base" and cuda support build ok
greetings
Weird, that PKGBUILD does indeed seem to compile. I'm curious what you get when you try to run build.sh
with your patch applied? That did not compile for me.
I made a PR for adding flatbuffers as a submodule, instead of relying on the system installed flatbuffers: https://github.com/microsoft/onnxruntime/pull/15205
With that PR I can compile using build.sh
.
i never try to build with build.sh, in personal preference, i prefeer do all by hand.
how i can "print" the options set the build.sh script (build.py) in cmake?
greetings
i never try to build with build.sh, in personal preference, i prefeer do all by hand.
how i can "print" the options set the build.sh script (build.py) in cmake?
greetings
Yep I can respect that, I prefer the same, but didn't want to figure out which flags I needed. By the way, your PKGBUILD didn't actually compile for me. It failed later in the build process with this error:
onnxruntime/core/providers/cpu/tensor/scatter.cc:343:25: error: array subscript -1 is outside array bounds of ‘long int [1152921504606846975]’ [-Werror=array-bounds]
343 | dim_block_size.back() = 1;
| ~~~~~~~~~~~~~~~~~~~~~~^~~
As for the command, it seems to run:
cmake cmake -Donnxruntime_RUN_ONNX_TESTS=OFF -Donnxruntime_GENERATE_TEST_REPORTS=ON -DPython_EXECUTABLE=/usr/bin/python3 -DPYTHON_EXECUTABLE=/usr/bin/python3 -Donnxruntime_USE_MIMALLOC=OFF -Donnxruntime_ENABLE_PYTHON=OFF -Donnxruntime_BUILD_CSHARP=OFF -Donnxruntime_BUILD_JAVA=OFF -Donnxruntime_BUILD_NODEJS=OFF -Donnxruntime_BUILD_OBJC=OFF -Donnxruntime_BUILD_SHARED_LIB=OFF -Donnxruntime_BUILD_APPLE_FRAMEWORK=OFF -Donnxruntime_USE_DNNL=OFF -Donnxruntime_USE_NNAPI_BUILTIN=OFF -Donnxruntime_USE_RKNPU=OFF -Donnxruntime_USE_LLVM=OFF -Donnxruntime_ENABLE_MICROSOFT_INTERNAL=OFF -Donnxruntime_USE_VITISAI=OFF -Donnxruntime_USE_TENSORRT=OFF -Donnxruntime_SKIP_AND_PERFORM_FILTERED_TENSORRT_TESTS=ON -Donnxruntime_USE_TENSORRT_BUILTIN_PARSER=OFF -Donnxruntime_TENSORRT_PLACEHOLDER_BUILDER=OFF -Donnxruntime_USE_TVM=OFF -Donnxruntime_TVM_CUDA_RUNTIME=OFF -Donnxruntime_TVM_USE_HASH=OFF -Donnxruntime_USE_MIGRAPHX=OFF -Donnxruntime_CROSS_COMPILING=OFF -Donnxruntime_DISABLE_CONTRIB_OPS=OFF -Donnxruntime_DISABLE_ML_OPS=OFF -Donnxruntime_DISABLE_RTTI=OFF -Donnxruntime_DISABLE_EXCEPTIONS=OFF -Donnxruntime_MINIMAL_BUILD=OFF -Donnxruntime_EXTENDED_MINIMAL_BUILD=OFF -Donnxruntime_MINIMAL_BUILD_CUSTOM_OPS=OFF -Donnxruntime_REDUCED_OPS_BUILD=OFF -Donnxruntime_ENABLE_LANGUAGE_INTEROP_OPS=OFF -Donnxruntime_USE_DML=OFF -Donnxruntime_USE_WINML=OFF -Donnxruntime_BUILD_MS_EXPERIMENTAL_OPS=OFF -Donnxruntime_USE_TELEMETRY=OFF -Donnxruntime_ENABLE_LTO=OFF -Donnxruntime_USE_ACL=OFF -Donnxruntime_USE_ACL_1902=OFF -Donnxruntime_USE_ACL_1905=OFF -Donnxruntime_USE_ACL_1908=OFF -Donnxruntime_USE_ACL_2002=OFF -Donnxruntime_USE_ARMNN=OFF -Donnxruntime_ARMNN_RELU_USE_CPU=ON -Donnxruntime_ARMNN_BN_USE_CPU=ON -Donnxruntime_ENABLE_NVTX_PROFILE=OFF -Donnxruntime_ENABLE_TRAINING=OFF -Donnxruntime_ENABLE_TRAINING_OPS=OFF -Donnxruntime_ENABLE_TRAINING_APIS=OFF -Donnxruntime_ENABLE_CPU_FP16_OPS=OFF -Donnxruntime_USE_NCCL=OFF -Donnxruntime_BUILD_BENCHMARKS=OFF -Donnxruntime_USE_ROCM=OFF -DOnnxruntime_GCOV_COVERAGE=OFF -Donnxruntime_USE_MPI=OFF -Donnxruntime_ENABLE_MEMORY_PROFILE=OFF -Donnxruntime_ENABLE_CUDA_LINE_NUMBER_INFO=OFF -Donnxruntime_BUILD_WEBASSEMBLY=OFF -Donnxruntime_BUILD_WEBASSEMBLY_STATIC_LIB=OFF -Donnxruntime_ENABLE_WEBASSEMBLY_EXCEPTION_CATCHING=ON -Donnxruntime_ENABLE_WEBASSEMBLY_API_EXCEPTION_CATCHING=OFF -Donnxruntime_ENABLE_WEBASSEMBLY_EXCEPTION_THROWING=ON -Donnxruntime_WEBASSEMBLY_RUN_TESTS_IN_BROWSER=OFF -Donnxruntime_ENABLE_WEBASSEMBLY_THREADS=OFF -Donnxruntime_ENABLE_WEBASSEMBLY_DEBUG_INFO=OFF -Donnxruntime_ENABLE_WEBASSEMBLY_PROFILING=OFF -Donnxruntime_ENABLE_EAGER_MODE=OFF -Donnxruntime_ENABLE_LAZY_TENSOR=OFF -Donnxruntime_ENABLE_EXTERNAL_CUSTOM_OP_SCHEMAS=OFF -Donnxruntime_ENABLE_CUDA_PROFILING=OFF -Donnxruntime_ENABLE_ROCM_PROFILING=OFF -Donnxruntime_USE_XNNPACK=OFF -Donnxruntime_USE_CANN=OFF -DCMAKE_TLS_VERIFY=ON -DFETCHCONTENT_QUIET=OFF -Donnxruntime_PYBIND_EXPORT_OPSCHEMA=OFF -Donnxruntime_ENABLE_MEMLEAK_CHECKER=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=build/Linux/Debug/installed
Followed by:
cmake --build build/Linux/Debug --config Debug
we also get
onnxruntime/core/providers/cpu/tensor/scatter.cc:343:25: error: array subscript -1 is outside array bounds of ‘long int [1152921504606846975]’ [-Werror=array-bounds]
343 | dim_block_size.back() = 1;
for onnxruntime 1.41.1 with GCC 12.2.1. Note that 1.14.1 builds fine with gcc 11.2/11.3
I was able to build v1.14.1 with the following change
- dim_block_size.back() = 1;
+ dim_block_size[num_dims-1] = 1;
1.15.0 is out, and now start build failure with flatbuffers 23.5.26
a little snip. the full log generate 3.7Mg of log with -j1
[ 3%] Building CXX object CMakeFiles/onnxruntime_flatbuffers.dir/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.cc.o
/opt/cuda/bin/g++ -DCPUINFO_SUPPORTED_PLATFORM=1 -DDNNL_OPENMP -DEIGEN_MPL2_ONLY -DEIGEN_USE_THREADS -DENABLE_ATEN -DENABLE_CPU_FP16_TRAINING_OPS -DENABLE_STRIDED_TENSORS -DENABLE_TRAINING -DENABLE_TRAINING_APIS -DENABLE_TRAINING_CORE -DENABLE_TRAINING_OPS -DNSYNC_ATOMIC_CPP11 -DONNX_ML=1 -DONNX_NAMESPACE=onnx -DONNX_USE_LITE_PROTO=1 -DORT_ENABLE_STREAM -DORT_USE_NCCL=1 -DPLATFORM_POSIX -DPROTOBUF_USE_DLLS -DUSE_CUDA=1 -DUSE_DNNL=1 -DUSE_FLASH_ATTENTION=1 -DUSE_MPI=1 -DUSE_NCCL_P2P=1 -D_GNU_SOURCE -D__ONNX_NO_DOC_STRINGS -I/tmp/makepkg/python-onnxruntime/src/onnxruntime/include/onnxruntime -I/tmp/makepkg/python-onnxruntime/src/onnxruntime/include/onnxruntime/core/session -I/tmp/makepkg/python-onnxruntime/src/onnxruntime/orttraining/orttraining/training_api/include -I/tmp/makepkg/python-onnxruntime/src/build/_deps/pytorch_cpuinfo-src/include -I/tmp/makepkg/python-onnxruntime/src/build -I/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime -I/tmp/makepkg/python-onnxruntime/src/onnxruntime/orttraining -I/tmp/makepkg/python-onnxruntime/src/build/_deps/onnx-src -I/tmp/makepkg/python-onnxruntime/src/build/_deps/onnx-build -I/tmp/makepkg/python-onnxruntime/src/build/_deps/gsl-src/include -march=native -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=0 -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -Wp,-D_GLIBCXX_ASSERTIONS -g -ffile-prefix-map=/tmp/makepkg/python-onnxruntime/src=/usr/src/debug/python-onnxruntime -Wno-maybe-uninitialized -ffunction-sections -fdata-sections -DCPUINFO_SUPPORTED -g -std=gnu++17 -fPIC -Wall -Wextra -Wno-deprecated-copy -Wno-nonnull-compare -Werror -MD -MT CMakeFiles/onnxruntime_flatbuffers.dir/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.cc.o -MF CMakeFiles/onnxruntime_flatbuffers.dir/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.cc.o.d -o CMakeFiles/onnxruntime_flatbuffers.dir/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.cc.o -c /tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.cc
In file included from /usr/include/flatbuffers/array.h:25,
from /usr/include/flatbuffers/flatbuffers.h:24,
from /tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/schema/ort.fbs.h:7,
from /tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.cc:8:
/usr/include/flatbuffers/vector.h:148:56: error: redeclared with 2 template parameters
148 | template<typename T, typename SizeT = uoffset_t> class Vector {
| ^~~~~~
In file included from /tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.cc:4:
/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.h:25:7: note: previous declaration 'template<class T> class flatbuffers::Vector' used 1 template parameter
25 | class Vector;
| ^~~~~~
/usr/include/flatbuffers/vector.h:304:60: error: wrong number of template arguments (2, should be 1)
304 | template<typename T> using Vector64 = Vector<T, uoffset64_t>;
| ^
/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.h:25:7: note: provided for 'template<class T> class flatbuffers::Vector'
25 | class Vector;
| ^~~~~~
In file included from /usr/include/flatbuffers/buffer_ref.h:21,
from /usr/include/flatbuffers/flatbuffers.h:27:
/usr/include/flatbuffers/verifier.h:121:41: error: wrong number of template arguments (2, should be 1)
121 | bool VerifyVector(const Vector<T, LenT> *const vec) const {
| ^
/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.h:25:7: note: provided for 'template<class T> class flatbuffers::Vector'
25 | class Vector;
| ^~~~~~
/usr/include/flatbuffers/verifier.h:128:49: error: wrong number of template arguments (2, should be 1)
128 | bool VerifyVector(const Vector<const T *, LenT> *const vec) const {
| ^
/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.h:25:7: note: provided for 'template<class T> class flatbuffers::Vector'
25 | class Vector;
| ^~~~~~
/usr/include/flatbuffers/verifier.h:128:8: error: 'template<int& ...<anonymous>, class T, class LenT> bool flatbuffers::Verifier::VerifyVector(const int*) const' cannot be overloaded with 'template<int& ...<anonymous>, class T, class LenT> bool flatbuffers::Verifier::VerifyVector(const int*) const'
128 | bool VerifyVector(const Vector<const T *, LenT> *const vec) const {
| ^~~~~~~~~~~~
/usr/include/flatbuffers/verifier.h:121:8: note: previous declaration 'template<int& ...<anonymous>, class T, class LenT> bool flatbuffers::Verifier::VerifyVector(const int*) const'
121 | bool VerifyVector(const Vector<T, LenT> *const vec) const {
| ^~~~~~~~~~~~
/usr/include/flatbuffers/verifier.h:224:58: error: wrong number of template arguments (2, should be 1)
224 | bool VerifyNestedFlatBuffer(const Vector<uint8_t, SizeT> *const buf,
| ^
/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.h:25:7: note: provided for 'template<class T> class flatbuffers::Vector'
25 | class Vector;
| ^~~~~~
/usr/include/flatbuffers/verifier.h: In member function 'bool flatbuffers::Verifier::VerifyVector(const int*) const':
/usr/include/flatbuffers/verifier.h:129:62: error: wrong number of template arguments (2, should be 1)
129 | return VerifyVector(reinterpret_cast<const Vector<T, LenT> *>(vec));
| ^
/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.h:25:7: note: provided for 'template<class T> class flatbuffers::Vector'
25 | class Vector;
| ^~~~~~
Even I am seeing this issue while building onnxruntime v1.16.3 with flatbuffers 23.5.26.
In file included from $PREFIX/include/flatbuffers/buffer_ref.h:21,
from $PREFIX/include/flatbuffers/flatbuffers.h:27,
from $SRC_DIR/onnxruntime/core/flatbuffers/schema/ort.fbs.h:7,
from $SRC_DIR/onnxruntime/core/graph/op_identifier_utils.cc:7:
$PREFIX/include/flatbuffers/verifier.h:121:41: error: wrong number of template arguments (2, should be 1)
121 | bool VerifyVector(const Vector<T, LenT> *const vec) const {
| ^
In file included from $SRC_DIR/onnxruntime/core/graph/op_identifier_utils.cc:6:
$SRC_DIR/onnxruntime/core/flatbuffers/flatbuffers_utils.h:25:7: note: provided for 'template<class T> class flatbuffers::Vector'
25 | class Vector;
| ^~~~~~
In file included from $PREFIX/include/flatbuffers/buffer_ref.h:21,
from $PREFIX/include/flatbuffers/flatbuffers.h:27,
from $SRC_DIR/onnxruntime/core/flatbuffers/schema/ort.fbs.h:7,
from $SRC_DIR/onnxruntime/core/graph/op_identifier_utils.cc:7:
$PREFIX/include/flatbuffers/verifier.h:128:49: error: wrong number of template arguments (2, should be 1)
128 | bool VerifyVector(const Vector<const T *, LenT> *const vec) const {
| ^
In file included from $SRC_DIR/onnxruntime/core/graph/op_identifier_utils.cc:6:
$SRC_DIR/onnxruntime/core/flatbuffers/flatbuffers_utils.h:25:7: note: provided for 'template<class T> class flatbuffers::Vector'
25 | class Vector;
| ^~~~~~
In file included from $PREFIX/include/flatbuffers/buffer_ref.h:21,
from $PREFIX/include/flatbuffers/flatbuffers.h:27,
from $SRC_DIR/onnxruntime/core/flatbuffers/schema/ort.fbs.h:7,
from $SRC_DIR/onnxruntime/core/graph/op_identifier_utils.cc:7:
$PREFIX/include/flatbuffers/verifier.h:128:8: error: 'template<int& ...<anonymous>, class T, class LenT> bool flatbuffers::Verifier::VerifyVector(const int*) const' cannot be overloaded with 'template<int& ...<anonymous>, class T, class LenT> bool flatbuffers::Verifier::VerifyVector(const int*) const'
128 | bool VerifyVector(const Vector<const T *, LenT> *const vec) const {
Is there a workaround known for this issue?
yes. disable cmake detection with
-DCMAKE_IGNORE_PATH=/usr/lib/cmake/flatbuffers/\;/lib/cmake/flatbuffers
(set the distro path manually)
Or adding "-DFETCHCONTENT_TRY_FIND_PACKAGE_MODE=NEVER". Also, please be aware that the official ONNX Runtime binary releases statically link to all open source libraries. Though you may build ONNX Runtime from source and change it to use shared libraries instead, the program's behavior would be different. Especially on when global objects are initialized/destroyed, which could lead to undefined behavior or crashes. Also, destruction order of global objects in shared libraries(or DLLs) are different between Windows and Linux, which adds to another layer of complexity. When you hit such issues, welcome to report the problems to us. However, the issues will be processed with a lower priority.
Describe the issue
Trying to build
main
on Arch Linux fails because Arch Linux packagesflatbuffers
as a shared library. The flatbuffers target then becomesflatbuffers::flatbuffers_shared
, notflatbuffers::flatbuffers
as is used in onnxruntime. As a result, CMake fails to find the target.Replacing
flatbuffers::flatbuffers
withflatbuffers::flatbuffers_shared
makes it pass the CMake stage, but fails to build as well:There's many more errors like this, possibly because of API changes?
Considering
flatbuffers
is designed as a header-only library, maybe it makes sense to include it as a submodule in this repository, same as protobuf?Urgency
No response
Target platform
x86_64
Build script
Error / output
Visual Studio Version
No response
GCC / Compiler Version
No response