Skip to content

Commit

Permalink
[SYCL] reqd_work_group_size attribute is reversed (fix intel#14)
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksander Fadeev <[email protected]>
  • Loading branch information
fadeeval committed Mar 6, 2020
1 parent 8696f6e commit dc704bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 44 deletions.
8 changes: 0 additions & 8 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -2420,14 +2420,6 @@ def ReqdWorkGroupSize : InheritableAttr {
let Documentation = [Undocumented];
}

def SYCLIntelReqdWorkGroupSize : InheritableAttr {
let Spellings = [CXX11<"intel","reqd_work_group_size">];
let Args = [IntArgument<"XDim">, DefaultIntArgument<"YDim", 1>,
DefaultIntArgument<"ZDim", 1>];
let Subjects = SubjectList<[Function], ErrorDiag>;
let Documentation = [Undocumented];
}

def WorkGroupSizeHint : InheritableAttr {
// Does not have a [[]] spelling because it is an OpenCL-related attribute.
let Spellings = [GNU<"work_group_size_hint">];
Expand Down
46 changes: 10 additions & 36 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2898,32 +2898,15 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr,
/*ReverseAttrs=*/true);

if (const auto *A = D->getAttr<SYCLIntelMaxWorkGroupSizeAttr>()) {
if (S.getLangOpts().SYCLIsDevice &&
!(WGSize[2] <= A->getXDim() && WGSize[1] <= A->getYDim() &&
WGSize[0] <= A->getZDim())) {
S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes)
<< Attr << A->getSpelling();
Result &= false;
}
if (!S.getLangOpts().SYCLIsDevice &&
!(WGSize[0] <= A->getXDim() && WGSize[1] <= A->getYDim() &&
if (!(WGSize[0] <= A->getXDim() && WGSize[1] <= A->getYDim() &&
WGSize[2] <= A->getZDim())) {
S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes)
<< Attr << A->getSpelling();
Result &= false;
}
}
if (const auto *A = D->getAttr<ReqdWorkGroupSizeAttr>()) {

if (S.getLangOpts().SYCLIsDevice &&
!(WGSize[2] >= A->getXDim() && WGSize[1] >= A->getYDim() &&
WGSize[0] >= A->getZDim())) {
S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes)
<< Attr << A->getSpelling();
Result &= false;
}
if (!S.getLangOpts().SYCLIsDevice &&
!(WGSize[0] >= A->getXDim() && WGSize[1] >= A->getYDim() &&
if (!(WGSize[0] >= A->getXDim() && WGSize[1] >= A->getYDim() &&
WGSize[2] >= A->getZDim())) {
S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes)
<< Attr << A->getSpelling();
Expand All @@ -2940,13 +2923,9 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
return;

uint32_t WGSize[3];
if (const auto *A = D->getAttr<SYCLIntelReqdWorkGroupSizeAttr>()){
WGSize[1] = SYCLIntelReqdWorkGroupSizeAttr::DefaultYDim;
WGSize[2] = SYCLIntelReqdWorkGroupSizeAttr::DefaultZDim;
}
for (unsigned i = 0; i < 3; ++i) {
const Expr *E = AL.getArgAsExpr(i);
if (i < AL.getNumArgs() && !checkUInt32Argument(S, AL, E, WGSize[i], i,
if (!checkUInt32Argument(S, AL, E, WGSize[i], i,
/*StrictlyUnsigned=*/true))
return;
if (WGSize[i] == 0) {
Expand All @@ -2956,25 +2935,20 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
}
}

// For a SYCLDevice WorkGroupAttr arguments are reversed
if (S.getLangOpts().SYCLIsDevice) {
std::swap(WGSize[0], WGSize[2]);
}
WorkGroupAttr *Existing = D->getAttr<WorkGroupAttr>();
if (S.getLangOpts().SYCLIsDevice && Existing &&
!(Existing->getXDim() == WGSize[2] && Existing->getYDim() == WGSize[1] &&
Existing->getZDim() == WGSize[0]))
S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
if (!S.getLangOpts().SYCLIsDevice && Existing &&
if (Existing &&
!(Existing->getXDim() == WGSize[0] && Existing->getYDim() == WGSize[1] &&
Existing->getZDim() == WGSize[2]))
S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;

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

if (S.getLangOpts().SYCLIsDevice)
D->addAttr(::new (S.Context) WorkGroupAttr(S.Context, AL, WGSize[2],
WGSize[1], WGSize[0]));
else
D->addAttr(::new (S.Context) WorkGroupAttr(S.Context, AL, WGSize[0],
WGSize[1], WGSize[2]));
D->addAttr(::new (S.Context)
WorkGroupAttr(S.Context, AL, WGSize[0], WGSize[1], WGSize[2]));
}

// Handles intel_reqd_sub_group_size.
Expand Down

0 comments on commit dc704bf

Please sign in to comment.