Skip to content

Commit

Permalink
Merge Add core and reference multiprecision tests
Browse files Browse the repository at this point in the history
This adds multiprecision tests for the core and reference modules. In addition to this, all non matrix, solver and preconditioners in the OpenMP module also have multiprecision tests.
### Summary of changes
+ All core tests rewrote for multiple precisions
+ All reference tests rewrote for multiple precisions
+ Extra OpenMP tests rewrote for multiple precisions (non matrix, solver or preconditioner).
+ codecov is put back into Ginkgo, and our coverage significantly improved thanks to the templated tests
+ In `core/test/utils.hpp`, a bunch of declarations were provided for default values we want to tests, and other tools used when doing multiprecision tests.
+ In `core/test/utils/assertions.hpp`, `get_relative_error` and other commonly used functions from the assertions were extended for the complex value case (using `gko::remove_complex` most of the time). A new assertion was added for comparing values of complex type (`GKO_ASSERT_NEAR`, which extends the basic gtest one `ASSERT_NEAR`).
+ Papi required some fixes (counting the instances of Papi loggers globally instead of per template valuetype).
+ `Ilu` required some fixes (using `gko::remove_complex` and removing default valuetype use of `<>`).

### How to write templated tests
`core/tests/utils.hpp` always needs to be included because it provides required definitions.
In general, if only one kind of precision (e.g. `value_type`) is required, then normal templating can be used, otherwise, due to the use of the macro for declaring the templated values to try, a tuple which contains all the elements need to be defined, see the `reference/test/matrix/csr_kernels.cpp` for example.
```cpp
template <typename ValueIndexType>
class Csr : public ::testing::Test {
protected:
    using value_type =
        typename std::tuple_element<0, decltype(ValueIndexType())>::type;
    using index_type =
        typename std::tuple_element<1, decltype(ValueIndexType())>::type;
};
```

Afterwards, the class needs to be instantiated for all precisions, which is done such as in the following way:
```cpp
TYPED_TEST_CASE(Csr, gko::test::ValueIndexTypes);
```
Note that `ValueIndexTypes` is provided by `utils.hpp` and contains tuples of all valuetype and index type combinations.

As a requirement, the tests now need to use the macro `TYPED_TEST` instead of `TEST_F`. This has multiple implications:
+ All member objects/functions have to be accessed with `this->`.
+ All member definitions such as `using` need to be accessed through `TestFixture::Mtx` for example. The approach I used is to add to every test the required `using` shortcut to make the tests look nicer.
+ A variable `TypeParam` is provided which is the template type of the test.
+ Due to complexes being able to be built with `{real, img}` notation, our initializations of the form `{{1.0, 2.0}, {3.0, 4.0}}` are ambiguous (the second `{`). I provided a shortcut `I<type>` for stating that this is actually an initializer list of type T, and not a complex construction. So the following example would be replaced with:  
```cpp
using T = typename TestFixture::value_type;
auto mtx = gko::initialize({I<T>{1.0, 2.0}, I<T>{3.0, 4.0}}, this->exec);
```

Finally, I implemented a shortcut `r<value_type>::value` for providing depending on the type of the value a proper precision (`1e-7` for `float` and `std::complex<float>`, and `1e-14` for `double` variants).


### Closes: #32
### Related PR: #448
  • Loading branch information
tcojean authored Mar 4, 2020
2 parents c1ac9f4 + 5b13903 commit 000a364
Show file tree
Hide file tree
Showing 96 changed files with 7,261 additions and 4,393 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ sonarqube_cov_:
-Dsonar.cfamily.build-wrapper-output=build/bw-output
-Dsonar.cfamily.gcov.reportsPath=build/Testing/CoverageInfo
${sonar_branching}
# - bash <(curl -s https://codecov.io/bash) -X gcov -X xcode -f "!*examples*" -f "!*third_party*" -f "!*c\\+\\+*" -f "!*benchmark*"
- bash <(curl -s https://codecov.io/bash) -f "\!*examples*" -f "\!*third_party*" -f "\!*c\\+\\+*" -f "\!*benchmark*"
dependencies: []
except:
refs:
Expand Down
2 changes: 1 addition & 1 deletion cmake/CTestCustom.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ list(APPEND CTEST_CUSTOM_COVERAGE_EXCLUDE

".*/third_party/.*"

".*/test/.*"
".*/doc/.*"

".*/benchmark/.*"

Expand Down
3 changes: 2 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ coverage:
threshold: 2
base: auto
ignore:
- "**/test/"
- "examples"
- "benchmark"
1 change: 1 addition & 0 deletions core/log/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ constexpr Logger::mask_type Logger::criterion_check_completed_mask;

constexpr Logger::mask_type Logger::iteration_complete_mask;


} // namespace log
} // namespace gko
4 changes: 0 additions & 4 deletions core/log/papi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ namespace gko {
namespace log {


template <typename ValueType>
size_type Papi<ValueType>::logger_count = 0;


template <typename ValueType>
void Papi<ValueType>::on_allocation_started(const Executor *exec,
const size_type &num_bytes) const
Expand Down
Loading

0 comments on commit 000a364

Please sign in to comment.