Create a new Python Package pipeline for CUDA 12 (#18348)

### Description
<!-- Describe your changes. -->



### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
This commit is contained in:
Jian Chen 2023-11-20 09:48:28 -08:00 committed by GitHub
parent 3bcc137eb4
commit d97fc1824f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 242 additions and 36 deletions

View file

@ -0,0 +1,39 @@
trigger: none
parameters:
- name: enable_linux_gpu
type: boolean
default: true
- name: enable_windows_gpu
type: boolean
default: true
- name: cmake_build_type
type: string
default: 'Release'
values:
- Debug
- Release
- RelWithDebInfo
- MinSizeRel
- name: cuda_version
type: string
default: '12.2'
values:
- 11.8
- 12.2
resources:
repositories:
- repository: manylinux
type: Github
endpoint: Microsoft
name: pypa/manylinux
ref: 5eda9aded5462201e6310105728d33016e637ea7
stages:
- template: stages/py-cuda-packaging-stage.yml
parameters:
enable_linux_gpu: ${{ parameters.enable_linux_gpu }}
enable_windows_gpu: ${{ parameters.enable_windows_gpu }}
cmake_build_type: ${{ parameters.cmake_build_type }}
cuda_version: ${{ parameters.cuda_version }}

View file

@ -0,0 +1,105 @@
parameters:
- name: build_py_parameters
displayName: >
Extra parameters to pass to build.py. Don't put newlines in here.
type: string
default: ''
- name: enable_linux_gpu
displayName: 'Whether Linux GPU package is built.'
type: boolean
default: true
- name: enable_windows_gpu
displayName: 'Whether Windows GPU package is built.'
type: boolean
default: true
# TODO: Now the Windows jobs use a different cmake build type. Consider to merge it.
- name: cmake_build_type
type: string
displayName: 'Linux packages cmake build type. Linux Only.'
default: 'Release'
values:
- Debug
- Release
- RelWithDebInfo
- MinSizeRel
- name: cuda_version
type: string
displayName: 'CUDA version. Windows Only.'
default: '12.2'
values:
- 11.8
- 12.2
stages:
- stage: Python_Packaging
dependsOn: []
variables:
- name: docker_base_image
${{ if eq(parameters.cuda_version, '11.8') }}:
value: nvidia/cuda:11.8.0-cudnn8-devel-ubi8
${{ if eq(parameters.cuda_version, '12.2') }}:
value: nvidia/cuda:12.2.2-cudnn8-devel-ubi8
- name: linux_trt_version
${{ if eq(parameters.cuda_version, '11.8') }}:
value: 8.6.1.6-1.cuda11.8
${{ if eq(parameters.cuda_version, '12.2') }}:
value: 8.6.1.6-1.cuda12.0
- name: win_trt_home
${{ if eq(parameters.cuda_version, '11.8') }}:
value: $(Agent.TempDirectory)\TensorRT-8.6.1.6.Windows10.x86_64.cuda-11.8
${{ if eq(parameters.cuda_version, '12.2') }}:
value: $(Agent.TempDirectory)\TensorRT-8.6.1.6.Windows10.x86_64.cuda-12.0
- name: win_cuda_home
${{ if eq(parameters.cuda_version, '11.8') }}:
value: $(Agent.TempDirectory)\v11.8
${{ if eq(parameters.cuda_version, '12.2') }}:
value: $(Agent.TempDirectory)\v12.2
jobs:
- ${{ if eq(parameters.enable_windows_gpu, true) }}:
- template: ../templates/py-win-gpu.yml
parameters:
MACHINE_POOL: 'onnxruntime-Win2022-GPU-T4'
PYTHON_VERSION: '3.8'
EP_BUILD_FLAGS: --use_tensorrt --tensorrt_home=${{ variables.win_trt_home }} --cuda_home=${{ variables.win_cuda_home }} --cmake_extra_defines "CMAKE_CUDA_ARCHITECTURES=52;60;61;70;75;80"
EP_NAME: gpu
CudaVersion: ${{ parameters.cuda_version }}
- template: ../templates/py-win-gpu.yml
parameters:
MACHINE_POOL: 'onnxruntime-Win2022-GPU-T4'
PYTHON_VERSION: '3.9'
EP_BUILD_FLAGS: --use_tensorrt --tensorrt_home=${{ variables.win_trt_home }} --cuda_home=${{ variables.win_cuda_home }} --cmake_extra_defines "CMAKE_CUDA_ARCHITECTURES=52;60;61;70;75;80"
EP_NAME: gpu
CudaVersion: ${{ parameters.cuda_version }}
- template: ../templates/py-win-gpu.yml
parameters:
MACHINE_POOL: 'onnxruntime-Win2022-GPU-T4'
PYTHON_VERSION: '3.10'
EP_BUILD_FLAGS: --use_tensorrt --tensorrt_home=${{ variables.win_trt_home }} --cuda_home=${{ variables.win_cuda_home }} --cmake_extra_defines "CMAKE_CUDA_ARCHITECTURES=52;60;61;70;75;80"
EP_NAME: gpu
CudaVersion: ${{ parameters.cuda_version }}
- template: ../templates/py-win-gpu.yml
parameters:
MACHINE_POOL: 'onnxruntime-Win2022-GPU-T4'
PYTHON_VERSION: '3.11'
EP_BUILD_FLAGS: --use_tensorrt --tensorrt_home=${{ variables.win_trt_home }} --cuda_home=${{ variables.win_cuda_home }} --cmake_extra_defines "CMAKE_CUDA_ARCHITECTURES=52;60;61;70;75;80"
EP_NAME: gpu
CudaVersion: ${{ parameters.cuda_version }}
- ${{ if eq(parameters.enable_linux_gpu, true) }}:
- template: ../templates/py-linux-gpu.yml
parameters:
arch: 'x86_64'
machine_pool: 'onnxruntime-Ubuntu2004-AMD-CPU'
extra_build_arg: ${{ parameters.build_py_parameters }}
cmake_build_type: ${{ parameters.cmake_build_type }}
docker_base_image: ${{ variables.docker_base_image }}
trt_version: ${{ variables.linux_trt_version }}
cuda_version: ${{ parameters.cuda_version }}

View file

@ -34,7 +34,7 @@ steps:
displayName: 'Download TensorRT-8.6.1.6.Windows10.x86_64.cuda-11.8'
- powershell: |
Write-Host "##vso[task.prependpath]$(Agent.TempDirectory)\TensorRT-8.6.1.6.Windows10.x86_64.cuda-11.8\lib"
displayName: 'Append CUDA SDK Directory to PATH'
displayName: 'Append TensorRT Directory to PATH'
- ${{ if eq(parameters.CudaVersion, '12.2') }}:
- powershell: |
@ -42,7 +42,7 @@ steps:
displayName: 'Download TensorRT-8.6.1.6.Windows10.x86_64.cuda-12.0'
- powershell: |
Write-Host "##vso[task.prependpath]$(Agent.TempDirectory)\TensorRT-8.6.1.6.Windows10.x86_64.cuda-12.0\lib"
displayName: 'Append CUDA SDK Directory to PATH'
displayName: 'Append TensorRT Directory to PATH'
- task: CmdLine@2
inputs:

View file

@ -17,7 +17,24 @@ parameters:
- Release
- RelWithDebInfo
- MinSizeRel
- name: docker_base_image
type: string
default: 'nvidia/cuda:11.8.0-cudnn8-devel-ubi8'
values:
- nvidia/cuda:11.8.0-cudnn8-devel-ubi8
- nvidia/cuda:12.2.2-cudnn8-devel-ubi8
- name: trt_version
type: string
default: '8.6.1.6-1.cuda11.8'
values:
- 8.6.1.6-1.cuda11.8
- 8.6.1.6-1.cuda12.0
- name: cuda_version
type: string
default: '11.8'
values:
- 11.8
- 12.2
jobs:
- job: Linux_py_GPU_Wheels_${{ parameters.arch }}
timeoutInMinutes: 240
@ -26,7 +43,13 @@ jobs:
pool: ${{ parameters.machine_pool }}
variables:
# The build machine pool doesn't have dotnet, so it can't run CG.
skipComponentGovernanceDetection: true
- name: skipComponentGovernanceDetection
value: true
- name: extra_build_args
${{ if ne(parameters.extra_build_arg, '') }}:
value: -x ${{ parameters.extra_build_arg }}
${{ if eq(parameters.extra_build_arg, '') }}:
value: ''
steps:
- checkout: self
clean: true
@ -40,12 +63,12 @@ jobs:
Context: tools/ci_build/github/linux/docker
DockerBuildArgs: "
--network=host
--build-arg BASEIMAGE=nvidia/cuda:11.8.0-cudnn8-devel-ubi8
--build-arg TRT_VERSION=8.6.1.6-1.cuda11.8
--build-arg BASEIMAGE=${{ parameters.docker_base_image }}
--build-arg TRT_VERSION=${{ parameters.trt_version }}
--build-arg BUILD_UID=$( id -u )
--build-arg PLATFORM=${{ parameters.arch }}
"
Repository: onnxruntimecuda118xtrt86build${{ parameters.arch }}
Repository: onnxruntimecuda${{ replace(parameters.cuda_version, '.', '') }}xtrt86build${{ parameters.arch }}
- task: Bash@3
@ -53,8 +76,7 @@ jobs:
inputs:
targetType: filePath
filePath: tools/ci_build/github/linux/run_python_dockerbuild.sh
# please check ONNXRUNTIME_CUDA_VERSION in tools/ci_build/github/linux/build_linux_arm64_python_package.sh
arguments: -i onnxruntimecuda118xtrt86build${{ parameters.arch }} -d "GPU" -c ${{ parameters.cmake_build_type }} -x "${{ parameters.extra_build_arg }}"
arguments: -i onnxruntimecuda${{ replace(parameters.cuda_version, '.', '') }}xtrt86build${{ parameters.arch }} -d "GPU" -c ${{ parameters.cmake_build_type }} $(extra_build_args)
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: ONNXRuntime python wheel'

View file

@ -46,9 +46,17 @@ jobs:
pool: ${{ parameters.machine_pool }}
variables:
# The build machine pool doesn't have dotnet, so it can't run CG.
skipComponentGovernanceDetection: true
ORT_CACHE_DIR: $(Agent.TempDirectory)/ort_ccache
TODAY: $[format('{0:dd}{0:MM}{0:yyyy}', pipeline.startTime)]
- name: skipComponentGovernanceDetection
value: true
- name: ORT_CACHE_DIR
value: $(Agent.TempDirectory)/ort_ccache
- name: TODAY
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 }}
${{ if eq(parameters.extra_build_arg, '') }}:
value: ''
steps:
- task: mspremier.PostBuildCleanup.PostBuildCleanup-task.PostBuildCleanup@3
displayName: 'Clean Agent Directories'
@ -82,7 +90,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 }} -x "${{ parameters.extra_build_arg }}"
arguments: -i onnxruntimecpubuildpython${{ parameters.arch }} -d "${{ parameters.device }}" -c ${{ parameters.cmake_build_type }} $(extra_build_args)
${{ 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"

View file

@ -14,21 +14,32 @@ parameters:
- name: ENV_SETUP_SCRIPT
type: string
default: ''
- name: BUILD_PY_PARAMETERS
displayName: >
Extra parameters to pass to build.py. Don't put newlines in here.
type: string
default: ''
- name: CudaVersion
type: string
default: '11.8'
values:
- 11.8
- 12.2
jobs:
- job: Win_py_${{ parameters.EP_NAME }}_Wheels_${{ replace(parameters.PYTHON_VERSION,'.','_') }}
timeoutInMinutes: 240
workspace:
clean: all
pool: ${{ parameters.MACHINE_POOL }}
pool:
name: ${{ parameters.MACHINE_POOL }}
# demands:
# - ImageVersionOverride -equals 1.0.367516
variables:
GRADLE_OPTS: '-Dorg.gradle.daemon=false'
VSGenerator: 'Visual Studio 17 2022'
CUDA_MODULE_LOADING: 'LAZY'
steps:
- checkout: self
clean: true
@ -61,10 +72,21 @@ jobs:
- template: download-deps.yml
- template: jobs/set-winenv.yml
parameters:
EnvSetupScript: ${{ parameters.ENV_SETUP_SCRIPT }}
DownloadCUDA: true
- ${{ if ne(parameters.ENV_SETUP_SCRIPT, '') }}:
- template: jobs/set-winenv.yml
parameters:
EnvSetupScript: ${{ parameters.ENV_SETUP_SCRIPT }}
${{ if or(contains(parameters.EP_BUILD_FLAGS, 'use_cuda'), contains(parameters.EP_BUILD_FLAGS, 'use_tensorrt')) }}:
DownloadCUDA: true
- ${{ if eq(parameters.ENV_SETUP_SCRIPT, '') }}:
- template: jobs/download_win_gpu_library.yml
parameters:
CudaVersion: ${{ parameters.CudaVersion }}
${{ if or(contains(parameters.EP_BUILD_FLAGS, 'use_cuda'), contains(parameters.EP_BUILD_FLAGS, 'use_tensorrt')) }}:
DownloadCUDA: true
${{ if contains(parameters.EP_BUILD_FLAGS, 'use_tensorrt') }}:
DownloadTRT: true
- task: PythonScript@0
displayName: 'Update deps.txt'

View file

@ -15,9 +15,11 @@ do case "${parameter_Option}"
in
#GPU or CPU.
d) BUILD_DEVICE=${OPTARG};;
p) PYTHON_EXES=(${OPTARG});;
x) EXTRA_ARG=(${OPTARG});;
p) PYTHON_EXES=${OPTARG};;
x) EXTRA_ARG=${OPTARG};;
c) BUILD_CONFIG=${OPTARG};;
*) echo "Usage: $0 -d <GPU|CPU> [-p <python_exe_path>] [-x <extra_build_arg>] [-c <build_config>]"
exit 1;;
esac
done
@ -48,7 +50,7 @@ if [ "$ARCH" == "x86_64" ] && [ "$GCC_VERSION" -ge 9 ]; then
fi
echo "EXTRA_ARG:"
echo $EXTRA_ARG
echo "$EXTRA_ARG"
if [ "$EXTRA_ARG" != "" ]; then
BUILD_ARGS+=("$EXTRA_ARG")
@ -60,19 +62,19 @@ if [ "$ARCH" == "x86_64" ]; then
fi
if [ "$BUILD_DEVICE" == "GPU" ]; then
SHORT_CUDA_VERSION=$(echo $CUDA_VERSION | sed 's/\([[:digit:]]\+\.[[:digit:]]\+\)\.[[:digit:]]\+/\1/')
#Enable CUDA and TRT EPs.
ONNXRUNTIME_CUDA_VERSION="11.8"
BUILD_ARGS+=("--nvcc_threads=1" "--use_cuda" "--use_tensorrt" "--cuda_version=$ONNXRUNTIME_CUDA_VERSION" "--tensorrt_home=/usr" "--cuda_home=/usr/local/cuda-$ONNXRUNTIME_CUDA_VERSION" "--cudnn_home=/usr/local/cuda-$ONNXRUNTIME_CUDA_VERSION" "--cmake_extra_defines" "CMAKE_CUDA_ARCHITECTURES=52;60;61;70;75;80")
BUILD_ARGS+=("--nvcc_threads=1" "--use_cuda" "--use_tensorrt" "--cuda_version=$SHORT_CUDA_VERSION" "--tensorrt_home=/usr" "--cuda_home=/usr/local/cuda-$SHORT_CUDA_VERSION" "--cudnn_home=/usr/local/cuda-$SHORT_CUDA_VERSION" "--cmake_extra_defines" "CMAKE_CUDA_ARCHITECTURES=52;60;61;70;75;80")
fi
export CFLAGS
export CXXFLAGS
for PYTHON_EXE in "${PYTHON_EXES[@]}"
do
rm -rf /build/$BUILD_CONFIG
rm -rf /build/"$BUILD_CONFIG"
${PYTHON_EXE} /onnxruntime_src/tools/ci_build/build.py "${BUILD_ARGS[@]}"
cp /build/$BUILD_CONFIG/dist/*.whl /build/dist
cp /build/"$BUILD_CONFIG"/dist/*.whl /build/dist
done
which ccache && ccache -sv && ccache -z

View file

@ -9,24 +9,32 @@ 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>]"
exit 1;;
esac
done
mkdir -p $HOME/.onnx
mkdir -p "${HOME}/.onnx"
DOCKER_SCRIPT_OPTIONS="-d ${DEVICE} -c ${BUILD_CONFIG}"
if [ "${BUILD_EXTR_PAR}" != "" ] ; then
DOCKER_SCRIPT_OPTIONS+=" -x ${BUILD_EXTR_PAR}"
fi
docker run --rm \
--volume /data/onnx:/data/onnx:ro \
--volume $BUILD_SOURCESDIRECTORY:/onnxruntime_src \
--volume $BUILD_BINARIESDIRECTORY:/build \
--volume "${BUILD_SOURCESDIRECTORY}:/onnxruntime_src" \
--volume "${BUILD_BINARIESDIRECTORY}:/build" \
--volume /data/models:/build/models:ro \
--volume $HOME/.onnx:/home/onnxruntimedev/.onnx \
--volume "${HOME}/.onnx:/home/onnxruntimedev/.onnx" \
-w /onnxruntime_src \
-e NIGHTLY_BUILD \
-e BUILD_BUILDNUMBER \
$ADDITIONAL_DOCKER_PARAMETER \
$DOCKER_IMAGE tools/ci_build/github/linux/build_linux_arm64_python_package.sh -d $DEVICE -c $BUILD_CONFIG -x $BUILD_EXTR_PAR
$DOCKER_IMAGE tools/ci_build/github/linux/build_linux_python_package.sh $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 \
$BUILD_BINARIESDIRECTORY/$BUILD_CONFIG/CMakeFiles
cd $BUILD_BINARIESDIRECTORY/$BUILD_CONFIG
find -executable -type f > $BUILD_BINARIESDIRECTORY/$BUILD_CONFIG/perms.txt
sudo rm -rf "${BUILD_BINARIESDIRECTORY}/${BUILD_CONFIG}/onnxruntime" "${BUILD_BINARIESDIRECTORY}/${BUILD_CONFIG}/pybind11" \
"${BUILD_BINARIESDIRECTORY}/${BUILD_CONFIG}/models" "${BUILD_BINARIESDIRECTORY}/${BUILD_CONFIG}/_deps" \
"${BUILD_BINARIESDIRECTORY}/${BUILD_CONFIG}/CMakeFiles"
cd "${BUILD_BINARIESDIRECTORY}/${BUILD_CONFIG}"
find -executable -type f > "${BUILD_BINARIESDIRECTORY}/${BUILD_CONFIG}/perms.txt"