Arithmetic types for alignment debugging
This class wraps fundamental arithmetic types and makes them overaligned. Actual alignment is checked at runtime in the constructor/destructor.
AVX SIMD types are overaligned, that is, some hardware instructions require them to be aligned to 32 bytes (or greater), while GCC only guarantees 16 bytes alignment. When allocated on the stack, the compiler still honours the overalignment, but typically not when allocated dynamically. This means that containers, that should support overaligned types, must use a special allocator to allocate internal memory that is supposed to hold objects of such types. This is however not always implemented correctly.
Debugging and unit testing with AVX SIMD types is not always possible, for instance because the required hardware or required libraries are not readily available. This makes is difficult to find incorrect use of allocators in containers.
This is where these overaligned wrapper types come in. They can be used for debugging and unit testing instead of SIMD types, and will work without particular hardware or libraries.
Depends: !225 (merged)
Due for merge: 2017-05-02
[WIP] Needs support for <cmath>
functions.
Missing:
- Support for
<cmath>
functions with more than one argument (can be added at a later time when someone needs them).
Merge request reports
Activity
Turns out that to debug
dune/istl/test/multirhstest
with this type we need support forsqrt()
and the other functions from<cmath>
. Turns out that when you add aDune::sqrt()
overload for the alignment debugging type, the world collapses, because there are places in dune where people forgot theusing std::sqrt;
before callingsqrt()
on e.g. adouble
value.Without
Dune::sqrt()
, asqrt(1.0)
in theDune
namespace will find the::sqrt()
candidates from<math.h>
via unqualified lookup, and will find nothing via ADL. It will then select the::sqrt(double)
overload.With
Dune::sqrt()
, asqrt(1.0)
in theDune
namespace will find::Dune::sqrt()
candidates via unqualified lookup. It will again find nothing via ADL, sincedouble
has no associated namespaces. No overload of::Dune::sqrt()
matches the double argument, so the lookup fails.Possible resolutions:
- Put
sqrt(AlignedNumber<...>)
and friends into namespaceDune
anyway, and fix all the bugs. Drawback: I can only fix the bugs that are in the core modules, and that are found by unit tests - Define
sqrt(AlignedNumber<...>)
and friends asfriend
functions insideAlignedNumber
, and do not declare them outside. This means that those functions will not be found by unqualified lookup, only by ADL. May not be possible to do right for functions with multiple argument (e.g.pow()
): where do you put the overload forpow(AlignedNumber<double, ...>, AlignedNumber<int, ...>)
? - Move
AlignedNumber
into a sub-namespace ofDune
, define the overloads there, and then dousing SubNamespace::AlignedNumber
insideDune
. A bit ugly, but should work.
- Put
mentioned in merge request dune-istl!87 (merged)
@joe did I miss something or does the type actually not specify the required alignement using
alignas
. This will lead to false positives for stack allocated objects.added 23 commits
-
94cbe250...3fcb1cf2 - 20 commits from branch
master
- 46cb6931 - [AlignedNumber] add unary function real
- d6a6abb7 - [AlignedNumber] add specialization of SimdScalarTypeTraits
- 7e4b9296 - Merge remote-tracking branch 'origin/master' into feature/debugalign
Toggle commit list-
94cbe250...3fcb1cf2 - 20 commits from branch
@joe, is there a reason not to merge yet?
added 35 commits
-
7e4b9296...c4d02b07 - 33 commits from branch
master
- bfac60ee - [AlignedNumber] Cleanup.
- ed778908 - Merge remote-tracking branch 'origin/master' into feature/debugalign
-
7e4b9296...c4d02b07 - 33 commits from branch
mentioned in commit 1d2a46ac