-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathbuild_locally.py
More file actions
218 lines (186 loc) · 5.78 KB
/
build_locally.py
File metadata and controls
218 lines (186 loc) · 5.78 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
# 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 argparse
import os
import sys
# add scripts dir to Python path so we can import _build_helper
sys.path.insert(0, os.path.abspath("scripts"))
from _build_helper import ( # noqa: E402
build_extension,
clean_build_dir,
err,
install_editable,
make_cmake_args,
resolve_compilers,
warn,
)
def parse_args():
p = argparse.ArgumentParser(description="Local dpctl build driver")
p.add_argument(
"--c-compiler", default=None, help="Path or name of C compiler"
)
p.add_argument(
"--cxx-compiler", default=None, help="Path or name of C++ compiler"
)
p.add_argument(
"--compiler-root",
type=str,
default=None,
help="Path to compiler installation root",
)
p.add_argument(
"--oneapi",
dest="oneapi",
action="store_true",
help="Use default oneAPI compiler layout",
)
p.add_argument(
"--debug",
dest="build_type",
const="Debug",
action="store_const",
default="Release",
help="Set build type to Debug (defaults to Release)",
)
p.add_argument(
"--generator", type=str, default="Ninja", help="CMake generator"
)
p.add_argument(
"--cmake-executable",
type=str,
default=None,
help="Path to CMake executable used by build",
)
p.add_argument(
"--glog",
dest="glog",
action="store_true",
help="Enable DPCTL Google logger support",
)
p.add_argument(
"--verbose",
dest="verbose",
action="store_true",
help="Enable verbose makefile output",
)
p.add_argument(
"--no-level-zero",
dest="no_level_zero",
action="store_true",
default=False,
help="Disable Level Zero backend (deprecated: use --target-level-zero "
"OFF)",
)
p.add_argument(
"--target-level-zero",
action="store_true",
help="Enable Level Zero backend explicitly",
)
p.add_argument(
"--cmake-opts",
type=str,
default="",
help="Additional options to pass directly to CMake",
)
p.add_argument(
"--target-cuda",
nargs="?",
const="ON",
default=None,
help="Enable CUDA build. Architecture is optional to specify.",
)
p.add_argument(
"--target-hip",
required=False,
type=str,
help="Enable HIP backend. Architecture required to be specified.",
)
p.add_argument(
"--clean",
action="store_true",
help="Remove build dir before rebuild",
)
p.add_argument(
"--skip-editable",
action="store_true",
help="Skip pip editable install step",
)
return p.parse_args()
def main():
if sys.platform not in ["cygwin", "win32", "linux"]:
err(f"{sys.platform} not supported", "build_locally")
args = parse_args()
setup_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
c_compiler, cxx_compiler = resolve_compilers(
args.oneapi, args.c_compiler, args.cxx_compiler, args.compiler_root
)
# clean build dir if --clean set
if args.clean:
clean_build_dir(setup_dir)
if args.no_level_zero and args.target_level_zero:
err(
"Cannot combine --no-level-zero and --target-level-zero",
"build_locally",
)
# Level Zero state (on unless explicitly disabled)
if args.no_level_zero:
level_zero_enabled = False
elif args.target_level_zero:
level_zero_enabled = True
else:
level_zero_enabled = True
cmake_args = make_cmake_args(
c_compiler=c_compiler,
cxx_compiler=cxx_compiler,
level_zero=level_zero_enabled,
glog=args.glog,
verbose=args.verbose,
other_opts=args.cmake_opts,
)
# handle architecture conflicts
if args.target_hip is not None and not args.target_hip.strip():
err("--target-hip requires an explicit architecture", "build_locally")
# CUDA/HIP targets
if args.target_cuda:
cmake_args += f" -DDPCTL_TARGET_CUDA={args.target_cuda}"
if args.target_hip:
cmake_args += f" -DDPCTL_TARGET_HIP={args.target_hip}"
cmake_args += (
" -DDPCTL_ENABLE_L0_PROGRAM_CREATION="
f"{'ON' if level_zero_enabled else 'OFF'}"
)
env = os.environ.copy()
# ignore pre-existing CMAKE_ARGS for determinism in build driver
if "CMAKE_ARGS" in env and env["CMAKE_ARGS"].strip():
warn("Ignoring pre-existing CMAKE_ARGS in environment", "build_locally")
del env["CMAKE_ARGS"]
env["CMAKE_ARGS"] = cmake_args
print(f"[build_locally] CMake args:\n {cmake_args}")
print("[build_locally] Building extensions in-place...")
build_extension(
setup_dir,
env,
cmake_executable=args.cmake_executable,
generator=args.generator,
build_type=args.build_type,
)
if not args.skip_editable:
install_editable(setup_dir, env)
else:
print("[build_locally] Skipping editable install (--skip-editable)")
print("[build_locally] Build complete")
if __name__ == "__main__":
main()