Skip to content

[SYCL] Refactor reqd_work_group_size attribute implementation #5782

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 27 commits into from
Mar 22, 2022

Conversation

smanna12
Copy link
Contributor

@smanna12 smanna12 commented Mar 10, 2022

This patch

  1. refactors SYCL kernel function attribute reqd_work_group_size to better fit for community standards.

  2. refactors the way we handled duplicate attributes logic with when present on a given declaration.

  3. refactors the way we handled mutually exclusive attributes logic with when present on a given declaration with
    reqd_work_group_size, max_work_group_size, max_global_work_dim, and num_simd_work_items attributes.

  4. handles redeclarations or template instantiations properly.

  5. stores ConstantExpr into the semantic attribute rather than calling getIntegerConstantExpr() for attribute dimension values.

  6. fixes crash with optional arguments on ReqdWorkGroupAttr and adds missing diagnostics for merging cases when present
    on a given declaration with reqd_work_group_size, max_work_group_size, max_global_work_dim, and num_simd_work_items
    attributes.

  7. updates clang-tidy build after reqd_work_group_size attribute changes.

  8. adds tests.

This patch fixes
#5736, #5735, #5734, #5732, #5731, #3223, #3361, #3175, #3742, and #5733

Signed-off-by: Soumi Manna [email protected]

@smanna12 smanna12 marked this pull request as ready for review March 11, 2022 00:34
@smanna12 smanna12 requested review from a team and bader as code owners March 11, 2022 00:34
@smanna12 smanna12 requested a review from AaronBallman March 11, 2022 00:35
Copy link
Contributor

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

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

Looks like it's heading in the right direction at a high level. One thing that would be nice (but perhaps not easy to do) would be to see how much attribute checking code can be refactored to share between the Add and Merge functions here. They're doing the same things notionally (as best I saw), so it'd be nice to only write that logic once if possible. However, that might require more refactoring that's better left until later.

@smanna12 smanna12 linked an issue Mar 13, 2022 that may be closed by this pull request
@smanna12
Copy link
Contributor Author

smanna12 commented Mar 13, 2022

One thing that would be nice (but perhaps not easy to do) would be to see how much attribute checking code can be refactored to share between the Add and Merge functions here. They're doing the same things notionally (as best I saw), so it'd be nice to only write that logic once if possible. However, that might require more refactoring that's better left until later.

Agreed. Existing implementation of "reqd_work_group_size" is very messy condition. This refactorization will fix several missing diagnostics and compilation crashes. I would like to do this (refactor the login once) in a separate PR. Not easy way to do this. @AaronBallman, would it be OK ?

Signed-off-by: Soumi Manna <[email protected]>
@smanna12
Copy link
Contributor Author

smanna12 commented Mar 18, 2022

Sorry for the force push. I was having issues to push my changes due to recent pulldown.

Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
Copy link
Contributor

@elizabethandrews elizabethandrews left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

Just wanted to point out that #3175 might still need more work. I see tests with FIXME for default value still. So we probably should not close this bug till we're sure of optional argument behavior.

// Same for the default values.
// FIXME: This turns out to be wrong as there aren't really default values
// (that is an implementation detail we use but shouldn't expose to the user).
// Instead, the dimensionality of the attribute needs to match that of the
// kernel, so the one, two, and three arg forms of the attribute are actually
// *different* attributes. This means that you should not be able to redeclare
// the function with a different dimensionality.
[[sycl::reqd_work_group_size(4)]] void four_again();
[[sycl::reqd_work_group_size(4)]] void four_again(); // OK
[[sycl::reqd_work_group_size(4, 1)]] void four_again(); // OK
[[sycl::reqd_work_group_size(4, 1)]] void four_again(); // OK
[[sycl::reqd_work_group_size(4, 1, 1)]] void four_again(); // OK
[[sycl::reqd_work_group_size(4, 1, 1)]] void four_again(); // OK

@smanna12
Copy link
Contributor Author

smanna12 commented Mar 18, 2022

LGTM. Thanks!

Just wanted to point out that #3175 might still need more work. I see tests with FIXME for default value still. So we probably should not close this bug till we're sure of optional argument behavior.

// Same for the default values.
// FIXME: This turns out to be wrong as there aren't really default values
// (that is an implementation detail we use but shouldn't expose to the user).
// Instead, the dimensionality of the attribute needs to match that of the
// kernel, so the one, two, and three arg forms of the attribute are actually
// *different* attributes. This means that you should not be able to redeclare
// the function with a different dimensionality.
[[sycl::reqd_work_group_size(4)]] void four_again();
[[sycl::reqd_work_group_size(4)]] void four_again(); // OK
[[sycl::reqd_work_group_size(4, 1)]] void four_again(); // OK
[[sycl::reqd_work_group_size(4, 1)]] void four_again(); // OK
[[sycl::reqd_work_group_size(4, 1, 1)]] void four_again(); // OK
[[sycl::reqd_work_group_size(4, 1, 1)]] void four_again(); // OK

Thanks for the reviews!
This issues is covered by #3743

Just wanted to point out that #3175 might still need more work

This is related to NULL value check issue and assertion, so this is covered by current patch.

bader
bader previously approved these changes Mar 19, 2022
@smanna12
Copy link
Contributor Author

ping @premanandrao and @AaronBallman

Copy link
Contributor

@premanandrao premanandrao left a comment

Choose a reason for hiding this comment

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

All minor nits. Changes are getting way better @smanna12!

@smanna12 smanna12 dismissed stale reviews from bader and elizabethandrews via f376e43 March 21, 2022 16:20
@smanna12 smanna12 requested a review from premanandrao March 21, 2022 16:26
@smanna12
Copy link
Contributor Author

@AaronBallman, are you OK with the patch? Do you have any more concerns? Thank you

@AaronBallman
Copy link
Contributor

@AaronBallman, are you OK with the patch? Do you have any more concerns? Thank you

Nope, this LGTM (I didn't spot anything with my quick once over from today).

@smanna12
Copy link
Contributor Author

Thank you everyone for the reviews!

@@ -84,3 +84,18 @@ int check() {
// CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}}
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}}

// No diagnostic is emitted because the arguments match. Duplicate attribute is silently ignored.
[[sycl::reqd_work_group_size(4, 4, 4)]] [[sycl::reqd_work_group_size(4, 4, 4)]] void func4() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not push new symmetrical examples/test like this.
Any mixing X, Y and Z would just pass the test.

@smanna12 smanna12 deleted the Refactor_Reqd_Work_Group_Size_Attr branch March 27, 2022 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment