Skip to content

Commit 6fdd6ae

Browse files
committed
[CD] Move linux-aarch64 build scripts
And delete them from builder repo
1 parent 41e4d88 commit 6fdd6ae

File tree

7 files changed

+1454
-1
lines changed

7 files changed

+1454
-1
lines changed

.ci/aarch64_linux/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Aarch64 (ARM/Graviton) Support Scripts
2+
Scripts for building aarch64 PyTorch PIP Wheels. These scripts build the following wheels:
3+
* torch
4+
* torchvision
5+
* torchaudio
6+
* torchtext
7+
* torchdata
8+
## Aarch64_ci_build.sh
9+
This script is design to support CD operations within PyPi manylinux aarch64 container, and be executed in the container. It prepares the container and then executes __aarch64_wheel_ci_build.py__ to build the wheels. The script "assumes" the PyTorch repo is located at: ```/pytorch``` and will put the wheels into ```/artifacts```.
10+
### Usage
11+
```DESIRED_PYTHON=<PythonVersion> aarch64_ci_build.sh```
12+
13+
__NOTE:__ CI build is currently __EXPERMINTAL__
14+
15+
## Build_aarch64_wheel.py
16+
This app allows a person to build using AWS EC3 resources and requires AWS-CLI and Boto3 with AWS credentials to support building EC2 instances for the wheel builds. Can be used in a codebuild CD or from a local system.
17+
18+
### Usage
19+
```build_aarch64_wheel.py --key-name <YourPemKey> --use-docker --python 3.8 --branch <RCtag>```
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
set -eux -o pipefail
3+
4+
GPU_ARCH_VERSION=${GPU_ARCH_VERSION:-}
5+
6+
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
7+
source $SCRIPTPATH/aarch64_ci_setup.sh
8+
9+
tagged_version() {
10+
GIT_DESCRIBE="git --git-dir /pytorch/.git describe --tags --match v[0-9]*.[0-9]*.[0-9]*"
11+
if ${GIT_DESCRIBE} --exact >/dev/null; then
12+
${GIT_DESCRIBE}
13+
else
14+
return 1
15+
fi
16+
}
17+
18+
if tagged_version >/dev/null; then
19+
export OVERRIDE_PACKAGE_VERSION="$(tagged_version | sed -e 's/^v//' -e 's/-.*$//')"
20+
fi
21+
22+
###############################################################################
23+
# Run aarch64 builder python
24+
###############################################################################
25+
cd /
26+
# adding safe directory for git as the permissions will be
27+
# on the mounted pytorch repo
28+
git config --global --add safe.directory /pytorch
29+
pip install -r /pytorch/requirements.txt
30+
pip install auditwheel
31+
if [ "$DESIRED_CUDA" = "cpu" ]; then
32+
echo "BASE_CUDA_VERSION is not set. Building cpu wheel."
33+
#USE_PRIORITIZED_TEXT_FOR_LD for enable linker script optimization https://github.com/pytorch/pytorch/pull/121975/files
34+
USE_PRIORITIZED_TEXT_FOR_LD=1 python /builder/aarch64_linux/aarch64_wheel_ci_build.py --enable-mkldnn
35+
else
36+
echo "BASE_CUDA_VERSION is set to: $DESIRED_CUDA"
37+
#USE_PRIORITIZED_TEXT_FOR_LD for enable linker script optimization https://github.com/pytorch/pytorch/pull/121975/files
38+
USE_PRIORITIZED_TEXT_FOR_LD=1 python /builder/aarch64_linux/aarch64_wheel_ci_build.py --enable-mkldnn --enable-cuda
39+
fi
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
set -eux -o pipefail
3+
4+
# This script is used to prepare the Docker container for aarch64_ci_wheel_build.py python script
5+
# as we need to install conda and setup the python version for the build.
6+
7+
CONDA_PYTHON_EXE=/opt/conda/bin/python
8+
CONDA_EXE=/opt/conda/bin/conda
9+
CONDA_ENV_NAME=aarch64_env
10+
PATH=/opt/conda/bin:$PATH
11+
LD_LIBRARY_PATH=/opt/conda/envs/${CONDA_ENV_NAME}/lib/:/opt/conda/lib:$LD_LIBRARY_PATH
12+
13+
###############################################################################
14+
# Install conda
15+
# disable SSL_verify due to getting "Could not find a suitable TLS CA certificate bundle, invalid path"
16+
# when using Python version, less than the conda latest
17+
###############################################################################
18+
echo 'Installing conda-forge'
19+
curl -L -o /mambaforge.sh https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-aarch64.sh
20+
chmod +x /mambaforge.sh
21+
/mambaforge.sh -b -p /opt/conda
22+
rm /mambaforge.sh
23+
source /opt/conda/etc/profile.d/conda.sh
24+
conda config --set ssl_verify False
25+
conda create -y -c conda-forge -n "${CONDA_ENV_NAME}" python=${DESIRED_PYTHON}
26+
conda activate "${CONDA_ENV_NAME}"
27+
28+
if [[ "$DESIRED_PYTHON" == "3.13" ]]; then
29+
pip install -q --pre numpy==2.1.2
30+
conda install -y -c conda-forge pyyaml==6.0.2 patchelf==0.17.2 pygit2==1.15.1 ninja==1.11.1 scons==4.7.0
31+
else
32+
pip install -q --pre numpy==2.0.2
33+
conda install -y -c conda-forge pyyaml==6.0.1 patchelf==0.17.2 pygit2==1.13.2 ninja==1.11.1 scons==4.5.2
34+
fi
35+
36+
python --version
37+
conda --version
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
#!/usr/bin/env python3
2+
# encoding: UTF-8
3+
4+
import os
5+
import shutil
6+
from subprocess import check_call, check_output
7+
from typing import List
8+
9+
from pygit2 import Repository
10+
11+
12+
def list_dir(path: str) -> List[str]:
13+
"""'
14+
Helper for getting paths for Python
15+
"""
16+
return check_output(["ls", "-1", path]).decode().split("\n")
17+
18+
19+
def build_ArmComputeLibrary() -> None:
20+
"""
21+
Using ArmComputeLibrary for aarch64 PyTorch
22+
"""
23+
print("Building Arm Compute Library")
24+
acl_build_flags = [
25+
"debug=0",
26+
"neon=1",
27+
"opencl=0",
28+
"os=linux",
29+
"openmp=1",
30+
"cppthreads=0",
31+
"arch=armv8a",
32+
"multi_isa=1",
33+
"fixed_format_kernels=1",
34+
"build=native",
35+
]
36+
acl_install_dir = "/acl"
37+
acl_checkout_dir = "ComputeLibrary"
38+
os.makedirs(acl_install_dir)
39+
check_call(
40+
[
41+
"git",
42+
"clone",
43+
"https://github.com/ARM-software/ComputeLibrary.git",
44+
"-b",
45+
"v24.09",
46+
"--depth",
47+
"1",
48+
"--shallow-submodules",
49+
]
50+
)
51+
52+
check_call(
53+
["scons", "Werror=1", "-j8", f"build_dir=/{acl_install_dir}/build"]
54+
+ acl_build_flags,
55+
cwd=acl_checkout_dir,
56+
)
57+
for d in ["arm_compute", "include", "utils", "support", "src"]:
58+
shutil.copytree(f"{acl_checkout_dir}/{d}", f"{acl_install_dir}/{d}")
59+
60+
61+
def update_wheel(wheel_path) -> None:
62+
"""
63+
Update the cuda wheel libraries
64+
"""
65+
folder = os.path.dirname(wheel_path)
66+
wheelname = os.path.basename(wheel_path)
67+
os.mkdir(f"{folder}/tmp")
68+
os.system(f"unzip {wheel_path} -d {folder}/tmp")
69+
libs_to_copy = [
70+
"/usr/local/cuda/extras/CUPTI/lib64/libcupti.so.12",
71+
"/usr/local/cuda/lib64/libcudnn.so.9",
72+
"/usr/local/cuda/lib64/libcublas.so.12",
73+
"/usr/local/cuda/lib64/libcublasLt.so.12",
74+
"/usr/local/cuda/lib64/libcudart.so.12",
75+
"/usr/local/cuda/lib64/libcufft.so.11",
76+
"/usr/local/cuda/lib64/libcusparse.so.12",
77+
"/usr/local/cuda/lib64/libcusparseLt.so.0",
78+
"/usr/local/cuda/lib64/libcusolver.so.11",
79+
"/usr/local/cuda/lib64/libcurand.so.10",
80+
"/usr/local/cuda/lib64/libnvToolsExt.so.1",
81+
"/usr/local/cuda/lib64/libnvJitLink.so.12",
82+
"/usr/local/cuda/lib64/libnvrtc.so.12",
83+
"/usr/local/cuda/lib64/libnvrtc-builtins.so.12.4",
84+
"/usr/local/cuda/lib64/libcudnn_adv.so.9",
85+
"/usr/local/cuda/lib64/libcudnn_cnn.so.9",
86+
"/usr/local/cuda/lib64/libcudnn_graph.so.9",
87+
"/usr/local/cuda/lib64/libcudnn_ops.so.9",
88+
"/usr/local/cuda/lib64/libcudnn_engines_runtime_compiled.so.9",
89+
"/usr/local/cuda/lib64/libcudnn_engines_precompiled.so.9",
90+
"/usr/local/cuda/lib64/libcudnn_heuristic.so.9",
91+
"/opt/conda/envs/aarch64_env/lib/libgomp.so.1",
92+
"/usr/lib64/libgfortran.so.5",
93+
"/acl/build/libarm_compute.so",
94+
"/acl/build/libarm_compute_graph.so",
95+
]
96+
if enable_cuda:
97+
libs_to_copy += [
98+
"/usr/local/lib/libnvpl_lapack_lp64_gomp.so.0",
99+
"/usr/local/lib/libnvpl_blas_lp64_gomp.so.0",
100+
"/usr/local/lib/libnvpl_lapack_core.so.0",
101+
"/usr/local/lib/libnvpl_blas_core.so.0",
102+
]
103+
else:
104+
libs_to_copy += [
105+
"/opt/OpenBLAS/lib/libopenblas.so.0",
106+
]
107+
# Copy libraries to unzipped_folder/a/lib
108+
for lib_path in libs_to_copy:
109+
lib_name = os.path.basename(lib_path)
110+
shutil.copy2(lib_path, f"{folder}/tmp/torch/lib/{lib_name}")
111+
os.system(
112+
f"cd {folder}/tmp/torch/lib/; "
113+
f"patchelf --set-rpath '$ORIGIN' --force-rpath {folder}/tmp/torch/lib/{lib_name}"
114+
)
115+
os.mkdir(f"{folder}/cuda_wheel")
116+
os.system(f"cd {folder}/tmp/; zip -r {folder}/cuda_wheel/{wheelname} *")
117+
shutil.move(
118+
f"{folder}/cuda_wheel/{wheelname}",
119+
f"{folder}/{wheelname}",
120+
copy_function=shutil.copy2,
121+
)
122+
os.system(f"rm -rf {folder}/tmp/ {folder}/cuda_wheel/")
123+
124+
125+
def complete_wheel(folder: str) -> str:
126+
"""
127+
Complete wheel build and put in artifact location
128+
"""
129+
wheel_name = list_dir(f"/{folder}/dist")[0]
130+
131+
if "pytorch" in folder and not enable_cuda:
132+
print("Repairing Wheel with AuditWheel")
133+
check_call(["auditwheel", "repair", f"dist/{wheel_name}"], cwd=folder)
134+
repaired_wheel_name = list_dir(f"/{folder}/wheelhouse")[0]
135+
136+
print(f"Moving {repaired_wheel_name} wheel to /{folder}/dist")
137+
os.rename(
138+
f"/{folder}/wheelhouse/{repaired_wheel_name}",
139+
f"/{folder}/dist/{repaired_wheel_name}",
140+
)
141+
else:
142+
repaired_wheel_name = wheel_name
143+
144+
print(f"Copying {repaired_wheel_name} to artifacts")
145+
shutil.copy2(
146+
f"/{folder}/dist/{repaired_wheel_name}", f"/artifacts/{repaired_wheel_name}"
147+
)
148+
149+
return repaired_wheel_name
150+
151+
152+
def parse_arguments():
153+
"""
154+
Parse inline arguments
155+
"""
156+
from argparse import ArgumentParser
157+
158+
parser = ArgumentParser("AARCH64 wheels python CD")
159+
parser.add_argument("--debug", action="store_true")
160+
parser.add_argument("--build-only", action="store_true")
161+
parser.add_argument("--test-only", type=str)
162+
parser.add_argument("--enable-mkldnn", action="store_true")
163+
parser.add_argument("--enable-cuda", action="store_true")
164+
return parser.parse_args()
165+
166+
167+
if __name__ == "__main__":
168+
"""
169+
Entry Point
170+
"""
171+
args = parse_arguments()
172+
enable_mkldnn = args.enable_mkldnn
173+
enable_cuda = args.enable_cuda
174+
repo = Repository("/pytorch")
175+
branch = repo.head.name
176+
if branch == "HEAD":
177+
branch = "master"
178+
179+
print("Building PyTorch wheel")
180+
build_vars = "MAX_JOBS=5 CMAKE_SHARED_LINKER_FLAGS=-Wl,-z,max-page-size=0x10000 "
181+
os.system("cd /pytorch; python setup.py clean")
182+
183+
override_package_version = os.getenv("OVERRIDE_PACKAGE_VERSION")
184+
if override_package_version is not None:
185+
version = override_package_version
186+
build_vars += (
187+
f"BUILD_TEST=0 PYTORCH_BUILD_VERSION={version} PYTORCH_BUILD_NUMBER=1 "
188+
)
189+
elif branch in ["nightly", "master"]:
190+
build_date = (
191+
check_output(["git", "log", "--pretty=format:%cs", "-1"], cwd="/pytorch")
192+
.decode()
193+
.replace("-", "")
194+
)
195+
version = (
196+
check_output(["cat", "version.txt"], cwd="/pytorch").decode().strip()[:-2]
197+
)
198+
if enable_cuda:
199+
desired_cuda = os.getenv("DESIRED_CUDA")
200+
build_vars += f"BUILD_TEST=0 PYTORCH_BUILD_VERSION={version}.dev{build_date}+{desired_cuda} PYTORCH_BUILD_NUMBER=1 "
201+
else:
202+
build_vars += f"BUILD_TEST=0 PYTORCH_BUILD_VERSION={version}.dev{build_date} PYTORCH_BUILD_NUMBER=1 "
203+
elif branch.startswith(("v1.", "v2.")):
204+
build_vars += f"BUILD_TEST=0 PYTORCH_BUILD_VERSION={branch[1:branch.find('-')]} PYTORCH_BUILD_NUMBER=1 "
205+
206+
if enable_mkldnn:
207+
build_ArmComputeLibrary()
208+
print("build pytorch with mkldnn+acl backend")
209+
build_vars += (
210+
"USE_MKLDNN=ON USE_MKLDNN_ACL=ON "
211+
"ACL_ROOT_DIR=/acl "
212+
"LD_LIBRARY_PATH=/pytorch/build/lib:/acl/build:$LD_LIBRARY_PATH "
213+
"ACL_INCLUDE_DIR=/acl/build "
214+
"ACL_LIBRARY=/acl/build "
215+
)
216+
if enable_cuda:
217+
build_vars += "BLAS=NVPL "
218+
else:
219+
build_vars += "BLAS=OpenBLAS OpenBLAS_HOME=/OpenBLAS "
220+
else:
221+
print("build pytorch without mkldnn backend")
222+
223+
os.system(f"cd /pytorch; {build_vars} python3 setup.py bdist_wheel")
224+
if enable_cuda:
225+
print("Updating Cuda Dependency")
226+
filename = os.listdir("/pytorch/dist/")
227+
wheel_path = f"/pytorch/dist/{filename[0]}"
228+
update_wheel(wheel_path)
229+
pytorch_wheel_name = complete_wheel("/pytorch/")
230+
print(f"Build Complete. Created {pytorch_wheel_name}..")

0 commit comments

Comments
 (0)