1
1
name : Python package
2
2
3
3
on :
4
- push : {}
5
- pull_request :
4
+ push :
6
5
branches : [ main ]
6
+ pull_request :
7
7
paths :
8
8
- ' .github/workflows/python-package.yml'
9
9
- ' bitsandbytes/**'
17
17
- ' pytest.ini'
18
18
- ' **/*.md'
19
19
release :
20
+ branches : [ main ]
20
21
types : [ published ]
21
22
23
+ concurrency :
24
+ group : ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
25
+ cancel-in-progress : true
26
+
22
27
jobs :
23
28
24
29
# #
25
30
# This job matrix builds the non-CUDA versions of the libraries for all supported platforms.
26
31
# #
27
32
build-shared-libs :
28
33
strategy :
34
+ # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
35
+ fail-fast : false
36
+
29
37
matrix :
30
38
os : [ubuntu-latest, macos-latest, windows-latest]
31
39
arch : [x86_64, aarch64]
40
+ build_type : [Release]
32
41
exclude :
33
42
- os : windows-latest # This probably requires arm64 Windows agents
34
43
arch : aarch64
35
44
runs-on : ${{ matrix.os }} # One day, we could run them on native agents. Azure supports this now but it's planned only for Q3 2023 for hosted agents
36
45
steps :
37
46
# Check out code
38
47
- uses : actions/checkout@v4
39
- # On Linux we use CMake within Docker
40
- - name : Setup cmake
41
- uses : jwlawson/actions-setup-cmake@v1.14
42
- with :
43
- cmake-version : ' 3.26.x'
48
+ - name : Allow cross-compile on aarch64
49
+ if : ${{ startsWith(matrix.os, 'ubuntu') && matrix.arch == 'aarch64' }}
50
+ run : |
51
+ # Allow cross-compile on aarch64
52
+ sudo apt-get install -y g++-aarch64-linux-gnu binutils-aarch64-linux-gnu
53
+
44
54
- name : Setup MSVC
45
55
if : startsWith(matrix.os, 'windows')
46
56
# uses: microsoft/setup-msbuild@v1.1 # to use msbuild
47
57
uses : ilammy/msvc-dev-cmd@v1.13.0 # to use cl
48
- # Compile C++ code
49
- - name : Build C++
50
- shell : bash
58
+ - name : Prep Compilers
59
+ shell : bash -el {0}
51
60
run : |
52
- set -ex
53
- build_os=${{ matrix.os }}
54
- build_arch=${{ matrix.arch }}
55
- if [ ${build_os:0:6} == ubuntu -a ${build_arch} == aarch64 ]; then
56
- # Allow cross-compile om aarch64
57
- sudo apt-get install -y gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
58
- fi
59
- if [ ${build_os:0:5} == macos -a ${build_arch} == aarch64 ]; then
60
- cmake -DCMAKE_OSX_ARCHITECTURES=arm64 -DCOMPUTE_BACKEND=cpu .
61
+ python3 -m pip install cmake==3.27.9 ninja
62
+ if [[ "${{ matrix.os }}" = windows-* ]]; then
63
+ echo CXX_COMPILER=-DCMAKE_CXX_COMPILER=cl >> "$GITHUB_ENV"
64
+ elif [[ "${{ matrix.os }}" = ubuntu-* ]] && [[ "${{ matrix.arch }}" = "aarch64" ]]; then
65
+ echo CXX_COMPILER=-DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ >> "$GITHUB_ENV"
61
66
else
62
- cmake -DCOMPUTE_BACKEND=cpu .
67
+ echo CXX_COMPILER=-DCMAKE_CXX_COMPILER=g++ >> "$GITHUB_ENV"
68
+ fi
69
+
70
+ if [[ "${{ matrix.os }}" = macos-* ]] && [[ "${{ matrix.arch }}" = "aarch64" ]]; then
71
+ echo DCMAKE_OSX_ARCHITECTURES=-DCMAKE_OSX_ARCHITECTURES=arm64 >> "$GITHUB_ENV"
63
72
fi
64
- cmake --build . --config Release
73
+
74
+ - name : Build CPU
75
+ shell : bash -el {0}
76
+ run : |
77
+ cmake -B build \
78
+ -G Ninja ${{ env.DCMAKE_OSX_ARCHITECTURES }} \
79
+ ${{ env.CXX_COMPILER }} \
80
+ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
81
+ -DCOMPUTE_BACKEND=cpu \
82
+ -S .
83
+
84
+ cmake --build build --config ${{ matrix.build_type }}
85
+
65
86
mkdir -p output/${{ matrix.os }}/${{ matrix.arch }}
87
+ ls -l bitsandbytes
88
+ echo " check lib files..."
89
+ file bitsandbytes/libbitsandbytes*.*
66
90
( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ )
67
91
- name : Upload build artifact
68
92
uses : actions/upload-artifact@v4
69
93
with :
70
94
name : shared_library_${{ matrix.os }}_${{ matrix.arch }}
71
95
path : output/*
72
- retention-days : 7
73
96
# #
74
97
# This job matrix builds the CUDA versions of the libraries for platforms that support CUDA (Linux x64/aarch64 + Windows x64)
75
98
# #
76
99
build-shared-libs-cuda :
77
100
strategy :
101
+ # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
102
+ fail-fast : false
103
+
78
104
matrix :
79
105
os : [ubuntu-latest, windows-latest]
80
106
arch : [x86_64, aarch64]
81
- cuda_version : ['12.1.0']
107
+ cuda-version : ['11.8.0', '12.1.1']
108
+ build_type : [Release]
82
109
exclude :
83
110
- os : windows-latest # This probably requires arm64 Windows agents
84
111
arch : aarch64
@@ -90,64 +117,106 @@ jobs:
90
117
- name : Set up Docker multiarch
91
118
if : startsWith(matrix.os, 'ubuntu')
92
119
uses : docker/setup-qemu-action@v2
93
- # On Linux we use CMake within Docker
94
- - name : Setup cmake
95
- if : ${{ !startsWith(matrix.os, 'linux') }}
96
- uses : jwlawson/actions-setup-cmake@v1.14
97
- with :
98
- cmake-version : ' 3.26.x'
99
120
# Windows: We install Cuda on the agent (slow)
100
121
- uses : Jimver/cuda-toolkit@v0.2.14
101
122
if : startsWith(matrix.os, 'windows')
102
123
id : cuda-toolkit
103
124
with :
104
- cuda : ${{ matrix.cuda_version }}
125
+ cuda : ${{ matrix.cuda-version }}
105
126
method : ' network'
106
127
sub-packages : ' ["nvcc","cudart","cusparse","cublas","thrust","nvrtc_dev","cublas_dev","cusparse_dev"]'
107
128
linux-local-args : ' ["--toolkit"]'
108
129
use-github-cache : false
130
+ - name : Set up Python 3.10
131
+ uses : actions/setup-python@v5
132
+ with :
133
+ python-version : " 3.10"
134
+
109
135
- name : Setup MSVC
110
136
if : startsWith(matrix.os, 'windows')
111
137
# uses: microsoft/setup-msbuild@v1.1 # to use msbuild
112
138
uses : ilammy/msvc-dev-cmd@v1.13.0 # to use cl
113
- # Compile C++ code
114
- - name : Build C++
139
+ - name : Setup Environments
140
+ if : startsWith(matrix.os, 'windows')
141
+ shell : bash -el {0}
142
+ run : |
143
+ if [[ "${{ matrix.os }}" = windows-* ]]; then
144
+ echo CXX_COMPILER=-DCMAKE_CXX_COMPILER=cl >> "$GITHUB_ENV"
145
+ # without -DCMAKE_CUDA_COMPILER=nvcc, cmake config always fail for cuda-11.8
146
+ echo DCMAKE_CUDA_COMPILER=-DCMAKE_CUDA_COMPILER=nvcc >> "$GITHUB_ENV"
147
+ else
148
+ echo CXX_COMPILER=-DCMAKE_CXX_COMPILER=g++ >> "$GITHUB_ENV"
149
+ fi
150
+
151
+ if [[ "${{ matrix.os }}" = macos-* ]] && [[ "${{ matrix.arch }}" = "aarch64" ]]; then
152
+ echo DCMAKE_OSX_ARCHITECTURES=-DCMAKE_OSX_ARCHITECTURES=arm64 >> "$GITHUB_ENV"
153
+ fi
154
+
155
+ nvcc --version
156
+
157
+ - name : Prep build
158
+ if : startsWith(matrix.os, 'windows')
159
+ run : python -m pip install cmake==3.27.9 ninja
160
+
161
+ - name : Build CUDA
162
+ if : startsWith(matrix.os, 'windows')
163
+ shell : bash -el {0}
164
+ run : |
165
+ cmake -B build \
166
+ -G Ninja ${{ env.DCMAKE_CUDA_COMPILER }} \
167
+ ${{ env.CXX_COMPILER }} \
168
+ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
169
+ -DCOMPUTE_CAPABILITY="50;52;60;61;62;70;72;75;80;86;87;89;90" \
170
+ -DCOMPUTE_BACKEND=cuda \
171
+ -S .
172
+
173
+ cmake --build build --config ${{ matrix.build_type }}
174
+
175
+ - name : Build CUDA (docker)
176
+ if : startsWith(matrix.os, 'ubuntu')
177
+ uses : addnab/docker-run-action@v3
178
+ with :
179
+ image : ${{ format('nvidia/cuda:{0}-{1}', matrix.cuda-version, 'devel-ubuntu22.04') }}
180
+ options : --platform linux/${{ matrix.arch }} -w /src -v ${{ github.workspace }}:/src
181
+ run : |
182
+ apt-get update
183
+ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends cmake python3 python3-pip
184
+ # install ninja to use -G ninja
185
+ python3 -m pip install ninja
186
+
187
+ for NO_CUBLASLT in OFF ON; do
188
+ cmake -B build \
189
+ -G Ninja \
190
+ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
191
+ -DCOMPUTE_CAPABILITY="50;52;60;61;62;70;72;75;80;86;87;89;90" \
192
+ -DCOMPUTE_BACKEND=cuda \
193
+ -DNO_CUBLASLT=$NO_CUBLASLT \
194
+ -S .
195
+
196
+ cmake --build build --config ${{ matrix.build_type }}
197
+ done
198
+
199
+ - name : Copy libraries
115
200
shell : bash
116
201
run : |
117
- set -ex
118
- build_os=${{ matrix.os }}
119
- build_arch=${{ matrix.arch }}
120
- [[ "${{ matrix.os }}" = windows-* ]] && python3 -m pip install ninja
121
- for NO_CUBLASLT in ON OFF; do
122
- if [ ${build_os:0:6} == ubuntu ]; then
123
- image=nvidia/cuda:${{ matrix.cuda_version }}-devel-ubuntu22.04
124
- echo "Using image $image"
125
- docker run --platform linux/$build_arch -i -w /src -v $PWD:/src $image sh -c \
126
- "apt-get update \
127
- && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends cmake \
128
- && cmake -DCOMPUTE_BACKEND=cuda -DNO_CUBLASLT=${NO_CUBLASLT} . \
129
- && cmake --build ."
130
- else
131
- cmake -G Ninja -DCOMPUTE_BACKEND=cuda -DNO_CUBLASLT=${NO_CUBLASLT} -DCMAKE_BUILD_TYPE=Release -S .
132
- cmake --build . --config Release
133
- fi
134
- done
135
202
mkdir -p output/${{ matrix.os }}/${{ matrix.arch }}
203
+ echo " check lib files..."
204
+ file bitsandbytes/libbitsandbytes*.*
136
205
( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ )
137
206
- name : Upload build artifact
138
207
uses : actions/upload-artifact@v4
139
208
with :
140
- name : shared_library_cuda_${{ matrix.os }}_${{ matrix.arch }}_${{ matrix.cuda_version }}
209
+ name : shared_library_cuda_${{ matrix.os }}_${{ matrix.arch }}_${{ matrix.cuda-version }}
141
210
path : output/*
142
- retention-days : 7
211
+
143
212
build-wheels :
144
213
needs :
145
214
- build-shared-libs
146
215
- build-shared-libs-cuda
147
216
strategy :
148
217
matrix :
149
218
os : [ubuntu-latest, macos-latest, windows-latest]
150
- python-version : ["3.9", "3.10", "3.11", "3.12 "]
219
+ python-version : ["3.10 "]
151
220
arch : [x86_64, aarch64]
152
221
exclude :
153
222
- os : windows-latest # This probably requires arm64 Windows agents
@@ -187,16 +256,23 @@ jobs:
187
256
# PYTHONPATH=. pytest --log-cli-level=DEBUG tests
188
257
- name : Build wheel
189
258
shell : bash
190
- run : python -m build .
259
+ run : |
260
+ python -m build . --wheel
261
+ # fix wheel name
262
+ if [ "${{ matrix.arch }}" = "aarch64" ]; then
263
+ o=$(ls dist/*.whl)
264
+ n=$(echo $o | sed 's@_x86_64@_aarch64@')
265
+ [ "$n" != "$o" ] && mv $o $n
266
+ fi
191
267
- name : Upload build artifact
192
268
uses : actions/upload-artifact@v4
193
269
with :
194
- name : bdist_wheel_${{ matrix.os }}_${{ matrix.arch }}_${{ matrix.python-version }}
195
- path : dist/bitsandbytes-*.whl
196
- retention-days : 7
270
+ name : bdist_wheel_${{ matrix.os }}-${{ matrix.arch }}
271
+ path : ${{ github.workspace }}/dist/bitsandbytes-*.whl
197
272
publish :
198
273
needs : build-wheels
199
274
runs-on : ubuntu-latest
275
+ if : startsWith(github.ref, 'refs/tags')
200
276
steps :
201
277
- uses : actions/checkout@v4
202
278
- name : Download build artifact
@@ -208,7 +284,6 @@ jobs:
208
284
- run : |
209
285
ls -lR dist/
210
286
- name : Publish to PyPi
211
- if : startsWith(github.ref, 'refs/tags')
212
287
uses : pypa/gh-action-pypi-publish@release/v1
213
288
with :
214
289
password : ${{ secrets.pypi }}
0 commit comments