-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[RFC]: Portable SIMD Libs Project Group #2977
Conversation
cc @Licenser based on your work in |
@KodrAus Very much, portable SIMD in the standard library would be awesome! |
LGTM. Thanks @KodrAus for putting this together! |
Sounds great! I have no desire to tie myself to particular intrinsics, but would love to be able to write my semantic meaning with a nice rusty library and have it compile to something good for the target. To repeat my personal opinion from the lang issue linked in the RFC: I expect that this will be semantically indistinguishable from an implementation that lowers to just using scalar operations for everything (and would probably do that on targets without simd instructions) so am expecting there to be minimal-if-any lang changes here. It'd be up to |
That works except in a few edge-cases: denormal floating-point numbers work differently on some architectures (ARM) when moving between SIMD/scalar, so requiring the exact same semantics would be detrimental. |
Also: bitwise ops on f32 don't work properly on x86/x64 if |
Rust has official i586 targets (tier2), which are i686 with sse/sse2 turned off (they are on by default in the i686 targets). |
Indeed! I actually currently live with someone who uses a 32 bit computer, so I am being quite serious when I say that the project group will likely have to discuss including some sort of caution about how the behavior will be normalized across architectures as much as possible but architectural variation may yield alterations, or guidelines about programming around such, or something. |
@Licenser @workingjubilee @programmerjake @scottmcm would any of you be interested in supporting the group and be added to the list? On that note... @rfcbot fcp merge Let's get the ball rolling on this so we don't lose any of this momentum! |
Team member @KodrAus has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
I think @sebcrozet may be interested in this too since he worked on |
Based on the current state of the Libs FCP list, I'll go ahead and check SimonSapin's box. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
There's a new simd crate, generic-simd, https://crates.io/crates/generic-simd and its author has shown interest in participating in this effort on Reddit (and states that they don't know how to participate in this groups). |
That's me, I'd like to participate wherever I can be helpful! |
@calebzulawski That's great! I'll add you to the list 😃 We're going to reach the end of the FCP soon so will be able to set up a dedicated workspace and figure out what our first steps will be. |
text/0000-stdsimd.md
Outdated
## Goals | ||
|
||
- Determine the shape of the portable SIMD API. | ||
- Get an unstable `std::simd` and `core::simd` API in the standard library. This may mean renaming `packed_simd` to `stdsimd` and working directly on it, or creating a new repository and pulling in chunks of code as needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we evaluate options other than packed_simd
and stdsimd
too or try experimenting more? Or are these already good enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely something to figure out when we kick off, and at the very least we should survey the various approaches out there. I’d love to take some time to dig into generic-simd
properly.
In general I think we’d settled on a starting point based off packed_simd
, without exposing a generic Simd<T>
(so a public structure similar to wide
), with a sprinkling of const generics for shuffles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we evaluate options other than
packed_simd
andstdsimd
too or try experimenting more? Or are these already good enough?
I think more experimentation carries a significant risk of not reaching the goal of getting to stable.
Notably, simd
already existed before packed_simd
, the initial design of packed_simd
omitted something that simd
already had (boolean/mask vectors) and ended up adding them back, so packed_simd
ended up being like a more comprehensive version of simd
with the internals rewritten.
That is, portable SIMD in Rust has already gone through the cycle of a change in the person working on it resulting in a rewrite that, while making things more comprehensive, on the high level ended up close to the old thing. While each such cycle might improved the design marginally, starting over means the distance to getting the stable gets reset to zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so the goal here is more of stabilizing it rather than having more experimentation to improve the existing ones and then only decide to go stable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also like to mention that even though I started from scratch, generic-simd
ended up particularly similar to packed_simd
, and most of the features would be applicable to an implementation based on packed_simd
.
The major differences of generic-simd
are:
- works on stable (likely irrelevant here)
- a little bit more comprehensive traits (like
num-traits
, but for SIMD) - a different model for runtime feature selection (not sure if this is relevant)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually looking at the LLVM code some more, it seems you can bypass this check by using #[inline(always)]
. Please ignore my previous comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just #[inline]
goes on the core::simd function, and then the caller can choose to target_feature(enable) in a function that uses core::simd.
According to the docs for is_x86_feature_detected!
, that alone should do it, without core::simd needing to be target feature aware at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to use #[inline(always)]
on the core::simd
function otherwise LLVM will refuse to inline functions with mismatching target features. But otherwise you are correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about runtime selection? Is rust going to provide runtime selection for SIMD which may not be zero-cost? Or maybe users can opt-in for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is what the multiversion
crate (or similar) would do.
Actually putting that sort of mechanic in the standard library is probably a whole separate project.
I'm also interested in this in terms of using it in For a fair while I had a branch which was able to function with either A note (though perhaps this should be discussed more once this is kicked off properly and not here) is that |
Lots of Rust has depended on C libs now or in the past. Obviously there's bindings to libc, and there's been various other bindings like to libbacktrace. The general precedent in the Rust project(s) has been "use opportunistically where necessary, then increasingly Rust away the C when it causes problems." Obviously this project group is going to have one of its tasks be "so, what DO we do about SLEEF?" |
While Rust depends on C libs for the libstd, libcore doesn't. libcore and liballoc can be built completely without a C compiler for as long as the |
Right, if SLEEF is involved then APIs that depend on it should be in libstd but not libcore. |
SLEEF is only for |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC will be merged soon. |
It looks like we've got the green light to make a start here! 🥳 As with the Error handling group, we might need some help from our friendly neighborhood @Mark-Simulacrum to set up a I'm happy to write up an announcement post for the Insiders Blog (unless somebody else would like to do it!). I can also start up a HackMD doc that we can use to put together a list of first steps, then figure out a time for a kickoff meeting via Zulip? What do you all think? |
Just so that everyone subscribed to this thread can find it I've created a HackMD that we can all drop some first steps and things that need to be figured out into: https://hackmd.io/_2MnKA4FTEaiac7RR1MG4A There's a link to a poll for a regular meeting time too. |
Alrighty, I've created a tracking issue for the project group in the Libs team repo that can be used to post status updates: rust-lang/libs-team#4 Some of the links won't work just yet 🙂 |
I've updated the filename and links so with a ✔️ we should be able to merge this one too. |
Establishes a new project group under libs for the production and stabilization of a
core::simd
andstd::simd
module. Based on the work of @hsivonen.Rendered
cc @BurntSushi @hsivonen @Lokathor