Skip to content

[SYCL][FPGA] Refactor of [[intel::max_global_work_dim()]] attribute #3326

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 35 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3614707
[SYCL][FPGA] Refactor of [[intel::max_global_work_dim()]] attribute
smanna12 Mar 9, 2021
bda9eef
Fix errors
smanna12 Mar 9, 2021
a56f449
Fix errors
smanna12 Mar 9, 2021
86509bf
address review comments
smanna12 Mar 9, 2021
165f537
Update comments
smanna12 Mar 9, 2021
1f82fa3
remove paren
smanna12 Mar 9, 2021
0b88e5c
Merge remote-tracking branch 'my_remote/sycl' into MaxGlobalAttr
smanna12 Mar 10, 2021
9e6a71e
Remove generic template function addIntelSingleArgAttr(), remove -fsy…
smanna12 Mar 10, 2021
a17f9cd
address review comments
smanna12 Mar 11, 2021
586a2d9
Fix errors
smanna12 Mar 11, 2021
22bc2d3
Merge remote-tracking branch 'my_remote/sycl' into MaxGlobalAttr
smanna12 Mar 11, 2021
f172eb4
don't duplicate the attribute with the same arguments
smanna12 Mar 20, 2021
422e730
Merge remote-tracking branch 'my_remote/sycl' into MaxGlobalAttr
smanna12 Mar 20, 2021
93e00ba
Fix lit test failure
smanna12 Mar 20, 2021
2833331
Upadte test
smanna12 Mar 20, 2021
0be1b62
Update logic for dropping duplicate attribute with same arguments and…
smanna12 Mar 21, 2021
afb6849
Refcator duplicate attr logic for same argument and add test
smanna12 Mar 21, 2021
70f87ca
Address review comments
smanna12 Mar 24, 2021
17166de
address review comments
smanna12 Mar 25, 2021
c5c31f1
Merge remote-tracking branch 'my_remote/sycl' into MaxGlobalAttr
smanna12 May 13, 2021
1ba0baa
handle dependent argument values and addressed review comments
smanna12 May 13, 2021
c4d5423
fix format issues
smanna12 May 13, 2021
8600280
fix wrong value
smanna12 May 13, 2021
56a36ee
adress review comments
smanna12 May 14, 2021
d8effc1
address review comments
smanna12 May 24, 2021
af29f9a
Merge remote-tracking branch 'my_remote/sycl' into MaxGlobalAttr
smanna12 May 24, 2021
a9ad2c4
Fix clang format issues
smanna12 May 24, 2021
ce62808
address review comments
smanna12 May 25, 2021
2ccb247
Merge remote-tracking branch 'my_remote/sycl' into MaxGlobalAttr
smanna12 May 25, 2021
f6c7c57
fix format issues
smanna12 May 25, 2021
a1139cd
address review comments
smanna12 May 26, 2021
45a294b
fix format issues
smanna12 May 26, 2021
65da4b8
address review comments
smanna12 May 26, 2021
5d5f1fa
fix format issues
smanna12 May 26, 2021
618bb3e
address review comments
smanna12 May 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -10234,6 +10234,11 @@ class Sema final {
Expr *E);
SYCLIntelLoopFuseAttr *
MergeSYCLIntelLoopFuseAttr(Decl *D, const SYCLIntelLoopFuseAttr &A);
void AddSYCLIntelMaxGlobalWorkDimAttr(Decl *D, const AttributeCommonInfo &CI,
Expr *E);
SYCLIntelMaxGlobalWorkDimAttr *
MergeSYCLIntelMaxGlobalWorkDimAttr(Decl *D,
const SYCLIntelMaxGlobalWorkDimAttr &A);

/// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E,
Expand Down Expand Up @@ -13100,20 +13105,6 @@ void Sema::addIntelSingleArgAttr(Decl *D, const AttributeCommonInfo &CI,
return;
}
}
if (CI.getParsedKind() == ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim) {
if (ArgInt < 0) {
Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)
<< CI << /*non-negative*/ 1;
return;
}
}
if (CI.getParsedKind() == ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim) {
if (ArgInt > 3) {
Diag(E->getBeginLoc(), diag::err_attribute_argument_out_of_range)
<< CI << 0 << 3 << E->getSourceRange();
return;
}
}
if (CI.getParsedKind() == ParsedAttr::AT_IntelFPGAPrivateCopies) {
if (ArgInt < 0) {
Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2626,6 +2626,8 @@ static bool mergeDeclAttribute(Sema &S, NamedDecl *D,
NewAttr = S.MergeSYCLIntelSchedulerTargetFmaxMhzAttr(D, *A);
else if (const auto *A = dyn_cast<SYCLIntelNoGlobalWorkOffsetAttr>(Attr))
NewAttr = S.MergeSYCLIntelNoGlobalWorkOffsetAttr(D, *A);
else if (const auto *A = dyn_cast<SYCLIntelMaxGlobalWorkDimAttr>(Attr))
NewAttr = S.MergeSYCLIntelMaxGlobalWorkDimAttr(D, *A);
else if (Attr->shouldInheritEvenIfAlreadyPresent() || !DeclHasAttr(D, Attr))
NewAttr = cast<InheritableAttr>(Attr->clone(S.Context));

Expand Down
99 changes: 86 additions & 13 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3430,23 +3430,96 @@ static void handleSYCLIntelSchedulerTargetFmaxMhzAttr(Sema &S, Decl *D,
}

// Handles max_global_work_dim.
static void handleMaxGlobalWorkDimAttr(Sema &S, Decl *D, const ParsedAttr &A) {
if (D->isInvalidDecl())
return;

Expr *E = A.getArgAsExpr(0);
void Sema::AddSYCLIntelMaxGlobalWorkDimAttr(Decl *D,
const AttributeCommonInfo &CI,
Expr *E) {
if (!E->isValueDependent()) {
// Validate that we have an integer constant expression and then store the
// converted constant expression into the semantic attribute so that we
// don't have to evaluate it again later.
llvm::APSInt ArgVal;
ExprResult Res = VerifyIntegerConstantExpression(E, &ArgVal);
if (Res.isInvalid())
return;
E = Res.get();

if (!checkWorkGroupSizeValues(S, D, A)) {
D->setInvalidDecl();
return;
// This attribute requires a non-negative value.
if (ArgVal < 0) {
Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)
<< CI << /*non-negative*/ 1;
return;
}
// This attribute must be in the range [0, 3].
if (ArgVal > 3) {
Diag(E->getBeginLoc(), diag::err_attribute_argument_out_of_range)
<< CI << 0 << 3 << E->getSourceRange();
return;
}
// Check to see if there's a duplicate attribute with different values
// already applied to the declaration.
if (const auto *DeclAttr = D->getAttr<SYCLIntelMaxGlobalWorkDimAttr>()) {
// If the other attribute argument is instantiation dependent, we won't
// have converted it to a constant expression yet and thus we test
// whether this is a null pointer.
const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue());
if (DeclExpr && ArgVal != DeclExpr->getResultAsAPSInt()) {
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);
return;
}
}
// If the declaration has a SYCLIntelMaxWorkGroupSizeAttr or
// ReqdWorkGroupSizeAttr, check to see if they hold equal values
// (1, 1, 1) in case the value of SYCLIntelMaxGlobalWorkDimAttr
// equals to 0.
auto Check = [this, &CI](const auto *A) {
Optional<llvm::APSInt> XDimVal = A->getXDimVal(Context);
Optional<llvm::APSInt> YDimVal = A->getYDimVal(Context);
Optional<llvm::APSInt> ZDimVal = A->getZDimVal(Context);
if (*XDimVal != 1 || *YDimVal != 1 || *ZDimVal != 1) {
Diag(A->getLocation(), diag::err_sycl_x_y_z_arguments_must_be_one)
<< A << CI;
return false;
}
return true;
};
if (const auto *DeclAttr = D->getAttr<SYCLIntelMaxWorkGroupSizeAttr>()) {
if ((ArgVal == 0) && !Check(DeclAttr))
return;
}
if (const auto *DeclAttr = D->getAttr<ReqdWorkGroupSizeAttr>()) {
if ((ArgVal == 0) && !Check(DeclAttr))
return;
}
}

if (D->getAttr<SYCLIntelMaxGlobalWorkDimAttr>())
S.Diag(A.getLoc(), diag::warn_duplicate_attribute) << A;
D->addAttr(::new (Context) SYCLIntelMaxGlobalWorkDimAttr(Context, CI, E));
}

S.CheckDeprecatedSYCLAttributeSpelling(A);
SYCLIntelMaxGlobalWorkDimAttr *Sema::MergeSYCLIntelMaxGlobalWorkDimAttr(
Decl *D, const SYCLIntelMaxGlobalWorkDimAttr &A) {
// Check to see if there's a duplicate attribute with different values
// already applied to the declaration.
if (const auto *DeclAttr = D->getAttr<SYCLIntelMaxGlobalWorkDimAttr>()) {
const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getValue());
const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getValue());
if (DeclExpr && MergeExpr &&
DeclExpr->getResultAsAPSInt() != MergeExpr->getResultAsAPSInt()) {
Diag(DeclAttr->getLoc(), diag::warn_duplicate_attribute) << &A;
Diag(A.getLoc(), diag::note_previous_attribute);
return nullptr;
}
}
return ::new (Context)
SYCLIntelMaxGlobalWorkDimAttr(Context, A, A.getValue());
}

S.addIntelSingleArgAttr<SYCLIntelMaxGlobalWorkDimAttr>(D, A, E);
static void handleSYCLIntelMaxGlobalWorkDimAttr(Sema &S, Decl *D,
const ParsedAttr &AL) {
S.CheckDeprecatedSYCLAttributeSpelling(AL);

Expr *E = AL.getArgAsExpr(0);
S.AddSYCLIntelMaxGlobalWorkDimAttr(D, AL, E);
}

// Handles [[intel::loop_fuse]] and [[intel::loop_fuse_independent]].
Expand Down Expand Up @@ -9129,7 +9202,7 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
handleSYCLIntelSchedulerTargetFmaxMhzAttr(S, D, AL);
break;
case ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim:
handleMaxGlobalWorkDimAttr(S, D, AL);
handleSYCLIntelMaxGlobalWorkDimAttr(S, D, AL);
break;
case ParsedAttr::AT_SYCLIntelNoGlobalWorkOffset:
handleSYCLIntelNoGlobalWorkOffsetAttr(S, D, AL);
Expand Down
14 changes: 12 additions & 2 deletions clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,16 @@ static void instantiateSYCLIntelNoGlobalWorkOffsetAttr(
S.AddSYCLIntelNoGlobalWorkOffsetAttr(New, *A, Result.getAs<Expr>());
}

static void instantiateSYCLIntelMaxGlobalWorkDimAttr(
Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
const SYCLIntelMaxGlobalWorkDimAttr *A, Decl *New) {
EnterExpressionEvaluationContext Unevaluated(
S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
ExprResult Result = S.SubstExpr(A->getValue(), TemplateArgs);
if (!Result.isInvalid())
S.AddSYCLIntelMaxGlobalWorkDimAttr(New, *A, Result.getAs<Expr>());
}

template <typename AttrName>
static void instantiateIntelSYCLFunctionAttr(
Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
Expand Down Expand Up @@ -892,8 +902,8 @@ void Sema::InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
}
if (const auto *SYCLIntelMaxGlobalWorkDim =
dyn_cast<SYCLIntelMaxGlobalWorkDimAttr>(TmplAttr)) {
instantiateIntelSYCLFunctionAttr<SYCLIntelMaxGlobalWorkDimAttr>(
*this, TemplateArgs, SYCLIntelMaxGlobalWorkDim, New);
instantiateSYCLIntelMaxGlobalWorkDimAttr(*this, TemplateArgs,
SYCLIntelMaxGlobalWorkDim, New);
continue;
}
if (const auto *SYCLIntelLoopFuse =
Expand Down
Loading