8000 [SYCL] [FPGA] Disable swapping dimension values of WorkGroupAttr arguments for semantic checks by smanna12 · Pull Request #2962 · intel/llvm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[SYCL] [FPGA] Disable swapping dimension values of WorkGroupAttr arguments for semantic checks #2962

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 2 commits into from
Dec 29, 2020
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
10 changes: 10 additions & 0 deletions clang/lib/CodeGen/CodeGenFunction.cpp
8000
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,11 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD,
A->getYDim()->getIntegerConstantExpr(FD->getASTContext());
Optional<llvm::APSInt> ZDimVal =
A->getZDim()->getIntegerConstantExpr(FD->getASTContext());

// For a SYCLDevice ReqdWorkGroupSizeAttr arguments are reversed.
if (getLangOpts().SYCLIsDevice)
std::swap(XDimVal, ZDimVal);

llvm::Metadata *AttrMDArgs[] = {
llvm::ConstantAsMetadata::get(
Builder.getInt32(XDimVal->getZExtValue())),
Expand Down Expand Up @@ -702,6 +707,11 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD,
A->getYDim()->getIntegerConstantExpr(FD->getASTContext());
Optional<llvm::APSInt> ZDimVal =
A->getZDim()->getIntegerConstantExpr(FD->getASTContext());

// For a SYCLDevice SYCLIntelMaxWorkGroupSizeAttr arguments are reversed.
if (getLangOpts().SYCLIsDevice)
std::swap(XDimVal, ZDimVal);

llvm::Metadata *AttrMDArgs[] = {
llvm::ConstantAsMetadata::get(
Builder.getInt32(XDimVal->getZExtValue())),
Expand Down
16 changes: 6 additions & 10 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3026,19 +3026,19 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &AL,
A->getValue()->getIntegerConstantExpr(S.Context)->getSExtValue();
if (AttrValue == 0) {
Result &=
checkZeroDim(A, getExprValue(AL.getArgAsExpr(2), S.getASTContext()),
checkZeroDim(A, getExprValue(AL.getArgAsExpr(0), S.getASTContext()),
getExprValue(AL.getArgAsExpr(1), S.getASTContext()),
getExprValue(AL.getArgAsExpr(0), S.getASTContext()),
getExprValue(AL.getArgAsExpr(2), S.getASTContext()),
/*ReverseAttrs=*/true);
}
}

if (const auto *A = D->getAttr<SYCLIntelMaxWorkGroupSizeAttr>()) {
if (!((getExprValue(AL.getArgAsExpr(2), S.getASTContext()) <=
if (!((getExprValue(AL.getArgAsExpr(0), S.getASTContext()) <=
getExprValue(A->getXDim(), S.getASTContext())) &&
(getExprValue(AL.getArgAsExpr(1), S.getASTContext()) <=
getExprValue(A->getYDim(), S.getASTContext())) &&
(getExprValue(AL.getArgAsExpr(0), S.getASTContext()) <=
(getExprValue(AL.getArgAsExpr(2), S.getASTContext()) <=
getExprValue(A->getZDim(), S.getASTContext())))) {
S.Diag(AL.getLoc(), diag::err_conflicting_sycl_function_attributes)
<< AL << A->getSpelling();
Expand All @@ -3047,11 +3047,11 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &AL,
}

if (const auto *A = D->getAttr<ReqdWorkGroupSizeAttr>()) {
if (!((getExprValue(AL.getArgAsExpr(2), S.getASTContext()) >=
if (!((getExprValue(AL.getArgAsExpr(0), S.getASTContext()) >=
getExprValue(A->getXDim(), S.getASTContext())) &&
(getExprValue(AL.getArgAsExpr(1), S.getASTContext()) >=
getExprValue(A->getYDim(), S.getASTContext())) &&
(getExprValue(AL.getArgAsExpr(0), S.getASTContext()) >=
(getExprValue(AL.getArgAsExpr(2), S.getASTContext()) >=
8000 getExprValue(A->getZDim(), S.getASTContext())))) {
S.Diag(AL.getLoc(), diag::err_conflicting_sycl_function_attributes)
<< AL << A->getSpelling();
Expand Down Expand Up @@ -3172,10 +3172,6 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
return;
}

// For a SYCLDevice WorkGroupAttr arguments are reversed.
if (S.getLangOpts().SYCLIsDevice)
std::swap(XDimExpr, ZDimExpr);

if (WorkGroupAttr *ExistingAttr = D->getAttr<WorkGroupAttr>()) {
Optional<llvm::APSInt> XDimVal =
XDimExpr->getIntegerConstantExpr(S.getASTContext());
Expand Down
18 changes: 14 additions & 4 deletions clang/test/CodeGenSYCL/intel-max-work-group-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class Foo {
[[intel::max_work_group_size(1, 1, 1)]] void operator()() const {}
};

class Bar {
public:
[[intel::max_work_group_size(1, 3, 6)]] void operator()() const {}
};

template <int SIZE, int SIZE1, int SIZE2>
class Functor {
public:
Expand All @@ -27,10 +32,13 @@ int main() {
h.single_task<class kernel_name2>(
[]() [[intel::max_work_group_size(8, 8, 8)]]{});

Bar bar;
h.single_task<class kernel_name3>(bar);

Functor<2, 2, 2> f;
h.single_task<class kernel_name3>(f);
h.single_task<class kernel_name4>(f);

h.single_task<class kernel_name4>([]() {
h.single_task<class kernel_name5>([]() {
func<4, 4, 4>();
});
});
Expand All @@ -39,9 +47,11 @@ int main() {

// CHECK: define spir_kernel void @{{.*}}kernel_name1"() #0 {{.*}} !max_work_group_size ![[NUM1:[0-9]+]]
// CHECK: define spir_kernel void @{{.*}}kernel_name2"() #0 {{.*}} !max_work_group_size ![[NUM8:[0-9]+]]
// CHECK: define spir_kernel void @{{.*}}kernel_name3"() #0 {{.*}} !max_work_group_size ![[NUM2:[0-9]+]]
// CHECK: define spir_kernel void @{{.*}}kernel_name4"() #0 {{.*}} !max_work_group_size ![[NUM4:[0-9]+]]
// CHECK: define spir_kernel void @{{.*}}kernel_name3"() #0 {{.*}} !max_work_group_size ![[NUM6:[0-9]+]]
// CHECK: define spir_kernel void @{{.*}}kernel_name4"() #0 {{.*}} !max_work_group_size ![[NUM2:[0-9]+]]
// CHECK: define spir_kernel void @{{.*}}kernel_name5"() #0 {{.*}} !max_work_group_size ![[NUM4:[0-9]+]]
// CHECK: ![[NUM1]] = !{i32 1, i32 1, i32 1}
// CHECK: ![[NUM8]] = !{i32 8, i32 8, i32 8}
// CHECK: ![[NUM6]] = !{i32 6, i32 3, i32 1}
// CHECK: ![[NUM2]] = !{i32 2, i32 2, i32 2}
// CHECK: ![[NUM4]] = !{i32 4, i32 4, i32 4}
5 changes: 5 additions & 0 deletions clang/test/CodeGenSYCL/reqd-work-group-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ int main() {
h.single_task<class kernel_name5>([]() {
func<8, 4, 4>();
});

h.single_task<class kernel_name6>(
[]() [[cl::reqd_work_group_size(1, 8, 2)]]{});
});
return 0;
}
Expand All @@ -54,8 +57,10 @@ int main() {
// CHECK: define spir_kernel void @{{.*}}kernel_name3"() #0 {{.*}} !reqd_work_group_size ![[WGSIZE88:[0-9]+]]
// CHECK: define spir_kernel void @{{.*}}kernel_name4"() #0 {{.*}} !reqd_work_group_size ![[WGSIZE22:[0-9]+]]
// CHECK: define spir_kernel void @{{.*}}kernel_name5"() #0 {{.*}} !reqd_work_group_size ![[WGSIZE44:[0-9]+]]
// CHECK: define spir_kernel void @{{.*}}kernel_name6"() #0 {{.*}} !reqd_work_group_size ![[WGSIZE2:[0-9]+]]
// CHECK: ![[WGSIZE32]] = !{i32 16, i32 16, i32 32}
// CHECK: ![[WGSIZE8]] = !{i32 1, i32 1, i32 8}
// CHECK: ![[WGSIZE88]] = !{i32 8, i32 8, i32 8}
// CHECK: ![[WGSIZE22]] = !{i32 2, i32 2, i32 2}
// CHECK: ![[WGSIZE44]] = !{i32 4, i32 4, i32 8}
// CHECK: ![[WGSIZE2]] = !{i32 2, i32 8, i32 1}
8 changes: 4 additions & 4 deletions clang/test/SemaSYCL/intel-max-global-work-dim-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ int main() {
h.single_task<class test_kernel5>(TRIFuncObjGood2());
// CHECK-LABEL: FunctionDecl {{.*}}test_kernel5
// CHECK: ReqdWorkGroupSizeAttr {{.*}}
// // CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}4{{$}}
// CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}}
// // CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK: SYCLIntelMaxGlobalWorkDimAttr {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}3{{$}}
#ifdef TRIGGER_ERROR
Expand Down
4 changes: 2 additions & 2 deletions clang/test/SemaSYCL/intel-max-work-group-size-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ int main() {

// CHECK-LABEL: FunctionDecl {{.*}}test_kernel4
// CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}}
// CHECK-NEXT: UnaryOperator{{.*}} 'int' prefix '-'
// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}}
// CHECK-NEXT: UnaryOperator{{.*}} 'int' prefix '-'
// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}}
// expected-warning@+2{{the resulting value of the 'max_work_group_size' attribute first parameter is always non-negative after implicit conversion}}
// expected-warning@+2{{the resulting value of the 'max_work_group_size' attribute third parameter is always non-negative after implicit conversion}}
h.single_task<class test_kernel4>(
[]() [[intel::max_work_group_size(8, 8, -8)]]{});

Expand Down
8 changes: 4 additions & 4 deletions clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ int main() {

// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name1
// CHECK: ReqdWorkGroupSizeAttr {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}}
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name2
// CHECK: ReqdWorkGroupSizeAttr {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}4{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}4{{$}}
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name3
// CHECK: ReqdWorkGroupSizeAttr {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}}
Expand All @@ -149,10 +149,10 @@ int main() {
// CHECK-NEXT: IntegerLiteral{{.*}}128{{$}}
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name5
// CHECK: ReqdWorkGroupSizeAttr {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}32{{$}}
// CHECK-NEXT: UnaryOperator{{.*}} 'int' prefix '-'
// CHECK-NEXT: IntegerLiteral{{.*}}4{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}32{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name6
// CHECK: ReqdWorkGroupSizeAttr {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}32{{$}}
Expand Down
4 changes: 2 additions & 2 deletions clang/test/SemaSYCL/reqd-work-group-size-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ int main() {

// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name1
// CHECK: ReqdWorkGroupSizeAttr {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}}
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name2
// CHECK: ReqdWorkGroupSizeAttr {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}4{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}4{{$}}
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name3
// CHECK: ReqdWorkGroupSizeAttr {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ int main() {
// CHECK: ReqdWorkGroupSizeAttr {{.*}}
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}}
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}

// Test that checks template parameter suppport on function.
template <int N, int N1, int N2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ int main() {
// CHECK: ReqdWorkGroupSizeAttr {{.*}}
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}}
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}}
// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}}

// Test that checks template parameter suppport on function.
template <int N, int N1, int N2>
Expand Down
0