forked from intel/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure.py
More file actions
219 lines (188 loc) · 10.1 KB
/
Copy pathconfigure.py
File metadata and controls
219 lines (188 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import argparse
import os
import platform
import subprocess
import sys
def do_configure(args):
# Get absolute path to source directory
abs_src_dir = os.path.abspath(args.src_dir if args.src_dir else os.path.join(__file__, "../.."))
# Get absolute path to build directory
abs_obj_dir = os.path.abspath(args.obj_dir) if args.obj_dir else os.path.join(abs_src_dir, "build")
# Create build directory if it doesn't exist
if not os.path.isdir(abs_obj_dir):
os.makedirs(abs_obj_dir)
llvm_external_projects = 'sycl;llvm-spirv;opencl;libdevice;xpti;xptifw'
if args.llvm_external_projects:
llvm_external_projects += ";" + args.llvm_external_projects.replace(",", ";")
llvm_dir = os.path.join(abs_src_dir, "llvm")
sycl_dir = os.path.join(abs_src_dir, "sycl")
spirv_dir = os.path.join(abs_src_dir, "llvm-spirv")
xpti_dir = os.path.join(abs_src_dir, "xpti")
xptifw_dir = os.path.join(abs_src_dir, "xptifw")
libdevice_dir = os.path.join(abs_src_dir, "libdevice")
llvm_targets_to_build = 'X86'
llvm_enable_projects = 'clang;' + llvm_external_projects
libclc_targets_to_build = ''
libclc_gen_remangled_variants = 'OFF'
sycl_build_pi_cuda = 'OFF'
sycl_build_pi_esimd_emulator = 'OFF'
sycl_build_pi_hip = 'OFF'
sycl_build_pi_hip_platform = 'AMD'
sycl_clang_extra_flags = ''
sycl_werror = 'ON'
llvm_enable_assertions = 'ON'
llvm_enable_doxygen = 'OFF'
llvm_enable_sphinx = 'OFF'
llvm_build_shared_libs = 'OFF'
llvm_enable_lld = 'OFF'
sycl_enable_xpti_tracing = 'ON'
xpti_enable_werror = 'ON'
if args.ci_defaults:
print("#############################################")
print("# Default CI configuration will be applied. #")
print("#############################################")
# replace not append, so ARM ^ X86
if args.arm:
llvm_targets_to_build = 'ARM;AArch64'
if args.enable_esimd_cpu_emulation:
sycl_build_pi_esimd_emulator = 'ON'
if args.cuda or args.hip:
llvm_enable_projects += ';libclc'
if args.cuda:
llvm_targets_to_build += ';NVPTX'
libclc_targets_to_build = 'nvptx64--;nvptx64--nvidiacl'
libclc_gen_remangled_variants = 'ON'
sycl_build_pi_cuda = 'ON'
if args.hip:
if args.hip_platform == 'AMD':
llvm_targets_to_build += ';AMDGPU'
libclc_targets_to_build += ';amdgcn--;amdgcn--amdhsa'
if args.hip_amd_arch:
sycl_clang_extra_flags += "-Xsycl-target-backend=amdgcn-amd-amdhsa --offload-arch="+args.hip_amd_arch
# The HIP plugin for AMD uses lld for linking
llvm_enable_projects += ';lld'
elif args.hip_platform == 'NVIDIA' and not args.cuda:
llvm_targets_to_build += ';NVPTX'
libclc_targets_to_build += ';nvptx64--;nvptx64--nvidiacl'
libclc_gen_remangled_variants = 'ON'
sycl_build_pi_hip_platform = args.hip_platform
sycl_build_pi_hip = 'ON'
if args.no_werror:
sycl_werror = 'OFF'
xpti_enable_werror = 'OFF'
if args.no_assertions:
llvm_enable_assertions = 'OFF'
if args.docs:
llvm_enable_doxygen = 'ON'
llvm_enable_sphinx = 'ON'
if args.shared_libs:
llvm_build_shared_libs = 'ON'
if args.use_lld:
llvm_enable_lld = 'ON'
install_dir = os.path.join(abs_obj_dir, "install")
cmake_cmd = [
"cmake",
"-G", args.cmake_gen,
"-DCMAKE_BUILD_TYPE={}".format(args.build_type),
"-DLLVM_ENABLE_ASSERTIONS={}".format(llvm_enable_assertions),
"-DLLVM_TARGETS_TO_BUILD={}".format(llvm_targets_to_build),
"-DLLVM_EXTERNAL_PROJECTS={}".format(llvm_external_projects),
"-DLLVM_EXTERNAL_SYCL_SOURCE_DIR={}".format(sycl_dir),
"-DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR={}".format(spirv_dir),
"-DLLVM_EXTERNAL_XPTI_SOURCE_DIR={}".format(xpti_dir),
"-DXPTI_SOURCE_DIR={}".format(xpti_dir),
"-DLLVM_EXTERNAL_XPTIFW_SOURCE_DIR={}".format(xptifw_dir),
"-DLLVM_EXTERNAL_LIBDEVICE_SOURCE_DIR={}".format(libdevice_dir),
"-DLLVM_ENABLE_PROJECTS={}".format(llvm_enable_projects),
"-DLIBCLC_TARGETS_TO_BUILD={}".format(libclc_targets_to_build),
"-DLIBCLC_GENERATE_REMANGLED_VARIANTS={}".format(libclc_gen_remangled_variants),
"-DSYCL_BUILD_PI_CUDA={}".format(sycl_build_pi_cuda),
"-DSYCL_BUILD_PI_HIP={}".format(sycl_build_pi_hip),
"-DSYCL_BUILD_PI_HIP_PLATFORM={}".format(sycl_build_pi_hip_platform),
"-DLLVM_BUILD_TOOLS=ON",
"-DSYCL_ENABLE_WERROR={}".format(sycl_werror),
"-DCMAKE_INSTALL_PREFIX={}".format(install_dir),
"-DSYCL_INCLUDE_TESTS=ON", # Explicitly include all kinds of SYCL tests.
"-DLLVM_ENABLE_DOXYGEN={}".format(llvm_enable_doxygen),
"-DLLVM_ENABLE_SPHINX={}".format(llvm_enable_sphinx),
"-DBUILD_SHARED_LIBS={}".format(llvm_build_shared_libs),
"-DSYCL_ENABLE_XPTI_TRACING={}".format(sycl_enable_xpti_tracing),
"-DLLVM_ENABLE_LLD={}".format(llvm_enable_lld),
"-DSYCL_BUILD_PI_ESIMD_EMULATOR={}".format(sycl_build_pi_esimd_emulator),
"-DXPTI_ENABLE_WERROR={}".format(xpti_enable_werror),
"-DSYCL_CLANG_EXTRA_FLAGS={}".format(sycl_clang_extra_flags)
]
if args.l0_headers and args.l0_loader:
cmake_cmd.extend([
"-DL0_INCLUDE_DIR={}".format(args.l0_headers),
"-DL0_LIBRARY={}".format(args.l0_loader)])
elif args.l0_headers or args.l0_loader:
sys.exit("Please specify both Level Zero headers and loader or don't specify "
"none of them to let download from github.com")
# Add additional CMake options if provided
if args.cmake_opt:
cmake_cmd += args.cmake_opt
# Add path to root CMakeLists.txt
cmake_cmd.append(llvm_dir)
if args.use_libcxx:
if not (args.libcxx_include and args.libcxx_library):
sys.exit("Please specify include and library path of libc++ when building sycl "
"runtime with it")
cmake_cmd.extend([
"-DSYCL_USE_LIBCXX=ON",
"-DSYCL_LIBCXX_INCLUDE_PATH={}".format(args.libcxx_include),
"-DSYCL_LIBCXX_LIBRARY_PATH={}".format(args.libcxx_library)])
print("[Cmake Command]: {}".format(" ".join(cmake_cmd)))
try:
subprocess.check_call(cmake_cmd, cwd=abs_obj_dir)
except subprocess.CalledProcessError:
cmake_cache = os.path.join(abs_obj_dir, "CMakeCache.txt")
if os.path.isfile(cmake_cache):
print("There is CMakeCache.txt at " + cmake_cache +
" ... you can try to remove it and rerun.")
print("Configure failed!")
return False
return True
def main():
parser = argparse.ArgumentParser(prog="configure.py",
description="Generate build files from CMake configuration files",
formatter_class=argparse.RawTextHelpFormatter)
# CI system options
parser.add_argument("-n", "--build-number", metavar="BUILD_NUM", help="build number")
parser.add_argument("-b", "--branch", metavar="BRANCH", help="pull request branch")
parser.add_argument("-d", "--base-branch", metavar="BASE_BRANCH", help="pull request base branch")
parser.add_argument("-r", "--pr-number", metavar="PR_NUM", help="pull request number")
parser.add_argument("-w", "--builder-dir", metavar="BUILDER_DIR",
help="builder directory, which is the directory containing source and build directories")
# User options
parser.add_argument("-s", "--src-dir", metavar="SRC_DIR", help="source directory (autodetected by default)")
parser.add_argument("-o", "--obj-dir", metavar="OBJ_DIR", help="build directory. (<src>/build by default)")
parser.add_argument("--l0-headers", metavar="L0_HEADER_DIR", help="directory with Level Zero headers")
parser.add_argument("--l0-loader", metavar="L0_LOADER", help="path to the Level Zero loader")
parser.add_argument("-t", "--build-type",
metavar="BUILD_TYPE", default="Release", help="build type: Debug, Release")
parser.add_argument("--cuda", action='store_true', help="switch from OpenCL to CUDA")
parser.add_argument("--hip", action='store_true', help="switch from OpenCL to HIP")
parser.add_argument("--hip-platform", type=str, choices=['AMD', 'NVIDIA'], default='AMD', help="choose hardware platform for HIP backend")
parser.add_argument("--hip-amd-arch", type=str, help="Sets AMD gpu architecture for llvm lit tests, this is only needed for the HIP backend and AMD platform")
parser.add_argument("--arm", action='store_true', help="build ARM support rather than x86")
parser.add_argument("--enable-esimd-cpu-emulation", action='store_true', help="build with ESIMD_CPU emulation support")
parser.add_argument("--no-assertions", action='store_true', help="build without assertions")
parser.add_argument("--docs", action='store_true', help="build Doxygen documentation")
parser.add_argument("--no-werror", action='store_true', help="Don't treat warnings as errors")
parser.add_argument("--shared-libs", action='store_true', help="Build shared libraries")
parser.add_argument("--cmake-opt", action='append', help="Additional CMake option not configured via script parameters")
parser.add_argument("--cmake-gen", default="Ninja", help="CMake generator")
parser.add_argument("--use-libcxx", action="store_true", help="build sycl runtime with libcxx")
parser.add_argument("--libcxx-include", metavar="LIBCXX_INCLUDE_PATH", help="libcxx include path")
parser.add_argument("--libcxx-library", metavar="LIBCXX_LIBRARY_PATH", help="libcxx library path")
parser.add_argument("--use-lld", action="store_true", help="Use LLD linker for build")
parser.add_argument("--llvm-external-projects", help="Add external projects to build. Add as comma seperated list.")
parser.add_argument("--ci-defaults", action="store_true", help="Enable default CI parameters")
args = parser.parse_args()
print("args:{}".format(args))
return do_configure(args)
if __name__ == "__main__":
ret = main()
exit_code = 0 if ret else 1
sys.exit(exit_code)