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

How to use new SIMD rules after 1.78 #122965

Closed
jianshu93 opened this issue Mar 23, 2024 · 3 comments
Closed

How to use new SIMD rules after 1.78 #122965

jianshu93 opened this issue Mar 23, 2024 · 3 comments

Comments

@jianshu93
Copy link

jianshu93 commented Mar 23, 2024

Dear Rust team,

I rely heavily on Rust stdsimd feature before v1.78 like below:

#[cfg(feature = "stdsimd")]
use packed_simd::*;


#[cfg(feature = "stdsimd")]
fn distance_l1_f32_simd(va:&[f32], vb: &[f32]) -> f32 {
    //
    let nb_lanes = 16;
    let nb_simd = va.len()/ nb_lanes;
    let simd_length = nb_simd * nb_lanes;
    //
    let dist_simd = va.chunks_exact(nb_lanes)
            .map(f32x16::from_slice_unaligned)
            .zip(vb.chunks_exact(nb_lanes).map(f32x16::from_slice_unaligned))
            .map(|(a,b)| (a - b).abs())
            .sum::<f32x16>();
    //
    let mut dist = dist_simd.sum();
    // residual
    for i in simd_length..va.len() {
        dist = dist + (va[i]- vb[i]).abs();
    }
    return dist as f32;
}  // end of distance_l1_f32_simd

How do I quickly port my code to allow it work for 1.78 or after, in which the stdsimd feature has been removed. I do not want to rewrite the function for each instructions like AVX2 AVS512 et.al..

Thanks,

Jianshu

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 23, 2024
@workingjubilee
Copy link
Contributor

@jianshu93 You should try using

#![feature(portable_simd)]

The packed_simd crate is fairly... lightly maintained at best.

@workingjubilee workingjubilee removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 23, 2024
@workingjubilee
Copy link
Contributor

workingjubilee commented Mar 24, 2024

The issue here is not a problem with rustc or the stdlib as it is a breakage in a nightly feature, it is rather due to the packed_simd crate not being updated to the latest nightly. It should be transferred to that crate's issues.

@jianshu93
Copy link
Author

hello all,

I believe the fix does not work and we have to wait for packed_simd to update to v1.78 v1.79. See the error here: rust-lang/packed_simd#360

Is there a plan for update?

Thanks,

Jianshu

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

3 participants