Skip to content

[SYCL][sycl-post-link] Implement transformation of sycl-properties annotations #5940

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

Conversation

steffenlarsen
Copy link
Contributor

This commit adds the transformation from llvm.ptr.annotations calls with "sycl-properties" as the annotation string into llvm.ptr.annotations calls with decoration IDs and values in a format the SPIR-V translator is able to translate into SPIR-V decorations.

…notations

This commit adds the transformation from llvm.ptr.annotations calls with
"sycl-properties" as the annotation string into llvm.ptr.annotations
calls with decoration IDs and values in a format the SPIR-V translator
is able to translate into SPIR-V decorations.

Signed-off-by: Steffen Larsen <[email protected]>
@steffenlarsen steffenlarsen requested a review from a team as a code owner March 31, 2022 15:50
@steffenlarsen
Copy link
Contributor Author

Changes to design document to reflect this format is in review here: #5884
SPIR-V translator changes have been merged and CFE changes are in review here: #5879

assert(IntrInst->getNumUses() == 0);
IntrInst->eraseFromParent();
}

// The pass just adds some metadata to the module, it should not ruin
Copy link

Choose a reason for hiding this comment

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

I'm not sure if this comment is actual now because the pass doesn't just add some metadata anymore. Can rewriting the @llvm.ptr.annotation intrinsics have any influence on the analysis?

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 don't imagine changing the annotation strings of a llvm.ptr.annotation with our own "sycl-properties" special-name should affect any analyses. However, I don't know if removing an annotation could affect any previous analyses. @AlexeySachkov - Do you know?

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 - Do you have some insight into this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we really care if this change can affect transformation (and therefore lead to different IR). Theoretically it could affect subsequent IR t-forms happening before SPIRV generation if they depend on llvm.ptr.annotations (maybe transitively via Analyses). But AFAICS, this is the last tform before SPIRV.

BTW, If this transformation does not require fully linked program, then sycl-post-link would be a wrong place for it. It is always preferable to put additional IR passes to compilation (via BakendUtil.cpp) over putting them into post-link.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW, If this transformation does not require fully linked program, then sycl-post-link would be a wrong place for it. It is always preferable to put additional IR passes to compilation (via BakendUtil.cpp) over putting them into post-link.

At the moment I don't believe it needs a fully linked program, but we could have a similar situation in the future to the devce_global where one of the properties need metadata information propagated to the runtime. We could of course create a new representation sycl-post-link would need to look for, but it does complicate the design.

Likewise, we would be splitting the property-translation logic, that is some would be done in additional IR pass (annotations -> annotations) while others would be done in sycl-post-link (IR attributes -> metadata). Would there be a good way for the two to share some logic?

@gmlueck - Ping in case you have some opinions on this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this is the pass that converts @llvm.ptr.annotation from the form that contains the property names (strings) into the form that contains SPIR-V decoration numbers? (This follows the design in #5884.) Correct?

That pass is part of the general logic for converting LLVM IR into a "SPIR-V friendly form", and I thought we did all of this logic in sycl-post-link, just before we translate to SPIR-V. One advantage of this, I suppose, is that we can avoid doing this translation for targets that don't use SPIR-V.

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 is indeed the implementation of that pass, currently shared with the logic for translating IR attributes.

Since @kbobrovs suggests for the pass to be part of BackendUtil.cpp, I believe we should be able to make it an elective pass that is only run when SPIR-V is the target, while other backend targets can use their own pass for the translations. However, for device_global sycl-post-link still needs to create the unique ID and communicate it to the runtime. We may be able to split the generation of the unique ID and the generation of the corresponding metadata to an earlier IR pass, but in that case sycl-post-link would have to parse the "SPIR-V friendly" metadata and base the information for the runtime on that.

Copy link
Contributor

Choose a reason for hiding this comment

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

We may be able to split the generation of the unique ID and the generation of the corresponding metadata to an earlier IR pass, but in that case sycl-post-link would have to parse the "SPIR-V friendly" metadata and base the information for the runtime on that.

Isn't this a reason not to move the translation to "SPIR-V friendly" form to BackendUtil.cpp? If we did this, then sycl-post-link needs to understand either the SPIR-V friendly form or the normal LLVM IR form (depending on whether the target supports SPIR-V)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we did this, then sycl-post-link needs to understand either the SPIR-V friendly form or the normal LLVM IR form (depending on whether the target supports SPIR-V)?

Either that, or we would make a common part of the pass (or another pass) that adds some new information that sycl-post-link will consume. It does complicate the design, but it would make backend-specific parsing of properties easier.

Either way, I think it should be considered for the entire pass rather than the changes made in this. @kbobrovs do you think there would be a problem in going with it as part of sycl-post-link for now and then discuss the transition to BackendUtil.cpp separately?

Copy link
Contributor

Choose a reason for hiding this comment

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

@steffenlarsen, I think transition to BackendUtil.cpp should be discussed separately, my comment was not meant to hold this PR.

A note about BackendUtil.cpp vs sycl-post-link.cpp. The original intent of sycl-post-link was to perform transformations which can not be done w/o knowing the entire program - such as assigning specialization constant IDs. The more transformations are implemented in sycl-post-link, the farther SYCL is from other compilers many of which don't even use any additional link-time IR transformations by default. It is like having a "hidden pass manager" in the form of the sycl-post-link, which bypasses clang optimization/transformation control mechanisms. There are some other disadvantages: extra link time (important for device libraries, which get compiled once and linked many times), compiler developers need to run post-link to see final code before SPIRV.

Signed-off-by: Steffen Larsen <[email protected]>
Signed-off-by: Steffen Larsen <[email protected]>
@steffenlarsen steffenlarsen requested a review from kbobrovs April 7, 2022 12:15
ghost
ghost previously approved these changes Apr 8, 2022
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

The changes themselves LGTM, I'm unable to give any advice about the design.

Signed-off-by: Larsen, Steffen <[email protected]>
@steffenlarsen steffenlarsen merged commit 35c2e00 into intel:sycl May 3, 2022
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.

3 participants