-
Notifications
You must be signed in to change notification settings - Fork 35
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
Handling complex arrays #60
Comments
Complex numbers are not supported. They should, of course. There are two possible ways to implement SIMD algorithms for complex numbers:
I know that certain architectures (Blue Gene/Q, old Intel CPUs with 128-bit SIMD lanes) support the second approach. I think that modern CPUs prefer the first approach, but I am not sure. Do you know which approach would be best, or do you have pointers to literature? |
I prefer the second approach, since it is also the one used by |
Looking at OpenBLAS is a good idea. Let's go with this approach. Implementing addition etc. should be straightforward (no shuffling required). Complex multiplication requires shuffling. |
and i² can be taken into account by a multiplication with a constant vector with alternating signs (e.g. |
|
Will this require a specific complex I looked a bit through base in for example simdloops over imaginary things, there it seems to be loading elementptrs, put it in a 2x wide double vec and applies the rest of the math from inside the loop. |
Related to the original error, what's the reason that SIMD isn't able to load from a ReinterpretArray? I've been trying to bang my head against this for a while and keep getting blocked. It seems like this should work?
|
As far as I can tell there is simply no method for |
Seems like all I had to do was change these lines to get ReinterpretArrays to work:
Is there something I'm missing? Edit: PR #72 for this |
Were you able to run my initial code above with this? |
@hofmannmartin Yes, no errors. Is this what you expect?
|
Alternating real and imaginary values are indeed what I expected. Might worth writing a small unit test? |
I would also like to see complex vectors supported. I won't have time for a few weeks, but if I were to file a PR to add support for complex vectors, would anyone be interested in reviewing? |
I would be happy to review. Feel free to demonstrate an incomplete work-in-progress version if you are looking for feedback. The challenging part will be complex number multiplication; this will require shuffling the vectors. A different internal representation would be to store real and imaginary parts in separate SIMD vectors, i.e. to have |
The fact that there are two storages possible and depending on your use case, either one might be better makes it a bit unclear to me if SIMD.jl should really pick one. If anything, I personally think having them as separate vector makes a lot of sense because that would make it much more easy to translate scalar code to vector code. |
Having them separated is the easy part. There is a section in I also have an example of a hand written kernel for this function. However, it would be great if this would work out of the box without having to tailor the kernel. |
All the number types currently supported by SIMD.jl directly translate to native vector instructions. Because the complex vectors can be implemented (almost or entirely?) using existing SIMD.jl methods, it seems the main point of adding complex vector support to SIMD.jl is to use the Vec abstraction to automate the process of manually vectorizing complex code. As is pointed out in that LoopVectorization link, there are several similar "composite" number types which might be vectorized via a similar process, such as doubledouble, raising similar implementation decisions regarding data layout, etc. Would it make sense to treat the Complex case as an example and test case for a minimal composite type vector interface? We might use a different base type ("VecComplex" or "ComplexVec") which supports the ability to choose between implementations. |
It seems both approaches would be useful. Whoever does the work should decide which to explore, with the understanding that SIMD might need to support both approaches in the future, so this road shouldn't be blocked. I suggest the following:
|
Any progress? |
I never found time to do this. Perhaps someone else does? |
For optimization of an algorithm operating on complex data I wanted to use SIMD. However, trying to naively handle complex arrays using
reinterpret
failed. E.g.throws an error
Am I missing something, or is this feature not yet supported?
The text was updated successfully, but these errors were encountered: