bab2min / EigenRand

Fastest Random Distribution Generator for Eigen
https://bab2min.github.io/eigenrand/
MIT License
92 stars 13 forks source link

Generic non-SIMD, platform-agnostic version? #59

Open barracuda156 opened 1 week ago

barracuda156 commented 1 week ago

The website mentions that "EigenRand currently supports only x86-64 architecture (SSE, AVX, AVX2) and ARM64 NEON". Can non-SIMD version be added? Or it won't make sense? Otherwise other platforms (PowerPC, RISC-V) cannot be supported.

bab2min commented 1 week ago

Hi @barracuda156 , In short, EigenRand already has non-SIMD version, and it may run on other platforms, but without acceleration. The reason I marked this as unsupported on other platforms is because I haven't (and don't plan on) testing that it works on all platforms, it doesn't mean that it's actually impossible to compile on PowerPC or RISC-V.

EigenRand actually has non-SIMD implementations like Eigen does. Every RNG of EigenRand has both scalarOp implementation (non-SIMD) & packetOp implementation (SIMD) and proper operation would be selected by Eigen's logic.

For example, StdNormalGen has both scalar version: https://github.com/bab2min/EigenRand/blob/f3190cd7f85c5878c949625cb2811262ff050d66/EigenRand/Dists/NormalExp.h#L35-L59 and packet version: https://github.com/bab2min/EigenRand/blob/f3190cd7f85c5878c949625cb2811262ff050d66/EigenRand/Dists/NormalExp.h#L60-L83

And only when packet operation is available, the latter one is selected by PacketAccess attribute. https://github.com/bab2min/EigenRand/blob/f3190cd7f85c5878c949625cb2811262ff050d66/EigenRand/RandUtils.h#L137

So, if you compile the code using EigenRand on other platforms, PacketAccess would be 0 and the scalar one would be selected. If any compile errors appears, please report because it must be a bug of EigenRand.

barracuda156 commented 1 week ago

Thank you very much for a detailed reply! I will try it.