Skip to content

Conversation

s-kanaev
Copy link
Contributor

No description provided.

Signed-off-by: Sergey Kanaev <sergey.kanaev@intel.com>
@s-kanaev s-kanaev requested a review from a team as a code owner August 24, 2021 16:33
@s-kanaev s-kanaev requested a review from smaslov-intel August 24, 2021 16:33
Signed-off-by: Sergey Kanaev <sergey.kanaev@intel.com>
@s-kanaev s-kanaev force-pushed the thread-safe-in-order-queue branch from 0ed5b4c to 9107613 Compare August 25, 2021 08:35
@s-kanaev s-kanaev requested a review from smaslov-intel August 25, 2021 08:35
@s-kanaev s-kanaev marked this pull request as draft August 27, 2021 14:55
@s-kanaev s-kanaev marked this pull request as ready for review September 9, 2021 11:02
@s-kanaev
Copy link
Contributor Author

s-kanaev commented Sep 28, 2021

@smaslov-intel , a friendly ping

if (MIsInorder && (Type == CG::CGTYPE::CodeplayHostTask ||
Type == CG::CGTYPE::CodeplayInteropTask))
Handler.depends_on(MLastEvent);
bool NeedSeparateDependencyMgmt =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used in this function other than passing it to finalizeHandler, Please just move it there.

Comment on lines +424 to +425
if (MIsInorder) {
// Accessing and changing of an event isn't atomic operation.
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec says:

The in_order property adds the requirement that the SYCL queue provides in-order semantics where tasks are executed in the order in which they are submitted. Tasks submitted in this fashion can be viewed as having an implicit dependence on the previously submitted operation.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the implementation should provide ordering between them.

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?

Copy link
Contributor Author

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.

Correct. Although, I can't see other ordering than impl-defined for the case of simultaneous calls.

Is this change fixing exactly the case where multiple threads submit simultaneously?

Absolutely. Probably, there should be spin-lock instead of mutex in some cases.

Was it just abnormally failing without this change?

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.

Copy link
Contributor

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).

@romanovvlad romanovvlad merged commit 20d9346 into intel:sycl Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants