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

[SYCL][libdevice] Don't force linkage to weak #14096

Draft
wants to merge 1 commit into
base: sycl
Choose a base branch
from
Draft

Conversation

sarnex
Copy link
Contributor

@sarnex sarnex commented Jun 7, 2024

I'm working on thinLTO and weak symbols are not guaranteed to be the same everywhere, so the thinLTO infrastructure does not link them in so devices libraries don't work.

I don't know of any reason to explicitly mark them as weak and in reality these functions should follow ODR, so just remove the specification.

Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
@sarnex sarnex marked this pull request as ready for review June 10, 2024 15:58
@sarnex sarnex requested a review from a team as a code owner June 10, 2024 15:58
@sarnex sarnex requested a review from againull June 10, 2024 15:58
@againull againull requested a review from jinge90 June 10, 2024 20:03
againull
againull previously approved these changes Jun 10, 2024
Copy link
Contributor

@againull againull left a comment

Choose a reason for hiding this comment

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

Looks good to me. Adding @jinge90 for awareness just in case if there are some concerns.

@sarnex
Copy link
Contributor Author

sarnex commented Jun 10, 2024

Thanks, I will wait a bit for any feedback from @jinge90 before merging.

@jinge90
Copy link
Contributor

jinge90 commented Jun 11, 2024

Hi, @sarnex and @againull
When sycl device library was added, we found some user may define their own version, for example, they may define a device version "sinf/cosf" in source code and multiple definition error will be reported since sycl device library also has provided these functions. Since sycl device library are linked by default, we don't know whether user will define their own version of some library function, so "weak" is added to avoid link error.
I haven't tried the latest compiler but suspect compiler will fail to compile any code including their own definition for functions which are provided in sycl device library as well if we remove "weak".
Thanks very much.

@sarnex
Copy link
Contributor Author

sarnex commented Jun 11, 2024

@jinge90 Thanks for the response. It seems like the relevant SYCL spec document is here

It seems the problem in question could happen with separate translation units, one that does not include cmath and uses a user defined sinf, and another one that includes cmath and uses the device library sinf.

My understanding of the current behavior/design as explained above is that we explicitly mark all device lib functions as weak linkage so that in the above case, both translation units will end up using the user defined sinf when linked.

This seems really strange to me. My initial reaction is that an error is the correct behavior, overwriting the function from another TU seems weird.

@gmlueck @intel/dpcpp-specification-reviewers Can you guys comment if the SYCL spec and/or our SYCL extensions give an idea of what should happen in this case? If not, can you give your opinion on what should happen?

@gmlueck
Copy link
Contributor

gmlueck commented Jun 11, 2024

This isn't really a spec question. The spec does not say that you can define your own version of a standard library. Strictly speaking, I think this is UB by the C++ language. However, if customers are doing it now, and you cause that code to break, then those customers will be unhappy.

What is the motivation for removing the "weak"? It sounds like thinLTO doesn't work with weak symbols? However, weak symbols are a pretty common C/C++ feature. Does thinLTO not work for regular C/C++ programs when there are weak symbols?

It seems the problem in question could happen with separate translation units, one that does not include cmath and uses a user defined sinf, and another one that includes cmath and uses the device library sinf.

I think @jinge90 is saying that the problem occurs even with a single TU that defines a a function like sinf. It would be good to try some examples and see exactly what cases will break if you remove the "weak".

@sarnex sarnex dismissed againull’s stale review June 11, 2024 17:44

don't want this to be merged accidentally

@sarnex
Copy link
Contributor Author

sarnex commented Jun 11, 2024

Thanks Greg. It looks like it actually thinLTO with weak symbols does work for pure x86 code, so let me investigate why the upstream community clang-linker-wrapper thinLTO doesn't work but the upstream community x86 thinLTO linker plugin does work. I'll come back to this PR if I think we really do need this change. Thanks to everyone for giving me a better place to investigate. Marking as a draft for now.

@sarnex sarnex marked this pull request as draft June 11, 2024 17:59
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.

4 participants