Skip to content

Commit

Permalink
soft_equiv used for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
brryan committed Sep 21, 2024
1 parent 925052b commit 9721942
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/utils/robust.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ KOKKOS_FORCEINLINE_FUNCTION
bool soft_equiv(const Real &val, const Real &ref,
const Real eps = 10. * std::numeric_limits<Real>::epsilon(),
const bool pass_on_small = true) {
if (std::fabs(val - ref) < precision * fabs(ref)) {
if (std::fabs(val - ref) < eps * fabs(ref)) {
// Return true equivalence if value and reference differ by less than precision
return true;
} else {
Expand Down
16 changes: 10 additions & 6 deletions tst/unit/kokkos_abstraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@

#include "basic_types.hpp"
#include "kokkos_abstraction.hpp"
#include "utils/robust.hpp"

using parthenon::DevExecSpace;
using parthenon::ParArray1D;
using parthenon::ParArray2D;
using parthenon::ParArray3D;
using parthenon::ParArray4D;
using parthenon::robust::soft_equiv;
using Real = double;

template <class T>
Expand Down Expand Up @@ -316,7 +318,6 @@ bool test_wrapper_nested_3d(OuterLoopPattern outer_loop_pattern,
// Copy array back from device to host
Kokkos::deep_copy(host_du, dev_du);

Real max_rel_err = -1;
const Real rel_tol = std::numeric_limits<Real>::epsilon();

// compare data on the host
Expand All @@ -326,12 +327,14 @@ bool test_wrapper_nested_3d(OuterLoopPattern outer_loop_pattern,
const Real analytic = 2.0 * (i + 1) * pow((j + 2) * (k + 3), 2.0);
const Real err = host_du(k, j, i - 1) - analytic;

max_rel_err = fmax(fabs(err / analytic), max_rel_err);
if (!soft_equiv(err, analytic, max_rel_err)) {
return false;
}
}
}
}

return max_rel_err < rel_tol;
return true;
}

template <class OuterLoopPattern, class InnerLoopPattern>
Expand Down Expand Up @@ -385,7 +388,6 @@ bool test_wrapper_nested_4d(OuterLoopPattern outer_loop_pattern,
// Copy array back from device to host
Kokkos::deep_copy(host_du, dev_du);

Real max_rel_err = -1;
const Real rel_tol = std::numeric_limits<Real>::epsilon();

// compare data on the host
Expand All @@ -396,13 +398,15 @@ bool test_wrapper_nested_4d(OuterLoopPattern outer_loop_pattern,
const Real analytic = 2.0 * (i + 1) * pow((j + 2) * (k + 3) * (n + 4), 2.0);
const Real err = host_du(n, k, j, i - 1) - analytic;

max_rel_err = fmax(fabs(err / analytic), max_rel_err);
if (!soft_equiv(err, analytic, max_rel_err)) {
return false;
}
}
}
}
}

return max_rel_err < rel_tol;
return true;
}

TEST_CASE("nested par_for loops", "[wrapper]") {
Expand Down

0 comments on commit 9721942

Please sign in to comment.