Skip to content

Commit e9df52d

Browse files
committed
[SYCL] do not test zero level backend with other backends
1 parent f42b6b8 commit e9df52d

File tree

3 files changed

+106
-11
lines changed

3 files changed

+106
-11
lines changed

sycl/include/sycl/backend.hpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,18 @@ make_queue(const typename backend_traits<Backend>::template input_type<queue>
350350
const context &TargetContext, const async_handler Handler = {}) {
351351
auto KeepOwnership =
352352
Backend == backend::ext_oneapi_cuda || Backend == backend::ext_oneapi_hip;
353-
return detail::make_queue(detail::ur::cast<ur_native_handle_t>(BackendObject),
353+
if constexpr (Backend == backend::ext_oneapi_level_zero)
354+
{
355+
return detail::make_queue(detail::ur::cast<ur_native_handle_t>(std::get<ze_command_queue_handle_t>(BackendObject.NativeHandle)),
354356
false, TargetContext, nullptr, KeepOwnership, {},
355357
Handler, Backend);
358+
}
359+
if constexpr (Backend != backend::ext_oneapi_level_zero)
360+
{
361+
return detail::make_queue(detail::ur::cast<ur_native_handle_t>(BackendObject),
362+
false, TargetContext, nullptr, KeepOwnership, {},
363+
Handler, Backend);
364+
}
356365
}
357366

358367
template <backend Backend>
@@ -361,8 +370,16 @@ std::enable_if_t<detail::InteropFeatureSupportMap<Backend>::MakeEvent == true,
361370
make_event(const typename backend_traits<Backend>::template input_type<event>
362371
&BackendObject,
363372
const context &TargetContext) {
364-
return detail::make_event(detail::ur::cast<ur_native_handle_t>(BackendObject),
373+
if constexpr (Backend == backend::ext_oneapi_level_zero)
374+
{
375+
return detail::make_event(detail::ur::cast<ur_native_handle_t>(BackendObject.NativeHandle),
365376
TargetContext, Backend);
377+
}
378+
if constexpr (Backend != backend::ext_oneapi_level_zero)
379+
{
380+
return detail::make_event(detail::ur::cast<ur_native_handle_t>(BackendObject),
381+
TargetContext, Backend);
382+
}
366383
}
367384

368385
template <backend Backend>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// RUN: %if any-device-is-level_zero %{ %{build} -isystem %sycl_include -DBUILD_FOR_L0 -o %t-l0.out %}
2+
3+
#include <sycl/backend.hpp>
4+
#include <sycl/detail/core.hpp>
5+
#include <sycl/properties/all_properties.hpp>
6+
#include <sycl/usm.hpp>
7+
using namespace sycl;
8+
9+
constexpr auto BACKEND = backend::ext_oneapi_level_zero;
10+
using nativeDevice = ze_device_handle_t;
11+
using nativeQueue = ze_command_queue_handle_t;
12+
using nativeEvent = ze_event_handle_t;
13+
14+
constexpr int N = 100;
15+
constexpr int VAL = 3;
16+
17+
int main() {
18+
19+
assert(static_cast<bool>(
20+
std::is_same_v<backend_traits<BACKEND>::return_type<device>,
21+
nativeDevice>));
22+
assert(static_cast<bool>(
23+
std::is_same_v<backend_traits<BACKEND>::return_type<queue>,
24+
nativeQueue>));
25+
assert(static_cast<bool>(
26+
std::is_same_v<backend_traits<BACKEND>::return_type<event>,
27+
nativeEvent>));
28+
29+
device Device;
30+
backend_traits<BACKEND>::return_type<device> NativeDevice =
31+
get_native<BACKEND>(Device);
32+
// Create sycl device with a native device.
33+
auto InteropDevice = make_device<BACKEND>(NativeDevice);
34+
35+
context Context(InteropDevice);
36+
37+
// Create sycl queue with device created from a native device.
38+
queue Queue(InteropDevice, {sycl::property::queue::in_order()});
39+
backend_traits<BACKEND>::return_type<queue> NativeQueue =
40+
get_native<BACKEND>(Queue);
41+
backend_traits<BACKEND>::input_type<queue> InputType(NativeQueue, Device);
42+
43+
auto InteropQueue = make_queue<BACKEND>(InputType, Context);
44+
45+
auto A = (int *)malloc_device(N * sizeof(int), InteropQueue);
46+
std::vector<int> vec(N, 0);
47+
48+
auto Event = Queue.submit([&](handler &h) {
49+
h.parallel_for<class kern1>(range<1>(N),
50+
[=](id<1> item) { A[item] = VAL; });
51+
});
52+
53+
backend_traits<BACKEND>::return_type<event> NativeEvent =
54+
get_native<BACKEND>(Event);
55+
backend_traits<BACKEND>::input_type<event> EventInputType;
56+
EventInputType.NativeHandle = NativeEvent;
57+
// Create sycl event with a native event.
58+
event InteropEvent = make_event<BACKEND>(EventInputType, Context);
59+
60+
// depends_on sycl event created from a native event.
61+
auto Event2 = InteropQueue.submit([&](handler &h) {
62+
h.depends_on(InteropEvent);
63+
h.parallel_for<class kern2>(range<1>(N), [=](id<1> item) { A[item]++; });
64+
});
65+
66+
auto Event3 = InteropQueue.memcpy(&vec[0], A, N * sizeof(int), Event2);
67+
Event3.wait();
68+
69+
if constexpr (BACKEND == backend::ext_oneapi_hip) {
70+
try {
71+
backend_traits<BACKEND>::return_type<context> NativeContext =
72+
get_native<BACKEND>(Context);
73+
} catch (sycl::exception &e) {
74+
assert(e.code() == sycl::errc::feature_not_supported);
75+
}
76+
}
77+
78+
free(A, InteropQueue);
79+
80+
for (const auto &val : vec) {
81+
assert(val == VAL + 1);
82+
}
83+
84+
return 0;
85+
}

sycl/test-e2e/Basic/interop/interop_all_backends.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
// XFAIL: any-device-is-opencl, any-device-is-cuda, any-device-is-level_zero
2-
// XFAIL-TRACKER: https://github.com/intel/llvm/issues/15819
31
// RUN: %if any-device-is-opencl %{ %{build} -o %t-opencl.out %}
4-
// RUN: %if any-device-is-level_zero %{ %{build} -DBUILD_FOR_L0 -o %t-l0.out %}
5-
// RUN: %if any-device-is-cuda %{ %{build} -DBUILD_FOR_CUDA -o %t-cuda.out %}
2+
// RUN: %if any-device-is-cuda %{ %{build} -isystem %sycl_include -DBUILD_FOR_CUDA -o %t-cuda.out %}
63
// RUN: %if any-device-is-hip %{ %{build} -DBUILD_FOR_HIP -o %t-hip.out %}
74

85
#include <sycl/backend.hpp>
@@ -12,6 +9,7 @@
129
using namespace sycl;
1310

1411
#ifdef BUILD_FOR_CUDA
12+
#include <sycl/ext/oneapi/experimental/backend/cuda.hpp>
1513
constexpr auto BACKEND = backend::ext_oneapi_cuda;
1614
using nativeDevice = CUdevice;
1715
using nativeQueue = CUstream;
@@ -22,11 +20,6 @@ constexpr auto BACKEND = backend::ext_oneapi_hip;
2220
using nativeDevice = device;
2321
using nativeQueue = ihipStream_t;
2422
using nativeEvent = ihipEvent_t;
25-
#elif defined(BUILD_FOR_L0)
26-
constexpr auto BACKEND = backend::ext_oneapi_level_zero;
27-
using nativeDevice = ze_device_handle_t;
28-
using nativeQueue = ze_command_queue_handle_t;
29-
using nativeEvent = ze_event_handle_t;
3023
#else
3124
constexpr auto BACKEND = backend::opencl;
3225
using nativeDevice = cl_device_id;

0 commit comments

Comments
 (0)