Rust and SIMD vectorization

Hello everyone,

I want to ask about vectorization in Rust. What is the standard way or best way to vectorize ? And using this, performance it would be like the Intel C++ Compiler (ICC) ? I need to choice between Rust and C for HPC, so i don't know if Rust is suitable to this kind of processing.

Would you recommend choosing Rust, or continue with C for HPC.

Thank you so much !

Rust relies on LLVM to do autovectorization, so you should expect similar results to clang. You can also use SIMD intrinsics which are the same as in C.

One thing to watch out for is bounds checks, which prevent autovectorization. In Rust iterators work best, because they don't add any extra bounds checks. Otherwise you may need to rely on LLVM optimizing them out, or use .get_unchecked().

Use to see if the code gets vectorized properly (make sure to add -O and -C target-cpu=native to flags on godbolt to see optimized code).

Another thing to watch out for in integer vectorization is potential overflow. Rust semantics require overflow detection and reaction at the specific point in the loop or iterator at which it occurs, which prohibits vectorization. Use of wrapping arithmetic provides the way to avoid the need for such per-instance detection and response.

In summary, eliminate bounds checks and the need to detect potential overflow if you want your code to be vectorizable.

In release mode it doesn't check, and defines overflow to wrap.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.