diff --git a/sycl/source/backend.cpp b/sycl/source/backend.cpp index 5f7ac8af1e1fb..304d5c8cce436 100644 --- a/sycl/source/backend.cpp +++ b/sycl/source/backend.cpp @@ -223,7 +223,7 @@ make_kernel_bundle(ur_native_handle_t NativeHandle, sizeof(ur_device_handle_t) * NumDevices, ProgramDevices.data(), nullptr); for (auto &Dev : ProgramDevices) { - ur_program_binary_type_t BinaryType; + ur_program_binary_type_t BinaryType = UR_PROGRAM_BINARY_TYPE_NONE; Adapter.call( UrProgram, Dev, UR_PROGRAM_BUILD_INFO_BINARY_TYPE, sizeof(ur_program_binary_type_t), &BinaryType, nullptr); diff --git a/sycl/source/detail/adapter_impl.hpp b/sycl/source/detail/adapter_impl.hpp index 383f095312117..67619dbea1558 100644 --- a/sycl/source/detail/adapter_impl.hpp +++ b/sycl/source/detail/adapter_impl.hpp @@ -296,7 +296,11 @@ template class Managed { if (!R) return; - Adapter->call(R); + try { + Adapter->call(R); + } catch (std::exception &e) { + __SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~Managed", e); + } } Managed retain() { diff --git a/sycl/source/detail/context_impl.cpp b/sycl/source/detail/context_impl.cpp index 6fb2dd375fe37..1e45e0882a63e 100644 --- a/sycl/source/detail/context_impl.cpp +++ b/sycl/source/detail/context_impl.cpp @@ -433,7 +433,7 @@ std::vector context_impl::initializeDeviceGlobals( } // Write the pointer to the device global and store the event in the // initialize events list. - ur_event_handle_t InitEvent; + ur_event_handle_t InitEvent = nullptr; void *const &USMPtr = DeviceGlobalUSM.getPtr(); Adapter.call( QueueImpl.getHandleRef(), NativePrg, diff --git a/sycl/source/detail/device_binary_image.cpp b/sycl/source/detail/device_binary_image.cpp index c8ff57631bb60..0b73dd3628784 100644 --- a/sycl/source/detail/device_binary_image.cpp +++ b/sycl/source/detail/device_binary_image.cpp @@ -452,6 +452,10 @@ mergeDeviceRequirements(const std::vector &Imgs) { size_t Pos = 0; do { const size_t NextPos = Contents.find(';', Pos); + if (NextPos == std::string::npos) { + Set.emplace(Contents.substr(Pos)); + break; + } if (NextPos != Pos) Set.emplace(Contents.substr(Pos, NextPos - Pos)); Pos = NextPos + 1; diff --git a/sycl/source/detail/device_global_map_entry.cpp b/sycl/source/detail/device_global_map_entry.cpp index 25704caaee6de..d710ed999296a 100644 --- a/sycl/source/detail/device_global_map_entry.cpp +++ b/sycl/source/detail/device_global_map_entry.cpp @@ -18,23 +18,28 @@ inline namespace _V1 { namespace detail { DeviceGlobalUSMMem::~DeviceGlobalUSMMem() { - // removeAssociatedResources is expected to have cleaned up both the pointer - // and the event. When asserts are enabled the values are set, so we check - // these here. - auto ContextImplPtr = MAllocatingContext.lock(); - if (ContextImplPtr) { - if (MPtr != nullptr) { - detail::usm::freeInternal(MPtr, ContextImplPtr.get()); - MPtr = nullptr; + try { + // removeAssociatedResources is expected to have cleaned up both the pointer + // and the event. When asserts are enabled the values are set, so we check + // these here. + auto ContextImplPtr = MAllocatingContext.lock(); + if (ContextImplPtr) { + if (MPtr != nullptr) { + detail::usm::freeInternal(MPtr, ContextImplPtr.get()); + MPtr = nullptr; + } + if (MInitEvent != nullptr) { + ContextImplPtr->getAdapter().call( + MInitEvent); + MInitEvent = nullptr; + } } - if (MInitEvent != nullptr) { - ContextImplPtr->getAdapter().call(MInitEvent); - MInitEvent = nullptr; - } - } - assert(MPtr == nullptr && "MPtr has not been cleaned up."); - assert(MInitEvent == nullptr && "MInitEvent has not been cleaned up."); + assert(MPtr == nullptr && "MPtr has not been cleaned up."); + assert(MInitEvent == nullptr && "MInitEvent has not been cleaned up."); + } catch (std::exception &e) { + __SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~DeviceGlobalUSMMem", e); + } } OwnedUrEvent DeviceGlobalUSMMem::getInitEvent(adapter_impl &Adapter) { @@ -80,7 +85,7 @@ DeviceGlobalMapEntry::getOrAllocateDeviceGlobalUSM(queue_impl &QueueImpl) { // Initialize here and save the event. { std::lock_guard Lock(NewAlloc.MInitEventMutex); - ur_event_handle_t InitEvent; + ur_event_handle_t InitEvent = nullptr; if (MDeviceGlobalPtr) { // C++ guarantees members appear in memory in the order they are declared, // so since the member variable that contains the initial contents of the diff --git a/sycl/source/detail/device_image_impl.hpp b/sycl/source/detail/device_image_impl.hpp index e688af8f3190c..a716da4514d19 100644 --- a/sycl/source/detail/device_image_impl.hpp +++ b/sycl/source/detail/device_image_impl.hpp @@ -326,7 +326,7 @@ class device_image_impl updateSpecConstSymMap(); } - device_image_impl(const std::string &Src, context Context, + device_image_impl(const std::string &Src, const context &Context, devices_range Devices, syclex::source_language Lang, include_pairs_t &&IncludePairsVec, private_tag) : MBinImage(Src), MContext(Context), diff --git a/sycl/source/detail/device_impl.hpp b/sycl/source/detail/device_impl.hpp index fa63f69dc5968..ae0303e0a3ead 100644 --- a/sycl/source/detail/device_impl.hpp +++ b/sycl/source/detail/device_impl.hpp @@ -190,7 +190,7 @@ class device_impl : public std::enable_shared_from_this { return {Error}; return {Result}; } else { - ur_ret_t Result; + ur_ret_t Result{}; ur_result_t Error = getAdapter().call_nocheck( getHandleRef(), Desc, sizeof(Result), &Result, nullptr); if (Error == UR_RESULT_SUCCESS) @@ -220,7 +220,7 @@ class device_impl : public std::enable_shared_from_this { getHandleRef(), Desc, ResultSize, Result.data(), nullptr); return Result; } else { - ur_ret_t Result; + ur_ret_t Result{}; getAdapter().call( getHandleRef(), Desc, sizeof(Result), &Result, nullptr); return Result; diff --git a/sycl/source/detail/event_impl.hpp b/sycl/source/detail/event_impl.hpp index 53727aa0505ba..0f98ac3958aa0 100644 --- a/sycl/source/detail/event_impl.hpp +++ b/sycl/source/detail/event_impl.hpp @@ -318,7 +318,8 @@ class event_impl { ur_exp_command_buffer_sync_point_t getSyncPoint() const { return MSyncPoint; } void setCommandGraph( - std::shared_ptr Graph) { + const std::shared_ptr + &Graph) { MGraph = Graph; } diff --git a/sycl/source/detail/memory_manager.cpp b/sycl/source/detail/memory_manager.cpp index f3bab09e2ca33..2501730dfccaa 100644 --- a/sycl/source/detail/memory_manager.cpp +++ b/sycl/source/detail/memory_manager.cpp @@ -445,7 +445,7 @@ void *MemoryManager::allocateMemSubBuffer(context_impl *TargetContext, ur_result_t Error = UR_RESULT_SUCCESS; ur_buffer_region_t Region = {UR_STRUCTURE_TYPE_BUFFER_REGION, nullptr, Offset, SizeInBytes}; - ur_mem_handle_t NewMem; + ur_mem_handle_t NewMem = nullptr; adapter_impl &Adapter = TargetContext->getAdapter(); Error = Adapter.call_nocheck( ur::cast(ParentMemObj), UR_MEM_FLAG_READ_WRITE, diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index 1d39a89a4dd45..0ceed42a73d17 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -693,6 +693,10 @@ ProgramManager::collectDeviceImageDepsForImportedSymbols( throw exception(make_error_code(errc::feature_not_supported), "Cannot resolve external symbols, linking is unsupported " "for the backend"); + + // Access to m_ExportedSymbolImages must be guarded by m_KernelIDsMutex. + std::lock_guard KernelIDsGuard(m_KernelIDsMutex); + while (!WorkList.empty()) { std::string Symbol = WorkList.front(); WorkList.pop(); diff --git a/sycl/source/detail/queue_impl.cpp b/sycl/source/detail/queue_impl.cpp index 5b7bfb5e90fae..424abbe38664d 100644 --- a/sycl/source/detail/queue_impl.cpp +++ b/sycl/source/detail/queue_impl.cpp @@ -500,7 +500,6 @@ EventImplPtr queue_impl::submit_kernel_scheduler_bypass( ResultEvent->setEnqueued(); // connect returned event with dependent events if (!isInOrder()) { - // DepEvents is not used anymore, so can move. ResultEvent->getPreparedDepsEvents() = std::move(DepEvents); // ResultEvent is local for current thread, no need to lock. ResultEvent->cleanDepEventsThroughOneLevelUnlocked(); @@ -581,7 +580,7 @@ EventImplPtr queue_impl::submit_kernel_direct_impl( KData.validateAndSetKernelLaunchProperties(Props, hasCommandGraph(), getDeviceImpl()); - auto SubmitKernelFunc = [&](detail::CG::StorageInitHelper &CGData, + auto SubmitKernelFunc = [&](detail::CG::StorageInitHelper &&CGData, bool SchedulerBypass) -> EventImplPtr { if (SchedulerBypass) { // No need to copy/move the kernel function, so we set @@ -693,7 +692,8 @@ queue_impl::submit_direct(bool CallerNeedsEvent, MNoLastEventMode.store(isInOrder() && SchedulerBypass, std::memory_order_relaxed); - EventImplPtr EventImpl = SubmitCommandFunc(CGData, SchedulerBypass); + EventImplPtr EventImpl = + SubmitCommandFunc(std::move(CGData), SchedulerBypass); // Sync with the last event for in order queue. For scheduler-bypass flow, // the ordering is done at the layers below the SYCL runtime, @@ -708,7 +708,7 @@ queue_impl::submit_direct(bool CallerNeedsEvent, Deps.UnenqueuedCmdEvents.push_back(EventImpl); } - return CallerNeedsEvent ? EventImpl : nullptr; + return CallerNeedsEvent ? std::move(EventImpl) : nullptr; } template diff --git a/sycl/source/detail/queue_impl.hpp b/sycl/source/detail/queue_impl.hpp index 7c793b619ecab..b7c74e07c2681 100644 --- a/sycl/source/detail/queue_impl.hpp +++ b/sycl/source/detail/queue_impl.hpp @@ -602,7 +602,8 @@ class queue_impl : public std::enable_shared_from_this { bool CallerNeedsEvent); void setCommandGraphUnlocked( - std::shared_ptr Graph) { + const std::shared_ptr + &Graph) { MGraph = Graph; MExtGraphDeps.reset(); @@ -614,7 +615,8 @@ class queue_impl : public std::enable_shared_from_this { } void setCommandGraph( - std::shared_ptr Graph) { + const std::shared_ptr + &Graph) { std::lock_guard Lock(MMutex); setCommandGraphUnlocked(Graph); }