Skip to content

Commit 41cc60a

Browse files
mszhanyiankitm3k
authored andcommitted
Add XNNPack build on Linux ARM64 and improve Linux CPU (microsoft#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() ``` ---------
1 parent 67bcf19 commit 41cc60a

File tree

5 files changed

+65
-22
lines changed

5 files changed

+65
-22
lines changed

tools/ci_build/github/azure-pipelines/linux-ci-pipeline.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ stages:
299299
machine_pool: 'onnxruntime-linux-ARM64-CPU-2019'
300300
with_cache: true
301301
cmake_build_type: Release
302+
python_exe_path: '/opt/python/cp310-cp310/bin/python3.10'
302303

303304
- stage: arm64_test
304305
dependsOn: ['arm64_build']
@@ -307,3 +308,24 @@ stages:
307308
parameters:
308309
arch: 'aarch64'
309310
machine_pool: 'onnxruntime-linux-ARM64-CPU-2019'
311+
312+
- stage: arm64_build_xnnpack
313+
dependsOn: []
314+
jobs:
315+
- template: templates/py-linux.yml
316+
parameters:
317+
arch: 'aarch64'
318+
machine_pool: 'onnxruntime-linux-ARM64-CPU-2019'
319+
with_cache: true
320+
cmake_build_type: Release
321+
ep: 'XNNPack'
322+
extra_build_arg: '--use_xnnpack'
323+
python_exe_path: '/opt/python/cp310-cp310/bin/python3.10'
324+
325+
- stage: arm64_test_xnnpack
326+
dependsOn: ['arm64_build_xnnpack']
327+
jobs:
328+
- template: templates/py-packaging-linux-test-cpu.yml
329+
parameters:
330+
arch: 'aarch64'
331+
machine_pool: 'onnxruntime-linux-ARM64-CPU-2019'

tools/ci_build/github/azure-pipelines/templates/py-linux.yml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,16 @@ parameters:
2626
type: string
2727
default: ''
2828

29+
- name: ep
30+
type: string
31+
default: 'cpu'
32+
33+
- name: python_exe_path
34+
type: string
35+
default: ''
36+
2937
jobs:
30-
- job: Linux_py_Wheels_${{ parameters.arch }}
38+
- job: Linux_py_Wheels_${{ parameters.arch }}_${{parameters.ep}}
3139
timeoutInMinutes: 240
3240
workspace:
3341
clean: all
@@ -42,9 +50,15 @@ jobs:
4250
value: $[format('{0:dd}{0:MM}{0:yyyy}', pipeline.startTime)]
4351
- name: extra_build_args
4452
${{ if ne(parameters.extra_build_arg, '') }}:
45-
value: -x ${{ parameters.extra_build_arg }}
53+
value: '-x ${{ parameters.extra_build_arg }}'
4654
${{ if eq(parameters.extra_build_arg, '') }}:
4755
value: ''
56+
- name: python_exe_path
57+
${{ if ne(parameters.python_exe_path, '') }}:
58+
value: '-p ${{ parameters.python_exe_path }}'
59+
${{ if eq(parameters.python_exe_path, '') }}:
60+
value: ''
61+
4862
steps:
4963
- task: mspremier.PostBuildCleanup.PostBuildCleanup-task.PostBuildCleanup@3
5064
displayName: 'Clean Agent Directories'
@@ -78,7 +92,7 @@ jobs:
7892
inputs:
7993
targetType: filePath
8094
filePath: tools/ci_build/github/linux/run_python_dockerbuild.sh
81-
arguments: -i onnxruntimecpubuildpython${{ parameters.arch }} -d "${{ parameters.device }}" -c ${{ parameters.cmake_build_type }} $(extra_build_args)
95+
arguments: -i onnxruntimecpubuildpython${{ parameters.arch }} -d "${{ parameters.device }}" -c ${{ parameters.cmake_build_type }} $(extra_build_args) $(python_exe_path)
8296
${{ if eq(parameters.with_cache, 'true') }}:
8397
env:
8498
ADDITIONAL_DOCKER_PARAMETER: "--volume $(ORT_CACHE_DIR):/cache -e CCACHE_DIR=/cache -e ORT_BUILD_WITH_CACHE=1"
@@ -87,14 +101,14 @@ jobs:
87101
displayName: 'Publish Artifact: ONNXRuntime python wheel'
88102
inputs:
89103
PathtoPublish: '$(Build.BinariesDirectory)/dist'
90-
ArtifactName: onnxruntime
104+
ArtifactName: onnxruntime-${{ parameters.ep }}
91105

92106
- task: PublishPipelineArtifact@0
93107
displayName: 'Publish Test Binaries'
94108
inputs:
95-
artifactName: 'drop-linux-cpu-${{ parameters.arch }}'
109+
artifactName: 'drop-linux-cpu-${{ parameters.arch }}-${{ parameters.ep }}'
96110
targetPath: '$(Build.BinariesDirectory)/${{ parameters.cmake_build_type }}'
97111

98112
- template: component-governance-component-detection-steps.yml
99113
parameters :
100-
condition : 'succeeded'
114+
condition : 'succeeded'

tools/ci_build/github/azure-pipelines/templates/py-packaging-linux-test-cpu.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ parameters:
2828
type: number
2929
default: 120
3030

31+
- name: ep
32+
type: string
33+
default: 'cpu'
34+
3135
jobs:
3236
- job: Linux_Test_CPU${{ parameters.extra_job_id }}_${{ parameters.arch }}
3337
timeoutInMinutes: ${{ parameters.timeout }}
@@ -43,30 +47,30 @@ jobs:
4347
# The public ADO project
4448
- ${{ if eq(variables['System.CollectionId'], 'f3ad12f2-e480-4533-baf2-635c95467d29') }}:
4549
- download: current # pipeline resource identifier.
46-
artifact: 'drop-linux-cpu-${{ parameters.arch }}'
50+
artifact: 'drop-linux-cpu-${{ parameters.arch }}-${{parameters.ep}}'
4751

4852
- download: current # pipeline resource identifier.
49-
artifact: 'onnxruntime${{ parameters.python_wheel_suffix }}'
53+
artifact: 'onnxruntime${{ parameters.python_wheel_suffix }}-${{ parameters.ep }}'
5054

5155
- bash: |
5256
set -e -x
53-
mv "$(Pipeline.Workspace)/drop-linux-cpu-${{ parameters.arch }}" $(Build.BinariesDirectory)/${{parameters.cmake_build_type}}
54-
mv "$(Pipeline.Workspace)/onnxruntime${{ parameters.python_wheel_suffix }}" "$(Build.BinariesDirectory)/whl"
57+
mv "$(Pipeline.Workspace)/drop-linux-cpu-${{ parameters.arch }}-${{parameters.ep}}" $(Build.BinariesDirectory)/${{parameters.cmake_build_type}}
58+
mv "$(Pipeline.Workspace)/onnxruntime${{ parameters.python_wheel_suffix }}-${{parameters.ep}}" "$(Build.BinariesDirectory)/whl"
5559
cp -r "$(Build.BinariesDirectory)/whl" $(Build.BinariesDirectory)/tmp
5660
find "$(Build.BinariesDirectory)/tmp" -name '*.whl' -exec bash -c 'unzip -d "${1%.*}" "$1"' _ {} \;
5761
# The private ADO project
5862
- ${{ if eq(variables['System.CollectionId'], 'bc038106-a83b-4dab-9dd3-5a41bc58f34c') }}:
5963
- download: build # pipeline resource identifier.
60-
artifact: 'drop-linux-cpu-${{ parameters.arch }}'
64+
artifact: 'drop-linux-cpu-${{ parameters.arch }}-${{parameters.ep}}'
6165

6266
- download: build # pipeline resource identifier.
63-
artifact: 'onnxruntime${{ parameters.python_wheel_suffix }}'
67+
artifact: 'onnxruntime${{ parameters.python_wheel_suffix }}-${{ parameters.ep }}'
6468

6569
- bash: |
6670
set -e -x
6771
ls $(Pipeline.Workspace)/build
68-
mv "$(Pipeline.Workspace)/build/drop-linux-cpu-${{ parameters.arch }}" $(Build.BinariesDirectory)/${{parameters.cmake_build_type}}
69-
mv "$(Pipeline.Workspace)/build/onnxruntime${{ parameters.python_wheel_suffix }}" "$(Build.BinariesDirectory)/whl"
72+
mv "$(Pipeline.Workspace)/build/drop-linux-cpu-${{ parameters.arch }}-${{parameters.ep}}" $(Build.BinariesDirectory)/${{parameters.cmake_build_type}}
73+
mv "$(Pipeline.Workspace)/build/onnxruntime${{ parameters.python_wheel_suffix }}-${{parameters.ep}}" "$(Build.BinariesDirectory)/whl"
7074
cp -r "$(Build.BinariesDirectory)/whl" $(Build.BinariesDirectory)/tmp
7175
find "$(Build.BinariesDirectory)/tmp" -name '*.whl' -exec bash -c 'unzip -d "${1%.*}" "$1"' _ {} \;
7276

tools/ci_build/github/linux/build_linux_python_package.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ mkdir -p /build/dist
77

88
EXTRA_ARG=""
99
ENABLE_CACHE=false
10-
# Put 3.10 at the last because Ubuntu 22.04 use python 3.10 and we will upload the intermediate build files of this
10+
# Put 3.10 at the last because Ubuntu 22.04 use python 3.10 and we will upload the intermediate build files of this
1111
# config to Azure DevOps Artifacts and download them to a Ubuntu 22.04 machine to run the tests.
1212
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")
1313
while getopts "d:p:x:c:e" parameter_Option
1414
do case "${parameter_Option}"
1515
in
1616
#GPU|CPU|NPU.
1717
d) BUILD_DEVICE=${OPTARG};;
18-
p) PYTHON_EXES=${OPTARG};;
18+
p) PYTHON_EXES=("${OPTARG}");;
1919
x) EXTRA_ARG=${OPTARG};;
2020
c) BUILD_CONFIG=${OPTARG};;
2121
e) ENABLE_CACHE=true;;
@@ -89,9 +89,11 @@ export CMAKE_ARGS="-DONNX_GEN_PB_TYPE_STUBS=ON -DONNX_WERROR=OFF"
8989
for PYTHON_EXE in "${PYTHON_EXES[@]}"
9090
do
9191
rm -rf /build/"$BUILD_CONFIG"
92-
${PYTHON_EXE} -m pip install -r /onnxruntime_src/tools/ci_build/github/linux/python/requirements.txt
93-
${PYTHON_EXE} /onnxruntime_src/tools/ci_build/build.py "${BUILD_ARGS[@]}"
94-
92+
# that's a workaround for the issue that there's no python3 in the docker image
93+
# like xnnpack's cmakefile, it uses pythone3 to run a external command
94+
python3_dir=$(dirname "$PYTHON_EXE")
95+
${PYTHON_EXE} -m pip install -r /onnxruntime_src/tools/ci_build/github/linux/python/requirements.txt
96+
PATH=$python3_dir:$PATH ${PYTHON_EXE} /onnxruntime_src/tools/ci_build/build.py "${BUILD_ARGS[@]}"
9597
cp /build/"$BUILD_CONFIG"/dist/*.whl /build/dist
9698
done
9799

tools/ci_build/github/linux/run_python_dockerbuild.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
set -e -x
33
BUILD_CONFIG="Release"
44

5-
while getopts "i:d:x:c:" parameter_Option
5+
while getopts "i:d:x:c:p:" parameter_Option
66
do case "${parameter_Option}"
77
in
88
i) DOCKER_IMAGE=${OPTARG};;
99
d) DEVICE=${OPTARG};;
1010
x) BUILD_EXTR_PAR=${OPTARG};;
1111
c) BUILD_CONFIG=${OPTARG};;
12-
*) echo "Usage: $0 -i <docker_image> -d <GPU|CPU> [-x <extra_build_arg>] [-c <build_config>]"
12+
p) PYTHON_EXES=${OPTARG};;
13+
*) echo "Usage: $0 -i <docker_image> -d <GPU|CPU> [-x <extra_build_arg>] [-c <build_config>] [-p <python_exe_path>]"
1314
exit 1;;
1415
esac
1516
done
@@ -33,7 +34,7 @@ docker run --rm \
3334
-e ORT_DISABLE_PYTHON_PACKAGE_LOCAL_VERSION \
3435
-e DEFAULT_TRAINING_PACKAGE_DEVICE \
3536
$ADDITIONAL_DOCKER_PARAMETER \
36-
$DOCKER_IMAGE tools/ci_build/github/linux/build_linux_python_package.sh $DOCKER_SCRIPT_OPTIONS
37+
$DOCKER_IMAGE tools/ci_build/github/linux/build_linux_python_package.sh -c $BUILD_CONFIG -p $PYTHON_EXES $DOCKER_SCRIPT_OPTIONS
3738

3839
sudo rm -rf "${BUILD_BINARIESDIRECTORY}/${BUILD_CONFIG}/onnxruntime" "${BUILD_BINARIESDIRECTORY}/${BUILD_CONFIG}/pybind11" \
3940
"${BUILD_BINARIESDIRECTORY}/${BUILD_CONFIG}/models" "${BUILD_BINARIESDIRECTORY}/${BUILD_CONFIG}/_deps" \

0 commit comments

Comments
 (0)