Skip to content

[SYCL] [FPGA] Add mutual diagnostic for num_simd_work_items attribute in conjunction with the reqd_work_group_size attribute #3170

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 14 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions clang/include/clang/Basic/AttrDocs.td
Original file line number Diff line number Diff line change
Expand Up @@ -2418,6 +2418,26 @@ device kernel, the attribute is not ignored and it is propagated to the kernel.
[[intel::num_simd_work_items(N)]] void operator()() const {}
};

If the`` intel::reqd_work_group_size`` or ``cl::reqd_work_group_size``
attribute is specified on a declaration along with a
intel::num_simd_work_items attribute, the work group size attribute
arguments must all be evenly divisible by the argument specified in
the ``intel::num_simd_work_items`` attribute.

.. code-block:: c++

struct func {
[[intel::num_simd_work_items(4)]]
[[intel::reqd_work_group_size(64, 64, 64)]]
void operator()() const {}
};

struct bar {
[[intel::reqd_work_group_size(64, 64, 64)]]
[[intel::num_simd_work_items(4)]]
void operator()() const {}
};

}];
}

Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -11212,6 +11212,9 @@ def err_sycl_invalid_accessor_property_list_template_param : Error<
"%select{accessor_property_list|accessor_property_list pack argument|buffer_location}0 "
"template parameter must be a "
"%select{parameter pack|type|non-negative integer}1">;
def err_sycl_num_kernel_wrong_reqd_wg_size : Error<
"%0 attribute must evenly divide the work-group size for the %1 attribute">;

def warn_sycl_pass_by_value_deprecated
: Warning<"Passing kernel functions by value is deprecated in SYCL 2020">,
InGroup<Sycl2020Compat>, ShowInSystemHeader;
Expand Down
8 changes: 5 additions & 3 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -13068,21 +13068,23 @@ void Sema::addIntelSingleArgAttr(Decl *D, const AttributeCommonInfo &CI,
return;
E = ICE.get();
int32_t ArgInt = ArgVal.getSExtValue();
if (CI.getParsedKind() == ParsedAttr::AT_SYCLIntelNumSimdWorkItems ||
CI.getParsedKind() == ParsedAttr::AT_IntelReqdSubGroupSize ||
if (CI.getParsedKind() == ParsedAttr::AT_IntelReqdSubGroupSize ||
CI.getParsedKind() == ParsedAttr::AT_IntelFPGAMaxReplicates) {
if (ArgInt <= 0) {
Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)
<< CI << /*positive*/ 0;
return;
}
}
if (CI.getParsedKind() == ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim) {
if (CI.getParsedKind() == ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim ||
CI.getParsedKind() == ParsedAttr::AT_SYCLIntelNumSimdWorkItems) {
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();
Expand Down
109 changes: 84 additions & 25 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3130,26 +3130,53 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
return;
}

if (WorkGroupAttr *ExistingAttr = D->getAttr<WorkGroupAttr>()) {
ASTContext &Ctx = S.getASTContext();
Optional<llvm::APSInt> XDimVal = XDimExpr->getIntegerConstantExpr(Ctx);
Optional<llvm::APSInt> YDimVal = YDimExpr->getIntegerConstantExpr(Ctx);
Optional<llvm::APSInt> ZDimVal = ZDimExpr->getIntegerConstantExpr(Ctx);
Optional<llvm::APSInt> ExistingXDimVal = ExistingAttr->getXDimVal(Ctx);
Optional<llvm::APSInt> ExistingYDimVal = ExistingAttr->getYDimVal(Ctx);
Optional<llvm::APSInt> ExistingZDimVal = ExistingAttr->getZDimVal(Ctx);

// Compare attribute arguments value and warn for a mismatch.
if (ExistingXDimVal != XDimVal || ExistingYDimVal != YDimVal ||
ExistingZDimVal != ZDimVal) {
S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
S.Diag(ExistingAttr->getLocation(), diag::note_conflicting_attribute);
ASTContext &Ctx = S.getASTContext();

if (!XDimExpr->isValueDependent() && !YDimExpr->isValueDependent() &&
!ZDimExpr->isValueDependent()) {
llvm::APSInt XDimVal, YDimVal, ZDimVal;
ExprResult XDim = S.VerifyIntegerConstantExpression(XDimExpr, &XDimVal);
ExprResult YDim = S.VerifyIntegerConstantExpression(YDimExpr, &YDimVal);
ExprResult ZDim = S.VerifyIntegerConstantExpression(ZDimExpr, &ZDimVal);

if (XDim.isInvalid())
return;
XDimExpr = XDim.get();

if (YDim.isInvalid())
return;
YDimExpr = YDim.get();

if (ZDim.isInvalid())
return;
ZDimExpr = ZDim.get();

if (const auto *A = D->getAttr<SYCLIntelNumSimdWorkItemsAttr>()) {
int64_t NumSimdWorkItems =
A->getValue()->getIntegerConstantExpr(Ctx)->getSExtValue();

if (!(XDimVal.getZExtValue() % NumSimdWorkItems == 0 ||
YDimVal.getZExtValue() % NumSimdWorkItems == 0 ||
ZDimVal.getZExtValue() % NumSimdWorkItems == 0)) {
S.Diag(A->getLocation(), diag::err_sycl_num_kernel_wrong_reqd_wg_size)
<< A << AL;
S.Diag(AL.getLoc(), diag::note_conflicting_attribute);
return;
}
}
if (const auto *ExistingAttr = D->getAttr<WorkGroupAttr>()) {
// Compare attribute arguments value and warn for a mismatch.
if (ExistingAttr->getXDimVal(Ctx) != XDimVal ||
ExistingAttr->getYDimVal(Ctx) != YDimVal ||
ExistingAttr->getZDimVal(Ctx) != ZDimVal) {
S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
S.Diag(ExistingAttr->getLocation(), diag::note_conflicting_attribute);
}
}
if (!checkWorkGroupSizeValues(S, D, AL))
return;
}

if (!checkWorkGroupSizeValues(S, D, AL))
return;

S.addIntelTripleArgAttr<WorkGroupAttr>(D, AL, XDimExpr, YDimExpr, ZDimExpr);
}

Expand Down Expand Up @@ -3196,18 +3223,51 @@ static void handleSubGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
}

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

Expr *E = A.getArgAsExpr(0);
Expr *E = AL.getArgAsExpr(0);

if (D->getAttr<SYCLIntelNumSimdWorkItemsAttr>())
S.Diag(A.getLoc(), diag::warn_duplicate_attribute) << A;
S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;

S.CheckDeprecatedSYCLAttributeSpelling(A);
S.CheckDeprecatedSYCLAttributeSpelling(AL);

if (!E->isValueDependent()) {
llvm::APSInt ArgVal;
ExprResult ICE = S.VerifyIntegerConstantExpression(E, &ArgVal);

S.addIntelSingleArgAttr<SYCLIntelNumSimdWorkItemsAttr>(D, A, E);
if (ICE.isInvalid())
return;

E = ICE.get();
int64_t NumSimdWorkItems = ArgVal.getSExtValue();

if (NumSimdWorkItems == 0) {
S.Diag(E->getExprLoc(), diag::err_attribute_argument_is_zero)
<< AL << E->getSourceRange();
return;
}

if (const auto *A = D->getAttr<ReqdWorkGroupSizeAttr>()) {
ASTContext &Ctx = S.getASTContext();
Optional<llvm::APSInt> XDimVal = A->getXDimVal(Ctx);
Optional<llvm::APSInt> YDimVal = A->getYDimVal(Ctx);
Optional<llvm::APSInt> ZDimVal = A->getZDimVal(Ctx);

if (!(XDimVal->getZExtValue() % NumSimdWorkItems == 0 ||
YDimVal->getZExtValue() % NumSimdWorkItems == 0 ||
ZDimVal->getZExtValue() % NumSimdWorkItems == 0)) {
S.Diag(AL.getLoc(), diag::err_sycl_num_kernel_wrong_reqd_wg_size)
<< AL << A;
S.Diag(A->getLocation(), diag::note_conflicting_attribute);
return;
}
}
}

S.addIntelSingleArgAttr<SYCLIntelNumSimdWorkItemsAttr>(D, AL, E);
}

// Handles use_stall_enable_clusters
Expand Down Expand Up @@ -5967,14 +6027,13 @@ void Sema::addSYCLIntelPipeIOAttr(Decl *D, const AttributeCommonInfo &Attr,
Optional<llvm::APSInt> ArgVal = E->getIntegerConstantExpr(getASTContext());
if (!ArgVal) {
Diag(E->getExprLoc(), diag::err_attribute_argument_type)
<< Attr.getAttrName() << AANT_ArgumentIntegerConstant
<< E->getSourceRange();
<< Attr << AANT_ArgumentIntegerConstant << E->getSourceRange();
return;
}
int32_t ArgInt = ArgVal->getSExtValue();
if (ArgInt < 0) {
Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)
<< Attr.getAttrName() << /*non-negative*/ 1;
<< Attr << /*non-negative*/ 1;
return;
}
}
Expand Down
Loading