Skip to content

Conversation

@frasercrmck
Copy link
Contributor

@frasercrmck frasercrmck commented Apr 17, 2025

This commit revisits the way we achieve the desired host-side mangling of half types as DF16_ (from the _Float16 type) coming from the original mangling of Dh type that OpenCL produces. We were previously manually achieving this by writing over a thousand wrapper functions from _Float16 types to half types.

The remangler can just as easily do this for us, while reducing the total source code line count by over 8000.

This work was originally spurred on by commit 316418d, which modified the AMDGCN sub-group shuffle builtins. In doing so it broke them in a couple of ways.

The first is a typo that hid the SubgroupShuffleXorINTEL builtins for sub 32-bit types but ommitting the 'INTEL' part of the builtin name. That was easily fixed by adjusting the builtin name.

The second was an issue of providing builtins using the OpenCL 'half' data type, without the _Float16 -> half wrappers which we relied on. This accidentally stopped the SYCL host being able to find the right symbols.

Commit 316418d modified the AMDGCN sub-group shuffle builtins. In doing
so it broke them in a couple of ways.

The first is a typo that hid the SubgroupShuffleXorINTEL builtins for
sub 32-bit types but ommitting the 'INTEL' part of the builtin name.

The second was an issue of mangling for the 'half' data type, which
accidentally stopped the SYCL host being able to find the right symbols.

Since libspirv is defined in OpenCL C, the plain 'half' data type is
mangled differently to the sycl::half type used by SYCL: 'Dh' vs
'DF16_'. We've long worked around this using manual mangling of the
builtins, which has never been very nice and has often caused bugs that
are awkward to track down.

This PR takes an alternative approach and instead uses a custom typedef
to the _Float16 type, and defines the sub-group shuffle builtins using
that new type. Since _Float16 is the 'half' type used everywhere except
OpenCL, we arrive at the correct mangling. If this approach proves
successful we might be able to expand on it and remove much of the
manual mangling elsewhere in libspirv.
@frasercrmck frasercrmck requested a review from a team as a code owner April 17, 2025 14:40
@frasercrmck frasercrmck changed the title [libspirv][AMD] Fix sub-group shuffle builtins [libspirv] Use the remangler to correctly mangle half types Apr 22, 2025
@frasercrmck frasercrmck changed the title [libspirv] Use the remangler to correctly mangle half types [libspirv] Use the remangler to mangle half types Apr 22, 2025
@frasercrmck
Copy link
Contributor Author

@intel/llvm-gatekeepers This is ready to merge, thanks.

@sarnex sarnex merged commit e484bea into intel:sycl Apr 23, 2025
25 checks passed
@frasercrmck frasercrmck deleted the libspirv-amd-subgroup-shuffles branch April 23, 2025 15:09
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