Multiversion: easy function multiversioning attributes

Hi all,

I have just released multiversion 0.5.0, the first version I consider "production ready".

This crate provides attribute macros for function multiversioning. In short, function multiversioning is when you compile different versions of a function for particular target platforms (such as Intel AVX or Arm Neon) and select the appropriate version at runtime. Commonly used with SIMD, function multiversioning allows runtime performance improvements on some platforms while maintaining compatibility with others.

A simple example of a function that squares a slice that automatically vectorizes using AVX and Neon:

#[clone(target = "[x86|x86_64]+avx")]
#[clone(target = "arm+neon")]
fn square(x: &mut [f32]) {
    for v in x {
        *v *= *v;

square is compiled both generically and for the AVX or Neon targets, depending on architecture. Calling square the first time performs CPU feature detection and selects between one of the possible function versions. Subsequent calls do not need to repeat feature detection, and simply perform an indirect function call.

Any comments or feature requests would be appreciated!


@AndreKR This might be something that you are interested. I saw your previous post:

Do crates use hardware instructions automatically?

1 Like

Indeed, that goes into the right direction. Let's hope many crates start using it.

I'm assuming for this to work I must not set any target-feature or target-cpu options/attributes?

1 Like

I haven't experimented with that at all. The intention is that you should not set target-feature, target-cpu, etc. and allow the multiversion attribute to handle all CPU features. I believe if you set the features on the command line everything will work as expected, but the multiversion attribute won't be doing much.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.