-
Notifications
You must be signed in to change notification settings - Fork 769
[sycl-post-link] Add property with the default values of specialization constants #3666
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-post-link] Add property with the default values of specialization constants #3666
Conversation
…on constants This patch introduces a new property which contains all the defaults for spec constants. It is done by setting of metadata with the default values: ``` ; Compilation line: ; sycl-post-link -spec-const=default -S llvm/test/tools/sycl-post-link/spec-constants/SYCL-2020.ll -o property.table !5 = !{i32 42} !6 = !{%struct.ComposConst { i32 1, double 2.000000e+00, %struct.myConst { i32 13, float 0x4020666660000000 } }} ``` Property set looks this way: ``` [SYCL/specialization constants default values] all=2|gAAAAAAAAAgKAAAA ```
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.
Partial review
Offset += Ty->getPrimitiveSizeInBits() / 8 + | ||
(Ty->getPrimitiveSizeInBits() % 8 != 0); |
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.
Since you are appending to a vector and not inserting into a pre-allocated vector, you probably don't need this argument anymore
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.
Offset
argument is actually used for calculations in StructTy
- it helps to fill the buffer with the correct alignment:
https://github.com/intel/llvm/pull/3666/files#diff-f9a582625f70ea58ef88b7713c591e8187629cca507b424557a3e4664e23848fR308-R312
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.
And the rest of the review
/// Recursively iterates over a composite type in order to collect information | ||
/// about default values of its scalar elements. | ||
void collectCompositeElementsDefaultValuesRecursive( | ||
const Module &M, Constant *C, unsigned &Offset, |
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.
NIT: processing of composite spec constants is similar in this function, emitSpecConstantRecursiveImpl
and generateSpecConstDefaultValueMetadata
. Could be factored out using e.g. the visitor pattern. At least a TODO for now would be good.
// default value of corresponding specialization constant. | ||
DefaultValue = Initializer->getAggregateElement(0u); | ||
} | ||
} |
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.
what GV == 0 means? please add a comment or handle
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.
Probably we should just use cast
instead of dyn_cast
and always expect to see a value there.
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.
We can meet nullptr instead of value here - this check is still needed. I left a comment above the if-.
/// Recursively iterates over a composite type in order to collect information | ||
/// about default values of its scalar elements. | ||
/// TODO: processing of composite spec constants here is similar to | ||
/// collectCompositeElementsInfoRecursive. Possible place for improvement - |
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.
Is it also similar to emitSpecConstantRecursiveImpl and generateSpecConstDefaultValueMetadata?
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 really, it doesn't look similar. generateSpecConstDefaultValueMetadata
is not related to recursive methods, and emitSpecConstantRecursiveImpl
is too different from this function.
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.
added few comments
// default value of corresponding specialization constant. | ||
DefaultValue = Initializer->getAggregateElement(0u); | ||
} | ||
} |
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.
Probably we should just use cast
instead of dyn_cast
and always expect to see a value there.
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.
RT changes look good
@kbobrovs, ping. |
a5cbe74
…binaries DefaultValues.DefaultValuesAreSet and DefaultValues.DefaultValuesAreOverriden tests only support JIT which is not the case for the default values. Once AOT binaries support is added, the tests can be enabled back.
57f8fbd
to
02293fb
Compare
@@ -256,7 +256,7 @@ class device_image_impl { | |||
// supposed to be called from c'tor. | |||
MSpecConstSymMap[std::string{SCName}].push_back( | |||
SpecConstDescT{/*ID*/ It[0], /*CompositeOffset*/ It[1], | |||
/*Size*/ It[2], BlobOffset, HasDefaultValues}); | |||
/*Size*/ It[2], BlobOffset}); |
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 a bit concerned that this change is being committed in scope of this PR. The PR title says that this is a modification of sycl-post-link
tool and all 13 commits are very likely to be squashed into a single one during the merge - we will end up with a commit to sycl-post-link
, which modifies DPC++ RT.
Moreover, it is not clear to me why this change is needed at all. From my point of view it is better if we submit it in a separate PR
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.
Tagging @dm-vodopyanov here
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.
This change is related to https://github.com/intel/llvm/pull/3667/files#r631154823. I'll create a separate PR to make it clear.
@@ -201,11 +201,21 @@ class PropertySetRegistry { | |||
PropSet.insert(std::make_pair(Prop.first, PropertyValue(Prop.second))); | |||
} | |||
|
|||
template <typename T> |
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.
- Please add a comment when this function should be used instead of
void add(StringRef Category, const std::map<StringRef, T> &Props)
above. I.e. when the order of properties matters. - Suggest to make
add
templated on the map type to have single implementation for bothstd::map<StringRef, T>
andstd::map<StringRef, T>
Remove backward compatibility according to discussion: https://github.com/intel/llvm/pull/3667/files#r631154823i This patch is expected to be merged together or before #3666
Moving to intel#3813
This patch introduces a new property which contains all the defaults for spec
constants.
It is done by setting of metadata with the default values:
Property set looks this way: