Skip to content

Commit

Permalink
Improve Windows ARM64 building & packaging (#687)
Browse files Browse the repository at this point in the history
A major overhaul of the NuGet packaging pipeline, including:

* Restructure capi & NuGet packaging pipeline to make multi-platform
nupkg possible. The NuGet artifacts are separated by EP(CPU, Cuda and
DirectML). A single nupkg contains native libraries for different os &
arch.
* Make win-arm64 CPU packages use DLLs from NuGet package, just like
win-x64.
* Enable win-arm64 DirectML NuGet build & packaging (Internal work item:
https://task.ms/aii/40037)
* Enable linux-x64 CPU & CUDA NuGet build & packaging (Internal work
item: https://task.ms/aii/34234)
* Continue the work of #683 to make it work with ARM64.

Run:
https://dev.azure.com/aiinfra/ONNX%20Runtime/_build/results?buildId=507547&view=results

Prior work: #498 
Supports: #637

 Future work: Needs #693 to fix Linux NuGet.

---------

Co-authored-by: Baiju Meswani <[email protected]>
Co-authored-by: kunal-vaishnavi <[email protected]>
  • Loading branch information
3 people authored Jul 24, 2024
1 parent 7f5a858 commit 1f96323
Show file tree
Hide file tree
Showing 26 changed files with 833 additions and 446 deletions.
35 changes: 21 additions & 14 deletions .github/workflows/win-cpu-arm64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
ort_dir: "onnxruntime-win-arm64-1.17.3"
ort_zip: "$(ort_dir).zip"
ort_url: "https://github.com/microsoft/onnxruntime/releases/download/v1.17.3/$(ort_zip)"
binaryDir: 'build/cpu'
binaryDir: 'build/cpu/win-arm64'
ORT_NIGHTLY_REST_API: "https://feeds.dev.azure.com/aiinfra/PublicPackages/_apis/packaging/Feeds/ORT-Nightly/packages?packageNameQuery=Microsoft.ML.OnnxRuntime&api-version=6.0-preview.1"
ORT_PACKAGE_NAME: "Microsoft.ML.OnnxRuntime"

jobs:
windows-cpu-arm64-build:
Expand All @@ -31,19 +30,27 @@ jobs:
vs-version: '17.4'
msbuild-architecture: arm64

- name: Download OnnxRuntime
run: |
$env:ort_url = "https://github.com/microsoft/onnxruntime/releases/download/v1.17.3/onnxruntime-win-arm64-1.17.3.zip"
Invoke-WebRequest -Uri $env:ort_url -OutFile $env:ort_zip
- uses: nuget/setup-nuget@v2
with:
nuget-version: '5.x'

- name: Unzip OnnxRuntime
- name: Download OnnxRuntime Nightly
shell: powershell
run: |
Expand-Archive $env:ort_zip -DestinationPath .
Remove-Item -Path $env:ort_zip
$resp = Invoke-RestMethod "${{ env.ORT_NIGHTLY_REST_API }}"
$ORT_NIGHTLY_VERSION = $resp.value[0].versions[0].normalizedVersion
Write-Host "$ORT_NIGHTLY_VERSION"
"ORT_NIGHTLY_VERSION=$ORT_NIGHTLY_VERSION" | Out-File -FilePath $env:GITHUB_ENV -Append
nuget install ${{ env.ORT_PACKAGE_NAME }} -version $ORT_NIGHTLY_VERSION -x -NonInteractive
- run: Get-ChildItem ${{ env.ORT_PACKAGE_NAME }} -Recurse
continue-on-error: true

- name: Rename OnnxRuntime to ort
- name: Extract OnnxRuntime library and header files
run: |
Rename-Item -Path $env:ort_dir -NewName ort
mkdir ort/lib
move ${{ env.ORT_PACKAGE_NAME }}/build/native/include ort/
move ${{ env.ORT_PACKAGE_NAME }}/runtimes/win-arm64/native/* ort/lib/
- name: Configure CMake
run: |
Expand Down Expand Up @@ -80,4 +87,4 @@ jobs:
- name: Run tests
run: |
.\build\cpu\test\Release\unit_tests.exe
& .\$env:binaryDir\test\Release\unit_tests.exe
13 changes: 5 additions & 8 deletions .github/workflows/win-cpu-x64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
binaryDir: 'build/cpu'
binaryDir: 'build/cpu/win-x64'
ORT_NIGHTLY_REST_API: "https://feeds.dev.azure.com/aiinfra/PublicPackages/_apis/packaging/Feeds/ORT-Nightly/packages?packageNameQuery=Microsoft.ML.OnnxRuntime&api-version=6.0-preview.1"
ORT_PACKAGE_NAME: "Microsoft.ML.OnnxRuntime"

Expand Down Expand Up @@ -41,15 +41,12 @@ jobs:
with:
dotnet-version: '8.0.x'

- name : Install jq and curl
run: |
choco install -y jq curl
- name: Download OnnxRuntime Nightly
shell: pwsh
run: |
$ORT_NIGHTLY_VERSION = $(curl -s "${{ env.ORT_NIGHTLY_REST_API }}" | jq -r '.value[0].versions[0].normalizedVersion')
echo "$ORT_NIGHTLY_VERSION"
$resp = Invoke-RestMethod "${{ env.ORT_NIGHTLY_REST_API }}"
$ORT_NIGHTLY_VERSION = $resp.value[0].versions[0].normalizedVersion
Write-Host "$ORT_NIGHTLY_VERSION"
"ORT_NIGHTLY_VERSION=$ORT_NIGHTLY_VERSION" | Out-File -FilePath $env:GITHUB_ENV -Append
nuget install ${{ env.ORT_PACKAGE_NAME }} -version $ORT_NIGHTLY_VERSION -x -NonInteractive
Expand Down Expand Up @@ -108,7 +105,7 @@ jobs:
- name: Run tests
run: |
.\build\cpu\test\Release\unit_tests.exe
& .\$env:binaryDir\test\Release\unit_tests.exe
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/win-cuda-x64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:
cuda_dir: "${{ github.workspace }}\\cuda_sdk"
cuda_version: "11.8"
CUDA_PATH: ${{ github.workspace }}\\cuda_sdk\\v11.8
binaryDir: 'build/cuda'
binaryDir: 'build/cuda/win-x64'
ORT_NIGHTLY_REST_API: "https://feeds.dev.azure.com/aiinfra/PublicPackages/_apis/packaging/Feeds/ORT-Nightly/packages?packageNameQuery=Microsoft.ML.OnnxRuntime.Gpu.Windows&api-version=6.0-preview.1"
ORT_PACKAGE_NAME: "Microsoft.ML.OnnxRuntime.Gpu.Windows"

Expand All @@ -43,15 +43,12 @@ jobs:
with:
dotnet-version: '8.0.x'

- name : Install jq and curl
run: |
choco install -y jq curl
- name: Download OnnxRuntime Nightly
shell: pwsh
run: |
$ORT_NIGHTLY_VERSION=$(curl -s "${{ env.ORT_NIGHTLY_REST_API }}" | jq -r '.value[0].versions[0].normalizedVersion')
echo "$ORT_NIGHTLY_VERSION"
$resp = Invoke-RestMethod "${{ env.ORT_NIGHTLY_REST_API }}"
$ORT_NIGHTLY_VERSION = $resp.value[0].versions[0].normalizedVersion
Write-Host "$ORT_NIGHTLY_VERSION"
"ORT_NIGHTLY_VERSION=$ORT_NIGHTLY_VERSION" | Out-File -FilePath $env:GITHUB_ENV -Append
nuget install ${{ env.ORT_PACKAGE_NAME }} -version $ORT_NIGHTLY_VERSION -ExcludeVersion -NonInteractive
Expand Down Expand Up @@ -110,4 +107,4 @@ jobs:
run: |
$env:PATH = "${{ env.cuda_dir }}\\v${{ env.cuda_version }}\\bin;" + $env:PATH
echo "Current PATH variable is: $env:PATH"
.\build\cuda\test\Release\unit_tests.exe
& .\$env:binaryDir\test\Release\unit_tests.exe
4 changes: 2 additions & 2 deletions .github/workflows/win-directml-x64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ env:
d3d12_dir: "Microsoft.Direct3D.D3D12.1.614.0"
d3d12_zip: "Microsoft.Direct3D.D3D12.1.614.0.zip"
d3d12_url: "https://www.nuget.org/api/v2/package/Microsoft.Direct3D.D3D12/1.614.0"
binaryDir: 'build/directml'
binaryDir: 'build/directml/win-x64'


jobs:
Expand Down Expand Up @@ -102,4 +102,4 @@ jobs:
- name: Run tests
run: |
.\build\directml\test\Release\unit_tests.exe
& .\$env:binaryDir\test\Release\unit_tests.exe
21 changes: 17 additions & 4 deletions .pipelines/nuget-publishing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ parameters:
type: boolean
default: true

- name: enable_win_arm64_cpu
- name: enable_win_arm64
displayName: 'Whether Windows ARM64 package is built.'
type: boolean
default: true
Expand Down Expand Up @@ -75,19 +75,32 @@ resources:

trigger: none
stages:
- template: stages/nuget-packaging-stage.yml
- template: stages/capi-packaging-stage.yml
parameters:
enable_win_cpu: ${{ parameters.enable_win_cpu }}
enable_win_cuda: ${{ parameters.enable_win_cuda }}
enable_linux_cpu: ${{ parameters.enable_linux_cpu }}
enable_linux_cuda: ${{ parameters.enable_linux_cuda }}
enable_win_dml: ${{ parameters.enable_win_dml }}
enable_win_arm64_cpu: ${{ parameters.enable_win_arm64_cpu }}
enable_win_arm64: ${{ parameters.enable_win_arm64 }}
ort_version: ${{ parameters.ort_version }}
ort_cuda_version: ${{ parameters.ort_cuda_version }}
ort_dml_version: ${{ parameters.ort_dml_version }}
cuda_version: ${{ parameters.cuda_version }}
build_config: ${{ parameters.build_config }}

- template: stages/nuget-packaging-stage.yml
parameters:
enable_win_cpu: ${{ parameters.enable_win_cpu }}
enable_win_cuda: ${{ parameters.enable_win_cuda }}
enable_linux_cpu: ${{ parameters.enable_linux_cpu }}
enable_linux_cuda: ${{ parameters.enable_linux_cuda }}
enable_win_dml: ${{ parameters.enable_win_dml }}
enable_win_arm64: ${{ parameters.enable_win_arm64 }}
ort_version: ${{ parameters.ort_version }}
ort_dml_version: ${{ parameters.ort_dml_version }}
build_config: ${{ parameters.build_config }}

- ${{ if eq(parameters.enable_post_packaging_validation, true) }}:
- template: stages/nuget-validation-stage.yml
parameters:
Expand All @@ -96,7 +109,7 @@ stages:
enable_linux_cpu: ${{ parameters.enable_linux_cpu }}
enable_linux_cuda: ${{ parameters.enable_linux_cuda }}
enable_win_dml: ${{ parameters.enable_win_dml }}
enable_win_arm64_cpu: ${{ parameters.enable_win_arm64_cpu }}
enable_win_arm64: ${{ parameters.enable_win_arm64 }}
ort_version: ${{ parameters.ort_version }}
ort_cuda_version: ${{ parameters.ort_cuda_version }}
ort_dml_version: ${{ parameters.ort_dml_version }}
Expand Down
2 changes: 1 addition & 1 deletion .pipelines/pypl-publishing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@ stages:
ort_rocm_version: ${{ parameters.ort_rocm_version }}
ort_dml_version: ${{ parameters.ort_dml_version }}
cuda_versions: ${{ parameters.cuda_versions }}
SpecificArtifact: false
SpecificArtifact: false
94 changes: 94 additions & 0 deletions .pipelines/stages/capi-packaging-stage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
parameters:
- name: enable_win_cpu
type: boolean
- name: enable_win_cuda
type: boolean
- name: enable_win_dml
type: boolean
- name: enable_win_arm64
type: boolean
- name: enable_linux_cpu
type: boolean
- name: enable_linux_cuda
type: boolean
- name: ort_version
type: string
- name: ort_cuda_version
type: string
- name: ort_dml_version
type: string
- name: cuda_version
type: string
default: ''
- name: build_config
type: string
default: 'release'


stages:
- stage: capi_packaging
jobs:
- ${{ if eq(parameters.enable_win_cpu, true) }}:
- template: jobs/capi-packaging-job.yml
parameters:
arch: 'x64'
ep: 'cpu'
ort_version: ${{ parameters.ort_version }}
os: 'win'
build_config: ${{ parameters.build_config }}

- ${{ if eq(parameters.enable_win_arm64, true) }}:
- template: jobs/capi-packaging-job.yml
parameters:
arch: 'arm64'
ep: 'cpu'
ort_version: ${{ parameters.ort_version }}
os: 'win'
build_config: ${{ parameters.build_config }}

- ${{ if eq(parameters.enable_win_dml, true) }}:
- template: jobs/capi-packaging-job.yml
parameters:
arch: 'x64'
ep: 'directml'
ort_version: ${{ parameters.ort_dml_version }}
os: 'win'
build_config: ${{ parameters.build_config }}

- ${{ if and(eq(parameters.enable_win_arm64, true), eq(parameters.enable_win_dml, true)) }}:
- template: jobs/capi-packaging-job.yml
parameters:
arch: 'arm64'
ep: 'directml'
ort_version: ${{ parameters.ort_dml_version }}
os: 'win'
build_config: ${{ parameters.build_config }}

- ${{ if eq(parameters.enable_win_cuda, true) }}:
- template: jobs/capi-packaging-job.yml
parameters:
arch: 'x64'
cuda_version: ${{ parameters.cuda_version }}
ep: 'cuda'
ort_version: ${{ parameters.ort_cuda_version }}
os: 'win'
build_config: ${{ parameters.build_config }}

- ${{ if eq(parameters.enable_linux_cpu, true) }}:
- template: jobs/capi-packaging-job.yml
parameters:
arch: 'x64'
ep: 'cpu'
ort_version: ${{ parameters.ort_version }}
os: 'linux'
build_config: ${{ parameters.build_config }}

- ${{ if eq(parameters.enable_linux_cuda, true) }}:
- template: jobs/capi-packaging-job.yml
parameters:
arch: 'x64'
cuda_version: ${{ parameters.cuda_version }}
ep: 'cuda'
ort_version: ${{ parameters.ort_cuda_version }}
os: 'linux'
build_config: ${{ parameters.build_config }}
Loading

0 comments on commit 1f96323

Please sign in to comment.