-
Notifications
You must be signed in to change notification settings - Fork 307
Fast homogeneous and rotation matrix multiplications #1845
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1845 +/- ##
===========================================
- Coverage 47.84% 33.35% -14.50%
===========================================
Files 532 466 -66
Lines 68944 66167 -2777
Branches 32201 28740 -3461
===========================================
- Hits 32986 22068 -10918
- Misses 31908 33587 +1679
- Partials 4050 10512 +6462 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
modules/core/src/math/transformation/vpHomogeneousMatrix.cpp:60:13: warning: unused variable 'outputData' [-Wunused-variable]
60 | double *outputData = output.data;
| ^~~~~~~~~~
modules/tracker/rbt/src/features/vpRBDenseDepthTracker.cpp:200:10: warning: variable 't1' set but not used [-Wunused-but-set-variable]
200 | double t1 = vpTime::measureTimeMs();
| ^
…able Document vpRotationMatrix::rotateVectors() method
…able Document vpHomogeneousMatrix::project() method
modules\core\src\math\transformation\vpRotationMatrix.cpp(128,21): error: always_inline function '_mm_hadd_pd' requires target feature 'sse3', but would be inlined into function 'rotateVectors' that is compiled without support for 'sse3'
128 | __m128d r01 = _mm_hadd_pd(mul0, mul1);
| ^
| #if defined(VISP_HAVE_AVX2) | ||
| using Register = __m512d; | ||
|
|
||
| inline constexpr int numLanes = 8; | ||
| inline const Register add(const Register a, const Register b) | ||
| { | ||
| return _mm512_add_pd(a, b); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two comments.
AVX2 != 512-bits register:
- AVX / AVX2 improvements: https://fr.wikipedia.org/wiki/Advanced_Vector_Extensions#Advanced_Vector_Extensions_2
- see AVX-512 and all the different flavors
- you can use
cat /proc/cpuinfoto see which AVX-512 variants your CPU has
I would definitely not expose SIMD code to the user:
- people knowing this subject will not use this code and there are already better libs doing that
- with SIMD code in
.h, withmarch=nativeand running ViSP on another computer there are some chances to have SIGILL crash on old CPU - I think what is done is runtime dispatching:
- the
.socan have all the more advanced instructions set - for example for a convolution function, a variant for 128-bits, 256-bits and 512-bits (the lib size will increase a lot)
- and at runtime you check if the CPU has this kind of instructions set and dispatch to the more advanced one
- the
For the moment this file is duplicated in core and rbt modules. We should find a solution to avoid code duplication.
This PR introduces two methods that perform batched 3d point transformations:
vpHomogeneousMatrix::project: Project N 3d points (Represented as a Nx3 vpMatrix) from a frame to anothervpRotationMatrix::rotateVectors: Rotate Vectors (Represented as a Nx3)These methods rely on explicit mat muls and SIMD operations to be faster. This PR adds tests to measure the speed up against two naive versions: the Naive
vpColVector pa = T * pbloop andvpMatrix::mult2Matricesversion (which multiplies a 4x4 matrix with an 4xN matrix.Interestingly, the version without SIMD in
projectorrotateVectors, already provides a x2/x3 speedup, while on my machine, I can obtain x5,x6 speedups.Some notes:
march=nativeflag. As it is, turning on AVX with-mavxdoes not turn on FMA. This also enables all SSE relevant feature sets, which could help simplify the compileflags.