-
Notifications
You must be signed in to change notification settings - Fork 86
"Free" dynamic dispatch for core SIMD? #178
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
Comments
https://crates.io/crates/multiversion exists for this currently, which is maintained by (our very own) @calebzulawski. I'd like to see some mechanism of this in the stdlib, but there's a lot of... trickiness to it, which I think makes it better off in an external crate. A big issue is that technically you can't do feature checking without This means that either (ignoring the bikeshed about the name):
Number 2 goes against the general way |
An argument in favor of doing it in the compiler (e.g. having something like This also means it could avoid going through any indirection in certain cases (for example, if it already knows the target_feature set), and more generally, the compiler understand and "see through" the abstraction if it were builtin, whereas (in practice, if not in theory) a library implementation of this will tend to function as an optimization barrier. That said, I suspect proper usage of this kind of thing would be on larger functions in order to to minimize the cost of the dispatch, and on these sorts of functions this kind of thing won't matter as much. Footnotes
|
Oh huh, I should definitely try multiversion! Looks like exactly what I want :)
Yeah I figured the runtime detection might be trickier than I was expecting... Is there much of a reason to have no_std if it is x86 only? I'm not sure if I see the use case of no_std on x86 only...
I could also see it being useful for small functions that are kernels for larger functions, but maybe that'd get inlined anyway. |
You might only support the runtime dispatch on x86, and use the statically known feature for other targets (for example, ... But perhaps you're right, in general, and this isn't as much of an issue as it seems like it might be to me. I don't really love having a language feature that doesn't work for
It probably wouldn't with the |
For small functions you shouldn't really be dispatching them at runtime--its probably better to dispatch once at a larger scope. |
With |
Properly speaking, you should not just check |
Hi! I'm very excited by the work on portable/core simd. Thank you for all of your work :)
I was looking over the API, and I was thinking it should be possible to get "free" runtime dispatch with a proc macro on top of portable SIMD, which would make portability really easy!
I'm thinking something like (more of a sketch than concrete proposal):
This would generate code much like the example in the
core::arch
docs here: https://doc.rust-lang.org/core/arch/index.html#dynamic-cpu-feature-detection, where it would generate versions of the function for eachtarget_feature
, then make the actual main function dynamically dispatch to each implementation.Anyway, I thought I'd open this and get your thoughts.
The text was updated successfully, but these errors were encountered: