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

CMake exports for static onnxruntime #22173

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

jordanozang
Copy link

@jordanozang jordanozang commented Sep 23, 2024

Description

See the example repository for a minimal example of using the static CMake Config.

  • Add libraries built during the static onnxruntime build (onnxruntime_common, onnxruntime_mlas, etc.) to the onnxruntime export set. Additionally, add an onnxruntime::onnxruntime interface target that behaves much the same as that target in the shared build case.
    find_package(onnxruntime REQUIRED)
    target_link_libraries(example PRIVATE onnxruntime::onnxruntime)
    should now work.
  • Add onnxruntime_USE_EIGEN_PACKAGE option to enable getting Eigen via find_package. It cannot be reliably added to the FIND_PACKAGE_ARGS because onnxruntime depends on a version of Eigen that is between releases. It is intended to be used in a controlled environment like vcpkg. In the example repo, I overrode the vcpkg port to fetch the same version as onnxruntime does.
  • Pin Protobuf version in the FIND_PACKAGE_ARGS to 3.21 because incompatible versions cause a build failure.
  • Add a case to handle systems like Arch Linux where the target nsync_cpp is imported rather than unofficial::nsync::nsync_cpp, as with vcpkg. Increment the nsync_cpp fetchcontent version from 1.26.0 to 1.29.0 to take advantage of new export targets upstream.
  • Minor modifications to ensure that dependency targets like Boost::mp11 are treated as imported targets and not part of the build interface.

Motivation and Context

Edit:
Abseil version was pinned by another pr in FIND_PACKAGE_ARGS so this no longer changes that.

@jordanozang
Copy link
Author

jordanozang commented Sep 23, 2024 via email

@jordanozang jordanozang force-pushed the cmake_config_static_builds branch 4 times, most recently from 4a274e0 to 6e977f1 Compare September 24, 2024 17:25
@jordanozang jordanozang marked this pull request as ready for review September 24, 2024 17:34
@jordanozang jordanozang marked this pull request as draft September 24, 2024 17:48
@jordanozang jordanozang marked this pull request as ready for review September 24, 2024 17:59
@jordanozang
Copy link
Author

I think @snnn probably has the most context on this. Hopefully tagging is ok. I don't think I have permission to add reviewers as suggested in the contributing guidelines.

@zwillikon
Copy link

@skottmckay Hey, may you please merge this?

@snnn
Copy link
Member

snnn commented Oct 15, 2024

/azp run Big Models, Linux Android Emulator QNN CI Pipeline, Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline

@snnn
Copy link
Member

snnn commented Oct 15, 2024

/azp run Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline,

@snnn
Copy link
Member

snnn commented Oct 15, 2024

/azp run Windows CPU CI Pipeline, Windows GPU CUDA CI Pipeline, Windows GPU DML CI Pipeline, Windows GPU Doc Gen CI Pipeline, Windows GPU TensorRT CI Pipeline, Windows x64 QNN CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline,

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

Copy link

Azure Pipelines successfully started running 5 pipeline(s).

Copy link

Azure Pipelines successfully started running 9 pipeline(s).

cmake/deps.txt Outdated Show resolved Hide resolved
This was referenced Oct 18, 2024
snnn added a commit that referenced this pull request Oct 21, 2024
### Description
1. Remove the onnxruntime::OrtMutex class and replace it with
~absl::Mutex~ std::mutex.
2. After this change, most source files will not include <Windows.h>
indirectly.


### Motivation and Context
To reduce the number of deps we have, and address some Github issues
that are related to build ONNX Runtime from source.
In PR #3000 , I added a custom implementation of std::mutex . It was
mainly because at that time std::mutex's default constructor was not
trivial on Windows. If you had such a mutex as a global var, it could
not be initialized at compile time. Then VC++ team fixed this issue.
Therefore we don't need this custom implementation anymore.

This PR also removes nsync. I ran several models tests on Linux. I
didn't see any perf difference.
This PR also reverts PR #21005 , which is no longer needed since conda
has updated its msvc runtime DLL.

This PR unblocks #22173 and resolves #22092 . We have a lot of open
issues with nsync. This PR can resolve all of them.
@jordanozang jordanozang force-pushed the cmake_config_static_builds branch 2 times, most recently from f73609e to 5f52e48 Compare October 22, 2024 12:40
On my system, Protobuf major version 4 causes
a build failure. However, newer versions seem to
work on other platforms and the vcpkg build
depends on using version 4.25, since it builds
upstream dependencies with that version.
onnxruntime_providers_qnn needs to be exported for
static builds.

ABSL_ENABLE_INSTALL option conflicts with using
XNNPACK.

Static builds with training enabled were failing
because of missing tensorboard exports.
As tensorboard has no CMake scripts, add them.
@snnn
Copy link
Member

snnn commented Oct 22, 2024

/azp run Big Models, Linux Android Emulator QNN CI Pipeline, Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline

@snnn
Copy link
Member

snnn commented Oct 22, 2024

/azp run Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline

@snnn
Copy link
Member

snnn commented Oct 22, 2024

/azp run Windows CPU CI Pipeline, Windows GPU CUDA CI Pipeline, Windows GPU DML CI Pipeline, Windows GPU Doc Gen CI Pipeline, Windows GPU TensorRT CI Pipeline, Windows x64 QNN CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

Copy link

Azure Pipelines successfully started running 5 pipeline(s).

Copy link

Azure Pipelines successfully started running 9 pipeline(s).

On Android, Protobuf needs to link with the log
system library. When passed directly to
target_link_libraries, CMake treats this as any
other dependency. In particular, it reports an
error for the static build because it isn't
imported or in an export set. Instead of passing
log, instead pass -llog, so CMake will treat it
as an external system library as expected.
@snnn
Copy link
Member

snnn commented Oct 22, 2024

/azp run Big Models, Linux Android Emulator QNN CI Pipeline, Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline

@snnn
Copy link
Member

snnn commented Oct 22, 2024

/azp run Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline

@snnn
Copy link
Member

snnn commented Oct 22, 2024

/azp run Windows CPU CI Pipeline, Windows GPU CUDA CI Pipeline, Windows GPU DML CI Pipeline, Windows GPU Doc Gen CI Pipeline, Windows GPU TensorRT CI Pipeline, Windows x64 QNN CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

Copy link

Azure Pipelines successfully started running 5 pipeline(s).

Copy link

Azure Pipelines successfully started running 9 pipeline(s).

Many headers are added as interface includes
by onnxruntime-extensions but are only required
for building that library. Only one include,
${onnxruntime_EXTENSIONS_PATH}/includes, is
required to consume the library. Additionally,
because the include of onnxruntime_extensions.h is
limited to onnxruntime_c_api.cc, not any api
headers, this include can safely be scoped to the
build interface, even for consumers of static
builds.

This should fix the wasm CI runs for pr microsoft#22173.
@jordanozang jordanozang requested a review from snnn October 22, 2024 23:15
@snnn
Copy link
Member

snnn commented Oct 22, 2024

/azp run Big Models, Linux Android Emulator QNN CI Pipeline, Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline

@snnn
Copy link
Member

snnn commented Oct 22, 2024

/azp run Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline

@snnn
Copy link
Member

snnn commented Oct 22, 2024

/azp run Windows CPU CI Pipeline, Windows GPU CUDA CI Pipeline, Windows GPU DML CI Pipeline, Windows GPU Doc Gen CI Pipeline, Windows GPU TensorRT CI Pipeline, Windows x64 QNN CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

Copy link

Azure Pipelines successfully started running 5 pipeline(s).

Copy link

Azure Pipelines successfully started running 9 pipeline(s).

@snnn
Copy link
Member

snnn commented Oct 25, 2024

/azp run Big Models, Linux Android Emulator QNN CI Pipeline, Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline

@snnn
Copy link
Member

snnn commented Oct 25, 2024

/azp run Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline, Windows CPU CI Pipeline, Windows GPU CUDA CI Pipeline

@snnn
Copy link
Member

snnn commented Oct 25, 2024

/azp run Windows GPU DML CI Pipeline, Windows GPU Doc Gen CI Pipeline, Windows GPU TensorRT CI Pipeline, Windows x64 QNN CI Pipeline

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

Copy link

Azure Pipelines successfully started running 4 pipeline(s).

Copy link

Azure Pipelines successfully started running 7 pipeline(s).

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

Successfully merging this pull request may close these issues.

3 participants