Skip to content

[SYCL][libdevice] Keep sign bit of result for std::sin(-0) #17440

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 2 commits into from
Mar 17, 2025

Conversation

jinge90
Copy link
Contributor

@jinge90 jinge90 commented Mar 13, 2025

For input '-0', __spirv_ocl_sin returns +0 for float and returns -0 for double, MSVC complex math implementation does depend on this, discarding the signbit for sin(-0) will lead to some corner case failures in exp(std::complex) e2e tests. This patch is a workaround for the issue.

@jinge90 jinge90 requested a review from a team as a code owner March 13, 2025 07:03
@jinge90
Copy link
Contributor Author

jinge90 commented Mar 13, 2025

Hi, @KornevNikita
This PR should fix the pre-ci failure for #16639
Could you try it?
Thanks very much.

For input '-0', __spirv_ocl_sin returns +0 for float and returns
-0 for double, although no definition exists in standard for -0
input, MSVC complex math implementation does depend on this,
discarding the signbit for sin(-0) will lead to some corner case
failures in exp(std::complex<float>) e2e tests. This patch is a
workaround for the issue.
@KornevNikita
Copy link
Contributor

KornevNikita commented Mar 13, 2025

@jinge90 I've cherry-picked your commit to my PR, waiting for the pre-commit results.
UPD. yep, the test passes now

Copy link
Contributor

@KseniyaTikhomirova KseniyaTikhomirova left a comment

Choose a reason for hiding this comment

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

LGTM but libdevice should be reviewed by another team, not SYCL RT

@Naghasan
Copy link
Contributor

Naghasan commented Mar 13, 2025

_spirv_ocl_sin returns +0 for float and returns -0 for double, although no definition exists in standard for -0 input

There is and it should return -0, the driver has a bug. See https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html#edge-case-behavior, and C99 F.9.1.6 states sin(-0) returns -0.

@KseniyaTikhomirova KseniyaTikhomirova self-requested a review March 13, 2025 11:48
@bader
Copy link
Contributor

bader commented Mar 13, 2025

libdevice should be reviewed by another team, not SYCL RT

@KseniyaTikhomirova, I disagree with this statement. libdevice code is owned by SYCL RT team for the last 3+ years. If you want to transfer the ownership to another team, please, open a PR changing https://github.com/intel/llvm/blob/sycl/.github/CODEOWNERS. The PR must be approved by both teams SYCL RT and new libdevice code owner team.

@jinge90
Copy link
Contributor Author

jinge90 commented Mar 14, 2025

_spirv_ocl_sin returns +0 for float and returns -0 for double, although no definition exists in standard for -0 input

There is and it should return -0, the driver has a bug. See https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html#edge-case-behavior, and C99 F.9.1.6 states sin(-0) returns -0.

Hi, @Naghasan
Thanks very much for pointing out this! I will report this to GPU driver developers and before the driver bug is fixed, we will use this workaround to fix complex math's corner case failure.

@jinge90 jinge90 requested a review from a team March 14, 2025 01:57
Signed-off-by: jinge90 <[email protected]>
@Maetveis
Copy link
Contributor

LGTM, thanks!

@jinge90 jinge90 removed the request for review from a team March 17, 2025 06:07
@jinge90
Copy link
Contributor Author

jinge90 commented Mar 17, 2025

Hi, @intel/llvm-gatekeepers
Could you help merge this PR?
Thanks very much.

@sommerlukas sommerlukas merged commit c0ee586 into intel:sycl Mar 17, 2025
22 checks passed
kbenzie pushed a commit that referenced this pull request Mar 17, 2025
The issue was fixed by #17440

---------

Co-authored-by: jinge90 <[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.

7 participants