Skip to content

Commit a207271

Browse files
Merge pull request #2109 from IntelPython/add_targets_args
Extend build_locally.py script by adding --target-cuda and --target-hip arguments to simplify configuration of CUDA and AMD targets without manually passing CMake options
2 parents 0dbd495 + f0c7c42 commit a207271

File tree

2 files changed

+75
-9
lines changed

2 files changed

+75
-9
lines changed

docs/doc_sources/beginners_guides/installation.rst

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,27 @@ A full list of available SYCL alias targets is available in the
166166
CUDA build
167167
~~~~~~~~~~
168168

169-
``dpctl`` can be built for CUDA devices using the ``DPCTL_TARGET_CUDA`` CMake option,
170-
which accepts a specific compute architecture string:
169+
``dpctl`` can be built for CUDA devices using the ``--target-cuda`` argument.
170+
171+
To target a specific architecture (e.g., ``sm_80``):
172+
173+
.. code-block:: bash
174+
175+
python scripts/build_locally.py --verbose --target-cuda=sm_80
176+
177+
To use the default architecture (``sm_50``), omit the value:
178+
179+
.. code-block:: bash
180+
181+
python scripts/build_locally.py --verbose --target-cuda
182+
183+
Alternatively, you can use the ``DPCTL_TARGET_CUDA`` CMake option:
171184

172185
.. code-block:: bash
173186
174187
python scripts/build_locally.py --verbose --cmake-opts="-DDPCTL_TARGET_CUDA=sm_80"
175188
176-
To use the default architecture (``sm_50``),
189+
To use the default architecture (``sm_50``) with CMake options,
177190
set ``DPCTL_TARGET_CUDA`` to a value such as ``ON``, ``TRUE``, ``YES``, ``Y``, or ``1``:
178191

179192
.. code-block:: bash
@@ -192,12 +205,11 @@ Compute Capabilities can be found in the official
192205
AMD build
193206
~~~~~~~~~
194207

195-
``dpctl`` can be built for AMD devices using the ``DPCTL_TARGET_HIP`` CMake option,
196-
which requires specifying a compute architecture string:
208+
``dpctl`` can be built for AMD devices using the ``--target-hip`` argument.
197209

198210
.. code-block:: bash
199211
200-
python scripts/build_locally.py --verbose --cmake-opts="-DDPCTL_TARGET_HIP=<arch>"
212+
python scripts/build_locally.py --verbose --target-hip=<arch>
201213
202214
Note that the `oneAPI for AMD GPUs` plugin requires the architecture be specified and only
203215
one architecture can be specified at a time.
@@ -208,11 +220,17 @@ To determine the architecture code (``<arch>``) for your AMD GPU, run:
208220
rocminfo | grep 'Name: *gfx.*'
209221
210222
This will print names like ``gfx90a``, ``gfx1030``, etc.
211-
You can then use one of them as the argument to ``-DDPCTL_TARGET_HIP``.
223+
You can then use one of them as the argument to ``--target-hip``.
212224

213225
For example:
214226

215227
.. code-block:: bash
228+
python scripts/build_locally.py --verbose --target-hip=gfx1030
229+
230+
Alternatively, you can use the ``DPCTL_TARGET_HIP`` CMake option:
231+
232+
.. code-block:: bash
233+
216234
python scripts/build_locally.py --verbose --cmake-opts="-DDPCTL_TARGET_HIP=gfx1030"
217235
218236
Multi-target build
@@ -225,8 +243,7 @@ devices at the same time:
225243

226244
.. code-block:: bash
227245
228-
python scripts/build_locally.py --verbose --cmake-opts="-DDPCTL_TARGET_CUDA=ON \
229-
-DDPCTL_TARGET_HIP=gfx1030"
246+
python scripts/build_locally.py --verbose --target-cuda --target-hip=gfx1030
230247
231248
Running Examples and Tests
232249
==========================

scripts/build_locally.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def run(
3030
use_glog=False,
3131
verbose=False,
3232
cmake_opts="",
33+
target_cuda=None,
34+
target_hip=None,
3335
):
3436
build_system = None
3537

@@ -65,6 +67,35 @@ def run(
6567
]
6668
if cmake_opts:
6769
cmake_args += cmake_opts.split()
70+
if target_cuda is not None:
71+
if not target_cuda.strip():
72+
raise ValueError(
73+
"--target-cuda can not be an empty string. "
74+
"Use --target-cuda=<arch> or --target-cuda"
75+
)
76+
if any(opt.startswith("-DDPCTL_TARGET_CUDA=") for opt in cmake_args):
77+
raise ValueError(
78+
"Both --target-cuda and -DDPCTL_TARGET_CUDA in --cmake-opts "
79+
"were specified. Please use only one method "
80+
"to avoid ambiguity"
81+
)
82+
cmake_args += [
83+
f"-DDPCTL_TARGET_CUDA={target_cuda}",
84+
]
85+
if target_hip is not None:
86+
if not target_hip.strip():
87+
raise ValueError(
88+
"--target-hip requires an architecture (e.g., gfx90a)"
89+
)
90+
if any(opt.startswith("-DDPCTL_TARGET_HIP=") for opt in cmake_args):
91+
raise ValueError(
92+
"Both --target-hip and -DDPCTL_TARGET_HIP in --cmake-opts "
93+
"were specified. Please use only one method "
94+
"to avoid ambiguity"
95+
)
96+
cmake_args += [
97+
f"-DDPCTL_TARGET_HIP={target_hip}",
98+
]
6899
subprocess.check_call(
69100
cmake_args, shell=False, cwd=setup_dir, env=os.environ
70101
)
@@ -131,6 +162,22 @@ def run(
131162
default="",
132163
type=str,
133164
)
165+
driver.add_argument(
166+
"--target-cuda",
167+
nargs="?",
168+
const="ON",
169+
help="Enable CUDA target for build; "
170+
"optionally specify architecture (e.g., --target-cuda=sm_80)",
171+
default=None,
172+
type=str,
173+
)
174+
driver.add_argument(
175+
"--target-hip",
176+
required=False,
177+
help="Enable HIP target for build. "
178+
"Must specify HIP architecture (e.g., --target-hip=gfx90a)",
179+
type=str,
180+
)
134181
args = parser.parse_args()
135182

136183
args_to_validate = [
@@ -186,4 +233,6 @@ def run(
186233
use_glog=args.glog,
187234
verbose=args.verbose,
188235
cmake_opts=args.cmake_opts,
236+
target_cuda=args.target_cuda,
237+
target_hip=args.target_hip,
189238
)

0 commit comments

Comments
 (0)