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

Replace Matrix.Equals() with simd implementation #1721

Open
wants to merge 1 commit into
base: opentk5.0
Choose a base branch
from

Conversation

BoyBaykiller
Copy link
Contributor

@BoyBaykiller BoyBaykiller commented Apr 21, 2024

Using SIMD for Matrix comparisons significantly improves performance.
The old implementation was creating a bottleneck for me as I had a lot of instances and comparing matrices to test wether a given instanced needed to be reuploaded to the GPU. This new implementation fixed it.

Matrix3x4EqualBenchmark

Method Mean Error StdDev
Current 8.297 ns 0.0856 ns 0.0759 ns
Avx2 3.259 ns 0.0282 ns 0.0264 ns

Matrix4x4EqualBenchmark

Method Mean Error StdDev
Current 13.225 ns 0.1935 ns 0.1810 ns
Avx2 3.490 ns 0.0290 ns 0.0272 ns

If .NET 8 was used we could further accelerate functions like this with AVX512. If this gets merged I wanted to add the same to otk4 (just slightly different because of different .net version).

@NogginBops
Copy link
Member

NogginBops commented Apr 21, 2024

Here is a small sharplab session where I compared the assembly for before and after.

Would ideally look at arm64 codegen too to verify it's still faster, but I'm fine with just assuming it will be.
But I'm also interested in knowing if debug performance is better or worse.

@BoyBaykiller
Copy link
Contributor Author

Thanks for the link. I cant test for arm64, but yeah I doubt its any slower - in Release mode.

BenchmarkDotNet does not work in Debug mode (if there is a way let me know) but I did a simple 10'000'000-iterations for-loop with 3x4 matrix comparisons. Stopwatch measures arround 58ms for non SIMD and 66ms with Avx2, that is on Ryzen 5 2600. So slightly slower in debug.

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

Successfully merging this pull request may close these issues.

None yet

2 participants