Skip to content

Commit f611c15

Browse files
committed
[SYCL] Propagate to kernel only the attributes of its lambda or function object
It is expected to propagate certain attributes to SYCL kernel from only lambda functions and function objects that are called directly from a kernel (i.e., those passed to the parallel_for function) This patch upholds this expectation by avoiding attributes being propagated from functions called from within kernel.
1 parent 03dd60d commit f611c15

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

clang/lib/Sema/SemaSYCL.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -420,39 +420,39 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
420420
// passed to the parallel_for function). For all other cases,
421421
// emit a warning and ignore.
422422
if (auto *A = FD->getAttr<SYCLIntelKernelArgsRestrictAttr>()) {
423-
if (ParentFD == SYCLKernel) {
423+
if (ParentFD == SYCLKernel && A->isImplicit()) {
424424
Attrs.insert(A);
425425
} else {
426426
SemaRef.Diag(A->getLocation(), diag::warn_attribute_ignored) << A;
427427
FD->dropAttr<SYCLIntelKernelArgsRestrictAttr>();
428428
}
429429
}
430430
if (auto *A = FD->getAttr<SYCLIntelNumSimdWorkItemsAttr>()) {
431-
if (ParentFD == SYCLKernel) {
431+
if (ParentFD == SYCLKernel && A->isImplicit()) {
432432
Attrs.insert(A);
433433
} else {
434434
SemaRef.Diag(A->getLocation(), diag::warn_attribute_ignored) << A;
435435
FD->dropAttr<SYCLIntelNumSimdWorkItemsAttr>();
436436
}
437437
}
438438
if (auto *A = FD->getAttr<SYCLIntelMaxWorkGroupSizeAttr>()) {
439-
if (ParentFD == SYCLKernel) {
439+
if (ParentFD == SYCLKernel && A->isImplicit()) {
440440
Attrs.insert(A);
441441
} else {
442442
SemaRef.Diag(A->getLocation(), diag::warn_attribute_ignored) << A;
443443
FD->dropAttr<SYCLIntelMaxWorkGroupSizeAttr>();
444444
}
445445
}
446446
if (auto *A = FD->getAttr<SYCLIntelMaxGlobalWorkDimAttr>()) {
447-
if (ParentFD == SYCLKernel) {
447+
if (ParentFD == SYCLKernel && A->isImplicit()) {
448448
Attrs.insert(A);
449449
} else {
450450
SemaRef.Diag(A->getLocation(), diag::warn_attribute_ignored) << A;
451451
FD->dropAttr<SYCLIntelMaxGlobalWorkDimAttr>();
452452
}
453453
}
454454
if (auto *A = FD->getAttr<SYCLIntelNoGlobalWorkOffsetAttr>()) {
455-
if (ParentFD == SYCLKernel) {
455+
if (ParentFD == SYCLKernel && A->isImplicit()) {
456456
Attrs.insert(A);
457457
} else {
458458
SemaRef.Diag(A->getLocation(), diag::warn_attribute_ignored) << A;
@@ -1677,7 +1677,9 @@ void Sema::MarkDevice(void) {
16771677
case attr::Kind::SYCLIntelMaxGlobalWorkDim:
16781678
case attr::Kind::SYCLIntelMaxWorkGroupSize:
16791679
case attr::Kind::SYCLIntelNoGlobalWorkOffset: {
1680-
SYCLKernel->addAttr(A);
1680+
Attr *NewA = A->clone(getASTContext());
1681+
NewA->setImplicit(true);
1682+
SYCLKernel->addAttr(NewA);
16811683
break;
16821684
}
16831685
// TODO: vec_len_hint should be handled here

0 commit comments

Comments
 (0)