Skip to content

[SYCL] Added test-e2e for queue, device, and event interop. #11292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions sycl/test-e2e/Basic/interop/interop_all_backends.cpp
Original file line number Diff line number Diff line change
@@ -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 <sycl/sycl.hpp>
using namespace sycl;

#ifdef SYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL
#include <sycl/ext/oneapi/experimental/backend/cuda.hpp>
constexpr auto BACKEND = backend::ext_oneapi_cuda;
using nativeDevice = CUdevice;
using nativeQueue = CUstream;
using nativeEvent = CUevent;
#elif defined(SYCL_EXT_ONEAPI_BACKEND_HIP)
#include <sycl/ext/oneapi/backend/hip.hpp>
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<bool>(
std::is_same_v<backend_traits<BACKEND>::return_type<device>,
nativeDevice>));
assert(static_cast<bool>(
std::is_same_v<backend_traits<BACKEND>::return_type<queue>,
nativeQueue>));
assert(static_cast<bool>(
std::is_same_v<backend_traits<BACKEND>::return_type<event>,
nativeEvent>));

device Device;
backend_traits<BACKEND>::return_type<device> NativeDevice =
get_native<BACKEND>(Device);
// Create sycl device with a native device.
auto InteropDevice = make_device<BACKEND>(NativeDevice);

context Context(InteropDevice);

// Create sycl queue with device created from a native device.
queue Queue(InteropDevice, {sycl::property::queue::in_order()});
backend_traits<BACKEND>::return_type<queue> NativeQueue =
get_native<BACKEND>(Queue);
auto InteropQueue = make_queue<BACKEND>(NativeQueue, Context);

auto A = (int *)malloc_device(N * sizeof(int), InteropQueue);
std::vector<int> vec(N, 0);

auto Event = Queue.submit([&](handler &h) {
h.parallel_for<class kern1>(range<1>(N),
[=](id<1> item) { A[item] = VAL; });
});

backend_traits<BACKEND>::return_type<event> NativeEvent =
get_native<BACKEND>(Event);
// Create sycl event with a native event.
event InteropEvent = make_event<BACKEND>(NativeEvent, Context);

// depends_on sycl event created from a native event.
auto Event2 = InteropQueue.submit([&](handler &h) {
h.depends_on(InteropEvent);
h.parallel_for<class kern2>(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;
}