Skip to content

Commit eefc82b

Browse files
authored
Merge pull request #1731 from IntelPython/feature/enable-amd-builds
Enable building to target AMD GPUs
2 parents ea6ae0b + c316380 commit eefc82b

26 files changed

+128
-46
lines changed

CMakeLists.txt

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,64 @@ option(DPCTL_TARGET_CUDA
2929
"Build DPCTL to target CUDA devices"
3030
OFF
3131
)
32+
set(DPCTL_TARGET_HIP
33+
""
34+
CACHE STRING
35+
"Build DPCTL to target a HIP device architecture"
36+
)
3237
option(DPCTL_WITH_REDIST "Build DPCTL assuming DPC++ redistributable is installed into Python prefix" OFF)
3338

3439
find_package(IntelSYCL REQUIRED PATHS ${CMAKE_SOURCE_DIR}/cmake NO_DEFAULT_PATH)
3540

41+
set(_dpctl_sycl_target_compile_options)
42+
set(_dpctl_sycl_target_link_options)
43+
3644
set(_dpctl_sycl_targets)
45+
set(_dpctl_amd_targets)
3746
if ("x${DPCTL_SYCL_TARGETS}" STREQUAL "x")
38-
if(DPCTL_TARGET_CUDA)
47+
if (DPCTL_TARGET_CUDA)
3948
set(_dpctl_sycl_targets "nvptx64-nvidia-cuda,spir64-unknown-unknown")
4049
else()
41-
if(DEFINED ENV{DPCTL_TARGET_CUDA})
50+
if (DEFINED ENV{DPCTL_TARGET_CUDA})
4251
set(_dpctl_sycl_targets "nvptx64-nvidia-cuda,spir64-unknown-unknown")
4352
endif()
4453
endif()
54+
if (NOT "x${DPCTL_TARGET_HIP}" STREQUAL "x")
55+
set(_dpctl_amd_targets ${DPCTL_TARGET_HIP})
56+
if(_dpctl_sycl_targets)
57+
set(_dpctl_sycl_targets "amdgcn-amd-amdhsa,${_dpctl_sycl_targets}")
58+
else()
59+
set(_dpctl_sycl_targets "amdgcn-amd-amdhsa,spir64-unknown-unknown")
60+
endif()
61+
else()
62+
if (DEFINED ENV{DPCTL_TARGET_HIP})
63+
set(_dpctl_amd_targets $ENV{DPCTL_TARGET_HIP})
64+
if(_dpctl_sycl_targets)
65+
set(_dpctl_sycl_targets "amdgcn-amd-amdhsa,${_dpctl_sycl_targets}")
66+
else()
67+
set(_dpctl_sycl_targets "amdgcn-amd-amdhsa,spir64-unknown-unknown")
68+
endif()
69+
endif()
70+
endif()
4571
else()
4672
set(_dpctl_sycl_targets ${DPCTL_SYCL_TARGETS})
73+
if (NOT "x${DPCTL_TARGET_HIP}" STREQUAL "x")
74+
set(_dpctl_amd_targets ${DPCTL_TARGET_HIP})
75+
else()
76+
if (DEFINED ENV{DPCTL_TARGET_HIP})
77+
set(_dpctl_amd_targets $ENV{DPCTL_TARGET_HIP})
78+
endif()
79+
endif()
4780
endif()
4881

49-
if(_dpctl_sycl_targets)
82+
if (_dpctl_sycl_targets)
5083
message(STATUS "Compiling for -fsycl-targets=${_dpctl_sycl_targets}")
84+
list(APPEND _dpctl_sycl_target_compile_options -fsycl-targets=${_dpctl_sycl_targets})
85+
list(APPEND _dpctl_sycl_target_link_options -fsycl-targets=${_dpctl_sycl_targets})
86+
if(_dpctl_amd_targets)
87+
list(APPEND _dpctl_sycl_target_compile_options -Xsycl-target-backend=amdgcn-amd-amdhsa --offload-arch=${_dpctl_amd_targets})
88+
list(APPEND _dpctl_sycl_target_link_options -Xsycl-target-backend=amdgcn-amd-amdhsa --offload-arch=${_dpctl_amd_targets})
89+
endif()
5190
endif()
5291

5392
add_subdirectory(libsyclinterface)

docs/doc_sources/beginners_guides/installation.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,28 @@ The following plugins from CodePlay are supported:
158158
.. _codeplay_nv_plugin: https://developer.codeplay.com/products/oneapi/nvidia/
159159
.. _codeplay_amd_plugin: https://developer.codeplay.com/products/oneapi/amd/
160160

161-
Build ``dpctl`` as follows:
161+
``dpctl`` can be built for CUDA devices as follows:
162162

163163
.. code-block:: bash
164164
165165
python scripts/build_locally.py --verbose --cmake-opts="-DDPCTL_TARGET_CUDA=ON"
166166
167+
And for AMD devices
168+
169+
.. code-block:: bash
170+
171+
python scripts/build_locally.py --verbose --cmake-opts="-DDPCTL_TARGET_HIP=gfx1030"
172+
173+
Note that the `oneAPI for AMD GPUs` plugin requires the architecture be specified and only
174+
one architecture can be specified at a time.
175+
176+
It is, however, possible to build for Intel devices, CUDA devices, and an AMD device
177+
architecture all at once:
178+
179+
.. code-block:: bash
180+
181+
python scripts/build_locally.py --verbose --cmake-opts="-DDPCTL_TARGET_CUDA=ON \
182+
-DDPCTL_TARGET_HIP=gfx1030"
167183
168184
Running Examples and Tests
169185
==========================

docs/doc_sources/beginners_guides/managing_devices.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ of valid settings are:
123123
* - ``cuda:*``
124124
- All devices only from CUDA backend are available
125125
126+
* - ``hip:*``
127+
- All devices only from HIP backend are available
128+
126129
* - ``level_zero:0,1``
127130
- Two specific devices from Level-Zero backend are available
128131

dpctl/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ function(build_dpctl_ext _trgt _src _dest)
116116
target_compile_options(
117117
${_trgt}
118118
PRIVATE
119-
-fsycl-targets=${_dpctl_sycl_targets}
119+
${_dpctl_sycl_target_compile_options}
120120
)
121121
target_link_options(
122122
${_trgt}
123123
PRIVATE
124-
-fsycl-targets=${_dpctl_sycl_targets}
124+
${_dpctl_sycl_target_link_options}
125125
)
126126
endif()
127127
endif()

dpctl/_backend.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ cdef extern from "syclinterface/dpctl_sycl_enum_types.h":
4343
ctypedef enum _backend_type 'DPCTLSyclBackendType':
4444
_ALL_BACKENDS 'DPCTL_ALL_BACKENDS'
4545
_CUDA 'DPCTL_CUDA'
46+
_HIP 'DPCTL_HIP'
4647
_LEVEL_ZERO 'DPCTL_LEVEL_ZERO'
4748
_OPENCL 'DPCTL_OPENCL'
4849
_UNKNOWN_BACKEND 'DPCTL_UNKNOWN_BACKEND'

dpctl/_sycl_device.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ cdef list _get_devices(DPCTLDeviceVectorRef DVRef):
172172
cdef str _backend_type_to_filter_string_part(_backend_type BTy):
173173
if BTy == _backend_type._CUDA:
174174
return "cuda"
175+
elif BTy == _backend_type._HIP:
176+
return "hip"
175177
elif BTy == _backend_type._LEVEL_ZERO:
176178
return "level_zero"
177179
elif BTy == _backend_type._OPENCL:
@@ -425,6 +427,8 @@ cdef class SyclDevice(_SyclDevice):
425427
)
426428
if BTy == _backend_type._CUDA:
427429
return backend_type.cuda
430+
elif BTy == _backend_type._HIP:
431+
return backend_type.hip
428432
elif BTy == _backend_type._LEVEL_ZERO:
429433
return backend_type.level_zero
430434
elif BTy == _backend_type._OPENCL:

dpctl/_sycl_device_factory.pyx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ cdef _backend_type _string_to_dpctl_sycl_backend_ty(str backend_str):
7171
return _backend_type._ALL_BACKENDS
7272
elif backend_str == "cuda":
7373
return _backend_type._CUDA
74+
elif backend_str == "hip":
75+
return _backend_type._HIP
7476
elif backend_str == "level_zero":
7577
return _backend_type._LEVEL_ZERO
7678
elif backend_str == "opencl":
@@ -100,6 +102,8 @@ cdef _device_type _string_to_dpctl_sycl_device_ty(str dty_str):
100102
cdef _backend_type _enum_to_dpctl_sycl_backend_ty(BTy):
101103
if BTy == backend_type.all:
102104
return _backend_type._ALL_BACKENDS
105+
elif BTy == backend_type.hip:
106+
return _backend_type._HIP
103107
elif BTy == backend_type.cuda:
104108
return _backend_type._CUDA
105109
elif BTy == backend_type.level_zero:
@@ -153,7 +157,7 @@ cpdef list get_devices(backend=backend_type.all, device_type=device_type_t.all):
153157
backend (optional):
154158
A :class:`dpctl.backend_type` enum value or a string that
155159
specifies a SYCL backend. Currently, accepted values are: "cuda",
156-
"opencl", "level_zero", or "all".
160+
"hip", "opencl", "level_zero", or "all".
157161
Default: ``dpctl.backend_type.all``.
158162
device_type (optional):
159163
A :class:`dpctl.device_type` enum value or a string that
@@ -209,7 +213,7 @@ cpdef int get_num_devices(
209213
backend (optional):
210214
A :class:`dpctl.backend_type` enum value or a string that
211215
specifies a SYCL backend. Currently, accepted values are: "cuda",
212-
"opencl", "level_zero", or "all".
216+
"hip", "opencl", "level_zero", or "all".
213217
Default: ``dpctl.backend_type.all``.
214218
device_type (optional):
215219
A :class:`dpctl.device_type` enum value or a string that

dpctl/_sycl_event.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ cdef class SyclEvent(_SyclEvent):
333333
return backend_type.level_zero
334334
elif BE == _backend_type._CUDA:
335335
return backend_type.cuda
336+
elif BE == _backend_type._HIP:
337+
return backend_type.hip
336338
else:
337339
raise ValueError("Unknown backend type.")
338340

dpctl/_sycl_platform.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ cdef class SyclPlatform(_SyclPlatform):
294294
)
295295
if BTy == _backend_type._CUDA:
296296
return backend_type.cuda
297+
elif BTy == _backend_type._HIP:
298+
return backend_type.hip
297299
elif BTy == _backend_type._LEVEL_ZERO:
298300
return backend_type.level_zero
299301
elif BTy == _backend_type._OPENCL:

dpctl/_sycl_queue.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,8 @@ cdef class SyclQueue(_SyclQueue):
886886
return backend_type.level_zero
887887
elif BE == _backend_type._CUDA:
888888
return backend_type.cuda
889+
elif BE == _backend_type._HIP:
890+
return backend_type.hip
889891
else:
890892
raise ValueError("Unknown backend type.")
891893

0 commit comments

Comments
 (0)