Skip to content

Commit 85075c1

Browse files
committed
[BE] Error handling in build_aarch64_wheel
I've noticed that build errors in `build_ArmComputeLibrary` would be ignored as semicolon is used between the commands, instead of && Also, replace nightly version evaluation by relying on torch, to rely on individual libraries
1 parent 890842c commit 85075c1

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

aarch64_linux/build_aarch64_wheel.py

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def run_cmd(self, args: Union[str, List[str]]) -> None:
128128
assert self.container_id is not None
129129
docker_cmd = self._gen_ssh_prefix() + ['docker', 'exec', '-i', self.container_id, 'bash']
130130
p = subprocess.Popen(docker_cmd, stdin=subprocess.PIPE)
131-
p.communicate(input=" ".join(["source .bashrc;"] + self._split_cmd(args)).encode("utf-8"))
131+
p.communicate(input=" ".join(["source .bashrc && "] + self._split_cmd(args)).encode("utf-8"))
132132
rc = p.wait()
133133
if rc != 0:
134134
raise subprocess.CalledProcessError(rc, docker_cmd)
@@ -139,7 +139,7 @@ def check_output(self, args: Union[str, List[str]]) -> str:
139139
assert self.container_id is not None
140140
docker_cmd = self._gen_ssh_prefix() + ['docker', 'exec', '-i', self.container_id, 'bash']
141141
p = subprocess.Popen(docker_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
142-
(out, err) = p.communicate(input=" ".join(["source .bashrc;"] + self._split_cmd(args)).encode("utf-8"))
142+
(out, err) = p.communicate(input=" ".join(["source .bashrc && "] + self._split_cmd(args)).encode("utf-8"))
143143
rc = p.wait()
144144
if rc != 0:
145145
raise subprocess.CalledProcessError(rc, docker_cmd, output=out, stderr=err)
@@ -225,23 +225,16 @@ def build_OpenBLAS(host: RemoteHost, git_clone_flags: str = "") -> None:
225225
print('Building OpenBLAS')
226226
host.run_cmd(f"git clone https://github.com/xianyi/OpenBLAS -b v0.3.19 {git_clone_flags}")
227227
make_flags = "NUM_THREADS=64 USE_OPENMP=1 NO_SHARED=1 DYNAMIC_ARCH=1 TARGET=ARMV8"
228-
host.run_cmd(f"pushd OpenBLAS; make {make_flags} -j8; sudo make {make_flags} install; popd; rm -rf OpenBLAS")
228+
host.run_cmd(f"pushd OpenBLAS && make {make_flags} -j8 && sudo make {make_flags} install && popd && rm -rf OpenBLAS")
229229

230230

231231
def build_ArmComputeLibrary(host: RemoteHost, git_clone_flags: str = "") -> None:
232232
print('Building Arm Compute Library')
233-
host.run_cmd("mkdir $HOME/acl")
233+
acl_install_dir="${HOME}/acl"
234+
acl_build_flags="debug=0 neon=1 opencl=0 os=linux openmp=1 cppthreads=0 arch=armv8.2-a multi_isa=1 build=native"
235+
host.run_cmd(f"mkdir {acl_install_dir}")
234236
host.run_cmd(f"git clone https://github.com/ARM-software/ComputeLibrary.git -b v22.11 {git_clone_flags}")
235-
host.run_cmd("pushd ComputeLibrary; export acl_install_dir=$HOME/acl; scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=linux openmp=1 cppthreads=0 arch=armv8.2-a multi_isa=1 build=native build_dir=$acl_install_dir/build; cp -r arm_compute $acl_install_dir; cp -r include $acl_install_dir; cp -r utils $acl_install_dir; cp -r support $acl_install_dir; popd")
236-
237-
238-
def build_FFTW(host: RemoteHost, git_clone_flags: str = "") -> None:
239-
print("Building FFTW3")
240-
host.run_cmd("sudo apt-get install -y ocaml ocamlbuild autoconf automake indent libtool fig2dev texinfo")
241-
# TODO: fix a version to build
242-
# TODO: consider adding flags --host=arm-linux-gnueabi --enable-single --enable-neon CC=arm-linux-gnueabi-gcc -march=armv7-a -mfloat-abi=softfp
243-
host.run_cmd(f"git clone https://github.com/FFTW/fftw3 {git_clone_flags}")
244-
host.run_cmd("pushd fftw3; sh bootstrap.sh; make -j8; sudo make install; popd")
237+
host.run_cmd(f"cd ComputeLibrary && scons Werror=1 -j8 {acl_build_flags} build_dir={acl_install_dir}/build")
245238

246239

247240
def embed_libgomp(host: RemoteHost, use_conda, wheel_name) -> None:
@@ -261,7 +254,7 @@ def embed_libgomp(host: RemoteHost, use_conda, wheel_name) -> None:
261254

262255

263256
def checkout_repo(host: RemoteHost, *,
264-
branch: str = "master",
257+
branch: str = "main",
265258
url: str,
266259
git_clone_flags: str,
267260
mapping: Dict[str, Tuple[str, str]]) -> Optional[str]:
@@ -272,12 +265,16 @@ def checkout_repo(host: RemoteHost, *,
272265
host.run_cmd(f"git clone {url} -b {tag} {git_clone_flags}")
273266
return mapping[prefix][0]
274267

275-
host.run_cmd(f"git clone {url} {git_clone_flags}")
268+
# Map master to main
269+
if branch == "master" and url.rsplit("/")[-1] in ['vision', 'text', 'audio', 'data']:
270+
branch = "main"
271+
272+
host.run_cmd(f"git clone {url} -b {branch} {git_clone_flags}")
276273
return None
277274

278275

279276
def build_torchvision(host: RemoteHost, *,
280-
branch: str = "master",
277+
branch: str = "main",
281278
use_conda: bool = True,
282279
git_clone_flags: str,
283280
run_smoke_tests: bool = True) -> str:
@@ -317,14 +314,14 @@ def build_torchvision(host: RemoteHost, *,
317314
if len(version) == 0:
318315
# In older revisions, version was embedded in setup.py
319316
version = host.check_output(["grep", "\"version = '\"", "vision/setup.py"]).strip().split("'")[1][:-2]
320-
build_date = host.check_output("cd pytorch ; git log --pretty=format:%s -1").strip().split()[0].replace("-", "")
317+
build_date = host.check_output("cd vision && git log --pretty=format:%s -1").strip().split()[0].replace("-", "")
321318
build_vars += f"BUILD_VERSION={version}.dev{build_date}"
322319
elif build_version is not None:
323320
build_vars += f"BUILD_VERSION={build_version} PYTORCH_VERSION={branch[1:].split('-')[0]}"
324321
if host.using_docker():
325322
build_vars += " CMAKE_SHARED_LINKER_FLAGS=-Wl,-z,max-page-size=0x10000"
326323

327-
host.run_cmd(f"cd vision; {build_vars} python3 setup.py bdist_wheel")
324+
host.run_cmd(f"cd vision && {build_vars} python3 setup.py bdist_wheel")
328325
vision_wheel_name = host.list_dir("vision/dist")[0]
329326
embed_libgomp(host, use_conda, os.path.join('vision', 'dist', vision_wheel_name))
330327

@@ -357,14 +354,14 @@ def build_torchdata(host: RemoteHost, *,
357354
build_vars = ""
358355
if branch == 'nightly':
359356
version = host.check_output(["if [ -f data/version.txt ]; then cat data/version.txt; fi"]).strip()
360-
build_date = host.check_output("cd pytorch ; git log --pretty=format:%s -1").strip().split()[0].replace("-", "")
357+
build_date = host.check_output("cd data && git log --pretty=format:%s -1").strip().split()[0].replace("-", "")
361358
build_vars += f"BUILD_VERSION={version}.dev{build_date}"
362359
elif build_version is not None:
363360
build_vars += f"BUILD_VERSION={build_version} PYTORCH_VERSION={branch[1:].split('-')[0]}"
364361
if host.using_docker():
365362
build_vars += " CMAKE_SHARED_LINKER_FLAGS=-Wl,-z,max-page-size=0x10000"
366363

367-
host.run_cmd(f"cd data; {build_vars} python3 setup.py bdist_wheel")
364+
host.run_cmd(f"cd data && {build_vars} python3 setup.py bdist_wheel")
368365
wheel_name = host.list_dir("data/dist")[0]
369366
embed_libgomp(host, use_conda, os.path.join('data', 'dist', wheel_name))
370367

@@ -400,14 +397,14 @@ def build_torchtext(host: RemoteHost, *,
400397
build_vars = ""
401398
if branch == 'nightly':
402399
version = host.check_output(["if [ -f text/version.txt ]; then cat text/version.txt; fi"]).strip()
403-
build_date = host.check_output("cd pytorch ; git log --pretty=format:%s -1").strip().split()[0].replace("-", "")
400+
build_date = host.check_output("cd text && git log --pretty=format:%s -1").strip().split()[0].replace("-", "")
404401
build_vars += f"BUILD_VERSION={version}.dev{build_date}"
405402
elif build_version is not None:
406403
build_vars += f"BUILD_VERSION={build_version} PYTORCH_VERSION={branch[1:].split('-')[0]}"
407404
if host.using_docker():
408405
build_vars += " CMAKE_SHARED_LINKER_FLAGS=-Wl,-z,max-page-size=0x10000"
409406

410-
host.run_cmd(f"cd text; {build_vars} python3 setup.py bdist_wheel")
407+
host.run_cmd(f"cd text && {build_vars} python3 setup.py bdist_wheel")
411408
wheel_name = host.list_dir("text/dist")[0]
412409
embed_libgomp(host, use_conda, os.path.join('text', 'dist', wheel_name))
413410

@@ -443,14 +440,14 @@ def build_torchaudio(host: RemoteHost, *,
443440
build_vars = ""
444441
if branch == 'nightly':
445442
version = host.check_output(["grep", "\"version = '\"", "audio/setup.py"]).strip().split("'")[1][:-2]
446-
build_date = host.check_output("cd pytorch ; git log --pretty=format:%s -1").strip().split()[0].replace("-", "")
443+
build_date = host.check_output("cd audio && git log --pretty=format:%s -1").strip().split()[0].replace("-", "")
447444
build_vars += f"BUILD_VERSION={version}.dev{build_date}"
448445
elif build_version is not None:
449446
build_vars += f"BUILD_VERSION={build_version} PYTORCH_VERSION={branch[1:].split('-')[0]}"
450447
if host.using_docker():
451448
build_vars += " CMAKE_SHARED_LINKER_FLAGS=-Wl,-z,max-page-size=0x10000"
452449

453-
host.run_cmd(f"cd audio; {build_vars} python3 setup.py bdist_wheel")
450+
host.run_cmd(f"cd audio && {build_vars} python3 setup.py bdist_wheel")
454451
wheel_name = host.list_dir("audio/dist")[0]
455452
embed_libgomp(host, use_conda, os.path.join('audio', 'dist', wheel_name))
456453

@@ -523,7 +520,6 @@ def start_build(host: RemoteHost, *,
523520
use_conda=use_conda,
524521
python_version=python_version)
525522
build_OpenBLAS(host, git_clone_flags)
526-
# build_FFTW(host, git_clone_flags)
527523

528524
if host.using_docker():
529525
print("Move libgfortant.a into a standard location")
@@ -546,7 +542,7 @@ def start_build(host: RemoteHost, *,
546542
# Breakpad build fails on aarch64
547543
build_vars = "USE_BREAKPAD=0 "
548544
if branch == 'nightly':
549-
build_date = host.check_output("cd pytorch ; git log --pretty=format:%s -1").strip().split()[0].replace("-", "")
545+
build_date = host.check_output("cd pytorch && git log --pretty=format:%s -1").strip().split()[0].replace("-", "")
550546
version = host.check_output("cat pytorch/version.txt").strip()[:-2]
551547
build_vars += f"BUILD_TEST=0 PYTORCH_BUILD_VERSION={version}.dev{build_date} PYTORCH_BUILD_NUMBER=1"
552548
if branch.startswith("v1.") or branch.startswith("v2."):
@@ -557,19 +553,19 @@ def start_build(host: RemoteHost, *,
557553
build_ArmComputeLibrary(host, git_clone_flags)
558554
print("build pytorch with mkldnn+acl backend")
559555
build_vars += " USE_MKLDNN=ON USE_MKLDNN_ACL=ON"
560-
host.run_cmd(f"cd pytorch ; export ACL_ROOT_DIR=$HOME/ComputeLibrary:$HOME/acl; {build_vars} python3 setup.py bdist_wheel{build_opts}")
556+
host.run_cmd(f"cd pytorch && export ACL_ROOT_DIR=$HOME/ComputeLibrary:$HOME/acl && {build_vars} python3 setup.py bdist_wheel{build_opts}")
561557
print('Repair the wheel')
562558
pytorch_wheel_name = host.list_dir("pytorch/dist")[0]
563-
host.run_cmd(f"export LD_LIBRARY_PATH=$HOME/acl/build:$HOME/pytorch/build/lib; auditwheel repair $HOME/pytorch/dist/{pytorch_wheel_name}")
559+
host.run_cmd(f"export LD_LIBRARY_PATH=$HOME/acl/build:$HOME/pytorch/build/lib && auditwheel repair $HOME/pytorch/dist/{pytorch_wheel_name}")
564560
print('replace the original wheel with the repaired one')
565561
pytorch_repaired_wheel_name = host.list_dir("wheelhouse")[0]
566562
host.run_cmd(f"cp $HOME/wheelhouse/{pytorch_repaired_wheel_name} $HOME/pytorch/dist/{pytorch_wheel_name}")
567563
else:
568564
print("build pytorch without mkldnn backend")
569-
host.run_cmd(f"cd pytorch ; {build_vars} python3 setup.py bdist_wheel{build_opts}")
565+
host.run_cmd(f"cd pytorch && {build_vars} python3 setup.py bdist_wheel{build_opts}")
570566

571567
print("Deleting build folder")
572-
host.run_cmd("cd pytorch; rm -rf build")
568+
host.run_cmd("cd pytorch && rm -rf build")
573569
pytorch_wheel_name = host.list_dir("pytorch/dist")[0]
574570
embed_libgomp(host, use_conda, os.path.join('pytorch', 'dist', pytorch_wheel_name))
575571
print('Copying the wheel')

0 commit comments

Comments
 (0)