logoalt Hacker News

jvanderbottoday at 3:39 PM1 replyview on HN

I do this. I do this a lot. My job involves processing a significant amount of weather data and flight telemetry _very quicky_.

What I have found is that getting rust to auto-vectorize is a nightmare. The options available to me have always converged around: 1) use simd-like apis 2) frame it as matrix-vector operations.

(1) is touched on in TFA

(2) is way easier, and allows use of well-tested apis and crates, each of which (sensibly) call out to better-tested C libraries. Each of those can, should, might, or will use your CPU better than you will. If you can frame it as matrix-vector operations, you will go very fast, not least of which, by stacking the operations into a _big_ matrix/vector op, which your CPU will happily tear though.

However the article proposes a third, very cool option: use algebraic ops API! Worth a read.

   Rust used to not have any reasonable way to do anything like this on stable (for my own definition of reasonable), but now it does! Rust 1.98 stabilized algebraic operators for floats. These allow you to declare per-operation that you’re okay with the compiler making optimizations that may change the result as long as the optimized code is algebraically equivalent to the original. Yes, this includes potentially reordering operations.

Replies

the__alchemisttoday at 3:45 PM

Great insight. My (much less sophisticated) mental model is: 1: I don't know how to get things to auto-vectorize nor evaluate if they did. [I should learn]; I assume they do not. Manual SIMD it is! [I have a lib for floats and vectors which mimics core::simd but on stable and x86 only)

I will check out your insights regarding matrix-vector ops and C libs!

show 1 reply