-
Notifications
You must be signed in to change notification settings - Fork 795
[SYCL] Fix coverity issues 11/11 2025 #20614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: sycl
Are you sure you want to change the base?
Changes from 1 commit
7cd4c59
11a7046
accc1c5
61ab573
bd3f7ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -422,7 +422,7 @@ queue_impl::submit_impl(const detail::type_erased_cgfo_ty &CGF, | |
| } | ||
|
|
||
| EventImplPtr queue_impl::submit_kernel_scheduler_bypass( | ||
| KernelData &KData, std::vector<detail::EventImplPtr> &DepEvents, | ||
| KernelData &KData, const std::vector<detail::EventImplPtr> &DepEvents, | ||
| bool EventNeeded, detail::kernel_impl *KernelImplPtr, | ||
| detail::kernel_bundle_impl *KernelBundleImpPtr, | ||
| const detail::code_location &CodeLoc, bool IsTopCodeLoc) { | ||
|
|
@@ -500,8 +500,7 @@ 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->getPreparedDepsEvents() = 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 | ||
|
|
@@ -609,12 +608,11 @@ EventImplPtr queue_impl::submit_kernel_direct_impl( | |
| KData.getNDRDesc(), std::move(HostKernelPtr), | ||
| nullptr, // Kernel | ||
| nullptr, // KernelBundle | ||
| std::move(CGData), std::move(KData).getArgs(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you remove the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but we do not move the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I was not aware of that syntax... And I suppose neither is Coverity. 😆 I still have concerns regarding it, but I can revert it here and we can discuss it in #20617 (comment). |
||
| *KData.getDeviceKernelInfoPtr(), std::move(StreamStorage), | ||
| std::move(AuxiliaryResources), detail::CGType::Kernel, | ||
| KData.getKernelCacheConfig(), KData.isCooperative(), | ||
| KData.usesClusterLaunch(), KData.getKernelWorkGroupMemorySize(), | ||
| CodeLoc)); | ||
| std::move(CGData), KData.getArgs(), *KData.getDeviceKernelInfoPtr(), | ||
| std::move(StreamStorage), std::move(AuxiliaryResources), | ||
| detail::CGType::Kernel, KData.getKernelCacheConfig(), | ||
| KData.isCooperative(), KData.usesClusterLaunch(), | ||
| KData.getKernelWorkGroupMemorySize(), CodeLoc)); | ||
| CommandGroup->MIsTopCodeLoc = IsTopCodeLoc; | ||
|
|
||
| if (auto GraphImpl = getCommandGraph(); GraphImpl) { | ||
|
|
@@ -693,7 +691,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 +707,7 @@ queue_impl::submit_direct(bool CallerNeedsEvent, | |
| Deps.UnenqueuedCmdEvents.push_back(EventImpl); | ||
| } | ||
|
|
||
| return CallerNeedsEvent ? EventImpl : nullptr; | ||
| return CallerNeedsEvent ? std::move(EventImpl) : nullptr; | ||
vinser52 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| template <typename HandlerFuncT> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we have a copy instead of a move. Does Coverity report potential use after the move? If so, does actual use occur after the move? If no, I believe the proper fix should be to change the
submit_kernel_scheduler_bypassfunction to acceptDepEventsby value and move the vector when we call thesubmit_kernel_scheduler_bypass.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
It is hard to say. The issue is that the events are actually owned by another object further up. This function is effectively stealing the dependency events from the object, without that behavior being very clear. Even if use-after-move isn't present currently, it is going to be very easy for someone to not realize it has been moved and assume that the dependencies tied to the owner object are still valid.
I disagree. In the current solution, a copy only happens under certain conditions. If we change the function to take it by value we will always make a copy of the dependencies vector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem I see right now is that before this PR, we had a move in case of a certain condition. And now we will have a copy.
What I have in mind is that today we have something like this:
And I suggested considering the following:
@slawekptak, please review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the second version with double std::move should work - there is no copy and the ownership is clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed this offline with @vinser52 and we agreed that doing the by-value solution can cause unnecessary copies in certain paths. As such, I plan on refactoring this code and its callers slightly to make the ownership easier to track.