-
Notifications
You must be signed in to change notification settings - Fork 32
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
Fix the use of simd with platform intrinsics for comparisons and boolean reductions in vectors. #85
Conversation
…ean reductions in vectors. - Unfortuatly there is a bug in rust/llvm that doesn't allow us to compile vek im some cases (see example) - Added a pass-by-value fn that can be used together with u8 to avoid the respective error Downside is, the interface is a bit uglier.
Hi, thanks for the PR!
No it's fine, the point is just to avoid situations where the author spent a huge amount of time on something that will actually not end up being merged; you know, just in case. Anyway, I swear SIMD vectors or bools are a pain... I'll try to fiddle with that, I'm not sure I like having extra It's great that you added an example with a detailed description of the error. Thanks. |
Thanks for understanding. We use this fix for over a year in veloren code, it was initially made by @pythonesque . Yeah, having a second fn is unclean, but it doesnt seem like SIMD vectors will be less of a pain soon. One could also just export those e.g. when using the platform_intrinsic or some other feature if you wish. Let me know if you find a more elegant solution to the problem ;) |
Hi, so I've tested some stuff and came to a few conclusions:
And some observations:
If we're serious about SIMD, then we have to somehow take that into account in our implementation. The changes I would plan are:
I've started work on this but I'll resume later. I'll add an example, as you did, to showcase the new way of doing things. |
HI @yoanlcq , nice findings. I am by far not so into the topic but here are my 2 cents:
|
They use So their comparison functions are like so : #[inline]
fn simd_lt(self, other: Self) -> Self::Mask {
// Safety: `self` is a vector, and the result of the comparison
// is always a valid mask.
unsafe { Mask::from_int_unchecked(intrinsics::simd_lt(self, other)) }
} I'm not sure how worth adding a
Yes but, it's better than "it doesn't compile"; though I agree with you that the function would be "lying", which is something that I don't like; but making it "good" would require changing the signature (accept owned values + return vector of ints/masks), which is a breaking change. |
Hi @yoanlcq , is there any update on the implementation you tried (: |
Hi, sorry to keep you waiting, I've just pushed a new commit to the main branch, as can be seen, which should address the issues. I'm not yet fully confident about publishing to a new version right now; I mean, it was tested and all, but I'd feel better about it if you reviewed it, to confirm that I didn't forget anything and that it does solve your issue. Thanks! |
Hi, I looked through the changes and they appear to address the issue and provide the same functionality we were using. @xMAC94x also setup a branch patching in the latest I made one note where I thought some helpful information could be added to the docs 3febca2#r72638972. |
All right, I've added a commit to address this, and with that, it looks like we're good to go! So I went ahead and published these changes as I'll close this PR because I assume we're done, but as usual, feel free to re-open if you encounter issues or have other remarks. |
Unfortuatly there is a bug in rust/llvm that doesn't allow us to compile vek im some cases (see example)
Added a pass-by-value fn that can be used together with u8 to avoid the respective error
Downside is, the interface is a bit uglier.
Try to run the attached example and compile the
failing
functioncargo build
is necessary,cargo check
doesnt work.This PR provides a workaround that can be used to make use of SIMD in this case ;)
Tell me if you need any adjustments.
Edit: just saw the contributing section, do you still need a issue opened ?