Skip to content

Commit ffb533d

Browse files
author
Mike Schneider
authored
Update aarch64 Scripts for CI worflow (#1431)
1 parent fe3dd0e commit ffb533d

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

aarch64_linux/aarch64_ci_build.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ PATH=/opt/conda/bin:$PATH
1212
# Install OS dependent packages
1313
###############################################################################
1414
yum -y install epel-release
15-
yum -y install less zstd
15+
yum -y install less zstd git
1616

1717
###############################################################################
1818
# Install conda
@@ -25,7 +25,7 @@ chmod +x /mambaforge.sh
2525
/mambaforge.sh -b -p /opt/conda
2626
rm /mambaforge.sh
2727
/opt/conda/bin/conda config --set ssl_verify False
28-
/opt/conda/bin/conda install -y -c conda-forge python=${DESIRED_PYTHON} numpy pyyaml setuptools patchelf
28+
/opt/conda/bin/conda install -y -c conda-forge python=${DESIRED_PYTHON} numpy pyyaml setuptools patchelf pygit2
2929
python --version
3030
conda --version
3131

@@ -37,16 +37,18 @@ conda --version
3737
# ubuntu's libgfortran.a which is compiled with -fPIC
3838
###############################################################################
3939
cd ~/
40-
curl -L -o ~/libgfortran-10-dev.deb http://ports.ubuntu.com/ubuntu-ports/pool/universe/g/gcc-10/libgfortran-10-dev_10.4.0-6ubuntu1_arm64.deb
41-
ar x ~/libgfortran-10-dev.deb
40+
curl -L -o ~/libgfortran-10-dev.deb http://ports.ubuntu.com/ubuntu-ports/pool/universe/g/gcc-10/libgfortran-10-dev_10.4.0-8ubuntu1_arm64.deb
41+
ar -x libgfortran-10-dev.deb
4242
tar --use-compress-program=unzstd -xvf data.tar.zst -C ~/
4343
cp -f ~/usr/lib/gcc/aarch64-linux-gnu/10/libgfortran.a /opt/rh/devtoolset-10/root/usr/lib/gcc/aarch64-redhat-linux/10/
4444

4545
###############################################################################
4646
# Run aarch64 builder python
4747
###############################################################################
48-
cd /
48+
cd /pytorch
4949
# adding safe directory for git as the permissions will be
5050
# on the mounted pytorch repo
5151
git config --global --add safe.directory /pytorch
52-
python /builder/aarch64_linux/aarch64_wheel_ci_build.py --enable-mkldnn
52+
pip install -r /pytorch/requirements.txt
53+
pip install auditwheel
54+
python /builder/aarch64_linux/aarch64_wheel_ci_build.py --enable-mkldnn

aarch64_linux/aarch64_wheel_ci_build.py

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import subprocess
5+
from pygit2 import Repository
56
from typing import Dict, List, Optional, Tuple
67

78

@@ -15,18 +16,20 @@ def list_dir(path: str) -> List[str]:
1516
'''
1617
Helper to get repo branches for specific versions
1718
'''
18-
def checkout_repo(branch: str = "main",
19-
url: str = "",
20-
git_clone_flags: str = "",
21-
mapping: Dict[str, Tuple[str, str]] = []) -> Optional[str]:
19+
def checkout_repo(
20+
package: str,
21+
branch: str = "main",
22+
url: str = "",
23+
git_clone_flags: str = "",
24+
mapping: Dict[str, Tuple[str, str]] = []) -> Optional[str]:
2225
for prefix in mapping:
2326
if not branch.startswith(prefix):
2427
continue
2528
tag = f"v{mapping[prefix][0]}-{mapping[prefix][1]}"
26-
os.system(f"git clone {url} -b {tag} {git_clone_flags}")
29+
os.system(f"git clone {url} /{package} -b {tag} {git_clone_flags}")
2730
return mapping[prefix][0]
2831

29-
os.system(f"git clone {url} {git_clone_flags}")
32+
os.system(f"git clone {url} /{package} {git_clone_flags}")
3033
return None
3134

3235

@@ -70,7 +73,8 @@ def embed_libgomp(wheel_name) -> None:
7073
def build_torchvision(branch: str = "main",
7174
git_clone_flags: str = "") -> str:
7275
print('Checking out TorchVision repo')
73-
build_version = checkout_repo(branch=branch,
76+
build_version = checkout_repo(package="vision",
77+
branch=branch,
7478
url="https://github.com/pytorch/vision",
7579
git_clone_flags=git_clone_flags,
7680
mapping={
@@ -118,7 +122,8 @@ def build_torchaudio(branch: str = "main",
118122
git_clone_flags: str = "") -> str:
119123
print('Checking out TorchAudio repo')
120124
git_clone_flags += " --recurse-submodules"
121-
build_version = checkout_repo(branch=branch,
125+
build_version = checkout_repo(package="audio",
126+
branch=branch,
122127
url="https://github.com/pytorch/audio",
123128
git_clone_flags=git_clone_flags,
124129
mapping={
@@ -161,7 +166,8 @@ def build_torchtext(branch: str = "main",
161166
print('Checking out TorchText repo')
162167
os.system(f"cd /")
163168
git_clone_flags += " --recurse-submodules"
164-
build_version = checkout_repo(branch=branch,
169+
build_version = checkout_repo(package="text",
170+
branch=branch,
165171
url="https://github.com/pytorch/text",
166172
git_clone_flags=git_clone_flags,
167173
mapping={
@@ -187,7 +193,7 @@ def build_torchtext(branch: str = "main",
187193
elif build_version is not None:
188194
build_vars += f"BUILD_VERSION={build_version}"
189195

190-
os.system(f"cd text; {build_vars} python3 setup.py bdist_wheel")
196+
os.system(f"cd /text; {build_vars} python3 setup.py bdist_wheel")
191197
wheel_name = list_dir("/text/dist")[0]
192198
embed_libgomp(f"/text/dist/{wheel_name}")
193199

@@ -203,7 +209,8 @@ def build_torchdata(branch: str = "main",
203209
git_clone_flags: str = "") -> str:
204210
print('Checking out TorchData repo')
205211
git_clone_flags += " --recurse-submodules"
206-
build_version = checkout_repo(branch=branch,
212+
build_version = checkout_repo(package="data",
213+
branch=branch,
207214
url="https://github.com/pytorch/data",
208215
git_clone_flags=git_clone_flags,
209216
mapping={
@@ -250,8 +257,10 @@ def parse_arguments():
250257

251258
args = parse_arguments()
252259
enable_mkldnn = args.enable_mkldnn
253-
os.system("cd /pytorch")
254-
branch = subprocess.check_output("git rev-parse --abbrev-ref HEAD")
260+
repo = Repository('/pytorch')
261+
branch = repo.head.name
262+
if branch == 'HEAD':
263+
branch = 'master'
255264

256265
git_clone_flags = " --depth 1 --shallow-submodules"
257266
os.system(f"conda install -y ninja scons")
@@ -261,31 +270,35 @@ def parse_arguments():
261270

262271
print('Building PyTorch wheel')
263272
build_vars = "CMAKE_SHARED_LINKER_FLAGS=-Wl,-z,max-page-size=0x10000 "
264-
os.system(f"cd /pytorch; pip install -r requirements.txt")
265-
os.system(f"pip install auditwheel")
266273
os.system(f"python setup.py clean")
267274

268275
if branch == 'nightly' or branch == 'master':
269276
build_date = subprocess.check_output(['git','log','--pretty=format:%cs','-1'], cwd='/pytorch').decode().replace('-','')
270277
version = subprocess.check_output(['cat','version.txt'], cwd='/pytorch').decode().strip()[:-2]
271-
build_vars += f"BUILD_TEST=0 PYTORCH_BUILD_VERSION={version}.dev{build_date} PYTORCH_BUILD_NUMBER=1"
278+
build_vars += f"BUILD_TEST=0 PYTORCH_BUILD_VERSION={version}.dev{build_date} PYTORCH_BUILD_NUMBER=1 "
272279
if branch.startswith("v1.") or branch.startswith("v2."):
273-
build_vars += f"BUILD_TEST=0 PYTORCH_BUILD_VERSION={branch[1:branch.find('-')]} PYTORCH_BUILD_NUMBER=1"
280+
build_vars += f"BUILD_TEST=0 PYTORCH_BUILD_VERSION={branch[1:branch.find('-')]} PYTORCH_BUILD_NUMBER=1 "
274281
if enable_mkldnn:
275282
build_ArmComputeLibrary(git_clone_flags)
276283
print("build pytorch with mkldnn+acl backend")
277-
os.system(f"export ACL_ROOT_DIR=/acl; export LD_LIBRARY_PATH=/acl/build; export ACL_LIBRARY=/acl/build")
278-
build_vars += " USE_MKLDNN=ON USE_MKLDNN_ACL=ON"
284+
build_vars += "USE_MKLDNN=ON USE_MKLDNN_ACL=ON " \
285+
"ACL_ROOT_DIR=/acl " \
286+
"LD_LIBRARY_PATH=/pytorch/build/lib:/acl/build " \
287+
"ACL_INCLUDE_DIR=/acl/build " \
288+
"ACL_LIBRARY=/acl/build "
279289
os.system(f"cd /pytorch; {build_vars} python3 setup.py bdist_wheel")
290+
291+
## Using AuditWheel on the pip package.
280292
print('Repair the wheel')
281-
pytorch_wheel_name = list_dir("pytorch/dist")[0]
282-
os.system(f"export LD_LIBRARY_PATH=/pytorch/build/lib:$LD_LIBRARY_PATH; auditwheel repair /pytorch/dist/{pytorch_wheel_name}")
293+
pytorch_wheel_name = list_dir("/pytorch/dist")[0]
294+
os.system(f"LD_LIBRARY_PATH=/pytorch/build/lib:/acl/build auditwheel repair /pytorch/dist/{pytorch_wheel_name}")
283295
print('replace the original wheel with the repaired one')
284296
pytorch_repaired_wheel_name = list_dir("wheelhouse")[0]
285297
os.system(f"cp /wheelhouse/{pytorch_repaired_wheel_name} /pytorch/dist/{pytorch_wheel_name}")
286298
else:
287299
print("build pytorch without mkldnn backend")
288-
os.system(f"cd pytorch ; {build_vars} python3 setup.py bdist_wheel")
300+
build_vars += "LD_LIBRARY_PATH=/pytorch/build/lib "
301+
os.system(f"cd /pytorch; {build_vars} python3 setup.py bdist_wheel")
289302

290303
print("Deleting build folder")
291304
os.system("cd /pytorch; rm -rf build")

0 commit comments

Comments
 (0)