From a00dbe2b88c14a432c0ae8844249fe29f1e6d827 Mon Sep 17 00:00:00 2001 From: rehana begam Date: Tue, 6 Jul 2021 14:33:27 -0700 Subject: [PATCH 01/11] [SYCL] Add Level-Zero interop with specification of ownership for Queue. Signed-off-by: rehana begam --- sycl/doc/extensions/LevelZeroBackend/LevelZeroBackend.md | 4 ++-- sycl/include/CL/sycl/backend.hpp | 1 + sycl/include/CL/sycl/backend/level_zero.hpp | 9 ++++++--- sycl/include/CL/sycl/detail/pi.h | 9 ++++++--- sycl/plugins/cuda/pi_cuda.cpp | 1 + sycl/plugins/esimd_cpu/pi_esimd_cpu.cpp | 2 +- sycl/plugins/level_zero/pi_level_zero.cpp | 7 ++++--- sycl/plugins/level_zero/pi_level_zero.hpp | 7 ++++++- sycl/plugins/opencl/pi_opencl.cpp | 4 +++- sycl/source/backend.cpp | 4 ++-- sycl/source/backend/level_zero.cpp | 5 +++-- sycl/source/backend/opencl.cpp | 2 +- sycl/test/abi/sycl_symbols_linux.dump | 4 ++-- 13 files changed, 38 insertions(+), 21 deletions(-) diff --git a/sycl/doc/extensions/LevelZeroBackend/LevelZeroBackend.md b/sycl/doc/extensions/LevelZeroBackend/LevelZeroBackend.md index 4370f7d422f46..0d05ea3e8400e 100755 --- a/sycl/doc/extensions/LevelZeroBackend/LevelZeroBackend.md +++ b/sycl/doc/extensions/LevelZeroBackend/LevelZeroBackend.md @@ -88,7 +88,7 @@ a SYCL object that encapsulates a corresponding Level-Zero object: |``` make(ze_driver_handle_t);```|Constructs a SYCL platform instance from a Level-Zero ```ze_driver_handle_t```.| |``` make(const platform &, ze_device_handle_t);```|Constructs a SYCL device instance from a Level-Zero ```ze_device_handle_t```. The platform argument gives a SYCL platform, encapsulating a Level-Zero driver supporting the passed Level-Zero device.| |``` make(const vector_class &, ze_context_handle_t, ownership = transfer);```| Constructs a SYCL context instance from a Level-Zero ```ze_context_handle_t```. The context is created against the devices passed in. There must be at least one device given and all the devices must be from the same SYCL platform and thus from the same Level-Zero driver. The ```ownership``` argument specifies if the SYCL runtime should take ownership of the passed native handle. The default behavior is to transfer the ownership to the SYCL runtime. See section 4.4 for details.| -|``` make(const context &, ze_command_queue_handle_t);```| Constructs a SYCL queue instance from a Level-Zero ```ze_command_queue_handle_t```. The context argument must be a valid SYCL context encapsulating a Level-Zero context. The queue is attached to the first device in the passed SYCL context.| +|``` make(const context &, ze_command_queue_handle_t, ownership = transfer);```| Constructs a SYCL queue instance from a Level-Zero ```ze_command_queue_handle_t```. The context argument must be a valid SYCL context encapsulating a Level-Zero context. The queue is attached to the first device in the passed SYCL context. The ```ownership``` argument specifies if the SYCL runtime should take ownership of the passed native handle. The default behavior is to transfer the ownership to the SYCL runtime. See section 4.4 for details.| |``` make(const context &, ze_module_handle_t);```| Constructs a SYCL program instance from a Level-Zero ```ze_module_handle_t```. The context argument must be a valid SYCL context encapsulating a Level-Zero context. The Level-Zero module must be fully linked (i.e. not require further linking through [```zeModuleDynamicLink```](https://spec.oneapi.com/level-zero/latest/core/api.html?highlight=zemoduledynamiclink#_CPPv419zeModuleDynamicLink8uint32_tP18ze_module_handle_tP28ze_module_build_log_handle_t)), and thus the SYCL program is created in the "linked" state.| NOTE: We shall consider adding other interoperability as needed, if possible. @@ -189,4 +189,4 @@ struct free_memory { |1|2021-01-26|Sergey Maslov|Initial public working draft |2|2021-02-22|Sergey Maslov|Introduced explicit ownership for context |3|2021-04-13|James Brodman|Free Memory Query - +|4|2021-07-06|Rehana Begam|Introduced explicit ownership for queue diff --git a/sycl/include/CL/sycl/backend.hpp b/sycl/include/CL/sycl/backend.hpp index 1608ed97ed8e4..0221787992e12 100644 --- a/sycl/include/CL/sycl/backend.hpp +++ b/sycl/include/CL/sycl/backend.hpp @@ -92,6 +92,7 @@ __SYCL_EXPORT context make_context(pi_native_handle NativeHandle, backend Backend); __SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle, const context &TargetContext, + bool KeepOwnership, const async_handler &Handler, backend Backend); __SYCL_EXPORT event make_event(pi_native_handle NativeHandle, const context &TargetContext, backend Backend); diff --git a/sycl/include/CL/sycl/backend/level_zero.hpp b/sycl/include/CL/sycl/backend/level_zero.hpp index ba87841be6b83..1c22db35354cc 100644 --- a/sycl/include/CL/sycl/backend/level_zero.hpp +++ b/sycl/include/CL/sycl/backend/level_zero.hpp @@ -92,7 +92,8 @@ __SYCL_EXPORT context make_context(const std::vector &DeviceList, __SYCL_EXPORT program make_program(const context &Context, pi_native_handle NativeHandle); __SYCL_EXPORT queue make_queue(const context &Context, - pi_native_handle InteropHandle); + pi_native_handle InteropHandle, + bool keep_ownership = false); // Construction of SYCL platform. template ::value> * = nullptr> T make(const context &Context, - typename interop::type Interop) { - return make_queue(Context, reinterpret_cast(Interop)); + typename interop::type Interop, + ownership Ownership = ownership::transfer) { + return make_queue(Context, reinterpret_cast(Interop), + Ownership == ownership::keep); } } // namespace level_zero diff --git a/sycl/include/CL/sycl/detail/pi.h b/sycl/include/CL/sycl/detail/pi.h index d682e35ef8f47..44016c52788e0 100644 --- a/sycl/include/CL/sycl/detail/pi.h +++ b/sycl/include/CL/sycl/detail/pi.h @@ -36,10 +36,11 @@ // 2. A number of types needed to define pi_device_binary_property_set added. // 3. Added new ownership argument to piextContextCreateWithNativeHandle. // 4. Add interoperability interfaces for kernel. +// 5. Added new ownership argument to piextQueueCreateWithNativeHandle. // #include "CL/cl.h" -#define _PI_H_VERSION_MAJOR 3 -#define _PI_H_VERSION_MINOR 5 +#define _PI_H_VERSION_MAJOR 4 +#define _PI_H_VERSION_MINOR 6 #define _PI_STRING_HELPER(a) #a #define _PI_CONCAT(a, b) _PI_STRING_HELPER(a.b) @@ -1042,9 +1043,11 @@ piextQueueGetNativeHandle(pi_queue queue, pi_native_handle *nativeHandle); /// /// \param nativeHandle is the native handle to create PI queue from. /// \param context is the PI context of the queue. +/// \param ownNativeHandle tells if SYCL RT should assume the ownership of +/// the native handle, if it can. /// \param queue is the PI queue created from the native handle. __SYCL_EXPORT pi_result piextQueueCreateWithNativeHandle( - pi_native_handle nativeHandle, pi_context context, pi_queue *queue); + pi_native_handle nativeHandle, pi_context context, bool ownNativeHandle, pi_queue *queue); // // Memory diff --git a/sycl/plugins/cuda/pi_cuda.cpp b/sycl/plugins/cuda/pi_cuda.cpp index a5f8f2faacd4a..e8930a6144b58 100644 --- a/sycl/plugins/cuda/pi_cuda.cpp +++ b/sycl/plugins/cuda/pi_cuda.cpp @@ -2149,6 +2149,7 @@ pi_result cuda_piextQueueGetNativeHandle(pi_queue queue, /// /// \return TBD pi_result cuda_piextQueueCreateWithNativeHandle(pi_native_handle, pi_context, + bool ownNativeHandle, pi_queue *) { cl::sycl::detail::pi::die( "Creation of PI queue from native handle not implemented"); diff --git a/sycl/plugins/esimd_cpu/pi_esimd_cpu.cpp b/sycl/plugins/esimd_cpu/pi_esimd_cpu.cpp index 63fc720f49eee..86c672b620d65 100644 --- a/sycl/plugins/esimd_cpu/pi_esimd_cpu.cpp +++ b/sycl/plugins/esimd_cpu/pi_esimd_cpu.cpp @@ -674,7 +674,7 @@ pi_result piextQueueGetNativeHandle(pi_queue, pi_native_handle *) { return PI_SUCCESS; } -pi_result piextQueueCreateWithNativeHandle(pi_native_handle, pi_context, +pi_result piextQueueCreateWithNativeHandle(pi_native_handle, pi_context, bool, pi_queue *) { DIE_NO_IMPLEMENTATION; return PI_SUCCESS; diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index f0ac45704d08a..95d35aa33deb0 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -2411,7 +2411,7 @@ pi_result piQueueCreate(pi_context Context, pi_device Device, try { *Queue = new _pi_queue(ZeComputeCommandQueue, ZeCopyCommandQueue, Context, - Device, ZeCommandListBatchSize, Properties); + Device, ZeCommandListBatchSize, true, Properties); } catch (const std::bad_alloc &) { return PI_OUT_OF_HOST_MEMORY; } catch (...) { @@ -2471,7 +2471,7 @@ pi_result piQueueRelease(pi_queue Queue) { std::lock_guard Lock(Queue->PiQueueMutex); Queue->RefCount--; if (Queue->RefCount == 0) - RefCountZero = true; + RefCountZero = Queue->OwnZeCommandQueue ? true : false; if (RefCountZero) { // It is possible to get to here and still have an open command list @@ -2546,6 +2546,7 @@ pi_result piextQueueGetNativeHandle(pi_queue Queue, pi_result piextQueueCreateWithNativeHandle(pi_native_handle NativeHandle, pi_context Context, + bool OwnNativeHandle, pi_queue *Queue) { PI_ASSERT(Context, PI_INVALID_CONTEXT); PI_ASSERT(NativeHandle, PI_INVALID_VALUE); @@ -2559,7 +2560,7 @@ pi_result piextQueueCreateWithNativeHandle(pi_native_handle NativeHandle, // TODO: see what we can do to correctly initialize PI queue for // compute vs. copy Level-Zero queue. *Queue = - new _pi_queue(ZeQueue, nullptr, Context, Device, ZeCommandListBatchSize); + new _pi_queue(ZeQueue, nullptr, Context, Device, ZeCommandListBatchSize, OwnNativeHandle); return PI_SUCCESS; } diff --git a/sycl/plugins/level_zero/pi_level_zero.hpp b/sycl/plugins/level_zero/pi_level_zero.hpp index 4abf77f5214be..c18a8e90d0bb4 100644 --- a/sycl/plugins/level_zero/pi_level_zero.hpp +++ b/sycl/plugins/level_zero/pi_level_zero.hpp @@ -434,12 +434,13 @@ const pi_uint32 DynamicBatchStartSize = 4; struct _pi_queue : _pi_object { _pi_queue(ze_command_queue_handle_t Queue, ze_command_queue_handle_t CopyQueue, pi_context Context, - pi_device Device, pi_uint32 BatchSize, + pi_device Device, pi_uint32 BatchSize, bool OwnZeCommandQueue, pi_queue_properties PiQueueProperties = 0) : ZeComputeCommandQueue{Queue}, ZeCopyCommandQueue{CopyQueue}, Context{Context}, Device{Device}, QueueBatchSize{BatchSize > 0 ? BatchSize : DynamicBatchStartSize}, UseDynamicBatching{BatchSize == 0}, + OwnZeCommandQueue{OwnZeCommandQueue}, PiQueueProperties(PiQueueProperties) {} // Level Zero compute command queue handle. @@ -497,6 +498,10 @@ struct _pi_queue : _pi_object { // const for the life of the queue. const bool UseDynamicBatching; + // Indicates if we own the ZeCommandQueue or it came from interop that + // asked to not transfer the ownership to SYCL RT. + bool OwnZeCommandQueue; + // These two members are used to keep track of how often the // batching closes and executes a command list before reaching the // QueueBatchSize limit, versus how often we reach the limit. diff --git a/sycl/plugins/opencl/pi_opencl.cpp b/sycl/plugins/opencl/pi_opencl.cpp index 6e3f569a94dce..bb7b561879540 100644 --- a/sycl/plugins/opencl/pi_opencl.cpp +++ b/sycl/plugins/opencl/pi_opencl.cpp @@ -352,8 +352,10 @@ pi_result piQueueCreate(pi_context context, pi_device device, } pi_result piextQueueCreateWithNativeHandle(pi_native_handle nativeHandle, - pi_context, pi_queue *piQueue) { + pi_context, bool ownNativeHandle, + pi_queue *piQueue) { assert(piQueue != nullptr); + assert(ownNativeHandle == false); *piQueue = reinterpret_cast(nativeHandle); return PI_SUCCESS; } diff --git a/sycl/source/backend.cpp b/sycl/source/backend.cpp index 26cc412446b7e..0e51a04b2ec5e 100644 --- a/sycl/source/backend.cpp +++ b/sycl/source/backend.cpp @@ -78,14 +78,14 @@ __SYCL_EXPORT context make_context(pi_native_handle NativeHandle, } __SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle, - const context &Context, + const context &Context, bool KeepOwnership, const async_handler &Handler, backend Backend) { const auto &Plugin = getPlugin(Backend); const auto &ContextImpl = getSyclObjImpl(Context); // Create PI queue first. pi::PiQueue PiQueue = nullptr; Plugin.call( - NativeHandle, ContextImpl->getHandleRef(), &PiQueue); + NativeHandle, ContextImpl->getHandleRef(), !KeepOwnership, &PiQueue); // Construct the SYCL queue from PI queue. return detail::createSyclObjFromImpl( std::make_shared(PiQueue, ContextImpl, Handler)); diff --git a/sycl/source/backend/level_zero.cpp b/sycl/source/backend/level_zero.cpp index d9c87fc9aa83e..3fd443017a0d0 100644 --- a/sycl/source/backend/level_zero.cpp +++ b/sycl/source/backend/level_zero.cpp @@ -79,9 +79,10 @@ __SYCL_EXPORT program make_program(const context &Context, //---------------------------------------------------------------------------- // Implementation of level_zero::make __SYCL_EXPORT queue make_queue(const context &Context, - pi_native_handle NativeHandle) { + pi_native_handle NativeHandle, + bool KeepOwnership) { const auto &ContextImpl = getSyclObjImpl(Context); - return detail::make_queue(NativeHandle, Context, + return detail::make_queue(NativeHandle, Context, KeepOwnership, ContextImpl->get_async_handler(), backend::level_zero); } diff --git a/sycl/source/backend/opencl.cpp b/sycl/source/backend/opencl.cpp index 4ecb1e6a76e17..7e76478c8e630 100644 --- a/sycl/source/backend/opencl.cpp +++ b/sycl/source/backend/opencl.cpp @@ -52,7 +52,7 @@ __SYCL_EXPORT program make_program(const context &Context, __SYCL_EXPORT queue make_queue(const context &Context, pi_native_handle NativeHandle) { const auto &ContextImpl = getSyclObjImpl(Context); - return detail::make_queue(NativeHandle, Context, + return detail::make_queue(NativeHandle, Context, false, ContextImpl->get_async_handler(), backend::opencl); } } // namespace opencl diff --git a/sycl/test/abi/sycl_symbols_linux.dump b/sycl/test/abi/sycl_symbols_linux.dump index 0683df8dcc193..18b70b8bc880f 100644 --- a/sycl/test/abi/sycl_symbols_linux.dump +++ b/sycl/test/abi/sycl_symbols_linux.dump @@ -3590,7 +3590,7 @@ _ZN2cl10__host_std9u_sub_satEhh _ZN2cl10__host_std9u_sub_satEjj _ZN2cl10__host_std9u_sub_satEmm _ZN2cl10__host_std9u_sub_satEtt -_ZN2cl4sycl10level_zero10make_queueERKNS0_7contextEm +_ZN2cl4sycl10level_zero10make_queueERKNS0_7contextEmb _ZN2cl4sycl10level_zero11make_deviceERKNS0_8platformEm _ZN2cl4sycl10level_zero12make_contextERKSt6vectorINS0_6deviceESaIS3_EEm _ZN2cl4sycl10level_zero12make_contextERKSt6vectorINS0_6deviceESaIS3_EEmb @@ -3741,7 +3741,7 @@ _ZN2cl4sycl6detail10image_implILi3EED0Ev _ZN2cl4sycl6detail10image_implILi3EED1Ev _ZN2cl4sycl6detail10image_implILi3EED2Ev _ZN2cl4sycl6detail10make_eventEmRKNS0_7contextENS0_7backendE -_ZN2cl4sycl6detail10make_queueEmRKNS0_7contextERKSt8functionIFvNS0_14exception_listEEENS0_7backendE +_ZN2cl4sycl6detail10make_queueEmRKNS0_7contextEbRKSt8functionIFvNS0_14exception_listEEENS0_7backendE _ZN2cl4sycl6detail10waitEventsESt6vectorINS0_5eventESaIS3_EE _ZN2cl4sycl6detail11SYCLMemObjT10releaseMemESt10shared_ptrINS1_12context_implEEPv _ZN2cl4sycl6detail11SYCLMemObjT16determineHostPtrERKSt10shared_ptrINS1_12context_implEEbRPvRb From 8f58fb9f67aa2b26db2ad59202b171a414e4b44b Mon Sep 17 00:00:00 2001 From: rehana begam Date: Tue, 6 Jul 2021 14:43:41 -0700 Subject: [PATCH 02/11] clang formatted. Signed-off-by: rehana begam --- sycl/include/CL/sycl/backend.hpp | 3 +-- sycl/include/CL/sycl/detail/pi.h | 3 ++- sycl/plugins/level_zero/pi_level_zero.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sycl/include/CL/sycl/backend.hpp b/sycl/include/CL/sycl/backend.hpp index 0221787992e12..59d1a270c4734 100644 --- a/sycl/include/CL/sycl/backend.hpp +++ b/sycl/include/CL/sycl/backend.hpp @@ -91,8 +91,7 @@ __SYCL_EXPORT context make_context(pi_native_handle NativeHandle, const async_handler &Handler, backend Backend); __SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle, - const context &TargetContext, - bool KeepOwnership, + const context &TargetContext, bool KeepOwnership, const async_handler &Handler, backend Backend); __SYCL_EXPORT event make_event(pi_native_handle NativeHandle, const context &TargetContext, backend Backend); diff --git a/sycl/include/CL/sycl/detail/pi.h b/sycl/include/CL/sycl/detail/pi.h index 44016c52788e0..1b610581963b5 100644 --- a/sycl/include/CL/sycl/detail/pi.h +++ b/sycl/include/CL/sycl/detail/pi.h @@ -1047,7 +1047,8 @@ piextQueueGetNativeHandle(pi_queue queue, pi_native_handle *nativeHandle); /// the native handle, if it can. /// \param queue is the PI queue created from the native handle. __SYCL_EXPORT pi_result piextQueueCreateWithNativeHandle( - pi_native_handle nativeHandle, pi_context context, bool ownNativeHandle, pi_queue *queue); + pi_native_handle nativeHandle, pi_context context, bool ownNativeHandle, + pi_queue *queue); // // Memory diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index 95d35aa33deb0..55662801af087 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -2559,8 +2559,8 @@ pi_result piextQueueCreateWithNativeHandle(pi_native_handle NativeHandle, pi_device Device = Context->Devices[0]; // TODO: see what we can do to correctly initialize PI queue for // compute vs. copy Level-Zero queue. - *Queue = - new _pi_queue(ZeQueue, nullptr, Context, Device, ZeCommandListBatchSize, OwnNativeHandle); + *Queue = new _pi_queue(ZeQueue, nullptr, Context, Device, + ZeCommandListBatchSize, OwnNativeHandle); return PI_SUCCESS; } From 9ed3ceabe39f020eff220f580d8395821b7f71d9 Mon Sep 17 00:00:00 2001 From: rehana begam Date: Wed, 7 Jul 2021 13:01:26 -0700 Subject: [PATCH 03/11] fixed the unittest fail and modified the API version. Signed-off-by: rehana begam --- sycl/include/CL/sycl/backend.hpp | 10 ++++++---- sycl/include/CL/sycl/detail/pi.h | 7 ++++--- sycl/plugins/esimd_cpu/pi_esimd_cpu.cpp | 4 ++-- sycl/plugins/level_zero/pi_level_zero.cpp | 21 ++++++++++++--------- sycl/plugins/level_zero/pi_level_zero.hpp | 17 +++++++++-------- sycl/plugins/opencl/pi_opencl.cpp | 4 ++-- sycl/source/backend.cpp | 7 ++++--- sycl/source/backend/level_zero.cpp | 4 ++-- sycl/source/backend/opencl.cpp | 6 +++--- sycl/source/detail/queue_impl.hpp | 4 +++- sycl/test/abi/sycl_symbols_linux.dump | 4 ++-- 11 files changed, 49 insertions(+), 39 deletions(-) diff --git a/sycl/include/CL/sycl/backend.hpp b/sycl/include/CL/sycl/backend.hpp index 59d1a270c4734..b01a1d9adf9e8 100644 --- a/sycl/include/CL/sycl/backend.hpp +++ b/sycl/include/CL/sycl/backend.hpp @@ -91,8 +91,9 @@ __SYCL_EXPORT context make_context(pi_native_handle NativeHandle, const async_handler &Handler, backend Backend); __SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle, - const context &TargetContext, bool KeepOwnership, - const async_handler &Handler, backend Backend); + const context &TargetContext, + const async_handler &Handler, bool KeepOwnership, + backend Backend); __SYCL_EXPORT event make_event(pi_native_handle NativeHandle, const context &TargetContext, backend Backend); __SYCL_EXPORT kernel make_kernel(pi_native_handle NativeHandle, @@ -139,9 +140,10 @@ typename std::enable_if< detail::InteropFeatureSupportMap::MakeQueue == true, queue>::type make_queue(const typename backend_traits::template input_type &BackendObject, - const context &TargetContext, const async_handler Handler = {}) { + const context &TargetContext, const async_handler Handler = {}, + bool KeepOwnership = true) { return detail::make_queue(detail::pi::cast(BackendObject), - TargetContext, Handler, Backend); + TargetContext, Handler, KeepOwnership, Backend); } template diff --git a/sycl/include/CL/sycl/detail/pi.h b/sycl/include/CL/sycl/detail/pi.h index 1b610581963b5..09f4705a17165 100644 --- a/sycl/include/CL/sycl/detail/pi.h +++ b/sycl/include/CL/sycl/detail/pi.h @@ -36,7 +36,8 @@ // 2. A number of types needed to define pi_device_binary_property_set added. // 3. Added new ownership argument to piextContextCreateWithNativeHandle. // 4. Add interoperability interfaces for kernel. -// 5. Added new ownership argument to piextQueueCreateWithNativeHandle. +// 4.6 Added new ownership argument to piextQueueCreateWithNativeHandle which +// changes the API version from 3.5 to 4.6. // #include "CL/cl.h" #define _PI_H_VERSION_MAJOR 4 @@ -1047,8 +1048,8 @@ piextQueueGetNativeHandle(pi_queue queue, pi_native_handle *nativeHandle); /// the native handle, if it can. /// \param queue is the PI queue created from the native handle. __SYCL_EXPORT pi_result piextQueueCreateWithNativeHandle( - pi_native_handle nativeHandle, pi_context context, bool ownNativeHandle, - pi_queue *queue); + pi_native_handle nativeHandle, pi_context context, + pi_queue *queue, bool ownNativeHandle); // // Memory diff --git a/sycl/plugins/esimd_cpu/pi_esimd_cpu.cpp b/sycl/plugins/esimd_cpu/pi_esimd_cpu.cpp index 86c672b620d65..2f794eb613cee 100644 --- a/sycl/plugins/esimd_cpu/pi_esimd_cpu.cpp +++ b/sycl/plugins/esimd_cpu/pi_esimd_cpu.cpp @@ -674,8 +674,8 @@ pi_result piextQueueGetNativeHandle(pi_queue, pi_native_handle *) { return PI_SUCCESS; } -pi_result piextQueueCreateWithNativeHandle(pi_native_handle, pi_context, bool, - pi_queue *) { +pi_result piextQueueCreateWithNativeHandle(pi_native_handle, pi_context, + pi_queue *, bool) { DIE_NO_IMPLEMENTATION; return PI_SUCCESS; } diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index 55662801af087..223f99ac2b866 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -2411,7 +2411,7 @@ pi_result piQueueCreate(pi_context Context, pi_device Device, try { *Queue = new _pi_queue(ZeComputeCommandQueue, ZeCopyCommandQueue, Context, - Device, ZeCommandListBatchSize, true, Properties); + Device, ZeCommandListBatchSize, Properties, true); } catch (const std::bad_alloc &) { return PI_OUT_OF_HOST_MEMORY; } catch (...) { @@ -2471,7 +2471,7 @@ pi_result piQueueRelease(pi_queue Queue) { std::lock_guard Lock(Queue->PiQueueMutex); Queue->RefCount--; if (Queue->RefCount == 0) - RefCountZero = Queue->OwnZeCommandQueue ? true : false; + RefCountZero = true; if (RefCountZero) { // It is possible to get to here and still have an open command list @@ -2494,11 +2494,14 @@ pi_result piQueueRelease(pi_queue Queue) { ZE_CALL(zeFenceDestroy, (MapEntry.second.ZeFence)); } Queue->ZeCommandListFenceMap.clear(); - ZE_CALL(zeCommandQueueDestroy, (Queue->ZeComputeCommandQueue)); - Queue->ZeComputeCommandQueue = nullptr; - if (Queue->ZeCopyCommandQueue) { - ZE_CALL(zeCommandQueueDestroy, (Queue->ZeCopyCommandQueue)); - Queue->ZeCopyCommandQueue = nullptr; + + if (Queue->OwnZeCommandQueue) { + ZE_CALL(zeCommandQueueDestroy, (Queue->ZeComputeCommandQueue)); + Queue->ZeComputeCommandQueue = nullptr; + if (Queue->ZeCopyCommandQueue) { + ZE_CALL(zeCommandQueueDestroy, (Queue->ZeCopyCommandQueue)); + Queue->ZeCopyCommandQueue = nullptr; + } } zePrint("piQueueRelease NumTimesClosedFull %d, NumTimesClosedEarly %d\n", @@ -2546,8 +2549,8 @@ pi_result piextQueueGetNativeHandle(pi_queue Queue, pi_result piextQueueCreateWithNativeHandle(pi_native_handle NativeHandle, pi_context Context, - bool OwnNativeHandle, - pi_queue *Queue) { + pi_queue *Queue, + bool OwnNativeHandle) { PI_ASSERT(Context, PI_INVALID_CONTEXT); PI_ASSERT(NativeHandle, PI_INVALID_VALUE); PI_ASSERT(Queue, PI_INVALID_QUEUE); diff --git a/sycl/plugins/level_zero/pi_level_zero.hpp b/sycl/plugins/level_zero/pi_level_zero.hpp index c18a8e90d0bb4..a129d2c84df8a 100644 --- a/sycl/plugins/level_zero/pi_level_zero.hpp +++ b/sycl/plugins/level_zero/pi_level_zero.hpp @@ -434,14 +434,15 @@ const pi_uint32 DynamicBatchStartSize = 4; struct _pi_queue : _pi_object { _pi_queue(ze_command_queue_handle_t Queue, ze_command_queue_handle_t CopyQueue, pi_context Context, - pi_device Device, pi_uint32 BatchSize, bool OwnZeCommandQueue, - pi_queue_properties PiQueueProperties = 0) + pi_device Device, pi_uint32 BatchSize, + pi_queue_properties PiQueueProperties = 0, + bool OwnZeCommandQueue = true) : ZeComputeCommandQueue{Queue}, ZeCopyCommandQueue{CopyQueue}, Context{Context}, Device{Device}, QueueBatchSize{BatchSize > 0 ? BatchSize : DynamicBatchStartSize}, UseDynamicBatching{BatchSize == 0}, - OwnZeCommandQueue{OwnZeCommandQueue}, - PiQueueProperties(PiQueueProperties) {} + PiQueueProperties(PiQueueProperties), + OwnZeCommandQueue{OwnZeCommandQueue} {} // Level Zero compute command queue handle. ze_command_queue_handle_t ZeComputeCommandQueue; @@ -498,10 +499,6 @@ struct _pi_queue : _pi_object { // const for the life of the queue. const bool UseDynamicBatching; - // Indicates if we own the ZeCommandQueue or it came from interop that - // asked to not transfer the ownership to SYCL RT. - bool OwnZeCommandQueue; - // These two members are used to keep track of how often the // batching closes and executes a command list before reaching the // QueueBatchSize limit, versus how often we reach the limit. @@ -535,6 +532,10 @@ struct _pi_queue : _pi_object { // Keeps the properties of this queue. pi_queue_properties PiQueueProperties; + // Indicates if we own the ZeCommandQueue or it came from interop that + // asked to not transfer the ownership to SYCL RT. + bool OwnZeCommandQueue = true; + // Returns true if the queue is a in-order queue. bool isInOrderQueue() const; diff --git a/sycl/plugins/opencl/pi_opencl.cpp b/sycl/plugins/opencl/pi_opencl.cpp index bb7b561879540..2cf1bff6fd32a 100644 --- a/sycl/plugins/opencl/pi_opencl.cpp +++ b/sycl/plugins/opencl/pi_opencl.cpp @@ -352,8 +352,8 @@ pi_result piQueueCreate(pi_context context, pi_device device, } pi_result piextQueueCreateWithNativeHandle(pi_native_handle nativeHandle, - pi_context, bool ownNativeHandle, - pi_queue *piQueue) { + pi_context, pi_queue *piQueue, + bool ownNativeHandle) { assert(piQueue != nullptr); assert(ownNativeHandle == false); *piQueue = reinterpret_cast(nativeHandle); diff --git a/sycl/source/backend.cpp b/sycl/source/backend.cpp index 0e51a04b2ec5e..9cf210188c610 100644 --- a/sycl/source/backend.cpp +++ b/sycl/source/backend.cpp @@ -78,14 +78,15 @@ __SYCL_EXPORT context make_context(pi_native_handle NativeHandle, } __SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle, - const context &Context, bool KeepOwnership, - const async_handler &Handler, backend Backend) { + const context &Context, + const async_handler &Handler, bool KeepOwnership, + backend Backend) { const auto &Plugin = getPlugin(Backend); const auto &ContextImpl = getSyclObjImpl(Context); // Create PI queue first. pi::PiQueue PiQueue = nullptr; Plugin.call( - NativeHandle, ContextImpl->getHandleRef(), !KeepOwnership, &PiQueue); + NativeHandle, ContextImpl->getHandleRef(), &PiQueue, !KeepOwnership); // Construct the SYCL queue from PI queue. return detail::createSyclObjFromImpl( std::make_shared(PiQueue, ContextImpl, Handler)); diff --git a/sycl/source/backend/level_zero.cpp b/sycl/source/backend/level_zero.cpp index 3fd443017a0d0..df3472d177585 100644 --- a/sycl/source/backend/level_zero.cpp +++ b/sycl/source/backend/level_zero.cpp @@ -82,8 +82,8 @@ __SYCL_EXPORT queue make_queue(const context &Context, pi_native_handle NativeHandle, bool KeepOwnership) { const auto &ContextImpl = getSyclObjImpl(Context); - return detail::make_queue(NativeHandle, Context, KeepOwnership, - ContextImpl->get_async_handler(), + return detail::make_queue(NativeHandle, Context, + ContextImpl->get_async_handler(), KeepOwnership, backend::level_zero); } diff --git a/sycl/source/backend/opencl.cpp b/sycl/source/backend/opencl.cpp index 7e76478c8e630..fcf1823b95fea 100644 --- a/sycl/source/backend/opencl.cpp +++ b/sycl/source/backend/opencl.cpp @@ -50,10 +50,10 @@ __SYCL_EXPORT program make_program(const context &Context, //---------------------------------------------------------------------------- // Implementation of opencl::make __SYCL_EXPORT queue make_queue(const context &Context, - pi_native_handle NativeHandle) { + pi_native_handle NativeHandle, bool KeepOwnership) { const auto &ContextImpl = getSyclObjImpl(Context); - return detail::make_queue(NativeHandle, Context, false, - ContextImpl->get_async_handler(), backend::opencl); + return detail::make_queue(NativeHandle, Context, + ContextImpl->get_async_handler(), KeepOwnership, backend::opencl); } } // namespace opencl } // namespace sycl diff --git a/sycl/source/detail/queue_impl.hpp b/sycl/source/detail/queue_impl.hpp index 93474890fbaf0..e259c838b00c6 100644 --- a/sycl/source/detail/queue_impl.hpp +++ b/sycl/source/detail/queue_impl.hpp @@ -115,7 +115,9 @@ class queue_impl { DeviceImplPtr(new device_impl(Device, Context->getPlatformImpl())); // TODO catch an exception and put it to list of asynchronous exceptions - Plugin.call(MQueues[0]); + if (Plugin.getBackend() == cl::sycl::backend::opencl) { + getPlugin().call(MQueues[0]); + } } ~queue_impl() { diff --git a/sycl/test/abi/sycl_symbols_linux.dump b/sycl/test/abi/sycl_symbols_linux.dump index 18b70b8bc880f..368c1276ebf2b 100644 --- a/sycl/test/abi/sycl_symbols_linux.dump +++ b/sycl/test/abi/sycl_symbols_linux.dump @@ -3741,7 +3741,7 @@ _ZN2cl4sycl6detail10image_implILi3EED0Ev _ZN2cl4sycl6detail10image_implILi3EED1Ev _ZN2cl4sycl6detail10image_implILi3EED2Ev _ZN2cl4sycl6detail10make_eventEmRKNS0_7contextENS0_7backendE -_ZN2cl4sycl6detail10make_queueEmRKNS0_7contextEbRKSt8functionIFvNS0_14exception_listEEENS0_7backendE +_ZN2cl4sycl6detail10make_queueEmRKNS0_7contextERKSt8functionIFvNS0_14exception_listEEEbNS0_7backendE _ZN2cl4sycl6detail10waitEventsESt6vectorINS0_5eventESaIS3_EE _ZN2cl4sycl6detail11SYCLMemObjT10releaseMemESt10shared_ptrINS1_12context_implEEPv _ZN2cl4sycl6detail11SYCLMemObjT16determineHostPtrERKSt10shared_ptrINS1_12context_implEEbRPvRb @@ -3856,7 +3856,7 @@ _ZN2cl4sycl6mallocEmRKNS0_5queueENS0_3usm5allocE _ZN2cl4sycl6mallocEmRKNS0_5queueENS0_3usm5allocERKNS0_13property_listE _ZN2cl4sycl6mallocEmRKNS0_6deviceERKNS0_7contextENS0_3usm5allocE _ZN2cl4sycl6mallocEmRKNS0_6deviceERKNS0_7contextENS0_3usm5allocERKNS0_13property_listE -_ZN2cl4sycl6opencl10make_queueERKNS0_7contextEm +_ZN2cl4sycl6opencl10make_queueERKNS0_7contextEmb _ZN2cl4sycl6opencl11make_deviceEm _ZN2cl4sycl6opencl12make_contextEm _ZN2cl4sycl6opencl12make_programERKNS0_7contextEm From a0bc9666107117f8bcd27c3065e492fc36fcde00 Mon Sep 17 00:00:00 2001 From: rehana begam Date: Wed, 7 Jul 2021 13:12:41 -0700 Subject: [PATCH 04/11] change pi_cuda. Signed-off-by: rehana begam --- sycl/include/CL/sycl/detail/pi.h | 2 +- sycl/plugins/cuda/pi_cuda.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sycl/include/CL/sycl/detail/pi.h b/sycl/include/CL/sycl/detail/pi.h index 09f4705a17165..790f51b938b03 100644 --- a/sycl/include/CL/sycl/detail/pi.h +++ b/sycl/include/CL/sycl/detail/pi.h @@ -1044,9 +1044,9 @@ piextQueueGetNativeHandle(pi_queue queue, pi_native_handle *nativeHandle); /// /// \param nativeHandle is the native handle to create PI queue from. /// \param context is the PI context of the queue. +/// \param queue is the PI queue created from the native handle. /// \param ownNativeHandle tells if SYCL RT should assume the ownership of /// the native handle, if it can. -/// \param queue is the PI queue created from the native handle. __SYCL_EXPORT pi_result piextQueueCreateWithNativeHandle( pi_native_handle nativeHandle, pi_context context, pi_queue *queue, bool ownNativeHandle); diff --git a/sycl/plugins/cuda/pi_cuda.cpp b/sycl/plugins/cuda/pi_cuda.cpp index e8930a6144b58..0c992cab9ef41 100644 --- a/sycl/plugins/cuda/pi_cuda.cpp +++ b/sycl/plugins/cuda/pi_cuda.cpp @@ -2146,11 +2146,14 @@ pi_result cuda_piextQueueGetNativeHandle(pi_queue queue, /// \param[in] nativeHandle The native handle to create PI queue object from. /// \param[in] context is the PI context of the queue. /// \param[out] queue Set to the PI queue object created from native handle. +/// \param ownNativeHandle tells if SYCL RT should assume the ownership of +/// the native handle, if it can. /// /// \return TBD pi_result cuda_piextQueueCreateWithNativeHandle(pi_native_handle, pi_context, - bool ownNativeHandle, - pi_queue *) { + pi_queue *, + bool ownNativeHandle) { + (void)ownNativeHandle; cl::sycl::detail::pi::die( "Creation of PI queue from native handle not implemented"); return {}; From 5d107bbf6965f180fa26465c71969a15930b87fe Mon Sep 17 00:00:00 2001 From: rehana begam Date: Wed, 7 Jul 2021 13:19:48 -0700 Subject: [PATCH 05/11] clang formatted. Signed-off-by: rehana begam --- sycl/include/CL/sycl/detail/pi.h | 4 ++-- sycl/plugins/level_zero/pi_level_zero.cpp | 3 +-- sycl/source/backend/opencl.cpp | 6 ++++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/sycl/include/CL/sycl/detail/pi.h b/sycl/include/CL/sycl/detail/pi.h index 790f51b938b03..439d147c011c7 100644 --- a/sycl/include/CL/sycl/detail/pi.h +++ b/sycl/include/CL/sycl/detail/pi.h @@ -1048,8 +1048,8 @@ piextQueueGetNativeHandle(pi_queue queue, pi_native_handle *nativeHandle); /// \param ownNativeHandle tells if SYCL RT should assume the ownership of /// the native handle, if it can. __SYCL_EXPORT pi_result piextQueueCreateWithNativeHandle( - pi_native_handle nativeHandle, pi_context context, - pi_queue *queue, bool ownNativeHandle); + pi_native_handle nativeHandle, pi_context context, pi_queue *queue, + bool ownNativeHandle); // // Memory diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index 223f99ac2b866..202aaf8bbc183 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -2548,8 +2548,7 @@ pi_result piextQueueGetNativeHandle(pi_queue Queue, } pi_result piextQueueCreateWithNativeHandle(pi_native_handle NativeHandle, - pi_context Context, - pi_queue *Queue, + pi_context Context, pi_queue *Queue, bool OwnNativeHandle) { PI_ASSERT(Context, PI_INVALID_CONTEXT); PI_ASSERT(NativeHandle, PI_INVALID_VALUE); diff --git a/sycl/source/backend/opencl.cpp b/sycl/source/backend/opencl.cpp index fcf1823b95fea..118d2c5302b48 100644 --- a/sycl/source/backend/opencl.cpp +++ b/sycl/source/backend/opencl.cpp @@ -50,10 +50,12 @@ __SYCL_EXPORT program make_program(const context &Context, //---------------------------------------------------------------------------- // Implementation of opencl::make __SYCL_EXPORT queue make_queue(const context &Context, - pi_native_handle NativeHandle, bool KeepOwnership) { + pi_native_handle NativeHandle, + bool KeepOwnership) { const auto &ContextImpl = getSyclObjImpl(Context); return detail::make_queue(NativeHandle, Context, - ContextImpl->get_async_handler(), KeepOwnership, backend::opencl); + ContextImpl->get_async_handler(), KeepOwnership, + backend::opencl); } } // namespace opencl } // namespace sycl From d237f850f7b492f5d82eadb6f05b45442cb32aca Mon Sep 17 00:00:00 2001 From: rehana begam Date: Wed, 7 Jul 2021 13:23:33 -0700 Subject: [PATCH 06/11] clang formatted. Signed-off-by: rehana begam --- sycl/plugins/level_zero/pi_level_zero.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sycl/plugins/level_zero/pi_level_zero.hpp b/sycl/plugins/level_zero/pi_level_zero.hpp index a129d2c84df8a..d179d562c61dc 100644 --- a/sycl/plugins/level_zero/pi_level_zero.hpp +++ b/sycl/plugins/level_zero/pi_level_zero.hpp @@ -441,8 +441,8 @@ struct _pi_queue : _pi_object { ZeCopyCommandQueue{CopyQueue}, Context{Context}, Device{Device}, QueueBatchSize{BatchSize > 0 ? BatchSize : DynamicBatchStartSize}, UseDynamicBatching{BatchSize == 0}, - PiQueueProperties(PiQueueProperties), - OwnZeCommandQueue{OwnZeCommandQueue} {} + PiQueueProperties(PiQueueProperties), OwnZeCommandQueue{ + OwnZeCommandQueue} {} // Level Zero compute command queue handle. ze_command_queue_handle_t ZeComputeCommandQueue; From 9bd92cccd4395c1521d5c3c9aa4bf9f78594537e Mon Sep 17 00:00:00 2001 From: rehana begam Date: Thu, 8 Jul 2021 17:14:53 -0700 Subject: [PATCH 07/11] fixed the lit-test fail. Signed-off-by: rehana begam --- sycl/include/CL/sycl/backend.hpp | 9 +++++---- sycl/plugins/level_zero/pi_level_zero.cpp | 2 +- sycl/plugins/level_zero/pi_level_zero.hpp | 18 +++++++++--------- sycl/source/backend.cpp | 4 ++-- sycl/source/backend/level_zero.cpp | 10 ++++++++-- sycl/source/backend/opencl.cpp | 7 +++---- sycl/source/detail/queue_impl.hpp | 4 +--- 7 files changed, 29 insertions(+), 25 deletions(-) diff --git a/sycl/include/CL/sycl/backend.hpp b/sycl/include/CL/sycl/backend.hpp index b01a1d9adf9e8..a87c2fda3cb06 100644 --- a/sycl/include/CL/sycl/backend.hpp +++ b/sycl/include/CL/sycl/backend.hpp @@ -92,7 +92,8 @@ __SYCL_EXPORT context make_context(pi_native_handle NativeHandle, backend Backend); __SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle, const context &TargetContext, - const async_handler &Handler, bool KeepOwnership, + bool KeepOwnership, + const async_handler &Handler, backend Backend); __SYCL_EXPORT event make_event(pi_native_handle NativeHandle, const context &TargetContext, backend Backend); @@ -140,10 +141,10 @@ typename std::enable_if< detail::InteropFeatureSupportMap::MakeQueue == true, queue>::type make_queue(const typename backend_traits::template input_type &BackendObject, - const context &TargetContext, const async_handler Handler = {}, - bool KeepOwnership = true) { + const context &TargetContext, bool KeepOwnership, + const async_handler Handler = {}) { return detail::make_queue(detail::pi::cast(BackendObject), - TargetContext, Handler, KeepOwnership, Backend); + TargetContext, KeepOwnership, Handler, Backend); } template diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index 202aaf8bbc183..4ba94862541a7 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -2411,7 +2411,7 @@ pi_result piQueueCreate(pi_context Context, pi_device Device, try { *Queue = new _pi_queue(ZeComputeCommandQueue, ZeCopyCommandQueue, Context, - Device, ZeCommandListBatchSize, Properties, true); + Device, ZeCommandListBatchSize, true, Properties); } catch (const std::bad_alloc &) { return PI_OUT_OF_HOST_MEMORY; } catch (...) { diff --git a/sycl/plugins/level_zero/pi_level_zero.hpp b/sycl/plugins/level_zero/pi_level_zero.hpp index d179d562c61dc..4b9e05e846ab9 100644 --- a/sycl/plugins/level_zero/pi_level_zero.hpp +++ b/sycl/plugins/level_zero/pi_level_zero.hpp @@ -434,15 +434,14 @@ const pi_uint32 DynamicBatchStartSize = 4; struct _pi_queue : _pi_object { _pi_queue(ze_command_queue_handle_t Queue, ze_command_queue_handle_t CopyQueue, pi_context Context, - pi_device Device, pi_uint32 BatchSize, - pi_queue_properties PiQueueProperties = 0, - bool OwnZeCommandQueue = true) + pi_device Device, pi_uint32 BatchSize, bool OwnZeCommandQueue, + pi_queue_properties PiQueueProperties = 0) : ZeComputeCommandQueue{Queue}, ZeCopyCommandQueue{CopyQueue}, Context{Context}, Device{Device}, QueueBatchSize{BatchSize > 0 ? BatchSize : DynamicBatchStartSize}, + OwnZeCommandQueue{OwnZeCommandQueue}, UseDynamicBatching{BatchSize == 0}, - PiQueueProperties(PiQueueProperties), OwnZeCommandQueue{ - OwnZeCommandQueue} {} + PiQueueProperties(PiQueueProperties) {} // Level Zero compute command queue handle. ze_command_queue_handle_t ZeComputeCommandQueue; @@ -494,11 +493,16 @@ struct _pi_queue : _pi_object { // is thread safe because of the locking of the queue that occurs. pi_uint32 QueueBatchSize = {0}; + // Indicates if we own the ZeCommandQueue or it came from interop that + // asked to not transfer the ownership to SYCL RT. + bool OwnZeCommandQueue; + // specifies whether this queue will be using dynamic batch size adjustment // or not. This is set only at queue creation time, and is therefore // const for the life of the queue. const bool UseDynamicBatching; + // These two members are used to keep track of how often the // batching closes and executes a command list before reaching the // QueueBatchSize limit, versus how often we reach the limit. @@ -532,10 +536,6 @@ struct _pi_queue : _pi_object { // Keeps the properties of this queue. pi_queue_properties PiQueueProperties; - // Indicates if we own the ZeCommandQueue or it came from interop that - // asked to not transfer the ownership to SYCL RT. - bool OwnZeCommandQueue = true; - // Returns true if the queue is a in-order queue. bool isInOrderQueue() const; diff --git a/sycl/source/backend.cpp b/sycl/source/backend.cpp index 9cf210188c610..6f56ad9938087 100644 --- a/sycl/source/backend.cpp +++ b/sycl/source/backend.cpp @@ -78,8 +78,8 @@ __SYCL_EXPORT context make_context(pi_native_handle NativeHandle, } __SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle, - const context &Context, - const async_handler &Handler, bool KeepOwnership, + const context &Context, bool KeepOwnership, + const async_handler &Handler, backend Backend) { const auto &Plugin = getPlugin(Backend); const auto &ContextImpl = getSyclObjImpl(Context); diff --git a/sycl/source/backend/level_zero.cpp b/sycl/source/backend/level_zero.cpp index df3472d177585..f89ccfbbb3844 100644 --- a/sycl/source/backend/level_zero.cpp +++ b/sycl/source/backend/level_zero.cpp @@ -82,11 +82,17 @@ __SYCL_EXPORT queue make_queue(const context &Context, pi_native_handle NativeHandle, bool KeepOwnership) { const auto &ContextImpl = getSyclObjImpl(Context); - return detail::make_queue(NativeHandle, Context, - ContextImpl->get_async_handler(), KeepOwnership, + return detail::make_queue(NativeHandle, Context, KeepOwnership, + ContextImpl->get_async_handler(), backend::level_zero); } +// TODO: remove this version (without ownership) when allowed to break ABI. +__SYCL_EXPORT queue make_queue(const context &Context, + pi_native_handle NativeHandle) { + return make_queue(Context, NativeHandle, false); +} + } // namespace level_zero } // namespace sycl } // __SYCL_INLINE_NAMESPACE(cl) diff --git a/sycl/source/backend/opencl.cpp b/sycl/source/backend/opencl.cpp index 118d2c5302b48..de72fb702f344 100644 --- a/sycl/source/backend/opencl.cpp +++ b/sycl/source/backend/opencl.cpp @@ -50,11 +50,10 @@ __SYCL_EXPORT program make_program(const context &Context, //---------------------------------------------------------------------------- // Implementation of opencl::make __SYCL_EXPORT queue make_queue(const context &Context, - pi_native_handle NativeHandle, - bool KeepOwnership) { + pi_native_handle NativeHandle) { const auto &ContextImpl = getSyclObjImpl(Context); - return detail::make_queue(NativeHandle, Context, - ContextImpl->get_async_handler(), KeepOwnership, + return detail::make_queue(NativeHandle, Context, false, + ContextImpl->get_async_handler(), backend::opencl); } } // namespace opencl diff --git a/sycl/source/detail/queue_impl.hpp b/sycl/source/detail/queue_impl.hpp index e259c838b00c6..4e7dbb750ad7b 100644 --- a/sycl/source/detail/queue_impl.hpp +++ b/sycl/source/detail/queue_impl.hpp @@ -115,9 +115,7 @@ class queue_impl { DeviceImplPtr(new device_impl(Device, Context->getPlatformImpl())); // TODO catch an exception and put it to list of asynchronous exceptions - if (Plugin.getBackend() == cl::sycl::backend::opencl) { - getPlugin().call(MQueues[0]); - } + getPlugin().call(MQueues[0]); } ~queue_impl() { From 458672c2f03c3eafbe474b3dccd598d2a8c5b9ec Mon Sep 17 00:00:00 2001 From: rehana begam Date: Thu, 8 Jul 2021 17:37:12 -0700 Subject: [PATCH 08/11] clang formatted. Signed-off-by: rehana begam --- sycl/include/CL/sycl/backend.hpp | 6 ++---- sycl/plugins/level_zero/pi_level_zero.hpp | 5 ++--- sycl/source/backend.cpp | 3 +-- sycl/source/backend/opencl.cpp | 3 +-- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/sycl/include/CL/sycl/backend.hpp b/sycl/include/CL/sycl/backend.hpp index a87c2fda3cb06..6809f4ea5fb97 100644 --- a/sycl/include/CL/sycl/backend.hpp +++ b/sycl/include/CL/sycl/backend.hpp @@ -91,10 +91,8 @@ __SYCL_EXPORT context make_context(pi_native_handle NativeHandle, const async_handler &Handler, backend Backend); __SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle, - const context &TargetContext, - bool KeepOwnership, - const async_handler &Handler, - backend Backend); + const context &TargetContext, bool KeepOwnership, + const async_handler &Handler, backend Backend); __SYCL_EXPORT event make_event(pi_native_handle NativeHandle, const context &TargetContext, backend Backend); __SYCL_EXPORT kernel make_kernel(pi_native_handle NativeHandle, diff --git a/sycl/plugins/level_zero/pi_level_zero.hpp b/sycl/plugins/level_zero/pi_level_zero.hpp index 4b9e05e846ab9..1bed511f729f0 100644 --- a/sycl/plugins/level_zero/pi_level_zero.hpp +++ b/sycl/plugins/level_zero/pi_level_zero.hpp @@ -439,8 +439,8 @@ struct _pi_queue : _pi_object { : ZeComputeCommandQueue{Queue}, ZeCopyCommandQueue{CopyQueue}, Context{Context}, Device{Device}, QueueBatchSize{BatchSize > 0 ? BatchSize : DynamicBatchStartSize}, - OwnZeCommandQueue{OwnZeCommandQueue}, - UseDynamicBatching{BatchSize == 0}, + OwnZeCommandQueue{OwnZeCommandQueue}, UseDynamicBatching{BatchSize == + 0}, PiQueueProperties(PiQueueProperties) {} // Level Zero compute command queue handle. @@ -502,7 +502,6 @@ struct _pi_queue : _pi_object { // const for the life of the queue. const bool UseDynamicBatching; - // These two members are used to keep track of how often the // batching closes and executes a command list before reaching the // QueueBatchSize limit, versus how often we reach the limit. diff --git a/sycl/source/backend.cpp b/sycl/source/backend.cpp index 6f56ad9938087..aaeefd7aa314a 100644 --- a/sycl/source/backend.cpp +++ b/sycl/source/backend.cpp @@ -79,8 +79,7 @@ __SYCL_EXPORT context make_context(pi_native_handle NativeHandle, __SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle, const context &Context, bool KeepOwnership, - const async_handler &Handler, - backend Backend) { + const async_handler &Handler, backend Backend) { const auto &Plugin = getPlugin(Backend); const auto &ContextImpl = getSyclObjImpl(Context); // Create PI queue first. diff --git a/sycl/source/backend/opencl.cpp b/sycl/source/backend/opencl.cpp index de72fb702f344..7e76478c8e630 100644 --- a/sycl/source/backend/opencl.cpp +++ b/sycl/source/backend/opencl.cpp @@ -53,8 +53,7 @@ __SYCL_EXPORT queue make_queue(const context &Context, pi_native_handle NativeHandle) { const auto &ContextImpl = getSyclObjImpl(Context); return detail::make_queue(NativeHandle, Context, false, - ContextImpl->get_async_handler(), - backend::opencl); + ContextImpl->get_async_handler(), backend::opencl); } } // namespace opencl } // namespace sycl From 066ed64849c80bd52db5005fe86b4cd19a1c8361 Mon Sep 17 00:00:00 2001 From: rehana begam Date: Thu, 8 Jul 2021 20:06:35 -0700 Subject: [PATCH 09/11] fix review comments. Signed-off-by: rehana begam --- sycl/include/CL/sycl/backend.hpp | 3 +++ sycl/plugins/level_zero/pi_level_zero.cpp | 7 +++++-- sycl/source/backend.cpp | 6 ++++++ sycl/test/abi/sycl_symbols_linux.dump | 6 ++++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/sycl/include/CL/sycl/backend.hpp b/sycl/include/CL/sycl/backend.hpp index 6809f4ea5fb97..958822776fc09 100644 --- a/sycl/include/CL/sycl/backend.hpp +++ b/sycl/include/CL/sycl/backend.hpp @@ -93,6 +93,9 @@ __SYCL_EXPORT context make_context(pi_native_handle NativeHandle, __SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle, const context &TargetContext, bool KeepOwnership, const async_handler &Handler, backend Backend); +__SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle, + const context &TargetContext, + const async_handler &Handler, backend Backend); __SYCL_EXPORT event make_event(pi_native_handle NativeHandle, const context &TargetContext, backend Backend); __SYCL_EXPORT kernel make_kernel(pi_native_handle NativeHandle, diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index 4ba94862541a7..19247b222495d 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -2497,13 +2497,16 @@ pi_result piQueueRelease(pi_queue Queue) { if (Queue->OwnZeCommandQueue) { ZE_CALL(zeCommandQueueDestroy, (Queue->ZeComputeCommandQueue)); - Queue->ZeComputeCommandQueue = nullptr; if (Queue->ZeCopyCommandQueue) { ZE_CALL(zeCommandQueueDestroy, (Queue->ZeCopyCommandQueue)); - Queue->ZeCopyCommandQueue = nullptr; } } + Queue->ZeComputeCommandQueue = nullptr; + if (Queue->ZeCopyCommandQueue) { + Queue->ZeCopyCommandQueue = nullptr; + } + zePrint("piQueueRelease NumTimesClosedFull %d, NumTimesClosedEarly %d\n", Queue->NumTimesClosedFull, Queue->NumTimesClosedEarly); } diff --git a/sycl/source/backend.cpp b/sycl/source/backend.cpp index aaeefd7aa314a..97d055965873f 100644 --- a/sycl/source/backend.cpp +++ b/sycl/source/backend.cpp @@ -77,6 +77,12 @@ __SYCL_EXPORT context make_context(pi_native_handle NativeHandle, std::make_shared(PiContext, Handler, Plugin)); } +__SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle, + const context &Context, + const async_handler &Handler, backend Backend) { + return make_queue(NativeHandle, Context, false, Handler, Backend); + } + __SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle, const context &Context, bool KeepOwnership, const async_handler &Handler, backend Backend) { diff --git a/sycl/test/abi/sycl_symbols_linux.dump b/sycl/test/abi/sycl_symbols_linux.dump index 368c1276ebf2b..fadfd99bc18e7 100644 --- a/sycl/test/abi/sycl_symbols_linux.dump +++ b/sycl/test/abi/sycl_symbols_linux.dump @@ -3590,6 +3590,7 @@ _ZN2cl10__host_std9u_sub_satEhh _ZN2cl10__host_std9u_sub_satEjj _ZN2cl10__host_std9u_sub_satEmm _ZN2cl10__host_std9u_sub_satEtt +_ZN2cl4sycl10level_zero10make_queueERKNS0_7contextEm _ZN2cl4sycl10level_zero10make_queueERKNS0_7contextEmb _ZN2cl4sycl10level_zero11make_deviceERKNS0_8platformEm _ZN2cl4sycl10level_zero12make_contextERKSt6vectorINS0_6deviceESaIS3_EEm @@ -3741,7 +3742,8 @@ _ZN2cl4sycl6detail10image_implILi3EED0Ev _ZN2cl4sycl6detail10image_implILi3EED1Ev _ZN2cl4sycl6detail10image_implILi3EED2Ev _ZN2cl4sycl6detail10make_eventEmRKNS0_7contextENS0_7backendE -_ZN2cl4sycl6detail10make_queueEmRKNS0_7contextERKSt8functionIFvNS0_14exception_listEEEbNS0_7backendE +_ZN2cl4sycl6detail10make_queueEmRKNS0_7contextERKSt8functionIFvNS0_14exception_listEEENS0_7backendE +_ZN2cl4sycl6detail10make_queueEmRKNS0_7contextEbRKSt8functionIFvNS0_14exception_listEEENS0_7backendE _ZN2cl4sycl6detail10waitEventsESt6vectorINS0_5eventESaIS3_EE _ZN2cl4sycl6detail11SYCLMemObjT10releaseMemESt10shared_ptrINS1_12context_implEEPv _ZN2cl4sycl6detail11SYCLMemObjT16determineHostPtrERKSt10shared_ptrINS1_12context_implEEbRPvRb @@ -3856,7 +3858,7 @@ _ZN2cl4sycl6mallocEmRKNS0_5queueENS0_3usm5allocE _ZN2cl4sycl6mallocEmRKNS0_5queueENS0_3usm5allocERKNS0_13property_listE _ZN2cl4sycl6mallocEmRKNS0_6deviceERKNS0_7contextENS0_3usm5allocE _ZN2cl4sycl6mallocEmRKNS0_6deviceERKNS0_7contextENS0_3usm5allocERKNS0_13property_listE -_ZN2cl4sycl6opencl10make_queueERKNS0_7contextEmb +_ZN2cl4sycl6opencl10make_queueERKNS0_7contextEm _ZN2cl4sycl6opencl11make_deviceEm _ZN2cl4sycl6opencl12make_contextEm _ZN2cl4sycl6opencl12make_programERKNS0_7contextEm From ea9b3f434cc6e46ce764dee55c1cb8180ea9e328 Mon Sep 17 00:00:00 2001 From: rehana begam Date: Thu, 8 Jul 2021 20:11:29 -0700 Subject: [PATCH 10/11] clang formatted. Signed-off-by: rehana begam --- sycl/source/backend.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/source/backend.cpp b/sycl/source/backend.cpp index 97d055965873f..94e31f82e2cc5 100644 --- a/sycl/source/backend.cpp +++ b/sycl/source/backend.cpp @@ -81,7 +81,7 @@ __SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle, const context &Context, const async_handler &Handler, backend Backend) { return make_queue(NativeHandle, Context, false, Handler, Backend); - } +} __SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle, const context &Context, bool KeepOwnership, From 39e9f6d22fd09e964984dc676067b73244bbae01 Mon Sep 17 00:00:00 2001 From: rehana begam Date: Fri, 9 Jul 2021 13:04:40 -0700 Subject: [PATCH 11/11] fixed the lit fail. Signed-off-by: rehana begam --- sycl/plugins/opencl/pi_opencl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/plugins/opencl/pi_opencl.cpp b/sycl/plugins/opencl/pi_opencl.cpp index 2cf1bff6fd32a..1f7b602211c3d 100644 --- a/sycl/plugins/opencl/pi_opencl.cpp +++ b/sycl/plugins/opencl/pi_opencl.cpp @@ -354,8 +354,8 @@ pi_result piQueueCreate(pi_context context, pi_device device, pi_result piextQueueCreateWithNativeHandle(pi_native_handle nativeHandle, pi_context, pi_queue *piQueue, bool ownNativeHandle) { + (void)ownNativeHandle; assert(piQueue != nullptr); - assert(ownNativeHandle == false); *piQueue = reinterpret_cast(nativeHandle); return PI_SUCCESS; }