Last active
December 13, 2022 11:10
-
-
Save andrew-raphael-lukasik/5c3052c9730b5a85a4c49fd33dfd535e to your computer and use it in GitHub Desktop.
my thoughts on simd and Burst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Unity.Collections; | |
| using Unity.Jobs; | |
| using Unity.Mathematics; | |
| using BurstCompile = Unity.Burst.BurstCompileAttribute; | |
| [BurstCompile] public unsafe struct NoSimd : IJob | |
| { | |
| public float a, b; | |
| public float* c; | |
| void IJob.Execute () { *c = a * b; } | |
| } | |
| [BurstCompile] public unsafe struct Simd : IJob | |
| { | |
| public float4 a, b; | |
| public float4* c; | |
| void IJob.Execute () { *c = a * b; } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
observation
This came to me as a surprise but I noticed that Burst packs scalar math in a SIMD operations + will also correctly inline legacy
MathfandVectorNcode now. This means that doing that manually is not a requirement nor a reasonable default anymore.Here is a different case:
As you can see my code generated less instructions, which seems good and feels good. But. But performance tests show little to no difference in how fast these 2 sets are. Mine even being sometimes the slower one :V
For weeks I thought this must have been a problem with my performance testing setup. But can't deny it anymore.
My conclusion, however it might change, is to leave SIMD optimizations to Burst because it catch up or beat me every time so far.
Data layouts and memory access patterns is where I see my role now, not here.