Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
26 changes: 21 additions & 5 deletions sycl/include/sycl/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,17 @@ make_queue(const typename backend_traits<Backend>::template input_type<queue>
const context &TargetContext, const async_handler Handler = {}) {
auto KeepOwnership =
Backend == backend::ext_oneapi_cuda || Backend == backend::ext_oneapi_hip;
return detail::make_queue(detail::ur::cast<ur_native_handle_t>(BackendObject),
false, TargetContext, nullptr, KeepOwnership, {},
Handler, Backend);
if constexpr (Backend == backend::ext_oneapi_level_zero) {
return detail::make_queue(
detail::ur::cast<ur_native_handle_t>(
std::get<ze_command_queue_handle_t>(BackendObject.NativeHandle)),
false, TargetContext, nullptr, KeepOwnership, {}, Handler, Backend);
}
if constexpr (Backend != backend::ext_oneapi_level_zero) {
return detail::make_queue(
detail::ur::cast<ur_native_handle_t>(BackendObject), false,
TargetContext, nullptr, KeepOwnership, {}, Handler, Backend);
}
}

template <backend Backend>
Expand All @@ -361,8 +369,16 @@ std::enable_if_t<detail::InteropFeatureSupportMap<Backend>::MakeEvent == true,
make_event(const typename backend_traits<Backend>::template input_type<event>
&BackendObject,
const context &TargetContext) {
return detail::make_event(detail::ur::cast<ur_native_handle_t>(BackendObject),
TargetContext, Backend);
if constexpr (Backend == backend::ext_oneapi_level_zero) {
return detail::make_event(
detail::ur::cast<ur_native_handle_t>(BackendObject.NativeHandle),
TargetContext, Backend);
}
if constexpr (Backend != backend::ext_oneapi_level_zero) {
return detail::make_event(
detail::ur::cast<ur_native_handle_t>(BackendObject), TargetContext,
Backend);
}
}

template <backend Backend>
Expand Down
85 changes: 85 additions & 0 deletions sycl/test-e2e/Basic/interop/Interop_level_zero_backend.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// RUN: %if any-device-is-level_zero %{ %{build} -isystem %sycl_include -DBUILD_FOR_L0 -o %t-l0.out %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is BUILD_FOR_L0 still used? I think it can be dropped, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, dropped. Thanks.


#include <sycl/backend.hpp>
#include <sycl/detail/core.hpp>
#include <sycl/properties/all_properties.hpp>
#include <sycl/usm.hpp>
using namespace sycl;

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;

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);
backend_traits<BACKEND>::input_type<queue> InputType(NativeQueue, Device);

auto InteropQueue = make_queue<BACKEND>(InputType, 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);
backend_traits<BACKEND>::input_type<event> EventInputType;
EventInputType.NativeHandle = NativeEvent;
// Create sycl event with a native event.
event InteropEvent = make_event<BACKEND>(EventInputType, 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();

if constexpr (BACKEND == backend::ext_oneapi_hip) {
try {
backend_traits<BACKEND>::return_type<context> NativeContext =
get_native<BACKEND>(Context);
} catch (sycl::exception &e) {
assert(e.code() == sycl::errc::feature_not_supported);
}
}

free(A, InteropQueue);

for (const auto &val : vec) {
assert(val == VAL + 1);
}

return 0;
}
20 changes: 7 additions & 13 deletions sycl/test-e2e/Basic/interop/interop_all_backends.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// XFAIL: any-device-is-opencl, any-device-is-cuda, any-device-is-level_zero, gpu-intel-dg2, hip_amd
// XFAIL-TRACKER: https://github.com/intel/llvm/issues/15819
// XFAIL: any-device-is-cuda
// XFAIL-TRACKER: https://github.com/intel/llvm/issues/16070
// RUN: %if any-device-is-opencl %{ %{build} -o %t-opencl.out %}
// RUN: %if any-device-is-level_zero %{ %{build} -DBUILD_FOR_L0 -o %t-l0.out %}
// RUN: %if any-device-is-cuda %{ %{build} -DBUILD_FOR_CUDA -o %t-cuda.out %}
// RUN: %if any-device-is-cuda %{ %{build} -isystem %sycl_include -DBUILD_FOR_CUDA -o %t-cuda.out %}
// RUN: %if any-device-is-hip %{ %{build} -DBUILD_FOR_HIP -o %t-hip.out %}

#include <sycl/backend.hpp>
Expand All @@ -20,17 +19,12 @@ using nativeEvent = CUevent;
#elif defined(BUILD_FOR_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(BUILD_FOR_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;
using nativeDevice = device;
using nativeQueue = ihipStream_t;
using nativeEvent = ihipEvent_t;
#else
constexpr auto BACKEND = backend::opencl;
using nativeDevice = cl_device;
using nativeDevice = cl_device_id;
using nativeQueue = cl_command_queue;
using nativeEvent = cl_event;
#endif
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// REQUIRES: ocloc, level_zero, gpu, cpu
// REQUIRES: ocloc, any-device-is-level_zero, any-device-is-gpu, any-device-is-cpu

// RUN: %clangxx -fsycl -fsycl-targets=spir64_fpga,spir64_gen -Xsycl-target-backend "-device *" %S/Inputs/is_compatible_with_env.cpp -o %t.out
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -Xsycl-target-backend=spir64_gen "-device *" %S/Inputs/is_compatible_with_env.cpp -o %t.out

// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:cpu %{run} not %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:fpga %{run} %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:gpu %{run} %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR=level_zero:gpu %{run} %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:cpu %{run-unfiltered-devices} not %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR=opencl:gpu %{run-unfiltered-devices} %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR=level_zero:gpu %{run-unfiltered-devices} %t.out
1 change: 1 addition & 0 deletions sycl/test-e2e/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"CL_CONFIG_DEVICES",
"SYCL_DEVICE_ALLOWLIST",
"SYCL_CONFIG_FILE_NAME",
"OCL_ICD_VENDORS",
]
)

Expand Down
Loading