Skip to content

SIMD revision proposal #690

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
Nov 3, 2022
Merged

SIMD revision proposal #690

merged 6 commits into from
Nov 3, 2022

Conversation

WhiteBlackGoose
Copy link
Contributor

Improves the SIMD experience in Maths.

Copy link
Member

@Perksey Perksey left a comment

Choose a reason for hiding this comment

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

Some pre-review comments: after these are addressed, please mark it as "Ready for Review" and we will review it in the meeting

@Perksey Perksey marked this pull request as ready for review November 29, 2021 19:20
@Perksey Perksey requested a review from a team as a code owner November 29, 2021 19:20
@Perksey
Copy link
Member

Perksey commented Nov 29, 2021

Proposal needs work (open questions addressed). Discussed in Working Group meeting 29/11/2021, 19:13 UTC.

Note: it has been assumed that all SIMD proposal elements are also being applied to Scalar.

  • IEEE754

    • All methods and code thus far just follows whatever makes it fast, no compliance to any standard or other behaviour (c# builtin, hardware, etc) is guaranteed
      • Pretty good to be that way, as we can be the fastest and 100% accuracy most people don't care about
    • There's a difference between doing things for correctness and doing it for performance.
    • example optimization which could be problematic: treating NaN as 0, assuming it'll never happen (case in point: GCC fastmath)
    • Don't throw exceptions in performant, use NaN instead to represent exceptional circumstances? What about ints?
    • The only time you can accelerate if a value is a constant (JIT-level knowledge...)
    • Separate methods for opt-in correctness-sacrificial optimizations?
      • "I'm aware of the implications, and am ready for them"
    • Most sense, least surprise (0 / 0 = 0)
    • Something like a "IsMaximum" API to represent the "maximum representable value for a T" and use that in operations
    • .NET's default behaviour is changing to match Rust, WASM etc - platform-specifics (i.e. faster paths)
    • "do whatever the operator will do"
    • Just throw exceptions where they're not trivially avoidable.
    • We want all of the APIs to be as close as they can to hardware-accelerated.
      • are we sure? should they be explicitly labelled?
      • If we're using an inaccurate algorithm, should it be explicitly labelled?
      • Figure out ULP, and document if we're making this decision? The user could check the docs, find the ULP, and then either use the library or don't use the library according to that.
      • It's not trivial to find edge cases, could catch people out without realising?
      • Let's just add estimate APIs
    • For estimate APIs should they throw exceptions?
  • Reciprocal of int

    • see consensus
  • IsHardwareAccelerated

    • Make IsHardwareAccelerated per-type
    • Perhaps we could make a smarter way of doing IsHardwareAccelerated, but the working group thinks it's not necessary (and also has no ideas)
    • "Some or most of the APIs for this type are hardware accelerated"
      • Methods that aren't are slow-path
    • Static class with a whole bunch of static APIs for indicating?
    • Where do we draw the line?
    • Lots of checks can hurt the JIT/inliner
    • Usually we optimize "all or nothing" for a given type. There may be a few exceptions, but these would be few and far between.
    • Per-method and per-type is just pernickety and the working group sees no use case for this today/doesn't really matter...

Consensus

  • IEEE754: We'll have estimate APIs and "native"/"more precise" APIs, two versions of all except things built in to the hardware (at a given baseline)
  • Reciprocal: do what C# does for non-estimate (and for estimate as well we guess)
  • IsHardwareAccelerated: one boolean per type. Not worth making a new flag for the few cases where we have a couple of functions which are slow for a given type.

@Perksey
Copy link
Member

Perksey commented Jan 15, 2022

Happy to merge this once comments are addressed and open questions are answered in the doc. If you need any comment clarifications lmk and I'll shake the brain bush.

@WhiteBlackGoose
Copy link
Contributor Author

There's some fair amount of work to distinguish methods which do need Estimate APIs from methods which don't... couldn't yet find time to resolve this 😅

@Perksey
Copy link
Member

Perksey commented Nov 3, 2022

Merging with outstanding comments, as it is only a proposal after all and not gospel... Renamed file to indicate it needs work.

@Perksey Perksey enabled auto-merge (squash) November 3, 2022 12:57
@Perksey Perksey disabled auto-merge November 3, 2022 14:01
@Perksey Perksey merged commit 039e4e5 into dotnet:main Nov 3, 2022
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.

2 participants