Skip to content

Commit 995352e

Browse files
committed
[SYCL] Support intel::reqd_work_group_size (fix intel#8)
Signed-off-by: Aleksander Fadeev <[email protected]>
1 parent 6a313bf commit 995352e

File tree

6 files changed

+22
-67
lines changed

6 files changed

+22
-67
lines changed

clang/include/clang/Basic/Attr.td

+3-10
Original file line numberDiff line numberDiff line change
@@ -2415,16 +2415,9 @@ def NoDeref : TypeAttr {
24152415

24162416
def ReqdWorkGroupSize : InheritableAttr {
24172417
let Spellings = [GNU<"reqd_work_group_size">,
2418-
CXX11<"cl","reqd_work_group_size">];
2419-
let Args = [UnsignedArgument<"XDim">, UnsignedArgument<"YDim">,
2420-
UnsignedArgument<"ZDim">];
2421-
let Subjects = SubjectList<[Function], ErrorDiag>;
2422-
let Documentation = [Undocumented];
2423-
}
2424-
2425-
def SYCLIntelReqdWorkGroupSize : InheritableAttr {
2426-
let Spellings = [CXX11<"intel","reqd_work_group_size">];
2427-
let Args = [IntArgument<"XDim">, DefaultIntArgument<"YDim", 1>,
2418+
CXX11<"cl","reqd_work_group_size">,
2419+
CXX11<"intel","reqd_work_group_size">];
2420+
let Args = [UnsignedArgument<"XDim">, DefaultIntArgument<"YDim", 1>,
24282421
DefaultIntArgument<"ZDim", 1>];
24292422
let Subjects = SubjectList<[Function], ErrorDiag>;
24302423
let Documentation = [Undocumented];

clang/include/clang/Basic/AttributeCommonInfo.h

-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ class AttributeCommonInfo {
160160
auto ParsedAttr = getParsedKind();
161161
if (ParsedAttr == AT_SYCLIntelKernelArgsRestrict ||
162162
(ParsedAttr == AT_ReqdWorkGroupSize && isCXX11Attribute()) ||
163-
(ParsedAttr == AT_SYCLIntelReqdWorkGroupSize && isCXX11Attribute()) ||
164163
(ParsedAttr == AT_IntelReqdSubGroupSize && isCXX11Attribute()) ||
165164
ParsedAttr == AT_SYCLIntelNumSimdWorkItems ||
166165
ParsedAttr == AT_SYCLIntelMaxWorkGroupSize ||

clang/lib/CodeGen/CodeGenFunction.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -644,16 +644,6 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD,
644644
Fn->setMetadata("reqd_work_group_size", llvm::MDNode::get(Context, AttrMDArgs));
645645
}
646646

647-
if (const SYCLIntelReqdWorkGroupSizeAttr *A =
648-
FD->getAttr<SYCLIntelReqdWorkGroupSizeAttr>()) {
649-
llvm::Metadata *AttrMDArgs[] = {
650-
llvm::ConstantAsMetadata::get(Builder.getInt32(A->getXDim())),
651-
llvm::ConstantAsMetadata::get(Builder.getInt32(A->getYDim())),
652-
llvm::ConstantAsMetadata::get(Builder.getInt32(A->getZDim()))};
653-
Fn->setMetadata("reqd_work_group_size",
654-
llvm::MDNode::get(Context, AttrMDArgs));
655-
}
656-
657647
if (const IntelReqdSubGroupSizeAttr *A =
658648
FD->getAttr<IntelReqdSubGroupSizeAttr>()) {
659649
llvm::Metadata *AttrMDArgs[] = {

clang/lib/Sema/SemaDeclAttr.cpp

+7-22
Original file line numberDiff line numberDiff line change
@@ -2890,9 +2890,6 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr,
28902890
if (const auto *A = D->getAttr<ReqdWorkGroupSizeAttr>())
28912891
Result &= checkZeroDim(A, A->getXDim(), A->getYDim(), A->getZDim());
28922892
return Result;
2893-
if (const auto *A = D->getAttr<SYCLIntelReqdWorkGroupSizeAttr>())
2894-
Result &= checkZeroDim(A, A->getXDim(), A->getYDim(), A->getZDim());
2895-
return Result;
28962893
}
28972894

28982895
if (const auto *A = D->getAttr<SYCLIntelMaxGlobalWorkDimAttr>())
@@ -2916,14 +2913,6 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr,
29162913
Result &= false;
29172914
}
29182915
}
2919-
if (const auto *A = D->getAttr<SYCLIntelReqdWorkGroupSizeAttr>()) {
2920-
if (!(WGSize[0] >= A->getXDim() && WGSize[1] >= A->getYDim() &&
2921-
WGSize[2] >= A->getZDim())) {
2922-
S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes)
2923-
<< Attr << A->getSpelling();
2924-
Result &= false;
2925-
}
2926-
}
29272916
return Result;
29282917
}
29292918

@@ -2935,13 +2924,15 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
29352924
return;
29362925

29372926
uint32_t WGSize[3];
2938-
if (std::is_same<WorkGroupAttr, SYCLIntelReqdWorkGroupSizeAttr>::value) {
2939-
WGSize[1] = SYCLIntelReqdWorkGroupSizeAttr::DefaultYDim;
2940-
WGSize[2] = SYCLIntelReqdWorkGroupSizeAttr::DefaultZDim;
2941-
}
2927+
if (AL.getNormalizedFullName() == "intel::reqd_work_group_size") {
2928+
WGSize[1] = ReqdWorkGroupSizeAttr::DefaultYDim;
2929+
WGSize[2] = ReqdWorkGroupSizeAttr::DefaultZDim;
2930+
} else if (!checkAttributeNumArgs(S, AL, 3))
2931+
return;
2932+
29422933
for (unsigned i = 0; i < 3; ++i) {
29432934
if (i < AL.getNumArgs())
2944-
if (!checkUInt32Argument(S, AL, AL.getArgAsExpr(i), WGSize[i], i,
2935+
if (!checkUInt32Argument(S, AL, AL.getArgAsExpr(i), WGSize[i], i,
29452936
/*StrictlyUnsigned=*/true))
29462937
return;
29472938
if (WGSize[i] == 0) {
@@ -7677,9 +7668,6 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
76777668
case ParsedAttr::AT_ReqdWorkGroupSize:
76787669
handleWorkGroupSize<ReqdWorkGroupSizeAttr>(S, D, AL);
76797670
break;
7680-
case ParsedAttr::AT_SYCLIntelReqdWorkGroupSize:
7681-
handleWorkGroupSize<SYCLIntelReqdWorkGroupSizeAttr>(S, D, AL);
7682-
break;
76837671
case ParsedAttr::AT_SYCLIntelMaxWorkGroupSize:
76847672
handleWorkGroupSize<SYCLIntelMaxWorkGroupSizeAttr>(S, D, AL);
76857673
break;
@@ -8182,9 +8170,6 @@ void Sema::ProcessDeclAttributeList(Scope *S, Decl *D,
81828170
// diag::err_attribute_wrong_decl_type + ExpectedKernelFunction.
81838171
Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A;
81848172
D->setInvalidDecl();
8185-
} else if (const auto *A = D->getAttr<SYCLIntelReqdWorkGroupSizeAttr>()) {
8186-
Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A;
8187-
D->setInvalidDecl();
81888173
} else if (const auto *A = D->getAttr<WorkGroupSizeHintAttr>()) {
81898174
Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A;
81908175
D->setInvalidDecl();

clang/lib/Sema/SemaSYCL.cpp

-19
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,6 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
410410
Attrs.insert(A);
411411
if (auto *A = FD->getAttr<ReqdWorkGroupSizeAttr>())
412412
Attrs.insert(A);
413-
if (auto *A = FD->getAttr<SYCLIntelReqdWorkGroupSizeAttr>())
414-
Attrs.insert(A);
415413
// Allow the following kernel attributes only on lambda functions and
416414
// function objects that are called directly from a kernel (i.e. the one
417415
// passed to the parallel_for function). For all other cases,
@@ -1372,23 +1370,6 @@ void Sema::MarkDevice(void) {
13721370
}
13731371
break;
13741372
}
1375-
case attr::Kind::SYCLIntelReqdWorkGroupSize: {
1376-
auto *Attr = cast<SYCLIntelReqdWorkGroupSizeAttr>(A);
1377-
if (auto *Existing = SYCLKernel->getAttr<SYCLIntelReqdWorkGroupSizeAttr>()) {
1378-
if (Existing->getXDim() != Attr->getXDim() ||
1379-
Existing->getYDim() != Attr->getYDim() ||
1380-
Existing->getZDim() != Attr->getZDim()) {
1381-
Diag(SYCLKernel->getLocation(),
1382-
diag::err_conflicting_sycl_kernel_attributes);
1383-
Diag(Existing->getLocation(), diag::note_conflicting_attribute);
1384-
Diag(Attr->getLocation(), diag::note_conflicting_attribute);
1385-
SYCLKernel->setInvalidDecl();
1386-
}
1387-
} else {
1388-
SYCLKernel->addAttr(A);
1389-
}
1390-
break;
1391-
}
13921373
case attr::Kind::SYCLIntelKernelArgsRestrict:
13931374
case attr::Kind::SYCLIntelNumSimdWorkItems:
13941375
case attr::Kind::SYCLIntelMaxGlobalWorkDim:

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

+12-5
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,16 @@ void bar() {
3030
[[intel::reqd_work_group_size(32, 32, 1)]] void f32x32x1() {} // expected-note {{conflicting attribute is here}}
3131
[[intel::reqd_work_group_size(32, 32, 32)]] void f32x32x32() {} // expected-note {{conflicting attribute is here}}
3232

33+
#ifdef TRIGGER_ERROR
34+
class Functor32 {
35+
public:
36+
[[cl::reqd_work_group_size(32)]] void operator()() {} // expected-error {{'reqd_work_group_size' attribute requires exactly 3 arguments}}
37+
};
38+
#endif
39+
3340
class Functor16 {
3441
public:
35-
[[intel::reqd_work_group_size(16, 1)]] void operator()() {}
42+
[[intel::reqd_work_group_size(16)]] void operator()() {}
3643
};
3744

3845
class Functor16x16x16 {
@@ -110,13 +117,13 @@ void bar() {
110117
}
111118

112119
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name1
113-
// CHECK: SYCLIntelReqdWorkGroupSizeAttr {{.*}} 1 1 16
120+
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 1 1 16
114121
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name2
115-
// CHECK: SYCLIntelReqdWorkGroupSizeAttr {{.*}} 1 1 4
122+
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 1 1 4
116123
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name3
117-
// CHECK: SYCLIntelReqdWorkGroupSizeAttr {{.*}} 16 16 16
124+
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 16 16 16
118125
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name4
119126
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 128 128 128
120127
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name5
121-
// CHECK: SYCLIntelReqdWorkGroupSizeAttr {{.*}} 32 32 32
128+
// CHECK: ReqdWorkGroupSizeAttr {{.*}} 32 32 32
122129
#endif // __SYCL_DEVICE_ONLY__

0 commit comments

Comments
 (0)