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

Add SIMD acceleration for Matrix4x4.Invert #34394 #36323

Merged
merged 11 commits into from
May 26, 2020
Merged

Add SIMD acceleration for Matrix4x4.Invert #34394 #36323

merged 11 commits into from
May 26, 2020

Conversation

eanova
Copy link
Contributor

@eanova eanova commented May 13, 2020

Fix for #34394.

Added SIMD hardware acceleration support to the Matrix4x4.Invert function.

Fix for #34394.

Added SIMD hardware acceleration support to the Matrix4x4.Invert function.
Added the link to Microsoft/DirectXMath source code and appended license to THIRD-PARTY-NOTICES.TXT
Given a Matrix4x4 of only rank 3 test to see the matrix is non-invertable.
@tannergooding
Copy link
Member

Overall, LGTM. I just had a few code cleanup and codegen quality nits.
It would be good to post the benchmark numbers here for reference as well.

Added missing using statement for Internal.Runtime.CompilerServices.Unknown static object.
}

// Create Vector128<float> copy of the determinant and invert them.
Vector128<float> ones = Vector128.Create(1.0f, 1.0f, 1.0f, 1.0f);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Vector128<float> ones = Vector128.Create(1.0f, 1.0f, 1.0f, 1.0f);
Vector128<float> ones = Vector128.Create(1.0f);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@eanova
Copy link
Contributor Author

eanova commented May 20, 2020

BenchmarkDotNet=v0.12.1, OS=Windows 10.0.18363.836 (1909/November2018Update/19H2)
Intel Core i9-9900K CPU 3.60GHz (Coffee Lake), 1 CPU, 16 logical and 8 physical cores
.NET Core SDK=5.0.100-preview.3.20216.6
  [Host]     : .NET Core 5.0.0 (CoreCLR 5.0.20.21406, CoreFX 5.0.20.21406), X64 RyuJIT
  DefaultJob : .NET Core 5.0.0 (CoreCLR 5.0.20.21406, CoreFX 5.0.20.21406), X64 RyuJIT

Method Mean Error StdDev
OriginalDotNetInverse 41.18 ns 0.288 ns 0.269 ns
FinalSIMDInverseWithSSEStore 31.30 ns 0.023 ns 0.020 ns

These are the results corresponding to the current commit, which uses the CompilerServices Unknown class to store the final output using SSE Store intrinsics. I followed the the benchmarking guidelines in the docs to generate the tests.




private static unsafe bool SseImpl(Matrix4x4 matrix, out Matrix4x4 result)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the other should still be made static local functions as I called out here: #36323 (comment)

Otherwise they may conflict with other methods we also accelerate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything thing else LGTM and I believe it is otherwise ready to merge

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, wasn't familiar with local functions. I thought you were pointing out the public modifier instead. Fixed!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I should have clarified 😄

Moved the SSE implementation and SoftwareFallback to local functions of Invert.
@tannergooding
Copy link
Member

CC. @pgovind if you want to give this a pair of eyes before it gets merged

@tannergooding tannergooding merged commit 639f06d into dotnet:master May 26, 2020
@eanova
Copy link
Contributor Author

eanova commented May 27, 2020

Thanks for all your help Tanner. Really appreciate it!

@eanova eanova deleted the SIMDMatrix4x4 branch May 27, 2020 01:07
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants