Loading...
Searching...
No Matches
Dune::Simd::UnitTest Class Reference

`#include <dune/common/simd/test.hh>`

## Public Member Functions

template<class V, class Rebinds, template< class > class RebindPrune = IsLoop, template< class > class RebindAccept = Dune::AlwaysTrue>
void | check ()
| run unit tests for simd vector type V
bool | good () const
| whether all tests succeeded
Test instantiation points

These functions should not be called directly, but serve as explicit instantiation points to keep memory usage bounded during compilation. There should be an explicit instantiation declaration (extern template ...) in the the overall header of your unit test for each type that is tested (possibly implicitly tested due to recursive checks). Similarly, there should be an explicit instantiation definition (template ...) in a separate translation unit. Ideally, there should be one translation unit per explicit instantiation definition, otherwise each of them will contribute to the overall memory used during compilation.

If explicitly instantiating the top-level instantiation point checkType() is not sufficient, there are further instantiation points for improved granularity. The hierarchy of instantiation points is:

- checkType()
  - checkNonOps()
  - checkUnaryOps()
  - checkBinaryOps()
    - checkBinaryOpsVectorVector()
    - checkBinaryOpsScalarVector()
    - checkBinaryOpsVectorScalar()
    - checkBinaryOpsProxyVector()
    - checkBinaryOpsVectorProxy()

Each instantiation point in the hierarchy implicitly instantiates its descendants, unless there are explicit instantiation declarations for them. However, for future-proofing it can make sense to explicitly instantiate nodes in the hierarchy even if all their children are already explicitly instantiated. This will limit the impact of instantiation points added in the future.

For an example of how to do the instantiations, look at standardtest, there is cmake machinery to support you.

Background: The compiler can use a lot of memory when compiling a unit test for many Simd vector types. E.g. for standardtest.cc, which tests all the fundamental arithmetic types plus `std::complex`, g++ 4.9.2 (-g -O0 -Wall on x86_64 GNU/Linux) used ~6GByte.

One mitigation was to explicitly instantiate `checkVector()` (a previous, now obsolete incarnation of this instantiation machinery) for the types that are tested. Still after doing that, standardtest.cc needed ~1.5GByte during compilation, which is more than the compilation units that actually instantiated `checkVector()` (which clocked in at maximum at around 800MB, depending on how many instantiations they contained).

The second mitigation was to define `checkVector()` outside of the class. I have no idea why this helped, but it made compilation use less than ~100MByte. (Yes, functions defined inside the class are implicitly `inline`, but the function is a template so it has inline semantics even when defined outside of the class. And I tried `attribute`((noinline)), which had no effect on memory consumption.)

template<class V>
void | checkType ()
template<class V>
void | checkNonOps ()
template<class V>
void | checkUnaryOps ()
template<class V>
void | checkBinaryOps ()
template<class V>
void | checkBinaryOpsVectorVector ()
template<class V>
void | checkBinaryOpsScalarVector ()
template<class V>
void | checkBinaryOpsVectorScalar ()
template<class V>
void | checkBinaryOpsProxyVector ()
template<class V>
void | checkBinaryOpsVectorProxy ()

## Member Function Documentation

## check()

template<class V, class Rebinds, template< class > class RebindPrune = IsLoop, template< class > class RebindAccept = Dune::AlwaysTrue>

void Dune::Simd::UnitTest::check | ( |  | ) |

inline

run unit tests for simd vector type V

This function will also ensure that check<W>() is run, for any type W = Rebind<R, V> where R is in Rebinds, and RebindPrune<W>::value == false. No test will be run twice for a given type.

If the result of Rebind is not pruned by RebindPrune, it will be passed to RebindAccept. If that rejects the type, a static assertion will trigger.

Template Parameters

  Rebinds | A list of types, usually in the form of a TypeList.
  RebindPrune | A type predicate determining whether to run check() for types obtained from Rebinds.
  RebindAccept | A type predicate determining whether a type is acceptable as the result of a Rebind.

## checkBinaryOps()

template<class V>

void Dune::Simd::UnitTest::checkBinaryOps | ( |  | ) |

## checkBinaryOpsProxyVector()

template<class V>

void Dune::Simd::UnitTest::checkBinaryOpsProxyVector | ( |  | ) |

## checkBinaryOpsScalarVector()

template<class V>

void Dune::Simd::UnitTest::checkBinaryOpsScalarVector | ( |  | ) |

## checkBinaryOpsVectorProxy()

template<class V>

void Dune::Simd::UnitTest::checkBinaryOpsVectorProxy | ( |  | ) |

## checkBinaryOpsVectorScalar()

template<class V>

void Dune::Simd::UnitTest::checkBinaryOpsVectorScalar | ( |  | ) |

## checkBinaryOpsVectorVector()

template<class V>

void Dune::Simd::UnitTest::checkBinaryOpsVectorVector | ( |  | ) |

## checkNonOps()

template<class V>

void Dune::Simd::UnitTest::checkNonOps | ( |  | ) |

## checkType()

template<class V>

void Dune::Simd::UnitTest::checkType | ( |  | ) |

## checkUnaryOps()

template<class V>

void Dune::Simd::UnitTest::checkUnaryOps | ( |  | ) |

## good()

bool Dune::Simd::UnitTest::good | ( |  | ) | const

inline

whether all tests succeeded

The documentation for this class was generated from the following file:

- test.hh