From c3379ecb6bee93975bd6a9f40605b689bd69769b Mon Sep 17 00:00:00 2001 From: Wenbing Li <10278425+wenbingl@users.noreply.github.com> Date: Sun, 17 Nov 2024 20:09:36 -0800 Subject: [PATCH] fix the build for mobile packaging (#843) * fix the build for mobile packaging * update the cmake file as well * more fixing on dlib related ops * release the iOS cmake version constraint * upgrade cmake in Linux CUDA build * Update Dockerfile.ubuntu_cuda11_8_tensorrt8_6 for typo * Update ios_packaging.yml for Azure Pipelines * update the dlib versoin * update all cases of cmake version * update the comment for dlb cmake --- .pipelines/ci.yml | 5 +-- .pipelines/ios_packaging.yml | 5 +-- .../build-package-for-ios-cocoapods.yml | 5 +-- .../templates/build-package-for-linux.yml | 2 +- .pipelines/templates/ios-framework-build.yml | 5 +-- CMakeLists.txt | 39 ++++++++++++------- ThirdPartyNotices.txt | 4 +- cgmanifest.json | 34 +++++++++++++++- cmake/externals/dlib.cmake | 10 ++--- include/ortx_extractor.h | 1 - .../build-package-for-ios-cocoapods.yml | 5 +-- .../templates/build-package-for-linux.yml | 2 +- .../templates/ios-framework-build.yml | 5 +-- .../Dockerfile.ubi8_cuda11_8_tensorrt8_6 | 2 +- .../Dockerfile.ubuntu_cuda11_8_tensorrt8_6 | 2 +- tools/gen_selectedops.py | 4 +- tutorials/ortx_api/CMakeLists.txt | 2 +- 17 files changed, 85 insertions(+), 47 deletions(-) diff --git a/.pipelines/ci.yml b/.pipelines/ci.yml index 486be80a..8290e71f 100644 --- a/.pipelines/ci.yml +++ b/.pipelines/ci.yml @@ -851,10 +851,9 @@ stages: architecture: 'x64' displayName: "Use Python 3.12" - # iOS xcframework build doesn't work with CMake 3.25.1, pin to 3.25.0 - script: | - python -m pip install cmake==3.25.0 - displayName: "Install CMake 3.25.0" + python -m pip install cmake + displayName: "Install CMake" - template: templates/set-package-version-variable-step.yml parameters: diff --git a/.pipelines/ios_packaging.yml b/.pipelines/ios_packaging.yml index 83087c00..4ad51f69 100644 --- a/.pipelines/ios_packaging.yml +++ b/.pipelines/ios_packaging.yml @@ -25,10 +25,9 @@ jobs: addToPath: true architecture: "x64" - # iOS xcframework build doesn't work with CMake 3.25.1, pin to 3.25.0 - script: | - python -m pip install cmake==3.25.0 - displayName: "Install CMake 3.25.0" + python -m pip install cmake + displayName: "Install CMake" - template: templates/install-appcenter.yml diff --git a/.pipelines/templates/build-package-for-ios-cocoapods.yml b/.pipelines/templates/build-package-for-ios-cocoapods.yml index 52a0724c..8fcc6615 100644 --- a/.pipelines/templates/build-package-for-ios-cocoapods.yml +++ b/.pipelines/templates/build-package-for-ios-cocoapods.yml @@ -78,10 +78,9 @@ jobs: addToPath: true architecture: "x64" - # iOS xcframework build doesn't work with CMake 3.25.1, pin to 3.25.0 - script: | - python -m pip install cmake==3.25.0 - displayName: "Install CMake 3.25.0" + python -m pip install cmake + displayName: "Install CMake" - template: set-package-version-variable-step.yml parameters: diff --git a/.pipelines/templates/build-package-for-linux.yml b/.pipelines/templates/build-package-for-linux.yml index 8e107892..2304d8f7 100644 --- a/.pipelines/templates/build-package-for-linux.yml +++ b/.pipelines/templates/build-package-for-linux.yml @@ -39,7 +39,7 @@ jobs: sudo apt-get install -y libssh-dev displayName: Install OpenSSL for Azure custom ops - # NOTE: on arm64 machine, CMake version needs to be updated since we now require CMake 3.25 or newer. + # NOTE: on arm64 machine, CMake version needs to be updated since we now require CMake 3.28 or newer. - ${{ if eq(parameters.OrtExtensionsArch, 'x64') }}: - bash: | export CFLAGS="${{parameters.OrtExtensionsCFlags}}" diff --git a/.pipelines/templates/ios-framework-build.yml b/.pipelines/templates/ios-framework-build.yml index ee3a9f8e..28cdb40d 100644 --- a/.pipelines/templates/ios-framework-build.yml +++ b/.pipelines/templates/ios-framework-build.yml @@ -38,10 +38,9 @@ jobs: addToPath: true architecture: "x64" - # iOS xcframework build doesn't work with CMake 3.25.1, pin to 3.25.0 - script: | - python -m pip install cmake==3.25.0 - displayName: "Install CMake 3.25.0" + python -m pip install cmake + displayName: "Install CMake" - template: set-package-version-variable-step.yml parameters: diff --git a/CMakeLists.txt b/CMakeLists.txt index fa94bd09..f4d7d35d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ # Licensed under the MIT License. # Minimum CMake required -cmake_minimum_required(VERSION 3.25) +cmake_minimum_required(VERSION 3.28) project(onnxruntime_extensions LANGUAGES C CXX) # set(CMAKE_VERBOSE_MAKEFILE ON) @@ -334,6 +334,20 @@ endif() file(GLOB TARGET_SRC_NOEXCEPTION "base/*.h" "base/*.cc") file(GLOB TARGET_SRC "operators/*.cc" "operators/*.h" "include/*.h" "include/*.hpp") +if(OCOS_ENABLE_DLIB) + set(DLIB_ISO_CPP_ONLY ON CACHE INTERNAL "") + set(DLIB_NO_GUI_SUPPORT ON CACHE INTERNAL "") + set(DLIB_USE_CUDA OFF CACHE INTERNAL "") + set(DLIB_USE_LAPACK OFF CACHE INTERNAL "") + set(DLIB_USE_BLAS OFF CACHE INTERNAL "") + include(dlib) + + # Ideally, dlib should be included as file(GLOB TARGET_SRC_DLIB "${dlib_SOURCE_DIR}/dlib/all/source.cpp") + # To avoid the unintentional using some unwanted component, we only include the test_for_odr_violations.cpp + # to check if there is any violation in build configuration to ensure compiling some dlib source files correctly. + file(GLOB TARGET_SRC_DLIB "${dlib_SOURCE_DIR}/dlib/test_for_odr_violations.cpp") +endif() + if(OCOS_ENABLE_TF_STRING) set(farmhash_SOURCE_DIR ${PROJECT_SOURCE_DIR}/cmake/externals/farmhash) file(GLOB TARGET_SRC_KERNELS "operators/text/*.cc" "operators/text/*.h*") @@ -342,8 +356,12 @@ if(OCOS_ENABLE_TF_STRING) endif() if(OCOS_ENABLE_AUDIO) + if (NOT OCOS_ENABLE_DLIB) + message(FATAL_ERROR "Audio operators require DLIB to be enabled.") + endif() include(dr_libs) file(GLOB TARGET_SRC_AUDIO "operators/audio/*.*") + list(APPEND TARGET_SRC_AUDIO ${dlib_SOURCE_DIR}/dlib/fft/fft.cpp) list(APPEND TARGET_SRC_NOEXCEPTION ${TARGET_SRC_AUDIO}) endif() @@ -353,20 +371,10 @@ if(OCOS_ENABLE_RE2_REGEX) endif() if(OCOS_ENABLE_MATH) - if(OCOS_ENABLE_DLIB) - set(DLIB_ISO_CPP_ONLY ON CACHE INTERNAL "") - set(DLIB_NO_GUI_SUPPORT ON CACHE INTERNAL "") - set(DLIB_USE_CUDA OFF CACHE INTERNAL "") - set(DLIB_USE_LAPACK OFF CACHE INTERNAL "") - set(DLIB_USE_BLAS OFF CACHE INTERNAL "") - include(dlib) - - # Ideally, dlib should be included as - # file(GLOB TARGET_SRC_DLIB "${dlib_SOURCE_DIR}/dlib/all/source.cpp") - # To avoid the unintentional using some unwanted component, only include - file(GLOB TARGET_SRC_DLIB "${dlib_SOURCE_DIR}/dlib/test_for_odr_violations.cpp") - file(GLOB TARGET_SRC_INVERSE "operators/math/dlib/*.cc" "operators/math/dlib/*.h*") + if (NOT OCOS_ENABLE_DLIB) + message(FATAL_ERROR "Math operators require DLIB to be enabled.") endif() + file(GLOB TARGET_SRC_INVERSE "operators/math/dlib/*.cc" "operators/math/dlib/*.h*") file(GLOB TARGET_SRC_MATH "operators/math/*.cc" "operators/math/*.h*") if(OCOS_USE_CUDA) @@ -664,6 +672,9 @@ if(OCOS_ENABLE_VISION) set(_DEFAULT_CODEC_ENABLE ON) # libpng and libjpeg can be optional after EncodeImage with native support too. if(_DEFAULT_CODEC_ENABLE) + if (NOT OCOS_ENABLE_DLIB) + message(FATAL_ERROR "Vision operators require DLIB to be enabled.") # for now, we need dlib for image processing + endif() include(ext_imgcodecs) target_include_directories(ocos_operators PUBLIC ${libPNG_SOURCE_DIR} ${libJPEG_SOURCE_DIR}) target_link_libraries(ocos_operators PUBLIC ${PNG_LIBRARY} ${JPEG_LIBRARY}) diff --git a/ThirdPartyNotices.txt b/ThirdPartyNotices.txt index 96dfcfa8..ffe320e8 100644 --- a/ThirdPartyNotices.txt +++ b/ThirdPartyNotices.txt @@ -45,7 +45,7 @@ blingfire 0831265c1aca95ca02eca5bf1155e4251e545328 _____ -dlib a12824d42584e292ecb3bad05c4b32c2015a7b89 +dlib v19.24.6 Boost Software License - Version 1.0 - August 17th, 2003 @@ -106,7 +106,7 @@ Google Inc. Samsung Electronics Stefano Rivera -Dominic Battré +Dominic Battré Doug Kwan Dmitriy Vyukov John Millikin diff --git a/cgmanifest.json b/cgmanifest.json index f12f4dbb..99c6f96a 100644 --- a/cgmanifest.json +++ b/cgmanifest.json @@ -34,7 +34,7 @@ "component": { "type": "git", "git": { - "commitHash": "a12824d42584e292ecb3bad05c4b32c2015a7b89", + "commitHash": "v19.24.6", "repositoryUrl": "https://github.com/davisking/dlib.git" } } @@ -87,6 +87,38 @@ "comments": "v3.10.5" } }, + { + "component": { + "type": "other", + "other": { + "name": "libjpeg", + "version": "release 9e of 16-Jan-2022", + "downloadUrl": "https://github.com/davisking/dlib/tree/v19.24.6/dlib/external/libjpeg" + }, + "comments": "for vision domain" + } + }, + { + "component": { + "type": "other", + "other": { + "name": "libpng", + "version": "1.6.37", + "downloadUrl": "https://github.com/davisking/dlib/tree/v19.24.6/dlib/external/libpng" + }, + "comments": "for vision domain" + } + }, + { + "component": { + "other": { + "name": "zlib", + "version": "1.2.11", + "downloadUrl": "https://github.com/davisking/dlib/tree/v19.24.6/dlib/external/zlib" + }, + "comments": "for vision domain" + } + }, { "component": { "type": "git", diff --git a/cmake/externals/dlib.cmake b/cmake/externals/dlib.cmake index 62ad2424..a41a00bf 100644 --- a/cmake/externals/dlib.cmake +++ b/cmake/externals/dlib.cmake @@ -1,8 +1,8 @@ -FetchContent_Declare(dlib - GIT_REPOSITORY https://github.com/davisking/dlib.git - # there is non an official tag which supports STFT, - # choose a relatively stable commit id for that. - GIT_TAG a12824d42584e292ecb3bad05c4b32c2015a7b89 +FetchContent_Declare( + dlib + URL https://github.com/davisking/dlib/archive/refs/tags/v19.24.6.zip + URL_HASH SHA1=59b1fb4e9909697c646e4f74e94871dacf49f0bf + DOWNLOAD_EXTRACT_TIMESTAMP TRUE SOURCE_SUBDIR not_set ) diff --git a/include/ortx_extractor.h b/include/ortx_extractor.h index 20c7dac0..568237eb 100644 --- a/include/ortx_extractor.h +++ b/include/ortx_extractor.h @@ -6,7 +6,6 @@ typedef OrtxObject OrtxFeatureExtractor; typedef OrtxObject OrtxRawAudios; -typedef OrtxObject OrtxTensorResult; #ifdef __cplusplus extern "C" { diff --git a/tools/ci_build/github/azure-pipeline/templates/build-package-for-ios-cocoapods.yml b/tools/ci_build/github/azure-pipeline/templates/build-package-for-ios-cocoapods.yml index e3b63a75..d95b4359 100644 --- a/tools/ci_build/github/azure-pipeline/templates/build-package-for-ios-cocoapods.yml +++ b/tools/ci_build/github/azure-pipeline/templates/build-package-for-ios-cocoapods.yml @@ -101,10 +101,9 @@ jobs: addToPath: true architecture: "x64" - # iOS xcframework build doesn't work with CMake 3.25.1, pin to 3.25.0 - script: | - python -m pip install cmake==3.25.0 - displayName: "Install CMake 3.25.0" + python -m pip install cmake + displayName: "Install CMake" - template: set-package-version-variable-step.yml parameters: diff --git a/tools/ci_build/github/azure-pipeline/templates/build-package-for-linux.yml b/tools/ci_build/github/azure-pipeline/templates/build-package-for-linux.yml index 40af07e5..72f58de7 100644 --- a/tools/ci_build/github/azure-pipeline/templates/build-package-for-linux.yml +++ b/tools/ci_build/github/azure-pipeline/templates/build-package-for-linux.yml @@ -49,7 +49,7 @@ jobs: sudo apt-get install -y libssh-dev displayName: Install OpenSSL for Azure custom ops - # NOTE: on arm64 machine, CMake version needs to be updated since we now require CMake 3.25 or newer. + # NOTE: on arm64 machine, CMake version needs to be updated since we now require CMake 3.28 or newer. - ${{ if eq(parameters.OrtExtensionsArch, 'x64') }}: - bash: | export CFLAGS="${{parameters.OrtExtensionsCFlags}}" diff --git a/tools/ci_build/github/azure-pipeline/templates/ios-framework-build.yml b/tools/ci_build/github/azure-pipeline/templates/ios-framework-build.yml index 397eb434..02ab68b2 100644 --- a/tools/ci_build/github/azure-pipeline/templates/ios-framework-build.yml +++ b/tools/ci_build/github/azure-pipeline/templates/ios-framework-build.yml @@ -45,10 +45,9 @@ jobs: addToPath: true architecture: "x64" - # iOS xcframework build doesn't work with CMake 3.25.1, pin to 3.25.0 - script: | - python -m pip install cmake==3.25.0 - displayName: "Install CMake 3.25.0" + python -m pip install cmake + displayName: "Install CMake" - template: set-package-version-variable-step.yml parameters: diff --git a/tools/ci_build/github/linux/docker/Dockerfile.ubi8_cuda11_8_tensorrt8_6 b/tools/ci_build/github/linux/docker/Dockerfile.ubi8_cuda11_8_tensorrt8_6 index c2b44690..fa175b23 100644 --- a/tools/ci_build/github/linux/docker/Dockerfile.ubi8_cuda11_8_tensorrt8_6 +++ b/tools/ci_build/github/linux/docker/Dockerfile.ubi8_cuda11_8_tensorrt8_6 @@ -23,7 +23,7 @@ RUN dnf install -y \ RUN pip3 install --upgrade pip RUN pip3 install setuptools>=68.2.2 -RUN pip3 install cmake==3.27.2 +RUN pip3 install cmake==3.28.4 # Install TensorRT RUN dnf install -y libnvinfer8 libnvonnxparsers8 libnvparsers8 libnvinfer-plugin8 libnvinfer-lean8 libnvinfer-vc-plugin8 libnvinfer-dispatch8 diff --git a/tools/ci_build/github/linux/docker/Dockerfile.ubuntu_cuda11_8_tensorrt8_6 b/tools/ci_build/github/linux/docker/Dockerfile.ubuntu_cuda11_8_tensorrt8_6 index 529080e0..dadfc3ab 100644 --- a/tools/ci_build/github/linux/docker/Dockerfile.ubuntu_cuda11_8_tensorrt8_6 +++ b/tools/ci_build/github/linux/docker/Dockerfile.ubuntu_cuda11_8_tensorrt8_6 @@ -27,7 +27,7 @@ RUN apt-get install -y --no-install-recommends \ RUN pip install --upgrade pip RUN pip install setuptools>=68.2.2 -RUN pip3 install cmake==3.27.2 +RUN pip3 install cmake==3.28.4 # Install TensorRT RUN v="8.6.1.6-1+cuda11.8" &&\ diff --git a/tools/gen_selectedops.py b/tools/gen_selectedops.py index 8d7e3f7e..fa786bbe 100755 --- a/tools/gen_selectedops.py +++ b/tools/gen_selectedops.py @@ -74,7 +74,9 @@ CMAKE_FLAG_TO_OPS = { ], "OCOS_ENABLE_DLIB": [ "Inverse", - "StftNorm" + "StftNorm", + "DecodeImage", + "EncodeImage" ], "OCOS_ENABLE_TRIE_TOKENIZER": [ "TrieTokenizer", diff --git a/tutorials/ortx_api/CMakeLists.txt b/tutorials/ortx_api/CMakeLists.txt index ecb48d64..39772ccb 100644 --- a/tutorials/ortx_api/CMakeLists.txt +++ b/tutorials/ortx_api/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.25) +cmake_minimum_required(VERSION 3.28) project(ortx_api_test)