diff --git a/sycl/test-e2e/Basic/interop/interop_all_backends.cpp b/sycl/test-e2e/Basic/interop/interop_all_backends.cpp new file mode 100644 index 0000000000000..976dd3d941a39 --- /dev/null +++ b/sycl/test-e2e/Basic/interop/interop_all_backends.cpp @@ -0,0 +1,89 @@ +// REQUIRES: CUDA || HIP +// RUN: %{build} %if hip %{ -DSYCL_EXT_ONEAPI_BACKEND_HIP %} %else %{ %if cuda %{ -DSYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL %} %else %{ %if level_zero %{ -DSYCL_EXT_ONEAPI_BACKEND_L0 %} %} %} -o %t.out + +#include +using namespace sycl; + +#ifdef SYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL +#include +constexpr auto BACKEND = backend::ext_oneapi_cuda; +using nativeDevice = CUdevice; +using nativeQueue = CUstream; +using nativeEvent = CUevent; +#elif defined(SYCL_EXT_ONEAPI_BACKEND_HIP) +#include +constexpr auto BACKEND = backend::ext_oneapi_hip; +using nativeDevice = hipDevice_t; +using nativeQueue = hipStream_t; +using nativeEvent = hipEvent_t; +#elif defined(SYCL_EXT_ONEAPI_BACKEND_L0) +constexpr auto BACKEND = backend::ext_oneapi_level_zero; +using nativeDevice = ze_device_handle_t; +using nativeQueue = ze_command_queue_handle_t; +using nativeEvent = ze_event_handle_t; +#else +constexpr auto BACKEND = backend::opencl; +using nativeDevice = cl_device; +using nativeQueue = cl_command_queue; +using nativeEvent = cl_event; +#endif + +constexpr int N = 100; +constexpr int VAL = 3; + +int main() { + + assert(static_cast( + std::is_same_v::return_type, + nativeDevice>)); + assert(static_cast( + std::is_same_v::return_type, + nativeQueue>)); + assert(static_cast( + std::is_same_v::return_type, + nativeEvent>)); + + device Device; + backend_traits::return_type NativeDevice = + get_native(Device); + // Create sycl device with a native device. + auto InteropDevice = make_device(NativeDevice); + + context Context(InteropDevice); + + // Create sycl queue with device created from a native device. + queue Queue(InteropDevice, {sycl::property::queue::in_order()}); + backend_traits::return_type NativeQueue = + get_native(Queue); + auto InteropQueue = make_queue(NativeQueue, Context); + + auto A = (int *)malloc_device(N * sizeof(int), InteropQueue); + std::vector vec(N, 0); + + auto Event = Queue.submit([&](handler &h) { + h.parallel_for(range<1>(N), + [=](id<1> item) { A[item] = VAL; }); + }); + + backend_traits::return_type NativeEvent = + get_native(Event); + // Create sycl event with a native event. + event InteropEvent = make_event(NativeEvent, Context); + + // depends_on sycl event created from a native event. + auto Event2 = InteropQueue.submit([&](handler &h) { + h.depends_on(InteropEvent); + h.parallel_for(range<1>(N), [=](id<1> item) { A[item]++; }); + }); + + auto Event3 = InteropQueue.memcpy(&vec[0], A, N * sizeof(int), Event2); + Event3.wait(); + + free(A, InteropQueue); + + for (const auto &val : vec) { + assert(val == VAL + 1); + } + + return 0; +}