From baf153cc0943b943f346ba161a3582109557806a Mon Sep 17 00:00:00 2001 From: Sergey V Maslov Date: Mon, 13 Sep 2021 20:30:24 -0700 Subject: [PATCH 1/2] [SYCL][L0] Rewrite interop test with new API Signed-off-by: Sergey V Maslov --- SYCL/Plugin/interop-level-zero.cpp | 47 +++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/SYCL/Plugin/interop-level-zero.cpp b/SYCL/Plugin/interop-level-zero.cpp index dbad7c95ca..47f37d6d70 100644 --- a/SYCL/Plugin/interop-level-zero.cpp +++ b/SYCL/Plugin/interop-level-zero.cpp @@ -7,22 +7,25 @@ #include // clang-format off #include -#include +#include // clang-format on using namespace cl::sycl; int main() { queue Queue{}; + + auto Event = Queue.single_task([=]() {}); auto Context = Queue.get_info(); auto Device = Queue.get_info(); auto Platform = Device.get_info(); // Get native Level Zero handles - auto ZePlatform = Platform.get_native(); - auto ZeDevice = Device.get_native(); - auto ZeContext = Context.get_native(); - auto ZeQueue = Queue.get_native(); + auto ZePlatform = get_native(Platform); + auto ZeDevice = get_native(Device); + auto ZeContext = get_native(Context); + auto ZeQueue = get_native(Queue); + auto ZeEvent = get_native(Event); // Create native Level-Zero context. // It then will be owned/destroyed by SYCL RT. @@ -32,17 +35,33 @@ int main() { zeContextCreate(ZePlatform, &ZeContextDesc, &ZeContextInterop); // Re-create SYCL objects from native Level Zero handles - auto PlatformInterop = level_zero::make(ZePlatform); - auto DeviceInterop = level_zero::make(PlatformInterop, ZeDevice); - auto ContextInterop = level_zero::make(PlatformInterop.get_devices(), - ZeContextInterop); - auto QueueInterop = level_zero::make(ContextInterop, ZeQueue); + auto PlatformInterop = + make_platform(ZePlatform); + auto DeviceInterop = make_device(ZeDevice); + + backend_input_t ContextInteropInput = + {ZeContextInterop, Context.get_devices()}; + auto ContextInterop = + make_context(ContextInteropInput); + + backend_input_t QueueInteropInput = { + ZeQueue}; + auto QueueInterop = make_queue( + QueueInteropInput, ContextInterop); + + backend_input_t EventInteropInput = { + ZeEvent}; + auto EventInterop = make_event( + EventInteropInput, ContextInterop); // Check native handles - assert(ZePlatform == PlatformInterop.get_native()); - assert(ZeDevice == DeviceInterop.get_native()); - assert(ZeContextInterop == ContextInterop.get_native()); - assert(ZeQueue == QueueInterop.get_native()); + assert(ZePlatform == + get_native(PlatformInterop)); + assert(ZeDevice == get_native(DeviceInterop)); + assert(ZeContextInterop == + get_native(ContextInterop)); + assert(ZeQueue == get_native(QueueInterop)); + assert(ZeEvent == get_native(EventInterop)); // Verify re-created objects int Arr[] = {2}; From 5e7a173ffd6ca6208bb7ea74eac5eaf43ace96c3 Mon Sep 17 00:00:00 2001 From: Sergey V Maslov Date: Wed, 15 Sep 2021 09:05:44 -0700 Subject: [PATCH 2/2] address review comments Signed-off-by: Sergey V Maslov --- SYCL/Plugin/interop-level-zero.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/SYCL/Plugin/interop-level-zero.cpp b/SYCL/Plugin/interop-level-zero.cpp index 47f37d6d70..e37327a81c 100644 --- a/SYCL/Plugin/interop-level-zero.cpp +++ b/SYCL/Plugin/interop-level-zero.cpp @@ -13,6 +13,7 @@ using namespace cl::sycl; int main() { +#ifdef SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO queue Queue{}; auto Event = Queue.single_task([=]() {}); @@ -73,6 +74,9 @@ int main() { }); } assert(Arr[0] == 6); - +#else + std::cout << "Test skipped due to missing support for Level-Zero backend." + << std::endl; +#endif return 0; }