From 04900f96c1e22f99f8cc12b7ee98930f03cd93f9 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Thu, 1 Dec 2022 09:51:59 -0800 Subject: [PATCH] Improve dependency management (#13523) ## 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. --- .gitmodules | 34 - cgmanifests/README.md | 5 +- cgmanifests/cgmanifest.json | 43 +- cgmanifests/generate_cgmanifest.py | 129 +- cgmanifests/generated/cgmanifest.json | 339 +++--- cmake/CMakeLists.txt | 1046 +++-------------- cmake/adjust_global_compile_flags.cmake | 371 ++++++ cmake/deps.txt | 24 +- cmake/external/FP16 | 1 - cmake/external/SafeInt/safeint | 1 - cmake/external/XNNPACK | 1 - cmake/external/abseil-cpp.cmake | 6 + cmake/external/cxxopts | 1 - cmake/external/dlpack | 1 - cmake/external/eigen.cmake | 15 +- cmake/external/extensions.cmake | 2 +- cmake/{ => external}/find_snpe.cmake | 0 cmake/external/flatbuffers | 1 - cmake/external/googlebenchmark | 1 - cmake/external/gsl.cmake | 25 - cmake/external/helper_functions.cmake | 8 +- cmake/external/jemalloc.cmake | 24 - cmake/external/json | 1 - cmake/external/mimalloc | 1 - cmake/external/mimalloc.cmake | 18 +- cmake/external/mp11 | 1 - cmake/external/nsync | 2 +- cmake/external/onnx_minimal.cmake | 7 +- .../external/onnxruntime_external_deps.cmake | 443 +++++++ cmake/{ => external}/protobuf_function.cmake | 0 cmake/external/pthreadpool | 1 - cmake/external/pybind11.cmake | 31 +- cmake/external/re2 | 2 +- cmake/external/wil | 2 +- cmake/external/wil.cmake | 22 + cmake/external/xnnpack.cmake | 34 +- cmake/onnxruntime_codegen_tvm.cmake | 2 +- cmake/onnxruntime_common.cmake | 46 +- cmake/onnxruntime_eager.cmake | 2 +- cmake/onnxruntime_framework.cmake | 8 +- cmake/onnxruntime_graph.cmake | 2 +- cmake/onnxruntime_language_interop_ops.cmake | 2 +- cmake/onnxruntime_opschema_lib.cmake | 4 +- cmake/onnxruntime_optimizer.cmake | 2 +- cmake/onnxruntime_providers.cmake | 81 +- cmake/onnxruntime_pyop.cmake | 7 +- cmake/onnxruntime_python.cmake | 2 +- cmake/onnxruntime_session.cmake | 3 +- cmake/onnxruntime_training.cmake | 18 +- cmake/onnxruntime_unittests.cmake | 55 +- cmake/onnxruntime_util.cmake | 2 +- cmake/tensorboard/CMakeLists.txt | 55 +- cmake/tensorboard/compat/proto/CMakeLists.txt | 25 + cmake/wil.cmake | 5 - cmake/winml.cmake | 68 +- cmake/winml_unittests.cmake | 10 +- onnxruntime/core/common/safeint.h | 3 +- tools/ci_build/build.py | 9 +- tools/ci_build/get_docker_image.py | 8 +- .../binary-size-checks-pipeline.yml | 2 +- .../azure-pipelines/linux-ci-pipeline.yml | 2 +- .../linux-cpu-minimal-build-ci-pipeline.yml | 4 +- .../linux-dnnl-ci-pipeline.yml | 2 +- .../azure-pipelines/linux-gpu-ci-pipeline.yml | 4 +- .../linux-gpu-tensorrt-ci-pipeline.yml | 2 +- .../linux-migraphx-ci-pipeline.yml | 6 +- .../linux-multi-gpu-ci-pipeline.yml | 2 +- .../azure-pipelines/mac-ci-pipeline.yml | 19 +- .../azure-pipelines/mac-ios-ci-pipeline.yml | 5 +- .../mac-ios-packaging-pipeline.yml | 5 +- .../nuget/templates/dml-vs-2019.yml | 19 +- .../orttraining-mac-ci-pipeline.yml | 17 +- .../azure-pipelines/post-merge-jobs.yml | 34 + .../templates/android-java-api-aar.yml | 2 +- .../azure-pipelines/templates/c-api-cpu.yml | 70 +- .../templates/c-api-linux-cpu.yml | 14 +- .../azure-pipelines/templates/mac-ci.yml | 115 +- .../templates/py-linux-gpu.yml | 22 +- .../templates/py-linux-ubuntu.yml | 25 +- .../azure-pipelines/templates/py-linux.yml | 25 +- .../py-packaging-selectable-stage.yml | 26 +- .../templates/py-packaging-stage.yml | 50 +- .../azure-pipelines/templates/py-win-gpu.yml | 15 +- .../azure-pipelines/templates/win-ci-arm.yml | 126 -- .../templates/win-ci-vs-2019.yml | 20 +- .../azure-pipelines/templates/win-ci.yml | 30 +- .../azure-pipelines/win-ci-fuzz-testing.yml | 13 +- .../azure-pipelines/win-ci-pipeline.yml | 6 +- .../win-gpu-reduce-op-ci-pipeline.yml | 13 +- .../win-gpu-tensorrt-ci-pipeline.yml | 22 +- .../linux/build_linux_arm64_python_package.sh | 7 +- .../x64/python/cpu/scripts/install_deps.sh | 5 - .../python/cpu/scripts/install_protobuf.sh | 82 +- .../x64/python/cpu/scripts/requirements.txt | 2 +- .../migraphx-ci-pipeline-env.Dockerfile | 11 +- .../linux/docker/scripts/install_protobuf.sh | 81 +- .../github/linux/run_python_dockerbuild.sh | 27 + .../windows/install_third_party_deps.ps1 | 60 + 98 files changed, 1935 insertions(+), 2119 deletions(-) create mode 100644 cmake/adjust_global_compile_flags.cmake delete mode 160000 cmake/external/FP16 delete mode 160000 cmake/external/SafeInt/safeint delete mode 160000 cmake/external/XNNPACK delete mode 160000 cmake/external/cxxopts delete mode 160000 cmake/external/dlpack rename cmake/{ => external}/find_snpe.cmake (100%) delete mode 160000 cmake/external/flatbuffers delete mode 160000 cmake/external/googlebenchmark delete mode 100644 cmake/external/gsl.cmake delete mode 100644 cmake/external/jemalloc.cmake delete mode 160000 cmake/external/json delete mode 160000 cmake/external/mimalloc delete mode 160000 cmake/external/mp11 create mode 100644 cmake/external/onnxruntime_external_deps.cmake rename cmake/{ => external}/protobuf_function.cmake (100%) delete mode 160000 cmake/external/pthreadpool create mode 100644 cmake/external/wil.cmake create mode 100644 cmake/tensorboard/compat/proto/CMakeLists.txt delete mode 100644 cmake/wil.cmake delete mode 100644 tools/ci_build/github/azure-pipelines/templates/win-ci-arm.yml rename tools/ci_build/github/{pai => linux/docker}/migraphx-ci-pipeline-env.Dockerfile (81%) create mode 100755 tools/ci_build/github/linux/run_python_dockerbuild.sh create mode 100644 tools/ci_build/github/windows/install_third_party_deps.ps1 diff --git a/.gitmodules b/.gitmodules index ff44348c8a..f8163e4be8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,9 +4,6 @@ [submodule "cmake/external/googletest"] path = cmake/external/googletest url = https://github.com/google/googletest.git -[submodule "cmake/external/googlebenchmark"] - path = cmake/external/googlebenchmark - url = https://github.com/google/benchmark.git [submodule "cmake/external/onnx"] path = cmake/external/onnx url = https://github.com/onnx/onnx.git @@ -22,36 +19,15 @@ [submodule "cmake/external/eigen"] path = cmake/external/eigen url = https://gitlab.com/libeigen/eigen.git -[submodule "cmake/external/cxxopts"] - path = cmake/external/cxxopts - url = https://github.com/jarro2783/cxxopts.git [submodule "cmake/external/tensorboard"] path = cmake/external/tensorboard url = https://github.com/tensorflow/tensorboard.git -[submodule "cmake/external/mimalloc"] - path = cmake/external/mimalloc - url = https://github.com/microsoft/mimalloc.git [submodule "cmake/external/wil"] path = cmake/external/wil url = https://github.com/microsoft/wil.git -[submodule "cmake/external/json"] - path = cmake/external/json - url = https://github.com/nlohmann/json.git [submodule "cmake/external/libprotobuf-mutator"] path = cmake/external/libprotobuf-mutator url = https://github.com/google/libprotobuf-mutator.git -[submodule "cmake/external/flatbuffers"] - path = cmake/external/flatbuffers - url = https://github.com/google/flatbuffers.git -[submodule "cmake/external/SafeInt/safeint"] - path = cmake/external/SafeInt/safeint - url = https://github.com/dcleblanc/SafeInt.git -[submodule "cmake/external/mp11"] - path = cmake/external/mp11 - url = https://github.com/boostorg/mp11.git -[submodule "cmake/external/dlpack"] - path = cmake/external/dlpack - url = https://github.com/dmlc/dlpack.git [submodule "cmake/external/emsdk"] path = cmake/external/emsdk url = https://github.com/emscripten-core/emsdk.git @@ -66,13 +42,3 @@ path = cmake/external/onnx-tensorrt url = https://github.com/onnx/onnx-tensorrt.git branch = 8.4-GA -[submodule "cmake/external/pthreadpool"] - path = cmake/external/pthreadpool - url = https://github.com/Maratyszcza/pthreadpool.git -[submodule "cmake/external/FP16"] - path = cmake/external/FP16 - url = https://github.com/Maratyszcza/FP16.git -[submodule "cmake/external/XNNPACK"] - path = cmake/external/XNNPACK - url = https://github.com/google/XNNPACK.git - ignore = dirty diff --git a/cgmanifests/README.md b/cgmanifests/README.md index 7ff7914d8d..fcd15232f9 100644 --- a/cgmanifests/README.md +++ b/cgmanifests/README.md @@ -8,6 +8,7 @@ This file contains generated CGManifest entries. It covers these dependencies: - git submodules - dependencies from the Dockerfile `tools/ci_build/github/linux/docker/Dockerfile.manylinux2014_cuda11` +- the entries in [../cmake/deps.txt](../cmake/deps.txt) If any of these dependencies change, this file should be updated. **When updating, please regenerate instead of editing manually.** @@ -20,8 +21,10 @@ If any of these dependencies change, this file should be updated. ``` 3. Run the generator script: ``` - $ python cgmanifests/generate_cgmanifest.py + $ python cgmanifests/generate_cgmanifest.py --username --token ``` +Please supply your github username and access token to the script. If you don't have a token, you can generate one at https://github.com/settings/tokens. This is for authenticating with Github REST API so that you would not hit the rate limit. + ## `cgmanifests/cgmanifest.json` This file contains non-generated CGManifest entries. Please edit directly as needed. diff --git a/cgmanifests/cgmanifest.json b/cgmanifests/cgmanifest.json index 4e78d999de..62d3de80b1 100644 --- a/cgmanifests/cgmanifest.json +++ b/cgmanifests/cgmanifest.json @@ -23,16 +23,7 @@ "maven": { "GroupId": "com.google.protobuf", "ArtifactId": "protobuf-java", "Version": "3.21.7" }, "DevelopmentDependency": true } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "a3534567187d2edc428efd3f13466ff75fe5805c", - "repositoryUrl": "https://github.com/microsoft/gsl.git" - } - } - }, + }, { "component": { "type": "git", @@ -324,26 +315,6 @@ } } }, - { - "component": { - "git": { - "commitHash": "cc4bed2d74f7c8717e31f9579214ab52a9c9c610", - "repositoryUrl": "https://github.com/abseil/abseil-cpp" - }, - "type": "git", - "comments": "used by onnxruntime server" - } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "256be563447a315f2a7993ec669460ba475fa86a", - "repositoryUrl": "https://github.com/abseil/abseil-cpp" - }, - "comments": "used by onnxruntime" - } - }, { "component": { "Type": "other", @@ -564,17 +535,7 @@ "DownloadUrl": "http://security.ubuntu.com/ubuntu/pool/main/s/sqlite3/libsqlite3-dev_3.22.0-1ubuntu0.4_amd64.deb" } } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "512d44b9aa22690fd7d7e665fcab9bdcb590f118", - "repositoryUrl": "https://github.com/google/XNNPACK.git" - }, - "comments": "xnnpack" - } - } + } ], "Version": 1 } diff --git a/cgmanifests/generate_cgmanifest.py b/cgmanifests/generate_cgmanifest.py index 23aaa09fd3..a85516011a 100644 --- a/cgmanifests/generate_cgmanifest.py +++ b/cgmanifests/generate_cgmanifest.py @@ -1,10 +1,28 @@ #!/usr/bin/env python3 +import argparse +import csv import json import os import re import subprocess import sys +from dataclasses import dataclass +from pathlib import PurePosixPath +from urllib.parse import urlparse + +import requests + + +def parse_arguments(): + parser = argparse.ArgumentParser() + parser.add_argument("--username", required=True, help="Github username") + parser.add_argument("--token", required=True, help="Github access token") + + return parser.parse_args() + + +args = parse_arguments() SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) REPO_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, "..")) @@ -15,6 +33,61 @@ package_url = None registrations = [] + +@dataclass(frozen=True) +class GitDep: + commit: str + url: str + + +git_deps = {} + + +def add_github_dep(name, parsed_url): + segments = parsed_url.path.split("/") + org_name = segments[1] + repo_name = segments[2] + if segments[3] != "archive": + print("unrecognized github url path:" + parsed_url.path) + return + git_repo_url = "https://github.com/%s/%s.git" % (org_name, repo_name) + # For example, the path might be like '/myorg/myrepo/archive/5a5f8a5935762397aa68429b5493084ff970f774.zip' + # The last segment, segments[4], is '5a5f8a5935762397aa68429b5493084ff970f774.zip' + if len(segments) == 5 and re.match(r"[0-9a-f]{40}", PurePosixPath(segments[4]).stem): + commit = PurePosixPath(segments[4]).stem + dep = GitDep(commit, git_repo_url) + if dep not in git_deps: + git_deps[dep] = name + else: + if len(segments) == 5: + tag = PurePosixPath(segments[4]).stem + if tag.endswith(".tar"): + tag = PurePosixPath(tag).stem + elif segments[4] == "refs" and segments[5] == "tags": + tag = PurePosixPath(segments[6]).stem + if tag.endswith(".tar"): + tag = PurePosixPath(tag).stem + else: + print("unrecognized github url path:" + parsed_url.path) + return + # Make a REST call to convert to tag to a git commit + url = "https://api.github.com/repos/%s/%s/git/refs/tags/%s" % (org_name, repo_name, tag) + res = requests.get(url, auth=(args.username, args.token)) + response_json = res.json() + tag_object = response_json["object"] + if tag_object["type"] == "commit": + commit = tag_object["sha"] + elif tag_object["type"] == "tag": + res = requests.get(tag_object["url"], auth=(args.username, args.token)) + commit = res.json()["object"]["sha"] + else: + print("unrecognized github url path:" + parsed_url.path) + return + dep = GitDep(commit, git_repo_url) + if dep not in git_deps: + git_deps[dep] = name + + with open( os.path.join(REPO_DIR, "tools", "ci_build", "github", "linux", "docker", "Dockerfile.manylinux2014_cuda11"), mode="r", @@ -44,18 +117,22 @@ with open( package_url = m.group(2) + "/v" + package_filename + "/cmake-" + package_filename + ".tar.gz" else: package_url = m.group(2) + "/" + package_filename + ".tar.gz" - registration = { - "Component": { - "Type": "other", - "other": { - "Name": package_name.lower(), - "Version": package_filename.split("-")[-1], - "DownloadUrl": package_url, - }, - "comments": "manylinux dependency", + parsed_url = urlparse(package_url) + if parsed_url.hostname == "github.com": + add_github_dep("manylinux dependency " + package_name, parsed_url) + else: + registration = { + "Component": { + "Type": "other", + "other": { + "Name": package_name.lower(), + "Version": package_filename.split("-")[-1], + "DownloadUrl": package_url, + }, + "comments": "manylinux dependency", + } } - } - registrations.append(registration) + registrations.append(registration) package_name = None package_filename = None package_url = None @@ -88,16 +165,36 @@ proc = subprocess.run( submodule_lines = proc.stdout.splitlines() for submodule_line in submodule_lines: (absolute_path, url, commit) = submodule_line.split(" ") + git_deps[GitDep(commit, url)] = "git submodule at {}".format( + normalize_path_separators(os.path.relpath(absolute_path, REPO_DIR)) + ) + +with open(os.path.join(SCRIPT_DIR, "..", "cmake", "deps.txt")) as f: + depfile_reader = csv.reader(f, delimiter=";") + for row in depfile_reader: + if len(row) < 3: + continue + name = row[0] + # Lines start with "#" are comments + if name.startswith("#"): + continue + url = row[1] + parsed_url = urlparse(url) + # TODO: add support for gitlab + if parsed_url.hostname == "github.com": + add_github_dep(name, parsed_url) + else: + print("unrecognized url:" + url) + +for git_dep, comment in git_deps.items(): registration = { "component": { "type": "git", "git": { - "commitHash": commit, - "repositoryUrl": url, + "commitHash": git_dep.commit, + "repositoryUrl": git_dep.url, }, - "comments": "git submodule at {}".format( - normalize_path_separators(os.path.relpath(absolute_path, REPO_DIR)) - ), + "comments": comment, } } registrations.append(registration) diff --git a/cgmanifests/generated/cgmanifest.json b/cgmanifests/generated/cgmanifest.json index bc7c0047cb..e829b6b0e3 100644 --- a/cgmanifests/generated/cgmanifest.json +++ b/cgmanifests/generated/cgmanifest.json @@ -35,17 +35,6 @@ "comments": "manylinux dependency" } }, - { - "Component": { - "Type": "other", - "other": { - "Name": "libxcrypt", - "Version": "4.4.28", - "DownloadUrl": "https://github.com/besser82/libxcrypt/archive/v4.4.28.tar.gz" - }, - "comments": "manylinux dependency" - } - }, { "Component": { "Type": "other", @@ -83,30 +72,20 @@ "component": { "type": "git", "git": { - "commitHash": "0a92994d729ff76a58f692d3028ca1b64b145d91", - "repositoryUrl": "https://github.com/Maratyszcza/FP16.git" + "commitHash": "50cf2b6dd4fdf04309445f2eec8de7051d953abf", + "repositoryUrl": "https://github.com/besser82/libxcrypt.git" }, - "comments": "git submodule at cmake/external/FP16" + "comments": "manylinux dependency LIBXCRYPT" } }, { "component": { "type": "git", "git": { - "commitHash": "ff15c6ada150a5018c5ef2172401cb4529eac9c0", - "repositoryUrl": "https://github.com/dcleblanc/SafeInt.git" + "commitHash": "215105818dfde3174fe799600bb0f3cae233d0bf", + "repositoryUrl": "https://github.com/abseil/abseil-cpp.git" }, - "comments": "git submodule at cmake/external/SafeInt/safeint" - } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "003c580e696a774afdc984996ee909b7c8d8128c", - "repositoryUrl": "https://github.com/google/XNNPACK.git" - }, - "comments": "git submodule at cmake/external/XNNPACK" + "comments": "abseil_cpp" } }, { @@ -116,7 +95,7 @@ "commitHash": "3c73d91c0b04e2b59462f0a741be8c07024c1bc0", "repositoryUrl": "https://github.com/jarro2783/cxxopts.git" }, - "comments": "git submodule at cmake/external/cxxopts" + "comments": "cxxopts" } }, { @@ -126,7 +105,7 @@ "commitHash": "e7e1482087f58913b80a20b04d5c58d9d6d90155", "repositoryUrl": "https://github.com/HowardHinnant/date.git" }, - "comments": "git submodule at cmake/external/date" + "comments": "date" } }, { @@ -136,27 +115,7 @@ "commitHash": "277508879878e0a5b5b43599b1bea11f66eb3c6c", "repositoryUrl": "https://github.com/dmlc/dlpack.git" }, - "comments": "git submodule at cmake/external/dlpack" - } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "d10b27fe37736d2944630ecd7557cefa95cf87c9", - "repositoryUrl": "https://gitlab.com/libeigen/eigen.git" - }, - "comments": "git submodule at cmake/external/eigen" - } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "c220895fd1163c01f0a8b44229fb9e4fe0ae0958", - "repositoryUrl": "https://github.com/emscripten-core/emsdk.git" - }, - "comments": "git submodule at cmake/external/emsdk" + "comments": "dlpack" } }, { @@ -166,67 +125,37 @@ "commitHash": "6df40a2471737b27271bdd9b900ab5f3aec746c7", "repositoryUrl": "https://github.com/google/flatbuffers.git" }, - "comments": "git submodule at cmake/external/flatbuffers" + "comments": "flatbuffers" } }, { "component": { "type": "git", "git": { - "commitHash": "7d0d9061d83b663ce05d9de5da3d5865a3845b79", + "commitHash": "0a92994d729ff76a58f692d3028ca1b64b145d91", + "repositoryUrl": "https://github.com/Maratyszcza/FP16.git" + }, + "comments": "fp16" + } + }, + { + "component": { + "type": "git", + "git": { + "commitHash": "63058eff77e11aa15bf531df5dd34395ec3017c8", + "repositoryUrl": "https://github.com/Maratyszcza/FXdiv.git" + }, + "comments": "fxdiv" + } + }, + { + "component": { + "type": "git", + "git": { + "commitHash": "361e8d1cfe0c6c36d30b39f1b61302ece5507320", "repositoryUrl": "https://github.com/google/benchmark.git" }, - "comments": "git submodule at cmake/external/googlebenchmark" - } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "58d77fa8070e8cec2dc1ed015d66b454c8d78850", - "repositoryUrl": "https://github.com/google/googletest.git" - }, - "comments": "git submodule at cmake/external/googletest" - } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "b5364faf9d732052506cefc933d3f4e4f04513a5", - "repositoryUrl": "https://github.com/nlohmann/json.git" - }, - "comments": "git submodule at cmake/external/json" - } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "7a2ed51a6b682a83e345ff49fc4cfd7ca47550db", - "repositoryUrl": "https://github.com/google/libprotobuf-mutator.git" - }, - "comments": "git submodule at cmake/external/libprotobuf-mutator" - } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "f412df7a2b64421e1f1d61fde6055a6ea288e8f5", - "repositoryUrl": "https://github.com/microsoft/mimalloc.git" - }, - "comments": "git submodule at cmake/external/mimalloc" - } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "21cace4e574180ba64d9307a5e4ea9e5e94d3e8d", - "repositoryUrl": "https://github.com/boostorg/mp11.git" - }, - "comments": "git submodule at cmake/external/mp11" + "comments": "google_benchmark" } }, { @@ -236,7 +165,77 @@ "commitHash": "436617053d0f39a1019a371c3a9aa599b3cb2cea", "repositoryUrl": "https://github.com/google/nsync.git" }, - "comments": "git submodule at cmake/external/nsync" + "comments": "google_nsync" + } + }, + { + "component": { + "type": "git", + "git": { + "commitHash": "519beb0e52c842729b4b53731d27c0e0c32ab4a2", + "repositoryUrl": "https://github.com/google/googletest.git" + }, + "comments": "googletest" + } + }, + { + "component": { + "type": "git", + "git": { + "commitHash": "003c580e696a774afdc984996ee909b7c8d8128c", + "repositoryUrl": "https://github.com/google/XNNPACK.git" + }, + "comments": "googlexnnpack" + } + }, + { + "component": { + "type": "git", + "git": { + "commitHash": "4f8fba14066156b73f1189a2b8bd568bde5284c5", + "repositoryUrl": "https://github.com/nlohmann/json.git" + }, + "comments": "json" + } + }, + { + "component": { + "type": "git", + "git": { + "commitHash": "a3534567187d2edc428efd3f13466ff75fe5805c", + "repositoryUrl": "https://github.com/microsoft/GSL.git" + }, + "comments": "microsoft_gsl" + } + }, + { + "component": { + "type": "git", + "git": { + "commitHash": "5f4caba4e7a9017816e47becdd918fcc872039ba", + "repositoryUrl": "https://github.com/microsoft/wil.git" + }, + "comments": "microsoft_wil" + } + }, + { + "component": { + "type": "git", + "git": { + "commitHash": "f412df7a2b64421e1f1d61fde6055a6ea288e8f5", + "repositoryUrl": "https://github.com/microsoft/mimalloc.git" + }, + "comments": "mimalloc" + } + }, + { + "component": { + "type": "git", + "git": { + "commitHash": "7bc4e1ae9b36ec8ee635c3629b59ec525bbe82b9", + "repositoryUrl": "https://github.com/boostorg/mp11.git" + }, + "comments": "mp11" } }, { @@ -246,27 +245,7 @@ "commitHash": "5a5f8a5935762397aa68429b5493084ff970f774", "repositoryUrl": "https://github.com/onnx/onnx.git" }, - "comments": "git submodule at cmake/external/onnx" - } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "0d98dba29d66e93259db7daa53a9327df767a415", - "repositoryUrl": "https://github.com/google/benchmark.git" - }, - "comments": "git submodule at cmake/external/onnx/third_party/benchmark" - } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "ffa346860b306c9bbfb341aed9c14c067751feb8", - "repositoryUrl": "https://github.com/pybind/pybind11.git" - }, - "comments": "git submodule at cmake/external/onnx/third_party/pybind11" + "comments": "onnx" } }, { @@ -276,57 +255,7 @@ "commitHash": "87c7a70688fd98fb355b8976f41425b40e4fe52f", "repositoryUrl": "https://github.com/onnx/onnx-tensorrt.git" }, - "comments": "git submodule at cmake/external/onnx-tensorrt" - } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "553df22c67bee5f0fe6599cff60f1afc6748c635", - "repositoryUrl": "https://github.com/onnx/onnx.git" - }, - "comments": "git submodule at cmake/external/onnx-tensorrt/third_party/onnx" - } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "e776aa0275e293707b6a0901e0e8d8a8a3679508", - "repositoryUrl": "https://github.com/google/benchmark.git" - }, - "comments": "git submodule at cmake/external/onnx-tensorrt/third_party/onnx/third_party/benchmark" - } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "09f082940113661256310e3f4811aa7261a9fa05", - "repositoryUrl": "https://github.com/pybind/pybind11.git" - }, - "comments": "git submodule at cmake/external/onnx-tensorrt/third_party/onnx/third_party/pybind11" - } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "6a00cbc4a9b8e68b71caf7f774b3f9c753ae84d5", - "repositoryUrl": "https://github.com/wjakob/clang-cindex-python3" - }, - "comments": "git submodule at cmake/external/onnx-tensorrt/third_party/onnx/third_party/pybind11/tools/clang" - } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "d4b2aff0c890ae38bad87c20f5731333db2a2cc1", - "repositoryUrl": "https://github.com/microsoft/onnxruntime-extensions.git" - }, - "comments": "git submodule at cmake/external/onnxruntime-extensions" + "comments": "onnx_tensorrt" } }, { @@ -336,27 +265,17 @@ "commitHash": "a902b39270841beafc307dfa709610aa1cac2f06", "repositoryUrl": "https://github.com/protocolbuffers/protobuf.git" }, - "comments": "git submodule at cmake/external/protobuf" + "comments": "protobuf" } }, { "component": { "type": "git", "git": { - "commitHash": "5b7683f49e1e9223cf9927b24f6fd3d6bd82e3f8", - "repositoryUrl": "https://github.com/google/benchmark.git" + "commitHash": "072586a71b55b7f8c584153d223e95687148a900", + "repositoryUrl": "https://github.com/Maratyszcza/psimd.git" }, - "comments": "git submodule at cmake/external/protobuf/third_party/benchmark" - } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "5ec7f0c4a113e2f18ac2c6cc7df51ad6afc24081", - "repositoryUrl": "https://github.com/google/googletest.git" - }, - "comments": "git submodule at cmake/external/protobuf/third_party/googletest" + "comments": "psimd" } }, { @@ -366,7 +285,17 @@ "commitHash": "1787867f6183f056420e532eec640cba25efafea", "repositoryUrl": "https://github.com/Maratyszcza/pthreadpool.git" }, - "comments": "git submodule at cmake/external/pthreadpool" + "comments": "pthreadpool" + } + }, + { + "component": { + "type": "git", + "git": { + "commitHash": "8de7772cc72daca8e947b79b83fea46214931604", + "repositoryUrl": "https://github.com/pybind/pybind11.git" + }, + "comments": "pybind11" } }, { @@ -376,17 +305,27 @@ "commitHash": "5916273f79a21551890fd3d56fc5375a78d1598d", "repositoryUrl": "https://github.com/pytorch/cpuinfo.git" }, - "comments": "git submodule at cmake/external/pytorch_cpuinfo" + "comments": "pytorch_cpuinfo" } }, { "component": { "type": "git", "git": { - "commitHash": "4244cd1cb492fa1d10986ec67f862964c073f844", + "commitHash": "5723bb8950318135ed9cf4fc76bed988a087f536", "repositoryUrl": "https://github.com/google/re2.git" }, - "comments": "git submodule at cmake/external/re2" + "comments": "re2" + } + }, + { + "component": { + "type": "git", + "git": { + "commitHash": "ff15c6ada150a5018c5ef2172401cb4529eac9c0", + "repositoryUrl": "https://github.com/dcleblanc/SafeInt.git" + }, + "comments": "safeint" } }, { @@ -396,17 +335,7 @@ "commitHash": "373eb09e4c5d2b3cc2493f0949dc4be6b6a45e81", "repositoryUrl": "https://github.com/tensorflow/tensorboard.git" }, - "comments": "git submodule at cmake/external/tensorboard" - } - }, - { - "component": { - "type": "git", - "git": { - "commitHash": "e8c599bca6c56c44b6730ad93f6abbc9ecd60fc1", - "repositoryUrl": "https://github.com/microsoft/wil.git" - }, - "comments": "git submodule at cmake/external/wil" + "comments": "tensorboard" } } ] diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index fe343c5601..3e820d7a4e 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -101,13 +101,8 @@ option(onnxruntime_ARMNN_RELU_USE_CPU "Use the CPU implementation for the Relu o option(onnxruntime_ARMNN_BN_USE_CPU "Use the CPU implementation for the Batch Normalization operator for the ArmNN EP" ON) option(onnxruntime_ENABLE_INSTRUMENT "Enable Instrument with Event Tracing for Windows (ETW)" OFF) option(onnxruntime_USE_TELEMETRY "Build with Telemetry" OFF) -option(onnxruntime_USE_MIMALLOC "Override new/delete and arena allocator with mimalloc" OFF) +cmake_dependent_option(onnxruntime_USE_MIMALLOC "Override new/delete and arena allocator with mimalloc" OFF "WIN32;NOT onnxruntime_USE_CUDA;NOT onnxruntime_USE_OPENVINO" OFF) option(onnxruntime_USE_CANN "Build with CANN support" OFF) -#The onnxruntime_PREFER_SYSTEM_LIB is mainly designed for package managers like apt/yum/vcpkg. -#Please note, by default Protobuf_USE_STATIC_LIBS is OFF but it's recommended to turn it ON on Windows. You should set it properly when onnxruntime_PREFER_SYSTEM_LIB is ON otherwise you'll hit linkage errors. -#If you have already installed protobuf(or the others) in your system at the default system paths(like /usr/include), then it's better to set onnxruntime_PREFER_SYSTEM_LIB ON. Otherwise onnxruntime may see two different protobuf versions and we won't know which one will be used, the worst case could be onnxruntime picked up header files from one of them but the binaries from the other one. -#It's default OFF because it's experimental now. -option(onnxruntime_PREFER_SYSTEM_LIB "Experimental: Build with the preinstalled libraries in your system" OFF) option(onnxruntime_USE_ROCM "Build with AMD GPU support" OFF) option(onnxruntime_USE_TVM "Build with TVM support" OFF) option(onnxruntime_TVM_CUDA_RUNTIME "Build TVM with CUDA support" OFF) @@ -116,7 +111,8 @@ option(onnxruntime_TVM_USE_HASH "Build ipp-crypto library for support hash algor option(onnxruntime_USE_XNNPACK "Build with XNNPACK support. Provides an alternative math library on ARM, WebAssembly and x86." OFF) # Options related to reducing the binary size produced by the build -option(onnxruntime_DISABLE_CONTRIB_OPS "Disable contrib ops" OFF) +# XNNPACK EP requires the internal NHWC contrib ops to be available, so this option must be OFF when onnxruntime_USE_XNNPACK is ON +cmake_dependent_option(onnxruntime_DISABLE_CONTRIB_OPS "Disable contrib ops" OFF "NOT onnxruntime_USE_XNNPACK" OFF) option(onnxruntime_DISABLE_ML_OPS "Disable traditional ML ops" OFF) option(onnxruntime_DISABLE_SPARSE_TENSORS "Disable sparse tensors data types" OFF) option(onnxruntime_DISABLE_OPTIONAL_TYPE "Disable optional type" OFF) @@ -222,6 +218,9 @@ endif() # Single output director for all binaries set(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin CACHE PATH "Single output directory for all binaries.") + +include(FetchContent) + function(set_msvc_c_cpp_compiler_warning_level warning_level) if (NOT "${warning_level}" MATCHES "^[0-4]$") message(FATAL_ERROR "Expected warning_level value of 0-4, got '${warning_level}'.") @@ -271,9 +270,6 @@ if (onnxruntime_ENABLE_MEMORY_PROFILE) add_definitions(-DORT_MEMORY_PROFILE=1) endif() -set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests" FORCE) -#nsync tests failed on Mac Build -set(NSYNC_ENABLE_TESTS OFF CACHE BOOL "Build protobuf tests" FORCE) set(ONNX_ML 1) if (NOT onnxruntime_ENABLE_PYTHON) set(onnxruntime_ENABLE_LANGUAGE_INTEROP_OPS OFF) @@ -325,171 +321,7 @@ if (onnxruntime_EXTENDED_MINIMAL_BUILD AND NOT onnxruntime_MINIMAL_BUILD) set(onnxruntime_MINIMAL_BUILD ON) endif() -# work around Android NDK bug which doesn't include -O flag for Release configuration -# https://github.com/android/ndk/issues/1740 -# TODO: remove this when the NDK version(s) we support get fixed -if (CMAKE_SYSTEM_NAME STREQUAL "Android") - # NB: attempting to match the effects of this fix: https://android-review.googlesource.com/c/platform/ndk/+/2168845 - string(APPEND CMAKE_C_FLAGS_RELEASE " -O3") - string(APPEND CMAKE_CXX_FLAGS_RELEASE " -O3") - string(APPEND CMAKE_ASM_FLAGS_RELEASE " -O3") -endif() - -# Enable space optimization for gcc/clang -# Cannot use "-ffunction-sections -fdata-sections" if we enable bitcode (iOS) -if (NOT MSVC AND NOT onnxruntime_ENABLE_BITCODE) - string(APPEND CMAKE_CXX_FLAGS " -ffunction-sections -fdata-sections") - string(APPEND CMAKE_C_FLAGS " -ffunction-sections -fdata-sections") -endif() - -if (onnxruntime_ENABLE_EAGER_MODE) - string(APPEND CMAKE_CXX_FLAGS " -D_GLIBCXX_USE_CXX11_ABI=${_GLIBCXX_USE_CXX11_ABI}") -endif() - -if (onnxruntime_BUILD_WEBASSEMBLY) - # Enable LTO for release single-thread build - if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") - # NOTES: - # (1) LTO does not work for WebAssembly multi-thread. (segment fault in worker) - # (2) "-flto=thin" does not work correctly for wasm-ld. - # we don't set onnxruntime_ENABLE_LTO because it appends flag "-flto=thin" - # instead, we manually set CMAKE_CXX_FLAGS "-flto" - string(APPEND CMAKE_C_FLAGS " -flto") - string(APPEND CMAKE_CXX_FLAGS " -flto") - endif() - - if (onnxruntime_ENABLE_WEBASSEMBLY_DEBUG_INFO) - # "-g3" generates DWARF format debug info. - # NOTE: With debug info enabled, web assembly artifacts will be very huge (>1GB). So we offer an option to build without debug info. - set(CMAKE_CXX_FLAGS_DEBUG "-g3") - else() - set(CMAKE_CXX_FLAGS_DEBUG "-g2") - endif() - - if (onnxruntime_ENABLE_WEBASSEMBLY_SIMD) - string(APPEND CMAKE_C_FLAGS " -msimd128") - string(APPEND CMAKE_CXX_FLAGS " -msimd128") - endif() - - if (onnxruntime_ENABLE_WEBASSEMBLY_EXCEPTION_CATCHING) - string(APPEND CMAKE_C_FLAGS " -s DISABLE_EXCEPTION_CATCHING=0") - string(APPEND CMAKE_CXX_FLAGS " -s DISABLE_EXCEPTION_CATCHING=0") - endif() - - # Build WebAssembly with multi-threads support. - if (onnxruntime_ENABLE_WEBASSEMBLY_THREADS) - string(APPEND CMAKE_C_FLAGS " -pthread") - string(APPEND CMAKE_CXX_FLAGS " -pthread") - string(APPEND CMAKE_C_FLAGS " -s USE_PTHREADS=1 -Wno-pthreads-mem-growth") - string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS=1 -Wno-pthreads-mem-growth") - endif() -endif() - -if (onnxruntime_EXTERNAL_TRANSFORMER_SRC_PATH) - add_definitions(-DORT_TRAINING_EXTERNAL_GRAPH_TRANSFORMERS=1) -endif() - -# ORT build with as much excluded as possible. Supports ORT flatbuffers models only. -if (onnxruntime_MINIMAL_BUILD) - add_compile_definitions(ORT_MINIMAL_BUILD) - - if (onnxruntime_EXTENDED_MINIMAL_BUILD) - # enable EPs that compile kernels at runtime - add_compile_definitions(ORT_EXTENDED_MINIMAL_BUILD) - endif() - - if (onnxruntime_MINIMAL_BUILD_CUSTOM_OPS) - add_compile_definitions(ORT_MINIMAL_BUILD_CUSTOM_OPS) - endif() - - if (MSVC) - # turn on LTO (which adds some compiler flags and turns on LTCG) unless it's a Debug build to minimize binary size - if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") - set(onnxruntime_ENABLE_LTO ON) - endif() - - # undocumented internal flag to allow analysis of a minimal build binary size - if (ADD_DEBUG_INFO_TO_MINIMAL_BUILD) - string(APPEND CMAKE_CXX_FLAGS " /Zi") - string(APPEND CMAKE_C_FLAGS " /Zi") - string(APPEND CMAKE_SHARED_LINKER_FLAGS " /debug") - endif() - else() - if (CMAKE_HOST_SYSTEM MATCHES "Darwin") - add_link_options(-Wl, -dead_strip) - else() - add_link_options(-Wl,--gc-sections) - endif() - - if (ADD_DEBUG_INFO_TO_MINIMAL_BUILD) - string(APPEND CMAKE_CXX_FLAGS " -g") - string(APPEND CMAKE_C_FLAGS " -g") - endif() - endif() -endif() - -if (onnxruntime_ENABLE_LTO) - include(CheckIPOSupported) - check_ipo_supported(RESULT ipo_enabled OUTPUT ipo_output) - if (NOT ipo_enabled) - message(WARNING "IPO is not supported by this compiler") - set(onnxruntime_ENABLE_LTO OFF) - else() - set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) - endif() -endif() - -if (onnxruntime_REDUCED_OPS_BUILD) - add_compile_definitions(REDUCED_OPS_BUILD) -endif() - -if (onnxruntime_DISABLE_EXTERNAL_INITIALIZERS) - add_definitions(-DDISABLE_EXTERNAL_INITIALIZERS=1) -endif() - -if (onnxruntime_DISABLE_RTTI) - add_compile_definitions(ORT_NO_RTTI) - if (MSVC) - # Disable RTTI and turn usage of dynamic_cast and typeid into errors - add_compile_options("$<$:/GR->" "$<$:/we4541>") - else() - add_compile_options("$<$:-fno-rtti>") - endif() -else() - #MSVC RTTI flag /GR is not added to CMAKE_CXX_FLAGS by default. But, anyway VC++2019 treats "/GR" default on. - #So we don't need the following three lines. But it's better to make it more explicit. - if (MSVC) - add_compile_options("$<$:/GR>") - endif() -endif() - -# If this is only enabled in an onnxruntime_ORT_MODEL_FORMAT_ONLY build we don't need ONNX changes -# as we (currently) only pull in data_type_utils.cc/h which doesn't throw -if (onnxruntime_DISABLE_EXCEPTIONS) - if (NOT onnxruntime_MINIMAL_BUILD) - message(FATAL_ERROR "onnxruntime_MINIMAL_BUILD required for onnxruntime_DISABLE_EXCEPTIONS") - endif() - - if (onnxruntime_ENABLE_PYTHON) - # pybind11 highly depends on C++ exceptions. - message(FATAL_ERROR "onnxruntime_ENABLE_PYTHON must be disabled for onnxruntime_DISABLE_EXCEPTIONS") - endif() - add_compile_definitions("ORT_NO_EXCEPTIONS") - add_compile_definitions("MLAS_NO_EXCEPTION") - add_compile_definitions("ONNX_NO_EXCEPTIONS") - add_compile_definitions("JSON_NOEXCEPTION") # https://json.nlohmann.me/api/macros/json_noexception/ - - if (MSVC) - string(REGEX REPLACE "/EHsc" "/EHs-c-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - # Eigen throw_std_bad_alloc calls 'new' instead of throwing which results in a nodiscard warning. - # It also has unreachable code as there's no good way to avoid EIGEN_EXCEPTIONS being set in macros.h - # TODO: see if we can limit the code this is disabled for. - string(APPEND CMAKE_CXX_FLAGS " /wd4834 /wd4702") - add_compile_definitions("_HAS_EXCEPTIONS=0") - else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables") - endif() -endif() +include(adjust_global_compile_flags.cmake) # We need to link with libatomic on systems that do not have built-in atomics, or # don't have built-in support for 8 byte atomics @@ -519,41 +351,8 @@ set(ORTTRAINING_SOURCE_DIR ${ORTTRAINING_ROOT}/orttraining) file (STRINGS "${REPO_ROOT}/VERSION_NUMBER" ORT_VERSION) -# Guarantee that the Eigen code that you are #including is licensed -# under the MPL2 and possibly more permissive licenses (like BSD). -add_definitions(-DEIGEN_MPL2_ONLY) -if (MSVC) - add_definitions(-DEIGEN_HAS_CONSTEXPR -DEIGEN_HAS_VARIADIC_TEMPLATES -DEIGEN_HAS_CXX11_MATH -DEIGEN_HAS_CXX11_ATOMIC - -DEIGEN_STRONG_INLINE=inline) -endif() - -if ( onnxruntime_DONT_VECTORIZE ) - add_definitions(-DEIGEN_DONT_VECTORIZE=1) -endif() - -if (onnxruntime_CROSS_COMPILING) - set(CMAKE_CROSSCOMPILING ON) - check_cxx_compiler_flag(-Wno-error HAS_NOERROR) - if (HAS_NOERROR) - string(APPEND CMAKE_CXX_FLAGS " -Wno-error=attributes") - string(APPEND CMAKE_C_FLAGS " -Wno-error=attributes") - endif() -endif() - -if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) - check_cxx_compiler_flag(-Wno-error HAS_NOERROR) - if (HAS_NOERROR) - string(APPEND CMAKE_CXX_FLAGS " -Wno-error=attributes") - string(APPEND CMAKE_C_FLAGS " -Wno-error=attributes") - endif() -endif() - -# Mark symbols to be invisible, for macOS/iOS target only -# Due to many dependencies have different symbol visibility settings, set global compile flags here. -if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS") - foreach(flags CMAKE_CXX_FLAGS CMAKE_OBJC_FLAGS CMAKE_OBJCXX_FLAGS) - string(APPEND ${flags} " -fvisibility=hidden -fvisibility-inlines-hidden") - endforeach() +if (onnxruntime_ENABLE_TRAINING) + set(onnxruntime_ENABLE_ATEN ON) endif() find_package(Threads) @@ -562,191 +361,6 @@ if(Patch_FOUND) message("Patch found: ${Patch_EXECUTABLE}") endif() -macro(check_nvcc_compiler_flag _FLAG _RESULT) - execute_process(COMMAND ${onnxruntime_CUDA_HOME}/bin/nvcc "${_FLAG}" RESULT_VARIABLE NVCC_OUT ERROR_VARIABLE NVCC_ERROR) - message("NVCC_ERROR = ${NVCC_ERROR}") - message("NVCC_OUT = ${NVCC_OUT}") - if ("${NVCC_OUT}" MATCHES "0") - set(${_RESULT} 1) - else() - set(${_RESULT} 0) - endif() -endmacro() - -#Set global compile flags for all the source code(including third_party code like protobuf) -#This section must be before any add_subdirectory, otherwise build may fail because /MD,/MT mismatch -if (MSVC) - enable_language(ASM_MASM) - if (CMAKE_GENERATOR_PLATFORM) - # Multi-platform generator - set(onnxruntime_target_platform ${CMAKE_GENERATOR_PLATFORM}) - else() - set(onnxruntime_target_platform ${CMAKE_SYSTEM_PROCESSOR}) - endif() - if (onnxruntime_target_platform STREQUAL "ARM64") - set(onnxruntime_target_platform "ARM64") - elseif (onnxruntime_target_platform STREQUAL "ARM64EC") - set(onnxruntime_target_platform "ARM64EC") - elseif (onnxruntime_target_platform STREQUAL "ARM" OR CMAKE_GENERATOR MATCHES "ARM") - set(onnxruntime_target_platform "ARM") - elseif (onnxruntime_target_platform STREQUAL "x64" OR onnxruntime_target_platform STREQUAL "x86_64" OR onnxruntime_target_platform STREQUAL "AMD64" OR CMAKE_GENERATOR MATCHES "Win64") - set(onnxruntime_target_platform "x64") - elseif (onnxruntime_target_platform STREQUAL "Win32" OR onnxruntime_target_platform STREQUAL "x86" OR onnxruntime_target_platform STREQUAL "i386" OR onnxruntime_target_platform STREQUAL "i686") - set(onnxruntime_target_platform "x86") - if (NOT onnxruntime_BUILD_WEBASSEMBLY) - message("Enabling SAFESEH for x86 build") - set(CMAKE_ASM_MASM_FLAGS "${CMAKE_ASM_MASM_FLAGS} /safeseh") - endif() - endif() - - - #Always enable exception handling, even for Windows ARM - if (NOT onnxruntime_DISABLE_EXCEPTIONS) - string(APPEND CMAKE_CXX_FLAGS " /EHsc") - string(APPEND CMAKE_C_FLAGS " /EHsc") - - string(APPEND CMAKE_CXX_FLAGS " /wd26812") - string(APPEND CMAKE_C_FLAGS " /wd26812") - # warning C4805: '|': unsafe mix of type 'uintptr_t' and type 'bool' in operation (from c10/core/TensorImpl.h) - if (onnxruntime_ENABLE_EAGER_MODE) - string(APPEND CMAKE_CXX_FLAGS " /wd4805") - endif() - endif() - string(APPEND CMAKE_CXX_FLAGS " /experimental:external /external:W0 /external:templates- /external:I ${CMAKE_CURRENT_SOURCE_DIR} /external:I ${CMAKE_CURRENT_BINARY_DIR}") - if (onnxruntime_USE_AVX) - string(APPEND CMAKE_CXX_FLAGS " /arch:AVX") - string(APPEND CMAKE_C_FLAGS " /arch:AVX") - elseif (onnxruntime_USE_AVX2) - string(APPEND CMAKE_CXX_FLAGS " /arch:AVX2") - string(APPEND CMAKE_C_FLAGS " /arch:AVX2") - elseif (onnxruntime_USE_AVX512) - string(APPEND CMAKE_CXX_FLAGS " /arch:AVX512") - string(APPEND CMAKE_C_FLAGS " /arch:AVX512") - endif() - - if (onnxruntime_ENABLE_LTO AND NOT onnxruntime_USE_CUDA) - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Gw /GL") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Gw /GL") - set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /Gw /GL") - endif() - - # The WinML build tool chain builds ARM/ARM64, and the internal tool chain does not have folders for spectre mitigation libs. - # WinML performs spectre mitigation differently. - if (NOT DEFINED onnxruntime_DISABLE_QSPECTRE_CHECK) - check_cxx_compiler_flag(-Qspectre HAS_QSPECTRE) - if (HAS_QSPECTRE) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Qspectre") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qspectre") - endif() - endif() - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DYNAMICBASE") - check_cxx_compiler_flag(-guard:cf HAS_GUARD_CF) - if (HAS_GUARD_CF) - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /guard:cf") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /guard:cf") - set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /guard:cf") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /guard:cf") - set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /guard:cf") - set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /guard:cf") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf") - endif() -else() - if (NOT APPLE) - set(onnxruntime_target_platform ${CMAKE_SYSTEM_PROCESSOR}) - endif() - if (onnxruntime_BUILD_FOR_NATIVE_MACHINE) - string(APPEND CMAKE_CXX_FLAGS " -march=native -mtune=native") - string(APPEND CMAKE_C_FLAGS " -march=native -mtune=native") - elseif (onnxruntime_USE_AVX) - string(APPEND CMAKE_CXX_FLAGS " -mavx") - string(APPEND CMAKE_C_FLAGS " -mavx") - elseif (onnxruntime_USE_AVX2) - string(APPEND CMAKE_CXX_FLAGS " -mavx2") - string(APPEND CMAKE_C_FLAGS " -mavx2") - elseif (onnxruntime_USE_AVX512) - string(APPEND CMAKE_CXX_FLAGS " -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl") - string(APPEND CMAKE_C_FLAGS " -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl") - endif() - - # Check support for AVX and f16c. - include(CheckCXXCompilerFlag) - check_cxx_compiler_flag("-mf16c" COMPILER_SUPPORT_MF16C) - if (NOT COMPILER_SUPPORT_MF16C) - message("F16C instruction set is not supported.") - endif() - - check_cxx_compiler_flag("-mfma" COMPILER_SUPPORT_FMA) - if (NOT COMPILER_SUPPORT_FMA) - message("FMA instruction set is not supported.") - endif() - - check_cxx_compiler_flag("-mavx" COMPILER_SUPPORT_AVX) - if (NOT COMPILER_SUPPORT_AVX) - message("AVX instruction set is not supported.") - endif() - - if (CMAKE_SYSTEM_NAME STREQUAL "Android" AND onnxruntime_ENABLE_TRAINING_ON_DEVICE) - message("F16C, FMA and AVX flags are not supported on Android for on-device training.") - endif() - - if (NOT (COMPILER_SUPPORT_MF16C AND COMPILER_SUPPORT_FMA AND COMPILER_SUPPORT_AVX) OR - (CMAKE_SYSTEM_NAME STREQUAL "Android" AND onnxruntime_ENABLE_TRAINING_ON_DEVICE)) - message("One or more AVX/F16C instruction flags are not supported. ") - set(onnxruntime_ENABLE_CPU_FP16_OPS FALSE) - endif() - - # This is enabled only for Adasum files in training mode. - # The flags won't be applied globally since some high-precision training and inferencing ops will incur precision loss. - if (onnxruntime_ENABLE_CPU_FP16_OPS) - set_source_files_properties(${ORTTRAINING_SOURCE_DIR}/core/framework/adasum/adasum_mpi.cc PROPERTIES COMPILE_FLAGS " -fassociative-math -ffast-math -ftree-vectorize -funsafe-math-optimizations -mf16c -mavx -mfma ") - set_source_files_properties(${ORTTRAINING_SOURCE_DIR}/training_ops/cpu/collective/adasum_kernels.cc PROPERTIES COMPILE_FLAGS " -fassociative-math -ffast-math -ftree-vectorize -funsafe-math-optimizations -mf16c -mavx -mfma ") - set_source_files_properties(${ORTTRAINING_SOURCE_DIR}/training_ops/cuda/collective/adasum_kernels.cc PROPERTIES COMPILE_FLAGS " -fassociative-math -ffast-math -ftree-vectorize -funsafe-math-optimizations -mf16c -mavx -mfma ") - add_definitions(-DENABLE_CPU_FP16_TRAINING_OPS) - endif() -endif() - -if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - #For Mac compliance - message("Adding flags for Mac builds") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong") -endif() - -#Dependencies begin -if (onnxruntime_BUILD_UNIT_TESTS) - if (onnxruntime_PREFER_SYSTEM_LIB) - find_package(GTest CONFIG) - endif() - if (TARGET GTest::gtest) - message("Use gtest from preinstalled system lib") - else() - message("Use gtest from submodule") - - # WebAssembly threading support in Node.js is still an experimental feature and - # not working properly with googletest suite. - if (onnxruntime_BUILD_WEBASSEMBLY) - set(gtest_disable_pthreads ON) - endif() - - # gtest and gmock - set_msvc_c_cpp_compiler_warning_level(4) - add_subdirectory(${PROJECT_SOURCE_DIR}/external/googletest EXCLUDE_FROM_ALL) - set_msvc_c_cpp_compiler_warning_level(3) - set_target_properties(gmock PROPERTIES FOLDER "External/GTest") - if (NOT MSVC) - # disable treating all warnings as errors for gmock - target_compile_options(gmock PRIVATE "-w") - target_compile_options(gtest PRIVATE "-w") - endif() - set_target_properties(gmock_main PROPERTIES FOLDER "External/GTest") - set_target_properties(gtest PROPERTIES FOLDER "External/GTest") - set_target_properties(gtest_main PROPERTIES FOLDER "External/GTest") - endif() -endif() - -set(ENABLE_DATE_TESTING OFF CACHE BOOL "" FORCE) -set(USE_SYSTEM_TZ_DB ON CACHE BOOL "" FORCE) -set(RE2_BUILD_TESTING OFF CACHE BOOL "" FORCE) - if (CMAKE_CROSSCOMPILING) message("Doing crosscompiling") endif() @@ -764,325 +378,16 @@ if (onnxruntime_BUILD_SHARED_LIB OR onnxruntime_ENABLE_PYTHON) endif() endif() -#target begins from here - -if (onnxruntime_BUILD_BENCHMARKS) - if (onnxruntime_PREFER_SYSTEM_LIB) - find_package(benchmark CONFIG) - endif() - if (TARGET benchmark::benchmark) - message("Use benchmark from preinstalled system lib") - else() - message("Use benchmark from submodule") - # We will not need to test benchmark lib itself. - set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark testing as we don't need it.") - # We will not need to install benchmark since we link it statically. - set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Disable benchmark install to avoid overwriting vendor install.") - add_subdirectory(${PROJECT_SOURCE_DIR}/external/googlebenchmark EXCLUDE_FROM_ALL) - #add_library(benchmark::benchmark ALIAS benchmark) - endif() -endif() - -if (NOT WIN32) - if (onnxruntime_PREFER_SYSTEM_LIB) - find_package(nsync) - endif() - if (TARGET nsync_cpp) # linking error with nsync_FOUND (why?) - message("Use nsync from preinstalled system lib") - else() - message("Use nsync from submodule") - add_subdirectory(${PROJECT_SOURCE_DIR}/external/nsync EXCLUDE_FROM_ALL) - endif() -endif() -# External dependencies -list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/external) - -include(external/helper_functions.cmake) - -file(STRINGS deps.txt ONNXRUNTIME_DEPS_LIST) -foreach(ONNXRUNTIME_DEP IN LISTS ONNXRUNTIME_DEPS_LIST) - # Lines start with "#" are comments - if(NOT ONNXRUNTIME_DEP MATCHES "^#") - # The first column is name - list(POP_FRONT ONNXRUNTIME_DEP ONNXRUNTIME_DEP_NAME) - # The second column is URL - # The URL below may be a local file path or an HTTPS URL - list(POP_FRONT ONNXRUNTIME_DEP ONNXRUNTIME_DEP_URL) - set(DEP_URL_${ONNXRUNTIME_DEP_NAME} ${ONNXRUNTIME_DEP_URL}) - # The third column is SHA1 hash value - set(DEP_SHA1_${ONNXRUNTIME_DEP_NAME} ${ONNXRUNTIME_DEP}) - endif() -endforeach() - -#protobuf begin - -#Here we support two build mode: -#1. if ONNX_CUSTOM_PROTOC_EXECUTABLE is set, build Protobuf from source, except protoc.exe. This mode is mainly -# for cross-compiling -#2. if ONNX_CUSTOM_PROTOC_EXECUTABLE is not set, Compile everything(including protoc) from source code. - -if(Patch_FOUND) - set(ONNXRUNTIME_PROTOBUF_PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/protobuf/protobuf_cmake.patch) -else() - set(ONNXRUNTIME_PROTOBUF_PATCH_COMMAND "") -endif() - -FetchContent_Declare( - Protobuf - URL ${DEP_URL_protobuf} - URL_HASH SHA1=${DEP_SHA1_protobuf} - SOURCE_SUBDIR cmake - PATCH_COMMAND ${ONNXRUNTIME_PROTOBUF_PATCH_COMMAND} - FIND_PACKAGE_ARGS NAMES Protobuf -) - -if (CMAKE_SYSTEM_NAME STREQUAL "Android") - set(protobuf_BUILD_PROTOC_BINARIES OFF CACHE BOOL "Build protobuf tests" FORCE) - set(protobuf_WITH_ZLIB OFF CACHE BOOL "Build with zlib support" FORCE) -endif() -if (onnxruntime_DISABLE_RTTI) - set(protobuf_DISABLE_RTTI ON CACHE BOOL "Remove runtime type information in the binaries" FORCE) -endif() - -onnxruntime_fetchcontent_makeavailable(Protobuf) -if(Protobuf_FOUND) - message("Protobuf version: ${Protobuf_VERSION}") -else() - # Adjust warning flags - if (TARGET libprotoc) - set_target_properties(libprotoc PROPERTIES FOLDER "External/Protobuf") - if (NOT MSVC) - target_compile_options(libprotoc PRIVATE "-w") - endif() - endif() - if (TARGET protoc) - add_executable(protobuf::protoc ALIAS protoc) - if (NOT MSVC) - target_compile_options(protoc PRIVATE "-w") - endif() - set_target_properties(protoc PROPERTIES FOLDER "External/Protobuf") - get_target_property(PROTOC_OSX_ARCH protoc OSX_ARCHITECTURES) - if (PROTOC_OSX_ARCH) - if (${CMAKE_HOST_SYSTEM_PROCESSOR} IN_LIST PROTOC_OSX_ARCH) - message("protoc can run") - else() - list(APPEND PROTOC_OSX_ARCH ${CMAKE_HOST_SYSTEM_PROCESSOR}) - set_target_properties(protoc PROPERTIES OSX_ARCHITECTURES "${CMAKE_HOST_SYSTEM_PROCESSOR}") - set_target_properties(libprotoc PROPERTIES OSX_ARCHITECTURES "${PROTOC_OSX_ARCH}") - set_target_properties(libprotobuf PROPERTIES OSX_ARCHITECTURES "${PROTOC_OSX_ARCH}") - endif() - endif() - endif() - if (TARGET libprotobuf AND NOT MSVC) - target_compile_options(libprotobuf PRIVATE "-w") - endif() - if (TARGET libprotobuf-lite AND NOT MSVC) - target_compile_options(libprotobuf-lite PRIVATE "-w") - endif() -endif() -if (onnxruntime_USE_FULL_PROTOBUF) - set(PROTOBUF_LIB protobuf::libprotobuf) -else() - set(PROTOBUF_LIB protobuf::libprotobuf-lite) -endif() - -include(protobuf_function.cmake) -#protobuf end - -if (onnxruntime_DISABLE_CONTRIB_OPS) - add_definitions(-DDISABLE_CONTRIB_OPS) -endif() - -if (onnxruntime_DISABLE_ML_OPS) - add_definitions(-DDISABLE_ML_OPS) -endif() - -if (onnxruntime_DISABLE_SPARSE_TENSORS) - add_compile_definitions(DISABLE_SPARSE_TENSORS) -endif() - -if (onnxruntime_DISABLE_OPTIONAL_TYPE) - add_compile_definitions(DISABLE_OPTIONAL_TYPE) -endif() - +#Dependencies begin get_filename_component(ONNXRUNTIME_ROOT "${ONNXRUNTIME_ROOT}" ABSOLUTE) get_filename_component(ORTTRAINING_ROOT "${ORTTRAINING_ROOT}" ABSOLUTE) get_filename_component(REPO_ROOT "${REPO_ROOT}" ABSOLUTE) set(ONNXRUNTIME_INCLUDE_DIR ${REPO_ROOT}/include/onnxruntime) -if (onnxruntime_PREFER_SYSTEM_LIB) - find_package(date) -endif() -if (date_FOUND) - message("Use date from preinstalled system lib") - add_library(date_interface ALIAS date::date) -else() - message("Use date from submodule") - add_subdirectory(external/date EXCLUDE_FROM_ALL) -endif() - -set(SAFEINT_INCLUDE_DIR ${REPO_ROOT}/cmake/external/SafeInt) -add_library(safeint_interface INTERFACE) -target_include_directories(safeint_interface INTERFACE ${SAFEINT_INCLUDE_DIR}) - -if (onnxruntime_PREFER_SYSTEM_LIB) - find_package(boost_mp11) - find_package(Boost) - if (TARGET Boost::boost AND NOT TARGET Boost::mp11) - add_library(Boost::mp11 ALIAS Boost::boost) - endif() -endif() -if (TARGET Boost::mp11) - message("Use mp11 from preinstalled system lib") -else() - message("Use mp11 from submodule") - add_subdirectory(external/mp11 EXCLUDE_FROM_ALL) -endif() - -if (onnxruntime_PREFER_SYSTEM_LIB) - find_package(nlohmann_json) -endif() -if (nlohmann_json_FOUND) - message("Use json from preinstalled system lib") -else() - message("Use json from submodule") - set(JSON_BuildTests OFF CACHE INTERNAL "") - set(JSON_Install OFF CACHE INTERNAL "") - add_subdirectory(external/json EXCLUDE_FROM_ALL) -endif() - -if (onnxruntime_PREFER_SYSTEM_LIB) - find_package(re2) -endif() -if (re2_FOUND) - message("Use re2 from preinstalled system lib") -else() - message("Use re2 from submodule") - add_subdirectory(external/re2 EXCLUDE_FROM_ALL) - set_target_properties(re2 PROPERTIES FOLDER "External/re2") - set(RE2_INCLUDE_DIR ${REPO_ROOT}/cmake/external/re2) -endif() - -if (onnxruntime_ENABLE_CPUINFO) - # Adding pytorch CPU info library - # TODO!! need a better way to find out the supported architectures - list(LENGTH CMAKE_OSX_ARCHITECTURES CMAKE_OSX_ARCHITECTURES_LEN) - if (APPLE) - if (CMAKE_OSX_ARCHITECTURES_LEN LESS_EQUAL 1) - set(CPUINFO_SUPPORTED TRUE) - elseif (onnxruntime_BUILD_APPLE_FRAMEWORK) - # We stitch multiple static libraries together when onnxruntime_BUILD_APPLE_FRAMEWORK is true, - # but that would not work for universal static libraries - message(FATAL_ERROR "universal binary is not supported for apple framework") - endif() - else() - # if xnnpack is enabled in a wasm build it needs clog from cpuinfo, but we won't internally use cpuinfo - # so we don't set CPUINFO_SUPPORTED in the CXX flags below. - if (onnxruntime_BUILD_WEBASSEMBLY AND NOT onnxruntime_USE_XNNPACK) - set(CPUINFO_SUPPORTED FALSE) - else() - set(CPUINFO_SUPPORTED TRUE) - endif() - if (WIN32) - # Exclude Windows ARM build and Windows Store - if (${onnxruntime_target_platform} MATCHES "^(ARM.*|arm.*)$" ) - message(WARNING "Cpuinfo not included for compilation problems with Windows ARM.") - set(CPUINFO_SUPPORTED FALSE) - elseif (WIN32 AND NOT CMAKE_CXX_STANDARD_LIBRARIES MATCHES kernel32.lib) - message(WARNING "Cpuinfo not included non-Desktop builds") - set(CPUINFO_SUPPORTED FALSE) - endif() - elseif (NOT ${onnxruntime_target_platform} MATCHES "^(i[3-6]86|AMD64|x86(_64)?|armv[5-8].*|aarch64|arm64)$") - message(WARNING - "Target processor architecture \"${onnxruntime_target_platform}\" is not supported in cpuinfo. " - "cpuinfo not included." - ) - set(CPUINFO_SUPPORTED FALSE) - endif() - endif() -else() - set(CPUINFO_SUPPORTED FALSE) -endif() - -if (CPUINFO_SUPPORTED) - if (CMAKE_SYSTEM_NAME STREQUAL "iOS") - set(IOS ON CACHE INTERNAL "") - set(IOS_ARCH "${CMAKE_OSX_ARCHITECTURES}" CACHE INTERNAL "") - endif() - - # if this is a wasm build with xnnpack (only type of wasm build where cpuinfo is involved) - # we do not use cpuinfo in ORT code, so don't define CPUINFO_SUPPORTED. - if (NOT onnxruntime_BUILD_WEBASSEMBLY) - string(APPEND CMAKE_CXX_FLAGS " -DCPUINFO_SUPPORTED") - endif() - - if (onnxruntime_PREFER_SYSTEM_LIB) - find_package(cpuinfo) - endif() - if (cpuinfo_FOUND) - message("Use cpuinfo from preinstalled system lib") - else() - message("Use cpuinfo from submodule") - set(CPUINFO_BUILD_TOOLS OFF CACHE INTERNAL "") - set(CPUINFO_BUILD_UNIT_TESTS OFF CACHE INTERNAL "") - set(CPUINFO_BUILD_MOCK_TESTS OFF CACHE INTERNAL "") - set(CPUINFO_BUILD_BENCHMARKS OFF CACHE INTERNAL "") - add_subdirectory(external/pytorch_cpuinfo EXCLUDE_FROM_ALL) - if (MSVC) - target_compile_options(cpuinfo PRIVATE "-D_CRT_SECURE_NO_WARNINGS") - endif() - endif() -endif() - -include(gsl) - -include(eigen) - -#onnxruntime_EXTERNAL_LIBRARIES could contain onnx, onnx_proto,libprotobuf, cuda/cudnn, -# dnnl/mklml, onnxruntime_codegen_tvm, tvm and pthread -# pthread is always at the last -set(onnxruntime_EXTERNAL_LIBRARIES onnx onnx_proto ${PROTOBUF_LIB} re2::re2 ${GSL_TARGET}) - -if(NOT onnxruntime_DISABLE_ABSEIL) - set(ABSEIL_LIBS absl::inlined_vector absl::flat_hash_set - absl::flat_hash_map absl::node_hash_set absl::node_hash_map absl::base absl::throw_delegate absl::raw_hash_set - absl::hash absl::city absl::low_level_hash absl::raw_logging_internal) - list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${ABSEIL_LIBS}) -else() - add_compile_definitions(DISABLE_ABSEIL) -endif() - -set(onnxruntime_LINK_DIRS ) -if (onnxruntime_USE_CUDA) - #TODO: combine onnxruntime_CUDNN_HOME and onnxruntime_CUDA_HOME, assume they are the same - if (WIN32) - if(onnxruntime_CUDNN_HOME) - list(APPEND onnxruntime_LINK_DIRS ${onnxruntime_CUDNN_HOME}/lib ${onnxruntime_CUDNN_HOME}/lib/x64) - endif() - list(APPEND onnxruntime_LINK_DIRS ${onnxruntime_CUDA_HOME}/x64/lib64) - else() - if(onnxruntime_CUDNN_HOME) - list(APPEND onnxruntime_LINK_DIRS ${onnxruntime_CUDNN_HOME}/lib64) - endif() - list(APPEND onnxruntime_LINK_DIRS ${onnxruntime_CUDA_HOME}/lib64) - endif() -endif() - -if(onnxruntime_USE_SNPE) - include(find_snpe.cmake) - list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${SNPE_NN_LIBS}) -endif() - -FILE(TO_NATIVE_PATH ${CMAKE_BINARY_DIR} ORT_BINARY_DIR) -FILE(TO_NATIVE_PATH ${PROJECT_SOURCE_DIR} ORT_SOURCE_DIR) - - +include(external/onnxruntime_external_deps.cmake) set(ORT_WARNING_FLAGS) if (WIN32) - # parallel build - # These compiler opitions cannot be forwarded to NVCC, so cannot use add_compiler_options - string(APPEND CMAKE_CXX_FLAGS " /MP") # class needs to have dll-interface to be used by clients list(APPEND ORT_WARNING_FLAGS "/wd4251") # issued by thrust nonstandard extension used: nameless struct/union @@ -1120,7 +425,6 @@ if (WIN32) endif() else() - add_definitions(-DPLATFORM_POSIX) check_cxx_compiler_flag(-Wunused-but-set-parameter HAS_UNUSED_BUT_SET_PARAMETER) check_cxx_compiler_flag(-Wunused-but-set-variable HAS_UNUSED_BUT_SET_VARIABLE) check_cxx_compiler_flag(-Wunused-variable HAS_UNUSED_VARIABLE) @@ -1167,7 +471,6 @@ else() if (HAS_DEPRECATED_BUILTINS) list(APPEND ORT_WARNING_FLAGS -Wno-deprecated-builtins) endif() - #see:https://reviews.llvm.org/D131307 #It was intended that the 'enum-constexpr-conversion' type warnings can not be silenced by -w if(HAS_ENUM_CONSTEXPR_CONVERSION AND NOT Protobuf_FOUND) @@ -1282,7 +585,37 @@ if (onnxruntime_USE_CANN) endif() function(onnxruntime_set_compile_flags target_name) + if (CPUINFO_SUPPORTED) + onnxruntime_add_include_to_target(${target_name} cpuinfo) + endif() + if (onnxruntime_ENABLE_CPU_FP16_OPS) + target_compile_definitions(${target_name} PRIVATE ENABLE_CPU_FP16_TRAINING_OPS) + endif() + if(onnxruntime_DISABLE_ABSEIL) + target_compile_definitions(${target_name} PRIVATE DISABLE_ABSEIL) + endif() + if(UNIX) + target_compile_definitions(${target_name} PRIVATE PLATFORM_POSIX) + endif() target_compile_definitions(${target_name} PUBLIC EIGEN_USE_THREADS) + if (onnxruntime_DISABLE_CONTRIB_OPS) + target_compile_definitions(${target_name} PRIVATE DISABLE_CONTRIB_OPS) + endif() + + if (onnxruntime_DISABLE_ML_OPS) + target_compile_definitions(${target_name} PRIVATE DISABLE_ML_OPS) + endif() + + if (onnxruntime_DISABLE_SPARSE_TENSORS) + target_compile_definitions(${target_name} PRIVATE DISABLE_SPARSE_TENSORS) + endif() + + if (onnxruntime_DISABLE_OPTIONAL_TYPE) + target_compile_definitions(${target_name} PRIVATE DISABLE_OPTIONAL_TYPE) + endif() + if (onnxruntime_ENABLE_ATEN) + target_compile_definitions(${target_name} PRIVATE ENABLE_ATEN) + endif() set_target_properties(${target_name} PROPERTIES COMPILE_WARNING_AS_ERROR ON) if (onnxruntime_USE_CUDA) # Suppress a "conversion_function_not_usable" warning in gsl/span @@ -1313,7 +646,7 @@ function(onnxruntime_set_compile_flags target_name) target_compile_options(${target_name} PRIVATE "-Wno-unused-parameter") endif() target_compile_definitions(${target_name} PUBLIC -DNSYNC_ATOMIC_CPP11) - target_include_directories(${target_name} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/external/nsync/public") + target_include_directories(${target_name} PRIVATE "${google_nsync_SOURCE_DIR}/public") endif() foreach(ORT_FLAG ${ORT_PROVIDER_FLAGS}) target_compile_definitions(${target_name} PRIVATE ${ORT_FLAG}) @@ -1428,14 +761,14 @@ endfunction() function(onnxruntime_add_include_to_target dst_target) foreach(src_target ${ARGN}) + if(TARGET ${src_target}) target_include_directories(${dst_target} PRIVATE $) target_compile_definitions(${dst_target} PRIVATE $) target_sources(${dst_target} PRIVATE $) + endif() endforeach() endfunction() -set(onnxruntime_EXTERNAL_DEPENDENCIES onnx_proto) - # ACL if (onnxruntime_USE_ACL OR onnxruntime_USE_ACL_1902 OR onnxruntime_USE_ACL_1905 OR onnxruntime_USE_ACL_1908 OR onnxruntime_USE_ACL_2002) set(onnxruntime_USE_ACL ON) @@ -1565,104 +898,14 @@ if (onnxruntime_USE_TVM) list(APPEND onnxruntime_EXTERNAL_DEPENDENCIES tvm) endif() -# XNNPACK EP -if (onnxruntime_USE_XNNPACK) - if (onnxruntime_DISABLE_CONTRIB_OPS) - message(FATAL_ERROR "XNNPACK EP requires the internal NHWC contrib ops to be available " - "but onnxruntime_DISABLE_CONTRIB_OPS is ON") - endif() - - include(xnnpack) -endif() # onnxruntime-extensions if (onnxruntime_USE_EXTENSIONS) include(extensions) endif() -if (APPLE OR CMAKE_SYSTEM_NAME STREQUAL "Android") - #onnx/onnx/proto_utils.h:34:16: error: 'SetTotalBytesLimit' is deprecated: Please use the single - #parameter version of SetTotalBytesLimit(). The second parameter is ignored. - # coded_stream.SetTotalBytesLimit((2048LL << 20) - 1, 512LL << 20); - #TODO: fix the warning in ONNX and re-enable this flag - string(APPEND CMAKE_CXX_FLAGS " -Wno-deprecated") - string(APPEND CMAKE_C_FLAGS " -Wno-deprecated") -endif() - -# ONNX -if (NOT onnxruntime_USE_FULL_PROTOBUF) - set(ONNX_USE_LITE_PROTO ON CACHE BOOL "" FORCE) -else() - set(ONNX_USE_LITE_PROTO OFF CACHE BOOL "" FORCE) -endif() - -if(Patch_FOUND) - set(ONNXRUNTIME_ONNX_PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/onnx/onnx.patch) -else() - set(ONNXRUNTIME_ONNX_PATCH_COMMAND "") -endif() - -FetchContent_Declare( - onnx - URL ${DEP_URL_onnx} - URL_HASH SHA1=${DEP_SHA1_onnx} - PATCH_COMMAND ${ONNXRUNTIME_ONNX_PATCH_COMMAND} -) - -if (NOT onnxruntime_MINIMAL_BUILD) - onnxruntime_fetchcontent_makeavailable(onnx) -else() - include(onnx_minimal) -endif() - -target_compile_definitions(onnx PUBLIC $ PRIVATE "__ONNX_DISABLE_STATIC_REGISTRATION") -if (NOT onnxruntime_USE_FULL_PROTOBUF) - target_compile_definitions(onnx PUBLIC "__ONNX_NO_DOC_STRINGS") -endif() -set_target_properties(onnx PROPERTIES FOLDER "External/ONNX") -set_target_properties(onnx_proto PROPERTIES FOLDER "External/ONNX") - - -# fix a warning in onnx code we can't do anything about -if (MSVC) - string(APPEND CMAKE_CXX_FLAGS " -DEIGEN_HAS_C99_MATH") # required to be set explicitly to enable Eigen-Unsupported SpecialFunctions -endif() - #Dependencies end. In the next we'll enable "treat warning as error" -if (onnxruntime_RUN_ONNX_TESTS) - add_definitions(-DORT_RUN_EXTERNAL_ONNX_TESTS) -endif() - -# Flatbuffers -if (onnxruntime_PREFER_SYSTEM_LIB) - find_package(Flatbuffers) -endif() -if (Flatbuffers_FOUND) - message("Use flatbuffers from preinstalled system lib") - add_library(flatbuffers ALIAS flatbuffers::flatbuffers) -else() - message("Use flatbuffers from submodule") - # We do not need to build flatc for iOS or Android Cross Compile - if (CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android" OR onnxruntime_BUILD_WEBASSEMBLY) - set(FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "FLATBUFFERS_BUILD_FLATC" FORCE) - endif() - set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "FLATBUFFERS_BUILD_TESTS" FORCE) - set(FLATBUFFERS_INSTALL OFF CACHE BOOL "FLATBUFFERS_INSTALL" FORCE) - set(FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "FLATBUFFERS_BUILD_FLATHASH" FORCE) - set(FLATBUFFERS_BUILD_FLATLIB ON CACHE BOOL "FLATBUFFERS_BUILD_FLATLIB" FORCE) - set_msvc_c_cpp_compiler_warning_level(4) - add_subdirectory(external/flatbuffers EXCLUDE_FROM_ALL) - set_msvc_c_cpp_compiler_warning_level(3) -endif() -list(APPEND onnxruntime_EXTERNAL_DEPENDENCIES flatbuffers) -list(APPEND onnxruntime_EXTERNAL_LIBRARIES flatbuffers) - -if (CMAKE_SYSTEM_NAME STREQUAL "Android" AND Onnxruntime_GCOV_COVERAGE) - string(APPEND CMAKE_CXX_FLAGS " -g -O0 --coverage ") - string(APPEND CMAKE_C_FLAGS " -g -O0 --coverage ") -endif() - #Adjust warning flags if (onnxruntime_USE_CUDA) set_msvc_c_cpp_compiler_warning_level(3) @@ -2075,10 +1318,6 @@ if (onnxruntime_ENABLE_TRAINING) list(APPEND onnxruntime_EXTERNAL_LIBRARIES tensorboard) endif() -if (onnxruntime_ENABLE_TRAINING) - set(onnxruntime_ENABLE_ATEN ON) -endif() - # Default version parts for Microsoft.AI.MachineLearning.dll, onnxruntime.dll, onnxruntime_providers_openvino.dll and onnxruntime_providers_shared.dll in non-ADO pipeline local builds set(VERSION_MAJOR_PART 0 CACHE STRING "First part of numeric file/product version.") set(VERSION_MINOR_PART 0 CACHE STRING "Second part of numeric file/product version.") @@ -2086,7 +1325,108 @@ set(VERSION_BUILD_PART 0 CACHE STRING "Third part of numeric file/product set(VERSION_PRIVATE_PART 0 CACHE STRING "Fourth part of numeric file/product version.") set(VERSION_STRING "Internal Build" CACHE STRING "String representation of file/product version.") -set(ONNXRUNTIME_TARGETS onnxruntime_common onnxruntime_graph onnxruntime_framework onnxruntime_util onnxruntime_providers onnxruntime_optimizer onnxruntime_session onnxruntime_mlas onnxruntime_flatbuffers) +if (WIN32) + list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${SYS_PATH_LIB}) + list(APPEND onnxruntime_EXTERNAL_LIBRARIES debug Dbghelp) +else() + list(APPEND onnxruntime_EXTERNAL_LIBRARIES nsync_cpp) + list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${CMAKE_DL_LIBS} Threads::Threads) +endif() + +if (CMAKE_SYSTEM_NAME STREQUAL "Android") + list(APPEND onnxruntime_EXTERNAL_LIBRARIES log) +endif() + +# check if we need to link against librt on Linux +include(CheckLibraryExists) +include(CheckFunctionExists) +if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME) + + if (NOT HAVE_CLOCK_GETTIME) + set(CMAKE_EXTRA_INCLUDE_FILES time.h) + check_function_exists(clock_gettime HAVE_CLOCK_GETTIME) + set(CMAKE_EXTRA_INCLUDE_FILES) + else() + list(APPEND onnxruntime_EXTERNAL_LIBRARIES rt) + endif() +endif() + + +#Now the 'onnxruntime_EXTERNAL_LIBRARIES' variable should be sealed. It will be used in onnxruntime.cmake which will be included in the next. +#The order of the following targets matters. Right depends on left. If target A appears before target B. Then A.cmake can not use variables defined in B.cmake. +set(ONNXRUNTIME_TARGETS onnxruntime_flatbuffers onnxruntime_common onnxruntime_mlas onnxruntime_graph onnxruntime_framework onnxruntime_util onnxruntime_providers onnxruntime_optimizer onnxruntime_session) + +if (onnxruntime_USE_WINML) + # WINML uses and depends on the shared lib. Note: You can build WINML without DML and you will get a + # CPU only WINML + if (NOT onnxruntime_BUILD_SHARED_LIB) + message( + FATAL_ERROR + "Option onnxruntime_USE_WINML can only be used when onnxruntime_BUILD_SHARED_LIB is also enabled") + endif() + list(APPEND ONNXRUNTIME_TARGETS winml) +endif() # if (onnxruntime_USE_WINML) + +if (onnxruntime_BUILD_SHARED_LIB OR onnxruntime_BUILD_APPLE_FRAMEWORK) + if (onnxruntime_BUILD_APPLE_FRAMEWORK AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS") + message(FATAL_ERROR "onnxruntime_BUILD_APPLE_FRAMEWORK can only be enabled for macOS or iOS.") + endif() + list(APPEND ONNXRUNTIME_TARGETS onnxruntime) +endif() + +if (onnxruntime_BUILD_JAVA) + message(STATUS "Java Build is enabled") + list(APPEND ONNXRUNTIME_TARGETS onnxruntime_java) +endif() + +if (onnxruntime_BUILD_NODEJS) + message(STATUS "Node.js Build is enabled") + list(APPEND ONNXRUNTIME_TARGETS onnxruntime_nodejs) +endif() + +if (onnxruntime_ENABLE_PYTHON) + message(STATUS "Python Build is enabled") + list(APPEND ONNXRUNTIME_TARGETS onnxruntime_python) +endif() + +if (onnxruntime_BUILD_OBJC) + message(STATUS "Objective-C Build is enabled") + list(APPEND ONNXRUNTIME_TARGETS onnxruntime_objectivec) +endif() + +if (onnxruntime_BUILD_UNIT_TESTS) + list(APPEND ONNXRUNTIME_TARGETS onnxruntime_unittests) +endif() + +if (onnxruntime_BUILD_WINML_TESTS) + list(APPEND ONNXRUNTIME_TARGETS winml_unittests) +endif() + +# onnxruntime_training depends on onnxruntime_unittests since onnxruntime_training.cmake uses a variable `TEST_SRC_DIR` +# that is defined in onnxruntime_unittests.cmake +if (onnxruntime_ENABLE_TRAINING) + list(APPEND ONNXRUNTIME_TARGETS onnxruntime_training) + if (onnxruntime_ENABLE_TRAINING_E2E_TESTS) + list(APPEND ONNXRUNTIME_TARGETS onnxruntime_training_e2e_tests) + endif() +endif() + +if (onnxruntime_BUILD_CSHARP) + message(STATUS "CSharp Build is enabled") +# set_property(GLOBAL PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "netstandard2.0") + list(APPEND ONNXRUNTIME_TARGETS onnxruntime_csharp) +endif() + +if (onnxruntime_BUILD_WEBASSEMBLY) + message(STATUS "WebAssembly Build is enabled") + list(APPEND ONNXRUNTIME_TARGETS onnxruntime_webassembly) +endif() + +if(onnxruntime_BUILD_KERNEL_EXPLORER) + message(STATUS "Kernel Explorer Build is enabled") + list(APPEND ONNXRUNTIME_TARGETS onnxruntime_kernel_explorer) +endif() if (onnxruntime_ENABLE_EAGER_MODE) if (NOT onnxruntime_ENABLE_TRAINING OR NOT onnxruntime_ENABLE_PYTHON) @@ -2113,30 +1453,8 @@ if (onnxruntime_ENABLE_LAZY_TENSOR) #list(APPEND ONNXRUNTIME_TARGETS onnxruntime_lazy_tensor) endif() -foreach(target_name ${ONNXRUNTIME_TARGETS}) - include(${target_name}.cmake) -endforeach() - -if (CMAKE_SYSTEM_NAME STREQUAL "Android") - list(APPEND onnxruntime_EXTERNAL_LIBRARIES log) -endif() - -if (WIN32) - list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${SYS_PATH_LIB}) - list(APPEND onnxruntime_EXTERNAL_LIBRARIES debug Dbghelp) -else() - list(APPEND onnxruntime_EXTERNAL_LIBRARIES nsync_cpp) - list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${CMAKE_DL_LIBS} Threads::Threads) -endif() - # When GDK_PLATFORM is set then WINAPI_FAMILY is defined in gdk_toolchain.cmake (along with other relevant flags/definitions). if (WIN32 AND NOT GDK_PLATFORM) - add_compile_definitions(WINAPI_FAMILY=100) # Desktop app - if (onnxruntime_USE_WINML) - add_compile_definitions(WINVER=0x0602 _WIN32_WINNT=0x0602 NTDDI_VERSION=0x06020000) # Support Windows 8 and newer - else() - add_compile_definitions(WINVER=0x0601 _WIN32_WINNT=0x0601 NTDDI_VERSION=0x06010000) # Support Windows 7 and newer - endif() if (NOT CMAKE_CXX_STANDARD_LIBRARIES MATCHES kernel32.lib) # On onecore, link to the onecore build of the MSVC runtime get_filename_component(msvc_path "${CMAKE_C_COMPILER}/../../../.." ABSOLUTE) @@ -2147,75 +1465,9 @@ if (WIN32 AND NOT GDK_PLATFORM) endif() endif() -include(wil.cmake) - -if (onnxruntime_USE_WINML) - # WINML uses and depends on the shared lib. Note: You can build WINML without DML and you will get a - # CPU only WINML - if (NOT onnxruntime_BUILD_SHARED_LIB) - message( - FATAL_ERROR - "Option onnxruntime_USE_WINML can only be used when onnxruntime_BUILD_SHARED_LIB is also enabled") - endif() - include(winml.cmake) -endif() # if (onnxruntime_USE_WINML) - - -#The following files may use the 'onnxruntime_libs' and 'onnxruntime_EXTERNAL_LIBRARIES' vars - -if (onnxruntime_BUILD_SHARED_LIB OR onnxruntime_BUILD_APPLE_FRAMEWORK) - if (onnxruntime_BUILD_APPLE_FRAMEWORK AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS") - message(FATAL_ERROR "onnxruntime_BUILD_APPLE_FRAMEWORK can only be enabled for macOS or iOS.") - endif() - include(onnxruntime.cmake) -endif() - -if (onnxruntime_BUILD_JAVA) - message(STATUS "Java Build is enabled") - include(onnxruntime_java.cmake) -endif() - -if (onnxruntime_BUILD_NODEJS) - message(STATUS "Node.js Build is enabled") - include(onnxruntime_nodejs.cmake) -endif() - -if (onnxruntime_ENABLE_PYTHON) - include(onnxruntime_python.cmake) -endif() - -if (onnxruntime_BUILD_OBJC) - message(STATUS "Objective-C Build is enabled") - include(onnxruntime_objectivec.cmake) -endif() - -if (onnxruntime_BUILD_UNIT_TESTS) - include(onnxruntime_unittests.cmake) -endif() - -if (onnxruntime_ENABLE_TRAINING) - include(onnxruntime_training.cmake) - if (onnxruntime_ENABLE_TRAINING_E2E_TESTS) - include(onnxruntime_training_e2e_tests.cmake) - endif() -endif() - -if (onnxruntime_BUILD_CSHARP) - message(STATUS "CSharp Build is enabled") -# set_property(GLOBAL PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "netstandard2.0") - include(onnxruntime_csharp.cmake) -endif() - -if (onnxruntime_BUILD_WEBASSEMBLY) - message(STATUS "WebAssembly Build is enabled") - include(onnxruntime_webassembly.cmake) -endif() - -if(onnxruntime_BUILD_KERNEL_EXPLORER) - message(STATUS "Kernel Explorer Build is enabled") - include(onnxruntime_kernel_explorer.cmake) -endif() - +foreach(target_name ${ONNXRUNTIME_TARGETS}) + include(${target_name}.cmake) +endforeach() if (UNIX) option(BUILD_PKGCONFIG_FILES "Build and install pkg-config files" ON) else() diff --git a/cmake/adjust_global_compile_flags.cmake b/cmake/adjust_global_compile_flags.cmake new file mode 100644 index 0000000000..80243020f1 --- /dev/null +++ b/cmake/adjust_global_compile_flags.cmake @@ -0,0 +1,371 @@ +# work around Android NDK bug which doesn't include -O flag for Release configuration +# https://github.com/android/ndk/issues/1740 +# TODO: remove this when the NDK version(s) we support get fixed +if (CMAKE_SYSTEM_NAME STREQUAL "Android") + # NB: attempting to match the effects of this fix: https://android-review.googlesource.com/c/platform/ndk/+/2168845 + string(APPEND CMAKE_C_FLAGS_RELEASE " -O3") + string(APPEND CMAKE_CXX_FLAGS_RELEASE " -O3") + string(APPEND CMAKE_ASM_FLAGS_RELEASE " -O3") +endif() + +# Enable space optimization for gcc/clang +# Cannot use "-ffunction-sections -fdata-sections" if we enable bitcode (iOS) +if (NOT MSVC AND NOT onnxruntime_ENABLE_BITCODE) + string(APPEND CMAKE_CXX_FLAGS " -ffunction-sections -fdata-sections") + string(APPEND CMAKE_C_FLAGS " -ffunction-sections -fdata-sections") +endif() + +if (onnxruntime_ENABLE_EAGER_MODE) + string(APPEND CMAKE_CXX_FLAGS " -D_GLIBCXX_USE_CXX11_ABI=${_GLIBCXX_USE_CXX11_ABI}") +endif() + +if (onnxruntime_BUILD_WEBASSEMBLY) + # Enable LTO for release single-thread build + if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + # NOTES: + # (1) LTO does not work for WebAssembly multi-thread. (segment fault in worker) + # (2) "-flto=thin" does not work correctly for wasm-ld. + # we don't set onnxruntime_ENABLE_LTO because it appends flag "-flto=thin" + # instead, we manually set CMAKE_CXX_FLAGS "-flto" + string(APPEND CMAKE_C_FLAGS " -flto") + string(APPEND CMAKE_CXX_FLAGS " -flto") + endif() + + if (onnxruntime_ENABLE_WEBASSEMBLY_DEBUG_INFO) + # "-g3" generates DWARF format debug info. + # NOTE: With debug info enabled, web assembly artifacts will be very huge (>1GB). So we offer an option to build without debug info. + set(CMAKE_CXX_FLAGS_DEBUG "-g3") + else() + set(CMAKE_CXX_FLAGS_DEBUG "-g2") + endif() + + if (onnxruntime_ENABLE_WEBASSEMBLY_SIMD) + string(APPEND CMAKE_C_FLAGS " -msimd128") + string(APPEND CMAKE_CXX_FLAGS " -msimd128") + endif() + + if (onnxruntime_ENABLE_WEBASSEMBLY_EXCEPTION_CATCHING) + string(APPEND CMAKE_C_FLAGS " -s DISABLE_EXCEPTION_CATCHING=0") + string(APPEND CMAKE_CXX_FLAGS " -s DISABLE_EXCEPTION_CATCHING=0") + endif() + + # Build WebAssembly with multi-threads support. + if (onnxruntime_ENABLE_WEBASSEMBLY_THREADS) + string(APPEND CMAKE_C_FLAGS " -pthread") + string(APPEND CMAKE_CXX_FLAGS " -pthread") + string(APPEND CMAKE_C_FLAGS " -s USE_PTHREADS=1 -Wno-pthreads-mem-growth") + string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS=1 -Wno-pthreads-mem-growth") + endif() +endif() + +if (onnxruntime_EXTERNAL_TRANSFORMER_SRC_PATH) + add_definitions(-DORT_TRAINING_EXTERNAL_GRAPH_TRANSFORMERS=1) +endif() + +# ORT build with as much excluded as possible. Supports ORT flatbuffers models only. +if (onnxruntime_MINIMAL_BUILD) + add_compile_definitions(ORT_MINIMAL_BUILD) + + if (onnxruntime_EXTENDED_MINIMAL_BUILD) + # enable EPs that compile kernels at runtime + add_compile_definitions(ORT_EXTENDED_MINIMAL_BUILD) + endif() + + if (onnxruntime_MINIMAL_BUILD_CUSTOM_OPS) + add_compile_definitions(ORT_MINIMAL_BUILD_CUSTOM_OPS) + endif() + + if (MSVC) + # turn on LTO (which adds some compiler flags and turns on LTCG) unless it's a Debug build to minimize binary size + if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + set(onnxruntime_ENABLE_LTO ON) + endif() + + # undocumented internal flag to allow analysis of a minimal build binary size + if (ADD_DEBUG_INFO_TO_MINIMAL_BUILD) + string(APPEND CMAKE_CXX_FLAGS " /Zi") + string(APPEND CMAKE_C_FLAGS " /Zi") + string(APPEND CMAKE_SHARED_LINKER_FLAGS " /debug") + endif() + else() + if (CMAKE_HOST_SYSTEM MATCHES "Darwin") + add_link_options(-Wl, -dead_strip) + else() + add_link_options(-Wl,--gc-sections) + endif() + + if (ADD_DEBUG_INFO_TO_MINIMAL_BUILD) + string(APPEND CMAKE_CXX_FLAGS " -g") + string(APPEND CMAKE_C_FLAGS " -g") + endif() + endif() +endif() + +if (onnxruntime_ENABLE_LTO) + include(CheckIPOSupported) + check_ipo_supported(RESULT ipo_enabled OUTPUT ipo_output) + if (NOT ipo_enabled) + message(WARNING "IPO is not supported by this compiler") + set(onnxruntime_ENABLE_LTO OFF) + else() + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) + endif() +endif() + +if (onnxruntime_REDUCED_OPS_BUILD) + add_compile_definitions(REDUCED_OPS_BUILD) +endif() + +if (onnxruntime_DISABLE_EXTERNAL_INITIALIZERS) + add_definitions(-DDISABLE_EXTERNAL_INITIALIZERS=1) +endif() + +if (onnxruntime_DISABLE_RTTI) + add_compile_definitions(ORT_NO_RTTI) + if (MSVC) + # Disable RTTI and turn usage of dynamic_cast and typeid into errors + add_compile_options("$<$:/GR->" "$<$:/we4541>") + else() + add_compile_options("$<$:-fno-rtti>") + endif() +else() + #MSVC RTTI flag /GR is not added to CMAKE_CXX_FLAGS by default. But, anyway VC++2019 treats "/GR" default on. + #So we don't need the following three lines. But it's better to make it more explicit. + if (MSVC) + add_compile_options("$<$:/GR>") + endif() +endif() + +# If this is only enabled in an onnxruntime_ORT_MODEL_FORMAT_ONLY build we don't need ONNX changes +# as we (currently) only pull in data_type_utils.cc/h which doesn't throw +if (onnxruntime_DISABLE_EXCEPTIONS) + if (NOT onnxruntime_MINIMAL_BUILD) + message(FATAL_ERROR "onnxruntime_MINIMAL_BUILD required for onnxruntime_DISABLE_EXCEPTIONS") + endif() + + if (onnxruntime_ENABLE_PYTHON) + # pybind11 highly depends on C++ exceptions. + message(FATAL_ERROR "onnxruntime_ENABLE_PYTHON must be disabled for onnxruntime_DISABLE_EXCEPTIONS") + endif() + add_compile_definitions("ORT_NO_EXCEPTIONS") + add_compile_definitions("MLAS_NO_EXCEPTION") + add_compile_definitions("ONNX_NO_EXCEPTIONS") + add_compile_definitions("JSON_NOEXCEPTION") # https://json.nlohmann.me/api/macros/json_noexception/ + + if (MSVC) + string(REGEX REPLACE "/EHsc" "/EHs-c-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + # Eigen throw_std_bad_alloc calls 'new' instead of throwing which results in a nodiscard warning. + # It also has unreachable code as there's no good way to avoid EIGEN_EXCEPTIONS being set in macros.h + # TODO: see if we can limit the code this is disabled for. + string(APPEND CMAKE_CXX_FLAGS " /wd4834 /wd4702") + add_compile_definitions("_HAS_EXCEPTIONS=0") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables") + endif() +endif() + + +# Guarantee that the Eigen code that you are #including is licensed +# under the MPL2 and possibly more permissive licenses (like BSD). +add_definitions(-DEIGEN_MPL2_ONLY) +if (MSVC) + add_definitions(-DEIGEN_HAS_CONSTEXPR -DEIGEN_HAS_VARIADIC_TEMPLATES -DEIGEN_HAS_CXX11_MATH -DEIGEN_HAS_CXX11_ATOMIC + -DEIGEN_STRONG_INLINE=inline) +endif() + +if ( onnxruntime_DONT_VECTORIZE ) + add_definitions(-DEIGEN_DONT_VECTORIZE=1) +endif() + +if (onnxruntime_CROSS_COMPILING) + set(CMAKE_CROSSCOMPILING ON) + check_cxx_compiler_flag(-Wno-error HAS_NOERROR) + if (HAS_NOERROR) + string(APPEND CMAKE_CXX_FLAGS " -Wno-error=attributes") + string(APPEND CMAKE_C_FLAGS " -Wno-error=attributes") + endif() +endif() + +if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) + check_cxx_compiler_flag(-Wno-error HAS_NOERROR) + if (HAS_NOERROR) + string(APPEND CMAKE_CXX_FLAGS " -Wno-error=attributes") + string(APPEND CMAKE_C_FLAGS " -Wno-error=attributes") + endif() +endif() + +# Mark symbols to be invisible, for macOS/iOS target only +# Due to many dependencies have different symbol visibility settings, set global compile flags here. +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS") + foreach(flags CMAKE_CXX_FLAGS CMAKE_OBJC_FLAGS CMAKE_OBJCXX_FLAGS) + string(APPEND ${flags} " -fvisibility=hidden -fvisibility-inlines-hidden") + endforeach() +endif() + + +macro(check_nvcc_compiler_flag _FLAG _RESULT) + execute_process(COMMAND ${onnxruntime_CUDA_HOME}/bin/nvcc "${_FLAG}" RESULT_VARIABLE NVCC_OUT ERROR_VARIABLE NVCC_ERROR) + message("NVCC_ERROR = ${NVCC_ERROR}") + message("NVCC_OUT = ${NVCC_OUT}") + if ("${NVCC_OUT}" MATCHES "0") + set(${_RESULT} 1) + else() + set(${_RESULT} 0) + endif() +endmacro() + +#Set global compile flags for all the source code(including third_party code like protobuf) +#This section must be before any add_subdirectory, otherwise build may fail because /MD,/MT mismatch +if (MSVC) + enable_language(ASM_MASM) + if (CMAKE_GENERATOR_PLATFORM) + # Multi-platform generator + set(onnxruntime_target_platform ${CMAKE_GENERATOR_PLATFORM}) + else() + set(onnxruntime_target_platform ${CMAKE_SYSTEM_PROCESSOR}) + endif() + if (onnxruntime_target_platform STREQUAL "ARM64") + set(onnxruntime_target_platform "ARM64") + elseif (onnxruntime_target_platform STREQUAL "ARM64EC") + set(onnxruntime_target_platform "ARM64EC") + elseif (onnxruntime_target_platform STREQUAL "ARM" OR CMAKE_GENERATOR MATCHES "ARM") + set(onnxruntime_target_platform "ARM") + elseif (onnxruntime_target_platform STREQUAL "x64" OR onnxruntime_target_platform STREQUAL "x86_64" OR onnxruntime_target_platform STREQUAL "AMD64" OR CMAKE_GENERATOR MATCHES "Win64") + set(onnxruntime_target_platform "x64") + elseif (onnxruntime_target_platform STREQUAL "Win32" OR onnxruntime_target_platform STREQUAL "x86" OR onnxruntime_target_platform STREQUAL "i386" OR onnxruntime_target_platform STREQUAL "i686") + set(onnxruntime_target_platform "x86") + if (NOT onnxruntime_BUILD_WEBASSEMBLY) + message("Enabling SAFESEH for x86 build") + set(CMAKE_ASM_MASM_FLAGS "${CMAKE_ASM_MASM_FLAGS} /safeseh") + endif() + endif() + + + #Always enable exception handling, even for Windows ARM + if (NOT onnxruntime_DISABLE_EXCEPTIONS) + string(APPEND CMAKE_CXX_FLAGS " /EHsc") + string(APPEND CMAKE_C_FLAGS " /EHsc") + + string(APPEND CMAKE_CXX_FLAGS " /wd26812") + string(APPEND CMAKE_C_FLAGS " /wd26812") + # warning C4805: '|': unsafe mix of type 'uintptr_t' and type 'bool' in operation (from c10/core/TensorImpl.h) + if (onnxruntime_ENABLE_EAGER_MODE) + string(APPEND CMAKE_CXX_FLAGS " /wd4805") + endif() + endif() + # We do not treat 3rd-party libraries' warnings as errors. In order to do that, we need to add their header files locations to /external:I. + # However, if a 3rd-party library was installed to a non-standard location and cmake find it and use it from there, you may see build errors + # like: "error C2220: the following warning is treated as an error" + string(APPEND CMAKE_CXX_FLAGS " /experimental:external /external:W0 /external:templates- /external:I ${CMAKE_CURRENT_SOURCE_DIR} /external:I ${CMAKE_CURRENT_BINARY_DIR}") + if (onnxruntime_USE_AVX) + string(APPEND CMAKE_CXX_FLAGS " /arch:AVX") + string(APPEND CMAKE_C_FLAGS " /arch:AVX") + elseif (onnxruntime_USE_AVX2) + string(APPEND CMAKE_CXX_FLAGS " /arch:AVX2") + string(APPEND CMAKE_C_FLAGS " /arch:AVX2") + elseif (onnxruntime_USE_AVX512) + string(APPEND CMAKE_CXX_FLAGS " /arch:AVX512") + string(APPEND CMAKE_C_FLAGS " /arch:AVX512") + endif() + + if (NOT GDK_PLATFORM) + add_compile_definitions(WINAPI_FAMILY=100) # Desktop app + if (onnxruntime_USE_WINML OR NOT CMAKE_CXX_STANDARD_LIBRARIES MATCHES kernel32.lib) + message("Building ONNX Runtime for Windows 8 and newer") + add_compile_definitions(WINVER=0x0602 _WIN32_WINNT=0x0602 NTDDI_VERSION=0x06020000) # Support Windows 8 and newer + else() + message("Building ONNX Runtime for Windows 7 and newer") + # For people who build ONNX Runtime from source, the result binary may still support Windows 7 + # Windows 7 doesn't have OneCore. So if CMAKE_CXX_STANDARD_LIBRARIES is for OneCore, the build won't come here + add_compile_definitions(WINVER=0x0601 _WIN32_WINNT=0x0601 NTDDI_VERSION=0x06010000) # Support Windows 7 and newer + endif() + endif() + if (onnxruntime_ENABLE_LTO AND NOT onnxruntime_USE_CUDA) + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Gw /GL") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Gw /GL") + set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /Gw /GL") + endif() + + # The WinML build tool chain builds ARM/ARM64, and the internal tool chain does not have folders for spectre mitigation libs. + # WinML performs spectre mitigation differently. + if (NOT DEFINED onnxruntime_DISABLE_QSPECTRE_CHECK) + check_cxx_compiler_flag(-Qspectre HAS_QSPECTRE) + if (HAS_QSPECTRE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Qspectre") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qspectre") + endif() + endif() + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DYNAMICBASE") + check_cxx_compiler_flag(-guard:cf HAS_GUARD_CF) + if (HAS_GUARD_CF) + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /guard:cf") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /guard:cf") + set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /guard:cf") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /guard:cf") + set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /guard:cf") + set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /guard:cf") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf") + endif() +else() + if (NOT APPLE) + set(onnxruntime_target_platform ${CMAKE_SYSTEM_PROCESSOR}) + endif() + if (onnxruntime_BUILD_FOR_NATIVE_MACHINE) + string(APPEND CMAKE_CXX_FLAGS " -march=native -mtune=native") + string(APPEND CMAKE_C_FLAGS " -march=native -mtune=native") + elseif (onnxruntime_USE_AVX) + string(APPEND CMAKE_CXX_FLAGS " -mavx") + string(APPEND CMAKE_C_FLAGS " -mavx") + elseif (onnxruntime_USE_AVX2) + string(APPEND CMAKE_CXX_FLAGS " -mavx2") + string(APPEND CMAKE_C_FLAGS " -mavx2") + elseif (onnxruntime_USE_AVX512) + string(APPEND CMAKE_CXX_FLAGS " -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl") + string(APPEND CMAKE_C_FLAGS " -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl") + endif() + if (CMAKE_SYSTEM_NAME STREQUAL "Android" AND Onnxruntime_GCOV_COVERAGE) + string(APPEND CMAKE_CXX_FLAGS " -g -O0 --coverage ") + string(APPEND CMAKE_C_FLAGS " -g -O0 --coverage ") + endif() + # Check support for AVX and f16c. + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag("-mf16c" COMPILER_SUPPORT_MF16C) + if (NOT COMPILER_SUPPORT_MF16C) + message("F16C instruction set is not supported.") + endif() + + check_cxx_compiler_flag("-mfma" COMPILER_SUPPORT_FMA) + if (NOT COMPILER_SUPPORT_FMA) + message("FMA instruction set is not supported.") + endif() + + check_cxx_compiler_flag("-mavx" COMPILER_SUPPORT_AVX) + if (NOT COMPILER_SUPPORT_AVX) + message("AVX instruction set is not supported.") + endif() + + if (CMAKE_SYSTEM_NAME STREQUAL "Android" AND onnxruntime_ENABLE_TRAINING_ON_DEVICE) + message("F16C, FMA and AVX flags are not supported on Android for on-device training.") + endif() + + if (NOT (COMPILER_SUPPORT_MF16C AND COMPILER_SUPPORT_FMA AND COMPILER_SUPPORT_AVX) OR + (CMAKE_SYSTEM_NAME STREQUAL "Android" AND onnxruntime_ENABLE_TRAINING_ON_DEVICE)) + message("One or more AVX/F16C instruction flags are not supported. ") + set(onnxruntime_ENABLE_CPU_FP16_OPS FALSE) + endif() + +endif() + +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + #For Mac compliance + message("Adding flags for Mac builds") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong") +endif() + +if (WIN32) + # parallel build + # These compiler opitions cannot be forwarded to NVCC, so cannot use add_compiler_options + string(APPEND CMAKE_CXX_FLAGS " /MP") + # required to be set explicitly to enable Eigen-Unsupported SpecialFunctions + string(APPEND CMAKE_CXX_FLAGS " -DEIGEN_HAS_C99_MATH") +endif() diff --git a/cmake/deps.txt b/cmake/deps.txt index 7f900635f1..30b5d2b7e5 100644 --- a/cmake/deps.txt +++ b/cmake/deps.txt @@ -8,6 +8,28 @@ #since the file contains a version string: "lts_20211102". However, the file is for debugging purposes only and would #not affect built binaries. abseil_cpp;https://github.com/abseil/abseil-cpp/archive/refs/tags/20211102.0.zip;ce61532df974d00025b1220408ce1c900d81baf2 +cxxopts;https://github.com/jarro2783/cxxopts/archive/3c73d91c0b04e2b59462f0a741be8c07024c1bc0.zip;6c6ca7f8480b26c8d00476e0e24b7184717fe4f0 +date;https://github.com/HowardHinnant/date/archive/refs/tags/v2.4.1.zip;ea99f021262b1d804a872735c658860a6a13cc98 +dlpack;https://github.com/dmlc/dlpack/archive/refs/tags/v0.6.zip;4d565dd2e5b31321e5549591d78aa7f377173445 +flatbuffers;https://github.com/google/flatbuffers/archive/refs/tags/v1.12.0.zip;ba0a75fd12dbef8f6557a74e611b7a3d0c5fe7bf +fp16;https://github.com/Maratyszcza/FP16/archive/0a92994d729ff76a58f692d3028ca1b64b145d91.zip;b985f6985a05a1c03ff1bb71190f66d8f98a1494 +fxdiv;https://github.com/Maratyszcza/FXdiv/archive/63058eff77e11aa15bf531df5dd34395ec3017c8.zip;a5658f4036402dbca7cebee32be57fb8149811e1 +google_benchmark;https://github.com/google/benchmark/archive/refs/tags/v1.7.0.zip;e97c368b176e8614e3f1bf13dd9abcf6a7ad9908 +google_nsync;https://github.com/google/nsync/archive/refs/tags/1.23.0.zip;f3233450cf7156fc0bedd1b0e884eddec264897c +googletest;https://github.com/google/googletest/archive/519beb0e52c842729b4b53731d27c0e0c32ab4a2.zip;4b3c37972e4c1bef1185d46f702082f8772ee73f +googlexnnpack;https://github.com/google/XNNPACK/archive/003c580e696a774afdc984996ee909b7c8d8128c.zip;9f192e3f15e1e37ae9c78d53eeea47e45c5eb31c +json;https://github.com/nlohmann/json/archive/refs/tags/v3.10.5.zip;f257f8dc27c5b8c085dc887b40cddd18ae1f725c microsoft_gsl;https://github.com/microsoft/GSL/archive/refs/tags/v4.0.0.zip;cf368104cd22a87b4dd0c80228919bb2df3e2a14 +microsoft_wil;https://github.com/microsoft/wil/archive/5f4caba4e7a9017816e47becdd918fcc872039ba.zip;fd119887d0d17c37adf1fc227b054befa28158ad +mimalloc;https://github.com/microsoft/mimalloc/archive/refs/tags/v2.0.3.zip;e4f37b93b2da78a5816c2495603a4188d316214b +mp11;https://github.com/boostorg/mp11/archive/refs/tags/boost-1.79.0.zip;c8f04e378535ededbe5af52c8f969d2dedbe73d5 onnx;https://github.com/onnx/onnx/archive/5a5f8a5935762397aa68429b5493084ff970f774.zip;edc8e1338c02f3ab222f3d803a24e17608c13895 -protobuf;https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.18.3.zip;b95bf7e9de9c2249b6c1f2ca556ace49999e90bd \ No newline at end of file +onnx_tensorrt;https://github.com/onnx/onnx-tensorrt/archive/87c7a70688fd98fb355b8976f41425b40e4fe52f.zip;b97d112d9d6efa180c9b94e05268f2ff3294a534 +protobuf;https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.18.3.zip;b95bf7e9de9c2249b6c1f2ca556ace49999e90bd +psimd;https://github.com/Maratyszcza/psimd/archive/072586a71b55b7f8c584153d223e95687148a900.zip;1f5454b01f06f9656b77e4a5e2e31d7422487013 +pthreadpool;https://github.com/Maratyszcza/pthreadpool/archive/1787867f6183f056420e532eec640cba25efafea.zip;e43e80781560c5ab404a4da20f34d846f5f5d101 +pybind11;https://github.com/pybind/pybind11/archive/refs/tags/v2.6.2.zip;950b3b319384a1a36b252cc821953e5f9be14840 +pytorch_cpuinfo;https://github.com/pytorch/cpuinfo/archive/5916273f79a21551890fd3d56fc5375a78d1598d.zip;2be4d2ae321fada97cb39eaf4eeba5f8c85597cf +re2;https://github.com/google/re2/archive/refs/tags/2022-06-01.zip;aa77313b76e91b531ee7f3e45f004c6a502a5374 +safeint;https://github.com/dcleblanc/SafeInt/archive/ff15c6ada150a5018c5ef2172401cb4529eac9c0.zip;913a4046e5274d329af2806cb53194f617d8c0ab +tensorboard;https://github.com/tensorflow/tensorboard/archive/373eb09e4c5d2b3cc2493f0949dc4be6b6a45e81.zip;67b833913605a4f3f499894ab11528a702c2b381 \ No newline at end of file diff --git a/cmake/external/FP16 b/cmake/external/FP16 deleted file mode 160000 index 0a92994d72..0000000000 --- a/cmake/external/FP16 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0a92994d729ff76a58f692d3028ca1b64b145d91 diff --git a/cmake/external/SafeInt/safeint b/cmake/external/SafeInt/safeint deleted file mode 160000 index ff15c6ada1..0000000000 --- a/cmake/external/SafeInt/safeint +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ff15c6ada150a5018c5ef2172401cb4529eac9c0 diff --git a/cmake/external/XNNPACK b/cmake/external/XNNPACK deleted file mode 160000 index 003c580e69..0000000000 --- a/cmake/external/XNNPACK +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 003c580e696a774afdc984996ee909b7c8d8128c diff --git a/cmake/external/abseil-cpp.cmake b/cmake/external/abseil-cpp.cmake index 6b3b709cfa..ebd5933db3 100644 --- a/cmake/external/abseil-cpp.cmake +++ b/cmake/external/abseil-cpp.cmake @@ -38,3 +38,9 @@ if (GDK_PLATFORM) # tell Abseil to pretend we're building an APP. target_compile_definitions(absl_symbolize PRIVATE WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP) endif() + +if(NOT onnxruntime_DISABLE_ABSEIL) + set(ABSEIL_LIBS absl::inlined_vector absl::flat_hash_set + absl::flat_hash_map absl::node_hash_set absl::node_hash_map absl::base absl::throw_delegate absl::raw_hash_set + absl::hash absl::city absl::low_level_hash absl::raw_logging_internal) +endif() \ No newline at end of file diff --git a/cmake/external/cxxopts b/cmake/external/cxxopts deleted file mode 160000 index 3c73d91c0b..0000000000 --- a/cmake/external/cxxopts +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3c73d91c0b04e2b59462f0a741be8c07024c1bc0 diff --git a/cmake/external/dlpack b/cmake/external/dlpack deleted file mode 160000 index 2775088798..0000000000 --- a/cmake/external/dlpack +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 277508879878e0a5b5b43599b1bea11f66eb3c6c diff --git a/cmake/external/eigen.cmake b/cmake/external/eigen.cmake index 264247a7c7..266dd534af 100644 --- a/cmake/external/eigen.cmake +++ b/cmake/external/eigen.cmake @@ -1,4 +1,3 @@ -include (ExternalProject) if (onnxruntime_USE_PREINSTALLED_EIGEN) add_library(eigen INTERFACE) @@ -6,7 +5,17 @@ if (onnxruntime_USE_PREINSTALLED_EIGEN) target_include_directories(eigen INTERFACE ${eigen_INCLUDE_DIRS}) else () if (onnxruntime_USE_ACL) - execute_process(COMMAND git apply --ignore-space-change --ignore-whitespace ${PROJECT_SOURCE_DIR}/patches/eigen/Fix_Eigen_Build_Break.patch WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) + FetchContent_Declare( + eigen + URL https://gitlab.com/libeigen/eigen/-/archive/d10b27fe37736d2944630ecd7557cefa95cf87c9/eigen-d10b27fe37736d2944630ecd7557cefa95cf87c9.zip + PATCH_COMMAND ${Patch_EXECUTABLE} --ignore-space-change --ignore-whitespace < ${PROJECT_SOURCE_DIR}/patches/eigen/Fix_Eigen_Build_Break.patch + ) + else() + FetchContent_Declare( + eigen + URL https://gitlab.com/libeigen/eigen/-/archive/d10b27fe37736d2944630ecd7557cefa95cf87c9/eigen-d10b27fe37736d2944630ecd7557cefa95cf87c9.zip + ) endif() - set(eigen_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/external/eigen") + FetchContent_Populate(eigen) + set(eigen_INCLUDE_DIRS "${eigen_SOURCE_DIR}") endif() diff --git a/cmake/external/extensions.cmake b/cmake/external/extensions.cmake index 7bd8aeafbb..5d7e3ad60c 100644 --- a/cmake/external/extensions.cmake +++ b/cmake/external/extensions.cmake @@ -27,5 +27,5 @@ endif() add_subdirectory(${onnxruntime_EXTENSIONS_PATH} ${CMAKE_BINARY_DIR}/_deps/extensions-subbuild EXCLUDE_FROM_ALL) # target library or executable are defined in CMakeLists.txt of onnxruntime-extensions -target_include_directories(ocos_operators PRIVATE ${RE2_INCLUDE_DIR} external/json/include) +target_include_directories(ocos_operators PRIVATE ${RE2_INCLUDE_DIR} ${json_SOURCE_DIR}/include) target_include_directories(ortcustomops PUBLIC ${onnxruntime_EXTENSIONS_PATH}/includes) diff --git a/cmake/find_snpe.cmake b/cmake/external/find_snpe.cmake similarity index 100% rename from cmake/find_snpe.cmake rename to cmake/external/find_snpe.cmake diff --git a/cmake/external/flatbuffers b/cmake/external/flatbuffers deleted file mode 160000 index 6df40a2471..0000000000 --- a/cmake/external/flatbuffers +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6df40a2471737b27271bdd9b900ab5f3aec746c7 diff --git a/cmake/external/googlebenchmark b/cmake/external/googlebenchmark deleted file mode 160000 index 7d0d9061d8..0000000000 --- a/cmake/external/googlebenchmark +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7d0d9061d83b663ce05d9de5da3d5865a3845b79 diff --git a/cmake/external/gsl.cmake b/cmake/external/gsl.cmake deleted file mode 100644 index f4f9ce770d..0000000000 --- a/cmake/external/gsl.cmake +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -include(FetchContent) - -if(onnxruntime_USE_CUDA) - FetchContent_Declare( - GSL - URL ${DEP_URL_microsoft_gsl} - URL_HASH SHA1=${DEP_SHA1_microsoft_gsl} - PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/gsl/1064.patch - ) -else() - FetchContent_Declare( - GSL - URL ${DEP_URL_microsoft_gsl} - URL_HASH SHA1=${DEP_SHA1_microsoft_gsl} - ) -endif() - - -onnxruntime_fetchcontent_makeavailable(GSL) - -set(GSL_TARGET "Microsoft.GSL::GSL") -set(GSL_INCLUDE_DIR "$") diff --git a/cmake/external/helper_functions.cmake b/cmake/external/helper_functions.cmake index a31e4b04f3..cbd06755c4 100644 --- a/cmake/external/helper_functions.cmake +++ b/cmake/external/helper_functions.cmake @@ -1,7 +1,13 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. -# This file was copied from cmake source with modifications +# This file was copied from cmake source with modifications: +# 1. Add the EXCLUDE_FROM_ALL keyword when this function calls add_subdirectory. It will also resolve the +# 'make install' issue. +# 2. Group the VC projects into the "external" folder. We can do it at there in a centralized way instead +# of doing it one by one. +# 3. Set the cmake property COMPILE_WARNING_AS_ERROR to OFF for these external projects. + macro(onnxruntime_fetchcontent_makeavailable) # We must append an item, even if the variable is unset, so prefix its value. diff --git a/cmake/external/jemalloc.cmake b/cmake/external/jemalloc.cmake deleted file mode 100644 index db0b922aee..0000000000 --- a/cmake/external/jemalloc.cmake +++ /dev/null @@ -1,24 +0,0 @@ -include (ExternalProject) - -set(JEMALLOC_URL https://github.com/jemalloc/jemalloc/releases/download/4.1.1/jemalloc-4.1.1.tar.bz2) -set(JEMALLOC_BUILD ${CMAKE_CURRENT_BINARY_DIR}/jemalloc/src/jemalloc) -set(JEMALLOC_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/jemalloc/install) - -if(NOT WIN32) - set(JEMALLOC_STATIC_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/jemalloc/install/lib/libjemalloc_pic.a) -else() - message( FATAL_ERROR "Jemalloc is not supported on Windows." ) -endif() - -ExternalProject_Add(jemalloc - PREFIX jemalloc - URL ${JEMALLOC_URL} - INSTALL_DIR ${JEMALLOC_INSTALL} - DOWNLOAD_DIR "${DOWNLOAD_LOCATION}" - BUILD_COMMAND $(MAKE) - BUILD_IN_SOURCE 1 - INSTALL_COMMAND $(MAKE) install - CONFIGURE_COMMAND - ${CMAKE_CURRENT_BINARY_DIR}/jemalloc/src/jemalloc/configure - --prefix=${JEMALLOC_INSTALL} - ) diff --git a/cmake/external/json b/cmake/external/json deleted file mode 160000 index b5364faf9d..0000000000 --- a/cmake/external/json +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b5364faf9d732052506cefc933d3f4e4f04513a5 diff --git a/cmake/external/mimalloc b/cmake/external/mimalloc deleted file mode 160000 index f412df7a2b..0000000000 --- a/cmake/external/mimalloc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f412df7a2b64421e1f1d61fde6055a6ea288e8f5 diff --git a/cmake/external/mimalloc.cmake b/cmake/external/mimalloc.cmake index 346e04f4d7..8738324d8a 100644 --- a/cmake/external/mimalloc.cmake +++ b/cmake/external/mimalloc.cmake @@ -1,15 +1,7 @@ -set(mimalloc_root_dir ${PROJECT_SOURCE_DIR}/external/mimalloc) - add_definitions(-DUSE_MIMALLOC) -include_directories(${mimalloc_root_dir}/include) -option(MI_OVERRIDE "" OFF) -option(MI_BUILD_TESTS "" OFF) -option(MI_DEBUG_FULL "" OFF) - -add_subdirectory(${mimalloc_root_dir} EXCLUDE_FROM_ALL) -set_target_properties(mimalloc-static PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - -if (WIN32) - set_target_properties(mimalloc-static PROPERTIES COMPILE_FLAGS "/wd4389 /wd4201 /wd4244 /wd4565") -endif() +set(MI_OVERRIDE OFF CACHE BOOL "" FORCE) +set(MI_BUILD_TESTS OFF CACHE BOOL "" FORCE) +set(MI_DEBUG_FULL OFF CACHE BOOL "" FORCE) +set(MI_BUILD_SHARED OFF CACHE BOOL "" FORCE) +onnxruntime_fetchcontent_makeavailable(mimalloc) \ No newline at end of file diff --git a/cmake/external/mp11 b/cmake/external/mp11 deleted file mode 160000 index 21cace4e57..0000000000 --- a/cmake/external/mp11 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 21cace4e574180ba64d9307a5e4ea9e5e94d3e8d diff --git a/cmake/external/nsync b/cmake/external/nsync index 436617053d..ac54896827 160000 --- a/cmake/external/nsync +++ b/cmake/external/nsync @@ -1 +1 @@ -Subproject commit 436617053d0f39a1019a371c3a9aa599b3cb2cea +Subproject commit ac5489682760393fe21bd2a8e038b528442412a7 diff --git a/cmake/external/onnx_minimal.cmake b/cmake/external/onnx_minimal.cmake index c42f431ea9..cf9429c185 100644 --- a/cmake/external/onnx_minimal.cmake +++ b/cmake/external/onnx_minimal.cmake @@ -12,7 +12,12 @@ endif() #TODO: if protobuf is a shared lib and onnxruntime_USE_FULL_PROTOBUF is ON, then onnx_proto should be built as a shared lib instead of a static lib. Otherwise any code outside onnxruntime.dll can't use onnx protobuf definitions if they share the protobuf.dll with onnxruntime. For example, if protobuf is a shared lib and onnx_proto is a static lib then onnxruntime_perf_test won't work. -set(ONNX_SOURCE_ROOT ${PROJECT_SOURCE_DIR}/external/onnx) + + +FetchContent_Populate(onnx) +set(ONNX_SOURCE_ROOT ${onnx_SOURCE_DIR}) + + add_library(onnx_proto ${ONNX_SOURCE_ROOT}/onnx/onnx-ml.proto ${ONNX_SOURCE_ROOT}/onnx/onnx-operators-ml.proto ${ONNX_SOURCE_ROOT}/onnx/onnx-data.proto) diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake new file mode 100644 index 0000000000..5dfe2b13dc --- /dev/null +++ b/cmake/external/onnxruntime_external_deps.cmake @@ -0,0 +1,443 @@ +message("Loading Dependencies URLs ...") + +include(external/helper_functions.cmake) + +file(STRINGS deps.txt ONNXRUNTIME_DEPS_LIST) +foreach(ONNXRUNTIME_DEP IN LISTS ONNXRUNTIME_DEPS_LIST) + # Lines start with "#" are comments + if(NOT ONNXRUNTIME_DEP MATCHES "^#") + # The first column is name + list(POP_FRONT ONNXRUNTIME_DEP ONNXRUNTIME_DEP_NAME) + # The second column is URL + # The URL below may be a local file path or an HTTPS URL + list(POP_FRONT ONNXRUNTIME_DEP ONNXRUNTIME_DEP_URL) + set(DEP_URL_${ONNXRUNTIME_DEP_NAME} ${ONNXRUNTIME_DEP_URL}) + # The third column is SHA1 hash value + set(DEP_SHA1_${ONNXRUNTIME_DEP_NAME} ${ONNXRUNTIME_DEP}) + endif() +endforeach() + +message("Loading Dependencies ...") +# ABSL should be included before protobuf because protobuf may use absl +if(NOT onnxruntime_DISABLE_ABSEIL) + include(external/abseil-cpp.cmake) +endif() + +set(RE2_BUILD_TESTING OFF CACHE BOOL "" FORCE) +FetchContent_Declare( + re2 + URL ${DEP_URL_re2} + URL_HASH SHA1=${DEP_SHA1_re2} + FIND_PACKAGE_ARGS NAMES re2 +) + +if (onnxruntime_BUILD_UNIT_TESTS) + # WebAssembly threading support in Node.js is still an experimental feature and + # not working properly with googletest suite. + if (onnxruntime_BUILD_WEBASSEMBLY) + set(gtest_disable_pthreads ON) + endif() + set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) + if(NOT onnxruntime_DISABLE_ABSEIL) + # It uses both ABSL and re2 + set(GTEST_HAS_ABSL OFF CACHE BOOL "" FORCE) + endif() + # gtest and gmock + FetchContent_Declare( + googletest + URL ${DEP_URL_googletest} + FIND_PACKAGE_ARGS NAMES GTest + URL_HASH SHA1=${DEP_SHA1_googletest} + ) +endif() + +if (onnxruntime_BUILD_BENCHMARKS) + # We will not need to test benchmark lib itself. + set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark testing as we don't need it.") + # We will not need to install benchmark since we link it statically. + set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Disable benchmark install to avoid overwriting vendor install.") + + FetchContent_Declare( + google_benchmark + URL ${DEP_URL_google_benchmark} + URL_HASH SHA1=${DEP_SHA1_google_benchmark} + ) +endif() + +if (NOT WIN32) + FetchContent_Declare( + google_nsync + URL ${DEP_URL_google_nsync} + URL_HASH SHA1=${DEP_SHA1_google_nsync} + FIND_PACKAGE_ARGS NAMES nsync + ) +endif() +list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/external) + +FetchContent_Declare( + mimalloc + URL ${DEP_URL_mimalloc} + URL_HASH SHA1=${DEP_SHA1_mimalloc} +) + + + +# Flatbuffers +# We do not need to build flatc for iOS or Android Cross Compile +if (CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android" OR onnxruntime_BUILD_WEBASSEMBLY) + set(FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "FLATBUFFERS_BUILD_FLATC" FORCE) +endif() +set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "FLATBUFFERS_BUILD_TESTS" FORCE) +set(FLATBUFFERS_INSTALL OFF CACHE BOOL "FLATBUFFERS_INSTALL" FORCE) +set(FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "FLATBUFFERS_BUILD_FLATHASH" FORCE) +set(FLATBUFFERS_BUILD_FLATLIB ON CACHE BOOL "FLATBUFFERS_BUILD_FLATLIB" FORCE) +FetchContent_Declare( + flatbuffers + URL ${DEP_URL_flatbuffers} + URL_HASH SHA1=${DEP_SHA1_flatbuffers} + FIND_PACKAGE_ARGS NAMES Flatbuffers +) + +#Here we support two build mode: +#1. if ONNX_CUSTOM_PROTOC_EXECUTABLE is set, build Protobuf from source, except protoc.exe. This mode is mainly +# for cross-compiling +#2. if ONNX_CUSTOM_PROTOC_EXECUTABLE is not set, Compile everything(including protoc) from source code. +if(Patch_FOUND) + set(ONNXRUNTIME_PROTOBUF_PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/protobuf/protobuf_cmake.patch) +else() + set(ONNXRUNTIME_PROTOBUF_PATCH_COMMAND "") +endif() +FetchContent_Declare( + Protobuf + URL ${DEP_URL_protobuf} + URL_HASH SHA1=${DEP_SHA1_protobuf} + SOURCE_SUBDIR cmake + PATCH_COMMAND ${ONNXRUNTIME_PROTOBUF_PATCH_COMMAND} + FIND_PACKAGE_ARGS NAMES Protobuf +) +set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests" FORCE) +if (CMAKE_SYSTEM_NAME STREQUAL "Android") + set(protobuf_BUILD_PROTOC_BINARIES OFF CACHE BOOL "Build protobuf tests" FORCE) + set(protobuf_WITH_ZLIB OFF CACHE BOOL "Build with zlib support" FORCE) +endif() +if (onnxruntime_DISABLE_RTTI) + set(protobuf_DISABLE_RTTI ON CACHE BOOL "Remove runtime type information in the binaries" FORCE) +endif() + +include(protobuf_function) +#protobuf end + +set(ENABLE_DATE_TESTING OFF CACHE BOOL "" FORCE) +set(USE_SYSTEM_TZ_DB ON CACHE BOOL "" FORCE) + +FetchContent_Declare( + date + URL ${DEP_URL_date} + URL_HASH SHA1=${DEP_SHA1_date} + ) +FetchContent_Populate(date) +add_library(date_interface INTERFACE) +target_include_directories(date_interface INTERFACE ${date_SOURCE_DIR}/include) + + + +FetchContent_Declare( + mp11 + URL ${DEP_URL_mp11} + URL_HASH SHA1=${DEP_SHA1_mp11} +) + +set(JSON_BuildTests OFF CACHE INTERNAL "") +set(JSON_Install OFF CACHE INTERNAL "") +set(JSON_BuildTests OFF CACHE INTERNAL "") +set(JSON_Install OFF CACHE INTERNAL "") + +FetchContent_Declare( + nlohmann_json + URL ${DEP_URL_json} + URL_HASH SHA1=${DEP_SHA1_json} + FIND_PACKAGE_ARGS 3.10 NAMES nlohmann_json +) + +#TODO: include clog first +if (onnxruntime_ENABLE_CPUINFO) + # Adding pytorch CPU info library + # TODO!! need a better way to find out the supported architectures + list(LENGTH CMAKE_OSX_ARCHITECTURES CMAKE_OSX_ARCHITECTURES_LEN) + if (APPLE) + if (CMAKE_OSX_ARCHITECTURES_LEN LESS_EQUAL 1) + set(CPUINFO_SUPPORTED TRUE) + elseif (onnxruntime_BUILD_APPLE_FRAMEWORK) + # We stitch multiple static libraries together when onnxruntime_BUILD_APPLE_FRAMEWORK is true, + # but that would not work for universal static libraries + message(FATAL_ERROR "universal binary is not supported for apple framework") + endif() + else() + # if xnnpack is enabled in a wasm build it needs clog from cpuinfo, but we won't internally use cpuinfo + # so we don't set CPUINFO_SUPPORTED in the CXX flags below. + if (onnxruntime_BUILD_WEBASSEMBLY AND NOT onnxruntime_USE_XNNPACK) + set(CPUINFO_SUPPORTED FALSE) + else() + set(CPUINFO_SUPPORTED TRUE) + endif() + if (WIN32) + # Exclude Windows ARM build and Windows Store + if (${onnxruntime_target_platform} MATCHES "^(ARM.*|arm.*)$" ) + message(WARNING "Cpuinfo not included for compilation problems with Windows ARM.") + set(CPUINFO_SUPPORTED FALSE) + elseif (WIN32 AND NOT CMAKE_CXX_STANDARD_LIBRARIES MATCHES kernel32.lib) + message(WARNING "Cpuinfo not included non-Desktop builds") + set(CPUINFO_SUPPORTED FALSE) + endif() + elseif (NOT ${onnxruntime_target_platform} MATCHES "^(i[3-6]86|AMD64|x86(_64)?|armv[5-8].*|aarch64|arm64)$") + message(WARNING + "Target processor architecture \"${onnxruntime_target_platform}\" is not supported in cpuinfo. " + "cpuinfo not included." + ) + set(CPUINFO_SUPPORTED FALSE) + endif() + endif() +else() + set(CPUINFO_SUPPORTED FALSE) +endif() + +if (CPUINFO_SUPPORTED) + if (CMAKE_SYSTEM_NAME STREQUAL "iOS") + set(IOS ON CACHE INTERNAL "") + set(IOS_ARCH "${CMAKE_OSX_ARCHITECTURES}" CACHE INTERNAL "") + endif() + + # if this is a wasm build with xnnpack (only type of wasm build where cpuinfo is involved) + # we do not use cpuinfo in ORT code, so don't define CPUINFO_SUPPORTED. + if (NOT onnxruntime_BUILD_WEBASSEMBLY) + string(APPEND CMAKE_CXX_FLAGS " -DCPUINFO_SUPPORTED") + endif() + + + set(CPUINFO_BUILD_TOOLS OFF CACHE INTERNAL "") + set(CPUINFO_BUILD_UNIT_TESTS OFF CACHE INTERNAL "") + set(CPUINFO_BUILD_MOCK_TESTS OFF CACHE INTERNAL "") + set(CPUINFO_BUILD_BENCHMARKS OFF CACHE INTERNAL "") + + FetchContent_Declare( + pytorch_cpuinfo + URL ${DEP_URL_pytorch_cpuinfo} + URL_HASH SHA1=${DEP_SHA1_pytorch_cpuinfo} + FIND_PACKAGE_ARGS NAMES cpuinfo + ) + +endif() + + +if (onnxruntime_BUILD_BENCHMARKS) + onnxruntime_fetchcontent_makeavailable(google_benchmark) +endif() + +if (NOT WIN32) + #nsync tests failed on Mac Build + set(NSYNC_ENABLE_TESTS OFF CACHE BOOL "" FORCE) + onnxruntime_fetchcontent_makeavailable(google_nsync) + set(nsync_SOURCE_DIR ${google_nsync_SOURCE_DIR}) +endif() + +if(onnxruntime_USE_CUDA) + FetchContent_Declare( + GSL + URL ${DEP_URL_microsoft_gsl} + URL_HASH SHA1=${DEP_SHA1_microsoft_gsl} + PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/gsl/1064.patch + ) +else() + FetchContent_Declare( + GSL + URL ${DEP_URL_microsoft_gsl} + URL_HASH SHA1=${DEP_SHA1_microsoft_gsl} + FIND_PACKAGE_ARGS 4.0 NAMES Microsoft.GSL + ) +endif() + +FetchContent_Declare( + safeint + URL ${DEP_URL_safeint} + URL_HASH SHA1=${DEP_SHA1_safeint} +) + +# The next line will generate an error message "fatal: not a git repository", but it is ok. It is from flatbuffers +onnxruntime_fetchcontent_makeavailable(Protobuf nlohmann_json mp11 re2 safeint GSL flatbuffers) +if (onnxruntime_BUILD_UNIT_TESTS) + onnxruntime_fetchcontent_makeavailable(googletest) +endif() + +if(Protobuf_FOUND) + message("Protobuf version: ${Protobuf_VERSION}") +else() + # Adjust warning flags + if (TARGET libprotoc) + if (NOT MSVC) + target_compile_options(libprotoc PRIVATE "-w") + endif() + endif() + if (TARGET protoc) + add_executable(protobuf::protoc ALIAS protoc) + if (UNIX AND onnxruntime_ENABLE_LTO) + #https://github.com/protocolbuffers/protobuf/issues/5923 + target_link_options(protoc PRIVATE "-Wl,--no-as-needed") + endif() + if (NOT MSVC) + target_compile_options(protoc PRIVATE "-w") + endif() + get_target_property(PROTOC_OSX_ARCH protoc OSX_ARCHITECTURES) + if (PROTOC_OSX_ARCH) + if (${CMAKE_HOST_SYSTEM_PROCESSOR} IN_LIST PROTOC_OSX_ARCH) + message("protoc can run") + else() + list(APPEND PROTOC_OSX_ARCH ${CMAKE_HOST_SYSTEM_PROCESSOR}) + set_target_properties(protoc PROPERTIES OSX_ARCHITECTURES "${CMAKE_HOST_SYSTEM_PROCESSOR}") + set_target_properties(libprotoc PROPERTIES OSX_ARCHITECTURES "${PROTOC_OSX_ARCH}") + set_target_properties(libprotobuf PROPERTIES OSX_ARCHITECTURES "${PROTOC_OSX_ARCH}") + endif() + endif() + endif() + if (TARGET libprotobuf AND NOT MSVC) + target_compile_options(libprotobuf PRIVATE "-w") + endif() + if (TARGET libprotobuf-lite AND NOT MSVC) + target_compile_options(libprotobuf-lite PRIVATE "-w") + endif() +endif() +if (onnxruntime_USE_FULL_PROTOBUF) + set(PROTOBUF_LIB protobuf::libprotobuf) +else() + set(PROTOBUF_LIB protobuf::libprotobuf-lite) +endif() + + +# ONNX +if (NOT onnxruntime_USE_FULL_PROTOBUF) + set(ONNX_USE_LITE_PROTO ON CACHE BOOL "" FORCE) +else() + set(ONNX_USE_LITE_PROTO OFF CACHE BOOL "" FORCE) +endif() + +if(Patch_FOUND) + set(ONNXRUNTIME_ONNX_PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/onnx/onnx.patch) +else() + set(ONNXRUNTIME_ONNX_PATCH_COMMAND "") +endif() + +FetchContent_Declare( + onnx + URL ${DEP_URL_onnx} + URL_HASH SHA1=${DEP_SHA1_onnx} + PATCH_COMMAND ${ONNXRUNTIME_ONNX_PATCH_COMMAND} +) + + +if (CPUINFO_SUPPORTED) + onnxruntime_fetchcontent_makeavailable(pytorch_cpuinfo) +endif() + + + +include(eigen) +include(wil) + +if (NOT onnxruntime_MINIMAL_BUILD) + onnxruntime_fetchcontent_makeavailable(onnx) +else() + include(onnx_minimal) +endif() + +set(GSL_TARGET "Microsoft.GSL::GSL") +set(GSL_INCLUDE_DIR "$") + +add_library(safeint_interface INTERFACE) +target_include_directories(safeint_interface INTERFACE ${safeint_SOURCE_DIR}) + +# XNNPACK EP +if (onnxruntime_USE_XNNPACK) + if (onnxruntime_DISABLE_CONTRIB_OPS) + message(FATAL_ERROR "XNNPACK EP requires the internal NHWC contrib ops to be available " + "but onnxruntime_DISABLE_CONTRIB_OPS is ON") + endif() + include(xnnpack) +endif() + +if (onnxruntime_USE_MIMALLOC) + add_definitions(-DUSE_MIMALLOC) + + set(MI_OVERRIDE OFF CACHE BOOL "" FORCE) + set(MI_BUILD_TESTS OFF CACHE BOOL "" FORCE) + set(MI_DEBUG_FULL OFF CACHE BOOL "" FORCE) + set(MI_BUILD_SHARED OFF CACHE BOOL "" FORCE) + onnxruntime_fetchcontent_makeavailable(mimalloc) +endif() + +#onnxruntime_EXTERNAL_LIBRARIES could contain onnx, onnx_proto,libprotobuf, cuda/cudnn, +# dnnl/mklml, onnxruntime_codegen_tvm, tvm and pthread +# pthread is always at the last +set(onnxruntime_EXTERNAL_LIBRARIES ${onnxruntime_EXTERNAL_LIBRARIES_XNNPACK} WIL::WIL nlohmann_json::nlohmann_json onnx onnx_proto ${PROTOBUF_LIB} re2::re2 Boost::mp11 safeint_interface flatbuffers ${GSL_TARGET} ${ABSEIL_LIBS}) +# The source code of onnx_proto is generated, we must build this lib first before starting to compile the other source code that uses ONNX protobuf types. +# The other libs do not have the problem. All the sources are already there. We can compile them in any order. +set(onnxruntime_EXTERNAL_DEPENDENCIES onnx_proto) + +target_compile_definitions(onnx PUBLIC $ PRIVATE "__ONNX_DISABLE_STATIC_REGISTRATION") +if (NOT onnxruntime_USE_FULL_PROTOBUF) + target_compile_definitions(onnx PUBLIC "__ONNX_NO_DOC_STRINGS") +endif() + +if (onnxruntime_RUN_ONNX_TESTS) + add_definitions(-DORT_RUN_EXTERNAL_ONNX_TESTS) +endif() + + +if(onnxruntime_ENABLE_ATEN) + message("Aten fallback is enabled.") + FetchContent_Declare( + dlpack + URL ${DEP_URL_dlpack} + URL_HASH SHA1=${DEP_SHA1_dlpack} + ) + # We can't use onnxruntime_fetchcontent_makeavailable since some part of the the dlpack code is Linux only. + # For example, dlpackcpp.h uses posix_memalign. + FetchContent_Populate(dlpack) +endif() + +if(onnxruntime_ENABLE_TRAINING) + FetchContent_Declare( + cxxopts + URL ${DEP_URL_cxxopts} + URL_HASH SHA1=${DEP_SHA1_cxxopts} + ) + set(CXXOPTS_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) + set(CXXOPTS_BUILD_TESTS OFF CACHE BOOL "" FORCE) + onnxruntime_fetchcontent_makeavailable(cxxopts) +endif() + +message("Finished fetching external dependencies") + + +set(onnxruntime_LINK_DIRS ) +if (onnxruntime_USE_CUDA) + #TODO: combine onnxruntime_CUDNN_HOME and onnxruntime_CUDA_HOME, assume they are the same + if (WIN32) + if(onnxruntime_CUDNN_HOME) + list(APPEND onnxruntime_LINK_DIRS ${onnxruntime_CUDNN_HOME}/lib ${onnxruntime_CUDNN_HOME}/lib/x64) + endif() + list(APPEND onnxruntime_LINK_DIRS ${onnxruntime_CUDA_HOME}/x64/lib64) + else() + if(onnxruntime_CUDNN_HOME) + list(APPEND onnxruntime_LINK_DIRS ${onnxruntime_CUDNN_HOME}/lib64) + endif() + list(APPEND onnxruntime_LINK_DIRS ${onnxruntime_CUDA_HOME}/lib64) + endif() +endif() + +if(onnxruntime_USE_SNPE) + include(find_snpe.cmake) + list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${SNPE_NN_LIBS}) +endif() + +FILE(TO_NATIVE_PATH ${CMAKE_BINARY_DIR} ORT_BINARY_DIR) +FILE(TO_NATIVE_PATH ${PROJECT_SOURCE_DIR} ORT_SOURCE_DIR) + diff --git a/cmake/protobuf_function.cmake b/cmake/external/protobuf_function.cmake similarity index 100% rename from cmake/protobuf_function.cmake rename to cmake/external/protobuf_function.cmake diff --git a/cmake/external/pthreadpool b/cmake/external/pthreadpool deleted file mode 160000 index 1787867f61..0000000000 --- a/cmake/external/pthreadpool +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1787867f6183f056420e532eec640cba25efafea diff --git a/cmake/external/pybind11.cmake b/cmake/external/pybind11.cmake index 86aee98efa..2c9e3cf454 100644 --- a/cmake/external/pybind11.cmake +++ b/cmake/external/pybind11.cmake @@ -1,24 +1,13 @@ +FetchContent_Declare( + pybind11_project + URL ${DEP_URL_pybind11} + URL_HASH SHA1=${DEP_SHA1_pybind11} + FIND_PACKAGE_ARGS 2.6 NAMES pybind11 +) +onnxruntime_fetchcontent_makeavailable(pybind11_project) -if(onnxruntime_PREFER_SYSTEM_LIB) - find_package(pybind11) -endif() - -if(NOT TARGET pybind11::module) - include(ExternalProject) - - set(pybind11_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/pybind11/src/pybind11/include) - set(pybind11_URL https://github.com/pybind/pybind11.git) - set(pybind11_TAG v2.6.2) - - ExternalProject_Add(pybind11 - PREFIX pybind11 - GIT_REPOSITORY ${pybind11_URL} - GIT_TAG ${pybind11_TAG} - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - ) - set(pybind11_dep pybind11) -else() +if(TARGET pybind11::module) set(pybind11_lib pybind11::module) +else() + set(pybind11_dep pybind11::pybind11) endif() diff --git a/cmake/external/re2 b/cmake/external/re2 index 4244cd1cb4..5723bb8950 160000 --- a/cmake/external/re2 +++ b/cmake/external/re2 @@ -1 +1 @@ -Subproject commit 4244cd1cb492fa1d10986ec67f862964c073f844 +Subproject commit 5723bb8950318135ed9cf4fc76bed988a087f536 diff --git a/cmake/external/wil b/cmake/external/wil index e8c599bca6..5f4caba4e7 160000 --- a/cmake/external/wil +++ b/cmake/external/wil @@ -1 +1 @@ -Subproject commit e8c599bca6c56c44b6730ad93f6abbc9ecd60fc1 +Subproject commit 5f4caba4e7a9017816e47becdd918fcc872039ba diff --git a/cmake/external/wil.cmake b/cmake/external/wil.cmake new file mode 100644 index 0000000000..d38535c4a1 --- /dev/null +++ b/cmake/external/wil.cmake @@ -0,0 +1,22 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +set(WIL_BUILD_PACKAGING OFF CACHE BOOL "" FORCE) +set(WIL_BUILD_TESTS OFF CACHE BOOL "" FORCE) + +FetchContent_Declare( + microsoft_wil + URL ${DEP_URL_microsoft_wil} + URL_HASH SHA1=${DEP_SHA1_microsoft_wil} + FIND_PACKAGE_ARGS NAMES wil +) +#We can not use FetchContent_MakeAvailable(microsoft_wil) at here, since their cmake file +#always executes install command without conditions. +FetchContent_Populate(microsoft_wil) +if(NOT wil_FOUND) + add_library(WIL INTERFACE) + add_library(WIL::WIL ALIAS WIL) + + # The interface's include directory. + target_include_directories(WIL INTERFACE + $) +endif() \ No newline at end of file diff --git a/cmake/external/xnnpack.cmake b/cmake/external/xnnpack.cmake index 5c40e3f6b3..1fc2c6ccdc 100644 --- a/cmake/external/xnnpack.cmake +++ b/cmake/external/xnnpack.cmake @@ -1,32 +1,38 @@ -set(XNNPACK_DIR external/XNNPACK) -set(XNNPACK_INCLUDE_DIR ${XNNPACK_DIR}/include) set(XNNPACK_USE_SYSTEM_LIBS ON CACHE INTERNAL "") set(XNNPACK_BUILD_TESTS OFF CACHE INTERNAL "") set(XNNPACK_BUILD_BENCHMARKS OFF CACHE INTERNAL "") set(FP16_BUILD_TESTS OFF CACHE INTERNAL "") set(FP16_BUILD_BENCHMARKS OFF CACHE INTERNAL "") -set(CLOG_SOURCE_DIR "${PYTORCH_CPUINFO_DIR}/deps/clog") -set(CPUINFO_SOURCE_DIR ${PYTORCH_CPUINFO_DIR}) +set(PTHREADPOOL_BUILD_TESTS OFF CACHE INTERNAL "") +set(PTHREADPOOL_BUILD_BENCHMARKS OFF CACHE INTERNAL "") # BF16 instructions cause ICE in Android NDK compiler if(CMAKE_ANDROID_ARCH_ABI STREQUAL armeabi-v7a) set(XNNPACK_ENABLE_ARM_BF16 OFF) ENDIF() -if(onnxruntime_BUILD_WEBASSEMBLY OR CMAKE_SYSTEM_NAME STREQUAL "iOS") - execute_process(COMMAND git apply --ignore-space-change --ignore-whitespace ${PROJECT_SOURCE_DIR}/patches/xnnpack/AddEmscriptenAndIosSupport.patch WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/${XNNPACK_DIR}) -endif() +# fp16 depends on psimd +FetchContent_Declare(psimd URL ${DEP_URL_psimd} URL_HASH SHA1=${DEP_SHA1_psimd}) +onnxruntime_fetchcontent_makeavailable(psimd) +set(PSIMD_SOURCE_DIR ${psimd_SOURCE_DIR}) +FetchContent_Declare(fp16 URL ${DEP_URL_fp16} URL_HASH SHA1=${DEP_SHA1_fp16}) +onnxruntime_fetchcontent_makeavailable(fp16) -add_subdirectory(external/FP16) -add_subdirectory(external/pthreadpool) -add_subdirectory(external/XNNPACK) +# pthreadpool depends on fxdiv +FetchContent_Declare(fxdiv URL ${DEP_URL_fxdiv} URL_HASH SHA1=${DEP_SHA1_fxdiv}) +onnxruntime_fetchcontent_makeavailable(fxdiv) +set(FXDIV_SOURCE_DIR ${fxdiv_SOURCE_DIR}) -set_target_properties(fp16 PROPERTIES FOLDER "External/Xnnpack") -set_target_properties(pthreadpool PROPERTIES FOLDER "External/Xnnpack") -set_target_properties(XNNPACK PROPERTIES FOLDER "External/Xnnpack") +FetchContent_Declare(pthreadpool URL ${DEP_URL_pthreadpool} URL_HASH SHA1=${DEP_SHA1_pthreadpool}) +onnxruntime_fetchcontent_makeavailable(pthreadpool) +FetchContent_Declare(googlexnnpack URL ${DEP_URL_googlexnnpack} URL_HASH SHA1=${DEP_SHA1_googlexnnpack} +PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/xnnpack/AddEmscriptenAndIosSupport.patch) + +onnxruntime_fetchcontent_makeavailable(googlexnnpack) +set(XNNPACK_DIR ${googlexnnpack_SOURCE_DIR}) +set(XNNPACK_INCLUDE_DIR ${XNNPACK_DIR}/include) set(onnxruntime_EXTERNAL_LIBRARIES_XNNPACK XNNPACK pthreadpool) -list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${onnxruntime_EXTERNAL_LIBRARIES_XNNPACK}) # the XNNPACK CMake setup doesn't include the WASM kernels so we have to manually set those up if(onnxruntime_BUILD_WEBASSEMBLY) diff --git a/cmake/onnxruntime_codegen_tvm.cmake b/cmake/onnxruntime_codegen_tvm.cmake index 93ce4a2683..8007401bb9 100644 --- a/cmake/onnxruntime_codegen_tvm.cmake +++ b/cmake/onnxruntime_codegen_tvm.cmake @@ -19,7 +19,7 @@ source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_codegen_common_sr onnxruntime_add_static_library(onnxruntime_codegen_tvm ${onnxruntime_codegen_common_srcs} ${onnxruntime_codegen_tvm_srcs}) set_target_properties(onnxruntime_codegen_tvm PROPERTIES FOLDER "ONNXRuntime") target_include_directories(onnxruntime_codegen_tvm PRIVATE ${ONNXRUNTIME_ROOT} ${TVM_INCLUDES} ${MKLML_INCLUDE_DIR} ${eigen_INCLUDE_DIRS}) -onnxruntime_add_include_to_target(onnxruntime_codegen_tvm onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers) +onnxruntime_add_include_to_target(onnxruntime_codegen_tvm onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers safeint_interface Boost::mp11) target_compile_options(onnxruntime_codegen_tvm PRIVATE ${DISABLED_WARNINGS_FOR_TVM}) # need onnx to build to create headers that this project includes add_dependencies(onnxruntime_codegen_tvm ${onnxruntime_EXTERNAL_DEPENDENCIES}) diff --git a/cmake/onnxruntime_common.cmake b/cmake/onnxruntime_common.cmake index fe301d4bd6..64ddef1555 100644 --- a/cmake/onnxruntime_common.cmake +++ b/cmake/onnxruntime_common.cmake @@ -90,26 +90,14 @@ onnxruntime_add_static_library(onnxruntime_common ${onnxruntime_common_src}) if (onnxruntime_USE_TELEMETRY) set_target_properties(onnxruntime_common PROPERTIES COMPILE_FLAGS "/FI${ONNXRUNTIME_INCLUDE_DIR}/core/platform/windows/TraceLoggingConfigPrivate.h") endif() - if (onnxruntime_USE_MIMALLOC) - if(NOT WIN32) - message(FATAL_ERROR "Currently do not support MIMALLOC in GPU builds") - endif() - if(onnxruntime_USE_CUDA OR onnxruntime_USE_OPENVINO) - message(WARNING "Currently do not support MIMALLOC in GPU builds") - else() - include(external/mimalloc.cmake) - list(APPEND onnxruntime_EXTERNAL_LIBRARIES mimalloc-static) - list(APPEND onnxruntime_EXTERNAL_DEPENDENCIES mimalloc-static) - set(onnxruntime_mimalloc_shim_src "${ONNXRUNTIME_ROOT}/core/platform/windows/mimalloc/mimalloc_overloads.cc") - add_library(onnxruntime_mimalloc_shim ${onnxruntime_mimalloc_shim_src}) - target_link_libraries(onnxruntime_mimalloc_shim mimalloc-static) - target_link_libraries(onnxruntime_common onnxruntime_mimalloc_shim) - endif() + list(APPEND onnxruntime_EXTERNAL_LIBRARIES mimalloc-static) + onnxruntime_add_static_library(onnxruntime_mimalloc_shim "${ONNXRUNTIME_ROOT}/core/platform/windows/mimalloc/mimalloc_overloads.cc") + target_link_libraries(onnxruntime_mimalloc_shim PRIVATE mimalloc-static) + target_link_libraries(onnxruntime_common PRIVATE onnxruntime_mimalloc_shim) endif() if(NOT onnxruntime_DISABLE_ABSEIL) - include(external/abseil-cpp.cmake) target_include_directories(onnxruntime_common PRIVATE ${ABSEIL_SOURCE_DIR}) if (MSVC) set(ABSEIL_NATVIS_FILE "abseil-cpp.natvis") @@ -119,18 +107,15 @@ if(NOT onnxruntime_DISABLE_ABSEIL) endif() endif() -onnxruntime_add_include_to_target(onnxruntime_common date_interface wil) +onnxruntime_add_include_to_target(onnxruntime_common date_interface WIL::WIL) target_include_directories(onnxruntime_common PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS} # propagate include directories of dependencies that are part of public interface PUBLIC ${OPTIONAL_LITE_INCLUDE_DIR}) -target_link_libraries(onnxruntime_common safeint_interface Boost::mp11 ${GSL_TARGET}) -if(NOT WIN32) - target_include_directories(onnxruntime_common PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/external/nsync/public") -endif() +target_link_libraries(onnxruntime_common PUBLIC safeint_interface ${GSL_TARGET}) add_dependencies(onnxruntime_common ${onnxruntime_EXTERNAL_DEPENDENCIES}) @@ -138,20 +123,6 @@ install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/common DEST set_target_properties(onnxruntime_common PROPERTIES LINKER_LANGUAGE CXX) set_target_properties(onnxruntime_common PROPERTIES FOLDER "ONNXRuntime") -# check if we need to link against librt on Linux -include(CheckLibraryExists) -include(CheckFunctionExists) -if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") - check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME) - - if (NOT HAVE_CLOCK_GETTIME) - set(CMAKE_EXTRA_INCLUDE_FILES time.h) - check_function_exists(clock_gettime HAVE_CLOCK_GETTIME) - set(CMAKE_EXTRA_INCLUDE_FILES) - else() - target_link_libraries(onnxruntime_common rt) - endif() -endif() if (onnxruntime_WINML_NAMESPACE_OVERRIDE STREQUAL "Windows") target_compile_definitions(onnxruntime_common PRIVATE "BUILD_INBOX=1") @@ -164,7 +135,7 @@ if (onnxruntime_LINK_LIBATOMIC) endif() if(APPLE) - target_link_libraries(onnxruntime_common "-framework Foundation") + target_link_libraries(onnxruntime_common PRIVATE "-framework Foundation") endif() @@ -222,9 +193,8 @@ if (ARM64 OR ARM OR X86 OR X64 OR X86_64) # Link cpuinfo if supported # Using it mainly in ARM with Android. # Its functionality in detecting x86 cpu features are lacking, so is support for Windows. - if (CPUINFO_SUPPORTED) - target_link_libraries(onnxruntime_common cpuinfo) + onnxruntime_add_include_to_target(onnxruntime_common cpuinfo) list(APPEND onnxruntime_EXTERNAL_LIBRARIES cpuinfo clog) endif() endif() diff --git a/cmake/onnxruntime_eager.cmake b/cmake/onnxruntime_eager.cmake index d8a1e83227..2756d48804 100644 --- a/cmake/onnxruntime_eager.cmake +++ b/cmake/onnxruntime_eager.cmake @@ -22,7 +22,7 @@ if(MSVC AND onnxruntime_ENABLE_EAGER_MODE) set_source_files_properties("${ORTTRAINING_ROOT}/orttraining/eager/ort_util.cpp" PROPERTIES COMPILE_FLAGS "/wd4100") endif() install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/eager DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core) -onnxruntime_add_include_to_target(onnxruntime_eager onnxruntime_common onnxruntime_framework onnxruntime_optimizer onnxruntime_graph onnx onnx_proto ${PROTOBUF_LIB} flatbuffers) +onnxruntime_add_include_to_target(onnxruntime_eager onnxruntime_common onnxruntime_framework onnxruntime_optimizer onnxruntime_graph onnx onnx_proto ${PROTOBUF_LIB} flatbuffers safeint_interface Boost::mp11) if(onnxruntime_ENABLE_INSTRUMENT) target_compile_definitions(onnxruntime_eager PUBLIC ONNXRUNTIME_ENABLE_INSTRUMENT) endif() diff --git a/cmake/onnxruntime_framework.cmake b/cmake/onnxruntime_framework.cmake index ca501dbeac..79a3b32016 100644 --- a/cmake/onnxruntime_framework.cmake +++ b/cmake/onnxruntime_framework.cmake @@ -51,19 +51,19 @@ if (onnxruntime_ENABLE_TRAINING OR onnxruntime_ENABLE_TRAINING_OPS) target_include_directories(onnxruntime_framework PRIVATE ${ORTTRAINING_ROOT}) if (onnxruntime_ENABLE_TRAINING_TORCH_INTEROP) onnxruntime_add_include_to_target(onnxruntime_framework Python::Module) - target_include_directories(onnxruntime_framework PRIVATE ${PROJECT_SOURCE_DIR}/external/dlpack/include) + target_include_directories(onnxruntime_framework PRIVATE ${dlpack_SOURCE_DIR}/include) endif() if (onnxruntime_USE_NCCL OR onnxruntime_USE_MPI) target_include_directories(onnxruntime_framework PUBLIC ${MPI_CXX_INCLUDE_DIRS}) endif() endif() + if (onnxruntime_ENABLE_ATEN) # DLPack is a header-only dependency - target_compile_definitions(onnxruntime_framework PRIVATE ENABLE_ATEN) - set(DLPACK_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/external/dlpack/include) + set(DLPACK_INCLUDE_DIR ${dlpack_SOURCE_DIR}/include) target_include_directories(onnxruntime_framework PRIVATE ${DLPACK_INCLUDE_DIR}) endif() -onnxruntime_add_include_to_target(onnxruntime_framework onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} flatbuffers) +onnxruntime_add_include_to_target(onnxruntime_framework onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} flatbuffers safeint_interface Boost::mp11) if (onnxruntime_USE_MIMALLOC) target_link_libraries(onnxruntime_framework mimalloc-static) diff --git a/cmake/onnxruntime_graph.cmake b/cmake/onnxruntime_graph.cmake index 35215714c6..12f4cd1033 100644 --- a/cmake/onnxruntime_graph.cmake +++ b/cmake/onnxruntime_graph.cmake @@ -86,7 +86,7 @@ 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 onnx onnx_proto ${PROTOBUF_LIB} 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") diff --git a/cmake/onnxruntime_language_interop_ops.cmake b/cmake/onnxruntime_language_interop_ops.cmake index a7cbe72a5e..d3921be797 100644 --- a/cmake/onnxruntime_language_interop_ops.cmake +++ b/cmake/onnxruntime_language_interop_ops.cmake @@ -4,5 +4,5 @@ include(onnxruntime_pyop.cmake) file (GLOB onnxruntime_language_interop_ops_src "${ONNXRUNTIME_ROOT}/core/language_interop_ops/language_interop_ops.cc") onnxruntime_add_static_library(onnxruntime_language_interop ${onnxruntime_language_interop_ops_src}) add_dependencies(onnxruntime_language_interop onnxruntime_pyop) -onnxruntime_add_include_to_target(onnxruntime_language_interop onnxruntime_common onnxruntime_graph onnxruntime_framework onnxruntime_pyop onnx onnx_proto ${PROTOBUF_LIB} flatbuffers) +onnxruntime_add_include_to_target(onnxruntime_language_interop onnxruntime_common onnxruntime_graph onnxruntime_framework onnxruntime_pyop onnx onnx_proto ${PROTOBUF_LIB} flatbuffers safeint_interface Boost::mp11) target_include_directories(onnxruntime_language_interop PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS}) \ No newline at end of file diff --git a/cmake/onnxruntime_opschema_lib.cmake b/cmake/onnxruntime_opschema_lib.cmake index d3f6f89dce..18c3eed6ed 100644 --- a/cmake/onnxruntime_opschema_lib.cmake +++ b/cmake/onnxruntime_opschema_lib.cmake @@ -27,10 +27,10 @@ target_compile_options(ort_opschema_lib PRIVATE -D_OPSCHEMA_LIB_=1) if(NOT MSVC) target_compile_options(ort_opschema_lib PRIVATE "-Wno-parentheses") endif() -set (OPSCHEMA_LIB_DEPENDENCIES onnx onnx_proto ${PROTOBUF_LIB} flatbuffers) +set (OPSCHEMA_LIB_DEPENDENCIES onnx onnx_proto ${PROTOBUF_LIB} flatbuffers safeint_interface Boost::mp11 safeint_interface) # ${CMAKE_CURRENT_BINARY_DIR} is so that #include "onnxruntime_config.h" is found target_include_directories(ort_opschema_lib PRIVATE ${ONNXRUNTIME_ROOT} ${ORTTRAINING_ROOT} ${CMAKE_CURRENT_BINARY_DIR}) -onnxruntime_add_include_to_target(ort_opschema_lib onnxruntime_common onnx onnx_proto protobuf::libprotobuf flatbuffers) +onnxruntime_add_include_to_target(ort_opschema_lib onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} flatbuffers Boost::mp11 safeint_interface) add_dependencies(ort_opschema_lib ${OPSCHEMA_LIB_DEPENDENCIES}) diff --git a/cmake/onnxruntime_optimizer.cmake b/cmake/onnxruntime_optimizer.cmake index c667ac868d..894c24ad11 100644 --- a/cmake/onnxruntime_optimizer.cmake +++ b/cmake/onnxruntime_optimizer.cmake @@ -94,7 +94,7 @@ endif() onnxruntime_add_static_library(onnxruntime_optimizer ${onnxruntime_optimizer_srcs}) install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/optimizer DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core) -onnxruntime_add_include_to_target(onnxruntime_optimizer onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers) +onnxruntime_add_include_to_target(onnxruntime_optimizer onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers Boost::mp11 safeint_interface) target_include_directories(onnxruntime_optimizer PRIVATE ${ONNXRUNTIME_ROOT}) if (onnxruntime_ENABLE_TRAINING) target_include_directories(onnxruntime_optimizer PRIVATE ${ORTTRAINING_ROOT}) diff --git a/cmake/onnxruntime_providers.cmake b/cmake/onnxruntime_providers.cmake index 3e6f62dae7..a8a195a597 100644 --- a/cmake/onnxruntime_providers.cmake +++ b/cmake/onnxruntime_providers.cmake @@ -246,7 +246,7 @@ if (MSVC) # target_compile_options(onnxruntime_providers PRIVATE "/wd4244") # endif() endif() -onnxruntime_add_include_to_target(onnxruntime_providers onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers) +onnxruntime_add_include_to_target(onnxruntime_providers onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers Boost::mp11 safeint_interface) if (onnxruntime_BUILD_MS_EXPERIMENTAL_OPS) target_compile_definitions(onnxruntime_providers PRIVATE BUILD_MS_EXPERIMENTAL_OPS=1) @@ -264,8 +264,16 @@ if(HAS_DEPRECATED_COPY) set_source_files_properties("${ONNXRUNTIME_ROOT}/core/providers/cpu/tensor/where_op.cc" PROPERTIES COMPILE_FLAGS -Wno-deprecated-copy) endif() -target_include_directories(onnxruntime_providers PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS} ${RE2_INCLUDE_DIR}) +# This is enabled only for Adasum files in training mode. +# The flags won't be applied globally since some high-precision training and inferencing ops will incur precision loss. +if (onnxruntime_ENABLE_CPU_FP16_OPS) + set_source_files_properties(${ORTTRAINING_SOURCE_DIR}/core/framework/adasum/adasum_mpi.cc PROPERTIES COMPILE_FLAGS " -fassociative-math -ffast-math -ftree-vectorize -funsafe-math-optimizations -mf16c -mavx -mfma ") + set_source_files_properties(${ORTTRAINING_SOURCE_DIR}/training_ops/cpu/collective/adasum_kernels.cc PROPERTIES COMPILE_FLAGS " -fassociative-math -ffast-math -ftree-vectorize -funsafe-math-optimizations -mf16c -mavx -mfma ") + set_source_files_properties(${ORTTRAINING_SOURCE_DIR}/training_ops/cuda/collective/adasum_kernels.cc PROPERTIES COMPILE_FLAGS " -fassociative-math -ffast-math -ftree-vectorize -funsafe-math-optimizations -mf16c -mavx -mfma ") +endif() +target_include_directories(onnxruntime_providers PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS}) +onnxruntime_add_include_to_target(onnxruntime_providers re2::re2) add_dependencies(onnxruntime_providers onnx ${onnxruntime_EXTERNAL_DEPENDENCIES}) if (onnxruntime_ENABLE_TRAINING OR onnxruntime_ENABLE_TRAINING_OPS) @@ -275,7 +283,7 @@ endif() if (onnxruntime_ENABLE_ATEN) target_compile_definitions(onnxruntime_providers PRIVATE ENABLE_ATEN) # DLPack is a header-only dependency - set(DLPACK_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/external/dlpack/include) + set(DLPACK_INCLUDE_DIR ${dlpack_SOURCE_DIR}/include) target_include_directories(onnxruntime_providers PRIVATE ${DLPACK_INCLUDE_DIR}) endif() @@ -318,6 +326,8 @@ if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD # On Apple/Unix we don't directly link with this library as we load it with RTLD_GLOBAL, so this is only set to the actual library on WIN32 + # But, in exchange we need to manually add Boost::mp11 to include dirs for every EP. + # It is because "provider_api.h" includes core/framework/op_kernel.h which includes op_kernel.h which includes "boost/mp11.hpp" set(ONNXRUNTIME_PROVIDERS_SHARED) if(APPLE) @@ -452,7 +462,7 @@ if (onnxruntime_USE_CUDA) endif() add_dependencies(onnxruntime_providers_cuda onnxruntime_providers_shared ${onnxruntime_EXTERNAL_DEPENDENCIES}) - target_link_libraries(onnxruntime_providers_cuda PRIVATE cublasLt cublas cudnn curand cufft ${ABSEIL_LIBS} ${ONNXRUNTIME_PROVIDERS_SHARED}) + target_link_libraries(onnxruntime_providers_cuda PRIVATE cublasLt cublas cudnn curand cufft ${ABSEIL_LIBS} ${ONNXRUNTIME_PROVIDERS_SHARED} Boost::mp11 safeint_interface) if(onnxruntime_CUDNN_HOME) target_include_directories(onnxruntime_providers_cuda PRIVATE ${onnxruntime_CUDNN_HOME}/include) endif() @@ -585,11 +595,10 @@ if (onnxruntime_USE_TENSORRT) set(BUILD_LIBRARY_ONLY 1) add_definitions("-DONNX_ML=1") add_definitions("-DONNX_NAMESPACE=onnx") - include_directories(${PROJECT_SOURCE_DIR}/external/protobuf) set(CUDA_INCLUDE_DIRS ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) set(TENSORRT_ROOT ${onnxruntime_TENSORRT_HOME}) - include_directories(${ONNXRUNTIME_ROOT}/../cmake/external/onnx) set(OLD_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) + set(PROTOBUF_LIBRARY ${PROTOBUF_LIB}) if (WIN32) add_definitions(-D_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING=1) set(OLD_CMAKE_CUDA_FLAGS ${CMAKE_CUDA_FLAGS}) @@ -598,7 +607,6 @@ if (onnxruntime_USE_TENSORRT) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4805") endif() set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -include algorithm") - set(PROTOBUF_LIBRARY libprotobuf) set(DISABLED_WARNINGS_FOR_TRT /wd4456) endif() if ( CMAKE_COMPILER_IS_GNUCC ) @@ -624,7 +632,13 @@ if (onnxruntime_USE_TENSORRT) set(TENSORRT_LIBRARY ${TENSORRT_LIBRARY_INFER} ${TENSORRT_LIBRARY_INFER_PLUGIN} ${TENSORRT_LIBRARY_NVONNXPARSER}) MESSAGE(STATUS "Find TensorRT libs at ${TENSORRT_LIBRARY}") else() - add_subdirectory(${ONNXRUNTIME_ROOT}/../cmake/external/onnx-tensorrt) + FetchContent_Declare( + onnx_tensorrt + URL ${DEP_URL_onnx_tensorrt} + URL_HASH SHA1=${DEP_SHA1_onnx_tensorrt} + ) + FetchContent_MakeAvailable(onnx_tensorrt) + include_directories(${onnx_tensorrt_SOURCE_DIR}) set(CMAKE_CXX_FLAGS ${OLD_CMAKE_CXX_FLAGS}) if ( CMAKE_COMPILER_IS_GNUCC ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter") @@ -638,7 +652,6 @@ if (onnxruntime_USE_TENSORRT) target_compile_options(nvonnxparser_static PRIVATE /FIio.h /wd4100) target_compile_options(nvonnxparser PRIVATE /FIio.h /wd4100) endif() - include_directories(${ONNXRUNTIME_ROOT}/../cmake/external/onnx-tensorrt) include_directories(${TENSORRT_INCLUDE_DIR}) set(onnxparser_link_libs nvonnxparser_static) endif() @@ -654,10 +667,10 @@ if (onnxruntime_USE_TENSORRT) source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_tensorrt_cc_srcs}) onnxruntime_add_shared_library_module(onnxruntime_providers_tensorrt ${onnxruntime_providers_tensorrt_cc_srcs}) - onnxruntime_add_include_to_target(onnxruntime_providers_tensorrt onnxruntime_common onnx flatbuffers) + onnxruntime_add_include_to_target(onnxruntime_providers_tensorrt onnxruntime_common onnx flatbuffers Boost::mp11 safeint_interface) add_dependencies(onnxruntime_providers_tensorrt onnxruntime_providers_shared ${onnxruntime_EXTERNAL_DEPENDENCIES}) if (onnxruntime_USE_TENSORRT_BUILTIN_PARSER) - target_link_libraries(onnxruntime_providers_tensorrt PRIVATE ${trt_link_libs} cudart ${ONNXRUNTIME_PROVIDERS_SHARED} ${PROTOBUF_LIB} flatbuffers ${ABSEIL_LIBS}) + target_link_libraries(onnxruntime_providers_tensorrt PRIVATE ${trt_link_libs} cudart ${ONNXRUNTIME_PROVIDERS_SHARED} ${PROTOBUF_LIB} flatbuffers Boost::mp11 safeint_interface ${ABSEIL_LIBS}) target_include_directories(onnxruntime_providers_tensorrt PRIVATE ${ONNXRUNTIME_ROOT} ${CMAKE_CURRENT_BINARY_DIR} ${eigen_INCLUDE_DIRS} ${TENSORRT_INCLUDE_DIR} PUBLIC ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) else() target_link_libraries(onnxruntime_providers_tensorrt PRIVATE ${onnxparser_link_libs} ${trt_link_libs} cudart ${ONNXRUNTIME_PROVIDERS_SHARED} ${PROTOBUF_LIB} flatbuffers ${ABSEIL_LIBS}) @@ -666,6 +679,7 @@ if (onnxruntime_USE_TENSORRT) if(onnxruntime_CUDNN_HOME) target_include_directories(onnxruntime_providers_tensorrt PRIVATE ${onnxruntime_CUDNN_HOME}/include) endif() + # ${CMAKE_CURRENT_BINARY_DIR} is so that #include "onnxruntime_config.h" inside tensor_shape.h is found install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/providers/tensorrt DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/providers) set_target_properties(onnxruntime_providers_tensorrt PROPERTIES LINKER_LANGUAGE CUDA) @@ -712,7 +726,7 @@ if (onnxruntime_USE_VITISAI) source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_vitisai_cc_srcs}) onnxruntime_add_static_library(onnxruntime_providers_vitisai ${onnxruntime_providers_vitisai_cc_srcs}) onnxruntime_add_include_to_target(onnxruntime_providers_vitisai - onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers + onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers Boost::mp11 safeint_interface ) add_dependencies(onnxruntime_providers_vitisai ${onnxruntime_EXTERNAL_DEPENDENCIES}) set_target_properties(onnxruntime_providers_vitisai PROPERTIES FOLDER "ONNXRuntime") @@ -778,7 +792,7 @@ if (onnxruntime_USE_OPENVINO) endif() add_dependencies(onnxruntime_providers_openvino onnxruntime_providers_shared ${onnxruntime_EXTERNAL_DEPENDENCIES}) target_include_directories(onnxruntime_providers_openvino SYSTEM PUBLIC ${ONNXRUNTIME_ROOT} ${CMAKE_CURRENT_BINARY_DIR} ${eigen_INCLUDE_DIRS} ${OpenVINO_INCLUDE_DIR} ${OPENVINO_INCLUDE_DIR_LIST} ${PYTHON_INCLUDE_DIRS} $ENV{OPENCL_INCS}) - target_link_libraries(onnxruntime_providers_openvino ${ONNXRUNTIME_PROVIDERS_SHARED} ${OPENVINO_LIB_LIST} ${ABSEIL_LIBS}) + target_link_libraries(onnxruntime_providers_openvino ${ONNXRUNTIME_PROVIDERS_SHARED} Boost::mp11 ${OPENVINO_LIB_LIST} ${ABSEIL_LIBS}) target_compile_definitions(onnxruntime_providers_openvino PRIVATE VER_MAJOR=${VERSION_MAJOR_PART}) target_compile_definitions(onnxruntime_providers_openvino PRIVATE VER_MINOR=${VERSION_MINOR_PART}) @@ -896,14 +910,15 @@ if (onnxruntime_USE_COREML) ${onnxruntime_providers_coreml_cc_srcs} ${onnxruntime_providers_coreml_objcc_srcs} ) onnxruntime_add_include_to_target(onnxruntime_providers_coreml - onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers + onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers Boost::mp11 safeint_interface ) if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS") onnxruntime_add_include_to_target(onnxruntime_providers_coreml onnxruntime_coreml_proto) target_link_libraries(onnxruntime_providers_coreml PRIVATE onnxruntime_coreml_proto "-framework Foundation" "-framework CoreML") add_dependencies(onnxruntime_providers_coreml onnxruntime_coreml_proto) endif() - add_dependencies(onnxruntime_providers_coreml onnx ${onnxruntime_EXTERNAL_DEPENDENCIES}) + add_dependencies(onnxruntime_providers_coreml ${onnxruntime_EXTERNAL_DEPENDENCIES}) + set_target_properties(onnxruntime_providers_coreml PROPERTIES CXX_STANDARD_REQUIRED ON) set_target_properties(onnxruntime_providers_coreml PROPERTIES FOLDER "ONNXRuntime") target_include_directories(onnxruntime_providers_coreml PRIVATE ${ONNXRUNTIME_ROOT} ${coreml_INCLUDE_DIRS}) @@ -980,7 +995,7 @@ if (onnxruntime_USE_NNAPI_BUILTIN) source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_nnapi_cc_srcs}) onnxruntime_add_static_library(onnxruntime_providers_nnapi ${onnxruntime_providers_nnapi_cc_srcs}) onnxruntime_add_include_to_target(onnxruntime_providers_nnapi - onnxruntime_common onnxruntime_framework onnx onnx_proto protobuf::libprotobuf-lite flatbuffers + onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers Boost::mp11 safeint_interface ) target_link_libraries(onnxruntime_providers_nnapi) add_dependencies(onnxruntime_providers_nnapi onnx ${onnxruntime_EXTERNAL_DEPENDENCIES}) @@ -1026,7 +1041,7 @@ if (onnxruntime_USE_RKNPU) source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_rknpu_cc_srcs}) onnxruntime_add_static_library(onnxruntime_providers_rknpu ${onnxruntime_providers_rknpu_cc_srcs}) onnxruntime_add_include_to_target(onnxruntime_providers_rknpu - onnxruntime_common onnxruntime_framework onnx onnx_proto protobuf::libprotobuf-lite flatbuffers + onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers Boost::mp11 safeint_interface ) target_link_libraries(onnxruntime_providers_rknpu PRIVATE -lrknpu_ddk) add_dependencies(onnxruntime_providers_rknpu onnx ${onnxruntime_EXTERNAL_DEPENDENCIES}) @@ -1055,11 +1070,11 @@ if (onnxruntime_USE_DML) source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_dml_cc_srcs}) onnxruntime_add_static_library(onnxruntime_providers_dml ${onnxruntime_providers_dml_cc_srcs}) onnxruntime_add_include_to_target(onnxruntime_providers_dml - onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers + onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers Boost::mp11 safeint_interface WIL::WIL ) add_dependencies(onnxruntime_providers_dml ${onnxruntime_EXTERNAL_DEPENDENCIES}) target_include_directories(onnxruntime_providers_dml PRIVATE - ${ONNXRUNTIME_ROOT} ${ONNXRUNTIME_ROOT}/../cmake/external/wil/include + ${ONNXRUNTIME_ROOT} ) add_definitions(-DDML_TARGET_VERSION_USE_LATEST=1) @@ -1138,9 +1153,11 @@ if (onnxruntime_USE_MIGRAPHX) set(BUILD_LIBRARY_ONLY 1) add_definitions("-DONNX_ML=1") add_definitions("-DONNX_NAMESPACE=onnx") + # TODO: Remove the next line so that we can delete the git submodule include_directories(${PROJECT_SOURCE_DIR}/external/protobuf ${PROJECT_SOURCE_DIR}/external/eigen) set(MIGRAPHX_ROOT ${onnxruntime_MIGRAPHX_HOME}) - include_directories(${ONNXRUNTIME_ROOT}/../cmake/external/onnx) + # TODO: Remove the next line so that we can delete the git submodule + include_directories(${PROJECT_SOURCE_DIR}/external/onnx) set(OLD_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) if ( CMAKE_COMPILER_IS_GNUCC ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-missing-field-initializers") @@ -1167,9 +1184,9 @@ if (onnxruntime_USE_MIGRAPHX) ) source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_migraphx_cc_srcs}) onnxruntime_add_shared_library_module(onnxruntime_providers_migraphx ${onnxruntime_providers_migraphx_cc_srcs}) - onnxruntime_add_include_to_target(onnxruntime_providers_migraphx onnxruntime_common onnx flatbuffers) + onnxruntime_add_include_to_target(onnxruntime_providers_migraphx onnxruntime_common onnx flatbuffers Boost::mp11 safeint_interface) add_dependencies(onnxruntime_providers_migraphx onnxruntime_providers_shared ${onnxruntime_EXTERNAL_DEPENDENCIES}) - target_link_libraries(onnxruntime_providers_migraphx PRIVATE ${migraphx_libs} ${ONNXRUNTIME_PROVIDERS_SHARED} onnx flatbuffers) + target_link_libraries(onnxruntime_providers_migraphx PRIVATE ${migraphx_libs} ${ONNXRUNTIME_PROVIDERS_SHARED} onnx flatbuffers Boost::mp11 safeint_interface) target_include_directories(onnxruntime_providers_migraphx PRIVATE ${ONNXRUNTIME_ROOT} ${CMAKE_CURRENT_BINARY_DIR}) install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/providers/migraphx DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/providers) set_target_properties(onnxruntime_providers_migraphx PROPERTIES LINKER_LANGUAGE CXX) @@ -1206,8 +1223,9 @@ if (onnxruntime_USE_ACL) source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_acl_cc_srcs}) onnxruntime_add_static_library(onnxruntime_providers_acl ${onnxruntime_providers_acl_cc_srcs}) onnxruntime_add_include_to_target(onnxruntime_providers_acl - onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers + onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers Boost::mp11 safeint_interface ) + target_link_libraries(onnxruntime_providers_acl -L$ENV{LD_LIBRARY_PATH}) add_dependencies(onnxruntime_providers_acl ${onnxruntime_EXTERNAL_DEPENDENCIES}) set_target_properties(onnxruntime_providers_acl PROPERTIES FOLDER "ONNXRuntime") @@ -1239,8 +1257,9 @@ if (onnxruntime_USE_ARMNN) source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_armnn_cc_srcs}) onnxruntime_add_static_library(onnxruntime_providers_armnn ${onnxruntime_providers_armnn_cc_srcs}) onnxruntime_add_include_to_target(onnxruntime_providers_armnn - onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers + onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers Boost::mp11 safeint_interface ) + add_dependencies(onnxruntime_providers_armnn ${onnxruntime_EXTERNAL_DEPENDENCIES}) set_target_properties(onnxruntime_providers_armnn PROPERTIES FOLDER "ONNXRuntime") target_include_directories(onnxruntime_providers_armnn PRIVATE @@ -1350,7 +1369,7 @@ if (onnxruntime_USE_ROCM) target_compile_options(onnxruntime_providers_rocm PRIVATE -Wno-undefined-var-template) endif() - onnxruntime_add_include_to_target(onnxruntime_providers_rocm onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers) + onnxruntime_add_include_to_target(onnxruntime_providers_rocm onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers Boost::mp11 safeint_interface) if (onnxruntime_ENABLE_TRAINING OR onnxruntime_ENABLE_TRAINING_OPS) onnxruntime_add_include_to_target(onnxruntime_providers_rocm onnxruntime_training) target_link_libraries(onnxruntime_providers_rocm PRIVATE onnxruntime_training) @@ -1379,6 +1398,7 @@ if (onnxruntime_USE_ROCM) ${onnxruntime_ROCM_HOME}/include ${onnxruntime_ROCM_HOME}/include/roctracer) install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/providers/rocm DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/providers) + set_target_properties(onnxruntime_providers_rocm PROPERTIES LINKER_LANGUAGE CXX) set_target_properties(onnxruntime_providers_rocm PROPERTIES FOLDER "ONNXRuntime") @@ -1444,16 +1464,10 @@ if (onnxruntime_USE_TVM) target_include_directories(onnxruntime_providers_tvm PRIVATE ${TVM_INCLUDES} ${PYTHON_INLCUDE_DIRS}) - onnxruntime_add_include_to_target(onnxruntime_providers_tvm onnxruntime_common onnx tvm) + onnxruntime_add_include_to_target(onnxruntime_providers_tvm onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers Boost::mp11 safeint_interface) add_dependencies(onnxruntime_providers_tvm ${onnxruntime_EXTERNAL_DEPENDENCIES}) - target_link_libraries(onnxruntime_providers_tvm PRIVATE - onnx - tvm - onnxruntime_common - onnxruntime_framework - ) if (onnxruntime_TVM_USE_HASH) add_dependencies(onnxruntime_providers_tvm ippcp_s) target_include_directories(onnxruntime_providers_tvm PRIVATE ${IPP_CRYPTO_INCLUDE_DIR}) @@ -1467,6 +1481,7 @@ if (onnxruntime_USE_TVM) # wd4100: identifier' : unreferenced formal parameter # wd4127: conditional expression is constant # wd4244: conversion from 'int' to 'char', possible loss of data + # TODO: 4244 should not be disabled target_compile_options(onnxruntime_providers_tvm PRIVATE "/wd4100" "/wd4127" "/wd4244") else() target_compile_options(onnxruntime_providers_tvm PRIVATE "-Wno-error=type-limits") @@ -1499,7 +1514,7 @@ if (onnxruntime_USE_XNNPACK) source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_providers_xnnpack_cc_srcs}) onnxruntime_add_static_library(onnxruntime_providers_xnnpack ${onnxruntime_providers_xnnpack_cc_srcs}) onnxruntime_add_include_to_target(onnxruntime_providers_xnnpack - onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} XNNPACK pthreadpool + onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} XNNPACK pthreadpool Boost::mp11 safeint_interface ) add_dependencies(onnxruntime_providers_xnnpack onnx ${onnxruntime_EXTERNAL_DEPENDENCIES}) diff --git a/cmake/onnxruntime_pyop.cmake b/cmake/onnxruntime_pyop.cmake index 5f663cbde9..fb6f6fca79 100644 --- a/cmake/onnxruntime_pyop.cmake +++ b/cmake/onnxruntime_pyop.cmake @@ -1,9 +1,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -file(GLOB onnxruntime_pyop_srcs "${ONNXRUNTIME_ROOT}/core/language_interop_ops/pyop/pyop.cc") -onnxruntime_add_static_library(onnxruntime_pyop ${onnxruntime_pyop_srcs}) -add_dependencies(onnxruntime_pyop onnxruntime_graph) -onnxruntime_add_include_to_target(onnxruntime_pyop onnxruntime_common onnxruntime_graph onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers) +onnxruntime_add_static_library(onnxruntime_pyop "${ONNXRUNTIME_ROOT}/core/language_interop_ops/pyop/pyop.cc") +add_dependencies(onnxruntime_pyop ${onnxruntime_EXTERNAL_DEPENDENCIES}) +onnxruntime_add_include_to_target(onnxruntime_pyop onnxruntime_common onnxruntime_graph onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers ${GSL_TARGET} Boost::mp11) target_include_directories(onnxruntime_pyop PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS}) onnxruntime_add_include_to_target(onnxruntime_pyop Python::Module Python::NumPy) if (TARGET Python::Python) diff --git a/cmake/onnxruntime_python.cmake b/cmake/onnxruntime_python.cmake index ee41f7fe46..8735b8e2f1 100644 --- a/cmake/onnxruntime_python.cmake +++ b/cmake/onnxruntime_python.cmake @@ -138,7 +138,7 @@ endif() if (onnxruntime_ENABLE_ATEN) target_compile_definitions(onnxruntime_pybind11_state PRIVATE ENABLE_ATEN) - target_include_directories(onnxruntime_pybind11_state PRIVATE ${PROJECT_SOURCE_DIR}/external/dlpack/include) + target_include_directories(onnxruntime_pybind11_state PRIVATE ${dlpack_SOURCE_DIR}/include) endif() if (onnxruntime_ENABLE_TRAINING) diff --git a/cmake/onnxruntime_session.cmake b/cmake/onnxruntime_session.cmake index de285dc8e3..cdd853465d 100644 --- a/cmake/onnxruntime_session.cmake +++ b/cmake/onnxruntime_session.cmake @@ -28,7 +28,7 @@ source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_session_srcs}) onnxruntime_add_static_library(onnxruntime_session ${onnxruntime_session_srcs}) install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/session DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core) -onnxruntime_add_include_to_target(onnxruntime_session onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers) +onnxruntime_add_include_to_target(onnxruntime_session onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers Boost::mp11 safeint_interface nlohmann_json::nlohmann_json) if(onnxruntime_ENABLE_INSTRUMENT) target_compile_definitions(onnxruntime_session PUBLIC ONNXRUNTIME_ENABLE_INSTRUMENT) endif() @@ -37,7 +37,6 @@ if(NOT MSVC) set_source_files_properties(${ONNXRUNTIME_ROOT}/core/session/environment.cc PROPERTIES COMPILE_FLAGS "-Wno-parentheses") endif() target_include_directories(onnxruntime_session PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS}) -target_link_libraries(onnxruntime_session PRIVATE nlohmann_json::nlohmann_json) if (onnxruntime_USE_EXTENSIONS) target_link_libraries(onnxruntime_session PRIVATE onnxruntime_extensions) endif() diff --git a/cmake/onnxruntime_training.cmake b/cmake/onnxruntime_training.cmake index 7b61779d6a..dc95ca0e19 100644 --- a/cmake/onnxruntime_training.cmake +++ b/cmake/onnxruntime_training.cmake @@ -1,7 +1,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -set (CXXOPTS ${PROJECT_SOURCE_DIR}/external/cxxopts/include) +set (CXXOPTS ${cxxopts_SOURCE_DIR}/include) # training lib file(GLOB_RECURSE onnxruntime_training_srcs @@ -28,14 +28,14 @@ list(REMOVE_ITEM onnxruntime_training_srcs ${onnxruntime_training_framework_excl onnxruntime_add_static_library(onnxruntime_training ${onnxruntime_training_srcs}) add_dependencies(onnxruntime_training onnx tensorboard ${onnxruntime_EXTERNAL_DEPENDENCIES}) -onnxruntime_add_include_to_target(onnxruntime_training onnxruntime_common onnx onnx_proto tensorboard ${PROTOBUF_LIB} flatbuffers) +onnxruntime_add_include_to_target(onnxruntime_training onnxruntime_common onnx onnx_proto tensorboard ${PROTOBUF_LIB} flatbuffers re2::re2 Boost::mp11 safeint_interface) # fix event_writer.cc 4100 warning if(WIN32) target_compile_options(onnxruntime_training PRIVATE /wd4100) endif() -target_include_directories(onnxruntime_training PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT} ${ORTTRAINING_ROOT} ${eigen_INCLUDE_DIRS} ${RE2_INCLUDE_DIR} PUBLIC ${onnxruntime_graph_header} ${MPI_CXX_INCLUDE_DIRS}) +target_include_directories(onnxruntime_training PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT} ${ORTTRAINING_ROOT} ${eigen_INCLUDE_DIRS} PUBLIC ${onnxruntime_graph_header} ${MPI_CXX_INCLUDE_DIRS}) if (onnxruntime_USE_CUDA) target_include_directories(onnxruntime_training PRIVATE ${onnxruntime_CUDNN_HOME}/include ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) @@ -75,7 +75,7 @@ if (onnxruntime_BUILD_UNIT_TESTS) target_link_libraries(onnxruntime_training_runner PRIVATE Python::Python) endif() - onnxruntime_add_include_to_target(onnxruntime_training_runner onnxruntime_training onnxruntime_framework onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} onnxruntime_training flatbuffers) + onnxruntime_add_include_to_target(onnxruntime_training_runner onnxruntime_training onnxruntime_framework onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} onnxruntime_training flatbuffers Boost::mp11 safeint_interface) target_include_directories(onnxruntime_training_runner PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT} ${ORTTRAINING_ROOT} ${eigen_INCLUDE_DIRS} PUBLIC ${onnxruntime_graph_header}) target_link_libraries(onnxruntime_training_runner PRIVATE nlohmann_json::nlohmann_json) @@ -113,7 +113,7 @@ if (onnxruntime_BUILD_UNIT_TESTS) "${ORTTRAINING_SOURCE_DIR}/models/mnist/main.cc" ) onnxruntime_add_executable(onnxruntime_training_mnist ${training_mnist_src}) - onnxruntime_add_include_to_target(onnxruntime_training_mnist onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} onnxruntime_training flatbuffers) + onnxruntime_add_include_to_target(onnxruntime_training_mnist onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} onnxruntime_training flatbuffers Boost::mp11 safeint_interface) target_include_directories(onnxruntime_training_mnist PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT} ${ORTTRAINING_ROOT} ${eigen_INCLUDE_DIRS} ${CXXOPTS} ${extra_includes} ${onnxruntime_graph_header} ${onnxruntime_exec_src_dir} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/onnx onnxruntime_training_runner) set(ONNXRUNTIME_LIBS @@ -136,6 +136,7 @@ if (onnxruntime_BUILD_UNIT_TESTS) ${ONNXRUNTIME_MLAS_LIBS} onnxruntime_common onnxruntime_flatbuffers + Boost::mp11 safeint_interface ) if (onnxruntime_ENABLE_LANGUAGE_INTEROP_OPS) @@ -158,7 +159,7 @@ if (onnxruntime_BUILD_UNIT_TESTS) "${ORTTRAINING_SOURCE_DIR}/models/squeezenet/*.cc" ) onnxruntime_add_executable(onnxruntime_training_squeezenet ${training_squeezene_src}) - onnxruntime_add_include_to_target(onnxruntime_training_squeezenet onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} onnxruntime_training flatbuffers) + onnxruntime_add_include_to_target(onnxruntime_training_squeezenet onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} onnxruntime_training flatbuffers Boost::mp11 safeint_interface) target_include_directories(onnxruntime_training_squeezenet PUBLIC ${ONNXRUNTIME_ROOT} ${ORTTRAINING_ROOT} ${eigen_INCLUDE_DIRS} ${extra_includes} ${onnxruntime_graph_header} ${onnxruntime_exec_src_dir} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/onnx onnxruntime_training_runner) if(UNIX AND NOT APPLE) @@ -181,7 +182,7 @@ if (onnxruntime_BUILD_UNIT_TESTS) endif() endif() - onnxruntime_add_include_to_target(onnxruntime_training_bert onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} onnxruntime_training flatbuffers) + onnxruntime_add_include_to_target(onnxruntime_training_bert onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} onnxruntime_training flatbuffers Boost::mp11 safeint_interface) target_include_directories(onnxruntime_training_bert PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT} ${ORTTRAINING_ROOT} ${MPI_CXX_INCLUDE_DIRS} ${eigen_INCLUDE_DIRS} ${CXXOPTS} ${extra_includes} ${onnxruntime_graph_header} ${onnxruntime_exec_src_dir} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/onnx onnxruntime_training_runner) # ROCM provider sources are generated, need to add include directory for generated headers @@ -205,7 +206,7 @@ if (onnxruntime_BUILD_UNIT_TESTS) endif() endif() - onnxruntime_add_include_to_target(onnxruntime_training_pipeline_poc onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} onnxruntime_training flatbuffers) + onnxruntime_add_include_to_target(onnxruntime_training_pipeline_poc onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} onnxruntime_training flatbuffers Boost::mp11 safeint_interface) target_include_directories(onnxruntime_training_pipeline_poc PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT} ${ORTTRAINING_ROOT} ${MPI_CXX_INCLUDE_DIRS} ${eigen_INCLUDE_DIRS} ${CXXOPTS} ${extra_includes} ${onnxruntime_graph_header} ${onnxruntime_exec_src_dir} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/onnx onnxruntime_training_runner) if (onnxruntime_USE_NCCL) target_include_directories(onnxruntime_training_pipeline_poc PRIVATE ${NCCL_INCLUDE_DIRS}) @@ -226,7 +227,6 @@ if (onnxruntime_BUILD_UNIT_TESTS) endif() endif() - onnxruntime_add_include_to_target(onnxruntime_training_gpt2 onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} onnxruntime_training flatbuffers) target_include_directories(onnxruntime_training_gpt2 PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT} ${ORTTRAINING_ROOT} ${MPI_CXX_INCLUDE_DIRS} ${eigen_INCLUDE_DIRS} ${CXXOPTS} ${extra_includes} ${onnxruntime_graph_header} ${onnxruntime_exec_src_dir} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/onnx onnxruntime_training_runner) target_link_libraries(onnxruntime_training_gpt2 PRIVATE onnxruntime_training_runner onnxruntime_training ${ONNXRUNTIME_LIBS} ${onnxruntime_EXTERNAL_LIBRARIES}) diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake index ffb52bf9bb..43e79a2dd6 100644 --- a/cmake/onnxruntime_unittests.cmake +++ b/cmake/onnxruntime_unittests.cmake @@ -125,7 +125,7 @@ function(AddTest) ${TEST_SRC_DIR}/xctest/ortxctest.m ${TEST_SRC_DIR}/xctest/xcgtest.mm ${_UT_SOURCES}) - + onnxruntime_configure_target(${_UT_TARGET}_xc) if(_UT_DYN) target_link_libraries(${_UT_TARGET}_xc PRIVATE ${_UT_LIBS} GTest::gtest GTest::gmock onnxruntime ${CMAKE_DL_LIBS} Threads::Threads) @@ -596,7 +596,9 @@ file(GLOB onnxruntime_test_framework_src CONFIGURE_DEPENDS ${onnxruntime_test_framework_src_patterns} ) -#without auto initialize onnxruntime +#This is a small wrapper library that shouldn't use any onnxruntime internal symbols(except onnxruntime_common). +#Because it could dynamically link to onnxruntime. Otherwise you will have two copies of onnxruntime in the same +#process and you won't know which one you are testing. onnxruntime_add_static_library(onnxruntime_test_utils ${onnxruntime_test_utils_src}) if(MSVC) target_compile_options(onnxruntime_test_utils PRIVATE "$<$:SHELL:--compiler-options /utf-8>" @@ -606,7 +608,7 @@ if(MSVC) else() target_compile_definitions(onnxruntime_test_utils PUBLIC -DNSYNC_ATOMIC_CPP11) target_include_directories(onnxruntime_test_utils PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT} - "${CMAKE_CURRENT_SOURCE_DIR}/external/nsync/public") + ${nsync_SOURCE_DIR}/public) endif() if (onnxruntime_USE_NCCL) target_include_directories(onnxruntime_test_utils PRIVATE ${NCCL_INCLUDE_DIRS}) @@ -614,7 +616,8 @@ endif() if (onnxruntime_USE_ROCM) target_include_directories(onnxruntime_test_utils PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/amdgpu/onnxruntime ${CMAKE_CURRENT_BINARY_DIR}/amdgpu/orttraining) endif() -onnxruntime_add_include_to_target(onnxruntime_test_utils onnxruntime_common onnxruntime_framework onnxruntime_session GTest::gtest GTest::gmock onnx onnx_proto flatbuffers) +onnxruntime_add_include_to_target(onnxruntime_test_utils onnxruntime_common onnxruntime_framework onnxruntime_session GTest::gtest GTest::gmock onnx onnx_proto flatbuffers nlohmann_json::nlohmann_json Boost::mp11 safeint_interface) + if (onnxruntime_USE_DML) @@ -639,17 +642,17 @@ if(MSVC) else() target_compile_definitions(onnx_test_runner_common PUBLIC -DNSYNC_ATOMIC_CPP11) target_include_directories(onnx_test_runner_common PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT} - "${CMAKE_CURRENT_SOURCE_DIR}/external/nsync/public") + ${nsync_SOURCE_DIR}/public) endif() if (MSVC AND NOT CMAKE_SIZEOF_VOID_P EQUAL 8) #TODO: fix the warnings, they are dangerous target_compile_options(onnx_test_runner_common PRIVATE "/wd4244") endif() onnxruntime_add_include_to_target(onnx_test_runner_common onnxruntime_common onnxruntime_framework - onnxruntime_test_utils onnx onnx_proto re2::re2 flatbuffers) + onnxruntime_test_utils onnx onnx_proto re2::re2 flatbuffers Boost::mp11 safeint_interface) add_dependencies(onnx_test_runner_common onnx_test_data_proto ${onnxruntime_EXTERNAL_DEPENDENCIES}) -target_include_directories(onnx_test_runner_common PRIVATE ${eigen_INCLUDE_DIRS} ${RE2_INCLUDE_DIR} +target_include_directories(onnx_test_runner_common PRIVATE ${eigen_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT}) set_target_properties(onnx_test_runner_common PROPERTIES FOLDER "ONNXRuntimeTest") @@ -719,7 +722,7 @@ AddTest( SOURCES ${all_tests} ${onnxruntime_unittest_main_src} LIBS onnx_test_runner_common ${onnxruntime_test_providers_libs} ${onnxruntime_test_common_libs} - onnx_test_data_proto nlohmann_json::nlohmann_json + onnx_test_data_proto DEPENDS ${all_dependencies} TEST_ARGS ${test_all_args} ) @@ -781,7 +784,7 @@ endif() onnxruntime_add_include_to_target(onnx_test_data_proto onnx_proto) target_include_directories(onnx_test_data_proto PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) set_target_properties(onnx_test_data_proto PROPERTIES FOLDER "ONNXRuntimeTest") -onnxruntime_protobuf_generate(APPEND_PATH IMPORT_DIRS external/onnx TARGET onnx_test_data_proto) +onnxruntime_protobuf_generate(APPEND_PATH IMPORT_DIRS ${onnx_SOURCE_DIR} TARGET onnx_test_data_proto) # # onnxruntime_ir_graph test data @@ -953,6 +956,9 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP) else() target_link_libraries(onnxruntime_mlas_benchmark PRIVATE nsync_cpp ${CMAKE_DL_LIBS}) endif() + if (CPUINFO_SUPPORTED AND NOT onnxruntime_BUILD_WEBASSEMBLY) + target_link_libraries(onnxruntime_mlas_benchmark PRIVATE cpuinfo) + endif() set_target_properties(onnxruntime_mlas_benchmark PROPERTIES FOLDER "ONNXRuntimeTest") endif() @@ -962,9 +968,9 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP) if (NOT onnxruntime_REDUCED_OPS_BUILD AND NOT onnxruntime_BUILD_WEBASSEMBLY) add_test(NAME onnx_test_pytorch_converted - COMMAND onnx_test_runner ${PROJECT_SOURCE_DIR}/external/onnx/onnx/backend/test/data/pytorch-converted) + COMMAND onnx_test_runner ${onnx_SOURCE_DIR}/onnx/backend/test/data/pytorch-converted) add_test(NAME onnx_test_pytorch_operator - COMMAND onnx_test_runner ${PROJECT_SOURCE_DIR}/external/onnx/onnx/backend/test/data/pytorch-operator) + COMMAND onnx_test_runner ${onnx_SOURCE_DIR}/onnx/backend/test/data/pytorch-operator) endif() if (CMAKE_SYSTEM_NAME STREQUAL "Android") @@ -977,7 +983,7 @@ if(onnxruntime_ENABLE_EAGER_MODE) file(GLOB onnxruntime_eager_mode_test_src CONFIGURE_DEPENDS "${TEST_SRC_DIR}/eager/*.cc" ) - add_executable(onnxruntime_eager_mode_test ${onnxruntime_eager_mode_test_src}) + onnxruntime_add_executable(onnxruntime_eager_mode_test ${onnxruntime_eager_mode_test_src}) target_include_directories(onnxruntime_eager_mode_test PRIVATE ${ONNXRUNTIME_ROOT} ${onnxruntime_graph_header} ${onnxruntime_exec_src_dir} @@ -1058,9 +1064,11 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP) endif() if (onnxruntime_BUILD_SHARED_LIB) + #It will dynamically link to onnxruntime. So please don't add onxruntime_graph/onxruntime_framework/... here. + #onnxruntime_common is kind of ok because it is thin, tiny and totally stateless. set(onnxruntime_perf_test_libs onnx_test_runner_common onnxruntime_test_utils onnxruntime_common - onnxruntime onnxruntime_flatbuffers onnx_test_data_proto + onnxruntime onnxruntime_flatbuffers onnx_test_data_proto ${onnxruntime_EXTERNAL_LIBRARIES} ${GETOPT_LIB_WIDE} ${SYS_PATH_LIB} ${CMAKE_DL_LIBS}) if(NOT WIN32) @@ -1222,21 +1230,25 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP) endif() target_include_directories(onnxruntime_mlas_test PRIVATE ${ONNXRUNTIME_ROOT}/core/mlas/inc ${ONNXRUNTIME_ROOT} ${CMAKE_CURRENT_BINARY_DIR}) - set(onnxruntime_mlas_test_libs GTest::gtest GTest::gmock ${ONNXRUNTIME_MLAS_LIBS} onnxruntime_common) + target_link_libraries(onnxruntime_mlas_test PRIVATE GTest::gtest GTest::gmock ${ONNXRUNTIME_MLAS_LIBS} onnxruntime_common) + if (CPUINFO_SUPPORTED AND NOT onnxruntime_BUILD_WEBASSEMBLY) + target_link_libraries(onnxruntime_mlas_test PRIVATE cpuinfo) + endif() if(NOT WIN32) - list(APPEND onnxruntime_mlas_test_libs nsync_cpp ${CMAKE_DL_LIBS}) + target_link_libraries(onnxruntime_mlas_test PRIVATE nsync_cpp ${CMAKE_DL_LIBS}) endif() if (CMAKE_SYSTEM_NAME STREQUAL "Android") - list(APPEND onnxruntime_mlas_test_libs ${android_shared_libs}) - endif() - list(APPEND onnxruntime_mlas_test_libs Threads::Threads) - target_link_libraries(onnxruntime_mlas_test PRIVATE ${onnxruntime_mlas_test_libs}) + target_link_libraries(onnxruntime_mlas_test PRIVATE ${android_shared_libs}) + endif() + if(WIN32) target_link_libraries(onnxruntime_mlas_test PRIVATE debug Dbghelp Advapi32) endif() if (onnxruntime_LINK_LIBATOMIC) target_link_libraries(onnxruntime_mlas_test PRIVATE atomic) endif() + target_link_libraries(onnxruntime_mlas_test PRIVATE Threads::Threads) + set_target_properties(onnxruntime_mlas_test PROPERTIES FOLDER "ONNXRuntimeTest") if (onnxruntime_BUILD_WEBASSEMBLY) if (onnxruntime_ENABLE_WEBASSEMBLY_THREADS) @@ -1247,6 +1259,7 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP) endif() endif() +if (NOT onnxruntime_BUILD_WEBASSEMBLY) if (onnxruntime_USE_CUDA) onnxruntime_add_shared_library_module(custom_op_library ${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/cuda_ops.cu ${TEST_SRC_DIR}/testdata/custom_op_library/custom_op_library.cc) @@ -1306,7 +1319,7 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP) set_property(TEST onnxruntime4j_test APPEND PROPERTY DEPENDS onnxruntime4j_jni) endif() endif() - +endif() # limit to only test on windows first, due to a runtime path issue on linux if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS" @@ -1322,7 +1335,7 @@ if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD onnxruntime_add_shared_library_module(test_execution_provider ${test_execution_provider_srcs}) add_dependencies(test_execution_provider onnxruntime_providers_shared onnx ${ABSEIL_LIBS}) - target_link_libraries(test_execution_provider PRIVATE onnxruntime_providers_shared ${ABSEIL_LIBS}) + target_link_libraries(test_execution_provider PRIVATE onnxruntime_providers_shared ${ABSEIL_LIBS} Boost::mp11) target_include_directories(test_execution_provider PRIVATE $) target_include_directories(test_execution_provider PRIVATE $) target_include_directories(test_execution_provider PRIVATE ${ONNXRUNTIME_ROOT} ${CMAKE_CURRENT_BINARY_DIR} ${ORTTRAINING_ROOT}) diff --git a/cmake/onnxruntime_util.cmake b/cmake/onnxruntime_util.cmake index 87292eb244..ae7e842f22 100644 --- a/cmake/onnxruntime_util.cmake +++ b/cmake/onnxruntime_util.cmake @@ -10,7 +10,7 @@ source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_util_srcs}) onnxruntime_add_static_library(onnxruntime_util ${onnxruntime_util_srcs}) target_include_directories(onnxruntime_util PRIVATE ${ONNXRUNTIME_ROOT} PUBLIC ${eigen_INCLUDE_DIRS}) -onnxruntime_add_include_to_target(onnxruntime_util onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB}) +onnxruntime_add_include_to_target(onnxruntime_util onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} Boost::mp11) if(UNIX) target_compile_options(onnxruntime_util PUBLIC "-Wno-error=comment") endif() diff --git a/cmake/tensorboard/CMakeLists.txt b/cmake/tensorboard/CMakeLists.txt index 0cc7098c28..81ce0261b1 100644 --- a/cmake/tensorboard/CMakeLists.txt +++ b/cmake/tensorboard/CMakeLists.txt @@ -1,54 +1 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -set(TENSORBOARD_ROOT ${PROJECT_SOURCE_DIR}/external/tensorboard) - -# tensorboard protos -file(GLOB_RECURSE tensorboard_proto_srcs CONFIGURE_DEPENDS - "${TENSORBOARD_ROOT}/tensorboard/compat/proto/*.proto" -) - -if(EXISTS "${ONNX_CUSTOM_PROTOC_EXECUTABLE}") - set(PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE}) -else() - set(PROTOC_EXECUTABLE $) - set(PROTOC_DEPS protobuf::protoc) -endif() -if(NOT onnxruntime_USE_FULL_PROTOBUF) - set(PROTOC_PROTOBUF_ARG "lite:") -endif() - -# tensorboard generated files -foreach(_proto ${tensorboard_proto_srcs}) - get_filename_component(_abs_file ${_proto} ABSOLUTE) - get_filename_component(_basename ${_proto} NAME_WE) - set(_tensorboard_cpp_srcs - "${CMAKE_CURRENT_BINARY_DIR}/tensorboard/compat/proto/${_basename}.pb.cc" - "${CMAKE_CURRENT_BINARY_DIR}/tensorboard/compat/proto/${_basename}.pb.h" - ) - add_custom_command( - OUTPUT ${_tensorboard_cpp_srcs} - COMMAND ${PROTOC_EXECUTABLE} - ARGS --cpp_out ${PROTOC_PROTOBUF_ARG}${CMAKE_CURRENT_BINARY_DIR} -I ${TENSORBOARD_ROOT} -I ${REPO_ROOT}/cmake/external/protobuf/src ${_abs_file} - DEPENDS ${_abs_file} ${PROTOC_DEPS} - COMMENT "Running cpp protocol buffer compiler on ${_proto}" - VERBATIM ) - list(APPEND tensorboard_cpp_srcs ${_tensorboard_cpp_srcs}) -endforeach() - -onnxruntime_add_static_library(tensorboard ${tensorboard_cpp_srcs}) -target_include_directories(tensorboard PUBLIC $ "${CMAKE_CURRENT_BINARY_DIR}") -target_compile_definitions(tensorboard PUBLIC $) - -if(WIN32) - target_compile_options(tensorboard PRIVATE /wd4100 /wd4125 /wd4127 /wd4996 /wd4244 /wd4267 /wd4309) - set_target_properties(tensorboard PROPERTIES FOLDER "External/tensorboard") -else() - target_compile_options(tensorboard PRIVATE "-Wno-unused-parameter") - if(HAS_UNUSED_BUT_SET_VARIABLE) - target_compile_options(tensorboard PRIVATE "-Wno-unused-but-set-variable") - endif() - target_compile_options(tensorboard PRIVATE "-Wno-unused-variable") - target_compile_options(tensorboard PRIVATE "-Wno-deprecated-declarations") -endif() - +add_subdirectory(compat/proto) diff --git a/cmake/tensorboard/compat/proto/CMakeLists.txt b/cmake/tensorboard/compat/proto/CMakeLists.txt new file mode 100644 index 0000000000..ad31e4062a --- /dev/null +++ b/cmake/tensorboard/compat/proto/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +FetchContent_Declare( + tensorboard + URL ${DEP_URL_tensorboard} + URL_HASH SHA1=${DEP_SHA1_tensorboard} +) +FetchContent_MakeAvailable(tensorboard) + +set(TENSORBOARD_ROOT ${tensorboard_SOURCE_DIR}) + +# tensorboard protos +file(GLOB_RECURSE tensorboard_proto_srcs CONFIGURE_DEPENDS + "${TENSORBOARD_ROOT}/tensorboard/compat/proto/*.proto" +) + +add_library(tensorboard STATIC ${tensorboard_proto_srcs}) +onnxruntime_protobuf_generate(APPEND_PATH IMPORT_DIRS ${tensorboard_SOURCE_DIR} ${protobuf_SOURCE_DIR}/src TARGET tensorboard) +onnxruntime_add_include_to_target(tensorboard ${PROTOBUF_LIB}) +target_include_directories(tensorboard PRIVATE ${PROJECT_BINARY_DIR}) +add_dependencies(tensorboard ${onnxruntime_EXTERNAL_DEPENDENCIES}) +if(WIN32) + target_compile_options(tensorboard PRIVATE "/wd4100" "/wd4125" "/wd4127" "/wd4267" "/wd4456" "/wd4800" "/wd6011" "/wd6387" "/wd28182") +endif() diff --git a/cmake/wil.cmake b/cmake/wil.cmake deleted file mode 100644 index 36a8bc9d3c..0000000000 --- a/cmake/wil.cmake +++ /dev/null @@ -1,5 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -add_library(wil INTERFACE) -target_include_directories(wil INTERFACE external/wil/include/) \ No newline at end of file diff --git a/cmake/winml.cmake b/cmake/winml.cmake index 798bd1af2e..b66ba088e4 100644 --- a/cmake/winml.cmake +++ b/cmake/winml.cmake @@ -202,7 +202,7 @@ add_dependencies(winml_lib_telemetry winml_api_native) add_dependencies(winml_lib_telemetry winml_api_native_internal) # Link libraries -target_link_libraries(winml_lib_telemetry PRIVATE wil) +target_link_libraries(winml_lib_telemetry PRIVATE WIL::WIL) ########################### # Add winml_lib_ort @@ -282,7 +282,7 @@ add_dependencies(winml_lib_ort winml_api_native_internal) if (onnxruntime_USE_DML) target_add_dml(winml_lib_ort) endif() -target_link_libraries(winml_lib_ort PRIVATE wil) +target_link_libraries(winml_lib_ort PRIVATE WIL::WIL) target_link_libraries(winml_lib_ort INTERFACE winml_lib_api) target_link_libraries(winml_lib_ort INTERFACE winml_lib_telemetry) @@ -321,7 +321,7 @@ set_target_properties(winml_adapter PROPERTIES CXX_STANDARD 17) set_target_properties(winml_adapter PROPERTIES CXX_STANDARD_REQUIRED ON) # Compiler definitions -onnxruntime_add_include_to_target(winml_adapter onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers) +onnxruntime_add_include_to_target(winml_adapter onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers safeint_interface Boost::mp11) target_include_directories(winml_adapter PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS}) add_dependencies(winml_adapter ${onnxruntime_EXTERNAL_DEPENDENCIES}) @@ -339,7 +339,7 @@ set_target_properties(winml_adapter ${target_folder}) # Link libraries -target_link_libraries(winml_adapter PRIVATE wil) +target_link_libraries(winml_adapter PRIVATE WIL::WIL) if (onnxruntime_USE_DML) target_add_dml(winml_adapter) endif() @@ -405,10 +405,8 @@ target_include_directories(winml_lib_image PRIVATE ${winml_lib_api_image_dir}) target_include_directories(winml_lib_image PRIVATE ${winml_lib_common_dir}/inc) target_include_directories(winml_lib_image PRIVATE ${ONNXRUNTIME_ROOT}) target_include_directories(winml_lib_image PRIVATE ${ONNXRUNTIME_INCLUDE_DIR}) # for status.h -onnxruntime_add_include_to_target(winml_lib_image ${PROTOBUF_LIB} onnx onnx_proto) +onnxruntime_add_include_to_target(winml_lib_image onnx onnx_proto ${PROTOBUF_LIB} re2::re2 flatbuffers Boost::mp11) target_include_directories(winml_lib_image PRIVATE ${ONNXRUNTIME_INCLUDE_DIR}/core/platform/windows) -target_include_directories(winml_lib_image PRIVATE ${REPO_ROOT}/cmake/external/flatbuffers/include) -target_include_directories(winml_lib_image PRIVATE ${REPO_ROOT}/cmake/external/mp11/include) target_include_directories(winml_lib_image PRIVATE ${REPO_ROOT}/winml) target_include_directories(winml_lib_image PRIVATE ${GSL_INCLUDE_DIR}) @@ -425,7 +423,7 @@ add_dependencies(winml_lib_image winml_api_native) add_dependencies(winml_lib_image winml_api_native_internal) # Link libraries -target_link_libraries(winml_lib_image PRIVATE dxgi d3d11 d3d12 wil winml_lib_common) +target_link_libraries(winml_lib_image PRIVATE dxgi d3d11 d3d12 WIL::WIL winml_lib_common) get_target_property(winml_lib_image_include_directories winml_lib_image INCLUDE_DIRECTORIES) @@ -511,19 +509,13 @@ target_include_directories(winml_lib_api PRIVATE ${winml_lib_telemetry_dir}/inc) target_include_directories(winml_lib_api PRIVATE ${winml_lib_common_dir}/inc) target_include_directories(winml_lib_api PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) -target_include_directories(winml_lib_api PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/external/date/include) - target_include_directories(winml_lib_api PRIVATE ${ONNXRUNTIME_INCLUDE_DIR}) target_include_directories(winml_lib_api PRIVATE ${ONNXRUNTIME_INCLUDE_DIR}/core/graph) target_include_directories(winml_lib_api PRIVATE ${ONNXRUNTIME_ROOT}) target_include_directories(winml_lib_api PRIVATE ${ONNXRUNTIME_ROOT}/core/graph) -target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/cmake/external/eigen) -onnxruntime_add_include_to_target(winml_lib_api ${PROTOBUF_LIB} onnx onnx_proto) -target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/cmake/external/SafeInt) -target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/cmake/external/flatbuffers/include) -target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/cmake/external/mp11/include) target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/winml) -target_include_directories(winml_lib_api PRIVATE ${GSL_INCLUDE_DIR}) +target_include_directories(winml_lib_api PRIVATE ${eigen_INCLUDE_DIRS}) +target_link_libraries(winml_lib_api PRIVATE ${GSL_TARGET} safeint_interface flatbuffers Boost::mp11 onnx onnx_proto) # Properties set_target_properties(winml_lib_api @@ -539,7 +531,7 @@ add_dependencies(winml_lib_api winml_api_native) add_dependencies(winml_lib_api winml_api_native_internal) # Link libraries -target_link_libraries(winml_lib_api PRIVATE wil winml_lib_telemetry) +target_link_libraries(winml_lib_api PRIVATE WIL::WIL winml_lib_telemetry) if (onnxruntime_USE_DML) target_add_dml(winml_lib_api) endif(onnxruntime_USE_DML) @@ -603,20 +595,14 @@ target_include_directories(winml_lib_api_experimental PRIVATE ${winml_lib_teleme target_include_directories(winml_lib_api_experimental PRIVATE ${winml_lib_common_dir}/inc) target_include_directories(winml_lib_api_experimental PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) -target_include_directories(winml_lib_api_experimental PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/external/date/include) - target_include_directories(winml_lib_api_experimental PRIVATE ${ONNXRUNTIME_INCLUDE_DIR}) target_include_directories(winml_lib_api_experimental PRIVATE ${ONNXRUNTIME_INCLUDE_DIR}/core/graph) target_include_directories(winml_lib_api_experimental PRIVATE ${ONNXRUNTIME_ROOT}) target_include_directories(winml_lib_api_experimental PRIVATE ${ONNXRUNTIME_ROOT}/core/graph) -target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/cmake/external/eigen) -onnxruntime_add_include_to_target(winml_lib_api_experimental ${PROTOBUF_LIB} onnx onnx_proto) -target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/cmake/external/SafeInt) -target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/cmake/external/flatbuffers/include) -target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/cmake/external/mp11/include) +target_include_directories(winml_lib_api_experimental PRIVATE ${eigen_INCLUDE_DIRS}) target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/winml) -target_include_directories(winml_lib_api_experimental PRIVATE ${GSL_INCLUDE_DIR}) +onnxruntime_add_include_to_target(winml_lib_api_experimental PRIVATE ${PROTOBUF_LIB} safeint_interface flatbuffers Boost::mp11 onnx onnx_proto ${GSL_TARGET}) # Properties set_target_properties(winml_lib_api_experimental @@ -633,7 +619,7 @@ add_dependencies(winml_lib_api_experimental winml_api_native_internal) add_dependencies(winml_lib_api_experimental winml_api_experimental) # Link libraries -target_link_libraries(winml_lib_api_experimental PRIVATE wil winml_lib_telemetry) +target_link_libraries(winml_lib_api_experimental PRIVATE WIL::WIL winml_lib_telemetry) if (onnxruntime_USE_DML) target_add_dml(winml_lib_api_experimental) endif(onnxruntime_USE_DML) @@ -662,7 +648,7 @@ onnxruntime_add_static_library(winml_lib_common set_target_properties(winml_lib_common PROPERTIES CXX_STANDARD 17) set_target_properties(winml_lib_common PROPERTIES CXX_STANDARD_REQUIRED ON) target_compile_options(winml_lib_common PRIVATE /GR- /await /bigobj /wd4238) -target_link_libraries(winml_lib_common PRIVATE wil) +target_link_libraries(winml_lib_common PRIVATE WIL::WIL) target_include_directories(winml_lib_common PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api) # Compiler flags @@ -719,7 +705,6 @@ onnxruntime_add_shared_library(winml_dll ${winml_dll_dir}/pch.h ${winml_dll_dir}/module.cpp ) - # Compiler options target_compile_features(winml_dll PRIVATE cxx_std_17) target_compile_options(winml_dll PRIVATE /GR- /await /bigobj /wd4238) @@ -764,21 +749,16 @@ target_include_directories(winml_dll PRIVATE ${winml_lib_telemetry_dir}/inc) target_include_directories(winml_dll PRIVATE ${winml_lib_common_dir}/inc) target_include_directories(winml_dll PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) -target_include_directories(winml_dll PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/external/date/include) - target_include_directories(winml_dll PRIVATE ${ONNXRUNTIME_INCLUDE_DIR}) target_include_directories(winml_dll PRIVATE ${ONNXRUNTIME_INCLUDE_DIR}/core/graph) target_include_directories(winml_dll PRIVATE ${ONNXRUNTIME_ROOT}) target_include_directories(winml_dll PRIVATE ${ONNXRUNTIME_ROOT}/core/graph) -onnxruntime_add_include_to_target(winml_dll ${PROTOBUF_LIB} onnx onnx_proto) -target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/cmake/external/eigen) -target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/cmake/external/SafeInt) -target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/cmake/external/flatbuffers/include) -target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/cmake/external/mp11/include) -target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/winml) -target_include_directories(winml_dll PRIVATE ${GSL_INCLUDE_DIR}) +target_include_directories(winml_dll PRIVATE ${eigen_INCLUDE_DIRS}) +target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/winml) +target_link_libraries(winml_dll PRIVATE onnx onnx_proto ${PROTOBUF_LIB} flatbuffers safeint_interface Boost::mp11 ${GSL_TARGET}) +target_link_libraries(winml_dll PRIVATE debug Dbghelp) # Properties set_target_properties(winml_dll PROPERTIES @@ -806,7 +786,7 @@ add_dependencies(winml_dll winml_api_native_internal) # Link libraries target_link_libraries(winml_dll PRIVATE re2) -target_link_libraries(winml_dll PRIVATE wil) +target_link_libraries(winml_dll PRIVATE WIL::WIL) target_link_libraries(winml_dll PRIVATE winml_lib_api) if (NOT winml_is_inbox) target_link_libraries(winml_dll PRIVATE winml_lib_api_experimental) @@ -818,14 +798,6 @@ target_link_libraries(winml_dll PRIVATE winml_lib_telemetry) target_link_libraries(winml_dll PRIVATE RuntimeObject.lib) target_link_libraries(winml_dll PRIVATE windowsapp.lib) -# Any project that links in debug_alloc.obj needs this lib. -# unresolved external symbol __imp_SymSetOptions -# ... __imp_SymGetLineFromAddr64 -# ... __imp_SymInitialize -# ... __imp_SymFromAddr -if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") - target_link_libraries(winml_dll PRIVATE dbghelp.lib) -endif() # 1 of 3 projects that fail in link with 'failed to do memory mapped file I/O' (Only release) # when using x86 hosted architecture. When using the LKG compiler this becomes a problem @@ -837,9 +809,7 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Release") endif("${CMAKE_BUILD_TYPE}" STREQUAL "Release") option(onnxruntime_BUILD_WINML_TESTS "Build WinML tests" ON) -if (onnxruntime_BUILD_WINML_TESTS) - include(winml_unittests.cmake) -endif() + # This is needed to suppress warnings that complain that no imports are found for the delayloaded library cublas64*.lib # When cuda is enabled in the pipeline, it sets CMAKE_SHARED_LINKER_FLAGS which affects all targets including winml_dll. diff --git a/cmake/winml_unittests.cmake b/cmake/winml_unittests.cmake index 3d100cee52..bb729a362f 100644 --- a/cmake/winml_unittests.cmake +++ b/cmake/winml_unittests.cmake @@ -8,9 +8,6 @@ set(WINML_TEST_INC_DIR ${REPO_ROOT}/winml/lib/Common/inc ${REPO_ROOT}/onnxruntime ${REPO_ROOT}/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/D3DX12 - ${REPO_ROOT}/cmake/external/googletest/googletest/include - ${REPO_ROOT}/cmake/external/wil/include - ${REPO_ROOT}/cmake/external/SafeInt ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/winml_api ${CMAKE_CURRENT_BINARY_DIR}/winml_api/comp_generated @@ -26,7 +23,6 @@ function(set_winml_target_properties target) CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO ) - onnxruntime_add_include_to_target(${target} ${PROTOBUF_LIB}) target_include_directories(${target} PRIVATE ${WINML_TEST_INC_DIR}) target_compile_definitions(${target} PRIVATE WINML_ROOT_NS=${winml_root_ns}) target_compile_definitions(${target} PRIVATE BINARY_NAME=\"${BINARY_NAME}\") @@ -183,8 +179,10 @@ add_dependencies(winml_test_common winml_api winml_dll ) -onnxruntime_add_include_to_target(winml_test_common onnx_proto ${GSL_TARGET}) + +onnxruntime_add_include_to_target(winml_test_common onnx_proto gtest ${PROTOBUF_LIB} WIL::WIL safeint_interface ${GSL_TARGET}) onnxruntime_add_static_library(winml_google_test_lib ${WINML_TEST_SRC_DIR}/common/googletest/main.cpp) +onnxruntime_add_include_to_target(winml_google_test_lib gtest) set_winml_target_properties(winml_google_test_lib) set_winml_target_properties(winml_test_common) @@ -269,7 +267,7 @@ target_include_directories(winml_test_adapter PRIVATE ${winml_lib_common_dir}/in target_include_directories(winml_test_adapter PRIVATE ${ONNXRUNTIME_INCLUDE_DIR}) target_include_directories(winml_test_adapter PRIVATE ${ONNXRUNTIME_ROOT}) -onnxruntime_add_include_to_target(winml_test_adapter onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers) +onnxruntime_add_include_to_target(winml_test_adapter onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers safeint_interface Boost::mp11) target_include_directories(winml_test_adapter PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS}) add_dependencies(winml_test_adapter ${onnxruntime_EXTERNAL_DEPENDENCIES}) target_include_directories(winml_test_adapter PRIVATE ${winml_adapter_dir}) diff --git a/onnxruntime/core/common/safeint.h b/onnxruntime/core/common/safeint.h index 263e936b83..5c2ebe9f13 100644 --- a/onnxruntime/core/common/safeint.h +++ b/onnxruntime/core/common/safeint.h @@ -32,7 +32,8 @@ class SafeIntExceptionHandler { #pragma GCC diagnostic ignored "-Wunused-but-set-parameter" #endif #endif -#include "safeint/SafeInt.hpp" +#include "SafeInt.hpp" #if defined(__GNUC__) #pragma GCC diagnostic pop #endif + diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 72db402cbe..6d094c8c6a 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -952,6 +952,10 @@ def generate_build_tree( "-Donnxruntime_USE_XNNPACK=" + ("ON" if args.use_xnnpack else "OFF"), "-Donnxruntime_USE_CANN=" + ("ON" if args.use_cann else "OFF"), ] + # By default cmake does not check TLS/SSL certificates. Here we turn it on. + # But, in some cases you may also need to supply a CA file. + add_default_definition(cmake_extra_defines, "CMAKE_TLS_VERIFY", "ON") + add_default_definition(cmake_extra_defines, "FETCHCONTENT_QUIET", "OFF") if args.external_graph_transformer_path: cmake_args.append("-Donnxruntime_EXTERNAL_TRANSFORMER_SRC_PATH=" + args.external_graph_transformer_path) if args.use_winml: @@ -1299,7 +1303,7 @@ def generate_build_tree( + os.pathsep + os.environ["PATH"] ) - + preinstalled_dir = Path(build_dir) / config run_subprocess( cmake_args + [ @@ -1315,6 +1319,9 @@ def generate_build_tree( else "OFF" ), "-DCMAKE_BUILD_TYPE={}".format(config), + "-DCMAKE_PREFIX_PATH={}/{}/installed".format(build_dir, config) + if preinstalled_dir.exists() and not (args.arm64 or args.arm64ec or args.arm) + else "", ], cwd=config_build_dir, cuda_home=cuda_home, diff --git a/tools/ci_build/get_docker_image.py b/tools/ci_build/get_docker_image.py index 498da7d12e..ecfeba2f36 100755 --- a/tools/ci_build/get_docker_image.py +++ b/tools/ci_build/get_docker_image.py @@ -70,6 +70,13 @@ def main(): log.info("Image: {}".format(full_image_name)) + dst_deps_file = Path(args.context) / "scripts" / "deps.txt" + # The docker file may provide a special deps.txt in its docker context dir and uses that one. + # Otherwise, copy a generic one from this repo's cmake dir. + if not dst_deps_file.exists(): + log.info("Copy deps.txt to : {}".format(str(dst_deps_file))) + shutil.copyfile(Path(REPO_DIR) / "cmake" / "deps.txt", str(dst_deps_file)) + if "manylinux" in args.dockerfile: manylinux_build_scripts_folder = Path(args.manylinux_src) / "docker" / "build_scripts" dest = Path(args.context) / "build_scripts" @@ -89,7 +96,6 @@ def main(): str((Path(SCRIPT_DIR) / "github" / "linux" / "docker" / "manylinux.patch").resolve()), cwd=str(dest), ) - if use_container_registry: run( args.docker_path, diff --git a/tools/ci_build/github/azure-pipelines/binary-size-checks-pipeline.yml b/tools/ci_build/github/azure-pipelines/binary-size-checks-pipeline.yml index c45c0b5fd6..d50e2fa113 100644 --- a/tools/ci_build/github/azure-pipelines/binary-size-checks-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/binary-size-checks-pipeline.yml @@ -45,7 +45,7 @@ jobs: steps: - checkout: self clean: true - submodules: recursive + submodules: none - template: templates/get-docker-image-steps.yml parameters: diff --git a/tools/ci_build/github/azure-pipelines/linux-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/linux-ci-pipeline.yml index d24f3dd606..bbf103d01c 100644 --- a/tools/ci_build/github/azure-pipelines/linux-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/linux-ci-pipeline.yml @@ -17,7 +17,7 @@ jobs: steps: - checkout: self clean: true - submodules: recursive + submodules: none - task: NodeTool@0 inputs: diff --git a/tools/ci_build/github/azure-pipelines/linux-cpu-minimal-build-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/linux-cpu-minimal-build-ci-pipeline.yml index 3daf443c5c..732b83a331 100644 --- a/tools/ci_build/github/azure-pipelines/linux-cpu-minimal-build-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/linux-cpu-minimal-build-ci-pipeline.yml @@ -42,7 +42,7 @@ jobs: steps: - checkout: self clean: true - submodules: recursive + submodules: none - template: templates/get-docker-image-steps.yml parameters: @@ -298,7 +298,7 @@ jobs: --build_shared_lib \ --disable_ml_ops \ --disable_exceptions \ - --skip_tests + --skip_tests --path_to_protoc_exe /usr/bin/protoc workingDirectory: $(Build.SourcesDirectory) - template: templates/clean-agent-build-directory-step.yml diff --git a/tools/ci_build/github/azure-pipelines/linux-dnnl-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/linux-dnnl-ci-pipeline.yml index 7bc6b80b64..2a75b6c3ee 100644 --- a/tools/ci_build/github/azure-pipelines/linux-dnnl-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/linux-dnnl-ci-pipeline.yml @@ -17,7 +17,7 @@ jobs: steps: - checkout: self clean: true - submodules: recursive + submodules: none - template: templates/get-docker-image-steps.yml parameters: diff --git a/tools/ci_build/github/azure-pipelines/linux-gpu-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/linux-gpu-ci-pipeline.yml index db285fe29a..04618b5881 100644 --- a/tools/ci_build/github/azure-pipelines/linux-gpu-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/linux-gpu-ci-pipeline.yml @@ -17,7 +17,7 @@ jobs: steps: - checkout: self clean: true - submodules: recursive + submodules: none - template: templates/get-docker-image-steps.yml parameters: @@ -56,7 +56,7 @@ jobs: - task: CmdLine@2 inputs: script: | - rm -rf $(Build.BinariesDirectory)/Release/onnxruntime $(Build.BinariesDirectory)/Release/pybind11 + rm -rf $(Build.BinariesDirectory)/Release/onnxruntime $(Build.BinariesDirectory)/Release/pybind11 $(Build.BinariesDirectory)/Release/_deps rm -f $(Build.BinariesDirectory)/Release/models rm -rf $(Build.BinariesDirectory)/Release/_deps cd $(Build.BinariesDirectory)/Release diff --git a/tools/ci_build/github/azure-pipelines/linux-gpu-tensorrt-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/linux-gpu-tensorrt-ci-pipeline.yml index 3a4b95fb53..1c51a82d16 100644 --- a/tools/ci_build/github/azure-pipelines/linux-gpu-tensorrt-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/linux-gpu-tensorrt-ci-pipeline.yml @@ -18,7 +18,7 @@ jobs: steps: - checkout: self clean: true - submodules: recursive + submodules: none - template: templates/get-docker-image-steps.yml parameters: diff --git a/tools/ci_build/github/azure-pipelines/linux-migraphx-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/linux-migraphx-ci-pipeline.yml index 91d6a3b013..f7d27d2fc7 100644 --- a/tools/ci_build/github/azure-pipelines/linux-migraphx-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/linux-migraphx-ci-pipeline.yml @@ -24,8 +24,8 @@ jobs: - template: templates/get-docker-image-steps.yml parameters: - Dockerfile: tools/ci_build/github/pai/migraphx-ci-pipeline-env.Dockerfile - Context: tools/ci_build/github/pai + Dockerfile: tools/ci_build/github/linux/docker/migraphx-ci-pipeline-env.Dockerfile + Context: tools/ci_build/github/linux/docker Repository: onnxruntimetrainingmigraphx-cibuild-rocm$(RocmVersion) - task: CmdLine@2 @@ -60,7 +60,7 @@ jobs: --parallel 32 \ --build_wheel \ --skip_submodule_sync \ - --skip_tests + --skip_tests --cmake_path /usr/bin/cmake --ctest_path /usr/bin/ctest workingDirectory: $(Build.SourcesDirectory) displayName: 'Build onnxruntime' diff --git a/tools/ci_build/github/azure-pipelines/linux-multi-gpu-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/linux-multi-gpu-ci-pipeline.yml index 6047e7ff78..4b6457adc2 100644 --- a/tools/ci_build/github/azure-pipelines/linux-multi-gpu-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/linux-multi-gpu-ci-pipeline.yml @@ -15,7 +15,7 @@ jobs: steps: - checkout: self clean: true - submodules: recursive + submodules: none - template: templates/get-docker-image-steps.yml parameters: diff --git a/tools/ci_build/github/azure-pipelines/mac-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/mac-ci-pipeline.yml index 35f3b21dfd..2c8588b96c 100644 --- a/tools/ci_build/github/azure-pipelines/mac-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/mac-ci-pipeline.yml @@ -1,19 +1,6 @@ jobs: - template: templates/mac-ci.yml parameters: - DoNugetPack: 'false' - BuildCommand: >- - python3 $(Build.SourcesDirectory)/tools/ci_build/build.py - --config Debug - --build_dir $(Build.BinariesDirectory) - --build_wheel - --skip_submodule_sync - --parallel - --build_shared_lib - --build_java - --build_nodejs - --build_objc - --enable_language_interop_ops - # Enable unreleased onnx opsets in CI builds - # This facilitates testing the implementation for the new opsets - AllowReleasedOpsetOnly: '0' + AllowReleasedOpsetOnly: 0 + BuildForAllArchs: false + AdditionalBuildFlags: --build_objc --enable_language_interop_ops \ No newline at end of file diff --git a/tools/ci_build/github/azure-pipelines/mac-ios-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/mac-ios-ci-pipeline.yml index 2c2daf8511..715c333c82 100644 --- a/tools/ci_build/github/azure-pipelines/mac-ios-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/mac-ios-ci-pipeline.yml @@ -12,10 +12,7 @@ jobs: timeoutInMinutes: 150 steps: - script: | - /bin/bash $(Build.SourcesDirectory)/tools/ci_build/github/apple/build_host_protoc.sh \ - $(Build.SourcesDirectory) \ - $(Build.BinariesDirectory)/protobuf \ - $(Build.BinariesDirectory)/protobuf_install + $(Build.SourcesDirectory)/tools/ci_build/github/linux/docker/inference/x64/python/cpu/scripts/install_protobuf.sh -p $(Build.BinariesDirectory)/protobuf_install -d $(Build.SourcesDirectory)/cmake/deps.txt displayName: Build Host Protoc - script: | diff --git a/tools/ci_build/github/azure-pipelines/mac-ios-packaging-pipeline.yml b/tools/ci_build/github/azure-pipelines/mac-ios-packaging-pipeline.yml index 1ad8b8205d..fd7fda87bb 100644 --- a/tools/ci_build/github/azure-pipelines/mac-ios-packaging-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/mac-ios-packaging-pipeline.yml @@ -77,10 +77,7 @@ jobs: displayName: "Set variables" - script: | - /bin/bash $(Build.SourcesDirectory)/tools/ci_build/github/apple/build_host_protoc.sh \ - $(Build.SourcesDirectory) \ - $(Build.BinariesDirectory)/protobuf \ - $(Build.BinariesDirectory)/protobuf_install + $(Build.SourcesDirectory)/tools/ci_build/github/linux/docker/inference/x64/python/cpu/scripts/install_protobuf.sh -p $(Build.BinariesDirectory)/protobuf_install -d $(Build.SourcesDirectory)/cmake/deps.txt displayName: "Build Host Protoc" # create and test mobile pods diff --git a/tools/ci_build/github/azure-pipelines/nuget/templates/dml-vs-2019.yml b/tools/ci_build/github/azure-pipelines/nuget/templates/dml-vs-2019.yml index 8816c6153e..2b722791ff 100644 --- a/tools/ci_build/github/azure-pipelines/nuget/templates/dml-vs-2019.yml +++ b/tools/ci_build/github/azure-pipelines/nuget/templates/dml-vs-2019.yml @@ -48,6 +48,7 @@ jobs: build_py_lto_flag: --enable_lto steps: + # Windows_CI_GPU_DML_Dev_arm64 build job still needs protobuf submodule - checkout: self clean: true submodules: recursive @@ -82,20 +83,12 @@ jobs: modifyEnvironment: true workingFolder: '$(Build.BinariesDirectory)' - - script: | - python -m pip install -q setuptools wheel numpy - workingDirectory: '$(Build.BinariesDirectory)' - displayName: 'Install python modules' - - - powershell: | - $Env:USE_MSVC_STATIC_RUNTIME=1 - $Env:ONNX_ML=1 - $Env:CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=${{ parameters.BuildArch }}-windows-static" - python setup.py bdist_wheel - python -m pip uninstall -y onnx -qq - Get-ChildItem -Path dist/*.whl | foreach {pip --disable-pip-version-check install --upgrade $_.fullname} - workingDirectory: '$(Build.SourcesDirectory)\cmake\external\onnx' + - task: PowerShell@2 displayName: 'Install ONNX' + inputs: + filePath: '$(Build.SourcesDirectory)/tools/ci_build/github/windows/install_third_party_deps.ps1' + workingDirectory: '$(Build.BinariesDirectory)' + arguments: -cpu_arch ${{ parameters.BuildArch }} -install_prefix $(Build.BinariesDirectory)\${{ parameters.BuildConfig }}\installed -build_config $(BuildConfig) - task: PythonScript@0 displayName: 'Generate cmake config' diff --git a/tools/ci_build/github/azure-pipelines/orttraining-mac-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/orttraining-mac-ci-pipeline.yml index aac47820ab..759e6bc264 100644 --- a/tools/ci_build/github/azure-pipelines/orttraining-mac-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/orttraining-mac-ci-pipeline.yml @@ -1,17 +1,6 @@ jobs: - template: templates/mac-ci.yml parameters: - JobName: 'Mac_CPU_Training' - SubmoduleCheckoutMode: 'recursive' - BuildCommand: > - python3 $(Build.SourcesDirectory)/tools/ci_build/build.py - --build_dir $(Build.BinariesDirectory) - --skip_submodule_sync - --parallel - --build_shared_lib - --config RelWithDebInfo - --enable_training - DoNugetPack: 'false' - # Enable unreleased onnx opsets in CI builds - # This facilitates testing the implementation for the new opsets - AllowReleasedOpsetOnly: '0' + AllowReleasedOpsetOnly: 0 + BuildForAllArchs: false + AdditionalBuildFlags: --enable_training \ No newline at end of file diff --git a/tools/ci_build/github/azure-pipelines/post-merge-jobs.yml b/tools/ci_build/github/azure-pipelines/post-merge-jobs.yml index 5895f3eaa2..ef225f5f89 100644 --- a/tools/ci_build/github/azure-pipelines/post-merge-jobs.yml +++ b/tools/ci_build/github/azure-pipelines/post-merge-jobs.yml @@ -1,4 +1,38 @@ jobs: +- template: templates/win-ci-vs-2019.yml + parameters: + BuildConfig: 'Debug' + EnvSetupScript: setup_env.bat + buildArch: x64 + additionalBuildFlags: --disable_memleak_checker --use_mimalloc + msbuildPlatform: x64 + isX86: false + job_name_suffix: x64_mimalloc + RunOnnxRuntimeTests: true + RunStaticCodeAnalysis: false + isTraining: false + ORT_EP_NAME: CPU + GenerateDocumentation: false + EnablePython: false + MachinePool: 'Win-CPU-2021' + +- template: templates/win-ci-vs-2019.yml + parameters: + BuildConfig: 'Debug' + EnvSetupScript: setup_env.bat + buildArch: x64 + additionalBuildFlags: --cmake_extra_defines onnxruntime_DISABLE_ABSEIL=ON + msbuildPlatform: x64 + isX86: false + job_name_suffix: x64_no_absl + RunOnnxRuntimeTests: true + RunStaticCodeAnalysis: false + isTraining: false + ORT_EP_NAME: CPU + GenerateDocumentation: false + EnablePython: false + MachinePool: 'Win-CPU-2021' + - job: CodeCoverage workspace: clean: all diff --git a/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar.yml b/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar.yml index a8762c4ef9..533750fa8f 100644 --- a/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar.yml +++ b/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar.yml @@ -54,7 +54,7 @@ jobs: steps: - checkout: self clean: true - submodules: recursive + submodules: none - task: CmdLine@2 displayName: Create artifacts directory diff --git a/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml b/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml index 17b3c4996a..bb0100adc9 100644 --- a/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml +++ b/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml @@ -59,68 +59,10 @@ jobs: OnnxruntimeNodejsBindingArch: 'arm64' PoolName: 'aiinfra-linux-ARM64-CPU-2019' -- job: MacOS_C_API_Packaging_CPU_x64 - workspace: - clean: all - variables: - MACOSX_DEPLOYMENT_TARGET: '10.14' - pool: - vmImage: 'macOS-11' - timeoutInMinutes: 300 - steps: - - template: set-version-number-variables-step.yml - - - task: UsePythonVersion@0 - # Use python 3.8 to avoid build some of the required packages - displayName: Use Python 3.8 - inputs: - versionSpec: 3.8 - - - script: | - set -e - pushd . - cd $(Build.SourcesDirectory)/cmake/external/protobuf - cmake ./cmake -DCMAKE_INSTALL_PREFIX=$(Build.BinariesDirectory)/protobuf -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Relwithdebinfo '-DCMAKE_OSX_ARCHITECTURES=x86_64;arm64' - make -j$(getconf _NPROCESSORS_ONLN) - make install - popd - export PATH=$(Build.BinariesDirectory)/protobuf/bin:$PATH - export ONNX_ML=1 - export CMAKE_ARGS="-DONNX_GEN_PB_TYPE_STUBS=OFF -DONNX_WERROR=OFF" - python3 -m pip install numpy wheel - python3 -m pip install $(Build.SourcesDirectory)/cmake/external/onnx - sudo xcode-select --switch /Applications/Xcode_12.4.app/Contents/Developer - displayName: 'Build and Test MacOS' - - - template: mac-packaging.yml - parameters : - AdditionalBuildFlags : ${{ parameters.AdditionalBuildFlags }} --build_java --build_nodejs --use_coreml --cmake_extra_defines CMAKE_OSX_ARCHITECTURES=arm64 - MacosArch: arm64 - BuildJava: true - BuildNodejs: true - - - template: mac-packaging.yml - parameters : - AdditionalBuildFlags : ${{ parameters.AdditionalBuildFlags }} --use_coreml --cmake_extra_defines CMAKE_OSX_ARCHITECTURES="arm64;x86_64" - MacosArch: universal2 - BuildJava: false - BuildNodejs: false - - - template: mac-packaging.yml - parameters : - AdditionalBuildFlags : ${{ parameters.AdditionalBuildFlags }} --build_java --build_nodejs --use_coreml - MacosArch: x86_64 - BuildJava: true - BuildNodejs: true - - - task: PublishPipelineArtifact@1 - inputs: - targetPath: '$(Build.ArtifactStagingDirectory)' - artifactName: 'onnxruntime-osx' - - - template: component-governance-component-detection-steps.yml - parameters : - condition : 'succeeded' +- template: mac-ci.yml + parameters: + AllowReleasedOpsetOnly: 1 + BuildForAllArchs: true - template: android-java-api-aar.yml parameters: @@ -211,7 +153,7 @@ jobs: buildArch: x64 msbuildPlatform: arm packageName: arm - buildparameter: --arm ${{ parameters.AdditionalBuildFlags }} ${{ parameters.AdditionalWinBuildFlags}} + buildparameter: --arm ${{ parameters.AdditionalBuildFlags }} ${{ parameters.AdditionalWinBuildFlags}} --path_to_protoc_exe $(Build.BinariesDirectory)\RelWithDebInfo\installed\bin\protoc.exe runTests: false buildJava: false buildNodejs: false @@ -225,7 +167,7 @@ jobs: buildArch: x64 msbuildPlatform: arm64 packageName: arm64 - buildparameter: --build_nodejs --arm64 ${{ parameters.AdditionalBuildFlags }} ${{ parameters.AdditionalWinBuildFlags}} + buildparameter: --build_nodejs --arm64 ${{ parameters.AdditionalBuildFlags }} ${{ parameters.AdditionalWinBuildFlags}} --path_to_protoc_exe $(Build.BinariesDirectory)\RelWithDebInfo\installed\bin\protoc.exe runTests: false buildJava: false buildNodejs: true diff --git a/tools/ci_build/github/azure-pipelines/templates/c-api-linux-cpu.yml b/tools/ci_build/github/azure-pipelines/templates/c-api-linux-cpu.yml index d6f01d6a3c..952ec43f9a 100644 --- a/tools/ci_build/github/azure-pipelines/templates/c-api-linux-cpu.yml +++ b/tools/ci_build/github/azure-pipelines/templates/c-api-linux-cpu.yml @@ -35,17 +35,9 @@ jobs: timeoutInMinutes: 210 pool: ${{parameters.PoolName}} steps: - - bash: | - set -euo pipefail - if ! which docker; then - sudo apt-get install apt-transport-https ca-certificates curl software-properties-common - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - - sudo add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" - sudo apt-get update - sudo apt-get install -y docker-ce docker-ce-cli containerd.io - sudo chmod 666 /var/run/docker.sock - fi - displayName: Install Docker Engine + - checkout: self + clean: true + submodules: none - template: set-version-number-variables-step.yml - template: get-docker-image-steps.yml parameters: diff --git a/tools/ci_build/github/azure-pipelines/templates/mac-ci.yml b/tools/ci_build/github/azure-pipelines/templates/mac-ci.yml index 0a0dab0798..10c703a9be 100644 --- a/tools/ci_build/github/azure-pipelines/templates/mac-ci.yml +++ b/tools/ci_build/github/azure-pipelines/templates/mac-ci.yml @@ -1,29 +1,37 @@ parameters: - JobName: 'MacOS_CI_Dev' - SubmoduleCheckoutMode: '' - BuildCommand: '' - DoNodejsPack: 'false' - DoNugetPack: 'false' - NuPackScript: '' - ArtifactName: 'drop-osx' - # Controls whether unreleased onnx opsets are allowed. Default is set to 1 - AllowReleasedOpsetOnly: '1' +- name: AdditionalBuildFlags + displayName: Additional build flags for build.py + type: string + default: '' + +# Must be 1 or 0 +- name: AllowReleasedOpsetOnly + displayName: Whether unreleased onnx opsets are allowed + type: number + default: 1 + values: + - 1 + - 0 + +- name: BuildForAllArchs + displayName: Build for all CPU ARCHs + type: boolean jobs: -- job: ${{ parameters.JobName }} +- job: MacOS_C_API_Packaging_CPU_x64 workspace: clean: all - timeoutInMinutes: 180 + variables: + MACOSX_DEPLOYMENT_TARGET: '10.14' + ALLOW_RELEASED_ONNX_OPSET_ONLY: ${{ parameters.AllowReleasedOpsetOnly }} pool: vmImage: 'macOS-11' - variables: - BuildCommand: ${{ parameters.BuildCommand }} - ALLOW_RELEASED_ONNX_OPSET_ONLY: ${{ parameters.AllowReleasedOpsetOnly }} - MACOSX_DEPLOYMENT_TARGET: '10.14' + timeoutInMinutes: 300 steps: - checkout: self - ${{ if ne(parameters.SubmoduleCheckoutMode, '') }}: - submodules: ${{ parameters.SubmoduleCheckoutMode }} + clean: true + submodules: none + - task: UsePythonVersion@0 # Use python 3.8 to avoid build some of the required packages displayName: Use Python 3.8 @@ -32,56 +40,49 @@ jobs: - task: NodeTool@0 inputs: versionSpec: '16.x' + + - template: set-version-number-variables-step.yml + - script: | - set -e + set -e -x pushd . - cd $(Build.SourcesDirectory)/cmake/external/protobuf - cmake ./cmake -DCMAKE_INSTALL_PREFIX=$(Build.BinariesDirectory)/protobuf -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Relwithdebinfo - make -j $(getconf _NPROCESSORS_ONLN) - make install + $(Build.SourcesDirectory)/tools/ci_build/github/linux/docker/inference/x64/python/cpu/scripts/install_protobuf.sh -d $(Build.SourcesDirectory)/cmake/deps.txt -p $(Build.BinariesDirectory)/installed popd - export PATH=$(Build.BinariesDirectory)/protobuf/bin:$PATH + export PATH=$(Build.BinariesDirectory)/installed/bin:$PATH export ONNX_ML=1 export CMAKE_ARGS="-DONNX_GEN_PB_TYPE_STUBS=OFF -DONNX_WERROR=OFF" - sudo python3 -m pip install -r '$(Build.SourcesDirectory)/tools/ci_build/github/linux/docker/scripts/requirements.txt' + python3 -m pip install -r '$(Build.SourcesDirectory)/tools/ci_build/github/linux/docker/scripts/requirements.txt' sudo xcode-select --switch /Applications/Xcode_12.4.app/Contents/Developer - ${{ parameters.BuildCommand }} - displayName: 'Build and Test OnnxRuntime lib for MacOS' + displayName: 'Install dependencies' - - ${{ if eq(parameters['DoNugetPack'], 'true') }}: - - script: | - ${{ parameters.NuPackScript }} - displayName: 'Copy MacOS libs to Artifact Staging' - - task: PublishPipelineArtifact@0 - displayName: 'Publish Pipeline Artifact: ${{ parameters.ArtifactName }}' - inputs: - artifactName: ${{ parameters.ArtifactName }} - targetPath: '$(Build.ArtifactStagingDirectory)' + - ${{ if eq(parameters.BuildForAllArchs, true) }}: + - template: mac-packaging.yml + parameters : + AdditionalBuildFlags : ${{ parameters.AdditionalBuildFlags }} --build_java --build_nodejs --use_coreml --cmake_extra_defines CMAKE_OSX_ARCHITECTURES=arm64 + MacosArch: arm64 + BuildJava: true + BuildNodejs: true - - ${{ if eq(parameters['DoNodejsPack'], 'true') }}: - # Esrp signing - # - # TODO: ESRP team is working on enable signing workflow on Mac. Should enable the following step when it's ready. - # - # - template: mac-esrp-dll.yml - # parameters: - # FolderPath: '$(Build.SourcesDirectory)/js/node/bin/napi-v3/darwin/x64' - # DisplayName: 'ESRP - Sign Node.js binding binaries' - # DoEsrp: ${{ parameters.DoEsrp }} - # Pattern: '*.dylib,*.node' + - ${{ if eq(parameters.BuildForAllArchs, true) }}: + - template: mac-packaging.yml + parameters : + AdditionalBuildFlags : ${{ parameters.AdditionalBuildFlags }} --use_coreml --cmake_extra_defines CMAKE_OSX_ARCHITECTURES="arm64;x86_64" + MacosArch: universal2 + BuildJava: false + BuildNodejs: false - - script: | - cp -R $(Build.SourcesDirectory)/js/node/bin $(Build.ArtifactStagingDirectory)/bin - workingDirectory: '$(Build.SourcesDirectory)/js/node' - displayName: 'Create Node.js Binding Artifact' + - template: mac-packaging.yml + parameters : + AdditionalBuildFlags : ${{ parameters.AdditionalBuildFlags }} --build_java --build_nodejs --use_coreml + MacosArch: x86_64 + BuildJava: true + BuildNodejs: true - - task: PublishPipelineArtifact@0 - displayName: 'Publish Pipeline Artifact: ${{ parameters.ArtifactName }}' - inputs: - artifactName: ${{ parameters.ArtifactName }} - targetPath: '$(Build.ArtifactStagingDirectory)' + - task: PublishPipelineArtifact@1 + inputs: + targetPath: '$(Build.ArtifactStagingDirectory)' + artifactName: 'onnxruntime-osx' - template: component-governance-component-detection-steps.yml parameters : - condition : 'succeeded' - - template: clean-agent-build-directory-step.yml + condition : 'succeeded' \ No newline at end of file diff --git a/tools/ci_build/github/azure-pipelines/templates/py-linux-gpu.yml b/tools/ci_build/github/azure-pipelines/templates/py-linux-gpu.yml index 5d317b43c2..d9c4e94304 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-linux-gpu.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-linux-gpu.yml @@ -28,25 +28,13 @@ jobs: DockerBuildArgs: "--network=host --build-arg POLICY=manylinux2014 --build-arg PLATFORM=x86_64 --build-arg DEVTOOLSET_ROOTPATH=/opt/rh/devtoolset-11/root --build-arg PREPEND_PATH=/opt/rh/devtoolset-11/root/usr/bin: --build-arg LD_LIBRARY_PATH_ARG=/opt/rh/devtoolset-11/root/usr/lib64:/opt/rh/devtoolset-11/root/usr/lib:/opt/rh/devtoolset-11/root/usr/lib64/dyninst:/opt/rh/devtoolset-11/root/usr/lib/dyninst:/usr/local/lib64 --build-arg BUILD_UID=$( id -u ) --build-arg PLATFORM=${{ parameters.arch }}" Repository: onnxruntimecuda116xtrt84build${{ parameters.arch }} - - task: CmdLine@2 + + - task: Bash@3 displayName: 'Build Python Wheel' inputs: - script: | - set -e -x - mkdir -p $HOME/.onnx - docker run --rm \ - --volume /data/onnx:/data/onnx:ro \ - --volume $(Build.SourcesDirectory):/onnxruntime_src \ - --volume $(Build.BinariesDirectory):/build \ - --volume /data/models:/build/models:ro \ - --volume $HOME/.onnx:/home/onnxruntimedev/.onnx \ - -w /onnxruntime_src \ - -e NIGHTLY_BUILD \ - -e BUILD_BUILDNUMBER \ - onnxruntimecuda116xtrt84build${{ parameters.arch }} /bin/bash tools/ci_build/github/linux/build_linux_arm64_python_package.sh -d GPU - rm -rf $(Build.BinariesDirectory)/Release/onnxruntime $(Build.BinariesDirectory)/Release/pybind11 $(Build.BinariesDirectory)/Release/models $(Build.BinariesDirectory)/Release/_deps $(Build.BinariesDirectory)/Release/CMakeFiles - cd $(Build.BinariesDirectory)/Release - find -executable -type f > $(Build.BinariesDirectory)/Release/perms.txt + targetType: filePath + filePath: tools/ci_build/github/linux/run_python_dockerbuild.sh + arguments: -i onnxruntimecuda116xtrt84build${{ parameters.arch }} -x "-d GPU" - task: PublishBuildArtifacts@1 displayName: 'Publish Artifact: ONNXRuntime python wheel' diff --git a/tools/ci_build/github/azure-pipelines/templates/py-linux-ubuntu.yml b/tools/ci_build/github/azure-pipelines/templates/py-linux-ubuntu.yml index 9026903e51..06cf18cbea 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-linux-ubuntu.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-linux-ubuntu.yml @@ -4,7 +4,7 @@ parameters: - name: machine_pool type: string - + - name: base_image type: string @@ -20,7 +20,7 @@ jobs: steps: - checkout: self clean: true - submodules: recursive + submodules: none - template: set-nightly-build-option-variable-step.yml @@ -33,25 +33,12 @@ jobs: ${{ if eq(parameters.arch, 'aarch64') }}: UpdateDepsTxt: false - - task: CmdLine@2 + - task: Bash@3 displayName: 'Build Python Wheel' inputs: - script: | - set -e -x - mkdir -p $HOME/.onnx - docker run --rm \ - --volume /data/onnx:/data/onnx:ro \ - --volume $(Build.SourcesDirectory):/onnxruntime_src \ - --volume $(Build.BinariesDirectory):/build \ - --volume /data/models:/build/models:ro \ - --volume $HOME/.onnx:/home/onnxruntimedev/.onnx \ - -w /onnxruntime_src \ - -e NIGHTLY_BUILD \ - -e BUILD_BUILDNUMBER \ - onnxruntimecpubuildubuntu20python${{ parameters.arch }} tools/ci_build/github/linux/build_linux_arm64_python_package.sh - rm -rf $(Build.BinariesDirectory)/Release/onnxruntime $(Build.BinariesDirectory)/Release/pybind11 $(Build.BinariesDirectory)/Release/models $(Build.BinariesDirectory)/Release/_deps $(Build.BinariesDirectory)/Release/CMakeFiles - cd $(Build.BinariesDirectory)/Release - find -executable -type f > $(Build.BinariesDirectory)/Release/perms.txt + targetType: filePath + filePath: tools/ci_build/github/linux/run_python_dockerbuild.sh + arguments: -i onnxruntimecpubuildubuntu20python${{ parameters.arch }} - task: PublishBuildArtifacts@1 displayName: 'Publish Artifact: ONNXRuntime python wheel' diff --git a/tools/ci_build/github/azure-pipelines/templates/py-linux.yml b/tools/ci_build/github/azure-pipelines/templates/py-linux.yml index 6426c5a033..363ba0db6d 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-linux.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-linux.yml @@ -4,7 +4,7 @@ parameters: - name: machine_pool type: string - + - name: base_image type: string @@ -29,7 +29,7 @@ jobs: steps: - checkout: self clean: true - submodules: recursive + submodules: none - template: set-nightly-build-option-variable-step.yml @@ -42,25 +42,12 @@ jobs: ${{ if eq(parameters.arch, 'aarch64') }}: UpdateDepsTxt: false - - task: CmdLine@2 + - task: Bash@3 displayName: 'Build Python Wheel' inputs: - script: | - set -e -x - mkdir -p $HOME/.onnx - docker run --rm \ - --volume /data/onnx:/data/onnx:ro \ - --volume $(Build.SourcesDirectory):/onnxruntime_src \ - --volume $(Build.BinariesDirectory):/build \ - --volume /data/models:/build/models:ro \ - --volume $HOME/.onnx:/home/onnxruntimedev/.onnx \ - -w /onnxruntime_src \ - -e NIGHTLY_BUILD \ - -e BUILD_BUILDNUMBER \ - onnxruntimecpubuilpython${{ parameters.arch }} tools/ci_build/github/linux/build_linux_arm64_python_package.sh - rm -rf $(Build.BinariesDirectory)/Release/onnxruntime $(Build.BinariesDirectory)/Release/pybind11 $(Build.BinariesDirectory)/Release/models $(Build.BinariesDirectory)/Release/_deps $(Build.BinariesDirectory)/Release/CMakeFiles - cd $(Build.BinariesDirectory)/Release - find -executable -type f > $(Build.BinariesDirectory)/Release/perms.txt + targetType: filePath + filePath: tools/ci_build/github/linux/run_python_dockerbuild.sh + arguments: -i onnxruntimecpubuilpython${{ parameters.arch }} - task: PublishBuildArtifacts@1 displayName: 'Publish Artifact: ONNXRuntime python wheel' diff --git a/tools/ci_build/github/azure-pipelines/templates/py-packaging-selectable-stage.yml b/tools/ci_build/github/azure-pipelines/templates/py-packaging-selectable-stage.yml index cbe3ddadcb..4ff80f1fa7 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-packaging-selectable-stage.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-packaging-selectable-stage.yml @@ -157,15 +157,12 @@ stages: workingDirectory: '$(Build.BinariesDirectory)' displayName: 'Install python modules' - - powershell: | - $Env:USE_MSVC_STATIC_RUNTIME=1 - $Env:ONNX_ML=1 - $Env:CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static" - python setup.py bdist_wheel - python -m pip uninstall -y onnx -qq - Get-ChildItem -Path dist/*.whl | foreach {pip --disable-pip-version-check install --force-reinstall --upgrade $_.fullname} - workingDirectory: '$(Build.SourcesDirectory)\cmake\external\onnx' + - task: PowerShell@2 displayName: 'Install ONNX' + inputs: + filePath: '$(Build.SourcesDirectory)/tools/ci_build/github/windows/install_third_party_deps.ps1' + workingDirectory: '$(Build.BinariesDirectory)' + arguments: -cpu_arch x64 -install_prefix $(Build.BinariesDirectory)\${{ parameters.BuildConfig }}\installed -build_config $(BuildConfig) - task: PythonScript@0 displayName: 'Generate cmake config' @@ -420,15 +417,12 @@ stages: workingDirectory: '$(Build.BinariesDirectory)' displayName: 'Install python modules' - - powershell: | - $Env:USE_MSVC_STATIC_RUNTIME=1 - $Env:ONNX_ML=1 - $Env:CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=$(buildArch)-windows-static" - python setup.py bdist_wheel - python -m pip uninstall -y onnx -qq - Get-ChildItem -Path dist/*.whl | foreach {pip --disable-pip-version-check install --upgrade $_.fullname} - workingDirectory: '$(Build.SourcesDirectory)\cmake\external\onnx' + - task: PowerShell@2 displayName: 'Install ONNX' + inputs: + filePath: '$(Build.SourcesDirectory)/tools/ci_build/github/windows/install_third_party_deps.ps1' + workingDirectory: '$(Build.BinariesDirectory)' + arguments: -cpu_arch x64 -install_prefix $(Build.BinariesDirectory)\RelWithDebInfo\installed -build_config RelWithDebInfo - task: PythonScript@0 displayName: 'Generate cmake config' diff --git a/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml b/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml index daae6acb19..9f5004995a 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml @@ -132,7 +132,7 @@ stages: displayName: 'Install python modules' - template: download-deps.yml - + - task: PythonScript@0 displayName: 'Update deps.txt' inputs: @@ -140,15 +140,12 @@ stages: arguments: --new_dir $(Build.BinariesDirectory)/deps workingDirectory: $(Build.BinariesDirectory) - - powershell: | - $Env:USE_MSVC_STATIC_RUNTIME=1 - $Env:ONNX_ML=1 - $Env:CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=$(buildArch)-windows-static" - python setup.py bdist_wheel - python -m pip uninstall -y onnx -qq - Get-ChildItem -Path dist/*.whl | foreach {pip --disable-pip-version-check install --upgrade $_.fullname} - workingDirectory: '$(Build.SourcesDirectory)\cmake\external\onnx' + - task: PowerShell@2 displayName: 'Install ONNX' + inputs: + filePath: '$(Build.SourcesDirectory)/tools/ci_build/github/windows/install_third_party_deps.ps1' + workingDirectory: '$(Build.BinariesDirectory)' + arguments: -cpu_arch $(buildArch) -install_prefix $(Build.BinariesDirectory)\$(BuildConfig)\installed -build_config $(BuildConfig) - task: PythonScript@0 displayName: 'Generate cmake config' @@ -300,7 +297,7 @@ stages: PYTHON_VERSION: '3.10' EP_BUILD_FLAGS: --use_tensorrt --tensorrt_home="C:\local\TensorRT-8.4.1.5.Windows10.x86_64.cuda-11.6.cudnn8.4" --cuda_version=11.6 --cuda_home="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6" --cmake_extra_defines "CMAKE_CUDA_ARCHITECTURES=37;50;52;60;61;70;75;80" ENV_SETUP_SCRIPT: setup_env_gpu.bat - EP_NAME: gpu + EP_NAME: gpu - template: py-win-gpu.yml parameters: @@ -333,7 +330,7 @@ stages: EP_BUILD_FLAGS: --use_dml --cmake_extra_defines CMAKE_SYSTEM_VERSION=10.0.18362.0 --enable_wcos ENV_SETUP_SCRIPT: setup_env.bat EP_NAME: directml - + - ${{ if eq(parameters.enable_mac_cpu, true) }}: - job: MacOS_py_Wheels timeoutInMinutes: 90 @@ -364,17 +361,17 @@ stages: versionSpec: $(PythonVersion) - script: | - set -e + set -e -x pushd . - cd $(Build.SourcesDirectory)/cmake/external/protobuf - cmake ./cmake -DCMAKE_INSTALL_PREFIX=$(Build.BinariesDirectory)/protobuf -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Relwithdebinfo '-DCMAKE_OSX_ARCHITECTURES=x86_64;arm64' - make -j$(getconf _NPROCESSORS_ONLN) - make install + mkdir -p /tmp/scripts + mkdir -p $(Build.BinariesDirectory)/installed + cp $(Build.SourcesDirectory)/cmake/deps.txt /tmp/scripts + $(Build.SourcesDirectory)/tools/ci_build/github/linux/docker/inference/x64/python/cpu/scripts/install_protobuf.sh -p $(Build.BinariesDirectory)/installed popd - export PATH=$(Build.BinariesDirectory)/protobuf/bin:$PATH + export PATH=$(Build.BinariesDirectory)/installed/bin:$PATH export ONNX_ML=1 export CMAKE_ARGS="-DONNX_GEN_PB_TYPE_STUBS=OFF -DONNX_WERROR=OFF" - sudo python3 -m pip install -r '$(Build.SourcesDirectory)/tools/ci_build/github/linux/docker/scripts/requirements.txt' + python3 -m pip install -r '$(Build.SourcesDirectory)/tools/ci_build/github/linux/docker/scripts/requirements.txt' sudo xcode-select --switch /Applications/Xcode_12.4.app/Contents/Developer python3 $(Build.SourcesDirectory)/tools/ci_build/build.py --build_dir $(Build.BinariesDirectory) --skip_submodule_sync --parallel --config Release --skip_onnx_tests --build_wheel ${{ parameters.build_py_parameters }} displayName: 'Command Line Script' @@ -431,18 +428,17 @@ stages: displayName: 'Mac machine info' - script: | - set -e + set -e -x pushd . - cd $(Build.SourcesDirectory)/cmake/external/protobuf - cmake ./cmake -DCMAKE_INSTALL_PREFIX=$(Build.BinariesDirectory)/protobuf -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Relwithdebinfo '-DCMAKE_OSX_ARCHITECTURES=x86_64;arm64' - make -j$(getconf _NPROCESSORS_ONLN) - make install + mkdir -p /tmp/scripts + mkdir -p $(Build.BinariesDirectory)/installed + cp $(Build.SourcesDirectory)/cmake/deps.txt /tmp/scripts + $(Build.SourcesDirectory)/tools/ci_build/github/linux/docker/inference/x64/python/cpu/scripts/install_protobuf.sh -p $(Build.BinariesDirectory)/installed popd - export PATH=$(Build.BinariesDirectory)/protobuf/bin:$PATH + export PATH=$(Build.BinariesDirectory)/installed/bin:$PATH export ONNX_ML=1 export CMAKE_ARGS="-DONNX_GEN_PB_TYPE_STUBS=OFF -DONNX_WERROR=OFF" - export _PYTHON_HOST_PLATFORM=macosx-${{variables.MACOSX_DEPLOYMENT_TARGET}}-arm64 - sudo python3 -m pip install -r '$(Build.SourcesDirectory)/tools/ci_build/github/linux/docker/scripts/requirements.txt' + python3 -m pip install -r '$(Build.SourcesDirectory)/tools/ci_build/github/linux/docker/scripts/requirements.txt' sudo xcode-select --switch /Applications/Xcode_12.4.app/Contents/Developer python3 $(Build.SourcesDirectory)/tools/ci_build/build.py --build_dir $(Build.BinariesDirectory) --skip_submodule_sync --parallel --config Release --skip_tests --cmake_extra_defines CMAKE_OSX_ARCHITECTURES=arm64 --build_wheel ${{ parameters.build_py_parameters }} displayName: 'Command Line Script' @@ -511,4 +507,4 @@ stages: - template: py-linux-gpu.yml parameters: arch: 'x86_64' - machine_pool: 'Linux-CPU' \ No newline at end of file + machine_pool: 'Linux-CPU' diff --git a/tools/ci_build/github/azure-pipelines/templates/py-win-gpu.yml b/tools/ci_build/github/azure-pipelines/templates/py-win-gpu.yml index a01675bf91..19d2a897fe 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-win-gpu.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-win-gpu.yml @@ -53,7 +53,7 @@ jobs: displayName: 'Install python modules' - template: download-deps.yml - + - task: PythonScript@0 displayName: 'Update deps.txt' inputs: @@ -61,15 +61,12 @@ jobs: arguments: --new_dir $(Build.BinariesDirectory)/deps workingDirectory: $(Build.BinariesDirectory) - - powershell: | - $Env:USE_MSVC_STATIC_RUNTIME=1 - $Env:ONNX_ML=1 - $Env:CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static" - python setup.py bdist_wheel - python -m pip uninstall -y onnx -qq - Get-ChildItem -Path dist/*.whl | foreach {pip --disable-pip-version-check install --upgrade $_.fullname} - workingDirectory: '$(Build.SourcesDirectory)\cmake\external\onnx' + - task: PowerShell@2 displayName: 'Install ONNX' + inputs: + filePath: '$(Build.SourcesDirectory)/tools/ci_build/github/windows/install_third_party_deps.ps1' + workingDirectory: '$(Build.BinariesDirectory)' + arguments: -cpu_arch x64 -install_prefix $(Build.BinariesDirectory)\RelWithDebInfo\installed -build_config RelWithDebInfo - template: set-nightly-build-option-variable-step.yml diff --git a/tools/ci_build/github/azure-pipelines/templates/win-ci-arm.yml b/tools/ci_build/github/azure-pipelines/templates/win-ci-arm.yml deleted file mode 100644 index de90d63023..0000000000 --- a/tools/ci_build/github/azure-pipelines/templates/win-ci-arm.yml +++ /dev/null @@ -1,126 +0,0 @@ -parameters: - DoDebugBuild: 'true' - DoCompliance: 'false' - BuildCommand: '' - JobName: 'Windows_CI_Dev' - DoNugetPack: 'false' - NuPackScript : '' - ArtifactName: 'drop-nuget' - DoEsrp: 'false' - BuildArch: 'x64' - DoTestCoverage: 'false' - sln_platform: 'Arm64' # Options: Win32, x64,Arm64 - SetVcvars: 'false' - MsbuildArguments: '/m' - EnvSetupScript: 'setup_env.bat' - CudaVersion: '' - -jobs: -- job: ${{ parameters.JobName }} - workspace: - clean: all - timeoutInMinutes: 120 - pool: ${{ parameters.AgentPool }} - variables: - buildDirectory: '$(Build.BinariesDirectory)' - BuildCommand: ${{ parameters.BuildCommand }} - OnnxRuntimeBuildDirectory: '$(Build.BinariesDirectory)' - DotNetExe: 'dotnet.exe' - CUDA_VERSION: ${{ parameters.CudaVersion }} - - steps: - - powershell: | - if($env:TELEMETRYGUID) - { - $length = $env:TELEMETRYGUID.length - $fileContent = "#define TraceLoggingOptionMicrosoftTelemetry() \ - TraceLoggingOptionGroup("+$env:TELEMETRYGUID.substring(1, $length-2)+")" - New-Item -Path "$(Build.SourcesDirectory)\include\onnxruntime\core\platform\windows\TraceLoggingConfigPrivate.h" -ItemType "file" -Value "$fileContent" -Force - Write-Output "Enabling TELEMETRY" - } - displayName: 'Create TraceLoggingConfigPrivate.h For WinML Telemetry' - env: - TELEMETRYGUID: $(TELEMETRYGUID) - - - task: BatchScript@1 - displayName: 'setup env' - inputs: - filename: '$(Build.SourcesDirectory)\tools\ci_build\github\windows\${{ parameters.EnvSetupScript }}' - modifyEnvironment: true - workingFolder: '$(Build.BinariesDirectory)' - - - task: BatchScript@1 - displayName: 'Setup VS2019 env vars' - inputs: - filename: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat' - arguments: amd64_arm - modifyEnvironment: true - - - task: UsePythonVersion@0 - inputs: - versionSpec: '3.7' - addToPath: true - architecture: x64 - - - script: | - python -m pip install -q setuptools wheel numpy - workingDirectory: '$(Build.BinariesDirectory)' - displayName: 'Install python modules' - - - task: PythonScript@0 - displayName: 'Generate cmake config' - inputs: - scriptPath: '$(Build.SourcesDirectory)\tools\ci_build\build.py' - arguments: '$(BuildCommand) --update --config RelWithDebInfo' - workingDirectory: '$(Build.BinariesDirectory)' - - - task: VSBuild@1 - displayName: 'Build' - inputs: - solution: '$(Build.BinariesDirectory)\RelWithDebInfo\onnxruntime.sln' - platform: ${{ parameters.sln_platform }} - configuration: RelWithDebInfo - msbuildArchitecture: ${{ parameters.BuildArch }} - maximumCpuCount: true - logProjectEvents: true - workingFolder: '$(Build.BinariesDirectory)\RelWithDebInfo' - createLogFile: true - - # Build RelWithDebInfo -- this variable required to build C# - - script: | - @echo ##vso[task.setvariable variable=Configuration]RelWithDebInfo - - - # Nuget packaging if needed - - ${{ if eq(parameters['DoNugetPack'], 'true') }}: - # Esrp signing - - template: win-esrp-dll.yml - parameters: - FolderPath: '$(Build.BinariesDirectory)\RelWithDebInfo' - DisplayName: 'ESRP - Sign Native dlls' - DoEsrp: ${{ parameters.DoEsrp }} - - - script: | - ${{ parameters.NuPackScript }} - workingDirectory: '$(Build.SourcesDirectory)\csharp' - displayName: 'Create NuGet Package' - - - task: PublishPipelineArtifact@0 - displayName: 'Publish Pipeline Artifact: drop-nuget' - inputs: - artifactName: ${{ parameters.ArtifactName }} - targetPath: '$(Build.ArtifactStagingDirectory)' - - - task: PublishSymbols@2 - displayName: 'Publish Build Symbols' - condition: eq(variables['IsReleaseBuild'], 'true') - inputs: - symbolsFolder: '$(Build.BinariesDirectory)\RelWithDebInfo\RelWithDebInfo' - searchPattern: '**/*.pdb' - symbolServerType: teamServices - - - template: component-governance-component-detection-steps.yml - parameters : - condition : 'succeeded' - - - template: clean-agent-build-directory-step.yml diff --git a/tools/ci_build/github/azure-pipelines/templates/win-ci-vs-2019.yml b/tools/ci_build/github/azure-pipelines/templates/win-ci-vs-2019.yml index ae58c5c951..932951c9f7 100644 --- a/tools/ci_build/github/azure-pipelines/templates/win-ci-vs-2019.yml +++ b/tools/ci_build/github/azure-pipelines/templates/win-ci-vs-2019.yml @@ -65,6 +65,10 @@ jobs: pool: ${{ parameters.MachinePool }} timeoutInMinutes: 300 steps: + - checkout: self + clean: true + submodules: none + - task: UsePythonVersion@0 inputs: versionSpec: '3.7' @@ -72,7 +76,7 @@ jobs: architecture: ${{ parameters.buildArch }} - template: download-deps.yml - + - task: PythonScript@0 displayName: 'Update deps.txt' inputs: @@ -116,15 +120,13 @@ jobs: displayName: 'Install python modules' - ${{ if or(eq(parameters.RunOnnxRuntimeTests, true), eq(parameters.GenerateDocumentation, true)) }}: - - powershell: | - $Env:USE_MSVC_STATIC_RUNTIME=1 - $Env:ONNX_ML=1 - $Env:CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=${{ parameters.buildArch }}-windows-static" - python setup.py bdist_wheel - python -m pip uninstall -y onnx -qq - Get-ChildItem -Path dist/*.whl | foreach {pip --disable-pip-version-check install --upgrade $_.fullname} - workingDirectory: '$(Build.SourcesDirectory)\cmake\external\onnx' + - task: PowerShell@2 displayName: 'Install ONNX' + inputs: + filePath: '$(Build.SourcesDirectory)/tools/ci_build/github/windows/install_third_party_deps.ps1' + workingDirectory: '$(Build.BinariesDirectory)' + arguments: -cpu_arch ${{ parameters.buildArch }} -install_prefix $(Build.BinariesDirectory)\${{ parameters.BuildConfig }}\installed -build_config ${{ parameters.BuildConfig }} + #Build.py disables running training python frontend tests on Windows, so here we don't install pytorch. - ${{ if eq(parameters.isTraining, true) }}: diff --git a/tools/ci_build/github/azure-pipelines/templates/win-ci.yml b/tools/ci_build/github/azure-pipelines/templates/win-ci.yml index dcb32a73b2..59c0c53fd8 100644 --- a/tools/ci_build/github/azure-pipelines/templates/win-ci.yml +++ b/tools/ci_build/github/azure-pipelines/templates/win-ci.yml @@ -60,6 +60,10 @@ jobs: timeoutInMinutes: 300 steps: + - checkout: self + clean: true + submodules: none + - template: telemetry-steps.yml - task: UsePythonVersion@0 @@ -80,13 +84,8 @@ jobs: modifyEnvironment: true workingFolder: '$(Build.BinariesDirectory)' - - script: | - python -m pip install -q setuptools wheel numpy - workingDirectory: '$(Build.BinariesDirectory)' - displayName: 'Install python modules' - - template: download-deps.yml - + - task: PythonScript@0 displayName: 'Update deps.txt' inputs: @@ -94,15 +93,12 @@ jobs: arguments: --new_dir $(Build.BinariesDirectory)/deps workingDirectory: $(Build.BinariesDirectory) - - powershell: | - $Env:USE_MSVC_STATIC_RUNTIME=1 - $Env:ONNX_ML=1 - $Env:CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=${{ parameters.buildArch }}-windows-static" - python setup.py bdist_wheel - python -m pip uninstall -y onnx -qq - Get-ChildItem -Path dist/*.whl | foreach {pip --disable-pip-version-check install --upgrade $_.fullname} - workingDirectory: '$(Build.SourcesDirectory)\cmake\external\onnx' - displayName: 'Install ONNX' + - task: PowerShell@2 + displayName: 'Install ONNX' + inputs: + filePath: '$(Build.SourcesDirectory)/tools/ci_build/github/windows/install_third_party_deps.ps1' + workingDirectory: '$(Build.BinariesDirectory)' + arguments: -cpu_arch ${{ parameters.buildArch }} -install_prefix $(Build.BinariesDirectory)\RelWithDebInfo\installed -build_config RelWithDebInfo - template: set-version-number-variables-step.yml @@ -158,7 +154,7 @@ jobs: - task: PublishPipelineArtifact@1 condition: and(succeeded(), eq('${{ parameters.packageName}}', 'x64')) inputs: - targetPath: '$(Build.BinariesDirectory)\RelWithDebInfo\_deps\protobuf-build\RelWithDebInfo\protoc.exe' + targetPath: '$(Build.BinariesDirectory)\RelWithDebInfo\installed\bin\protoc.exe' artifactName: 'drop-extra' @@ -174,7 +170,7 @@ jobs: - task: PublishPipelineArtifact@1 condition: and(succeeded(), eq('${{ parameters.packageName}}', 'x64')) inputs: - targetPath: '$(Build.BinariesDirectory)\RelWithDebInfo\_deps\protobuf-build\RelWithDebInfo\protoc.exe' + targetPath: '$(Build.BinariesDirectory)\RelWithDebInfo\installed\bin\protoc.exe' artifactName: 'drop-nuget' diff --git a/tools/ci_build/github/azure-pipelines/win-ci-fuzz-testing.yml b/tools/ci_build/github/azure-pipelines/win-ci-fuzz-testing.yml index fcdab7957f..b98ada6632 100644 --- a/tools/ci_build/github/azure-pipelines/win-ci-fuzz-testing.yml +++ b/tools/ci_build/github/azure-pipelines/win-ci-fuzz-testing.yml @@ -41,15 +41,12 @@ jobs: workingDirectory: '$(Build.BinariesDirectory)' displayName: 'Install python modules' - - powershell: | - $Env:USE_MSVC_STATIC_RUNTIME=1 - $Env:ONNX_ML=1 - $Env:CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=$(buildArch)-windows-static" - python setup.py bdist_wheel - python -m pip uninstall -y onnx -qq - Get-ChildItem -Path dist/*.whl | foreach {pip --disable-pip-version-check install --upgrade $_.fullname} - workingDirectory: '$(Build.SourcesDirectory)\cmake\external\onnx' + - task: PowerShell@2 displayName: 'Install ONNX' + inputs: + filePath: '$(Build.SourcesDirectory)/tools/ci_build/github/windows/install_third_party_deps.ps1' + workingDirectory: '$(Build.BinariesDirectory)' + arguments: -cpu_arch x64 -install_prefix $(Build.BinariesDirectory)\$(BuildConfig)\installed -build_config $(BuildConfig) - task: NuGetToolInstaller@0 displayName: Use Nuget 5.7.0 diff --git a/tools/ci_build/github/azure-pipelines/win-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/win-ci-pipeline.yml index f2d8853371..64c39c64c4 100644 --- a/tools/ci_build/github/azure-pipelines/win-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/win-ci-pipeline.yml @@ -13,7 +13,7 @@ stages: BuildConfig: 'Debug' EnvSetupScript: setup_env.bat buildArch: x64 - additionalBuildFlags: --build_java --build_nodejs --build_wheel + additionalBuildFlags: --build_java --build_nodejs --build_wheel --disable_memleak_checker msbuildPlatform: x64 isX86: false job_name_suffix: x64_debug @@ -131,7 +131,7 @@ stages: BuildConfig: 'Debug' EnvSetupScript: setup_env.bat buildArch: x64 - additionalBuildFlags: --enable_training --build_wheel + additionalBuildFlags: --enable_training --build_wheel --disable_memleak_checker msbuildPlatform: x64 isX86: false job_name_suffix: training_x64_debug @@ -179,4 +179,4 @@ stages: isTraining: true ORT_EP_NAME: CPU GenerateDocumentation: false - MachinePool: 'onnxruntime-Win2019-CPU-training' + MachinePool: 'onnxruntime-Win2019-CPU-training' \ No newline at end of file diff --git a/tools/ci_build/github/azure-pipelines/win-gpu-reduce-op-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/win-gpu-reduce-op-ci-pipeline.yml index 510225e69c..aa265bce24 100644 --- a/tools/ci_build/github/azure-pipelines/win-gpu-reduce-op-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/win-gpu-reduce-op-ci-pipeline.yml @@ -38,15 +38,12 @@ jobs: workingDirectory: '$(Build.BinariesDirectory)' displayName: 'Install python modules' - - powershell: | - $Env:USE_MSVC_STATIC_RUNTIME=1 - $Env:ONNX_ML=1 - $Env:CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=$(buildArch)-windows-static" - python setup.py bdist_wheel - python -m pip uninstall -y onnx -qq - Get-ChildItem -Path dist/*.whl | foreach {pip --disable-pip-version-check install --upgrade $_.fullname} - workingDirectory: '$(Build.SourcesDirectory)\cmake\external\onnx' + - task: PowerShell@2 displayName: 'Install ONNX' + inputs: + filePath: '$(Build.SourcesDirectory)/tools/ci_build/github/windows/install_third_party_deps.ps1' + workingDirectory: '$(Build.BinariesDirectory)' + arguments: -cpu_arch x64 -install_prefix $(Build.BinariesDirectory)\$(BuildConfig)\installed -build_config $(BuildConfig) - task: PythonScript@0 displayName: 'Build and test' diff --git a/tools/ci_build/github/azure-pipelines/win-gpu-tensorrt-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/win-gpu-tensorrt-ci-pipeline.yml index 0aba08795f..5ff784bf1b 100644 --- a/tools/ci_build/github/azure-pipelines/win-gpu-tensorrt-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/win-gpu-tensorrt-ci-pipeline.yml @@ -34,15 +34,21 @@ jobs: workingDirectory: '$(Build.BinariesDirectory)' displayName: 'Install python modules' - - powershell: | - $Env:USE_MSVC_STATIC_RUNTIME=1 - $Env:ONNX_ML=1 - $Env:CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=$(buildArch)-windows-static" - python setup.py bdist_wheel - python -m pip uninstall -y onnx -qq - Get-ChildItem -Path dist/*.whl | foreach {pip --disable-pip-version-check install --upgrade $_.fullname} - workingDirectory: '$(Build.SourcesDirectory)\cmake\external\onnx' + - template: templates/download-deps.yml + + - task: PythonScript@0 + displayName: 'Update deps.txt' + inputs: + scriptPath: $(Build.SourcesDirectory)/tools/ci_build/replace_urls_in_deps.py + arguments: --new_dir $(Build.BinariesDirectory)/deps + workingDirectory: $(Build.BinariesDirectory) + + - task: PowerShell@2 displayName: 'Install ONNX' + inputs: + filePath: '$(Build.SourcesDirectory)/tools/ci_build/github/windows/install_third_party_deps.ps1' + workingDirectory: '$(Build.BinariesDirectory)' + arguments: -cpu_arch x64 -install_prefix $(Build.BinariesDirectory)\$(BuildConfig)\installed -build_config $(BuildConfig) - task: PythonScript@0 displayName: 'Generate cmake config' diff --git a/tools/ci_build/github/linux/build_linux_arm64_python_package.sh b/tools/ci_build/github/linux/build_linux_arm64_python_package.sh index a56e385b35..e272339a4d 100755 --- a/tools/ci_build/github/linux/build_linux_arm64_python_package.sh +++ b/tools/ci_build/github/linux/build_linux_arm64_python_package.sh @@ -7,11 +7,13 @@ CXXFLAGS="-Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-st BUILD_DEVICE="CPU" BUILD_CONFIG="Release" +PYTHON_EXES=("/opt/python/cp37-cp37m/bin/python3.7" "/opt/python/cp38-cp38/bin/python3.8" "/opt/python/cp39-cp39/bin/python3.9" "/opt/python/cp310-cp310/bin/python3.10") while getopts "d:" parameter_Option do case "${parameter_Option}" in -#GPU or CPU. +#GPU or CPU. d) BUILD_DEVICE=${OPTARG};; +p) PYTHON_EXES=(${OPTARG});; esac done @@ -45,11 +47,10 @@ if [ "$BUILD_DEVICE" == "GPU" ]; then fi export CFLAGS export CXXFLAGS -PYTHON_EXES=("/opt/python/cp37-cp37m/bin/python3.7" "/opt/python/cp38-cp38/bin/python3.8" "/opt/python/cp39-cp39/bin/python3.9" "/opt/python/cp310-cp310/bin/python3.10") for PYTHON_EXE in "${PYTHON_EXES[@]}" do rm -rf /build/$BUILD_CONFIG ${PYTHON_EXE} /onnxruntime_src/tools/ci_build/build.py "${BUILD_ARGS[@]}" - + cp /build/$BUILD_CONFIG/dist/*.whl /build/dist done diff --git a/tools/ci_build/github/linux/docker/inference/x64/python/cpu/scripts/install_deps.sh b/tools/ci_build/github/linux/docker/inference/x64/python/cpu/scripts/install_deps.sh index 2f02c4e77a..f9106f586c 100755 --- a/tools/ci_build/github/linux/docker/inference/x64/python/cpu/scripts/install_deps.sh +++ b/tools/ci_build/github/linux/docker/inference/x64/python/cpu/scripts/install_deps.sh @@ -14,10 +14,5 @@ for PYTHON_EXE in "${PYTHON_EXES[@]}" do ${PYTHON_EXE} -m pip install -r requirements.txt done -if [ -f "/tmp/protobuf_install_manifest.txt" ]; then - echo "Uninstalling protobuf..." - xargs rm -f < /tmp/protobuf_install_manifest.txt - rm /tmp/protobuf_install_manifest.txt -fi diff --git a/tools/ci_build/github/linux/docker/inference/x64/python/cpu/scripts/install_protobuf.sh b/tools/ci_build/github/linux/docker/inference/x64/python/cpu/scripts/install_protobuf.sh index 56426e708a..537019d513 100755 --- a/tools/ci_build/github/linux/docker/inference/x64/python/cpu/scripts/install_protobuf.sh +++ b/tools/ci_build/github/linux/docker/inference/x64/python/cpu/scripts/install_protobuf.sh @@ -1,43 +1,51 @@ #!/bin/bash -set -e -#Download a file from internet -function GetFile { - local uri=$1 - local path=$2 - local force=${3:-false} - local download_retries=${4:-5} - local retry_wait_time_seconds=${5:-30} +set -e -x - if [[ -f $path ]]; then - if [[ $force = false ]]; then - echo "File '$path' already exists. Skipping download" - return 0 - else - rm -rf $path +INSTALL_PREFIX='/usr' +DEP_FILE_PATH='/tmp/scripts/deps.txt' +while getopts "p:d:" parameter_Option +do case "${parameter_Option}" +in +p) INSTALL_PREFIX=${OPTARG};; +d) DEP_FILE_PATH=${OPTARG};; +esac +done + +EXTRA_CMAKE_ARGS="" + +case "$(uname -s)" in + Darwin*) + echo 'Building ONNX Runtime on Mac OS X' + EXTRA_CMAKE_ARGS="-DCMAKE_OSX_ARCHITECTURES=x86_64;arm64" + ;; + Linux*) + # Depending on how the compiler has been configured when it was built, sometimes "gcc -dumpversion" shows the full version. + GCC_VERSION=$(gcc -dumpversion | cut -d . -f 1) + #-fstack-clash-protection prevents attacks based on an overlapping heap and stack. + if [ "$GCC_VERSION" -ge 8 ]; then + CFLAGS="$CFLAGS -fstack-clash-protection" + CXXFLAGS="$CXXFLAGS -fstack-clash-protection" fi - fi + ARCH=$(uname -m) - if [[ -f $uri ]]; then - echo "'$uri' is a file path, copying file to '$path'" - cp $uri $path - return $? - fi - - echo "Downloading $uri" - # Use aria2c if available, otherwise use curl - if command -v aria2c > /dev/null; then - aria2c -q -d $(dirname $path) -o $(basename $path) "$uri" - else - curl "$uri" -sSL --retry $download_retries --retry-delay $retry_wait_time_seconds --create-dirs -o "$path" --fail - fi - - return $? -} - -GetFile https://github.com/protocolbuffers/protobuf/archive/v3.18.1.tar.gz protobuf_src.tar.gz -tar -xf protobuf_src.tar.gz -cd protobuf-3.18.1 -cmake ./cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Relwithdebinfo + if [ "$ARCH" == "x86_64" ] && [ "$GCC_VERSION" -ge 9 ]; then + CFLAGS="$CFLAGS -fcf-protection" + CXXFLAGS="$CXXFLAGS -fcf-protection" + fi + export CFLAGS + export CXXFLAGS + ;; + *) + exit -1 +esac +mkdir -p $INSTALL_PREFIX +echo "Installing protobuf ..." +protobuf_url=$(grep '^protobuf' $DEP_FILE_PATH | cut -d ';' -f 2 | sed 's/\.zip$/\.tar.gz/') +curl -sSL --retry 5 --retry-delay 10 --create-dirs --fail -L -o protobuf_src.tar.gz $protobuf_url +mkdir protobuf +cd protobuf +tar -zxf ../protobuf_src.tar.gz --strip=1 +cmake ./cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -Dprotobuf_WITH_ZLIB_DEFAULT=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF $EXTRA_CMAKE_ARGS make -j$(getconf _NPROCESSORS_ONLN) make install -cp install_manifest.txt /tmp/protobuf_install_manifest.txt \ No newline at end of file +cd .. \ No newline at end of file diff --git a/tools/ci_build/github/linux/docker/inference/x64/python/cpu/scripts/requirements.txt b/tools/ci_build/github/linux/docker/inference/x64/python/cpu/scripts/requirements.txt index b678ed2109..2c329b32c5 100644 --- a/tools/ci_build/github/linux/docker/inference/x64/python/cpu/scripts/requirements.txt +++ b/tools/ci_build/github/linux/docker/inference/x64/python/cpu/scripts/requirements.txt @@ -3,7 +3,7 @@ mypy pytest setuptools>=41.4.0 wheel -onnx==1.12.0 +git+http://github.com/onnx/onnx.git@5a5f8a5935762397aa68429b5493084ff970f774#egg=onnx protobuf==3.18.3 sympy==1.10.1 flatbuffers diff --git a/tools/ci_build/github/pai/migraphx-ci-pipeline-env.Dockerfile b/tools/ci_build/github/linux/docker/migraphx-ci-pipeline-env.Dockerfile similarity index 81% rename from tools/ci_build/github/pai/migraphx-ci-pipeline-env.Dockerfile rename to tools/ci_build/github/linux/docker/migraphx-ci-pipeline-env.Dockerfile index db7351f667..003a3ff075 100644 --- a/tools/ci_build/github/pai/migraphx-ci-pipeline-env.Dockerfile +++ b/tools/ci_build/github/linux/docker/migraphx-ci-pipeline-env.Dockerfile @@ -3,7 +3,7 @@ FROM rocm/pytorch:rocm5.2.3_ubuntu20.04_py3.7_pytorch_1.12.1 ENV DEBIAN_FRONTEND noninteractive ENV MIGRAPHX_DISABLE_FAST_GELU=1 -RUN apt-get clean && apt-get update && apt-get install -y locales +RUN apt-get clean && apt-get update && apt-get install -y locales unzip RUN locale-gen en_US.UTF-8 RUN update-locale LANG=en_US.UTF-8 ENV LC_ALL C.UTF-8 @@ -11,6 +11,9 @@ ENV LANG C.UTF-8 WORKDIR /stage +ADD scripts /tmp/scripts +RUN /tmp/scripts/install_os_deps.sh + # from rocm/pytorch's image, work around ucx's dlopen replacement conflicting with shared provider RUN cd /opt/mpi_install/ucx/build &&\ make clean &&\ @@ -18,11 +21,7 @@ RUN cd /opt/mpi_install/ucx/build &&\ make -j $(nproc) &&\ make install -# CMake -ENV CMAKE_VERSION=3.24.2 -RUN cd /usr/local && \ - wget -q -O - https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-Linux-x86_64.tar.gz | tar zxf - -ENV PATH=/usr/local/cmake-${CMAKE_VERSION}-linux-x86_64/bin:${PATH} + RUN apt-get update &&\ apt-get install -y half libnuma-dev diff --git a/tools/ci_build/github/linux/docker/scripts/install_protobuf.sh b/tools/ci_build/github/linux/docker/scripts/install_protobuf.sh index dff4d2e282..1a8aa8c6d1 100755 --- a/tools/ci_build/github/linux/docker/scripts/install_protobuf.sh +++ b/tools/ci_build/github/linux/docker/scripts/install_protobuf.sh @@ -1,42 +1,51 @@ #!/bin/bash -set -e -#Download a file from internet -function GetFile { - local uri=$1 - local path=$2 - local force=${3:-false} - local download_retries=${4:-5} - local retry_wait_time_seconds=${5:-30} +set -e -x - if [[ -f $path ]]; then - if [[ $force = false ]]; then - echo "File '$path' already exists. Skipping download" - return 0 - else - rm -rf $path +INSTALL_PREFIX='/usr' +DEP_FILE_PATH='/tmp/scripts/deps.txt' +while getopts "p:d:" parameter_Option +do case "${parameter_Option}" +in +p) INSTALL_PREFIX=${OPTARG};; +d) DEP_FILE_PATH=${OPTARG};; +esac +done + +EXTRA_CMAKE_ARGS="" + +case "$(uname -s)" in + Darwin*) + echo 'Building ONNX Runtime on Mac OS X' + EXTRA_CMAKE_ARGS="-DCMAKE_OSX_ARCHITECTURES=x86_64;arm64" + ;; + Linux*) + # Depending on how the compiler has been configured when it was built, sometimes "gcc -dumpversion" shows the full version. + GCC_VERSION=$(gcc -dumpversion | cut -d . -f 1) + #-fstack-clash-protection prevents attacks based on an overlapping heap and stack. + if [ "$GCC_VERSION" -ge 8 ]; then + CFLAGS="$CFLAGS -fstack-clash-protection" + CXXFLAGS="$CXXFLAGS -fstack-clash-protection" fi - fi + ARCH=$(uname -m) - if [[ -f $uri ]]; then - echo "'$uri' is a file path, copying file to '$path'" - cp $uri $path - return $? - fi - - echo "Downloading $uri" - # Use aria2c if available, otherwise use curl - if command -v aria2c > /dev/null; then - aria2c -q -d $(dirname $path) -o $(basename $path) "$uri" - else - curl "$uri" -sSL --retry $download_retries --retry-delay $retry_wait_time_seconds --create-dirs -o "$path" --fail - fi - - return $? -} - -GetFile https://github.com/protocolbuffers/protobuf/archive/v3.18.1.tar.gz /tmp/src/v3.18.1.tar.gz -tar -xf /tmp/src/v3.18.1.tar.gz -C /tmp/src -cd /tmp/src/protobuf-3.18.1 -cmake ./cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Relwithdebinfo + if [ "$ARCH" == "x86_64" ] && [ "$GCC_VERSION" -ge 9 ]; then + CFLAGS="$CFLAGS -fcf-protection" + CXXFLAGS="$CXXFLAGS -fcf-protection" + fi + export CFLAGS + export CXXFLAGS + ;; + *) + exit -1 +esac +mkdir -p $INSTALL_PREFIX +echo "Installing protobuf ..." +protobuf_url=$(grep '^protobuf' $DEP_FILE_PATH | cut -d ';' -f 2 | sed 's/\.zip$/\.tar.gz/') +curl -sSL --retry 5 --retry-delay 10 --create-dirs --fail -L -o protobuf_src.tar.gz $protobuf_url +mkdir protobuf +cd protobuf +tar -zxf ../protobuf_src.tar.gz --strip=1 +cmake ./cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -Dprotobuf_WITH_ZLIB_DEFAULT=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF $EXTRA_CMAKE_ARGS make -j$(getconf _NPROCESSORS_ONLN) make install +cd .. diff --git a/tools/ci_build/github/linux/run_python_dockerbuild.sh b/tools/ci_build/github/linux/run_python_dockerbuild.sh new file mode 100755 index 0000000000..b31029713d --- /dev/null +++ b/tools/ci_build/github/linux/run_python_dockerbuild.sh @@ -0,0 +1,27 @@ +#!/bin/bash +set -e -x +while getopts "x:i:" parameter_Option +do case "${parameter_Option}" +in +i) DOCKER_IMAGE=${OPTARG};; +x) BUILD_EXTR_PAR=${OPTARG};; +esac +done + +mkdir -p $HOME/.onnx +docker run --rm \ + --volume /data/onnx:/data/onnx:ro \ + --volume $BUILD_SOURCESDIRECTORY:/onnxruntime_src \ + --volume $BUILD_BINARIESDIRECTORY:/build \ + --volume /data/models:/build/models:ro \ + --volume $HOME/.onnx:/home/onnxruntimedev/.onnx \ + -w /onnxruntime_src \ + -e NIGHTLY_BUILD \ + -e BUILD_BUILDNUMBER \ + $DOCKER_IMAGE tools/ci_build/github/linux/build_linux_arm64_python_package.sh $BUILD_EXTR_PAR + +rm -rf $BUILD_BINARIESDIRECTORY/Release/onnxruntime $BUILD_BINARIESDIRECTORY/Release/pybind11 \ + $BUILD_BINARIESDIRECTORY/Release/models $BUILD_BINARIESDIRECTORY/Release/_deps \ + $BUILD_BINARIESDIRECTORY/Release/CMakeFiles +cd $BUILD_BINARIESDIRECTORY/Release +find -executable -type f > $BUILD_BINARIESDIRECTORY/Release/perms.txt diff --git a/tools/ci_build/github/windows/install_third_party_deps.ps1 b/tools/ci_build/github/windows/install_third_party_deps.ps1 new file mode 100644 index 0000000000..b2e3feafa0 --- /dev/null +++ b/tools/ci_build/github/windows/install_third_party_deps.ps1 @@ -0,0 +1,60 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + + param ( + [string]$cpu_arch = "x64", + [string]$build_config = "RelWithDebInfo", + [string]$install_prefix + ) + +$ErrorActionPreference = "Stop" + +$env:Path = "$install_prefix\bin;C:\Program Files\7-Zip;" + $env:Path + +New-Item -Path "$install_prefix" -ItemType Directory -Force + +$cmake_extra_args=@() +if($cpu_arch -eq 'x86'){ + Write-Host "Build for x86" + $cmake_extra_args="-A", "Win32", "-T", "host=x64" +} else { + Write-Host "Build for $cpu_arch" +} + +$url='https://github.com/pybind/pybind11/archive/refs/tags/v2.10.1.zip' +Write-Host "Downloading pybind11 from $url" +Invoke-WebRequest -Uri $url -OutFile pybind11.zip +7z x pybind11.zip +cd pybind11-2.10.1 +mkdir build +cd build + +cmake .. "-DCMAKE_INSTALL_PREFIX=$install_prefix" -DBUILD_TESTING=OFF $cmake_extra_args +cmake --build . --parallel --config $build_config --target INSTALL +cd ../.. + +$protobuf_version="3.18.3" +$url="https://github.com/protocolbuffers/protobuf/releases/download/v$protobuf_version/protobuf-cpp-$protobuf_version.zip" +Write-Host "Downloading protobuf from $url" +Invoke-WebRequest -Uri $url -OutFile protobuf_src.zip +7z x protobuf_src.zip +cd protobuf-$protobuf_version +Get-Content $Env:BUILD_SOURCESDIRECTORY\cmake\patches\protobuf\protobuf_cmake.patch | &'C:\Program Files\Git\usr\bin\patch.exe' --binary --ignore-whitespace -p1 +cmake cmake -DCMAKE_BUILD_TYPE=$build_config -Dprotobuf_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF "-DCMAKE_PREFIX_PATH=$install_prefix" "-DCMAKE_INSTALL_PREFIX=$install_prefix" -Dprotobuf_MSVC_STATIC_RUNTIME=OFF $cmake_extra_args +cmake --build . --parallel --config $build_config --target INSTALL +cd .. +python -m pip install -q setuptools wheel numpy protobuf==$protobuf_version pybind11 +$onnx_commit_id="5a5f8a5935762397aa68429b5493084ff970f774" +$url="https://github.com/onnx/onnx/archive/$onnx_commit_id.zip" +Write-Host "Downloading onnx from $url" +Invoke-WebRequest -Uri $url -OutFile onnx.zip +7z x onnx.zip +cd "onnx-$onnx_commit_id" +$Env:ONNX_ML=1 +if($build_config -eq 'Debug'){ + $Env:DEBUG='1' +} +$Env:CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=OFF" +python setup.py bdist_wheel +python -m pip uninstall -y onnx -qq +Get-ChildItem -Path dist/*.whl | foreach {pip --disable-pip-version-check install --upgrade $_.fullname} \ No newline at end of file