-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathbuild_locally.py
More file actions
226 lines (215 loc) · 6.55 KB
/
build_locally.py
File metadata and controls
226 lines (215 loc) · 6.55 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
220
221
222
223
224
225
226
# Data Parallel Control (dpctl)
#
# Copyright 2020-2025 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import subprocess
import sys
def run(
use_oneapi=True,
build_type="Release",
c_compiler=None,
cxx_compiler=None,
level_zero=True,
compiler_root=None,
cmake_executable=None,
use_glog=False,
verbose=False,
cmake_opts="",
target_cuda=None,
target_hip=None,
):
build_system = None
if "linux" in sys.platform:
build_system = "Ninja"
elif sys.platform in ["win32", "cygwin"]:
build_system = "Ninja"
else:
assert False, sys.platform + " not supported"
setup_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
cmake_args = [
sys.executable,
"setup.py",
"develop",
]
if cmake_executable:
cmake_args += [
"--cmake-executable=" + cmake_executable,
]
cmake_args += [
"--build-type=" + build_type,
"--generator=" + build_system,
"--",
"-DCMAKE_C_COMPILER:PATH=" + c_compiler,
"-DCMAKE_CXX_COMPILER:PATH=" + cxx_compiler,
"-DDPCTL_ENABLE_L0_PROGRAM_CREATION=" + ("ON" if level_zero else "OFF"),
"-DDPCTL_ENABLE_GLOG:BOOL=" + ("ON" if use_glog else "OFF"),
]
if verbose:
cmake_args += [
"-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON",
]
if cmake_opts:
cmake_args += cmake_opts.split()
if target_cuda is not None:
if not target_cuda.strip():
raise ValueError(
"--target-cuda can not be an empty string. "
"Use --target-cuda=<arch> or --target-cuda"
)
cmake_args += [
f"-DDPCTL_TARGET_CUDA={target_cuda}",
]
if target_hip is not None:
if not target_hip.strip():
raise ValueError(
"--target-hip requires an architecture (e.g., gfx90a)"
)
cmake_args += [
f"-DDPCTL_TARGET_HIP={target_hip}",
]
subprocess.check_call(
cmake_args, shell=False, cwd=setup_dir, env=os.environ
)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(
description="Driver to build dpctl for in-place installation"
)
driver = parser.add_argument_group(title="Coverage driver arguments")
driver.add_argument("--c-compiler", help="Name of C compiler", default=None)
driver.add_argument(
"--cxx-compiler", help="Name of C++ compiler", default=None
)
driver.add_argument(
"--oneapi",
help="Is one-API installation",
dest="oneapi",
action="store_true",
)
driver.add_argument(
"--debug",
default="Release",
const="Debug",
action="store_const",
help="Set the compilation mode to debugging",
)
driver.add_argument(
"--compiler-root",
type=str,
help="Path to compiler home directory",
default=None,
)
driver.add_argument(
"--cmake-executable",
type=str,
help="Path to cmake executable",
default=None,
)
driver.add_argument(
"--no-level-zero",
help="Enable Level Zero support",
dest="level_zero",
action="store_false",
)
driver.add_argument(
"--glog",
help="DPCTLSyclInterface uses Google logger",
dest="glog",
action="store_true",
)
driver.add_argument(
"--verbose",
help="Build using vebose makefile mode",
dest="verbose",
action="store_true",
)
driver.add_argument(
"--cmake-opts",
help="Options to pass through to cmake",
dest="cmake_opts",
default="",
type=str,
)
driver.add_argument(
"--target-cuda",
nargs="?",
const="ON",
help="Enable CUDA target for build; "
"optionally specify architecture (e.g., --target-cuda=sm_80)",
default=None,
type=str,
)
driver.add_argument(
"--target-hip",
required=False,
help="Enable HIP target for build. "
"Must specify HIP architecture (e.g., --target-hip=gfx90a)",
type=str,
)
args = parser.parse_args()
args_to_validate = [
"c_compiler",
"cxx_compiler",
"compiler_root",
]
if args.oneapi or (
args.c_compiler is None
and args.cxx_compiler is None
and args.compiler_root is None
):
args.c_compiler = "icx"
args.cxx_compiler = "icpx" if "linux" in sys.platform else "icx"
args.compiler_root = None
else:
cr = args.compiler_root
if isinstance(cr, str) and os.path.exists(cr):
if args.c_compiler is None:
args.c_compiler = "icx"
if args.cxx_compiler is None:
args.cxx_compiler = "icpx" if "linux" in sys.platform else "icx"
else:
raise RuntimeError(
"Option 'compiler-root' must be provided when "
"using non-default DPC++ layout."
)
args_to_validate = [
"c_compiler",
"cxx_compiler",
]
for p in args_to_validate:
arg = getattr(args, p)
assert isinstance(arg, str)
if not os.path.exists(arg):
arg2 = os.path.join(cr, arg)
if os.path.exists(arg2):
arg = arg2
setattr(args, p, arg)
if not os.path.exists(arg):
opt_name = p.replace("_", "-")
raise RuntimeError(f"Option {opt_name} value {arg} must exist.")
run(
use_oneapi=args.oneapi,
build_type=args.debug,
c_compiler=args.c_compiler,
cxx_compiler=args.cxx_compiler,
level_zero=args.level_zero,
compiler_root=args.compiler_root,
cmake_executable=args.cmake_executable,
use_glog=args.glog,
verbose=args.verbose,
cmake_opts=args.cmake_opts,
target_cuda=args.target_cuda,
target_hip=args.target_hip,
)