Skip to content

Commit 7625b60

Browse files
author
Hugh Delaney
committed
Deprecate context interop for CUDA and HIP
1 parent 5e9d07b commit 7625b60

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

sycl/include/sycl/backend.hpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,74 @@ 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+
217+
template <>
218+
__SYCL_DEPRECATED(
219+
"Context interop is deprecated for CUDA. If a native context is required,"
220+
" use cuDevicePrimaryCtxRetain with a native device")
221+
inline backend_return_t<backend::ext_oneapi_cuda, context> get_native<
222+
backend::ext_oneapi_cuda, context>(const context &Obj) {
223+
if (Obj.get_backend() != backend::ext_oneapi_cuda) {
224+
throw sycl::exception(make_error_code(errc::backend_mismatch),
225+
"Backends mismatch");
226+
}
227+
return reinterpret_cast<backend_return_t<backend::ext_oneapi_cuda, context>>(
228+
Obj.getNative());
229+
}
230+
231+
template <>
232+
__SYCL_DEPRECATED("Context interop is deprecated for CUDA. If a native context"
233+
" is required, use cuDevicePrimaryCtxRetain with a native"
234+
" device")
235+
inline backend_return_t<backend::ext_oneapi_cuda, context> interop_handle::
236+
get_native_context<backend::ext_oneapi_cuda>() const {
237+
if (get_backend() != backend::ext_oneapi_cuda) {
238+
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
239+
PI_ERROR_INVALID_OPERATION);
240+
}
241+
#ifndef __SYCL_DEVICE_ONLY__
242+
return reinterpret_cast<backend_return_t<backend::ext_oneapi_cuda, context>>(
243+
getNativeContext());
244+
#else
245+
return 0;
246+
#endif
247+
}
248+
249+
#endif
250+
#if SYCL_EXT_ONEAPI_BACKEND_HIP
251+
252+
template <>
253+
__SYCL_DEPRECATED(
254+
"Context interop is deprecated for HIP. If a native context is required,"
255+
" use hipDevicePrimaryCtxRetain with a native device")
256+
inline backend_return_t<backend::ext_oneapi_hip, context> get_native<
257+
backend::ext_oneapi_hip, context>(const context &Obj) {
258+
if (Obj.get_backend() != backend::ext_oneapi_hip) {
259+
throw sycl::exception(make_error_code(errc::backend_mismatch),
260+
"Backends mismatch");
261+
}
262+
return reinterpret_cast<backend_return_t<backend::ext_oneapi_hip, context>>(
263+
Obj.getNative());
264+
}
265+
266+
template <>
267+
__SYCL_DEPRECATED("Context interop is deprecated for HIP. If a native context"
268+
" is required, use hipDevicePrimaryCtxRetain with a native"
269+
" device")
270+
inline backend_return_t<backend::ext_oneapi_hip, context> interop_handle::
271+
get_native_context<backend::ext_oneapi_hip>() const {
272+
if (get_backend() != backend::ext_oneapi_hip) {
273+
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
274+
PI_ERROR_INVALID_OPERATION);
275+
}
276+
#ifndef __SYCL_DEVICE_ONLY__
277+
return reinterpret_cast<backend_return_t<backend::ext_oneapi_hip, context>>(
278+
getNativeContext());
279+
#else
280+
return 0;
281+
#endif
282+
}
283+
216284
#endif
217285

218286
template <backend BackendName, typename DataT, int Dimensions,

sycl/include/sycl/ext/oneapi/experimental/backend/cuda.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ inline __SYCL_EXPORT bool has_native_event(event sycl_event) {
3535

3636
// CUDA context specialization
3737
template <>
38+
__SYCL_DEPRECATED(
39+
"Context interop is deprecated for CUDA. If a native context is required,"
40+
" use cuDevicePrimaryCtxRetain with a native device")
3841
inline auto get_native<backend::ext_oneapi_cuda, context>(const context &C)
3942
-> backend_return_t<backend::ext_oneapi_cuda, context> {
4043
// create a vector to be returned
@@ -51,8 +54,11 @@ inline auto get_native<backend::ext_oneapi_cuda, context>(const context &C)
5154

5255
// Specialisation of interop_handles get_native_context
5356
template <>
54-
inline backend_return_t<backend::ext_oneapi_cuda, context>
55-
interop_handle::get_native_context<backend::ext_oneapi_cuda>() const {
57+
__SYCL_DEPRECATED(
58+
"Context interop is deprecated for CUDA. If a native context is required,"
59+
" use cuDevicePrimaryCtxRetain with a native device")
60+
inline backend_return_t<backend::ext_oneapi_cuda, context> interop_handle::
61+
get_native_context<backend::ext_oneapi_cuda>() const {
5662
#ifndef __SYCL_DEVICE_ONLY__
5763
return std::vector{reinterpret_cast<CUcontext>(getNativeContext())};
5864
#else

0 commit comments

Comments
 (0)