-
Notifications
You must be signed in to change notification settings - Fork 51
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
Expose width
on vec types and provide sum() ability.
#5
Comments
Hello, Thank you for using faster, and apologies for the current lack of documentation and API instability - we're still a ways away from a stable release :) Faster's vector types are just typedefs over stdsimd's vector types. It looks like stdsimd's docs are in a bit of upheaval right now, but here's the impl applied to all vector types in stdsimd. Unfortunately, one can't get the width of a vector with just that API (although you can get the scalar values with I'm not sure if publicly exposing the width of a vector is a smart idea, as it could encourage people to write fragile or nonportable code. I'm still open to feedback on whether that should be part of the public API. A more elegant solution (imo) to your problem should be arriving in 0.3.0 (late December probably), which would allow you to reduce over both a vector and a collection using SIMD, so your code would look like xvec.zip(yvec).simd_iter() // returns `PackedZip<f32>`
.simd_reduce(|acc, (a, b)| acc + (a - b) * (a - b)) // returns `f32s`
.scalar_reduce(|a, b| a + b) // returns `f32` with the first closure doing roughly what your for loop does, and the second closure doing roughly what your |
Hi, thank you very much for your swift response!
I'm probably too new to Rust to give a good answer. However, my feeling is that people working with SIMD (and downloading Then it's a balance between enabling unforeseen use cases, and preventing happy little accidents. For example, I used the hack described above ( Given Rust is a systems programming language, I think I would want to have access to low-level information, in the "safest way possible given the circumstances" (e.g., if you later do run time feature detection #2, the API should accurately / dynamically reflect the current type mappings and vector width).
Yes, looks very nice!
Regarding documentation, when I started looking at faster I was mostly interested in examples, exactly like the one you just provided. I think if you had a dozen or so diverse ones in the |
width() and sum() on vectors has landed, although I haven't implemented a Because reductive operations are inherently unportable anyway, I see no harm in exposing some nonportable APIs with sufficient warnings in the documentation. |
Thanks! Does a way doing like |
That's also coming in 0.4.0 - I'm sitting on a mostly-working implmentation right now, but I ran into the "you can't impl a trait in std on a type in std" problem at the last second. That should land in master alongside or immediately before gathers/scatters. |
Resolved in 0.4.0 |
I have code where I want to add / multiply two vectors and compute the sum over all results. It looks somewhat like this:
I haven't found a way to a) either sum
simd_sum
(e.g.,sum = simd_sum.0 + simd_sum.1 + ... simd_sum.n
) with an existing function, or b) generically implement my own sum function.The problem I'm having with implementing
sum_f32s
myself is that I haven't seen an easy way to get the current width. The hack I'm using looks like this:It would be nice if both a) and b) were implemented, or, if they are already, documented how to use them.
The text was updated successfully, but these errors were encountered: