mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-25 22:26:24 +00:00
## Description 1. Convert some git submodules to cmake external projects 2. Update nsync from [1.23.0](https://github.com/google/nsync/releases/tag/1.23.0) to [1.25.0](https://github.com/google/nsync/releases/tag/1.25.0) 3. Update re2 from 2021-06-01 to 2022-06-01 4. Update wil from an old commit to 1.0.220914.1 tag 5. Update gtest to a newer commit so that it can optionally leverage absl/re2 for parsing command line flags. The following git submodules are deleted: 1. FP16 2. safeint 3. XNNPACK 4. cxxopts 5. dlpack 7. flatbuffers 8. googlebenchmark 9. json 10. mimalloc 11. mp11 12. pthreadpool More will come. ## Motivation and Context There are 3 ways of integrating 3rd party C/C++ libraries into ONNX Runtime: 1. Install them to a system location, then use cmake's find_package module to locate them. 2. Use git submodules 6. Use cmake's external projects(externalproject_add). At first when this project was just started, we considered both option 2 and option 3. We preferred option 2 because: 1. It's easier to handle authentication. At first this project was not open source, and it had some other non-public dependencies. If we use git submodule, ADO will handle authentication smoothly. Otherwise we need to manually pass tokens around and be very careful on not exposing them in build logs. 2. At that time, cmake fetched dependencies after "cmake" finished generating vcprojects/makefiles. So it was very difficult to make cflags consistent. Since cmake 3.11, it has a new command: FetchContent, which fetches dependencies when it generates vcprojects/makefiles just before add_subdirectories, so the parent project's variables/settings can be easily passed to the child projects. And when the project went on, we had some new concerns: 1. As we started to have more and more EPs and build configs, the number of submodules grew quickly. For more developers, most ORT submodules are not relevant to them. They shouldn't need to download all of them. 2. It is impossible to let two different build configs use two different versions of the same dependency. For example, right now we have protobuf 3.18.3 in the submodules. Then every EP must use the same version. Whenever we have a need to upgrade protobuf, we need to coordinate across the whole team and many external developers. I can't manage it anymore. 3. Some projects want to manage the dependencies in a different way, either because of their preference or because of compliance requirements. For example, some Microsoft teams want to use vcpkg, but we don't want to force every user of onnxruntime using vcpkg. 7. Someone wants to dynamically link to protobuf, but our build script only does static link. 8. Hard to handle security vulnerabilities. For example, whenever protobuf has a security patch, we have a lot of things to do. But if we allowed people to build ORT with a different version of protobuf without changing ORT"s source code, the customer who build ORT from source will be able to act on such things in a quicker way. They will not need to wait ORT having a patch release. 9. Every time we do a release, github will also publish a source file zip file and a source file tarball for us. But they are not usable, because they miss submodules. ### New features After this change, users will be able to: 1. Build the dependencies in the way they want, then install them to somewhere(for example, /usr or a temp folder). 2. Or download the dependencies by using cmake commands from these dependencies official website 3. Similar to the above, but use your private mirrors to migrate supply chain risks. 4. Use different versions of the dependencies, as long as our source code is compatible with them. For example, you may use you can't use protobuf 3.20.x as they need code changes in ONNX Runtime. 6. Only download the things the current build needs. 10. Avoid building external dependencies again and again in every build. ### Breaking change The onnxruntime_PREFER_SYSTEM_LIB build option is removed you could think from now it is default ON. If you don't like the new behavior, you can set FETCHCONTENT_TRY_FIND_PACKAGE_MODE to NEVER. Besides, for who relied on the onnxruntime_PREFER_SYSTEM_LIB build option, please be aware that this PR will change find_package calls from Module mode to Config mode. For example, in the past if you have installed protobuf from apt-get from ubuntu 20.04's official repo, find_package can find it and use it. But after this PR, it won't. This is because that protobuf version provided by Ubuntu 20.04 is too old to support the "config mode". It can be resolved by getting a newer version of protobuf from somewhere.
155 lines
5.9 KiB
CMake
155 lines
5.9 KiB
CMake
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
|
|
file(GLOB_RECURSE onnxruntime_graph_src CONFIGURE_DEPENDS
|
|
"${ONNXRUNTIME_INCLUDE_DIR}/core/graph/*.h"
|
|
"${ONNXRUNTIME_ROOT}/core/graph/*.h"
|
|
"${ONNXRUNTIME_ROOT}/core/graph/*.cc"
|
|
)
|
|
|
|
# create empty list for any excludes
|
|
set(onnxruntime_graph_src_exclude_patterns)
|
|
|
|
if (onnxruntime_MINIMAL_BUILD)
|
|
# remove schema registration support
|
|
list(APPEND onnxruntime_graph_src_exclude_patterns
|
|
"${ONNXRUNTIME_INCLUDE_DIR}/core/graph/schema_registry.h"
|
|
"${ONNXRUNTIME_ROOT}/core/graph/schema_registry.cc"
|
|
"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/*defs.h"
|
|
"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/*defs.cc"
|
|
"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/onnx_deprecated_operators.cc"
|
|
"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/onnx_function_util.h"
|
|
"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/onnx_function_util.cc"
|
|
"${ONNXRUNTIME_ROOT}/core/graph/function_template.h"
|
|
"${ONNXRUNTIME_ROOT}/core/graph/function_utils.h"
|
|
"${ONNXRUNTIME_ROOT}/core/graph/function_utils.cc"
|
|
)
|
|
|
|
# no Function support initially
|
|
list(APPEND onnxruntime_graph_src_exclude_patterns
|
|
"${ONNXRUNTIME_ROOT}/core/graph/function*"
|
|
)
|
|
|
|
# remove graph proto serializer
|
|
list(APPEND onnxruntime_graph_src_exclude_patterns
|
|
"${ONNXRUNTIME_ROOT}/core/graph/graph_proto_serializer.cc"
|
|
"${ONNXRUNTIME_ROOT}/core/graph/graph_proto_serializer.h"
|
|
)
|
|
|
|
# no optimizer support in base minimal build
|
|
# some optimizer support in extended minimal build
|
|
if (NOT onnxruntime_EXTENDED_MINIMAL_BUILD)
|
|
list(APPEND onnxruntime_graph_src_exclude_patterns
|
|
"${ONNXRUNTIME_ROOT}/core/graph/graph_utils.*"
|
|
)
|
|
endif()
|
|
endif()
|
|
|
|
if (onnxruntime_DISABLE_CONTRIB_OPS)
|
|
list(APPEND onnxruntime_graph_src_exclude_patterns
|
|
"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/*.h"
|
|
"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/*.cc"
|
|
)
|
|
endif()
|
|
|
|
if(NOT onnxruntime_USE_DML)
|
|
list(APPEND onnxruntime_graph_src_exclude_patterns
|
|
"${ONNXRUNTIME_ROOT}/core/graph/dml_ops/*.h"
|
|
"${ONNXRUNTIME_ROOT}/core/graph/dml_ops/*.cc"
|
|
)
|
|
endif()
|
|
|
|
file(GLOB onnxruntime_graph_src_exclude ${onnxruntime_graph_src_exclude_patterns})
|
|
list(REMOVE_ITEM onnxruntime_graph_src ${onnxruntime_graph_src_exclude})
|
|
|
|
file(GLOB_RECURSE onnxruntime_ir_defs_src CONFIGURE_DEPENDS
|
|
"${ONNXRUNTIME_ROOT}/core/defs/*.cc"
|
|
)
|
|
|
|
if (onnxruntime_ENABLE_TRAINING_OPS AND NOT onnxruntime_ENABLE_TRAINING)
|
|
set(orttraining_graph_src
|
|
"${ORTTRAINING_SOURCE_DIR}/core/graph/training_op_defs.cc"
|
|
"${ORTTRAINING_SOURCE_DIR}/core/graph/training_op_defs.h"
|
|
)
|
|
endif()
|
|
if (onnxruntime_ENABLE_TRAINING)
|
|
file(GLOB_RECURSE orttraining_graph_src CONFIGURE_DEPENDS
|
|
"${ORTTRAINING_SOURCE_DIR}/core/graph/*.h"
|
|
"${ORTTRAINING_SOURCE_DIR}/core/graph/*.cc"
|
|
)
|
|
endif()
|
|
|
|
set(onnxruntime_graph_lib_src ${onnxruntime_graph_src} ${onnxruntime_ir_defs_src})
|
|
if (onnxruntime_ENABLE_TRAINING OR onnxruntime_ENABLE_TRAINING_OPS)
|
|
list(APPEND onnxruntime_graph_lib_src ${orttraining_graph_src})
|
|
endif()
|
|
|
|
onnxruntime_add_static_library(onnxruntime_graph ${onnxruntime_graph_lib_src})
|
|
add_dependencies(onnxruntime_graph onnx_proto flatbuffers)
|
|
onnxruntime_add_include_to_target(onnxruntime_graph onnxruntime_common WIL::WIL onnx onnx_proto ${PROTOBUF_LIB} flatbuffers safeint_interface Boost::mp11)
|
|
|
|
if (MSVC)
|
|
set(ONNX_PROTOBUF_NATVIS_FILE "onnx_protobuf.natvis")
|
|
target_sources(
|
|
onnxruntime_graph
|
|
INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/external/${ONNX_PROTOBUF_NATVIS_FILE}>
|
|
)
|
|
endif()
|
|
|
|
if(NOT MSVC)
|
|
target_compile_options(onnxruntime_graph PRIVATE "-Wno-parentheses")
|
|
endif()
|
|
if (onnxruntime_ENABLE_TRAINING)
|
|
#TODO: the graph library should focus on ONNX IR, it shouldn't depend on math libraries like MKLML/OpenBlas
|
|
target_include_directories(onnxruntime_graph PRIVATE ${MKLML_INCLUDE_DIR})
|
|
target_link_libraries(onnxruntime_graph PRIVATE nlohmann_json::nlohmann_json)
|
|
endif()
|
|
|
|
target_include_directories(onnxruntime_graph PRIVATE ${ONNXRUNTIME_ROOT})
|
|
|
|
if (onnxruntime_ENABLE_TRAINING OR onnxruntime_ENABLE_TRAINING_OPS)
|
|
target_include_directories(onnxruntime_graph PRIVATE ${ORTTRAINING_ROOT})
|
|
|
|
if (onnxruntime_USE_NCCL)
|
|
target_include_directories(onnxruntime_graph PRIVATE ${NCCL_INCLUDE_DIRS})
|
|
endif()
|
|
endif()
|
|
|
|
set_target_properties(onnxruntime_graph PROPERTIES FOLDER "ONNXRuntime")
|
|
set_target_properties(onnxruntime_graph PROPERTIES LINKER_LANGUAGE CXX)
|
|
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/graph DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core)
|
|
source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_graph_src} ${onnxruntime_ir_defs_src})
|
|
if (onnxruntime_ENABLE_TRAINING OR onnxruntime_ENABLE_TRAINING_OPS)
|
|
source_group(TREE ${ORTTRAINING_ROOT} FILES ${orttraining_graph_src})
|
|
endif()
|
|
|
|
if (onnxruntime_BUILD_MS_EXPERIMENTAL_OPS)
|
|
target_compile_definitions(onnxruntime_graph PRIVATE BUILD_MS_EXPERIMENTAL_OPS=1)
|
|
endif()
|
|
|
|
if (WIN32)
|
|
set(onnxruntime_graph_static_library_flags
|
|
-IGNORE:4221 # LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
|
|
)
|
|
|
|
set_target_properties(onnxruntime_graph PROPERTIES
|
|
STATIC_LIBRARY_FLAGS "${onnxruntime_graph_static_library_flags}")
|
|
|
|
if (NOT onnxruntime_DISABLE_EXCEPTIONS)
|
|
target_compile_options(onnxruntime_graph PRIVATE
|
|
/EHsc # exception handling - C++ may throw, extern "C" will not
|
|
)
|
|
endif()
|
|
endif()
|
|
|
|
if (onnxruntime_ENABLE_ATEN)
|
|
target_compile_definitions(onnxruntime_graph PRIVATE ENABLE_ATEN)
|
|
endif()
|
|
|
|
if (NOT onnxruntime_BUILD_SHARED_LIB)
|
|
install(TARGETS onnxruntime_graph
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
endif()
|