Skip to content

[SYCL] Refactor of [[intel::private_copies()] and [[intel::max_replicates()]] attributes #3251

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 21 commits into from
Mar 10, 2021

Conversation

smanna12
Copy link
Contributor

@smanna12 smanna12 commented Feb 23, 2021

This patch

  1. refactors two declaration attributes using [SYCL] Refactor the way we handle duplicate attribute logic #3224:
    [[intel::private_copies()] and [[intel::max_replicates()]] to better fit for community standards.
  2. refactors the way we handle duplicate attributes and
    mutually exclusive attributes logic when present on a given declaration.
  3. handles redeclarations or template instantiations properly.
  4. adds test

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

…ates()]] attributes

This patch
 1. refactors two declaration attributes: [[intel::private_copies()] and [[intel::max_replicates()]]
    using intel#3224 as a template to better fit for community standards.
 2. refactors the way we handle duplicate attributes and
    mutually exclusive attributes logic when present on a given declaration.
 3. handles redeclarations or template instantiations properly.
 4. adds test

Signed-off-by: Soumi Manna <[email protected]>
@smanna12 smanna12 closed this Feb 23, 2021
@smanna12 smanna12 reopened this Feb 23, 2021
Signed-off-by: Soumi Manna <[email protected]>
@smanna12 smanna12 changed the title [SYCL] Refactor of [[intel::private_copies()] and [[intel::max_replic… [SYCL] [WIP] Refactor of [[intel::private_copies()] and [[intel::max_replic… Feb 23, 2021
@smanna12 smanna12 changed the title [SYCL] [WIP] Refactor of [[intel::private_copies()] and [[intel::max_replic… [SYCL] [WIP] Refactor of [[intel::private_copies()] and [[intel::max_replicates()]] attributes Feb 23, 2021
Signed-off-by: Soumi Manna <[email protected]>
@smanna12
Copy link
Contributor Author

The patch will be rebased after #3234 lands.

@smanna12 smanna12 changed the title [SYCL] [WIP] Refactor of [[intel::private_copies()] and [[intel::max_replicates()]] attributes [SYCL] Refactor of [[intel::private_copies()] and [[intel::max_replicates()]] attributes Feb 23, 2021
@smanna12 smanna12 changed the title [SYCL] Refactor of [[intel::private_copies()] and [[intel::max_replicates()]] attributes [SYCL] [WIP] Refactor of [[intel::private_copies()] and [[intel::max_replicates()]] attributes Feb 23, 2021
Signed-off-by: Soumi Manna <[email protected]>
@smanna12 smanna12 changed the title [SYCL] [WIP] Refactor of [[intel::private_copies()] and [[intel::max_replicates()]] attributes [SYCL] Refactor of [[intel::private_copies()] and [[intel::max_replicates()]] attributes Feb 23, 2021
@smanna12 smanna12 marked this pull request as ready for review February 25, 2021 14:21
@smanna12
Copy link
Contributor Author

Thanks @AaronBallman for feedbacks. I will address them and submit new patch.

@smanna12 smanna12 requested a review from AaronBallman March 6, 2021 04:13
Comment on lines 6017 to 6024
// [[intel::max_replicates()]] and [[intel::fpga_register]]
// attributes are incompatible.
if (const auto *DeclAttr = D->getAttr<IntelFPGARegisterAttr>()) {
Diag(DeclAttr->getLoc(), diag::err_attributes_are_not_compatible)
<< &A << DeclAttr;
Diag(A.getLoc(), diag::note_conflicting_attribute);
return nullptr;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not add checkAttrMutualExclusion<> here since this will generate incompatible attribute on first line instead of second line

// Merging of incompatible args
[[intel::max_replicates(12)]] extern const int var_max_replicates_2;
[[intel::fpga_register]] const int var_max_replicates_2 = 0;

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, the other merge*Attr use checkAttrMutualExclusion(), so I don't think the order is incorrect.

D holds the attributes we've already applied, so if D has an IntelFPGARegisterAttr, then the conflict we want to report is not with that attribute, but with the one we're about to add (IntelFPGAMaxReplicatesAttr). From that perspective, I think your code is diagnosing the opposite of what I'd expect -- it is diagnosing the IntelFPGARegisterAttr attribute location as being incompatible, but that's not the incompatible attribute -- the attempt to merge in IntelFPGAMaxReplicatesAttr is.

If you still think the behavior is wrong when using checkAttrMutualExclusion<>, can you post the exact diagnostic output you're getting from it?

Copy link
Contributor Author

@smanna12 smanna12 Mar 8, 2021

Choose a reason for hiding this comment

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

@AaronBallman, thanks for the feedback.

I think your code is diagnosing the opposite of what I'd expect -- it is diagnosing the IntelFPGARegisterAttr attribute location as being incompatible,

Yes, this is what happening here.

I confused myself with CheckMutualExclusionSYCLLoopAttribute() that the incompatible diagnostic will be on second line where we have IntelFPGARegisterAttr attribute on declaration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the output from checkAttrMutualExclusion<> with the current patch:

// Merging of incompatible attributes
//expected-error@+2{{'max_replicates' and 'fpga_register' attributes are not compatible}}
//expected-note@+2{{conflicting attribute is here}}
[[intel::max_replicates(12)]] extern const int var_max_replicates_2;
[[intel::fpga_register]] const int var_max_replicates_2 =0;

Copy link
Contributor

Choose a reason for hiding this comment

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

That order looks wrong to me. I'd expect:

[[intel::max_replicates(12)]] extern const int var_max_replicates_2; // expected-note {{conflicting attribute is here}}
[[intel::fpga_register]] const int var_max_replicates_2 =0; // expected-error {{'max_replicates' and 'fpga_register' attributes are not compatible}}

One question I have is: are you sure this behavior isn't coming from checkIntelFPGARegisterAttrCompatibility() rather than this change?

Copy link
Contributor Author

@smanna12 smanna12 Mar 8, 2021

Choose a reason for hiding this comment

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

That order looks wrong to me. I'd expect:

[[intel::max_replicates(12)]] extern const int var_max_replicates_2; // expected-note {{conflicting attribute is here}}
[[intel::fpga_register]] const int var_max_replicates_2 =0; // expected-error {{'max_replicates' and 'fpga_register' attributes are not compatible}}

This is what i had before checkAttrMutualExclusion<>

// attributes are incompatible.
if (const auto *DeclAttr = D->getAttr<IntelFPGARegisterAttr>()) {
  Diag(DeclAttr->getLoc(), diag::err_attributes_are_not_compatible)
      << &A << DeclAttr;
  Diag(A.getLoc(), diag::note_conflicting_attribute);
  return nullptr;
}

checkAttrMutualExclusion<>  function changes the order because of this:

template <typename AttrTy>
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const Attr &AL) {
if (const auto *A = D->getAttr<AttrTy>()) {
  S.Diag(AL.getLocation(), diag::err_attributes_are_not_compatible) << &AL
                                                                    << A;
  S.Diag(A->getLocation(), diag::note_conflicting_attribute);
  return true;
}
return false;
}


Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for checking! I don't want us to get too hung up on this, but something fishy is going on that I'm not quite understanding. Your code looks like it should issue the diagnostics in the wrong order -- you check to see if the declaration has an existing IntelFPGARegisterAttr attribute and if it does, it issues the diagnostic on that previous attribute (not the one being added). It then notes the one being added as being the conflicting attribute. This is backwards -- the initial attribute is fine (there were no attributes on the declaration for it to conflict with), it's the second attribute location that should be diagnosed as the error (rather than the note).

Are all of the merge*Attr() functions which call checkAttrMutualExclusion getting the order wrong? (I suppose that's a possibility I hadn't considered.) Or is it perhaps because we don't have any merge function for IntelFPGARegisterAttr when we should have one

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks to some excellent detective work from @smanna12, we figured out that this is a community issue. All of the merge functions currently calling checkAttrMutualExclusion() have the same backwards diagnostic behavior. Yay for getting to the bottom of the mystery!

I think you should use checkAttrMutualExclusion() and add a FIXME comment to the test about this behavior not being ideal, but it being an issue that should be solved in community. I don't think we need to rush to get a fix into community because the diagnostic behavior here is sufficient for users to understand what's wrong with their code, even if the diagnostic location isn't ideal (redeclaration merging is a bit of an edge case for attribute handling).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @AaronBallman for the comments and the detailed explanation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added FIXME comments in the test.

smanna12 added 3 commits March 7, 2021 10:45
Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
Signed-off-by: Soumi Manna <[email protected]>
S.CheckDeprecatedSYCLAttributeSpelling(A);

S.addIntelSingleArgAttr<IntelFPGAMaxReplicatesAttr>(D, A, A.getArgAsExpr(0));
Expr *E = A.getArgAsExpr(0);
S.AddIntelFPGAMaxReplicatesAttr(D, A, E);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
S.AddIntelFPGAMaxReplicatesAttr(D, A, E);
S.AddIntelFPGAMaxReplicatesAttr(D, A, A.getArgAsExpr(0));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

S.CheckDeprecatedSYCLAttributeSpelling(A);

S.addIntelSingleArgAttr<IntelFPGAPrivateCopiesAttr>(D, A, A.getArgAsExpr(0));
Expr *E = A.getArgAsExpr(0);
S.AddIntelFPGAPrivateCopiesAttr(D, A, E);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
S.AddIntelFPGAPrivateCopiesAttr(D, A, E);
S.AddIntelFPGAPrivateCopiesAttr(D, A, A.getArgAsExpr(0));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@smanna12 smanna12 requested review from premanandrao and removed request for AaronBallman March 8, 2021 21:25
Signed-off-by: Soumi Manna <[email protected]>
AaronBallman
AaronBallman previously approved these changes Mar 9, 2021
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.

LGTM!

@smanna12
Copy link
Contributor Author

smanna12 commented Mar 9, 2021

Thanks @AaronBallman.

@smanna12
Copy link
Contributor Author

smanna12 commented Mar 9, 2021

@premanandrao / @elizabethandrews , can you please review this? Thanks.

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.

Just a few nits

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!

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.

5 participants