Skip to content

Commit 449670e

Browse files
committed
Implement HIP backend
1 parent 33d587c commit 449670e

17 files changed

+49
-3
lines changed

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

dpctl/enum_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class backend_type(Enum):
6969

7070
all = auto()
7171
cuda = auto()
72+
hip = auto()
7273
level_zero = auto()
7374
opencl = auto()
7475

dpctl/tests/test_sycl_device_factory.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def string_to_device_type(dty_str):
6060
def string_to_backend_type(bty_str):
6161
if bty_str == "cuda":
6262
return bty.cuda
63+
elif bty_str == "hip":
64+
return bty.hip
6365
elif bty_str == "host":
6466
return bty.host
6567
elif bty_str == "level_zero":

libsyclinterface/helper/source/dpctl_utils_helper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ backend DPCTL_DPCTLBackendTypeToSyclBackend(DPCTLSyclBackendType BeTy)
9494
return backend::opencl;
9595
case DPCTLSyclBackendType::DPCTL_ALL_BACKENDS:
9696
return backend::all;
97+
case DPCTLSyclBackendType::DPCTL_HIP:
98+
return backend::ext_oneapi_hip;
9799
default:
98100
throw std::runtime_error("Unsupported backend type");
99101
}
@@ -108,6 +110,8 @@ DPCTLSyclBackendType DPCTL_SyclBackendToDPCTLBackendType(backend B)
108110
return DPCTLSyclBackendType::DPCTL_LEVEL_ZERO;
109111
case backend::opencl:
110112
return DPCTLSyclBackendType::DPCTL_OPENCL;
113+
case backend::ext_oneapi_hip:
114+
return DPCTLSyclBackendType::DPCTL_HIP;
111115
default:
112116
return DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND;
113117
}
@@ -467,6 +471,9 @@ std::string DPCTL_GetDeviceFilterString(const device &Device)
467471
case backend::opencl:
468472
ss << "opencl";
469473
break;
474+
case backend::ext_oneapi_hip:
475+
ss << "hip";
476+
break;
470477
default:
471478
ss << "unknown";
472479
};

libsyclinterface/include/syclinterface/dpctl_sycl_enum_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ typedef enum
5454
DPCTL_LEVEL_ZERO = 1 << 17,
5555
DPCTL_OPENCL = 1 << 18,
5656
DPCTL_UNKNOWN_BACKEND = 0,
57-
DPCTL_ALL_BACKENDS = ((1<<5)-1) << 16
57+
DPCTL_ALL_BACKENDS = ((1<<5)-1) << 16,
58+
DPCTL_HIP = 1 << 19,
5859
// clang-format on
5960
} DPCTLSyclBackendType;
6061

0 commit comments

Comments
 (0)