-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathbuild_locally.py
More file actions
194 lines (166 loc) · 4.89 KB
/
build_locally.py
File metadata and controls
194 lines (166 loc) · 4.89 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
# 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
from _build_helper import (
build_extension,
clean_build_dir,
err,
install_editable,
log_cmake_args,
make_cmake_args,
resolve_compilers,
)
def parse_args():
p = argparse.ArgumentParser(description="Local dpctl build driver")
p.add_argument(
"--c-compiler",
type=str,
default=None,
help="Path or name of C compiler",
)
p.add_argument(
"--cxx-compiler",
type=str,
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",
)
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)
# Level Zero state (on unless explicitly disabled)
level_zero_enabled = False if args.no_level_zero else 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}"]
log_cmake_args(cmake_args, "build_locally")
print("[build_locally] Building extensions in-place...")
env = os.environ.copy()
build_extension(
setup_dir,
env,
cmake_args,
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()