-
Notifications
You must be signed in to change notification settings - Fork 353
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
Portable SIMD support #1912
Comments
I guess we can start with the hello world example. :D #![feature(portable_simd)]
use std::simd::*;
fn main() {
let a = f32x4::splat(10.0);
let b = f32x4::from_array([1.0, 2.0, 3.0, 4.0]);
println!("{:?}", a + b);
}
I also found this list of intrinsics so I guess once the basics work we'll want to ensure that we have a test that calls all these intrinsics. |
Yes, if you support that suite of LLVM-esque intrinsics, you will support essentially all of the higher-level constructs we derive from that, at least for the moment. In general, we don't get very far with integers without the SIMD arithmetic and bitops. Almost all higher-level constructs after there then gate on the availability of the masks, which require |
Sounds good. Supporting most of that list should not be too hard -- we can basically apply the primitive MIR operators in a loop, I think (unless there are extra restrictions for the SIMD intrinsics that we have to check for).
Now I am worried. ;) Is there a longer-term plan to rely more directly on the |
No.
Significantly? Not really. We will only add instructions to this "Rust SIMD Extension ISA" with great reluctance since we know the burden of supporting them is high. When we do, it will be aimed mostly at "we know this is fairly simple and there is a clear, direct lowering for it", e.g. we have discussed |
Also by the time we are seriously looking at adding to this list we likely will have finally advanced on our plan of adding a """library""" in Rust that can handle these instructions to the compiler (by converting them to scalarized loops on arrays, yes), so that there is always a valid lowering a backend can use. |
…orkingjubilee disable portable SIMD tests in Miri Until rust-lang/miri#1912 is resolved, we'll have to skip these tests in Miri.
I see, sounds great! Miri being an interpreter it has slightly different needs than regular codegen backends, but that infrastructure can probably be made to handle both. :) (And I know a lot of formal verification people are also interested in having these things lowered away before their MIR/LLVM-based tools run.) |
…orkingjubilee disable portable SIMD tests in Miri Until rust-lang/miri#1912 is resolved, we'll have to skip these tests in Miri.
…orkingjubilee disable portable SIMD tests in Miri Until rust-lang/miri#1912 is resolved, we'll have to skip these tests in Miri.
…orkingjubilee disable portable SIMD tests in Miri Until rust-lang/miri#1912 is resolved, we'll have to skip these tests in Miri.
fix CTFE/Miri simd_insert/extract on array-style repr(simd) types The changed test would previously fail since `place_index` would just return the only field of `f32x4`, i.e., the array -- rather than *indexing into* the array which is what we have to do. The new helper methods will also be needed for rust-lang/miri#1912. r? `@oli-obk`
fix CTFE/Miri simd_insert/extract on array-style repr(simd) types The changed test would previously fail since `place_index` would just return the only field of `f32x4`, i.e., the array -- rather than *indexing into* the array which is what we have to do. The new helper methods will also be needed for rust-lang/miri#1912. r? ``@oli-obk``
fix CTFE/Miri simd_insert/extract on array-style repr(simd) types The changed test would previously fail since `place_index` would just return the only field of `f32x4`, i.e., the array -- rather than *indexing into* the array which is what we have to do. The new helper methods will also be needed for rust-lang/miri#1912. r? ```@oli-obk```
fix CTFE/Miri simd_insert/extract on array-style repr(simd) types The changed test would previously fail since `place_index` would just return the only field of `f32x4`, i.e., the array -- rather than *indexing into* the array which is what we have to do. The new helper methods will also be needed for rust-lang/miri#1912. r? ````@oli-obk````
fix CTFE/Miri simd_insert/extract on array-style repr(simd) types The changed test would previously fail since `place_index` would just return the only field of `f32x4`, i.e., the array -- rather than *indexing into* the array which is what we have to do. The new helper methods will also be needed for rust-lang/miri#1912. r? `````@oli-obk`````
fix CTFE/Miri simd_insert/extract on array-style repr(simd) types The changed test would previously fail since `place_index` would just return the only field of `f32x4`, i.e., the array -- rather than *indexing into* the array which is what we have to do. The new helper methods will also be needed for rust-lang/miri#1912. r? ``````@oli-obk``````
portable SIMD: basic binops First steps towards #1912. Requires rust-lang/rust#90999.
Looks like we need to implement But there also is (Unfortunately the file at https://github.com/rust-lang/portable-simd/blob/master/crates/core_simd/src/intrinsics.rs is not very useful for people not already intimately familiar with SIMD intrinsics -- it does neither sufficiently declare the types nor the behavior of these intrinsics. Is there some documentation of this elsewhere that I am missing?) |
rustup; implement simd_and/or I had to disable the integer division tests since they now require simd_eq, which seems [non-trivial to implement](#1912 (comment)). Cc rust-lang/rust#93619
Yes, that is how On machines that have SIMD architectures, there is a concept of a "mask". This is essentially a "vector of bools". On many, this is an unspecialized concept: it is merely a vector of the same size as any other vector, which has had its lanes set to -1 (i.e. On some, like AVX512F, and in other, newer SIMD architectures, this type is conceptually identical but has a different size and uses special registers: it is in fact exactly 1 bit per "lane", so it's an integer used as a bitmask... except... well, it gets a bit more complicated from there onwards. What we would like to attempt to do is implement a single |
Wow so the very type of these intrinsics depends not only on the architecture but on the exact feature flags used for compilation? We have these hardware details leak all the way out to the language and Abstract Machine itself? What a mess. :( |
I believe simd_eq always returns a wide mask, but there is the simd_bitmask intrinsic to convert to a bitmask. See https://github.com/rust-lang/rust/blob/a41a6925badac7508d7a72cc1fc20f43dc6ad75e/compiler/rustc_codegen_ssa/src/base.rs#L121-L125 and https://github.com/rust-lang/rust/blob/6250d5a08cf0870d3655fa98b83718bc01ff6f45/compiler/rustc_codegen_llvm/src/intrinsic.rs#L1063-L1071 |
Ah you are right, I had overlooked that the return value of |
Sure, I'll make sure Miri always hits the Also I have started the process rolling of adding many more comments to the intrinsics.rs module in question that you already found. I will find a better way to expose and document them somewhere, but feel free to pepper me with any other questions you have. |
@workingjubilee sounds great, thanks. :-) |
implement more SIMD intrinsics Requires rust-lang/rust#94681 With this, the cast, i32_ops, and f32_ops test suites of portable-simd pass. :) Cc #1912
implement simd_{shuffle,gather,scatter} This makes portable-simd doctests pass. :) Cc #1912
implement SIMD float rounding functions Cc #1912
implement SIMD float rounding functions Cc #1912
Once #2029 lands (which requires sorting out rust-lang/portable-simd#267), all intrinsics are implemented and the entire portable-simd test suite passes. :-) However, @workingjubilee already indicated new intrinsics will probably be added in the future (unless I misunderstood), so it probably makes sense to keep this issue open for now. |
implement simd bitmask intrinsics Cc #1912
As far as I know we are currently implementing all intrinsics used by portable-simd. So I'll close this; let's reopen when a new one is introduced. @workingjubilee I'd appreciate a ping when that happens. :) |
It'd be great if Miri would support at least a reasonable subset of Rust's portable SIMD API -- and from what I heard in the past, that is much more feasible than supporting things from
core::arch
. Now that rust-lang/rust#89167 has landed I'd like to add corresponding tests in Miri to ensure we cover the required intrinsics.@workingjubilee what would be a good small-ish set of tests to start with here, that cover as much of the underlying support infrastructure as possible?
The text was updated successfully, but these errors were encountered: