|
9 | 9 |
|
10 | 10 |
|
11 | 11 | def list_dir(path: str) -> List[str]:
|
12 |
| - '''' |
| 12 | + """' |
13 | 13 | Helper for getting paths for Python
|
14 |
| - ''' |
| 14 | + """ |
15 | 15 | return check_output(["ls", "-1", path]).decode().split("\n")
|
16 | 16 |
|
17 | 17 |
|
18 | 18 | def build_ArmComputeLibrary() -> None:
|
19 |
| - ''' |
| 19 | + """ |
20 | 20 | Using ArmComputeLibrary for aarch64 PyTorch
|
21 |
| - ''' |
22 |
| - print('Building Arm Compute Library') |
23 |
| - acl_build_flags=["debug=0", "neon=1", "opencl=0", "os=linux", "openmp=1", "cppthreads=0", |
24 |
| - "arch=armv8a", "multi_isa=1", "fixed_format_kernels=1", "build=native"] |
25 |
| - acl_install_dir="/acl" |
26 |
| - acl_checkout_dir="ComputeLibrary" |
| 21 | + """ |
| 22 | + print("Building Arm Compute Library") |
| 23 | + acl_build_flags = [ |
| 24 | + "debug=0", |
| 25 | + "neon=1", |
| 26 | + "opencl=0", |
| 27 | + "os=linux", |
| 28 | + "openmp=1", |
| 29 | + "cppthreads=0", |
| 30 | + "arch=armv8a", |
| 31 | + "multi_isa=1", |
| 32 | + "fixed_format_kernels=1", |
| 33 | + "build=native", |
| 34 | + ] |
| 35 | + acl_install_dir = "/acl" |
| 36 | + acl_checkout_dir = "ComputeLibrary" |
27 | 37 | os.makedirs(acl_install_dir)
|
28 |
| - check_call(["git", "clone", "https://github.com/ARM-software/ComputeLibrary.git", "-b", "v23.08", |
29 |
| - "--depth", "1", "--shallow-submodules"]) |
30 |
| - check_call(["scons", "Werror=1", "-j8", f"build_dir=/{acl_install_dir}/build"] + acl_build_flags, |
31 |
| - cwd=acl_checkout_dir) |
| 38 | + check_call( |
| 39 | + [ |
| 40 | + "git", |
| 41 | + "clone", |
| 42 | + "https://github.com/ARM-software/ComputeLibrary.git", |
| 43 | + "-b", |
| 44 | + "v23.08", |
| 45 | + "--depth", |
| 46 | + "1", |
| 47 | + "--shallow-submodules", |
| 48 | + ] |
| 49 | + ) |
| 50 | + check_call( |
| 51 | + ["scons", "Werror=1", "-j8", f"build_dir=/{acl_install_dir}/build"] |
| 52 | + + acl_build_flags, |
| 53 | + cwd=acl_checkout_dir, |
| 54 | + ) |
32 | 55 | for d in ["arm_compute", "include", "utils", "support", "src"]:
|
33 | 56 | shutil.copytree(f"{acl_checkout_dir}/{d}", f"{acl_install_dir}/{d}")
|
34 | 57 |
|
35 | 58 |
|
| 59 | +def update_wheel(wheel_path) -> None: |
| 60 | + """ |
| 61 | + Update the cuda wheel libraries |
| 62 | + """ |
| 63 | + folder = os.path.dirname(wheel_path) |
| 64 | + wheelname = os.path.basename(wheel_path) |
| 65 | + os.mkdir(f"{folder}/tmp") |
| 66 | + os.system(f"unzip {wheel_path} -d {folder}/tmp") |
| 67 | + libs_to_copy = [ |
| 68 | + "/usr/local/cuda/extras/CUPTI/lib64/libcupti.so.12", |
| 69 | + "/usr/local/cuda/lib64/libcudnn.so.8", |
| 70 | + "/usr/local/cuda/lib64/libcublas.so.12", |
| 71 | + "/usr/local/cuda/lib64/libcublasLt.so.12", |
| 72 | + "/usr/local/cuda/lib64/libcudart.so.12", |
| 73 | + "/usr/local/cuda/lib64/libcufft.so.11", |
| 74 | + "/usr/local/cuda/lib64/libcusparse.so.12", |
| 75 | + "/usr/local/cuda/lib64/libcusparseLt.so.0", |
| 76 | + "/usr/local/cuda/lib64/libcusolver.so.11", |
| 77 | + "/usr/local/cuda/lib64/libcurand.so.10", |
| 78 | + "/usr/local/cuda/lib64/libnvToolsExt.so.1", |
| 79 | + "/usr/local/cuda/lib64/libnvJitLink.so.12", |
| 80 | + "/usr/local/cuda/lib64/libnvrtc.so.12", |
| 81 | + "/usr/local/cuda/lib64/libnvrtc-builtins.so.12.4", |
| 82 | + "/usr/local/cuda/lib64/libcudnn_adv_infer.so.8", |
| 83 | + "/usr/local/cuda/lib64/libcudnn_adv_train.so.8", |
| 84 | + "/usr/local/cuda/lib64/libcudnn_cnn_infer.so.8", |
| 85 | + "/usr/local/cuda/lib64/libcudnn_cnn_train.so.8", |
| 86 | + "/usr/local/cuda/lib64/libcudnn_ops_infer.so.8", |
| 87 | + "/usr/local/cuda/lib64/libcudnn_ops_train.so.8", |
| 88 | + "/opt/conda/envs/aarch64_env/lib/libopenblas.so.0", |
| 89 | + "/opt/conda/envs/aarch64_env/lib/libgfortran.so.5", |
| 90 | + "/opt/conda/envs/aarch64_env/lib/libgomp.so.1", |
| 91 | + "/acl/build/libarm_compute.so", |
| 92 | + "/acl/build/libarm_compute_graph.so", |
| 93 | + "/acl/build/libarm_compute_core.so", |
| 94 | + ] |
| 95 | + # Copy libraries to unzipped_folder/a/lib |
| 96 | + for lib_path in libs_to_copy: |
| 97 | + lib_name = os.path.basename(lib_path) |
| 98 | + shutil.copy2(lib_path, f"{folder}/tmp/torch/lib/{lib_name}") |
| 99 | + os.system( |
| 100 | + f"cd {folder}/tmp/torch/lib/; patchelf --set-rpath '$ORIGIN' {folder}/tmp/torch/lib/libtorch_cuda.so" |
| 101 | + ) |
| 102 | + os.mkdir(f"{folder}/cuda_wheel") |
| 103 | + os.system(f"cd {folder}/tmp/; zip -r {folder}/cuda_wheel/{wheelname} *") |
| 104 | + shutil.move( |
| 105 | + f"{folder}/cuda_wheel/{wheelname}", |
| 106 | + f"/dist/{wheelname}", |
| 107 | + copy_function=shutil.copy2, |
| 108 | + ) |
| 109 | + os.system(f"rm -rf {folder}/tmp {folder}/dist/cuda_wheel/") |
| 110 | + |
| 111 | + |
36 | 112 | def complete_wheel(folder: str) -> str:
|
37 |
| - ''' |
| 113 | + """ |
38 | 114 | Complete wheel build and put in artifact location
|
39 |
| - ''' |
| 115 | + """ |
40 | 116 | wheel_name = list_dir(f"/{folder}/dist")[0]
|
41 | 117 |
|
42 |
| - if "pytorch" in folder: |
| 118 | + if "pytorch" in folder and not enable_cuda: |
43 | 119 | print("Repairing Wheel with AuditWheel")
|
44 |
| - check_call(["auditwheel","repair", f"dist/{wheel_name}"], cwd=folder) |
| 120 | + check_call(["auditwheel", "repair", f"dist/{wheel_name}"], cwd=folder) |
45 | 121 | repaired_wheel_name = list_dir(f"/{folder}/wheelhouse")[0]
|
46 | 122 |
|
47 | 123 | print(f"Moving {repaired_wheel_name} wheel to /{folder}/dist")
|
48 |
| - os.rename(f"/{folder}/wheelhouse/{repaired_wheel_name}", f"/{folder}/dist/{repaired_wheel_name}") |
| 124 | + os.rename( |
| 125 | + f"/{folder}/wheelhouse/{repaired_wheel_name}", |
| 126 | + f"/{folder}/dist/{repaired_wheel_name}", |
| 127 | + ) |
49 | 128 | else:
|
50 | 129 | repaired_wheel_name = wheel_name
|
51 | 130 |
|
52 |
| - print(f"Copying {repaired_wheel_name} to artfacts") |
53 |
| - shutil.copy2(f"/{folder}/dist/{repaired_wheel_name}", f"/artifacts/{repaired_wheel_name}") |
| 131 | + print(f"Copying {repaired_wheel_name} to artifacts") |
| 132 | + shutil.copy2( |
| 133 | + f"/{folder}/dist/{repaired_wheel_name}", f"/artifacts/{repaired_wheel_name}" |
| 134 | + ) |
54 | 135 |
|
55 | 136 | return repaired_wheel_name
|
56 | 137 |
|
57 | 138 |
|
58 | 139 | def parse_arguments():
|
59 |
| - ''' |
| 140 | + """ |
60 | 141 | Parse inline arguments
|
61 |
| - ''' |
| 142 | + """ |
62 | 143 | from argparse import ArgumentParser
|
| 144 | + |
63 | 145 | parser = ArgumentParser("AARCH64 wheels python CD")
|
64 | 146 | parser.add_argument("--debug", action="store_true")
|
65 | 147 | parser.add_argument("--build-only", action="store_true")
|
66 | 148 | parser.add_argument("--test-only", type=str)
|
67 | 149 | parser.add_argument("--enable-mkldnn", action="store_true")
|
| 150 | + parser.add_argument("--enable-cuda", action="store_true") |
68 | 151 | return parser.parse_args()
|
69 | 152 |
|
70 | 153 |
|
71 |
| -if __name__ == '__main__': |
72 |
| - ''' |
| 154 | +if __name__ == "__main__": |
| 155 | + """ |
73 | 156 | Entry Point
|
74 |
| - ''' |
| 157 | + """ |
75 | 158 | args = parse_arguments()
|
76 | 159 | enable_mkldnn = args.enable_mkldnn
|
77 |
| - repo = Repository('/pytorch') |
| 160 | + enable_cuda = args.enable_cuda |
| 161 | + repo = Repository("/pytorch") |
78 | 162 | branch = repo.head.name
|
79 |
| - if branch == 'HEAD': |
80 |
| - branch = 'master' |
81 |
| - |
| 163 | + if branch == "HEAD": |
| 164 | + branch = "master" |
82 | 165 |
|
83 |
| - print('Building PyTorch wheel') |
| 166 | + print("Building PyTorch wheel") |
84 | 167 | build_vars = "CMAKE_SHARED_LINKER_FLAGS=-Wl,-z,max-page-size=0x10000 "
|
85 | 168 | os.system("python setup.py clean")
|
86 | 169 |
|
87 | 170 | override_package_version = os.getenv("OVERRIDE_PACKAGE_VERSION")
|
88 | 171 | if override_package_version is not None:
|
89 | 172 | version = override_package_version
|
90 |
| - build_vars += f"BUILD_TEST=0 PYTORCH_BUILD_VERSION={version} PYTORCH_BUILD_NUMBER=1 " |
91 |
| - elif branch in ['nightly', 'master']: |
92 |
| - build_date = check_output(['git', 'log', '--pretty=format:%cs', '-1'], cwd='/pytorch').decode().replace('-', '') |
93 |
| - version = check_output(['cat', 'version.txt'], cwd='/pytorch').decode().strip()[:-2] |
| 173 | + build_vars += ( |
| 174 | + f"BUILD_TEST=0 PYTORCH_BUILD_VERSION={version} PYTORCH_BUILD_NUMBER=1 " |
| 175 | + ) |
| 176 | + elif branch in ["nightly", "master"]: |
| 177 | + build_date = ( |
| 178 | + check_output(["git", "log", "--pretty=format:%cs", "-1"], cwd="/pytorch") |
| 179 | + .decode() |
| 180 | + .replace("-", "") |
| 181 | + ) |
| 182 | + version = ( |
| 183 | + check_output(["cat", "version.txt"], cwd="/pytorch").decode().strip()[:-2] |
| 184 | + ) |
94 | 185 | build_vars += f"BUILD_TEST=0 PYTORCH_BUILD_VERSION={version}.dev{build_date} PYTORCH_BUILD_NUMBER=1 "
|
95 | 186 | elif branch.startswith(("v1.", "v2.")):
|
96 | 187 | build_vars += f"BUILD_TEST=0 PYTORCH_BUILD_VERSION={branch[1:branch.find('-')]} PYTORCH_BUILD_NUMBER=1 "
|
97 | 188 |
|
98 | 189 | if enable_mkldnn:
|
99 | 190 | build_ArmComputeLibrary()
|
100 | 191 | print("build pytorch with mkldnn+acl backend")
|
101 |
| - build_vars += "USE_MKLDNN=ON USE_MKLDNN_ACL=ON " \ |
102 |
| - "ACL_ROOT_DIR=/acl " \ |
103 |
| - "LD_LIBRARY_PATH=/pytorch/build/lib:/acl/build:$LD_LIBRARY_PATH " \ |
104 |
| - "ACL_INCLUDE_DIR=/acl/build " \ |
105 |
| - "ACL_LIBRARY=/acl/build " |
| 192 | + build_vars += ( |
| 193 | + "USE_MKLDNN=ON USE_MKLDNN_ACL=ON " |
| 194 | + "ACL_ROOT_DIR=/acl " |
| 195 | + "LD_LIBRARY_PATH=/pytorch/build/lib:/acl/build:$LD_LIBRARY_PATH " |
| 196 | + "ACL_INCLUDE_DIR=/acl/build " |
| 197 | + "ACL_LIBRARY=/acl/build " |
| 198 | + ) |
106 | 199 | else:
|
107 | 200 | print("build pytorch without mkldnn backend")
|
108 | 201 |
|
109 | 202 | os.system(f"cd /pytorch; {build_vars} python3 setup.py bdist_wheel")
|
110 |
| - pytorch_wheel_name = complete_wheel("pytorch") |
111 |
| - print(f"Build Compelete. Created {pytorch_wheel_name}..") |
| 203 | + if enable_cuda: |
| 204 | + print("Updating Cuda Dependency") |
| 205 | + filename = os.listdir("/pytorch/dist/") |
| 206 | + wheel_path = f"/pytorch/dist/{filename[0]}" |
| 207 | + update_wheel(wheel_path) |
| 208 | + pytorch_wheel_name = complete_wheel("/pytorch/") |
| 209 | + print(f"Build Complete. Created {pytorch_wheel_name}..") |
0 commit comments