Skip to content

Commit 5b0ff3a

Browse files
authored
feat(ci): add ARM64 CUDA wheel builds (#1798)
Signed-off-by: AlpinDale <alpindale@gmail.com>
1 parent eb7fa1a commit 5b0ff3a

18 files changed

Lines changed: 562 additions & 45 deletions

‎.github/actionlint.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
self-hosted-runner:
22
labels:
33
- aphrodite-wheel-builder
4+
- sonar-arm64-wheel-builder
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
set -euo pipefail
5+
6+
output_dir="${1:?usage: build_cuda_arm64_wheel.sh OUTPUT_DIR}"
7+
builder_name="${CUDA_ARM64_BUILDER_NAME:-sonar-cuda-arm64}"
8+
dockerfile="${CUDA_ARM64_BUILD_DOCKERFILE:-docker/Dockerfile}"
9+
version="${SONAR_VERSION_OVERRIDE:-}"
10+
if [[ -z "$version" ]]; then
11+
version="$(git describe --tags --exact-match)"
12+
version="${version#v}"
13+
fi
14+
15+
mkdir -p "$output_dir"
16+
rm -f "$output_dir"/sonar-*.whl
17+
18+
docker buildx build \
19+
--builder "$builder_name" \
20+
--platform linux/arm64 \
21+
--file "$dockerfile" \
22+
--target main-wheel-export \
23+
--output "type=local,dest=${output_dir}" \
24+
--build-arg "CUDA_VERSION=${CUDA_VERSION:-13.0.3}" \
25+
--build-arg "PYTHON_VERSION=${PYTHON_VERSION:-3.12}" \
26+
--build-arg "torch_cuda_arch_list=${TORCH_CUDA_ARCH_LIST:-8.0 8.6 8.9 9.0 10.0 11.0 12.0+PTX}" \
27+
--build-arg "max_jobs=${MAX_JOBS:-64}" \
28+
--build-arg "nvcc_threads=${NVCC_THREADS:-4}" \
29+
--build-arg python_abi_tag=cp311 \
30+
--build-arg "SONAR_VERSION_OVERRIDE=${version}" \
31+
.
32+
33+
shopt -s nullglob
34+
wheels=("$output_dir"/sonar-*-cp311-abi3-*aarch64.whl)
35+
if (( ${#wheels[@]} != 1 )); then
36+
echo "Expected exactly one CPython 3.11+ ARM64 CUDA wheel in ${output_dir}." >&2
37+
exit 1
38+
fi
39+
TMPDIR="${RUNNER_TEMP:-${TMPDIR:-/tmp}}" \
40+
uv run --isolated --no-project --with auditwheel==6.6.0 \
41+
python .github/scripts/detect_manylinux_tag.py "${wheels[0]}"

‎.github/scripts/build_pr_wheel.sh‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,21 @@ version="${major}.${minor}.$((patch + 1)).dev${timestamp}+${PLATFORM_VERSION_LOC
3232

3333
mkdir -p "$output_dir"
3434
find "$output_dir" -maxdepth 1 -type f -name '*.whl' -delete
35-
if [[ "$PLATFORM_BACKEND" == "cuda" ]]; then
35+
if [[ -n "${PLATFORM_BUILD_SCRIPT:-}" ]]; then
36+
SONAR_VERSION_OVERRIDE="$version" "$PLATFORM_BUILD_SCRIPT" "$output_dir"
37+
wheel="$(find "$output_dir" -maxdepth 1 -type f -name '*.whl' -print -quit)"
38+
elif [[ "$PLATFORM_BACKEND" == cuda && "$PLATFORM_ARCHITECTURE" == x86_64 ]]; then
3639
SONAR_VERSION_OVERRIDE="$version" ./docker/export_wheels.sh
3740
wheel="$(find wheels/main -maxdepth 1 -type f -name '*.whl' -print -quit)"
3841
else
39-
: "${PLATFORM_BUILD_SCRIPT:?PLATFORM_BUILD_SCRIPT is required for non-CUDA wheels}"
40-
SONAR_VERSION_OVERRIDE="$version" "$PLATFORM_BUILD_SCRIPT" "$output_dir"
41-
wheel="$(find "$output_dir" -maxdepth 1 -type f -name '*.whl' -print -quit)"
42+
echo "::error::PLATFORM_BUILD_SCRIPT is required for ${PLATFORM_BACKEND}/${PLATFORM_ARCHITECTURE}"
43+
exit 1
4244
fi
4345
if [[ -z "$wheel" ]]; then
4446
echo "::error::The PR build did not export a ${PLATFORM_BACKEND} wheel"
4547
exit 1
4648
fi
49+
python3 .github/scripts/verify_wheel_version.py "$wheel" "$version"
4750

4851
wheel_name="$(basename "$wheel")"
4952
if command -v sha256sum >/dev/null 2>&1; then
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
set -euo pipefail
5+
6+
control_host="${DOCKER_HOST:-tcp://127.0.0.1:23750}"
7+
host_control="${CUDA_ARM64_HOST_DOCKER_HOST:-unix:///var/run/docker.sock}"
8+
dind_container="${CUDA_ARM64_DIND_CONTAINER:-aphrodite-nightly-docker}"
9+
builder_name="${CUDA_ARM64_BUILDER_NAME:-sonar-cuda-arm64}"
10+
container_name="${CUDA_ARM64_BUILDKIT_CONTAINER:-sonar-cuda-arm64-buildkit}"
11+
builder_port="${CUDA_ARM64_BUILDKIT_PORT:-12352}"
12+
state_dir=/home/user/.local/share/buildkit
13+
# Includes BuildKit's userspace ARM64 emulator; no host binfmt registration.
14+
image=moby/buildkit@sha256:504731e577c20559c00f968f33219f30115e70be29ab96728d1d06e963fc494b
15+
16+
dind_address="$(docker --host "$host_control" inspect --format \
17+
'{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$dind_container")"
18+
test -n "$dind_address"
19+
endpoint="tcp://${dind_address}:${builder_port}"
20+
21+
if ! docker --host "$control_host" inspect "$container_name" >/dev/null 2>&1; then
22+
# Match native CUDA: 300 GiB of tmpfs, without CPU or memory cgroup caps.
23+
docker --host "$control_host" run --detach \
24+
--name "$container_name" \
25+
--security-opt seccomp=unconfined \
26+
--security-opt apparmor=unconfined \
27+
--publish "${builder_port}:1234" \
28+
--tmpfs "${state_dir}:rw,exec,size=300g,mode=1777" \
29+
"$image" \
30+
--oci-worker-no-process-sandbox \
31+
--oci-worker-platform linux/amd64 \
32+
--oci-worker-platform linux/arm64 \
33+
--oci-worker-gc=false \
34+
--addr tcp://0.0.0.0:1234
35+
elif [[ "$(docker --host "$control_host" inspect --format '{{.State.Running}}' "$container_name")" != true ]]; then
36+
docker --host "$control_host" start "$container_name" >/dev/null
37+
fi
38+
39+
configured_endpoint="$(docker buildx inspect "$builder_name" 2>/dev/null |
40+
sed -n 's/^Endpoint:[[:space:]]*//p' || true)"
41+
if [[ -n "$configured_endpoint" && "$configured_endpoint" != "$endpoint" ]]; then
42+
echo "Builder ${builder_name} already uses ${configured_endpoint}, expected ${endpoint}." >&2
43+
exit 1
44+
fi
45+
if [[ -z "$configured_endpoint" ]]; then
46+
docker buildx create --name "$builder_name" --driver remote "$endpoint"
47+
fi
48+
# Do not change the user's default builder: x86 and ROCm jobs share this host.
49+
for _ in $(seq 1 60); do
50+
if docker buildx inspect "$builder_name" --bootstrap >/dev/null 2>&1; then
51+
exit 0
52+
fi
53+
sleep 1
54+
done
55+
56+
docker --host "$control_host" logs --tail 100 "$container_name" >&2 || true
57+
echo "ARM64 CUDA BuildKit did not become ready at ${endpoint}." >&2
58+
exit 1

‎.github/scripts/preserve_wheel_indexes.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ preserve "simple/sonar"
3333
for channel in release nightly; do
3434
for platform in \
3535
cuda/x86_64 \
36+
cuda/aarch64 \
3637
cpu/x86_64 \
3738
cpu/aarch64 \
3839
rocm/x86_64 \

‎.github/scripts/reconcile_platform_wheels.sh‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ if [[ ! -x "$PLATFORM_BUILD_SCRIPT" ]]; then
2929
exit 1
3030
fi
3131

32+
# Keep publication tools from the triggering revision across historical checkouts.
33+
publication_tools="$(mktemp -d "${RUNNER_TEMP}/sonar-publication.XXXXXX")"
34+
trap 'rm -rf -- "$publication_tools"' EXIT
35+
for script in generate_nightly_index.py verify_wheel_version.py; do
36+
cp ".github/scripts/${script}" "${publication_tools}/${script}"
37+
done
38+
3239
encode_path() {
3340
printf '%s' "${1//+/%2B}"
3441
}
@@ -129,6 +136,7 @@ write_commit_index() {
129136
local entries
130137
local output
131138
local encoded_name
139+
local install_command
132140

133141
entries="$(mktemp "${RUNNER_TEMP}/sonar-platform-entries.XXXXXX")"
134142
output="$(mktemp "${RUNNER_TEMP}/sonar-platform-index.XXXXXX")"
@@ -144,13 +152,16 @@ write_commit_index() {
144152
"${public_root}/commits/${commit}/${encoded_name}" >"$entries"
145153
fi
146154

147-
python3 .github/scripts/generate_nightly_index.py \
155+
install_command="uv pip install sonar --extra-index-url ${public_root}/commits/${commit} --index-strategy first-index"
156+
if [[ "$PLATFORM_BACKEND" == cuda ]]; then
157+
install_command+=" --torch-backend cu130"
158+
fi
159+
python3 "${publication_tools}/generate_nightly_index.py" \
148160
--entry-file "$entries" \
149161
--commit "$commit" \
150162
--title "Sonar ${PLATFORM_BACKEND} wheel for ${commit:0:12}" \
151163
--description "Precompiled ${PLATFORM_BACKEND} wheel for ${PLATFORM_ARCHITECTURE} at commit ${commit}." \
152-
--install-command \
153-
"uv pip install sonar --extra-index-url ${public_root}/commits/${commit} --index-strategy first-index" \
164+
--install-command "$install_command" \
154165
--output "$output"
155166
"$rclone" copyto \
156167
"$output" \
@@ -234,6 +245,7 @@ for commit in ${commits[@]+"${commits[@]}"}; do
234245
echo "::error::The build did not export a wheel for ${commit}"
235246
exit 1
236247
fi
248+
python3 "${publication_tools}/verify_wheel_version.py" "$wheel" "$version"
237249

238250
wheel_name="$(basename "$wheel")"
239251
if command -v sha256sum >/dev/null 2>&1; then
@@ -292,10 +304,11 @@ package_dir="${index_dir}/simple/sonar"
292304
nightly_dir="${index_root}/nightly/${PLATFORM_BACKEND}/${PLATFORM_ARCHITECTURE}"
293305
mkdir -p "$package_dir" "$nightly_dir"
294306
install_command="uv pip install sonar --extra-index-url https://sonar.dphn.ai/whl/nightly/${PLATFORM_BACKEND}/${PLATFORM_ARCHITECTURE}/simple --index-strategy first-index"
295-
if [[ "$PLATFORM_BACKEND" == cpu ]]; then
296-
install_command="curl -LsSf https://sonar.dphn.ai/install.sh | sh -s -- --backend cpu --channel nightly"
297-
fi
298-
python3 .github/scripts/generate_nightly_index.py \
307+
case "$PLATFORM_BACKEND" in
308+
cuda) install_command+=" --torch-backend cu130" ;;
309+
cpu) install_command="curl -LsSf https://sonar.dphn.ai/install.sh | sh -s -- --backend cpu --channel nightly" ;;
310+
esac
311+
python3 "${publication_tools}/generate_nightly_index.py" \
299312
--entry-file "$entries" \
300313
--commit "$target_commit" \
301314
--title "Sonar nightly ${PLATFORM_BACKEND} wheels" \

‎.github/workflows/platform-wheel.yml‎

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ on:
2323
options:
2424
- all
2525
- cuda
26+
- cuda-arm64
2627
- rocm
2728
- cpu
2829
- metal
@@ -237,6 +238,88 @@ jobs:
237238
--filter type=regular \
238239
--max-used-space 25gb
239240
241+
cuda-arm64-wheel:
242+
name: CUDA nightly (aarch64)
243+
needs: authorize
244+
if: ${{ needs.authorize.outputs.build == 'true' && (inputs.platform == '' || inputs.platform == 'all' || inputs.platform == 'cuda' || inputs.platform == 'cuda-arm64') }}
245+
runs-on: [self-hosted, linux, x64, sonar-arm64-wheel-builder]
246+
timeout-minutes: 1440
247+
env:
248+
DOCKER_HOST: tcp://127.0.0.1:23750
249+
MAX_JOBS: "64"
250+
NVCC_THREADS: "4"
251+
CUDA_VERSION: "13.0.3"
252+
TORCH_CUDA_ARCH_LIST: "8.0 8.6 8.9 9.0 10.0 11.0 12.0+PTX"
253+
RCLONE_CONFIG_B2_TYPE: s3
254+
RCLONE_CONFIG_B2_PROVIDER: Other
255+
RCLONE_CONFIG_B2_ACCESS_KEY_ID: ${{ secrets.B2_S3_KEY_ID }}
256+
RCLONE_CONFIG_B2_SECRET_ACCESS_KEY: ${{ secrets.B2_S3_APPLICATION_KEY }}
257+
RCLONE_CONFIG_B2_REGION: ${{ vars.B2_S3_REGION }}
258+
RCLONE_CONFIG_B2_ENDPOINT: ${{ vars.B2_S3_ENDPOINT }}
259+
RCLONE_CONFIG_B2_NO_CHECK_BUCKET: "true"
260+
B2_S3_BUCKET: ${{ vars.B2_S3_BUCKET }}
261+
B2_PUBLIC_BASE_URL: ${{ vars.B2_PUBLIC_BASE_URL }}
262+
PR_WHEEL_NUMBER: ${{ needs.authorize.outputs.pr_number }}
263+
TARGET_COMMIT: ${{ needs.authorize.outputs.target_sha }}
264+
PLATFORM_BACKEND: cuda
265+
PLATFORM_ARCHITECTURE: aarch64
266+
PLATFORM_VERSION_LOCAL: cu130
267+
steps:
268+
- name: Check out target revision
269+
uses: actions/checkout@v4
270+
with:
271+
ref: ${{ needs.authorize.outputs.target_sha }}
272+
fetch-depth: 0
273+
274+
- name: Install uv
275+
uses: astral-sh/setup-uv@v7
276+
277+
- name: Start isolated ARM64 CUDA builder
278+
run: .github/scripts/ensure_cuda_arm64_builder.sh
279+
280+
- name: Install rclone
281+
run: ./.github/scripts/install-rclone.sh "$RUNNER_TEMP/rclone-bin"
282+
283+
- name: Pin ARM64 CUDA build driver
284+
run: |
285+
install -m 0755 \
286+
.github/scripts/build_cuda_arm64_wheel.sh \
287+
"$RUNNER_TEMP/build_cuda_arm64_wheel.sh"
288+
install -m 0644 \
289+
docker/Dockerfile \
290+
"$RUNNER_TEMP/Dockerfile.cuda-arm64"
291+
292+
- name: Build and publish missing ARM64 CUDA wheels
293+
if: ${{ needs.authorize.outputs.temporary != 'true' }}
294+
env:
295+
PUSH_BEFORE: ${{ github.event.before }}
296+
PLATFORM_BUILD_SCRIPT: ${{ runner.temp }}/build_cuda_arm64_wheel.sh
297+
CUDA_ARM64_BUILD_DOCKERFILE: ${{ runner.temp }}/Dockerfile.cuda-arm64
298+
run: |
299+
.github/scripts/reconcile_platform_wheels.sh \
300+
dist/cuda-aarch64 page-index
301+
302+
- name: Build and publish PR ARM64 CUDA wheel
303+
if: ${{ needs.authorize.outputs.temporary == 'true' }}
304+
env:
305+
PLATFORM_BUILD_SCRIPT: ${{ runner.temp }}/build_cuda_arm64_wheel.sh
306+
CUDA_ARM64_BUILD_DOCKERFILE: ${{ runner.temp }}/Dockerfile.cuda-arm64
307+
run: .github/scripts/build_pr_wheel.sh dist/cuda-aarch64 page-index
308+
309+
- name: Upload ARM64 CUDA index
310+
uses: actions/upload-artifact@v4
311+
with:
312+
name: platform-index-cuda-aarch64
313+
path: page-index
314+
if-no-files-found: error
315+
retention-days: 1
316+
317+
- name: Limit ARM64 CUDA build cache
318+
if: ${{ always() }}
319+
run: |
320+
docker buildx prune --builder sonar-cuda-arm64 --force \
321+
--filter type=regular --max-used-space 25gb
322+
240323
cpu-wheel:
241324
name: CPU nightly (${{ matrix.architecture }})
242325
needs: authorize
@@ -528,7 +611,7 @@ jobs:
528611
529612
build-pages:
530613
name: Build documentation with nightly indexes
531-
needs: [authorize, cuda-wheel, cpu-wheel, metal-wheel, rocm-wheel]
614+
needs: [authorize, cuda-wheel, cuda-arm64-wheel, cpu-wheel, metal-wheel, rocm-wheel]
532615
if: ${{ always() && !cancelled() && needs.authorize.outputs.temporary != 'true' }}
533616
runs-on: ubuntu-24.04
534617
steps:

0 commit comments

Comments
 (0)