Skip to content

[SYCL][NVPTX][AMDGCN] Fix compilation for cmath long double #19558

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
merged 6 commits into from
Jul 23, 2025

Conversation

Maetveis
Copy link
Contributor

Make sure to not define long double wrappers in the cmath wrapper. We unintentionally defined these for two or three argument functions with mixed types. These definitions fail to compile if we try to use them, because there are no SPIR-V builtins for long double. By not defining them, overload resolution will pick the "host" versions. We can't make overload resolution fail, because function bodies that are not called on the device still need to be semantically valid for the device.

This was discovered by the SYCL CTS, in its reference implementation for the builtins. That code is never called on the device, but it needs to compile without errors.

Make sure to not define `long double` wrappers in the cmath wrapper.
We unintentionally defined these for two or three argument functions
with mixed types. These definitions fail to compile if we try to use
them, because there are no SPIR-V builtins for long double.
By not defining them, overload resolution will pick the "host" versions.
We can't make overload resolution fail, because function bodies that
are not called on the device still need to be semantically valid for the
device.

This was discovered by the SYCL CTS, in its reference implementation
for the builtins. That code is never called on the device, but it needs
to compile without errors.
@Maetveis Maetveis requested review from bader and npmiller July 23, 2025 09:01
@Maetveis Maetveis requested a review from a team as a code owner July 23, 2025 09:01
@Maetveis Maetveis requested a review from steffenlarsen July 23, 2025 09:01
@Maetveis
Copy link
Contributor Author

The mentioned code from the SYCL-CTS is here: https://github.com/KhronosGroup/SYCL-CTS/blob/main/util/math_reference.h#L433

Copy link
Contributor

@steffenlarsen steffenlarsen left a comment

Choose a reason for hiding this comment

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

Does the SYCL-CTS test the std math function on device? How do we know that long double is even supported on a given device?

Co-authored-by: Steffen Larsen <[email protected]>
@steffenlarsen
Copy link
Contributor

@Maetveis - Please see my previous comment. I don't necessarily think this is wrong, but I am concerned about the need for the use of long double and cmath functions in the device code of the CTS.

@Maetveis
Copy link
Contributor Author

Maetveis commented Jul 23, 2025

Does the SYCL-CTS test the std math function on device?

Yes, it runs on the device and is compared to reference values on the host. long double is not used on the device, only for the host reference implementations. However that "host" code still has to make it through semantic analysis during device compilation, we will just not codegen it.

How do we know that long double is even supported on a given device?

I don't think long double is ever supported by any device actually.

The comment about the SYCL-CTS is mostly for reference. The reduced testcase added in the PR can be reasonably expected to compile in SYCL language mode, and without the rest of the changes it does not.

@Maetveis
Copy link
Contributor Author

Maetveis commented Jul 23, 2025

Does the SYCL-CTS test the std math function on device?

Yes, it runs on the device and is compared to reference values on the host.

I checked more deeply and I think I was wrong on this in the previous comment, the test only calls the math functions from the sycl namespace on the device.

(Called functions are defined here: https://github.com/KhronosGroup/SYCL-CTS/blob/main/tests/math_builtin_api/modules/sycl_functions.py#L44, the first namespace field is never std)

Copy link
Contributor

@steffenlarsen steffenlarsen left a comment

Choose a reason for hiding this comment

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

Thank you for clarifying! I think the change is fine, though I feel like the long double specialization is a little redundant. The note is nice though.

@Maetveis
Copy link
Contributor Author

@intel/llvm-gatekeepers I believe this should be ready to merge, thanks :)

@againull againull merged commit 121c876 into intel:sycl Jul 23, 2025
39 of 40 checks passed
@Maetveis Maetveis deleted the fix-cmath-long-double branch July 23, 2025 19:19
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