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

expr: explicit SIMD #776

Open
skyzh opened this issue Feb 19, 2023 · 7 comments
Open

expr: explicit SIMD #776

skyzh opened this issue Feb 19, 2023 · 7 comments

Comments

@skyzh
Copy link
Member

skyzh commented Feb 19, 2023

I've been working with some other database things recently and it seems that Rust compiler cannot automatically vectorize array-array operation.

https://godbolt.org/z/G8WMr4acY

Probably we should bring back the portable SIMD expressions framework?

@skyzh skyzh transferred this issue from risinglightdb/sqllogictest-rs Feb 19, 2023
@lokax
Copy link
Member

lokax commented Feb 19, 2023

Bounds checking does not allow the compiler to auto-vectorize.

Try and test
res = vec::from_iter(a.iter().zip(b.iter()).map())

@skyzh
Copy link
Member Author

skyzh commented Feb 19, 2023

yeah it works! https://godbolt.org/z/eG61feTM4 I'll check if binary operations are actually vectorized in RisingLight later...

@wangrunji0408
Copy link
Member

You can check them via cargo bench --bench array. It would be obvious which operations are vectorized and which are not.

@wangrunji0408
Copy link
Member

wangrunji0408 commented Feb 20, 2023

I still prefer auto-vectorization over explicit SIMD, because usually compilers do it better than humans and it makes code cleaner. However, as mentioned above, auto-vectorization requires special craft of codes. There are plenty of things that prevent SIMD, e.g. bound check, branching. AFAIK, there's also no way to hint or ensure auto-vectorization for a piece of code in Rust, i.e. no equivalent for #pragma clang loop vectorize(enable).

@skyzh
Copy link
Member Author

skyzh commented Feb 20, 2023

Yep, I also think auto vectorization

@skyzh
Copy link
Member Author

skyzh commented Feb 20, 2023

… is good

@xxchan
Copy link
Member

xxchan commented Apr 23, 2023

https://matklad.github.io/2023/04/09/can-you-trust-a-compiler-to-optimize-your-code.html

:p

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

No branches or pull requests

4 participants