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

Remove CoreCLR math.h CRT PAL Redefines #98048

Merged
merged 21 commits into from
Feb 10, 2024
Merged

Conversation

jkoritzinsky
Copy link
Member

In the CoreCLR PAL, we redefine some of the math.h functions. These functions were redefined to provide consistent behavior in various boundary conditions (such as getting a byte-for-byte exact answer in some scenarios).

These APIs were used by CoreCLR and RyuJIT, but were not used by NativeAOT or Mono, so users could get unexpectedly different behavior (NativeAOT in particular, where a constant-propagated result would have the result from the PAL, but a non-const-prop result would have the underlying CRT function's results instead).

This PR extracts these APIs from the CoreCLR PAL and moves them into a library under src/native to provide this consistent functionality across all runtimes for these APIs.

This does not change the experience for the LLVM-backend, which uses LLVM-intrinsics today to implement these functions.

@ghost
Copy link

ghost commented Feb 6, 2024

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

Issue Details

In the CoreCLR PAL, we redefine some of the math.h functions. These functions were redefined to provide consistent behavior in various boundary conditions (such as getting a byte-for-byte exact answer in some scenarios).

These APIs were used by CoreCLR and RyuJIT, but were not used by NativeAOT or Mono, so users could get unexpectedly different behavior (NativeAOT in particular, where a constant-propagated result would have the result from the PAL, but a non-const-prop result would have the underlying CRT function's results instead).

This PR extracts these APIs from the CoreCLR PAL and moves them into a library under src/native to provide this consistent functionality across all runtimes for these APIs.

This does not change the experience for the LLVM-backend, which uses LLVM-intrinsics today to implement these functions.

Author: jkoritzinsky
Assignees: -
Labels:

area-Meta

Milestone: -

@ghost ghost assigned jkoritzinsky Feb 6, 2024
Copy link
Member

@lambdageek lambdageek left a comment

Choose a reason for hiding this comment

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

mono bits lgtm

@vargaz
Copy link
Contributor

vargaz commented Feb 6, 2024

The mono changes look ok to me.

@jkoritzinsky
Copy link
Member Author

@tannergooding @jkotas instead of having the separate netintrinsics library/target, we could instead just remove the shims as the tests for the Math and MathF APIs have been passing on CoreCLR, Mono, and NativeAOT for quite a while with only CoreCLR having the shims. What do you think?

@ryujit-bot
Copy link

Diff results for #98048

Throughput diffs

Throughput diffs for linux/arm64 ran on windows/x64

MinOpts (-0.01% to +0.00%)
Collection PDIFF
libraries.pmi.linux.arm64.checked.mch -0.01%

Throughput diffs for windows/arm64 ran on windows/x64

MinOpts (-0.00% to +0.01%)
Collection PDIFF
libraries.pmi.windows.arm64.checked.mch +0.01%

Details here


@ryujit-bot
Copy link

Diff results for #98048

Throughput diffs

Throughput diffs for linux/arm64 ran on windows/x64

MinOpts (-0.00% to +0.01%)
Collection PDIFF
libraries.pmi.linux.arm64.checked.mch +0.01%

Details here


@jkoritzinsky
Copy link
Member Author

/azp run runtime-coreclr libraries-jitstress

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkoritzinsky
Copy link
Member Author

@tannergooding theres some JitStress failures for TensorPrimitives, but the TC=0 and TC=1 lanes are both green for all numerics tests (there's one timeout in Dataflow which I don't think is related).

Let me know if you think there's any more test lanes I should run here.

@tannergooding
Copy link
Member

Let me know if you think there's any more test lanes I should run here.

The extra platforms to get additional Mono coverage is the only one I can think of.

theres some JitStress failures for TensorPrimitives

At a glance looks like this is failing for x86 in outerloop due to a timeout (which Jakob fixed earlier today) and more recently for Arm64 under JitStress2 due to some bug in TensorPrimitives.Round (potentially related to #98186 and the switch of double from using CreateScalar to using CreateScalarUnsafe, although they should be identical for double).

@jkoritzinsky
Copy link
Member Author

Now that there's no Mono or NativeAOT changes, I don't think we'd get any additional coverage by running extra-platforms

I'll remove the mono infra change, resolve the merge conflicts, and rerun CI.

@jkoritzinsky
Copy link
Member Author

Cleaned everything up I wanted to clean up in this PR. This is ready for final review before merging.

Copy link
Member

@jkotas jkotas 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!

@ryujit-bot
Copy link

Diff results for #98048

Throughput diffs

Throughput diffs for linux/arm64 ran on windows/x64

MinOpts (-0.01% to +0.00%)
Collection PDIFF
libraries.pmi.linux.arm64.checked.mch -0.01%

Details here


@jkoritzinsky jkoritzinsky merged commit 0ce3c32 into dotnet:main Feb 10, 2024
196 of 199 checks passed
#define acos DUMMMY_acos
#define asin DUMMMY_asin
#define atan2 DUMMMY_atan2
#define exp DUMMMY_exp
Copy link
Member

Choose a reason for hiding this comment

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

@jkoritzinsky I have noticed that you have by accident used DUMMMY instead of DUMMY prefix (tripple M instead of double). While this doesn't have any effect on the functionality, it would be nice to change that eventually.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll clean this up in the next week or so (either by fixing it or enabling the usage of standard CRT headers by removing the rest of the overrides)

@github-actions github-actions bot locked and limited conversation to collaborators Mar 14, 2024
@jkoritzinsky jkoritzinsky deleted the math-pal branch March 22, 2024 01:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants