You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
System.Numerics.Matrix4x4.Invert has no SIMD acceleration #34394
I'm happy for this, or any of the other methods on Matrix3x2, Matrix4x4, Plane, Quaternion, Vector2, Vector3, or Vector4 to be accelerated where they aren't already.
If you provide a pull-request, please also provide some performance numbers (from benchmark.net) and an assembly diff.
Feel free to ping me on here if you need help with any of that or would like to discuss an appropriate implementation.
Cool. Just shortly I'm going to use the DirectXMath library as the reference. The only thing that immediately jumps out at me is if the Matrix4x4 class has the right structure since it's not using vector128. I don't think this is going to be a big issue, but I guess it should also be benchmarked?
Also, I've read your blog post, looking at Intel's and DotNet docs on Instrinsic, and the BenchMark site. Any other sources I should be aware of?
@tannergooding I wonder if it makes sense to optimize redundant loads after inlining (in case of Matrix methods are not inlineable mostly but I am about a general case). E.g. after inlining:
Hi just wanted to provide an update on progress. I've written up the code in a Benchmark project and was able to get a 20% improvement using SIMD. I still have to test for correctness.
Hi guys, sorry about the delay. I was able to debug and test the new code. All 7 Invert tests from Matrix4x4Tests.cs are now passing. Should I begin the ARM/NEON code before the PR? Or should I submit just the SSE code for now?
We can add the case to #33565 for ARM64. There may still be a few additional intrinsics required before it can be completed succesfully.
However, if you want to give it a try and report back on any intrinsics that are needed but not yet implemented, that is also fine 😄
I use a combination of a rPI 3/4 or a Windows 10 on ARM laptop (such as the Surface Book X or GalaxyBook 2). I'm not aware of any emulators in use.
I would recommend cross-building on your desktop (Ubuntu directly or WSL on Windows) and then copying bits to your pi rather than attempting to build on your pi directly. It significantly shortens the turnaround time.
These are all the benchmarks I've tried so far, both in terms of the code and MM_SHUFFLE.
CallParamaters refers to this.
ie.
public void SSEInverseDirectStoreCallParameters()
{
Matrix4x4 mtx = new Matrix4x4(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);
Matrix4x4 result;
Matrix4x4Inverse.BenchInverseDirectStore(mtx, out result);
}
public void SSEInverseDirectStore() => Matrix4x4Inverse.BenchInverseDirectStore();
Q: I'm not 100% sure how to interpret these results, am I benching the wrong use case? It would seem there is a clear winner here, as well as a choice in how MM_SHUFFLE is implemented/used?
Activity
tannergooding commentedon Apr 1, 2020
I'm happy for this, or any of the other methods on
Matrix3x2,Matrix4x4,Plane,Quaternion,Vector2,Vector3, orVector4to be accelerated where they aren't already.If you provide a pull-request, please also provide some performance numbers (from benchmark.net) and an assembly diff.
Feel free to ping me on here if you need help with any of that or would like to discuss an appropriate implementation.
gfoidl commentedon Apr 1, 2020
A reference implementation for SSE in C can be found here.
(I didn't check if there are faster ways to do it.)
tannergooding commentedon Apr 1, 2020
There is also an implementation as part of the DirectX Math library which is known to fit with the general use-case that the
System.Numericstypes were designed for (and also has an ARM implementation): https://github.com/microsoft/DirectXMath/blob/master/Inc/DirectXMathMatrix.inl#L772EgorBo commentedon Apr 1, 2020
A lot of shuffles and we still don't have an API for MM_SHUFFLE :-)
tannergooding commentedon Apr 1, 2020
Feel free to open a proposal 😉
eanova commentedon Apr 8, 2020
I'd like to grab and investigate this if there are no objections.
tannergooding commentedon Apr 9, 2020
Thanks @eanova, no concerns on my end so I've assigned it out.
Feel free to let me know if you have any questions, comments, concerns!
eanova commentedon Apr 9, 2020
Cool. Just shortly I'm going to use the DirectXMath library as the reference. The only thing that immediately jumps out at me is if the Matrix4x4 class has the right structure since it's not using vector128. I don't think this is going to be a big issue, but I guess it should also be benchmarked?
Also, I've read your blog post, looking at Intel's and DotNet docs on Instrinsic, and the BenchMark site. Any other sources I should be aware of?
2 remaining items
EgorBo commentedon Apr 9, 2020
@tannergooding I wonder if it makes sense to optimize redundant loads after inlining (in case of Matrix methods are not inlineable mostly but I am about a general case). E.g. after inlining:
in jit.
tannergooding commentedon Apr 9, 2020
@EgorBo, there are likely some possible optimizations. I don't know what scenarios the above would be possible/legal under.
eanova commentedon Apr 13, 2020
Hi just wanted to provide an update on progress. I've written up the code in a Benchmark project and was able to get a 20% improvement using SIMD. I still have to test for correctness.
eanova commentedon Apr 23, 2020
Hi guys, sorry about the delay. I was able to debug and test the new code. All 7 Invert tests from Matrix4x4Tests.cs are now passing. Should I begin the ARM/NEON code before the PR? Or should I submit just the SSE code for now?
tannergooding commentedon Apr 23, 2020
We can add the case to #33565 for ARM64. There may still be a few additional intrinsics required before it can be completed succesfully.
However, if you want to give it a try and report back on any intrinsics that are needed but not yet implemented, that is also fine 😄
eanova commentedon Apr 23, 2020
Got it... I can do that. Let me clean up the current code and I'll post it as a gist for now.
Just one quick question, what do you recommend for ARM64 development. Is there a proper emulator or should I be looking at a Raspberry Pi..
tannergooding commentedon Apr 23, 2020
I use a combination of a rPI 3/4 or a Windows 10 on ARM laptop (such as the Surface Book X or GalaxyBook 2). I'm not aware of any emulators in use.
I would recommend cross-building on your desktop (Ubuntu directly or WSL on Windows) and then copying bits to your pi rather than attempting to build on your pi directly. It significantly shortens the turnaround time.
eanova commentedon May 7, 2020
// * Summary *
BenchmarkDotNet=v0.12.1, OS=Windows 10.0.18363.778 (1909/November2018Update/19H2)
Intel Core i9-9900K CPU 3.60GHz (Coffee Lake), 1 CPU, 16 logical and 8 physical cores
.NET Core SDK=3.1.201
[Host] : .NET Core 3.1.3 (CoreCLR 4.700.20.11803, CoreFX 4.700.20.12001), X64 RyuJIT
DefaultJob : .NET Core 3.1.3 (CoreCLR 4.700.20.11803, CoreFX 4.700.20.12001), X64 RyuJIT
These are all the benchmarks I've tried so far, both in terms of the code and MM_SHUFFLE.
CallParamaters refers to this.
ie.
Q: I'm not 100% sure how to interpret these results, am I benching the wrong use case? It would seem there is a clear winner here, as well as a choice in how MM_SHUFFLE is implemented/used?
Thanks! @tannergooding
Add SIMD acceleration for Matrix4x4.Invert #34394 (#36323)
WhiteBlackGoose commentedon May 10, 2021
Also should be closed
tannergooding commentedon May 10, 2021
Closed, thanks for pointing this out 😄