diff --git a/.gitignore b/.gitignore index f3a8c7903b4dab089be74151a36c29481c1ec843..72e5933ebb6ab708fa233c584e2ff3c5dcbac99e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ -hpvm/build*/ +build*/ +llvm-*.src.tar.xz +llvm-*.src/ +model_params.tar.gz +model_params/ hpvm/llvm/ -hpvm/llvm-*.src.tar.xz -hpvm/llvm-*.src/ hpvm/llvm_patches/**/*.patch # Below is taken from Python.gitignore: https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore diff --git a/hpvm/install.sh b/hpvm/install.sh index 3676a61972ff32566102d0eebdb490f00eaccb4b..6a009b7a2de20211dd28965940fa84cd4d8e7142 100755 --- a/hpvm/install.sh +++ b/hpvm/install.sh @@ -1,6 +1,6 @@ #!/bin/bash # Run installer script and pass on args to installer that can parse them -scripts/hpvm_installer.py "$@" +"${BASH_SOURCE%/*}/scripts/hpvm_installer.py" "$@" ret_code=$? echo "Installer returned with code $ret_code" exit $ret_code diff --git a/hpvm/scripts/hpvm_installer.py b/hpvm/scripts/hpvm_installer.py index 6460b82c1f0592eeaf389818757807c3f498f0af..142b27c656588fd7f5e4289a52bdd0957779e47f 100755 --- a/hpvm/scripts/hpvm_installer.py +++ b/hpvm/scripts/hpvm_installer.py @@ -14,7 +14,7 @@ LLVM_DIR = f"llvm-{VERSION}.src" LLVM_TARBALL = f"{LLVM_DIR}.tar.xz" ROOT_DIR = (Path(__file__).parent / "..").absolute().resolve() -MODEL_PARAMS_TAR = ROOT_DIR / "model_params.tar.gz" +MODEL_PARAMS_TAR = Path("model_params.tar.gz") MODEL_PARAMS_DIR = ROOT_DIR / "test/dnn_benchmarks/model_params" MODEL_PARAMS_LINK = "https://databank.illinois.edu/datafiles/o3izd/download" @@ -65,7 +65,8 @@ def parse_args(args=None): "--build-dir", type=Path, default="build", - help=f"Where to create the build directory. Relative to ({ROOT_DIR}). Default: build", + help=f"Where to create the build directory " + "(absolute path, or relative to current directory). Default: build", ) parser.add_argument( "-t", @@ -101,7 +102,6 @@ def parse_args(args=None): "Example: DCMAKE_BUILD_TYPE=Release DCMAKE_INSTALL_PREFIX=install", ) args = parser.parse_args(args) - args.build_dir = ROOT_DIR / args.build_dir args.cmake_args = [f"-{arg}" for arg in args.cmake_args] return args @@ -202,7 +202,8 @@ def check_python_version(): def check_download_llvm_clang(): - if Path("llvm/").is_dir(): + llvm = ROOT_DIR / "llvm" + if llvm.is_dir(): print("Found LLVM directory, not extracting it again.") else: if Path(LLVM_TARBALL).is_file(): @@ -212,26 +213,26 @@ def check_download_llvm_clang(): print(f"=============================") download(f"{URL}/{VERSION}/{LLVM_TARBALL}", LLVM_TARBALL) check_call(["tar", "xf", LLVM_TARBALL]) - check_call(["mv", LLVM_DIR, "llvm"]) - tools = Path("llvm/tools") + check_call(["mv", LLVM_DIR, str(llvm)]) + tools = llvm / "tools" assert tools.is_dir(), "Problem with LLVM download. Exiting!" if Path(LLVM_TARBALL).is_file(): Path(LLVM_TARBALL).unlink() # Remove tarball + # TODO: check and remove this environ["LLVM_SRC_ROOT"] = str(ROOT_DIR / "llvm") - if (tools / "clang/").is_dir(): + clang = tools / "clang" + if clang.is_dir(): print("Found clang directory, not extracting it again.") return - chdir(tools) print(f"Downloading {CLANG_TARBALL}...") print(f"=============================") download(f"{URL}/{VERSION}/{CLANG_TARBALL}", CLANG_TARBALL) check_call(["tar", "xf", CLANG_TARBALL]) - check_call(["mv", CLANG_DIR, "clang"]) - assert Path("clang/").is_dir(), "Problem with clang download. Exiting!" + check_call(["mv", CLANG_DIR, str(clang)]) + assert clang.is_dir(), "Problem with clang download. Exiting!" if Path(CLANG_TARBALL).is_file(): Path(CLANG_TARBALL).unlink() - chdir(ROOT_DIR) def check_download_model_params(): @@ -265,6 +266,7 @@ def check_download_model_params(): def link_and_patch(): from os import symlink + cwd = Path.cwd() hpvm = ROOT_DIR / "llvm/tools/hpvm" print("Adding HPVM sources to tree...") makedirs(hpvm, exist_ok=True) @@ -273,11 +275,11 @@ def link_and_patch(): print(ROOT_DIR / link, hpvm / link) symlink(ROOT_DIR / link, hpvm / link) print("Applying HPVM patches...") - chdir("llvm_patches") + chdir(ROOT_DIR / "llvm_patches") check_call(["bash", "./construct_patch.sh"]) check_call(["bash", "./apply_patch.sh"]) print("Patches applied.") - chdir("..") + chdir(cwd) def build( @@ -291,10 +293,11 @@ def build( print(f"Using {nthreads} threads to build HPVM.") makedirs(build_dir, exist_ok=True) + cwd = Path.cwd() chdir(build_dir) cmake_args = [ "cmake", - "../llvm", + str(ROOT_DIR / "llvm"), "-DCMAKE_C_COMPILER=gcc", "-DCMAKE_CXX_COMPILER=g++", f"-DLLVM_TARGETS_TO_BUILD={targets}", @@ -311,27 +314,27 @@ def build( print(f"Build system ({build_sys}): {' '.join(build_args)}") print(f"=============================") check_call(build_args) - chdir(ROOT_DIR) + chdir(cwd) def install_py_packages(): import sys - project_root = Path(__file__).parent.parent for package in PY_PACKAGES: - package_home = project_root / package + package_home = ROOT_DIR / package print(f"Installing python package {package_home}") check_call([sys.executable, "-m", "pip", "install", str(package_home)]) def run_tests(build_dir: Path, use_ninja: bool, nthreads: int): + cwd = Path.cwd() chdir(build_dir) build_sys = "ninja" if use_ninja else "make" build_args = [build_sys, f"-j{nthreads}", *MAKE_TARGETS] print(f"Tests: {' '.join(build_args)}") print(f"=============================") check_call(build_args) - chdir(ROOT_DIR) + chdir(cwd) def input_with_check(prompt: str, parse, prompt_when_invalid: str):