Fast homogeneous and rotation matrix multiplications#1845
Draft
SamFlt wants to merge 26 commits intolagadic:masterfrom
Draft
Fast homogeneous and rotation matrix multiplications#1845SamFlt wants to merge 26 commits intolagadic:masterfrom
SamFlt wants to merge 26 commits intolagadic:masterfrom
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);
| ^
s-trinh
reviewed
Dec 7, 2025
Comment on lines
+97
to
+104
| #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); | ||
| } |
Contributor
There was a problem hiding this comment.
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 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.