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] Supprt CoreML feature, Download CMake scripts from upstream #265

Merged
merged 4 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
109 changes: 0 additions & 109 deletions ports/onnxruntime/cuDNN.cmake

This file was deleted.

42 changes: 42 additions & 0 deletions ports/onnxruntime/fix-cmake-coreml.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
diff --git a/cmake/onnxruntime_providers_coreml.cmake b/cmake/onnxruntime_providers_coreml.cmake
index 0aa25a2..1cb768c 100644
--- a/cmake/onnxruntime_providers_coreml.cmake
+++ b/cmake/onnxruntime_providers_coreml.cmake
@@ -9,7 +9,7 @@ add_compile_definitions(USE_COREML=1)

# Check if we can build the coremltools code for creating an mlpackage with an mlprogram.
# The coremltools source requires std::filesystem::path which is only available from iOS 13 on.
-set(_enable_ML_PROGRAM ON)
+option(_enable_ML_PROGRAM "..." ON)
if (IOS AND CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 13.0)
message(WARNING "CoreML ML Program is not supported on iOS < 13.0. Excluding ML Program support from build.")
set(_enable_ML_PROGRAM OFF)
@@ -29,7 +29,9 @@ if (_enable_ML_PROGRAM)
endif()

# Compile CoreML proto definition to ${CMAKE_CURRENT_BINARY_DIR}/coreml_proto
-set(COREML_PROTO_ROOT ${coremltools_SOURCE_DIR}/mlmodel/format)
+if(NOT DEFINED COREML_PROTO_ROOT)
+ set(COREML_PROTO_ROOT ${coremltools_SOURCE_DIR}/mlmodel/format)
+endif()
file(GLOB coreml_proto_srcs "${COREML_PROTO_ROOT}/*.proto")

onnxruntime_add_static_library(coreml_proto ${coreml_proto_srcs})
@@ -62,7 +64,7 @@ endif()
# Separate source_group for each as the .proto files are in the repo and the .cc/.h files are generated in the build
# output directory.
set_target_properties(coreml_proto PROPERTIES FOLDER "External")
-source_group(TREE ${COREML_PROTO_ROOT} PREFIX coreml_proto FILES ${coreml_proto_srcs})
+# source_group(TREE ${COREML_PROTO_ROOT} PREFIX coreml_proto FILES ${coreml_proto_srcs})

# filter to the generated .cc/.h files
get_target_property(coreml_proto_generated_srcs coreml_proto SOURCES)
@@ -119,7 +121,7 @@ if(_enable_ML_PROGRAM)
${onnxruntime_providers_coreml_modelpackage_cc_srcs}
)

- source_group(TREE ${coremltools_SOURCE_DIR} PREFIX coremltools FILES ${coremltools_srcs})
+ # source_group(TREE ${coremltools_SOURCE_DIR} PREFIX coremltools FILES ${coremltools_srcs})
endif()

# Add CoreML objective c++ source code
23 changes: 15 additions & 8 deletions ports/onnxruntime/onnxruntime_external_deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -630,14 +630,21 @@ if(onnxruntime_ENABLE_TRAINING OR (onnxruntime_ENABLE_TRAINING_APIS AND onnxrunt
endif()

if (onnxruntime_USE_COREML)
FetchContent_Declare(
coremltools
URL ${DEP_URL_coremltools}
URL_HASH SHA1=${DEP_SHA1_coremltools}
PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/coremltools/crossplatformbuild.patch
)
# we don't build directly so use Populate. selected files are built from onnxruntime_providers_coreml.cmake
FetchContent_Populate(coremltools)
if(onnxruntime_USE_VCPKG)
# using vcpkg-registry 'coreml-tools'
# check onnxruntime_providers_coreml.cmake together
find_path(COREML_PROTO_INCLUDE_DIR NAMES "mlmodel/format/Model.proto" REQUIRED)
get_filename_component(COREML_PROTO_ROOT "${COREML_PROTO_INCLUDE_DIR}/mlmodel/format" ABSOLUTE)
else()
FetchContent_Declare(
coremltools
URL ${DEP_URL_coremltools}
URL_HASH SHA1=${DEP_SHA1_coremltools}
PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/coremltools/crossplatformbuild.patch
)
# we don't build directly so use Populate. selected files are built from onnxruntime_providers_coreml.cmake
FetchContent_Populate(coremltools)
endif()
endif()

message(STATUS "Finished fetching external dependencies")
Expand Down
34 changes: 30 additions & 4 deletions ports/onnxruntime/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY)
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" BUILD_SHARED)

set(ORT_GIT_COMMIT "26250ae74d2c9a3c6860625ba4a147ddfb936907")
set(ORT_GIT_BRANCH "v${VERSION}")

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO microsoft/onnxruntime
REF "v${VERSION}"
REF ${ORT_GIT_BRANCH}
SHA512 da0cd297ffc11e2f627a91e55476952b2511e36bf97fb0d9a0a8b1e2cbd12a451e1a8ead1581bfe03d08c97946f0938434edd4637cbeb28f7007533d4b37ee55
PATCHES
fix-cmake.patch
fix-cmake-cuda.patch
fix-cmake-training.patch
fix-cmake-tensorrt.patch
fix-cmake-coreml.patch
fix-sources.patch
fix-clang-cl-simd-compile.patch
)
file(COPY "${CMAKE_CURRENT_LIST_DIR}/onnxruntime_external_deps.cmake" DESTINATION "${SOURCE_PATH}/cmake/external")
file(COPY "${CMAKE_CURRENT_LIST_DIR}/cuDNN.cmake" DESTINATION "${SOURCE_PATH}/cmake/external")

# todo: remove when release branch contains the files
vcpkg_download_distfile(EXTERNAL_ABSEIL_CPP_CMAKE_PATH
URLS "https://raw.githubusercontent.com/microsoft/onnxruntime/main/cmake/external/abseil-cpp.cmake?full_index=1"
FILENAME onnxruntime-external-abseil.cmake
SKIP_SHA512
)
vcpkg_download_distfile(EXTERNAL_CUDNN_CMAKE_PATH
URLS "https://raw.githubusercontent.com/microsoft/onnxruntime/main/cmake/external/cuDNN.cmake?full_index=1"
FILENAME onnxruntime-external-cuDNN.cmake
SKIP_SHA512
)
file(COPY_FILE "${EXTERNAL_ABSEIL_CPP_CMAKE_PATH}" "${SOURCE_PATH}/cmake/external/abseil-cpp.cmake" ONLY_IF_DIFFERENT)
file(COPY_FILE "${EXTERNAL_CUDNN_CMAKE_PATH}" "${SOURCE_PATH}/cmake/external/cuDNN.cmake" ONLY_IF_DIFFERENT)

find_program(PROTOC NAMES protoc
PATHS "${CURRENT_HOST_INSTALLED_DIR}/tools/protobuf"
Expand Down Expand Up @@ -98,6 +115,12 @@ if("tensorrt" IN_LIST FEATURES)
list(APPEND FEATURE_OPTIONS "-Donnxruntime_TENSORRT_HOME:PATH=${TENSORRT_ROOT}")
endif()
endif()
if("coreml" IN_LIST FEATURES)
list(APPEND FEATURE_OPTIONS
-D_enable_ML_PROGRAM=OFF # do not build CoreML Tools program
"-Dcoreml_INCLUDE_DIRS:PATH=${CURRENT_INSTALLED_DIR}/include"
)
endif()

# see tools/ci_build/build.py
vcpkg_cmake_configure(
Expand Down Expand Up @@ -128,8 +151,8 @@ vcpkg_cmake_configure(
-Donnxruntime_USE_NEURAL_SPEED=OFF
-DUSE_NEURAL_SPEED=OFF
# for ORT_BUILD_INFO
"-DORT_GIT_COMMIT:STRING=26250ae74d2c9a3c6860625ba4a147ddfb936907"
"-DORT_GIT_BRANCH:STRING=v${VERSION}"
-DORT_GIT_COMMIT=${ORT_GIT_COMMIT}
-DORT_GIT_BRANCH=${ORT_GIT_BRANCH}
--compile-no-warning-as-error
OPTIONS_DEBUG
-Donnxruntime_ENABLE_MEMLEAK_CHECKER=OFF
Expand All @@ -151,6 +174,9 @@ endif()
if("directml" IN_LIST FEATURES)
vcpkg_cmake_build(TARGET onnxruntime_providers_dml LOGFILE_BASE build-directml)
endif()
if("coreml" IN_LIST FEATURES)
vcpkg_cmake_build(TARGET onnxruntime_providers_coreml LOGFILE_BASE build-coreml)
endif()
if("training" IN_LIST FEATURES)
vcpkg_cmake_build(TARGET tensorboard LOGFILE_BASE build-tensorboard)
endif()
Expand Down
8 changes: 8 additions & 0 deletions ports/onnxruntime/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "onnxruntime",
"version-semver": "1.19.0",
"port-version": 1,
"description": "ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator",
"homepage": "https://onnxruntime.ai/",
"license": "MIT",
Expand Down Expand Up @@ -71,6 +72,13 @@
"wil"
],
"features": {
"coreml": {
"description": "Build with CoreML support",
"supports": "osx | ios",
"dependencies": [
"coreml-tools"
]
},
"cuda": {
"description": "Build with CUDA support",
"dependencies": [
Expand Down
2 changes: 1 addition & 1 deletion test/azure-port-osx.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tensorflow-lite[gpu]
onnxruntime[framework]
onnxruntime[framework,coreml]
metal-cpp
miniaudio
abseil
7 changes: 7 additions & 0 deletions test/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@
"test"
]
},
{
"name": "onnxruntime",
"features": [
"test"
],
"platform": "osx | linux"
},
{
"name": "opencl",
"platform": "windows | linux"
Expand Down
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
},
"onnxruntime": {
"baseline": "1.19.0",
"port-version": 0
"port-version": 1
},
"opencl": {
"baseline": "v2024.05.08",
Expand Down
5 changes: 5 additions & 0 deletions versions/o-/onnxruntime.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "9eb55d7729512170d6b61045036bba2ac0d8aa91",
"version-semver": "1.19.0",
"port-version": 1
},
{
"git-tree": "af74437fc8574baf7c2f36f729493f7be3059d5a",
"version-semver": "1.19.0",
Expand Down
Loading