Skip to content

[SYCL] Add option to sycl-post-link to embed module properties/symbols as metadata #14197

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

Closed
wants to merge 2 commits into from

Conversation

sarnex
Copy link
Contributor

@sarnex sarnex commented Jun 17, 2024

With thinLTO, we decided to run sycl-post-link early. To do that, we need to be able to figure out the properties and symbol table for each split inside clang-linker-wrapper. Today these are computed inside sycl-post-link after splitting, and we need a way to get them inside clang-linker-wrapper. Right now sycl-post-link is written such that these are most easily computed on a module that has just been split. It should be possible to change that to only look at a BC file without requiring that it was just split, but it seemed simpler to just keep the current architecture. To do that, we embed the symbol table and module properties into the module when thinLTO is enabled. This information will later be read by clang-linker-wrapper, to be added in a future change.

When this option is enabled, we don't create separate files for the properties and symbols and also do not add it to the output table.

@sarnex sarnex temporarily deployed to WindowsCILock June 17, 2024 17:41 — with GitHub Actions Inactive
@sarnex sarnex marked this pull request as ready for review June 17, 2024 20:23
@sarnex sarnex requested review from a team as code owners June 17, 2024 20:23
bool IsUsingLTO = TC.getDriver().isUsingLTO(/*IsDeviceOffloadAction=*/true);
auto LTOMode = TC.getDriver().getLTOMode(/*IsDeviceOffloadAction=*/true);
if (IsUsingLTO && LTOMode == LTOK_Thin)
addArgs(PostLinkArgs, TCArgs, {"-embed-aux-info-as-metadata"});
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't look like it needs any Triple information to resolve - can you move into getNonTripleBasedSYCLPostLinkOpts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh yeah sorry, fixed in latest commit, thanks.

Signed-off-by: Sarnie, Nick <[email protected]>
@sarnex sarnex temporarily deployed to WindowsCILock June 17, 2024 20:42 — with GitHub Actions Inactive
@sarnex sarnex temporarily deployed to WindowsCILock June 17, 2024 22:08 — with GitHub Actions Inactive
Copy link
Contributor

@bader bader left a comment

Choose a reason for hiding this comment

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

I'm not sure about this approach, so I'd like @AlexeySachkov to review as well.

According to my understanding, sycl-post-link runs llvm pass to obtain SYCL properties and sym-table (i.e. this information is encoded in LLVM IR) and saves it to a separate file, so that SYCL runtime won't need to parse LLVM IR.

Don't clang-linker-wrapper parses LLVM module? If so, it make sense to run the analysis pass in clang-linker-wrapper instead of sycl-post-link tool to avoid an overhead on handling metadata.

Comment on lines +2 to +3
; In particular, we should see the properties and symbols file are not added to the output table
; and are instead embedded in the module as metadata.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
; In particular, we should see the properties and symbols file are not added to the output table
; and are instead embedded in the module as metadata.
; In particular, we should see the properties and symbols file are embedded in the module as metadata.

if (DoSymGen) {
// We don't need a seperate file with properties if we saved it as
// metadata inside the module itself.
if (!EmbedAuxillaryInfoAsMetadata)
Copy link
Contributor

Choose a reason for hiding this comment

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

Little bit of simplification. We can do,
if (EmbedAuxillaryInfoAsMetadata)
return Res;
followed by original code.

@asudarsa
Copy link
Contributor

I'm not sure about this approach, so I'd like @AlexeySachkov to review as well.

According to my understanding, sycl-post-link runs llvm pass to obtain SYCL properties and sym-table (i.e. this information is encoded in LLVM IR) and saves it to a separate file, so that SYCL runtime won't need to parse LLVM IR.

Don't clang-linker-wrapper parses LLVM module? If so, it make sense to run the analysis pass in clang-linker-wrapper instead of sycl-post-link tool to avoid an overhead on handling metadata.

I did have some thoughts in similar lines. I am ok with adding this functionality inside the sycl-post-link. We can try to move it out of the post-link tool and possibly right to the spot where it gets consumed in a future PR.
I also, think that the design/implementation is getting to a stage where it will be beneficial to have a design document backing this effort. For example, though it is perfectly fine to add the prop/sym 'consumer' logic in a future PR, it will be beneficial to understand how/where we will be doing that.
Need not block this PR though.

Thanks

@asudarsa
Copy link
Contributor

Add [thinLTO] to PR topic?

@@ -7,3 +7,4 @@
// Verify there's no error and we see the expected cc1 flags with the new offload driver.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Verify there's no error and we see the expected cc1 flags with the new offload driver.
// Verify there's no error and we see the expected cc1 and sycl-post-link flags with the new offload driver.

Copy link
Contributor

@asudarsa asudarsa left a comment

Choose a reason for hiding this comment

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

Overall LGTM. Few minor comments.
This PR is well-written and is designed such that it is a well-guarded and incremental change. I will wait for consensus on the discussion about where this logic needs to reside to see if anyone identifies a red flag.
From my side, I am fine with the current location and any optimization can be added later.

Thanks @sarnex.

@AlexeySachkov
Copy link
Contributor

I'm not sure about this approach, so I'd like @AlexeySachkov to review as well.

According to my understanding, sycl-post-link runs llvm pass to obtain SYCL properties and sym-table (i.e. this information is encoded in LLVM IR) and saves it to a separate file, so that SYCL runtime won't need to parse LLVM IR.

Don't clang-linker-wrapper parses LLVM module? If so, it make sense to run the analysis pass in clang-linker-wrapper instead of sycl-post-link tool to avoid an overhead on handling metadata.

I think that gathering properties later in a pipeline (i.e. within clang-linker-wrapper) is a right thing to do. Their only purpose is to be embedded into device image (somehow) so that SYCL RT can read them afterwards, i.e. they should not be used by linker or any of our sycl-post-link steps, they are generated and used at the very end right before we do wrapping.

Moreover, thinLTO implies some optimizations, right? It could theoretically invalidate some of those properties due to LLVM IR changes. Moreover, some of the properties (like ones about specialization constants) can only be gathered once we have linked device image - computing them before any kind of linking is not possible.

At first glance this PR seems like a workaround for not calling sycl-post-link in thinLTO pipeline, but do we really need to spend time on this? Wouldn't it be better to just officially incorporate properties generation part into clang-linker-wrapper so it can be used by both fullLTO and thinLTO paths?

@sarnex
Copy link
Contributor Author

sarnex commented Jun 18, 2024

Thanks for the comments and sorry @AlexeySachkov I must have misunderstood our earlier conversion, I got the impression we decided to do it this way.

I'll drop this PR and try to rework how property generation works so we can call it from clang-linker-wrapper.

@sarnex sarnex closed this Jun 18, 2024
sarnex added a commit that referenced this pull request Jun 28, 2024
…n into IR-based analysis (#14220)

Based on feedback from #14197, I
seperated out the code that generates the module properties and symbol
table into separate functions that can be called by anyone, and just
looks at the IR and entry points.

For now, we still call it inside `sycl-post-link` because we still
support the old offloading model, but once we drop support for that we
can drop this responsibility from sycl-post-link and only compute it
inside `clang-linker-wrapper`, both for normal compilation and thinLTO.

In a (hopefully soon) future PR I plan to call these functions from
`clang-linker-wrapper` when compiling for thinLTO, which we need because
we will split early.

Most of this change should be NFC(I). The expected changes are:

1) New option to sycl-post-link to generate the properties file
2) Driver change to NOT pass the option from 1) in thinLTO mode
3) Two minor chages in logic from properties generation, I've called
these out inline.

---------

Signed-off-by: Sarnie, Nick <[email protected]>
calebwat pushed a commit that referenced this pull request Jul 1, 2024
…n into IR-based analysis (#14220)

Based on feedback from #14197, I
seperated out the code that generates the module properties and symbol
table into separate functions that can be called by anyone, and just
looks at the IR and entry points.

For now, we still call it inside `sycl-post-link` because we still
support the old offloading model, but once we drop support for that we
can drop this responsibility from sycl-post-link and only compute it
inside `clang-linker-wrapper`, both for normal compilation and thinLTO.

In a (hopefully soon) future PR I plan to call these functions from
`clang-linker-wrapper` when compiling for thinLTO, which we need because
we will split early.

Most of this change should be NFC(I). The expected changes are:

1) New option to sycl-post-link to generate the properties file
2) Driver change to NOT pass the option from 1) in thinLTO mode
3) Two minor chages in logic from properties generation, I've called
these out inline.

---------

Signed-off-by: Sarnie, Nick <[email protected]>
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.

5 participants