Skip to content

Commit e213fe2

Browse files
authored
[SYCL][CUDA][HIP] Deprecate context interop for CUDA and HIP (#10975)
The `sycl::context` does not map clearly to a native context for CUDA and HIP backends. This is especially true now that we are adding support for multi device context #10737 . It would be good to start this deprecation process. PRs to oneMKL and oneDNN to follow
1 parent 803a77f commit e213fe2

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

sycl/include/sycl/backend.hpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,42 @@ get_native<backend::ext_oneapi_cuda, device>(const device &Obj) {
213213
return static_cast<backend_return_t<backend::ext_oneapi_cuda, device>>(
214214
Obj.getNative());
215215
}
216-
#endif
216+
217+
#ifndef SYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL
218+
template <>
219+
__SYCL_DEPRECATED(
220+
"Context interop is deprecated for CUDA. If a native context is required,"
221+
" use cuDevicePrimaryCtxRetain with a native device")
222+
inline backend_return_t<backend::ext_oneapi_cuda, context> get_native<
223+
backend::ext_oneapi_cuda, context>(const context &Obj) {
224+
if (Obj.get_backend() != backend::ext_oneapi_cuda) {
225+
throw sycl::exception(make_error_code(errc::backend_mismatch),
226+
"Backends mismatch");
227+
}
228+
return reinterpret_cast<backend_return_t<backend::ext_oneapi_cuda, context>>(
229+
Obj.getNative());
230+
}
231+
232+
#endif // SYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL
233+
#endif // SYCL_EXT_ONEAPI_BACKEND_CUDA
234+
235+
#if SYCL_EXT_ONEAPI_BACKEND_HIP
236+
237+
template <>
238+
__SYCL_DEPRECATED(
239+
"Context interop is deprecated for HIP. If a native context is required,"
240+
" use hipDevicePrimaryCtxRetain with a native device")
241+
inline backend_return_t<backend::ext_oneapi_hip, context> get_native<
242+
backend::ext_oneapi_hip, context>(const context &Obj) {
243+
if (Obj.get_backend() != backend::ext_oneapi_hip) {
244+
throw sycl::exception(make_error_code(errc::backend_mismatch),
245+
"Backends mismatch");
246+
}
247+
return reinterpret_cast<backend_return_t<backend::ext_oneapi_hip, context>>(
248+
Obj.getNative());
249+
}
250+
251+
#endif // SYCL_EXT_ONEAPI_BACKEND_HIP
217252

218253
template <backend BackendName, typename DataT, int Dimensions,
219254
access::mode AccessMode, access::target AccessTarget,

sycl/test/basic_tests/interop-cuda.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
/// Also test the experimental CUDA interop interface
66
// RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note -DSYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL %s
77
// RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note -D__SYCL_INTERNAL_API -DSYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL %s
8-
// expected-no-diagnostics
98

109
// Test for legacy and experimental CUDA interop API
1110

1211
#ifdef SYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL
12+
// expected-no-diagnostics
1313
#include <sycl/ext/oneapi/experimental/backend/cuda.hpp>
1414
#endif
1515

@@ -59,6 +59,9 @@ int main() {
5959
// backend-defined and specified in the backend specification.
6060

6161
cu_device = get_native<backend::ext_oneapi_cuda>(Device);
62+
#ifndef SYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL
63+
// expected-warning@+2{{'get_native<sycl::backend::ext_oneapi_cuda, sycl::context>' is deprecated: Context interop is deprecated for CUDA. If a native context is required, use cuDevicePrimaryCtxRetain with a native device}}
64+
#endif
6265
cu_context = get_native<backend::ext_oneapi_cuda>(Context);
6366
cu_event = get_native<backend::ext_oneapi_cuda>(Event);
6467
cu_queue = get_native<backend::ext_oneapi_cuda>(Queue);

sycl/test/basic_tests/interop-hip.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// REQUIRES: hip_be
22
// RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note %s
33
// RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note -D__SYCL_INTERNAL_API %s
4-
// expected-no-diagnostics
54

65
// Test for HIP interop API
76

@@ -52,6 +51,7 @@ int main() {
5251
// backend-defined and specified in the backend specification.
5352

5453
hip_device = get_native<backend::ext_oneapi_hip>(Device);
54+
// expected-warning@+1{{'get_native<sycl::backend::ext_oneapi_hip, sycl::context>' is deprecated: Context interop is deprecated for HIP. If a native context is required, use hipDevicePrimaryCtxRetain with a native device}}
5555
hip_context = get_native<backend::ext_oneapi_hip>(Context);
5656
hip_event = get_native<backend::ext_oneapi_hip>(Event);
5757
hip_queue = get_native<backend::ext_oneapi_hip>(Queue);

0 commit comments

Comments
 (0)