forked from RTKConsortium/RTK
-
Notifications
You must be signed in to change notification settings - Fork 0
209 lines (180 loc) Β· 10.1 KB
/
build-test-package-python-cuda.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: 'Package RTK with CUDA'
on: [push,pull_request]
env:
itk-wheel-tag: 'v5.4.0'
itk-python-package-tag: '45cfd02a22661731ca5b155f210cfa2f887d50e7'
itk-python-package-org: 'SimonRit'
itk-module-deps: "RTKConsortium/ITKCudaCommon@cae7c93c2f6d4c5b3cb5f6e5ce4a97686e626bf7"
jobs:
build-linux-cuda-python-packages:
runs-on: self-hosted-linux
strategy:
max-parallel: 2
matrix:
python3-minor-version: ["8","9","10","11"]
manylinux-platform: ["_2_28-x64","2014-x64"]
cuda-version: ["116","121"]
steps:
- uses: actions/checkout@v3
- name: 'Fetch build script'
run: |
IPP_DOWNLOAD_GIT_TAG=${{ env.itk-python-package-tag }}
IPP_DOWNLOAD_ORG=${{ env.itk-python-package-org }}
curl -L https://raw.githubusercontent.com/${IPP_DOWNLOAD_ORG:=InsightSoftwareConsortium}/ITKPythonPackage/${IPP_DOWNLOAD_GIT_TAG:=master}/scripts/dockcross-manylinux-download-cache-and-build-module-wheels.sh -O
chmod u+x dockcross-manylinux-download-cache-and-build-module-wheels.sh
- name: 'Build π Python π¦ package'
shell: bash
run: |
rm -rf dist
export ITK_PACKAGE_VERSION=${{ env.itk-wheel-tag }}
export ITKPYTHONPACKAGE_TAG=${{ env.itk-python-package-tag }}
export ITKPYTHONPACKAGE_ORG=${{ env.itk-python-package-org }}
export ITK_MODULE_PREQ=${{ env.itk-module-deps }}
export CUDA_VERSION=${{ matrix.cuda-version }}
export CUDA_VERSION_MAJOR=`(echo ${CUDA_VERSION} | cut -b1-2)`
export CUDA_VERSION_MINOR=`(echo ${CUDA_VERSION} | cut -b3-)`
CMAKE_OPTIONS="-DRTK_CUDA_VERSION=${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DRTK_BUILD_APPLICATIONS:BOOL=OFF"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCUDAToolkit_ROOT=/usr/lib64/cuda${CUDA_VERSION}"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_CUDA_COMPILER=/usr/lib64/cuda${CUDA_VERSION}/bin/nvcc"
# The first two are not library paths but are included to be mounted in the
# docker by dockcross-manylinux-build-module-wheels.sh
export LD_LIBRARY_PATH="/home/srit/Downloads/cuda${CUDA_VERSION}"
export LD_LIBRARY_PATH="/usr/lib64/libcuda.so.1:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH="/home/srit/Downloads/cuda${CUDA_VERSION}/targets/x86_64-linux/lib:$LD_LIBRARY_PATH"
if test -e ../../ITKPythonBuilds-linux-manylinux2014.tar.zst ; then
mv ../../*zst .
fi
MANYLINUX_PLATFORM=${{ matrix.manylinux-platform }}
if test ${MANYLINUX_PLATFORM} == "_2_28-x64" && test ${CUDA_VERSION} -lt 120; then
export IMAGE_TAG=20230106-1aeaea0
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DITK_USE_PYTHON_LIMITED_API=FALSE"
fi
CMAKE_OPTIONS=(--cmake_options "${CMAKE_OPTIONS}")
echo "Manylinux platform ${MANYLINUX_PLATFORM}"
rm -rf ITKPythonPackage
export MANYLINUX_VERSION=`(echo ${MANYLINUX_PLATFORM} | cut -d '-' -f 1)`
export TARGET_ARCH=`(echo ${MANYLINUX_PLATFORM} | cut -d '-' -f 2)`
export ITK_MODULE_NO_CLEANUP=TRUE
echo "Building for manylinux specialization ${MANYLINUX_VERSION} and target architecture ${TARGET_ARCH}"
LIBCUDART=`basename /home/srit/Downloads/cuda${CUDA_VERSION}/targets/x86_64-linux/lib/libcudart.so.${CUDA_VERSION_MAJOR}*`
LIBCUBLAS=`basename /home/srit/Downloads/cuda${CUDA_VERSION}/targets/x86_64-linux/lib/libcublas.so.${CUDA_VERSION_MAJOR}*`
LIBCUBLASLT=`basename /home/srit/Downloads/cuda${CUDA_VERSION}/targets/x86_64-linux/lib/libcublasLt.so.${CUDA_VERSION_MAJOR}*`
LIBCUFFT=`basename /home/srit/Downloads/cuda${CUDA_VERSION}/targets/x86_64-linux/lib/libcufft.so.$((${CUDA_VERSION_MAJOR}-1))*`
sed -i "s/dependencies = \[/dependencies = [ \"itk-cudacommon-cuda${CUDA_VERSION} == 1.1.*\",/g" pyproject.toml
sed -i "s/itk-rtk/itk-rtk-cuda${CUDA_VERSION}/g" pyproject.toml
./dockcross-manylinux-download-cache-and-build-module-wheels.sh "${CMAKE_OPTIONS[@]}" -x "libcuda.so.1;${LIBCUDART};${LIBCUBLAS};${LIBCUBLASLT};${LIBCUFFT}" cp3${{ matrix.python3-minor-version }}
mv *zst ../..
- name: Validate build output
shell: bash
run: |
/home/srit/miniconda3/envs/py310/bin/python -m pip install twine
ls dist/
MANYLINUX_PLATFORM=${{ matrix.manylinux-platform }}
MANYLINUX_VERSION=`(echo ${MANYLINUX_PLATFORM} | cut -d '-' -f 1)`
TARGET_ARCH_NAME=`(echo ${MANYLINUX_PLATFORM} | cut -d '-' -f 2)`
if [[ ${TARGET_ARCH_NAME} == "x64" ]]; then
TARGET_ARCH_NAME="x86_64" # Match auditwheel naming convention
fi
WHEEL_PATTERN="dist/itk_*cp3${{ matrix.python3-minor-version }}*manylinux${MANYLINUX_VERSION}*${TARGET_ARCH_NAME}.whl"
echo "Searching for wheels matching pattern ${WHEEL_PATTERN}"
/home/srit/miniconda3/envs/py310/bin/python -m twine check ${WHEEL_PATTERN}
- name: Publish Python package as GitHub Artifact
uses: actions/upload-artifact@v3
with:
name: LinuxWheel3${{ matrix.python3-minor-version }}${{ matrix.manylinux-platform }}-cuda${{ matrix.cuda-version }}
path: dist/*.whl
build-windows-cuda-python-packages:
runs-on: self-hosted-windows
strategy:
max-parallel: 2
matrix:
python3-minor-version: ["8","9","10","11"]
cuda-version: ["116","121"]
steps:
- uses: actions/checkout@v4
with:
path: "im"
- name: 'Reduce source path length'
shell: bash
run: |
# Move ITKPythonBuilds archive to the checked-out source
if test -f ../../im/ITKPythonBuilds-windows.zip; then
mv ../../im/*.zip im
fi
rm -fr ../../im
# Move checked-out source to a shorter path to avoid Windows path length issues
mv im ../../
- name: 'Fetch build script'
shell: pwsh
run: |
cd ../../im
$ITKPYTHONPACKAGE_TAG = "${{ env.itk-python-package-tag }}"
$ITKPYTHONPACKAGE_ORG = "${{ env.itk-python-package-org }}"
$SCRIPT_UPSTREAM = "https://raw.githubusercontent.com/$ITKPYTHONPACKAGE_ORG/ITKPythonPackage/$ITKPYTHONPACKAGE_TAG/scripts/windows-download-cache-and-build-module-wheels.ps1"
echo "Fetching $SCRIPT_UPSTREAM"
(new-object net.webclient).DownloadString($SCRIPT_UPSTREAM) > windows-download-cache-and-build-module-wheels.ps1
- name: 'Build π Python π¦ package'
shell: pwsh
run: |
if (Test-Path dist) { rm dist -r -fo }
cd ../../im
& "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1" -Arch amd64 -SkipAutomaticLocation
$env:CC="cl.exe"
$env:CXX="cl.exe"
$env:ITK_PACKAGE_VERSION = "${{ env.itk-wheel-tag }}"
$env:ITKPYTHONPACKAGE_TAG = "${{ env.itk-python-package-tag }}"
$env:ITKPYTHONPACKAGE_ORG = "${{ env.itk-python-package-org }}"
$env:ITK_MODULE_PREQ = "${{ env.itk-module-deps }}"
$CUDA_VERSION = "${{ matrix.cuda-version }}"
$CUDA_VERSION_MAJOR=$CUDA_VERSION.substring(0,2)
$CUDA_VERSION_MINOR=$CUDA_VERSION.substring(2,$CUDA_VERSION.Length-2)
$env:CUDA_PATH = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}"
$env:CUDACXX = "$env:CUDA_PATH\bin\nvcc.exe"
$env:Path = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}\bin;" + $env:Path
$LIBCUDART= (Get-Item "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}\bin\cudart64*dll" ).Name
$LIBCUBLAS= (Get-Item "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}\bin\cublas64*dll" ).Name
$LIBCUBLASLT= (Get-Item "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}\bin\cublasLt64*dll" ).Name
$LIBCUFFT= (Get-Item "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}\bin\cufft64*dll" ).Name
((Get-Content -Path pyproject.toml) -replace "itk-rtk","itk-rtk-cuda${CUDA_VERSION}") | Set-Content -Path pyproject.toml
((Get-Content -Path pyproject.toml) -replace "dependencies = \[","dependencies = [""itk-cudacommon-cuda${CUDA_VERSION} == 1.1.*"",") | Set-Content -Path pyproject.toml
./windows-download-cache-and-build-module-wheels.ps1 "${{ matrix.python3-minor-version }}" -setup_options "--lib-paths ""C:/Program\ Files/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}/bin"" --exclude-libs ""nvcuda.dll;concrt140.dll;${LIBCUDART};${LIBCUBLAS};${LIBCUBLASLT};${LIBCUFFT}""" -cmake_options """-DRTK_CUDA_VERSION=${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}"" ""-DRTK_BUILD_APPLICATIONS:BOOL=OFF"""
mkdir -p '${{ github.workspace }}\dist'
cp 'dist\*.whl' '${{ github.workspace }}\dist'
- name: Validate build output
shell: pwsh
run: |
python -m pip install twine
ls dist/
$WHEEL_PATTERN = "dist/itk_*cp3${{ matrix.python3-minor-version }}*win*.whl"
echo "Searching for wheels matching pattern ${WHEEL_PATTERN}"
python -m twine check ${WHEEL_PATTERN}
- name: Publish Python package as GitHub Artifact
uses: actions/upload-artifact@v4
with:
name: WindowsWheel3${{ matrix.python3-minor-version }}-cuda${{ matrix.cuda-version }}
path: dist/*.whl
publish-python-packages-to-pypi:
needs:
- build-linux-cuda-python-packages
- build-windows-cuda-python-packages
runs-on: ubuntu-22.04
steps:
- name: Download Python Packages
uses: actions/download-artifact@v4
- name: Prepare packages for upload
run: |
ls -R
for d in */; do
mv ${d}/*.whl .
done
mkdir dist
mv *.whl dist/
ls dist
- name: Publish π Python π¦ package to PyPI
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@v1.5.1
with:
skip_existing: true
user: __token__
password: ${{ secrets.pypi_password }}