diff --git a/sycl/include/sycl/queue.hpp b/sycl/include/sycl/queue.hpp index 23008e75b80fb..729bc2b7e76da 100644 --- a/sycl/include/sycl/queue.hpp +++ b/sycl/include/sycl/queue.hpp @@ -2963,7 +2963,9 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase { Rest...); } +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES buffer &getAssertHappenedBuffer(); +#endif event memcpyToDeviceGlobal(void *DeviceGlobalPtr, const void *Src, bool IsDeviceImageScope, size_t NumBytes, @@ -3017,9 +3019,7 @@ class AssertInfoCopier; */ event submitAssertCapture(queue &Self, event &Event, queue *SecondaryQueue, const detail::code_location &CodeLoc) { - using AHBufT = buffer; - - AHBufT &Buffer = Self.getAssertHappenedBuffer(); + buffer Buffer{1}; event CopierEv, CheckerEv, PostCheckerEv; auto CopierCGF = [&](handler &CGH) { diff --git a/sycl/source/detail/queue_impl.hpp b/sycl/source/detail/queue_impl.hpp index 0c27a177dbf1a..2bfe4ab75c7e3 100644 --- a/sycl/source/detail/queue_impl.hpp +++ b/sycl/source/detail/queue_impl.hpp @@ -108,7 +108,9 @@ class queue_impl { const async_handler &AsyncHandler, const property_list &PropList) : MDevice(Device), MContext(Context), MAsyncHandler(AsyncHandler), MPropList(PropList), MHostQueue(MDevice->is_host()), +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES MAssertHappenedBuffer(range<1>{1}), +#endif MIsInorder(has_property()), MDiscardEvents( has_property()), @@ -283,7 +285,9 @@ class queue_impl { queue_impl(sycl::detail::pi::PiQueue PiQueue, const ContextImplPtr &Context, const async_handler &AsyncHandler) : MContext(Context), MAsyncHandler(AsyncHandler), MHostQueue(false), +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES MAssertHappenedBuffer(range<1>{1}), +#endif MIsInorder(has_property()), MDiscardEvents( has_property()), @@ -305,7 +309,10 @@ class queue_impl { queue_impl(sycl::detail::pi::PiQueue PiQueue, const ContextImplPtr &Context, const async_handler &AsyncHandler, const property_list &PropList) : MContext(Context), MAsyncHandler(AsyncHandler), MPropList(PropList), - MHostQueue(false), MAssertHappenedBuffer(range<1>{1}), + MHostQueue(false), +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES + MAssertHappenedBuffer(range<1>{1}), +#endif MIsInorder(has_property()), MDiscardEvents( has_property()), @@ -670,9 +677,11 @@ class queue_impl { /// \return a native handle. pi_native_handle getNative(int32_t &NativeHandleDesc) const; +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES buffer &getAssertHappenedBuffer() { return MAssertHappenedBuffer; } +#endif void registerStreamServiceEvent(const EventImplPtr &Event) { std::lock_guard Lock(MMutex); @@ -888,8 +897,10 @@ class queue_impl { /// need to emulate it with multiple native in-order queues. bool MEmulateOOO = false; +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES // Buffer to store assert failure descriptor buffer MAssertHappenedBuffer; +#endif // This event is employed for enhanced dependency tracking with in-order queue // Access to the event should be guarded with MLastEventMtx diff --git a/sycl/source/queue.cpp b/sycl/source/queue.cpp index 109e6396a0341..6ca29b8505d50 100644 --- a/sycl/source/queue.cpp +++ b/sycl/source/queue.cpp @@ -268,9 +268,11 @@ pi_native_handle queue::getNative(int32_t &NativeHandleDesc) const { return impl->getNative(NativeHandleDesc); } +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES buffer &queue::getAssertHappenedBuffer() { return impl->getAssertHappenedBuffer(); } +#endif event queue::memcpyToDeviceGlobal(void *DeviceGlobalPtr, const void *Src, bool IsDeviceImageScope, size_t NumBytes, diff --git a/sycl/test-e2e/Assert/check_resource_leak.cpp b/sycl/test-e2e/Assert/check_resource_leak.cpp new file mode 100644 index 0000000000000..252d2ed9e0c49 --- /dev/null +++ b/sycl/test-e2e/Assert/check_resource_leak.cpp @@ -0,0 +1,32 @@ +// RUN: %{build} -o %t.out +// RUN: %{run} %t.out + +// Device globals aren't supported on opencl:gpu yet. +// UNSUPPORTED: opencl && gpu + +// TODO: Fails at JIT compilation for some reason. +// UNSUPPORTED: hip +#define SYCL_FALLBACK_ASSERT 1 + +#include + +// DeviceGlobalUSMMem::~DeviceGlobalUSMMem() has asserts to ensure some +// resources have been cleaned up when it's executed. Those asserts used to fail +// when "AssertHappened" buffer used in fallback implementation of the device +// assert was a data member of the queue_impl. +sycl::ext::oneapi::experimental::device_global dg; + +int main() { + sycl::queue q; + q.submit([&](sycl::handler &cgh) { + sycl::range<1> R{16}; + cgh.parallel_for(sycl::nd_range<1>{R, R}, [=](sycl::nd_item<1> ndi) { + if (ndi.get_global_linear_id() == 0) + dg.get() = 42; + auto sg = sycl::ext::oneapi::experimental::this_sub_group(); + auto active = sycl::ext::oneapi::group_ballot(sg, 1); + }); + }).wait(); + + return 0; +}