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

Vectorized version ? #67

Open
OlivierSohn opened this issue Apr 12, 2018 · 3 comments
Open

Vectorized version ? #67

OlivierSohn opened this issue Apr 12, 2018 · 3 comments

Comments

@OlivierSohn
Copy link
Contributor

OlivierSohn commented Apr 12, 2018

Using a state vector containing the information of 4 seeds, we could provide a new API where we get 4 random numbers at a time (using SIMD instructions for example).

The state vector would have to be "interleaved" to optimize cache usage, so that when reading or writing 4 elements, we read or write contiguous memory.

(I use the number 4 but it could be a different number depending on the Variate type (to build a double we need 2 Word32), and on the vectorization primitives available.)

I'm not familiar with haskell vector primitives but looking at GHC.Exts I saw some there, so I guess it is possible to go this way... What do you think?

@Shimuuar
Copy link
Collaborator

That's interesting idea although I don't know anything about state of SIMD in GHC. AFAIR they never landed properly but I may be mistaken. It raises two interesting problems

  1. Do we have SIMD? Since function is small we can get away by writing everything by hand.

  2. Say we have SIMD and vectorized generator. Now what should we do with 4 Word32? This question is important even if we don't have vectorized generator. For example is we generate Word8 we can generate 4 at time! And 32 for Bools.

@OlivierSohn
Copy link
Contributor Author

Do we have SIMD? Since function is small we can get away by writing everything by hand.

I'm not sure to understand, what do you mean? If we don't have SIMD (or another vectorization instruction set) available, I don't see how we can vectorize by hand?

Say we have SIMD and vectorized generator. Now what should we do with 4 Word32?

In the spirit of foldMUniforms in #66 we could have an API where we provide a stream of values.

This question is important even if we don't have vectorized generator. For example is we generate Word8 we can generate 4 at time! And 32 for Bools.

Yes, maybe it would make sense as you say, even without vectorization, to have an API that provides a stream of values. This was the idea I was trying to address in #66, although I made it only for Word32.

@Shimuuar
Copy link
Collaborator

RE SIMD support. I meant that we may just have bunch of rather low-level primitives in GHC.Whatever where one need to do everything by hand without any compiler support.

And about API. I'm thinking about making fork of mwc-random to experiment with API and possibly squeeze a bit of performance. mw-random is relatively popular so API couldn't be changed will-nilly.

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

2 participants