Skip to content

Commit 29aa6c1

Browse files
committed
CI: restore some accidentally removed stuff and polish
* fix to support cmake -B build option * add cuda 11.8, 12.1 * use python-version==3.10 for builds. * fix wheel names for aarch64 * drop artifact retention-days: it could be configured Settings->Actions->General. * make wheel with all available cuda versions. * use docker-run-actions * update docker image version
1 parent 56d866a commit 29aa6c1

File tree

2 files changed

+133
-79
lines changed

2 files changed

+133
-79
lines changed

.github/workflows/python-package.yml

+133-58
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: Python package
22

33
on:
4-
push: {}
5-
pull_request:
4+
push:
65
branches: [ main ]
6+
pull_request:
77
paths:
88
- '.github/workflows/python-package.yml'
99
- 'bitsandbytes/**'
@@ -17,68 +17,95 @@ on:
1717
- 'pytest.ini'
1818
- '**/*.md'
1919
release:
20+
branches: [ main ]
2021
types: [ published ]
2122

23+
concurrency:
24+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
25+
cancel-in-progress: true
26+
2227
jobs:
2328

2429
##
2530
# This job matrix builds the non-CUDA versions of the libraries for all supported platforms.
2631
##
2732
build-shared-libs:
2833
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+
2937
matrix:
3038
os: [ubuntu-latest, macos-latest, windows-latest]
3139
arch: [x86_64, aarch64]
40+
build_type: [Release]
3241
exclude:
3342
- os: windows-latest # This probably requires arm64 Windows agents
3443
arch: aarch64
3544
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
3645
steps:
3746
# Check out code
3847
- 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+
4454
- name: Setup MSVC
4555
if: startsWith(matrix.os, 'windows')
4656
#uses: microsoft/setup-msbuild@v1.1 # to use msbuild
4757
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}
5160
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"
6166
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"
6372
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+
6586
mkdir -p output/${{ matrix.os }}/${{ matrix.arch }}
87+
ls -l bitsandbytes
88+
echo " check lib files..."
89+
file bitsandbytes/libbitsandbytes*.*
6690
( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ )
6791
- name: Upload build artifact
6892
uses: actions/upload-artifact@v4
6993
with:
7094
name: shared_library_${{ matrix.os }}_${{ matrix.arch }}
7195
path: output/*
72-
retention-days: 7
7396
##
7497
# This job matrix builds the CUDA versions of the libraries for platforms that support CUDA (Linux x64/aarch64 + Windows x64)
7598
##
7699
build-shared-libs-cuda:
77100
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+
78104
matrix:
79105
os: [ubuntu-latest, windows-latest]
80106
arch: [x86_64, aarch64]
81-
cuda_version: ['12.1.0']
107+
cuda-version: ['11.8.0', '12.1.1']
108+
build_type: [Release]
82109
exclude:
83110
- os: windows-latest # This probably requires arm64 Windows agents
84111
arch: aarch64
@@ -90,64 +117,106 @@ jobs:
90117
- name: Set up Docker multiarch
91118
if: startsWith(matrix.os, 'ubuntu')
92119
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'
99120
# Windows: We install Cuda on the agent (slow)
100121
- uses: Jimver/cuda-toolkit@v0.2.14
101122
if: startsWith(matrix.os, 'windows')
102123
id: cuda-toolkit
103124
with:
104-
cuda: ${{ matrix.cuda_version }}
125+
cuda: ${{ matrix.cuda-version }}
105126
method: 'network'
106127
sub-packages: '["nvcc","cudart","cusparse","cublas","thrust","nvrtc_dev","cublas_dev","cusparse_dev"]'
107128
linux-local-args: '["--toolkit"]'
108129
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+
109135
- name: Setup MSVC
110136
if: startsWith(matrix.os, 'windows')
111137
#uses: microsoft/setup-msbuild@v1.1 # to use msbuild
112138
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
115200
shell: bash
116201
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
135202
mkdir -p output/${{ matrix.os }}/${{ matrix.arch }}
203+
echo " check lib files..."
204+
file bitsandbytes/libbitsandbytes*.*
136205
( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ )
137206
- name: Upload build artifact
138207
uses: actions/upload-artifact@v4
139208
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 }}
141210
path: output/*
142-
retention-days: 7
211+
143212
build-wheels:
144213
needs:
145214
- build-shared-libs
146215
- build-shared-libs-cuda
147216
strategy:
148217
matrix:
149218
os: [ubuntu-latest, macos-latest, windows-latest]
150-
python-version: ["3.9", "3.10", "3.11", "3.12"]
219+
python-version: ["3.10"]
151220
arch: [x86_64, aarch64]
152221
exclude:
153222
- os: windows-latest # This probably requires arm64 Windows agents
@@ -187,16 +256,23 @@ jobs:
187256
# PYTHONPATH=. pytest --log-cli-level=DEBUG tests
188257
- name: Build wheel
189258
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
191267
- name: Upload build artifact
192268
uses: actions/upload-artifact@v4
193269
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
197272
publish:
198273
needs: build-wheels
199274
runs-on: ubuntu-latest
275+
if: startsWith(github.ref, 'refs/tags')
200276
steps:
201277
- uses: actions/checkout@v4
202278
- name: Download build artifact
@@ -208,7 +284,6 @@ jobs:
208284
- run: |
209285
ls -lR dist/
210286
- name: Publish to PyPi
211-
if: startsWith(github.ref, 'refs/tags')
212287
uses: pypa/gh-action-pypi-publish@release/v1
213288
with:
214289
password: ${{ secrets.pypi }}

environment-bnb.yml

-21
This file was deleted.

0 commit comments

Comments
 (0)