Skip to content

Commit 62485a3

Browse files
akxTitus-von-Koeller
authored andcommitted
Move build scripts to .github/scripts (from scripts/ and workflow YAML)
1 parent 958dfa9 commit 62485a3

File tree

4 files changed

+64
-78
lines changed

4 files changed

+64
-78
lines changed

.github/scripts/build-cpu.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
declare build_arch
3+
declare build_os
4+
5+
set -xeuo pipefail
6+
7+
pip install cmake==3.28.3
8+
9+
if [ "${build_os:0:6}" == ubuntu ] && [ "${build_arch}" == aarch64 ]; then
10+
# Allow cross-compile on aarch64
11+
sudo apt-get update
12+
sudo apt-get install -y gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu g++-aarch64-linux-gnu
13+
cmake -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCOMPUTE_BACKEND=cpu .
14+
elif [ "${build_os:0:5}" == macos ] && [ "${build_arch}" == aarch64 ]; then
15+
cmake -DCMAKE_OSX_ARCHITECTURES=arm64 -DCOMPUTE_BACKEND=cpu .
16+
else
17+
cmake -DCOMPUTE_BACKEND=cpu .
18+
fi
19+
cmake --build . --config Release
20+
21+
output_dir="output/${build_os}/${build_arch}"
22+
mkdir -p "${output_dir}"
23+
(shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} "${output_dir}")

.github/scripts/build-cuda.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
declare build_arch
3+
declare build_os
4+
declare cuda_version
5+
6+
set -xeuo pipefail
7+
build_capability="50;52;60;61;70;75;80;86;89;90"
8+
[[ "${cuda_version}" == 11.7.* ]] && build_capability=${build_capability%??????}
9+
[[ "${cuda_version}" == 11.8.* ]] && build_capability=${build_capability%???}
10+
[[ "${build_os}" = windows-* ]] && python3 -m pip install ninja
11+
for NO_CUBLASLT in ON OFF; do
12+
if [ "${build_os:0:6}" == ubuntu ]; then
13+
image=nvidia/cuda:${cuda_version}-devel-ubuntu22.04
14+
echo "Using image $image"
15+
docker run --platform "linux/$build_arch" -i -w /src -v "$PWD:/src" "$image" sh -c \
16+
"apt-get update \
17+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends cmake \
18+
&& cmake -DCOMPUTE_BACKEND=cuda -DCOMPUTE_CAPABILITY=\"${build_capability}\" -DNO_CUBLASLT=${NO_CUBLASLT} . \
19+
&& cmake --build ."
20+
else
21+
pip install cmake==3.28.3
22+
cmake -G Ninja -DCOMPUTE_BACKEND=cuda -DCOMPUTE_CAPABILITY="${build_capability}" -DNO_CUBLASLT=${NO_CUBLASLT} -DCMAKE_BUILD_TYPE=Release -S .
23+
cmake --build . --config Release
24+
fi
25+
done
26+
27+
output_dir="output/${build_os}/${build_arch}"
28+
mkdir -p "${output_dir}"
29+
(shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} "${output_dir}")
File renamed without changes.

.github/workflows/python-package.yml

Lines changed: 12 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,15 @@ jobs:
3737
arch: aarch64
3838
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
3939
steps:
40-
# Check out code
4140
- uses: actions/checkout@v4
42-
# On Linux we use CMake within Docker
43-
- name: Setup cmake
44-
uses: jwlawson/actions-setup-cmake@v1.14
45-
with:
46-
cmake-version: "3.26.x"
4741
- name: Setup MSVC
4842
if: startsWith(matrix.os, 'windows')
49-
#uses: microsoft/setup-msbuild@v1.1 # to use msbuild
5043
uses: ilammy/msvc-dev-cmd@v1.13.0 # to use cl
51-
# Compile C++ code
5244
- name: Build C++
53-
shell: bash
54-
run: |
55-
set -ex
56-
build_os=${{ matrix.os }}
57-
build_arch=${{ matrix.arch }}
58-
if [ ${build_os:0:6} == ubuntu -a ${build_arch} == aarch64 ]; then
59-
# Allow cross-compile on aarch64
60-
sudo apt-get update
61-
sudo apt-get install -y gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu g++-aarch64-linux-gnu
62-
cmake -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCOMPUTE_BACKEND=cpu .
63-
elif [ ${build_os:0:5} == macos -a ${build_arch} == aarch64 ]; then
64-
cmake -DCMAKE_OSX_ARCHITECTURES=arm64 -DCOMPUTE_BACKEND=cpu .
65-
else
66-
cmake -DCOMPUTE_BACKEND=cpu .
67-
fi
68-
cmake --build . --config Release
69-
mkdir -p output/${{ matrix.os }}/${{ matrix.arch }}
70-
( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ )
45+
run: bash .github/scripts/build-cpu.sh
46+
env:
47+
build_os: ${{ matrix.os }}
48+
build_arch: ${{ matrix.arch }}
7149
- name: Upload build artifact
7250
uses: actions/upload-artifact@v4
7351
with:
@@ -91,18 +69,11 @@ jobs:
9169
arch: aarch64
9270
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
9371
steps:
94-
# Check out code
9572
- uses: actions/checkout@v4
9673
# Linux: We use Docker to build cross platform Cuda (aarch64 is built in emulation)
9774
- name: Set up Docker multiarch
9875
if: startsWith(matrix.os, 'ubuntu')
9976
uses: docker/setup-qemu-action@v2
100-
# On Linux we use CMake within Docker
101-
- name: Setup cmake
102-
if: ${{ !startsWith(matrix.os, 'linux') }}
103-
uses: jwlawson/actions-setup-cmake@v1.14
104-
with:
105-
cmake-version: "3.26.x"
10677
# Windows: We install Cuda on the agent (slow)
10778
- uses: Jimver/cuda-toolkit@v0.2.14
10879
if: startsWith(matrix.os, 'windows')
@@ -115,35 +86,13 @@ jobs:
11586
use-github-cache: false
11687
- name: Setup MSVC
11788
if: startsWith(matrix.os, 'windows')
118-
#uses: microsoft/setup-msbuild@v1.1 # to use msbuild
11989
uses: ilammy/msvc-dev-cmd@v1.13.0 # to use cl
120-
# Compile C++ code
12190
- name: Build C++
122-
shell: bash
123-
run: |
124-
set -ex
125-
build_os=${{ matrix.os }}
126-
build_arch=${{ matrix.arch }}
127-
build_capability="50;52;60;61;70;75;80;86;89;90"
128-
[[ "${{ matrix.cuda_version }}" == 11.7.* ]] && build_capability=${build_capability%??????}
129-
[[ "${{ matrix.cuda_version }}" == 11.8.* ]] && build_capability=${build_capability%???}
130-
[[ "${{ matrix.os }}" = windows-* ]] && python3 -m pip install ninja
131-
for NO_CUBLASLT in ON OFF; do
132-
if [ ${build_os:0:6} == ubuntu ]; then
133-
image=nvidia/cuda:${{ matrix.cuda_version }}-devel-ubuntu22.04
134-
echo "Using image $image"
135-
docker run --platform linux/$build_arch -i -w /src -v $PWD:/src $image sh -c \
136-
"apt-get update \
137-
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends cmake \
138-
&& cmake -DCOMPUTE_BACKEND=cuda -DCOMPUTE_CAPABILITY=\"${build_capability}\" -DNO_CUBLASLT=${NO_CUBLASLT} . \
139-
&& cmake --build ."
140-
else
141-
cmake -G Ninja -DCOMPUTE_BACKEND=cuda -DCOMPUTE_CAPABILITY="${build_capability}" -DNO_CUBLASLT=${NO_CUBLASLT} -DCMAKE_BUILD_TYPE=Release -S .
142-
cmake --build . --config Release
143-
fi
144-
done
145-
mkdir -p output/${{ matrix.os }}/${{ matrix.arch }}
146-
( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ )
91+
run: bash .github/scripts/build-cuda.sh
92+
env:
93+
build_os: ${{ matrix.os }}
94+
build_arch: ${{ matrix.arch }}
95+
cuda_version: ${{ matrix.cuda_version }}
14796
- name: Upload build artifact
14897
uses: actions/upload-artifact@v4
14998
with:
@@ -167,9 +116,7 @@ jobs:
167116
arch: aarch64
168117
runs-on: ${{ matrix.os }}
169118
steps:
170-
# Check out code
171119
- uses: actions/checkout@v4
172-
# Download shared libraries
173120
- name: Download build artifact
174121
uses: actions/download-artifact@v4
175122
with:
@@ -181,30 +128,17 @@ jobs:
181128
run: |
182129
ls -lR output/
183130
cp output/${{ matrix.os }}/${{ matrix.arch }}/* bitsandbytes/
184-
# Set up the Python version needed
185131
- name: Set up Python ${{ matrix.python-version }}
186132
uses: actions/setup-python@v5
187133
with:
188134
python-version: ${{ matrix.python-version }}
189135
cache: pip
190-
- name: Install build package
191-
shell: bash
192-
run: pip install build
193-
- name: Install Python test dependencies
194-
shell: bash
195-
run: pip install -r requirements-ci.txt
196-
# TODO: How to run CUDA tests on GitHub actions?
197-
#- name: Run unit tests
198-
# if: ${{ matrix.arch == 'x86_64' }} # Tests are too slow to run in emulation. Wait for real aarch64 agents
199-
# run: |
200-
# PYTHONPATH=. pytest --log-cli-level=DEBUG tests
201-
- name: Build wheel
202-
shell: bash
203-
run: python -m build .
136+
- run: pip install build wheel
137+
- run: python -m build .
204138
- name: Determine and Set Platform Tag, then Tag Wheel
205139
shell: bash
206140
run: |
207-
PLATFORM_TAG=$(python scripts/set_platform_tag.py ${{ matrix.arch }})
141+
PLATFORM_TAG=$(python .github/scripts/set_platform_tag.py "${{ matrix.arch }}")
208142
echo "PLATFORM_TAG=$PLATFORM_TAG"
209143
wheel tags --remove --abi-tag=none --python-tag=py3 --platform-tag=$PLATFORM_TAG dist/bitsandbytes-*.whl
210144
- name: Upload build artifact

0 commit comments

Comments
 (0)