Skip to content
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

POD Specialization constants design update #2669

Merged

Conversation

AlexeySachkov
Copy link
Contributor

@AlexeySachkov AlexeySachkov commented Oct 22, 2020

Besides some tiny markup & typo fixes this PR changes interfaces for defining specialization constants between sycl-post-link and SPIRV-LLVM-Translator, in particular:

Renamed __spirvCompositeSpecConstant to __spirv_SpecConstantComposite to better match SPIR-V friendly IR representaiton, which is aligned with opcode names from SPIR-V spec.

Changed logic of generating __spirv_SpecConstantComposite: instead of getting list of SpecID for each composite member it now accepts vector of actual members, which might be another composits, undefs or regular constants. This change was done to align this intrinsic with corresponding opcode prototype to make its handling more universal and useful for the upstream translator project.

Removed `__sycl_getCompositeSpecConstantValue` intrinsic, because we can
check if specialization constant is a composite type by looking at
return type of `__sycl_getSpecConstantValue`. This also allows us to
avoid any changes in
`cl::sycl::ONEAPI::experimental::spec_constant::get` method.

Renamed `__spirvCompositeSpecConstant` to
`__spirv_SpecConstantComposite` to better match SPIR-V friendly IR
representaiton, which is aligned with opcode names from SPIR-V spec.

Changed logic of generating `__spirv_SpecConstantComposite`: instead of
getting list of `SpecID` for each composite member it now accepts vector
of actual members, which might be another composits, undefs or regular
constants. This change was done to align this intrinsic with
corresponding opcode prototype to make its handling more universal and
useful for the upstream translator project.
Therefore, completely removed some sections which are outdated assuming
new approach.
pvchupin
pvchupin previously approved these changes Oct 23, 2020
Copy link
Contributor

@pvchupin pvchupin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kbobrovs, please review

Type information is useless in precence of constant size
Copy link
Contributor

@kbobrovs kbobrovs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked into details yet, but have a question below on removal of SPIRV translator section

sycl/doc/SpecializationConstants.md Show resolved Hide resolved

And 1 "composite"
%gold = call %struct.POD __spirv_SpecConstantComposite([2 x %struct.A] %gold_POD_A, i32 %gold_POD_b)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only reason why __spirvCompositeSpecConstant accepted IDs instead of SSA values is a concern that there could be some non-trivia data flow (i.e. via store/load to alloca) of an operand, which might confuse the translator. If we can be sure that this will never happen, then using SSA with spec constant tree construction in IR seems fine.

Renamed section describing interaction with the SPIR-V translator.
Returned back section about interaction with the SPIR-V translator about
composite spec constants.

Returned back `__sycl_getCompositeSpecConstantValue` intrinsic.

Improved an example of composite spec constant by adding vector into it.
sycl/doc/SpecializationConstants.md Outdated Show resolved Hide resolved
sycl/doc/SpecializationConstants.md Show resolved Hide resolved
sycl/doc/SpecializationConstants.md Outdated Show resolved Hide resolved
sycl/doc/SpecializationConstants.md Outdated Show resolved Hide resolved
kbobrovs
kbobrovs previously approved these changes Nov 17, 2020
@kbobrovs
Copy link
Contributor

@AlexeySotkin - please review/approve

It does not need a default value, because its default value consists of default
valued of its leaf specialization constants (see below).
`__sycl_getCompositeSpecConstantValue` is a new "intrinsic" (in addition to
`__sycl_getSpecConstantValue`) recognized by the `SpecConstants` pass, which
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kbobrovs, what do you think about renaming existing __sycl_getSpecConstantValue into __sycl_getScalarSpecConstantValue to unify names and add more clarity?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexeySachkov, I don't mind

struct A {
int x;
float y;
};

struct POD {
A a[2];
int b;
cl::sycl::vec<int, 2> b;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example might actually be confusing, because cl::sycl::vec is not a POD-type in our implementation, because it is not trivially copyable due to the fact that there is non-trivial copy constructor (I don't know why it is coded in this way, probably @romanovvlad can say something about this).

I guess that from user point of view it would be nice to have possibility to use vectors as specialization constants, so, what should I do here: do I put a vector into the example or do I leave it as-is?

value for each leaf as for a separate specialization constant. It contains the
following data:
- ID of composite constants leaf, i.e. ID of scalar spec constant
- Offset from the beginning of composite, which points to the location of a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the offset also points to the location of the specialization value in the byte array provided by the user. Should we mention it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this item in 8f323a1

Copy link
Contributor

@AlexeySotkin AlexeySotkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks!

@daoviethoang0793
Copy link

daoviethoang0793 commented Nov 19, 2020 via email

@bader bader merged commit 81963d1 into intel:sycl Nov 19, 2020
@AlexeySachkov AlexeySachkov deleted the private/asachkov/spec-constants-design-update branch February 25, 2021 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants