-
Notifications
You must be signed in to change notification settings - Fork 778
[SYCL] Add aspect enum value information to LLVM IR metadata #6804
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
[SYCL] Add aspect enum value information to LLVM IR metadata #6804
Conversation
This commit adds a new module-level metadata node !intel_sycl_aspects which contains metadata pairs of the enum element names and integral values of the SYCL aspects enum, identified by the [[__sycl_detail__::sycl_type(aspect)]] attribute. This commit also makes the SYCLPropagateAspectsUsage pass read !intel_sycl_aspects and use this information to determine the value of the fp64 aspect instead of relying on it being synchronized with the SYCL implementation headers. Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
clang/lib/CodeGen/CodeGenModule.cpp
Outdated
// Emit metadata for all aspects defined in the aspects enum. | ||
if (AspectsEnumDecl) { | ||
llvm::NamedMDNode *AspectEnumValsMD = | ||
TheModule.getOrInsertNamedMetadata("intel_sycl_aspects"); |
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.
I suggest we drop "intel_" prefix. The attribute value is not intel specific and it should be easier to upstream w/o the prefix.
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.
The same could be said for every other LLVM attribute described in this design (e.g. intel_declared_aspects
, intel_used_aspects
). We have existing LLVM attributes named this way too (e.g. intel_reqd_sub_group_size
). If we think we want to rename SYCL-related LLVM attributes to make them easier to upstream, we should make some sort of global decision and rename them all.
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.
intel_reqd_sub_group_size
was introduced for Intel specific extension, whereas aspect is already SYCL core feature.
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.
The [[sycl::reqd_sub_group_size()]]
C++ attribute is also a core SYCL feature now.
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.
That's right, but what "intel_" in "intel_sycl_aspects" refers to? Is this the name of some type in the extension? I assumed that it refers to "Intel specific implementation" and this will be difficult to upstream.
I think we agree that things should be named after the spec entities, rather than implementation names like dpcpp, intel, etc. if we aim to commit this code to LLVM project.
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.
I'm not opposed to renaming these LLVM IR attributes, I just think they should all be named consistently. If we want to remove the "intel" prefix, maybe the new names could be like:
intel_types_that_use_aspects
->sycl_types_that_use_aspects
intel_declared_aspects
->sycl_declared_aspects
intel_used_aspects
->sycl_used_aspects
intel_fixed_targets
->sycl_fixed_targets
intel_sycl_aspects
->sycl_aspects
In addition, we should identify other sycl-related LLVM IR attributes that start with "intel" and rename them to start with "sycl". This PR could rename the attributes defined in the OptionalDeviceFeratures design, and we could create a tracker to capture the work required to rename any other attributes.
Alternatively, we could keep the names as "intel" in this PR and create a new PR that renames everything to "sycl" prefix.
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.
Yes, please, update other LLVM IR attributes (if it's possible to do w/o ABI breaking) too. This PR mentions only one attribute and I was not aware that there other similar attributes.
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.
I am happy to go rename the metadata nodes related to OptionalDeviceFeratures, but I would prefer to do it in a separate PR to avoid polluting this one. That said, since intel_sycl_aspects
is introduced with this I will make the renaming of it as part of this PR.
!1 = !{!"cpu", i32 1} | ||
!2 = !{!"gpu", i32 2} | ||
... | ||
``` |
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.
It's not very clear from this design document how the intel_sycl_aspects
metadata is used. I think the reason is to provide the enum value for aspect::fp64
to the new LLVM IR pass, correct? If that is the case, can you add a note to the description of that pass saying that it uses this metadata for that purpose?
Did you consider as an alternate solution to have the CFE include one more entry in intel_types_that_use_aspects
? For example:
!intel_types_that_use_aspects = !{!0, ...}
!0 = !{!"double", i32 8} # The value 8 is "aspect::fp64"
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.
It's not very clear from this design document how the
intel_sycl_aspects
metadata is used. I think the reason is to provide the enum value foraspect::fp64
to the new LLVM IR pass, correct? If that is the case, can you add a note to the description of that pass saying that it uses this metadata for that purpose?
Absolutely! I'll add a note.
Did you consider as an alternate solution to have the CFE include one more entry in
intel_types_that_use_aspects
? For example:!intel_types_that_use_aspects = !{!0, ...} !0 = !{!"double", i32 8} # The value 8 is "aspect::fp64"
I did consider this, but having all of them present has the added benefit of allowing us to map values to aspects when diagnostics are added in a follow-up patch.
Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
if (AspectValues.empty()) { | ||
assert(TypesWithAspects.empty() && | ||
"sycl_aspects metadata is missing but " | ||
"intel_types_that_use_aspects is present."); |
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.
I suppose this needs renaming at some point to sycl_?
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.
Good eye! Yes, I might as well do that renaming now.
@@ -333,7 +362,19 @@ buildFunctionsToAspectsMap(Module &M, TypeToAspectsMapTy &TypesWithAspects) { | |||
PreservedAnalyses | |||
SYCLPropagateAspectsUsagePass::run(Module &M, ModuleAnalysisManager &MAM) { | |||
TypeToAspectsMapTy TypesWithAspects = getTypesThatUseAspectsFromMetadata(M); | |||
propagateAspectsToOtherTypesInModule(M, TypesWithAspects); | |||
AspectValueToNameMapTy AspectValues = getSYCLAspectsFromMetadata(M); |
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.
Why is the function named 'getSYCLAspects' and not just 'getAspects'?
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.
It made sense when the metadata was named intel_sycl_aspects
, but now I think I agree that getAspects
looks better. It has been renamed.
@@ -121,18 +151,17 @@ void propagateAspectsThroughTypes(const TypesEdgesTy &Edges, const Type *Start, | |||
/// Time complexity: O((V + E) * T) where T is the number of input types | |||
/// containing aspects. | |||
void propagateAspectsToOtherTypesInModule( | |||
const Module &M, TypeToAspectsMapTy &TypesWithAspects) { | |||
const Module &M, TypeToAspectsMapTy &TypesWithAspects, | |||
AspectValueToNameMapTy &AspectValues) { | |||
std::unordered_set<const Type *> TypesToProcess; | |||
const Type *DoubleTy = Type::getDoubleTy(M.getContext()); |
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.
Do we need to check if DoubleTy could be NULL?
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.
I don't believe so. To my knowledge the context should be able to supply it in all cases we care about, but @AlexeySachkov may know better.
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.
To my knowledge the context should be able to supply it in all cases we care about, but @AlexeySachkov may know better.
I don't see any guarantees in the doxygen documentation, but looking at the source code we simply return an address of a LLVMContextImpl
field, which can't be nullptr
.
We definitely don't need to insert a runtime if
here and even assertion would excessive, I think.
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.
SYCLLowerIR pass looks good to me. Just a few nitpicks. Nothing blocking. Thanks
clang/lib/CodeGen/CodeGenModule.cpp
Outdated
AspectEnumValMD.push_back(llvm::MDString::get(Ctx, ECD->getName())); | ||
AspectEnumValMD.push_back( | ||
llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( | ||
llvm::Type::getInt32Ty(Ctx), ECD->getInitVal().getZExtValue()))); |
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.
Should this be getSExtValue()?
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.
I am not sure it matters for this specific case, but better keep it consistent! It has been changed, thanks!
Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
6622dcc
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.
LGTM. Thanks
Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
This commit adds a new module-level metadata node !intel_sycl_aspects which contains metadata pairs of the enum element names and integral values of the SYCL aspects enum, identified by the [[sycl_detail::sycl_type(aspect)]] attribute.
This commit also makes the SYCLPropagateAspectsUsage pass read !intel_sycl_aspects and use this information to determine the value of the fp64 aspect instead of relying on it being synchronized with the SYCL implementation headers.