Add XNNPack build on Linux ARM64 and improve Linux CPU (#22773)

### Description
1. Add XNNPack build on Linux ARM64
2. Build only one python wheel for PR request.

[AB#49763](https://aiinfra.visualstudio.com/6a833879-cd9b-44a4-a9de-adc2d818f13c/_workitems/edit/49763)



### Motivation and Context
Why I add xnnpack build on Linux ARM64  rather than Windows ARM64.
Becuase KleidiAI  doesn't support Windows

```
IF(XNNPACK_TARGET_PROCESSOR STREQUAL "arm64" AND XNNPACK_ENABLE_ARM_I8MM AND NOT CMAKE_C_COMPILER_ID STREQUAL "MSVC")
  IF (XNNPACK_ENABLE_KLEIDIAI)
    MESSAGE(STATUS "Enabling KleidiAI for Arm64")
  ENDIF()
ELSE()
  SET(XNNPACK_ENABLE_KLEIDIAI OFF)
ENDIF()
```

---------
This commit is contained in:
Yi Zhang 2024-11-09 11:26:19 +08:00 committed by GitHub
parent a8539ec7d1
commit ef281f850a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 65 additions and 22 deletions

View file

@ -299,6 +299,7 @@ stages:
machine_pool: 'onnxruntime-linux-ARM64-CPU-2019'
with_cache: true
cmake_build_type: Release
python_exe_path: '/opt/python/cp310-cp310/bin/python3.10'
- stage: arm64_test
dependsOn: ['arm64_build']
@ -307,3 +308,24 @@ stages:
parameters:
arch: 'aarch64'
machine_pool: 'onnxruntime-linux-ARM64-CPU-2019'
- stage: arm64_build_xnnpack
dependsOn: []
jobs:
- template: templates/py-linux.yml
parameters:
arch: 'aarch64'
machine_pool: 'onnxruntime-linux-ARM64-CPU-2019'
with_cache: true
cmake_build_type: Release
ep: 'XNNPack'
extra_build_arg: '--use_xnnpack'
python_exe_path: '/opt/python/cp310-cp310/bin/python3.10'
- stage: arm64_test_xnnpack
dependsOn: ['arm64_build_xnnpack']
jobs:
- template: templates/py-packaging-linux-test-cpu.yml
parameters:
arch: 'aarch64'
machine_pool: 'onnxruntime-linux-ARM64-CPU-2019'

View file

@ -26,8 +26,16 @@ parameters:
type: string
default: ''
- name: ep
type: string
default: 'cpu'
- name: python_exe_path
type: string
default: ''
jobs:
- job: Linux_py_Wheels_${{ parameters.arch }}
- job: Linux_py_Wheels_${{ parameters.arch }}_${{parameters.ep}}
timeoutInMinutes: 240
workspace:
clean: all
@ -42,9 +50,15 @@ jobs:
value: $[format('{0:dd}{0:MM}{0:yyyy}', pipeline.startTime)]
- name: extra_build_args
${{ if ne(parameters.extra_build_arg, '') }}:
value: -x ${{ parameters.extra_build_arg }}
value: '-x ${{ parameters.extra_build_arg }}'
${{ if eq(parameters.extra_build_arg, '') }}:
value: ''
- name: python_exe_path
${{ if ne(parameters.python_exe_path, '') }}:
value: '-p ${{ parameters.python_exe_path }}'
${{ if eq(parameters.python_exe_path, '') }}:
value: ''
steps:
- task: mspremier.PostBuildCleanup.PostBuildCleanup-task.PostBuildCleanup@3
displayName: 'Clean Agent Directories'
@ -78,7 +92,7 @@ jobs:
inputs:
targetType: filePath
filePath: tools/ci_build/github/linux/run_python_dockerbuild.sh
arguments: -i onnxruntimecpubuildpython${{ parameters.arch }} -d "${{ parameters.device }}" -c ${{ parameters.cmake_build_type }} $(extra_build_args)
arguments: -i onnxruntimecpubuildpython${{ parameters.arch }} -d "${{ parameters.device }}" -c ${{ parameters.cmake_build_type }} $(extra_build_args) $(python_exe_path)
${{ if eq(parameters.with_cache, 'true') }}:
env:
ADDITIONAL_DOCKER_PARAMETER: "--volume $(ORT_CACHE_DIR):/cache -e CCACHE_DIR=/cache -e ORT_BUILD_WITH_CACHE=1"
@ -87,14 +101,14 @@ jobs:
displayName: 'Publish Artifact: ONNXRuntime python wheel'
inputs:
PathtoPublish: '$(Build.BinariesDirectory)/dist'
ArtifactName: onnxruntime
ArtifactName: onnxruntime-${{ parameters.ep }}
- task: PublishPipelineArtifact@0
displayName: 'Publish Test Binaries'
inputs:
artifactName: 'drop-linux-cpu-${{ parameters.arch }}'
artifactName: 'drop-linux-cpu-${{ parameters.arch }}-${{ parameters.ep }}'
targetPath: '$(Build.BinariesDirectory)/${{ parameters.cmake_build_type }}'
- template: component-governance-component-detection-steps.yml
parameters :
condition : 'succeeded'
condition : 'succeeded'

View file

@ -28,6 +28,10 @@ parameters:
type: number
default: 120
- name: ep
type: string
default: 'cpu'
jobs:
- job: Linux_Test_CPU${{ parameters.extra_job_id }}_${{ parameters.arch }}
timeoutInMinutes: ${{ parameters.timeout }}
@ -43,30 +47,30 @@ jobs:
# The public ADO project
- ${{ if eq(variables['System.CollectionId'], 'f3ad12f2-e480-4533-baf2-635c95467d29') }}:
- download: current # pipeline resource identifier.
artifact: 'drop-linux-cpu-${{ parameters.arch }}'
artifact: 'drop-linux-cpu-${{ parameters.arch }}-${{parameters.ep}}'
- download: current # pipeline resource identifier.
artifact: 'onnxruntime${{ parameters.python_wheel_suffix }}'
artifact: 'onnxruntime${{ parameters.python_wheel_suffix }}-${{ parameters.ep }}'
- bash: |
set -e -x
mv "$(Pipeline.Workspace)/drop-linux-cpu-${{ parameters.arch }}" $(Build.BinariesDirectory)/${{parameters.cmake_build_type}}
mv "$(Pipeline.Workspace)/onnxruntime${{ parameters.python_wheel_suffix }}" "$(Build.BinariesDirectory)/whl"
mv "$(Pipeline.Workspace)/drop-linux-cpu-${{ parameters.arch }}-${{parameters.ep}}" $(Build.BinariesDirectory)/${{parameters.cmake_build_type}}
mv "$(Pipeline.Workspace)/onnxruntime${{ parameters.python_wheel_suffix }}-${{parameters.ep}}" "$(Build.BinariesDirectory)/whl"
cp -r "$(Build.BinariesDirectory)/whl" $(Build.BinariesDirectory)/tmp
find "$(Build.BinariesDirectory)/tmp" -name '*.whl' -exec bash -c 'unzip -d "${1%.*}" "$1"' _ {} \;
# The private ADO project
- ${{ if eq(variables['System.CollectionId'], 'bc038106-a83b-4dab-9dd3-5a41bc58f34c') }}:
- download: build # pipeline resource identifier.
artifact: 'drop-linux-cpu-${{ parameters.arch }}'
artifact: 'drop-linux-cpu-${{ parameters.arch }}-${{parameters.ep}}'
- download: build # pipeline resource identifier.
artifact: 'onnxruntime${{ parameters.python_wheel_suffix }}'
artifact: 'onnxruntime${{ parameters.python_wheel_suffix }}-${{ parameters.ep }}'
- bash: |
set -e -x
ls $(Pipeline.Workspace)/build
mv "$(Pipeline.Workspace)/build/drop-linux-cpu-${{ parameters.arch }}" $(Build.BinariesDirectory)/${{parameters.cmake_build_type}}
mv "$(Pipeline.Workspace)/build/onnxruntime${{ parameters.python_wheel_suffix }}" "$(Build.BinariesDirectory)/whl"
mv "$(Pipeline.Workspace)/build/drop-linux-cpu-${{ parameters.arch }}-${{parameters.ep}}" $(Build.BinariesDirectory)/${{parameters.cmake_build_type}}
mv "$(Pipeline.Workspace)/build/onnxruntime${{ parameters.python_wheel_suffix }}-${{parameters.ep}}" "$(Build.BinariesDirectory)/whl"
cp -r "$(Build.BinariesDirectory)/whl" $(Build.BinariesDirectory)/tmp
find "$(Build.BinariesDirectory)/tmp" -name '*.whl' -exec bash -c 'unzip -d "${1%.*}" "$1"' _ {} \;

View file

@ -7,7 +7,7 @@ mkdir -p /build/dist
EXTRA_ARG=""
ENABLE_CACHE=false
# Put 3.10 at the last because Ubuntu 22.04 use python 3.10 and we will upload the intermediate build files of this
# Put 3.10 at the last because Ubuntu 22.04 use python 3.10 and we will upload the intermediate build files of this
# config to Azure DevOps Artifacts and download them to a Ubuntu 22.04 machine to run the tests.
PYTHON_EXES=("/opt/python/cp311-cp311/bin/python3.11" "/opt/python/cp312-cp312/bin/python3.12" "/opt/python/cp313-cp313/bin/python3.13" "/opt/python/cp313-cp313t/bin/python3.13t" "/opt/python/cp310-cp310/bin/python3.10")
while getopts "d:p:x:c:e" parameter_Option
@ -15,7 +15,7 @@ do case "${parameter_Option}"
in
#GPU|CPU|NPU.
d) BUILD_DEVICE=${OPTARG};;
p) PYTHON_EXES=${OPTARG};;
p) PYTHON_EXES=("${OPTARG}");;
x) EXTRA_ARG=${OPTARG};;
c) BUILD_CONFIG=${OPTARG};;
e) ENABLE_CACHE=true;;
@ -89,9 +89,11 @@ export CMAKE_ARGS="-DONNX_GEN_PB_TYPE_STUBS=ON -DONNX_WERROR=OFF"
for PYTHON_EXE in "${PYTHON_EXES[@]}"
do
rm -rf /build/"$BUILD_CONFIG"
${PYTHON_EXE} -m pip install -r /onnxruntime_src/tools/ci_build/github/linux/python/requirements.txt
${PYTHON_EXE} /onnxruntime_src/tools/ci_build/build.py "${BUILD_ARGS[@]}"
# that's a workaround for the issue that there's no python3 in the docker image
# like xnnpack's cmakefile, it uses pythone3 to run a external command
python3_dir=$(dirname "$PYTHON_EXE")
${PYTHON_EXE} -m pip install -r /onnxruntime_src/tools/ci_build/github/linux/python/requirements.txt
PATH=$python3_dir:$PATH ${PYTHON_EXE} /onnxruntime_src/tools/ci_build/build.py "${BUILD_ARGS[@]}"
cp /build/"$BUILD_CONFIG"/dist/*.whl /build/dist
done

View file

@ -2,14 +2,15 @@
set -e -x
BUILD_CONFIG="Release"
while getopts "i:d:x:c:" parameter_Option
while getopts "i:d:x:c:p:" parameter_Option
do case "${parameter_Option}"
in
i) DOCKER_IMAGE=${OPTARG};;
d) DEVICE=${OPTARG};;
x) BUILD_EXTR_PAR=${OPTARG};;
c) BUILD_CONFIG=${OPTARG};;
*) echo "Usage: $0 -i <docker_image> -d <GPU|CPU> [-x <extra_build_arg>] [-c <build_config>]"
p) PYTHON_EXES=${OPTARG};;
*) echo "Usage: $0 -i <docker_image> -d <GPU|CPU> [-x <extra_build_arg>] [-c <build_config>] [-p <python_exe_path>]"
exit 1;;
esac
done
@ -33,7 +34,7 @@ docker run --rm \
-e ORT_DISABLE_PYTHON_PACKAGE_LOCAL_VERSION \
-e DEFAULT_TRAINING_PACKAGE_DEVICE \
$ADDITIONAL_DOCKER_PARAMETER \
$DOCKER_IMAGE tools/ci_build/github/linux/build_linux_python_package.sh $DOCKER_SCRIPT_OPTIONS
$DOCKER_IMAGE tools/ci_build/github/linux/build_linux_python_package.sh -c $BUILD_CONFIG -p $PYTHON_EXES $DOCKER_SCRIPT_OPTIONS
sudo rm -rf "${BUILD_BINARIESDIRECTORY}/${BUILD_CONFIG}/onnxruntime" "${BUILD_BINARIESDIRECTORY}/${BUILD_CONFIG}/pybind11" \
"${BUILD_BINARIESDIRECTORY}/${BUILD_CONFIG}/models" "${BUILD_BINARIESDIRECTORY}/${BUILD_CONFIG}/_deps" \