-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Implement SYCL 2020 spec functionality: no propagation from functions to the caller #3836
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
Changes from all commits
b99d43f
8457394
a61aea0
c887413
712c32b
a62d6cc
ade77f5
79a043d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3369,6 +3369,14 @@ static void handleIntelNamedSubGroupSize(Sema &S, Decl *D, | |
SizeType)) { | ||
S.Diag(Loc, diag::warn_attribute_type_not_supported) << AL << SizeStr; | ||
} | ||
|
||
// If the [[intel::named_sub_group_size]] attribute spelling is used in | ||
// SYCL 2017 mode, we want to diagnose it as being an ignored attribute. | ||
Comment on lines
+3373
to
+3374
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the docs may need to be updated for this attribute, as they currently imply there's a mode other than SYCL 2020 mode: https://github.com/intel/llvm/blob/sycl/clang/include/clang/Basic/AttrDocs.td#L4613 Also, this should be expressed in Attr.td in a |
||
if (S.LangOpts.getSYCLVersion() == LangOptions::SYCL_2017) { | ||
S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL; | ||
return; | ||
} | ||
|
||
D->addAttr(IntelNamedSubGroupSizeAttr::Create(S.Context, SizeType, AL)); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -343,15 +343,43 @@ static void collectSYCLAttributes(Sema &S, FunctionDecl *FD, | |
if (!FD->hasAttrs()) | ||
return; | ||
|
||
llvm::copy_if(FD->getAttrs(), std::back_inserter(Attrs), [](Attr *A) { | ||
// FIXME: Make this list self-adapt as new SYCL attributes are added. | ||
return isa<IntelReqdSubGroupSizeAttr, IntelNamedSubGroupSizeAttr, | ||
ReqdWorkGroupSizeAttr, SYCLIntelKernelArgsRestrictAttr, | ||
SYCLIntelNumSimdWorkItemsAttr, | ||
SYCLIntelSchedulerTargetFmaxMhzAttr, | ||
SYCLIntelMaxWorkGroupSizeAttr, SYCLIntelMaxGlobalWorkDimAttr, | ||
SYCLIntelNoGlobalWorkOffsetAttr, SYCLSimdAttr>(A); | ||
}); | ||
// Attributes that should be propagated from device functions to a kernel | ||
// in SYCL 1.2.1. | ||
if (S.getASTContext().getLangOpts().getSYCLVersion() < | ||
LangOptions::SYCL_2020) { | ||
llvm::copy_if(FD->getAttrs(), std::back_inserter(Attrs), [](Attr *A) { | ||
// FIXME: Make this list self-adapt as new SYCL attributes are added. | ||
return isa<IntelReqdSubGroupSizeAttr, SYCLIntelKernelArgsRestrictAttr, | ||
ReqdWorkGroupSizeAttr, SYCLIntelNumSimdWorkItemsAttr, | ||
SYCLIntelSchedulerTargetFmaxMhzAttr, | ||
SYCLIntelMaxWorkGroupSizeAttr, SYCLIntelMaxGlobalWorkDimAttr, | ||
SYCLIntelNoGlobalWorkOffsetAttr, SYCLSimdAttr>(A); | ||
}); | ||
// Attributes that should not be propagated from device functions to a | ||
// kernel in SYCL 1.2.1. | ||
if (DirectlyCalled) { | ||
llvm::copy_if(FD->getAttrs(), std::back_inserter(Attrs), [](Attr *A) { | ||
return isa<SYCLIntelLoopFuseAttr, SYCLIntelFPGAMaxConcurrencyAttr, | ||
SYCLIntelFPGADisableLoopPipeliningAttr, | ||
SYCLIntelFPGAInitiationIntervalAttr>(A); | ||
}); | ||
} | ||
} else { | ||
// Attributes that should not be propagated from device functions to a | ||
// kernel in SYCL 2020. | ||
if (DirectlyCalled) { | ||
llvm::copy_if(FD->getAttrs(), std::back_inserter(Attrs), [](Attr *A) { | ||
return isa< | ||
SYCLIntelFPGAMaxConcurrencyAttr, | ||
SYCLIntelFPGADisableLoopPipeliningAttr, SYCLSimdAttr, | ||
SYCLIntelKernelArgsRestrictAttr, ReqdWorkGroupSizeAttr, | ||
SYCLIntelNumSimdWorkItemsAttr, SYCLIntelSchedulerTargetFmaxMhzAttr, | ||
SYCLIntelNoGlobalWorkOffsetAttr, SYCLIntelMaxWorkGroupSizeAttr, | ||
IntelReqdSubGroupSizeAttr, SYCLIntelMaxGlobalWorkDimAttr, | ||
IntelNamedSubGroupSizeAttr, SYCLIntelFPGAInitiationIntervalAttr>(A); | ||
}); | ||
} | ||
Comment on lines
+367
to
+381
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we can get rid of this entire branch because in 2020 mode, it seems like none of the attributes propagate anyway (or did I get that wrong)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect we can simplify this code somehow but this branch collects attributes to be applied to device functions and kernel itself. The attributes applied to kernel still need to be collected and applied irrespective of SYCL version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry @AaronBallman. i was wrong. We need this entire else branch in SYCL2020 mode since we still need to copy the attributes for DirectlyCalled = TRUE. I have no better idea about how we can avoid duplicating the codes here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
where each of the generated lists of attributes in the
Thanks @AaronBallman for the tablegen design. I agree with you that it seems reasonable to do this here. I did not have a chance to look into the new design yesterday. I will take a look at this today and will follow up with you about this for any question. |
||
} | ||
|
||
// Allow the kernel attribute "use_stall_enable_clusters" only on lambda | ||
// functions and function objects called directly from a kernel. | ||
|
@@ -366,15 +394,6 @@ static void collectSYCLAttributes(Sema &S, FunctionDecl *FD, | |
FD->dropAttr<SYCLIntelUseStallEnableClustersAttr>(); | ||
} | ||
} | ||
|
||
// Attributes that should not be propagated from device functions to a kernel. | ||
if (DirectlyCalled) { | ||
llvm::copy_if(FD->getAttrs(), std::back_inserter(Attrs), [](Attr *A) { | ||
return isa<SYCLIntelLoopFuseAttr, SYCLIntelFPGAMaxConcurrencyAttr, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't these be added to the DirectlyCalled list in L362? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This attributes directly apply on kernel functor/lambda in SYCL2020 modes, so i did not add them in L362. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These attributes are available prior to SYCL2020 right? Shouldn't they apply for earlier versions as well? I think this patch changes existing behavior for these attributes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
All attributes were added recently. they were added after SYCl2020 spec release. I think they should not apply in SYCL2017 modes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how its expected to work but unless the extensions these attributes support are limited to SYCL2020, or these attributes are documented to work only in SYCL 2020, we probably should not be changing this behavior for earlier versions of SYCL. @AaronBallman please let us know your thoughts here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The diagnostic seems reasonable to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please wait for @AaronBallman's input. In my opinion it is confusing/strange to have individual attributes behave differently in different versions of SYCL spec, but I guess we are doing that with this change anyway. I guess the question is more - should we change existing behavior for these attributes in SYCL 2017 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I agree with you, @elizabethandrews. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry about the delayed response -- having power issues at the house.
Agreed. I think the route we want to go is:
I don't think we should change existing behaviors -- that runs too much risk of silently breaking user code. However, it's also not clear to much just how much implementation effort it is to retain the old behavior in each case and whether the old behavior was sensible or not in SYCL 1.2.1. My reading of the 1.2.1 spec suggests that only the
That said, I have no idea if this is an accurate understanding of the SYCL spec. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @AaronBallman and @elizabethandrews. I have added the attributes below in SYCL 1.2.1 mode. The semantic is same in all modes. SYCLIntelFPGAMaxConcurrencyAttr, |
||
SYCLIntelFPGADisableLoopPipeliningAttr, | ||
SYCLIntelFPGAInitiationIntervalAttr>(A); | ||
}); | ||
} | ||
} | ||
|
||
class DiagDeviceFunction : public RecursiveASTVisitor<DiagDeviceFunction> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this risk breaking code, or was the old documentation wrong in SYCL 2020 mode? Same question applies to the other documentation instances where we go from always propagating to sometimes propagating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure i understand your question correctly.
The current PR changes the existing behavior. Only breaking part happens here - propagation with SYCL 1.2.1 and no propagation with SYCL 2020 mode when the attribute is applied to a function from a device kernel. so old documentation was wrong in SYCL 2020 mode.