Skip to content

Commit

Permalink
fix dml/coreml build
Browse files Browse the repository at this point in the history
  • Loading branch information
dantmnf committed May 29, 2024
1 parent e0d0c9a commit 620cf6e
Show file tree
Hide file tree
Showing 6 changed files with 9,753 additions and 3 deletions.
51 changes: 51 additions & 0 deletions vcpkg-overlay/ports/directml-bin/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY)

set(VERSION 1.5.1)

vcpkg_download_distfile(ARCHIVE
URLS "https://www.nuget.org/api/v2/package/Microsoft.AI.DirectML/1.14.1"
FILENAME "Microsoft.AI.DirectML.1.14.1.nupkg"
SHA512 362be04b10c5a443250909e0d57b2dc3e0e709e0651578cfea8a702e2d295b78d3d058533e728d1edd61963750c76359552dd02b1a66e8a55635347b73796637
)

vcpkg_extract_source_archive(
SOURCE_PATH
ARCHIVE ${ARCHIVE}
NO_REMOVE_ONE_LEVEL
)

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}/include
DESTINATION ${CURRENT_PACKAGES_DIR}
)


file(COPY ${SOURCE_PATH}/bin/${VCPKG_TARGET_ARCHITECTURE}-win/DirectML.dll
DESTINATION ${CURRENT_PACKAGES_DIR}/bin)
file(COPY ${SOURCE_PATH}/bin/${VCPKG_TARGET_ARCHITECTURE}-win/DirectML.pdb
DESTINATION ${CURRENT_PACKAGES_DIR}/bin)
file(COPY ${SOURCE_PATH}/bin/${VCPKG_TARGET_ARCHITECTURE}-win/DirectML.lib
DESTINATION ${CURRENT_PACKAGES_DIR}/lib)

file(COPY ${SOURCE_PATH}/bin/${VCPKG_TARGET_ARCHITECTURE}-win/DirectML.dll
DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin)
file(COPY ${SOURCE_PATH}/bin/${VCPKG_TARGET_ARCHITECTURE}-win/DirectML.pdb
DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin)
file(COPY ${SOURCE_PATH}/bin/${VCPKG_TARGET_ARCHITECTURE}-win/DirectML.lib
DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib)

# file(COPY ${SOURCE_PATH}/bin/${VCPKG_TARGET_ARCHITECTURE}-win/DirectML.Debug.dll
# DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin)
# file(COPY ${SOURCE_PATH}/bin/${VCPKG_TARGET_ARCHITECTURE}-win/DirectML.Debug.pdb
# DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin)

# # Handle copyright
file(INSTALL ${SOURCE_PATH}/LICENSE.txt DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
8 changes: 8 additions & 0 deletions vcpkg-overlay/ports/directml-bin/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "directml-bin",
"version": "1.14.1",
"port-version": 1,
"description": "DirectML (standalone)",
"homepage": "https://www.nuget.org/packages/Microsoft.AI.DirectML",
"supports": "windows"
}
100 changes: 97 additions & 3 deletions vcpkg-overlay/ports/maa-onnxruntime/0000-system-lib-fix.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index 8edbb6ad6..9524cb858 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -1494,7 +1494,7 @@ if (onnxruntime_USE_DML)
message(FATAL_ERROR "The DirectML execution provider is only supported when building for Windows.")
endif()

- include(dml)
+ #include(dml)
endif()

if (onnxruntime_ENABLE_TRAINING_APIS)
diff --git a/cmake/external/abseil-cpp.cmake b/cmake/external/abseil-cpp.cmake
index 57cfbee46..529f8dfa5 100644
--- a/cmake/external/abseil-cpp.cmake
Expand Down Expand Up @@ -66,7 +79,7 @@ index b123adb62..3d8fa153f 100644
FetchContent_Declare(
eigen
diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake
index 8839dbc8f..acdb8a1ee 100644
index 8839dbc8f..e8ea4a8b2 100644
--- a/cmake/external/onnxruntime_external_deps.cmake
+++ b/cmake/external/onnxruntime_external_deps.cmake
@@ -85,7 +85,7 @@ if (NOT WIN32)
Expand Down Expand Up @@ -157,7 +170,7 @@ index 8839dbc8f..acdb8a1ee 100644
- add_library(nsync::nsync_cpp ALIAS nsync_cpp)
- target_include_directories(nsync_cpp PUBLIC ${google_nsync_SOURCE_DIR}/public)
+ # vcpkg-specific
+ find_package(unofficial-nsync CONFIG REQUIRED)
+ find_package(unofficial-nsync CONFIGS REQUIRED)
+ if(TARGET unofficial::nsync::nsync_cpp)
+ add_library(nsync::nsync_cpp ALIAS unofficial::nsync::nsync_cpp)
endif()
Expand All @@ -177,7 +190,7 @@ index 8839dbc8f..acdb8a1ee 100644

if (NOT onnxruntime_MINIMAL_BUILD)
- onnxruntime_fetchcontent_makeavailable(onnx)
+ find_package(ONNX CONFIG REQUIRED)
+ find_package(ONNX CONFIGS REQUIRED)
+ add_library(onnx ALIAS ONNX::onnx)
+ add_library(onnx_proto ALIAS ONNX::onnx_proto)
else()
Expand All @@ -195,3 +208,84 @@ index 8839dbc8f..acdb8a1ee 100644
if (onnxruntime_RUN_ONNX_TESTS)
add_definitions(-DORT_RUN_EXTERNAL_ONNX_TESTS)
endif()
@@ -558,14 +556,7 @@ 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)
+ set(coremltools_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/external/coremltools")
endif()

message("Finished fetching external dependencies")
diff --git a/cmake/onnxruntime_providers_coreml.cmake b/cmake/onnxruntime_providers_coreml.cmake
index 0aa25a221..62b53173d 100644
--- a/cmake/onnxruntime_providers_coreml.cmake
+++ b/cmake/onnxruntime_providers_coreml.cmake
@@ -9,20 +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)
-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)
diff --git a/cmake/onnxruntime_providers_dml.cmake b/cmake/onnxruntime_providers_dml.cmake
index 439be882d..dfc061f42 100644
--- a/cmake/onnxruntime_providers_dml.cmake
+++ b/cmake/onnxruntime_providers_dml.cmake
@@ -21,32 +21,9 @@
target_compile_options(onnxruntime_providers_dml PRIVATE "/wd4100" "/wd4238" "/wd4189" "/wd4702")
endif()

- if (NOT onnxruntime_USE_CUSTOM_DIRECTML)
- foreach(file "DirectML.dll" "DirectML.pdb" "DirectML.Debug.dll" "DirectML.Debug.pdb")
- add_custom_command(TARGET onnxruntime_providers_dml
- POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy_if_different
- "${DML_PACKAGE_DIR}/bin/${onnxruntime_target_platform}-win/${file}" $<TARGET_FILE_DIR:onnxruntime_providers_dml>)
- endforeach()
- endif()
-
function(target_add_dml target)
- if (onnxruntime_USE_CUSTOM_DIRECTML)
- if (dml_EXTERNAL_PROJECT)
- # Internal build of DirectML: link against the "DirectML" target.
- target_link_libraries(${target} PRIVATE DirectML)
- else()
- if (dml_LIB_DIR)
- target_link_libraries(${target} PRIVATE ${dml_LIB_DIR}/DirectML.lib)
- else()
- target_link_libraries(${target} PRIVATE DirectML)
- endif()
- endif()
- else()
- add_dependencies(${target} RESTORE_PACKAGES)
- target_link_libraries(${target} PRIVATE "${DML_PACKAGE_DIR}/bin/${onnxruntime_target_platform}-win/DirectML.lib")
- target_compile_definitions(${target} PRIVATE DML_TARGET_VERSION_USE_LATEST)
- endif()
+ # use directml.lib from Windows SDK
+ target_link_libraries(${target} PRIVATE DirectML)
endfunction()

target_add_dml(onnxruntime_providers_dml)
Loading

0 comments on commit 620cf6e

Please sign in to comment.