Skip to content

Commit

Permalink
feat: coreml
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Nov 6, 2024
1 parent 9b3dd4e commit dffe088
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 13 deletions.
86 changes: 86 additions & 0 deletions vcpkg-overlay/ports/maa-onnxruntime/0001-coremltools.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
diff --git a/cmake/onnxruntime_providers_coreml.cmake b/cmake/onnxruntime_providers_coreml.cmake
index 0aa25a2..b41eac7 100644
--- a/cmake/onnxruntime_providers_coreml.cmake
+++ b/cmake/onnxruntime_providers_coreml.cmake
@@ -9,27 +9,14 @@ 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)
-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)
-elseif(LINUX)
- # uuid-dev is required. we don't bother installing on CIs as it's really for manual developer testing.
- find_library(LibUUID_LIBRARY NAMES uuid)
- find_path(LibUUID_INCLUDE_DIR NAMES uuid/uuid.h)
- if (NOT LibUUID_INCLUDE_DIR)
- message(STATUS "uuid/uuid.h was not found as is required for ML Program support. "
- "Run `sudo apt install uuid-dev` if you need to test ML Program related CoreML EP code. ")
- set(_enable_ML_PROGRAM OFF)
- endif()
-endif()
+set(_enable_ML_PROGRAM OFF)

if (_enable_ML_PROGRAM)
add_compile_definitions(COREML_ENABLE_MLPROGRAM=1)
endif()

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

onnxruntime_add_static_library(coreml_proto ${coreml_proto_srcs})
@@ -98,20 +85,20 @@ if(_enable_ML_PROGRAM)
# build on Windows and Linux.
file(GLOB
onnxruntime_providers_coreml_milblob_cc_srcs CONFIGURE_DEPENDS
- "${coremltools_SOURCE_DIR}/mlmodel/src/MILBlob/*.hpp"
- "${coremltools_SOURCE_DIR}/mlmodel/src/MILBlob/*.cpp"
- "${coremltools_SOURCE_DIR}/mlmodel/src/MILBlob/Util/*.hpp"
- "${coremltools_SOURCE_DIR}/mlmodel/src/MILBlob/Blob/BlobDataType.hpp"
- "${coremltools_SOURCE_DIR}/mlmodel/src/MILBlob/Blob/StorageFormat.hpp"
- "${coremltools_SOURCE_DIR}/mlmodel/src/MILBlob/Blob/FileWriter.?pp"
- "${coremltools_SOURCE_DIR}/mlmodel/src/MILBlob/Blob/StorageWriter.?pp"
+ "${onnxruntime_COREMLTOOLS_HOME}/mlmodel/src/MILBlob/*.hpp"
+ "${onnxruntime_COREMLTOOLS_HOME}/mlmodel/src/MILBlob/*.cpp"
+ "${onnxruntime_COREMLTOOLS_HOME}/mlmodel/src/MILBlob/Util/*.hpp"
+ "${onnxruntime_COREMLTOOLS_HOME}/mlmodel/src/MILBlob/Blob/BlobDataType.hpp"
+ "${onnxruntime_COREMLTOOLS_HOME}/mlmodel/src/MILBlob/Blob/StorageFormat.hpp"
+ "${onnxruntime_COREMLTOOLS_HOME}/mlmodel/src/MILBlob/Blob/FileWriter.?pp"
+ "${onnxruntime_COREMLTOOLS_HOME}/mlmodel/src/MILBlob/Blob/StorageWriter.?pp"
)

# Add helpers to create mlpackage
file(GLOB
onnxruntime_providers_coreml_modelpackage_cc_srcs CONFIGURE_DEPENDS
- "${coremltools_SOURCE_DIR}/modelpackage/src/ModelPackage.?pp"
- "${coremltools_SOURCE_DIR}/modelpackage/src/utils/JsonMap.?pp"
+ "${onnxruntime_COREMLTOOLS_HOME}/modelpackage/src/ModelPackage.?pp"
+ "${onnxruntime_COREMLTOOLS_HOME}/modelpackage/src/utils/JsonMap.?pp"
)

set(coremltools_srcs
@@ -119,7 +106,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 ${onnxruntime_COREMLTOOLS_HOME} PREFIX coremltools FILES ${coremltools_srcs})
endif()

# Add CoreML objective c++ source code
@@ -190,9 +177,9 @@ if (_enable_ML_PROGRAM)
target_include_directories(onnxruntime_providers_coreml PRIVATE
${fp16_SOURCE_DIR}/include
${nlohmann_json_SOURCE_DIR}/single_include/nlohmann
- ${coremltools_SOURCE_DIR}
- ${coremltools_SOURCE_DIR}/mlmodel/src/
- ${coremltools_SOURCE_DIR}/modelpackage/src/
+ ${onnxruntime_COREMLTOOLS_HOME}
+ ${onnxruntime_COREMLTOOLS_HOME}/mlmodel/src/
+ ${onnxruntime_COREMLTOOLS_HOME}/modelpackage/src/
)

add_dependencies(onnxruntime_providers_coreml nlohmann_json::nlohmann_json fp16)
14 changes: 14 additions & 0 deletions vcpkg-overlay/ports/maa-onnxruntime/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ vcpkg_from_github(
SHA512 3bf25e431d175c61953d28b1bf8f6871376684263992451a5b2a66e670768fc66e7027f141c6e3f4d1eddeebeda51f31ea0adf4749e50d99ee89d0a26bec77ce
PATCHES
0000-system-lib-fix.patch
0001-coremltools.patch
revert-pr-21492.patch
fix-pr-21348.patch # cmake, source changes of PR 21348
fix-cmake.patch
Expand Down Expand Up @@ -76,6 +77,19 @@ if("tensorrt" IN_LIST FEATURES)
endif()
endif()

if("coreml" IN_LIST FEATURES)
if(NOT DEFINED COREMLTOOLS_ROOT)
vcpkg_from_github(
OUT_SOURCE_PATH COREMLTOOLS_ROOT
REPO apple/coremltools
REF 8.0
SHA512 ed1c5140d8b613632dcc408b789176ec95c11e3e1a504df92d1f7930e79e6eb9de8a42c18cf19bb115e52d5c4c64ed22e61e6bb1e8d97ebb8291a6c1e8c42920
)
endif()
message(STATUS "Using CoreML: ${COREMLTOOLS_ROOT}")
list(APPEND FEATURE_OPTIONS "-Donnxruntime_COREMLTOOLS_HOME:PATH=${COREMLTOOLS_ROOT}")
endif()

string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" BUILD_SHARED)

# see tools/ci_build/build.py
Expand Down
16 changes: 7 additions & 9 deletions vcpkg-overlay/ports/maa-onnxruntime/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,15 @@
"nvidia-cutlass"
]
},
"tensorrt": {
"description": "Build with TensorRT support",
"directml": {
"description": "Build with DirectML support",
"dependencies": [
{
"name": "onnxruntime",
"default-features": false,
"features": [
"cuda"
]
}
"directml-bin",
"directx-headers"
]
},
"coreml": {
"description": "Build with CoreML support"
}
}
}
18 changes: 14 additions & 4 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@
"default-features": false,
"features": ["eigen", "jpeg", "png", "tiff", "world"]
},
"maa-onnxruntime",
"maa-fastdeploy",
{
"name": "directml-bin",
"platform": "windows"
"name": "maa-onnxruntime",
"platform": "windows",
"features": ["cuda", "directml"]
},
{
"name": "maa-onnxruntime",
"platform": "osx",
"features": ["coreml"]
},
{
"name": "maa-onnxruntime",
"platform": "linux",
"features": ["cuda"]
},
"maa-fastdeploy",
"zlib",
"boost-asio",
"boost-core",
Expand Down

0 comments on commit dffe088

Please sign in to comment.