-
Notifications
You must be signed in to change notification settings - Fork 803
[SYCL] Add thread safety to host-task submit to in-order queue #4395
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
92305e5
[SYCL] Add thread safety to host-task submit to in-order queue
9107613
Fixes and comments
cd0f0ee
Update queue_impl.hpp
8553620
Merge remote-tracking branch 'public/sycl' into thread-safe-in-order-…
0fe5f96
Merge remote-tracking branch 'public/sycl' into thread-safe-in-order-…
a8f52ab
Fix merge conflict resolution glitch
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -419,6 +419,23 @@ class queue_impl { | |
} | ||
|
||
private: | ||
void finalizeHandler(handler &Handler, bool NeedSeparateDependencyMgmt, | ||
event &EventRet) { | ||
if (MIsInorder) { | ||
// Accessing and changing of an event isn't atomic operation. | ||
// Hence, here is the lock for thread-safety. | ||
std::lock_guard<std::mutex> Lock{MLastEventMtx}; | ||
|
||
if (NeedSeparateDependencyMgmt) | ||
Handler.depends_on(MLastEvent); | ||
|
||
EventRet = Handler.finalize(); | ||
|
||
MLastEvent = EventRet; | ||
} else | ||
EventRet = Handler.finalize(); | ||
} | ||
|
||
/// Performs command group submission to the queue. | ||
/// | ||
/// \param CGF is a function object containing command group. | ||
|
@@ -437,9 +454,9 @@ class queue_impl { | |
// Host and interop tasks, however, are not submitted to low-level runtimes | ||
// and require separate dependency management. | ||
const CG::CGTYPE Type = Handler.getType(); | ||
if (MIsInorder && (Type == CG::CGTYPE::CodeplayHostTask || | ||
Type == CG::CGTYPE::CodeplayInteropTask)) | ||
Handler.depends_on(MLastEvent); | ||
bool NeedSeparateDependencyMgmt = | ||
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. This is not used in this function other than passing it to |
||
MIsInorder && (Type == CG::CGTYPE::CodeplayHostTask || | ||
Type == CG::CGTYPE::CodeplayInteropTask); | ||
|
||
event Event; | ||
|
||
|
@@ -452,14 +469,11 @@ class queue_impl { | |
: ProgramManager::getInstance().kernelUsesAssert( | ||
Handler.MOSModuleHandle, Handler.MKernelName); | ||
|
||
Event = Handler.finalize(); | ||
finalizeHandler(Handler, NeedSeparateDependencyMgmt, Event); | ||
|
||
(*PostProcess)(IsKernel, KernelUsesAssert, Event); | ||
} else | ||
Event = Handler.finalize(); | ||
|
||
if (MIsInorder) | ||
MLastEvent = Event; | ||
finalizeHandler(Handler, NeedSeparateDependencyMgmt, Event); | ||
|
||
addEvent(Event); | ||
return Event; | ||
|
@@ -521,7 +535,11 @@ class queue_impl { | |
// Buffer to store assert failure descriptor | ||
buffer<AssertHappened, 1> MAssertHappenedBuffer; | ||
|
||
// This event is employed for enhanced dependency tracking with in-order queue | ||
// Access to the event should be guarded with MLastEventMtx | ||
event MLastEvent; | ||
std::mutex MLastEventMtx; | ||
|
||
const bool MIsInorder; | ||
}; | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What does spec say about thread-safety of the in-order queue? If multiple threads concurrently submit commands to the same in-order queue then no order is guaranteed, right?
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 spec says:
I believe, the following can be considered as correct.
When several threads attempt to submit a command simultaneously, the implementation should provide ordering between them.
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.
But this would be implementation-defined ordering, right? So no clear in-order semantics.
Is this change fixing exactly the case where multiple threads submit simultaneously?
Was it just abnormally failing without this change?
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.
Correct. Although, I can't see other ordering than impl-defined for the case of simultaneous calls.
Absolutely. Probably, there should be spin-lock instead of mutex in some cases.
I didn't observe such failures yet. This issue was found by eyeballing. I expect the issue is hard to reproduce due small size of non-atomic change.
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.
NIT: I suggest adding a comment explaining that this lock doesn't provide any specific order for the in-order queue, but just to served competing requests safely (in arbitrary order).