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

Question: Using SIMD in Image? #2077

Closed
JulianKnodt opened this issue Dec 19, 2023 · 4 comments
Closed

Question: Using SIMD in Image? #2077

JulianKnodt opened this issue Dec 19, 2023 · 4 comments

Comments

@JulianKnodt
Copy link
Contributor

Currently, I'm attempting to optimize bilinear interpolation, and have noticed there's some opportunities for SIMD, but I was wondering whether it would be ok to use portable SIMD (std::simd) inside the library?

@fintelia
Copy link
Contributor

Portable SIMD isn't available in stable Rust yet, so any use would have to be behind an unstable feature flag as we did for the png crate. (And even once it stabilizes we'd still have to wait until it was present in our MSRV before enabling it by default.)

The other consideration is that manually using SIMD has to be "worth it". The Rust compiler is very good at auto-vectorization so that should always be attempted first. And even when that's not possible, there has to be an impactful enough performance difference to justify making the code more complex.

@JulianKnodt
Copy link
Contributor Author

sounds good, for now I'll avoid using it, but I'll try to fix up the code so that it's more amenable to optimization.
Right now I'm running the code in a hot path and I've found it to be slow,
I've also chucked it into godbolt and it's about 300 lines of asm with -O, so I'll try to shrink it down

@Shnatsel
Copy link
Contributor

Shnatsel commented Jan 2, 2024

@JulianKnodt note that -O on godbolt does not optimize as much as cargo build --release does. You need to pass -Copt-level=3 to get the high optimization level that includes auto-vectorization.

I've been banging my head for two hours on why the compiler won't autovectorize something, and it turned out that I was using -O on godbolt. I hope I am not too late to spare you this fate!

@JulianKnodt
Copy link
Contributor Author

ah I didn't realize that, but I've updated the interpolation code to be more efficient in the unoptimized case, which is probably still good in the vectorized case: #2078

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