Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[onnxruntime] Refactor install process #23768

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ports/onnxruntime-gpu/fix-build-issues.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
index aaa8a02..41c9b97 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -1214,7 +1214,7 @@ function(onnxruntime_add_shared_library target_name)
endfunction()

function(onnxruntime_add_static_library target_name)
- add_library(${target_name} ${ARGN})
+ add_library(${target_name} STATIC ${ARGN})
onnxruntime_configure_target(${target_name})
endfunction()

150 changes: 150 additions & 0 deletions ports/onnxruntime-gpu/fix-dependencies.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index acbde7f..c712ba7 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -718,8 +718,13 @@ if (onnxruntime_BUILD_BENCHMARKS)
endif()
endif()

-if (NOT WIN32 AND NOT onnxruntime_PREFER_SYSTEM_LIB)
+if (NOT WIN32)
+ if (NOT onnxruntime_PREFER_SYSTEM_LIB)
add_subdirectory(${PROJECT_SOURCE_DIR}/external/nsync EXCLUDE_FROM_ALL)
+ else()
+ find_package(unofficial-nsync CONFIG REQUIRED)
+ get_target_property(NSYNC_INCLUDE_DIR unofficial::nsync::nsync_cpp INTERFACE_INCLUDE_DIRECTORIES)
+ endif()
endif()
# External dependencies
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/external)
@@ -833,20 +838,20 @@ else()
add_subdirectory(external/date EXCLUDE_FROM_ALL)
endif()

-set(SAFEINT_INCLUDE_DIR ${REPO_ROOT}/cmake/external/SafeInt)
+find_path(SAFEINT_INCLUDE_DIR NAMES "SafeInt.hpp" PATHS_SUFFIXES include)
add_library(safeint_interface INTERFACE)
target_include_directories(safeint_interface INTERFACE ${SAFEINT_INCLUDE_DIR})

if (onnxruntime_PREFER_SYSTEM_LIB)
- find_package(boost_mp11)
+ find_path(BOOST_MP11_INCLUDES NAMES mp11.hpp PATH_SUFFIXES include/boost)
+ add_library(Boost::mp11 INTERFACE IMPORTED)
+ target_include_directories(Boost::mp11 INTERFACE ${BOOST_MP11_INCLUDES})
endif()
if (NOT TARGET Boost::mp11)
add_subdirectory(external/mp11 EXCLUDE_FROM_ALL)
endif()

-set(JSON_BuildTests OFF CACHE INTERNAL "")
-set(JSON_Install OFF CACHE INTERNAL "")
-add_subdirectory(external/json EXCLUDE_FROM_ALL)
+find_package(nlohmann_json CONFIG REQUIRED)

if (onnxruntime_PREFER_SYSTEM_LIB)
find_package(re2)
@@ -894,6 +899,9 @@ endif()

# TODO do we have to add target_include_directories to each project that uses this?
if (CPUINFO_SUPPORTED)
+ find_package(unofficial-cpuinfo CONFIG REQUIRED)
+ add_library(cpuinfo ALIAS unofficial::cpuinfo::cpuinfo)
+ if (0)
set(PYTORCH_CPUINFO_DIR external/pytorch_cpuinfo)
set(PYTORCH_CPUINFO_INCLUDE_DIR ${PYTORCH_CPUINFO_DIR}/include)
set(CPUINFO_BUILD_TOOLS OFF CACHE INTERNAL "")
@@ -911,6 +919,7 @@ if (CPUINFO_SUPPORTED)
if (MSVC)
target_compile_options(cpuinfo PRIVATE "-D_CRT_SECURE_NO_WARNINGS")
endif()
+ endif()
endif()

# bounds checking behavior.
@@ -1165,7 +1174,7 @@ function(onnxruntime_set_compile_flags target_name)
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 "${NSYNC_INCLUDE_DIR}")
endif()
foreach(ORT_FLAG ${ORT_PROVIDER_FLAGS})
target_compile_definitions(${target_name} PRIVATE ${ORT_FLAG})
@@ -1388,12 +1397,14 @@ else()
include(onnx_minimal)
endif()

+if (0)
target_compile_definitions(onnx PUBLIC $<TARGET_PROPERTY:onnx_proto,INTERFACE_COMPILE_DEFINITIONS> 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")
+endif()


# fix a warning in onnx code we can't do anything about
diff --git a/cmake/external/eigen.cmake b/cmake/external/eigen.cmake
index 264247a..f5908ab 100644
--- a/cmake/external/eigen.cmake
+++ b/cmake/external/eigen.cmake
@@ -1,9 +1,8 @@
include (ExternalProject)

if (onnxruntime_USE_PREINSTALLED_EIGEN)
- add_library(eigen INTERFACE)
- file(TO_CMAKE_PATH ${eigen_SOURCE_PATH} eigen_INCLUDE_DIRS)
- target_include_directories(eigen INTERFACE ${eigen_INCLUDE_DIRS})
+ find_package(Eigen3 CONFIG REQUIRED)
+ add_library(eigen ALIAS Eigen3::Eigen)
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})
diff --git a/cmake/external/onnx_minimal.cmake b/cmake/external/onnx_minimal.cmake
index 33df1f5..13a0b3a 100644
--- a/cmake/external/onnx_minimal.cmake
+++ b/cmake/external/onnx_minimal.cmake
@@ -12,6 +12,9 @@ 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.

+find_package(ONNX CONFIG REQUIRED)
+
+if (0)
set(ONNX_SOURCE_ROOT ${PROJECT_SOURCE_DIR}/external/onnx)

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)
@@ -93,4 +96,5 @@ else()
target_compile_options(onnx PRIVATE "-Wno-unused-but-set-variable")
endif()
endif()
+endif()

diff --git a/cmake/wil.cmake b/cmake/wil.cmake
index 36a8bc9..0126a69 100644
--- a/cmake/wil.cmake
+++ b/cmake/wil.cmake
@@ -1,5 +1,5 @@
# 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
+find_package(wil CONFIG REQUIRED)
+add_library(wil ALIAS WIL::WIL)
\ No newline at end of file
diff --git a/onnxruntime/core/common/safeint.h b/onnxruntime/core/common/safeint.h
index 263e936..3ee70f3 100644
--- a/onnxruntime/core/common/safeint.h
+++ b/onnxruntime/core/common/safeint.h
@@ -32,7 +32,7 @@ class SafeIntExceptionHandler<onnxruntime::OnnxRuntimeException> {
#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
112 changes: 77 additions & 35 deletions ports/onnxruntime-gpu/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,41 +1,83 @@
vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY)

set(VERSION 1.5.1)

vcpkg_download_distfile(ARCHIVE
URLS "https://github.com/microsoft/onnxruntime/releases/download/v1.5.1/onnxruntime-win-x64-gpu-1.5.1.zip"
FILENAME "onnxruntime-win-x64-gpu-1.5.1.zip"
SHA512 893dbed1196b5c9730744dc5566cd3ad8ec677cbea04dd0572efc9a8b3563d3f1cbf40d0dea3d624d9451dc33272c0ae44d53d6deee6f249fa2520e60718ee52
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO microsoft/onnxruntime
REF 0d9030e79888d1d5828730b254fedc53c7b640c1 # v1.10.0
SHA512 502b68fae7d2e8441ec26253a9e0cdcf970ab2b61efecee7d964e9880e59d657971a82a666710944617c86d18fa99c2cb9640fcd15f63d05b2617b562a5bdb2f
HEAD_REF master
PATCHES
fix-dependencies.patch
fix-build-issues.patch
)

vcpkg_extract_source_archive_ex(
OUT_SOURCE_PATH SOURCE_PATH
ARCHIVE ${ARCHIVE}
NO_REMOVE_ONE_LEVEL
REF ${VERSION}
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" BUILD_SHARED)

if ("${VCPKG_HOST_TRIPLET}" STREQUAL "${VCPKG_TARGET_TRIPLET}")
set(BUILD_HOST ON)
set(CROSS_BUILD OFF)
else()
set(BUILD_HOST OFF)
set(CROSS_BUILD ON)
endif()
string(COMPARE EQUAL "${VCPKG_HOST_TRIPLET}" "${VCPKG_TARGET_TRIPLET}" BUILD_HOST)

vcpkg_find_acquire_program(PYTHON3)
get_filename_component(PYTHON_DIR "${PYTHON3}" PATH)
vcpkg_add_to_path(PREPEND "${PYTHON_DIR}")

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}/cmake"
OPTIONS
-Donnxruntime_BUILD_SHARED_LIB=${BUILD_SHARED}
-Donnxruntime_BUILD_FOR_NATIVE_MACHINE=${BUILD_HOST}
-Donnxruntime_CROSS_COMPILING=${CROSS_BUILD}
-DCMAKE_INSTALL_INCLUDEDIR=include
"-DPython_EXECUTABLE=${PYTHON3}"
-Donnxruntime_RUN_ONNX_TESTS=OFF
-Donnxruntime_GENERATE_TEST_REPORTS=OFF
-Donnxruntime_ENABLE_STATIC_ANALYSIS=OFF
-Donnxruntime_ENABLE_PYTHON=OFF
-Donnxruntime_ENABLE_MEMLEAK_CHECKER=OFF
-Donnxruntime_USE_CUDA=OFF
-Donnxruntime_ENABLE_CUDA_LINE_NUMBER_INFO=OFF
-Donnxruntime_USE_NNAPI_BUILTIN=OFF
-Donnxruntime_DEV_MODE=OFF
-Donnxruntime_BUILD_UNIT_TESTS=OFF
-Donnxruntime_BUILD_CSHARP=OFF
-Donnxruntime_BUILD_OBJC=OFF
-Donnxruntime_USE_PREINSTALLED_EIGEN=ON
-Donnxruntime_BUILD_BENCHMARKS=OFF
-Donnxruntime_USE_LLVM=OFF
-Donnxruntime_USE_AVX=OFF
-Donnxruntime_USE_AVX2=OFF
-Donnxruntime_USE_AVX512=OFF
-Donnxruntime_USE_OPENMP=OFF
-Donnxruntime_BUILD_APPLE_FRAMEWORK=OFF
-Donnxruntime_ENABLE_MICROSOFT_INTERNAL=OFF
-Donnxruntime_USE_TENSORRT=OFF
-Donnxruntime_ENABLE_LTO=ON
-Donnxruntime_DEBUG_NODE_INPUTS_OUTPUTS=OFF
-Donnxruntime_USE_ROCM=OFF # AMD GPU SUPPORT
-Donnxruntime_PREFER_SYSTEM_LIB=ON
-Donnxruntime_MINIMAL_BUILD=ON
-Donnxruntime_EXTENDED_MINIMAL_BUILD=OFF
-Donnxruntime_MINIMAL_BUILD_CUSTOM_OPS=OFF
-Donnxruntime_DISABLE_EXTERNAL_INITIALIZERS=OFF
-Donnxruntime_USE_VALGRIND=OFF
-Donnxruntime_RUN_MODELTEST_IN_DEBUG_MODE=OFF
-Donnxruntime_FUZZ_TEST=OFF
-Donnxruntime_USE_NCCL=OFF
-Donnxruntime_USE_MPI=OFF
-Donnxruntime_ENABLE_BITCODE=OFF
-Donnxruntime_BUILD_OPSCHEMA_LIB=ON
-Donnxruntime_USE_EXTENSIONS=OFF

)

file(MAKE_DIRECTORY
${CURRENT_PACKAGES_DIR}/include
${CURRENT_PACKAGES_DIR}/lib
${CURRENT_PACKAGES_DIR}/bin
${CURRENT_PACKAGES_DIR}/debug/lib
${CURRENT_PACKAGES_DIR}/debug/bin
)

file(COPY
${SOURCE_PATH}/onnxruntime-win-x64-gpu-1.5.1/include
DESTINATION ${CURRENT_PACKAGES_DIR}
)

file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-1.5.1/lib/onnxruntime.lib
DESTINATION ${CURRENT_PACKAGES_DIR}/lib)
file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-1.5.1/lib/onnxruntime.lib
DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib)
file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-1.5.1/lib/onnxruntime.dll
DESTINATION ${CURRENT_PACKAGES_DIR}/bin)
file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-1.5.1/lib/onnxruntime.dll
DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin)

# # Handle copyright
file(INSTALL ${SOURCE_PATH}/onnxruntime-win-x64-gpu-1.5.1/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
vcpkg_cmake_install()
vcpkg_copy_pdbs()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")

file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
26 changes: 23 additions & 3 deletions ports/onnxruntime-gpu/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
{
"name": "onnxruntime-gpu",
"version": "1.5.1",
"port-version": 1,
"version": "1.10.0",
"description": "onnxruntime (GPU)",
"homepage": "https://github.com/microsoft/onnxruntime",
"supports": "windows & !x86 & !uwp & !static & !arm"
"supports": "!uwp & !arm",
"dependencies": [
"boost-mp11",
"cpuinfo",
"date",
"eigen3",
"flatbuffers",
"nlohmann-json",
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
{
"name": "nsync",
"platform": "!windows"
},
"onnx",
"protobuf",
"re2",
"safeint",
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
"wil",
{
"name": "vcpkg-cmake",
"host": true
}
]
}