Skip to content

[libclc] Don't run remangler on OpenCL library #18697

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

Merged

Conversation

wenju-he
Copy link
Contributor

The remangler is for libspirv. Don't run remangler on OpenCL library until there is a use case. This would avoids confusions on unused remangled OpenCL library in build folder.

The remangler is for libspirv. Don't run remangler on OpenCL library
until there is a use case. This would avoids confusions on unused
remangled OpenCL library in build folder.
@wenju-he wenju-he requested a review from a team as a code owner May 28, 2025 09:05
@wenju-he wenju-he requested a review from omarahmed1111 May 28, 2025 09:05
@wenju-he wenju-he temporarily deployed to WindowsCILock May 28, 2025 09:05 — with GitHub Actions Inactive
Copy link
Contributor

@frasercrmck frasercrmck 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. I was wanting to do this. On sycl-web I've also started to fix all of our downstream modifications to the OpenCL builtins.

I've left a suggestion about another way to do it, but nothing blocking. I suspect this code will undergo changes anyway.

@@ -483,7 +483,7 @@ function(add_libclc_builtin_set)
install( FILES ${builtins_lib} DESTINATION ${CMAKE_INSTALL_DATADIR}/clc )

# Generate remangled variants if requested
if( LIBCLC_GENERATE_REMANGLED_VARIANTS )
if( LIBCLC_GENERATE_REMANGLED_VARIANTS AND "${ARG_TARGET_ENV} " MATCHES "^libspirv" )
Copy link
Contributor

Choose a reason for hiding this comment

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

Just because matching ARG_TARGET_ENV with a regex is a little gnarly we could perhaps alternatively pass in something based on LIBCLC_GENERATE_REMANGLED_VARIANTS as an arg to add_libclc_builtin_set, and only pass it in for the libspirv version?

That said, this is all pretty messy (checking and changing obj_suffix, below) and could do with a refactor. Perhaps we can get rid of the remangler entirely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just because matching ARG_TARGET_ENV with a regex is a little gnarly we could perhaps alternatively pass in something based on LIBCLC_GENERATE_REMANGLED_VARIANTS as an arg to add_libclc_builtin_set, and only pass it in for the libspirv version?

done, thanks

Perhaps we can get rid of the remangler entirely.

Do you mean we don't run remangler on libspirv? Can we rename built-in in device code when necessary in a pass during linking of libspirv?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still not 100% sure, we haven't started looking at it in detail. Perhaps the compiler could provide headers that forward the host types on to the OpenCL types. Or perhaps we could change the OpenCL mangling itself via an extension or compiler option. There's nothing in the OpenCL spec to say that a char or long has to be mangled in a specific way.

Or yes it could perhaps be a compiler pass - but moving things out of the 'clang' space is likely going to be difficult, since we currently rely on clang for the remangler. I suspect having it in LLVM would lead to more assumptions. Basically I'd really like to avoid doing any actual demangling and remangling as it's not very robust,.. or nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps the compiler could provide headers that forward the host types on to the OpenCL types. Or perhaps we could change the OpenCL mangling itself via an extension or compiler option. There's nothing in the OpenCL spec to say that a char or long has to be mangled in a specific way.

thanks @frasercrmck, it looks very promising to me. Without the above support, renaming is always required for libspirv, making it awkward to compile libspirv using OpenCL C.

@wenju-he wenju-he temporarily deployed to WindowsCILock May 29, 2025 01:57 — with GitHub Actions Inactive
@wenju-he wenju-he requested a review from frasercrmck May 29, 2025 02:06
@wenju-he wenju-he temporarily deployed to WindowsCILock May 29, 2025 02:19 — with GitHub Actions Inactive
@wenju-he wenju-he temporarily deployed to WindowsCILock May 29, 2025 02:19 — with GitHub Actions Inactive
Copy link
Contributor

@frasercrmck frasercrmck 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, thanks! It removes a whole bunch of remangled OpenCL libraries on my system 👍

@wenju-he
Copy link
Contributor Author

@intel/llvm-gatekeepers please merge, thanks, BMG fail is probably infrastructure issue because they pass in the runs of the first commit.

@aelovikov-intel aelovikov-intel merged commit 3c91cf9 into intel:sycl May 30, 2025
34 of 37 checks passed
@wenju-he wenju-he deleted the libclc-do-not-remangle-opencl-library branch June 2, 2025 01:47
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