From b4f1e769c09f75af51623c2e296017c491adffe5 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Tue, 7 Jun 2022 23:58:20 +0800 Subject: [PATCH] Add Mac Silicon/M1 Wheel (#11591) --- .../azure-pipelines/py-packaging-pipeline.yml | 6 ++ .../templates/py-packaging-stage.yml | 83 ++++++++++++++++++- 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/tools/ci_build/github/azure-pipelines/py-packaging-pipeline.yml b/tools/ci_build/github/azure-pipelines/py-packaging-pipeline.yml index 83daaefe15..9c45694ec1 100644 --- a/tools/ci_build/github/azure-pipelines/py-packaging-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/py-packaging-pipeline.yml @@ -24,6 +24,11 @@ parameters: type: boolean default: true +- name: enable_mac_silicon + displayName: 'Whether Mac silicon package is built.' + type: boolean + default: true + - name: enable_linux_arm displayName: 'Whether Linux ARM package is built.' type: boolean @@ -39,4 +44,5 @@ stages: enable_windows_cpu: ${{ parameters.enable_windows_cpu }} enable_windows_gpu: ${{ parameters.enable_windows_gpu }} enable_mac_cpu: ${{ parameters.enable_mac_cpu }} + enable_mac_silicon: ${{ parameters.enable_mac_silicon }} enable_linux_arm: ${{ parameters.enable_linux_arm }} diff --git a/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml b/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml index ebb075ef89..dc5238c288 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml @@ -40,6 +40,11 @@ parameters: type: boolean default: true +- name: enable_mac_silicon + displayName: 'Whether Mac silicon package is built.' + type: boolean + default: true + - name: enable_linux_arm displayName: 'Whether Linux ARM package is built.' type: boolean @@ -624,7 +629,6 @@ stages: Contents: '*.whl' TargetFolder: '$(Build.ArtifactStagingDirectory)' - - task: PublishBuildArtifacts@1 displayName: 'Publish Artifact: ONNXRuntime python wheel' inputs: @@ -751,6 +755,83 @@ stages: parameters: condition: 'succeeded' + - ${{ if eq(parameters.enable_mac_silicon, true) }}: + - job: MacOS_silicon_py_Wheels + timeoutInMinutes: 90 + workspace: + clean: all + pool: + vmImage: 'macOS-11' + variables: + MACOSX_DEPLOYMENT_TARGET: '11.0' + strategy: + # As of 3.9.1, Python now fully supports building and running on macOS 11.0 (Big Sur) and on Apple Silicon Macs (based on the ARM64 architecture). + # https://docs.python.org/3/whatsnew/3.9.html + matrix: + Python38: + PythonVersion: '3.8' + Python39: + PythonVersion: '3.9' + Python310: + PythonVersion: '3.10' + steps: + - checkout: self + clean: true + submodules: recursive + + - task: UsePythonVersion@0 + displayName: 'Use Python' + inputs: + versionSpec: $(PythonVersion) + + - script: | + set -ex + uname -m + system_profiler SPSoftwareDataType SPHardwareDataType + displayName: 'Mac machine info' + + - script: | + set -e + pushd . + cd $(Build.SourcesDirectory)/cmake/external/protobuf + cmake ./cmake -DCMAKE_INSTALL_PREFIX=$(Build.BinariesDirectory)/protobuf -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Relwithdebinfo + make -j$(getconf _NPROCESSORS_ONLN) + make install + popd + export PATH=$(Build.BinariesDirectory)/protobuf/bin:$PATH + export ONNX_ML=1 + export CMAKE_ARGS="-DONNX_GEN_PB_TYPE_STUBS=OFF -DONNX_WERROR=OFF" + export _PYTHON_HOST_PLATFORM=macosx-${{variables.MACOSX_DEPLOYMENT_TARGET}}-arm64 + sudo python3 -m pip install -r '$(Build.SourcesDirectory)/tools/ci_build/github/linux/docker/scripts/requirements.txt' + sudo xcode-select --switch /Applications/Xcode_12.4.app/Contents/Developer + python3 $(Build.SourcesDirectory)/tools/ci_build/build.py --build_dir $(Build.BinariesDirectory) --skip_submodule_sync --parallel --config Release --skip_tests --cmake_extra_defines CMAKE_OSX_ARCHITECTURES=arm64 --build_wheel ${{ parameters.build_py_parameters }} + displayName: 'Command Line Script' + + - script: | + python -m pip install --upgrade delocate + cd '$(Build.BinariesDirectory)/Release/dist' + for file in *.whl + do + delocate-listdeps "$file" + delocate-wheel --require-archs=arm64 -w fixed_wheels -v "$file" + done + displayName: 'delocate wheel' + + - task: CopyFiles@2 + displayName: 'Copy Python Wheel to: $(Build.ArtifactStagingDirectory)' + inputs: + SourceFolder: '$(Build.BinariesDirectory)/Release/dist/fixed_wheels' + Contents: '*.whl' + TargetFolder: '$(Build.ArtifactStagingDirectory)' + + - task: PublishBuildArtifacts@1 + displayName: 'Publish Artifact: ONNXRuntime python wheel' + inputs: + ArtifactName: onnxruntime + + - template: component-governance-component-detection-steps.yml + parameters: + condition: 'succeeded' - ${{ if eq(parameters.enable_linux_arm, true) }}: - job: Linux_py_Wheels