Skip to content

Commit ca26f57

Browse files
committed
Add work-group scope attribute to the SYCL kernel
Kernel objects passed to parallel_for_work_group function must be shared among all work-items withing a work-group.
1 parent 969b468 commit ca26f57

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,14 +2763,19 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
27632763
}
27642764

27652765
static VarDecl *createKernelObjClone(ASTContext &Ctx, DeclContext *DC,
2766-
const CXXRecordDecl *KernelObj) {
2766+
const CXXRecordDecl *KernelObj,
2767+
FunctionDecl *KernelCallerFunc) {
27672768
TypeSourceInfo *TSInfo =
27682769
KernelObj->isLambda() ? KernelObj->getLambdaTypeInfo() : nullptr;
2770+
auto Type = QualType(KernelObj->getTypeForDecl(), 0);
2771+
Type->getAsRecordDecl()->setAnonymousStructOrUnion(true);
27692772
VarDecl *VD = VarDecl::Create(
27702773
Ctx, DC, KernelObj->getLocation(), KernelObj->getLocation(),
2771-
KernelObj->getIdentifier(), QualType(KernelObj->getTypeForDecl(), 0),
2774+
KernelObj->getIdentifier(), Type,
27722775
TSInfo, SC_None);
2773-
2776+
if (getKernelInvocationKind(KernelCallerFunc) == InvokeParallelForWorkGroup)
2777+
VD->addAttr(
2778+
SYCLScopeAttr::CreateImplicit(Ctx, SYCLScopeAttr::Level::WorkGroup));
27742779
return VD;
27752780
}
27762781

@@ -2846,7 +2851,8 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
28462851
FunctionDecl *KernelCallerFunc)
28472852
: SyclKernelFieldHandler(S), DeclCreator(DC),
28482853
KernelObjClone(createKernelObjClone(S.getASTContext(),
2849-
DC.getKernelDecl(), KernelObj)),
2854+
DC.getKernelDecl(), KernelObj,
2855+
KernelCallerFunc)),
28502856
VarEntity(InitializedEntity::InitializeVariable(KernelObjClone)),
28512857
KernelObj(KernelObj), KernelCallerFunc(KernelCallerFunc),
28522858
KernelCallerSrcLoc(KernelCallerFunc->getLocation()) {

clang/test/SemaSYCL/kernel-handler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ int main() {
7575
// NONATIVESUPPORT-NEXT: InitListExpr
7676
// NONATIVESUPPORT-NEXT: ImplicitCastExpr {{.*}} 'int' <LValueToRValue>
7777
// NONATIVESUPPORT-NEXT: DeclRefExpr {{.*}} 'int' lvalue ParmVar {{.*}} '_arg_a' 'int'
78+
// NONATIVESUPPORT-NEXT: SYCLScopeAttr {{.*}} Implicit WorkGroup
7879

7980
// Check declaration and initialization of kernel handler local clone using default constructor
8081
// NONATIVESUPPORT-NEXT: DeclStmt

0 commit comments

Comments
 (0)