Skip to content

Commit 68c459a

Browse files
committed
[FPGA][SYCL] Fix max_work_group_size and reqd_work_group_size attribute arguments check
If the [[intel::max_work_group_size(X, Y, Z)]] attribute is specified on a declaration along with [[sycl::reqd_work_group_size(X1, Y1, Z1)]] attribute, this patch checks if values of reqd_work_group_size arguments are equal or less than values of max_work_group_size attribute arguments. Some of the test cases were missed during refactoring work with PGA function attribute [[intel::max_work_group_size()]] on intel#5392 This patch fixes them. Signed-off-by: Soumi Manna <[email protected]>
1 parent c228f12 commit 68c459a

File tree

3 files changed

+82
-8
lines changed

3 files changed

+82
-8
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3523,6 +3523,23 @@ static bool InvalidWorkGroupSizeAttrs(const Expr *MGValue, const Expr *XDim,
35233523
ZDimExpr->getResultAsAPSInt() != 1));
35243524
}
35253525

3526+
// If the [[intel::max_work_group_size(X, Y, Z)]] attribute is specified on
3527+
// a declaration along with [[sycl::reqd_work_group_size(X1, Y1, Z1)]]
3528+
// attribute, check to see if values of reqd_work_group_size arguments are
3529+
// equal or less than values of max_work_group_size attribute arguments.
3530+
static bool checkWorkGroupSizeAttrValues(const Expr *LHS, const Expr *RHS) {
3531+
// If any of the operand is still value dependent, we can't test anything.
3532+
const auto *LHSCE = dyn_cast<ConstantExpr>(LHS);
3533+
const auto *RHSCE = dyn_cast<ConstantExpr>(RHS);
3534+
3535+
if (!LHSCE || !RHSCE)
3536+
return false;
3537+
3538+
// Otherwise, check if value of reqd_work_group_size argument is
3539+
// equal or less than value of max_work_group_size attribute argument.
3540+
return !(LHSCE->getResultAsAPSInt() <= RHSCE->getResultAsAPSInt());
3541+
}
3542+
35263543
void Sema::AddSYCLIntelMaxWorkGroupSizeAttr(Decl *D,
35273544
const AttributeCommonInfo &CI,
35283545
Expr *XDim, Expr *YDim,
@@ -3556,6 +3573,20 @@ void Sema::AddSYCLIntelMaxWorkGroupSizeAttr(Decl *D,
35563573
if (!XDim || !YDim || !ZDim)
35573574
return;
35583575

3576+
// If the [[intel::max_work_group_size(X, Y, Z)]] attribute is specified on
3577+
// a declaration along with [[sycl::reqd_work_group_size(X1, Y1, Z1)]]
3578+
// attribute, check to see if values of reqd_work_group_size arguments are
3579+
// equal or less than values of max_work_group_size attribute arguments.
3580+
if (const auto *DeclAttr = D->getAttr<ReqdWorkGroupSizeAttr>()) {
3581+
if (checkWorkGroupSizeAttrValues(DeclAttr->getXDim(), XDim),
3582+
checkWorkGroupSizeAttrValues(DeclAttr->getYDim(), YDim),
3583+
checkWorkGroupSizeAttrValues(DeclAttr->getZDim(), ZDim)) {
3584+
Diag(CI.getLoc(), diag::err_conflicting_sycl_function_attributes)
3585+
<< CI << DeclAttr->getSpelling();
3586+
return;
3587+
}
3588+
}
3589+
35593590
// If the declaration has a SYCLIntelMaxWorkGroupSizeAttr, check to see if
35603591
// the attribute holds equal values to (1, 1, 1) in case the value of
35613592
// SYCLIntelMaxGlobalWorkDimAttr equals to 0.
@@ -3616,6 +3647,20 @@ SYCLIntelMaxWorkGroupSizeAttr *Sema::MergeSYCLIntelMaxWorkGroupSizeAttr(
36163647
return nullptr;
36173648
}
36183649

3650+
// If the [[intel::max_work_group_size(X, Y, Z)]] attribute is specified on
3651+
// a declaration along with [[sycl::reqd_work_group_size(X1, Y1, Z1)]]
3652+
// attribute, check to see if values of reqd_work_group_size arguments are
3653+
// equal or less than values of max_work_group_size attribute arguments.
3654+
if (const auto *DeclAttr = D->getAttr<ReqdWorkGroupSizeAttr>()) {
3655+
if (checkWorkGroupSizeAttrValues(DeclAttr->getXDim(), A.getXDim()),
3656+
checkWorkGroupSizeAttrValues(DeclAttr->getYDim(), A.getYDim()),
3657+
checkWorkGroupSizeAttrValues(DeclAttr->getZDim(), A.getZDim())) {
3658+
Diag(DeclAttr->getLoc(), diag::err_conflicting_sycl_function_attributes)
3659+
<< DeclAttr << A.getSpelling();
3660+
return nullptr;
3661+
}
3662+
}
3663+
36193664
// If the declaration has a SYCLIntelMaxWorkGroupSizeAttr,
36203665
// check to see if the attribute holds equal values to
36213666
// (1, 1, 1) in case the value of SYCLIntelMaxGlobalWorkDimAttr

clang/test/SemaSYCL/intel-max-work-group-size.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ class Functor {
3030
[[intel::max_work_group_size(16, 16, 16)]] [[intel::max_work_group_size(32, 32, 32)]] void operator()(int) const; // expected-warning {{attribute 'max_work_group_size' is already applied with different arguments}} expected-note {{previous attribute is here}}
3131
};
3232

33+
class FunctorC {
34+
public:
35+
[[sycl::reqd_work_group_size(64, 64, 64)]] [[intel::max_work_group_size(16, 16, 16)]] void operator()() const; //expected-error{{'max_work_group_size' attribute conflicts with 'reqd_work_group_size' attribute}}
36+
[[sycl::reqd_work_group_size(64, 64, 64)]] [[intel::max_work_group_size(16, 16, 16)]] void operator()(int) const; //expected-error{{'max_work_group_size' attribute conflicts with 'reqd_work_group_size' attribute}}
37+
};
38+
3339
// Ensure that template arguments behave appropriately based on instantiations.
3440
template <int N>
3541
[[intel::max_work_group_size(N, 1, 1)]] void f6(); // #f6
@@ -59,3 +65,31 @@ void instantiate() {
5965
// expected-note@#f7prev {{previous attribute is here}}
6066
f7<2, 2, 2>(); // expected-note {{in instantiation}}
6167
}
68+
69+
70+
// If the [[intel::max_work_group_size(X, Y, Z)]] attribute is specified on
71+
// a declaration along with [[sycl::reqd_work_group_size(X1, Y1, Z1)]]
72+
// attribute, check to see if values of reqd_work_group_size arguments are
73+
// equal or less than values coming from max_work_group_size attribute.
74+
[[sycl::reqd_work_group_size(64, 64, 64)]]
75+
[[intel::max_work_group_size(16, 16, 16)]] //expected-error{{'max_work_group_size' attribute conflicts with 'reqd_work_group_size' attribute}}
76+
void f9() {}
77+
78+
[[intel::max_work_group_size(4, 4, 4)]] void f10();
79+
[[sycl::reqd_work_group_size(2, 2, 2)]] void f10(); // OK
80+
81+
[[sycl::reqd_work_group_size(2, 2, 2)]]
82+
[[intel::max_work_group_size(4, 4, 4)]] void f11() {} // OK
83+
84+
// FIXME: We do not have support yet for checking
85+
// reqd_work_group_size and max_work_group_size
86+
// attributes when merging, so the test compiles without
87+
// any diagnostic when it shouldn't.
88+
[[sycl::reqd_work_group_size(64, 64, 64)]] void f12();
89+
[[intel::max_work_group_size(16, 16, 16)]] void f12(); // expected error but now OK.
90+
91+
[[intel::max_work_group_size(16, 16, 16)]]
92+
[[sycl::reqd_work_group_size(64, 64, 64)]] void f13() {} // expected-error{{'reqd_work_group_size' attribute conflicts with 'max_work_group_size' attribute}}
93+
94+
[[intel::max_work_group_size(16, 16, 16)]] void f14();
95+
[[sycl::reqd_work_group_size(64, 64, 64)]] void f14(); // expected-error{{'reqd_work_group_size' attribute conflicts with 'max_work_group_size' attribute}}

clang/test/SemaSYCL/redeclaration-attribute-propagation.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,8 @@ func1();
2020

2121
#else
2222
//second case - expect error
23-
[[intel::max_work_group_size(4, 4, 4)]] // expected-note {{conflicting attribute is here}}
24-
void
25-
func2();
26-
27-
[[sycl::reqd_work_group_size(8, 8, 8)]] // expected-note {{conflicting attribute is here}}
28-
void
29-
func2() {}
23+
[[intel::max_work_group_size(4, 4, 4)]] void func2();
24+
[[sycl::reqd_work_group_size(8, 8, 8)]] void func2() {} // expected-error {{'reqd_work_group_size' attribute conflicts with 'max_work_group_size' attribute}}
3025

3126
//third case - expect error
3227
[[sycl::reqd_work_group_size(4, 4, 4)]] // expected-note {{conflicting attribute is here}}
@@ -77,7 +72,7 @@ int main() {
7772

7873
#else
7974
h.single_task<class test_kernel2>(
80-
[]() { func2(); }); // expected-error {{conflicting attributes applied to a SYCL kernel or SYCL_EXTERNAL function}}
75+
[]() { func2(); });
8176

8277
h.single_task<class test_kernel3>(
8378
[]() { func3(); });

0 commit comments

Comments
 (0)