diff --git a/sycl/include/sycl/backend.hpp b/sycl/include/sycl/backend.hpp index c47f077b4319a..667d5377b62fb 100644 --- a/sycl/include/sycl/backend.hpp +++ b/sycl/include/sycl/backend.hpp @@ -213,7 +213,42 @@ get_native(const device &Obj) { return static_cast>( Obj.getNative()); } -#endif + +#ifndef SYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL +template <> +__SYCL_DEPRECATED( + "Context interop is deprecated for CUDA. If a native context is required," + " use cuDevicePrimaryCtxRetain with a native device") +inline backend_return_t get_native< + backend::ext_oneapi_cuda, context>(const context &Obj) { + if (Obj.get_backend() != backend::ext_oneapi_cuda) { + throw sycl::exception(make_error_code(errc::backend_mismatch), + "Backends mismatch"); + } + return reinterpret_cast>( + Obj.getNative()); +} + +#endif // SYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL +#endif // SYCL_EXT_ONEAPI_BACKEND_CUDA + +#if SYCL_EXT_ONEAPI_BACKEND_HIP + +template <> +__SYCL_DEPRECATED( + "Context interop is deprecated for HIP. If a native context is required," + " use hipDevicePrimaryCtxRetain with a native device") +inline backend_return_t get_native< + backend::ext_oneapi_hip, context>(const context &Obj) { + if (Obj.get_backend() != backend::ext_oneapi_hip) { + throw sycl::exception(make_error_code(errc::backend_mismatch), + "Backends mismatch"); + } + return reinterpret_cast>( + Obj.getNative()); +} + +#endif // SYCL_EXT_ONEAPI_BACKEND_HIP template #endif @@ -59,6 +59,9 @@ int main() { // backend-defined and specified in the backend specification. cu_device = get_native(Device); +#ifndef SYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL + // expected-warning@+2{{'get_native' is deprecated: Context interop is deprecated for CUDA. If a native context is required, use cuDevicePrimaryCtxRetain with a native device}} +#endif cu_context = get_native(Context); cu_event = get_native(Event); cu_queue = get_native(Queue); diff --git a/sycl/test/basic_tests/interop-hip.cpp b/sycl/test/basic_tests/interop-hip.cpp index 579139ff4300b..ea249d092d471 100644 --- a/sycl/test/basic_tests/interop-hip.cpp +++ b/sycl/test/basic_tests/interop-hip.cpp @@ -1,7 +1,6 @@ // REQUIRES: hip_be // RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note %s // RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note -D__SYCL_INTERNAL_API %s -// expected-no-diagnostics // Test for HIP interop API @@ -52,6 +51,7 @@ int main() { // backend-defined and specified in the backend specification. hip_device = get_native(Device); + // expected-warning@+1{{'get_native' is deprecated: Context interop is deprecated for HIP. If a native context is required, use hipDevicePrimaryCtxRetain with a native device}} hip_context = get_native(Context); hip_event = get_native(Event); hip_queue = get_native(Queue);