Update Kokkos library in LAMMPS to v3.7.0
This commit is contained in:
@ -48,13 +48,12 @@
|
||||
#include <algorithm>
|
||||
#include <initializer_list>
|
||||
#include <type_traits>
|
||||
#include "Kokkos_ExecPolicy.hpp"
|
||||
#include "Kokkos_Parallel_Reduce.hpp"
|
||||
|
||||
#include <cfloat>
|
||||
|
||||
#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) || \
|
||||
defined(KOKKOS_ENABLE_SYCL) || defined(KOKKOS_ENABLE_OPENMPTARGET)
|
||||
#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) || \
|
||||
defined(KOKKOS_ENABLE_SYCL) || defined(KOKKOS_ENABLE_OPENMPTARGET) || \
|
||||
defined(KOKKOS_ENABLE_OPENACC)
|
||||
#else
|
||||
#define MATHEMATICAL_FUNCTIONS_HAVE_LONG_DOUBLE_OVERLOADS
|
||||
#endif
|
||||
@ -239,14 +238,14 @@ struct FloatingPointComparison {
|
||||
|
||||
// Using absolute here instead of abs, since we actually test abs ...
|
||||
template <class T>
|
||||
KOKKOS_FUNCTION typename std::enable_if<std::is_signed<T>::value, T>::type
|
||||
absolute(T val) const {
|
||||
KOKKOS_FUNCTION std::enable_if_t<std::is_signed<T>::value, T> absolute(
|
||||
T val) const {
|
||||
return val < T(0) ? -val : val;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
KOKKOS_FUNCTION typename std::enable_if<!std::is_signed<T>::value, T>::type
|
||||
absolute(T val) const {
|
||||
KOKKOS_FUNCTION std::enable_if_t<!std::is_signed<T>::value, T> absolute(
|
||||
T val) const {
|
||||
return val;
|
||||
}
|
||||
|
||||
@ -257,10 +256,9 @@ struct FloatingPointComparison {
|
||||
|
||||
bool ar = absolute(fpv) < abs_tol;
|
||||
if (!ar) {
|
||||
#if !defined(KOKKOS_ENABLE_SYCL) && !defined(KOKKOS_ENABLE_HIP)
|
||||
printf("absolute value exceeds tolerance [|%e| > %e]\n", (double)fpv,
|
||||
abs_tol);
|
||||
#endif
|
||||
KOKKOS_IMPL_DO_NOT_USE_PRINTF(
|
||||
"absolute value exceeds tolerance [|%e| > %e]\n", (double)fpv,
|
||||
abs_tol);
|
||||
}
|
||||
|
||||
return ar;
|
||||
@ -279,12 +277,11 @@ struct FloatingPointComparison {
|
||||
double min_denom = static_cast<double>(
|
||||
absolute(rhs) < absolute(lhs) ? absolute(rhs) : absolute(lhs));
|
||||
double rel_diff = abs_diff / min_denom;
|
||||
bool ar = rel_diff < rel_tol;
|
||||
bool ar = abs_diff == 0 || rel_diff < rel_tol;
|
||||
if (!ar) {
|
||||
#if !defined(KOKKOS_ENABLE_SYCL) && !defined(KOKKOS_ENABLE_HIP)
|
||||
printf("relative difference exceeds tolerance [%e > %e]\n",
|
||||
(double)rel_diff, rel_tol);
|
||||
#endif
|
||||
KOKKOS_IMPL_DO_NOT_USE_PRINTF(
|
||||
"relative difference exceeds tolerance [%e > %e]\n",
|
||||
(double)rel_diff, rel_tol);
|
||||
}
|
||||
|
||||
return ar;
|
||||
@ -299,10 +296,10 @@ struct math_function_name;
|
||||
struct MathUnaryFunction_##FUNC { \
|
||||
template <typename T> \
|
||||
static KOKKOS_FUNCTION auto eval(T x) { \
|
||||
static_assert(std::is_same<decltype(Kokkos::Experimental::FUNC((T)0)), \
|
||||
static_assert(std::is_same<decltype(Kokkos::FUNC((T)0)), \
|
||||
math_unary_function_return_type_t<T>>::value, \
|
||||
""); \
|
||||
return Kokkos::Experimental::FUNC(x); \
|
||||
return Kokkos::FUNC(x); \
|
||||
} \
|
||||
template <typename T> \
|
||||
static auto eval_std(T x) { \
|
||||
@ -320,11 +317,17 @@ struct math_function_name;
|
||||
}; \
|
||||
constexpr char math_function_name<MathUnaryFunction_##FUNC>::name[]
|
||||
|
||||
#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_1
|
||||
// Generally the expected ULP error should come from here:
|
||||
// https://www.gnu.org/software/libc/manual/html_node/Errors-in-Math-Functions.html
|
||||
// For now 1s largely seem to work ...
|
||||
DEFINE_UNARY_FUNCTION_EVAL(exp, 2);
|
||||
#ifdef KOKKOS_COMPILER_NVHPC // FIXME_NVHPC exp2 not device callable,
|
||||
// workaround computes it via exp
|
||||
DEFINE_UNARY_FUNCTION_EVAL(exp2, 30);
|
||||
#else
|
||||
DEFINE_UNARY_FUNCTION_EVAL(exp2, 2);
|
||||
#endif
|
||||
DEFINE_UNARY_FUNCTION_EVAL(expm1, 2);
|
||||
DEFINE_UNARY_FUNCTION_EVAL(log, 2);
|
||||
DEFINE_UNARY_FUNCTION_EVAL(log10, 2);
|
||||
@ -347,7 +350,9 @@ DEFINE_UNARY_FUNCTION_EVAL(tanh, 2);
|
||||
DEFINE_UNARY_FUNCTION_EVAL(asinh, 4);
|
||||
DEFINE_UNARY_FUNCTION_EVAL(acosh, 2);
|
||||
DEFINE_UNARY_FUNCTION_EVAL(atanh, 2);
|
||||
#endif
|
||||
|
||||
#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_2
|
||||
#if defined(__APPLE__)
|
||||
// Apple's standard library implementation seems to have a poor implementation
|
||||
DEFINE_UNARY_FUNCTION_EVAL(erf, 5);
|
||||
@ -365,10 +370,14 @@ DEFINE_UNARY_FUNCTION_EVAL(lgamma, 2);
|
||||
DEFINE_UNARY_FUNCTION_EVAL(ceil, 2);
|
||||
DEFINE_UNARY_FUNCTION_EVAL(floor, 2);
|
||||
DEFINE_UNARY_FUNCTION_EVAL(trunc, 2);
|
||||
DEFINE_UNARY_FUNCTION_EVAL(round, 1);
|
||||
#ifndef KOKKOS_ENABLE_SYCL
|
||||
DEFINE_UNARY_FUNCTION_EVAL(nearbyint, 2);
|
||||
#endif
|
||||
|
||||
DEFINE_UNARY_FUNCTION_EVAL(logb, 2);
|
||||
#endif
|
||||
|
||||
#undef DEFINE_UNARY_FUNCTION_EVAL
|
||||
|
||||
#define DEFINE_BINARY_FUNCTION_EVAL(FUNC, ULP_FACTOR) \
|
||||
@ -376,10 +385,10 @@ DEFINE_UNARY_FUNCTION_EVAL(nearbyint, 2);
|
||||
template <typename T, typename U> \
|
||||
static KOKKOS_FUNCTION auto eval(T x, U y) { \
|
||||
static_assert( \
|
||||
std::is_same<decltype(Kokkos::Experimental::FUNC((T)0, (U)0)), \
|
||||
std::is_same<decltype(Kokkos::FUNC((T)0, (U)0)), \
|
||||
math_binary_function_return_type_t<T, U>>::value, \
|
||||
""); \
|
||||
return Kokkos::Experimental::FUNC(x, y); \
|
||||
return Kokkos::FUNC(x, y); \
|
||||
} \
|
||||
template <typename T, typename U> \
|
||||
static auto eval_std(T x, U y) { \
|
||||
@ -398,8 +407,14 @@ DEFINE_UNARY_FUNCTION_EVAL(nearbyint, 2);
|
||||
}; \
|
||||
constexpr char math_function_name<MathBinaryFunction_##FUNC>::name[]
|
||||
|
||||
#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_1
|
||||
DEFINE_BINARY_FUNCTION_EVAL(pow, 2);
|
||||
DEFINE_BINARY_FUNCTION_EVAL(hypot, 2);
|
||||
#endif
|
||||
#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_2
|
||||
DEFINE_BINARY_FUNCTION_EVAL(nextafter, 1);
|
||||
DEFINE_BINARY_FUNCTION_EVAL(copysign, 1);
|
||||
#endif
|
||||
|
||||
#undef DEFINE_BINARY_FUNCTION_EVAL
|
||||
|
||||
@ -443,10 +458,9 @@ struct TestMathUnaryFunction : FloatingPointComparison {
|
||||
bool ar = compare(Func::eval(val_[i]), res_[i], Func::ulp_factor());
|
||||
if (!ar) {
|
||||
++e;
|
||||
#if !defined(KOKKOS_ENABLE_SYCL) && !defined(KOKKOS_ENABLE_HIP)
|
||||
printf("value at %f which is %f was expected to be %f\n", (double)val_[i],
|
||||
(double)Func::eval(val_[i]), (double)res_[i]);
|
||||
#endif
|
||||
KOKKOS_IMPL_DO_NOT_USE_PRINTF(
|
||||
"value at %f which is %f was expected to be %f\n", (double)val_[i],
|
||||
(double)Func::eval(val_[i]), (double)res_[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -482,11 +496,9 @@ struct TestMathBinaryFunction : FloatingPointComparison {
|
||||
bool ar = compare(Func::eval(val1_, val2_), res_, Func::ulp_factor());
|
||||
if (!ar) {
|
||||
++e;
|
||||
#if !defined(KOKKOS_ENABLE_SYCL) && !defined(KOKKOS_ENABLE_HIP)
|
||||
printf("value at %f, %f which is %f was expected to be %f\n",
|
||||
(double)val1_, (double)val2_, (double)Func::eval(val1_, val2_),
|
||||
(double)res_);
|
||||
#endif
|
||||
KOKKOS_IMPL_DO_NOT_USE_PRINTF(
|
||||
"value at %f, %f which is %f was expected to be %f\n", (double)val1_,
|
||||
(double)val2_, (double)Func::eval(val1_, val2_), (double)res_);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -497,6 +509,8 @@ void do_test_math_binary_function(Arg1 arg1, Arg2 arg2) {
|
||||
(TestMathBinaryFunction<Space, Func, Arg1, Arg2>(arg1, arg2), 0)...};
|
||||
}
|
||||
|
||||
#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_1
|
||||
|
||||
TEST(TEST_CATEGORY, mathematical_functions_trigonometric_functions) {
|
||||
TEST_MATH_FUNCTION(sin)({true, false});
|
||||
TEST_MATH_FUNCTION(sin)({-3, -2, -1, 0, 1});
|
||||
@ -785,6 +799,9 @@ TEST(TEST_CATEGORY, mathematical_functions_hyperbolic_functions) {
|
||||
TEST_MATH_FUNCTION(atanh)({-.97l, .86l, -.53l, .42l, -.1l, 0.l});
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_2
|
||||
|
||||
TEST(TEST_CATEGORY, mathematical_functions_error_and_gamma_functions) {
|
||||
TEST_MATH_FUNCTION(erf)({-3, -2, -1, 0, 1});
|
||||
@ -874,6 +891,18 @@ TEST(TEST_CATEGORY,
|
||||
TEST_MATH_FUNCTION(trunc)({12.3l, 4.56l, 789.l});
|
||||
#endif
|
||||
|
||||
TEST_MATH_FUNCTION(round)({-3, -2, -1, 0, 1});
|
||||
TEST_MATH_FUNCTION(round)({-3l, -2l, -1l, 0l, 1l});
|
||||
TEST_MATH_FUNCTION(round)({-3ll, -2ll, -1ll, 0ll, 1ll});
|
||||
TEST_MATH_FUNCTION(round)({2u, 3u, 4u, 5u, 6u});
|
||||
TEST_MATH_FUNCTION(round)({2ul, 3ul, 4ul, 5ul, 6ul});
|
||||
TEST_MATH_FUNCTION(round)({2ull, 3ull, 4ull, 5ull, 6ull});
|
||||
TEST_MATH_FUNCTION(round)({2.3f, 2.5f, 2.7f, -2.3f, -2.5f, -2.7f, -0.0f});
|
||||
TEST_MATH_FUNCTION(round)({2.3, 2.5, 2.7, -2.3, -2.5, -2.7, -0.0});
|
||||
#ifdef MATHEMATICAL_FUNCTIONS_HAVE_LONG_DOUBLE_OVERLOADS
|
||||
TEST_MATH_FUNCTION(round)({2.3l, 2.5l, 2.7l, -2.3l, -2.5l, -2.7l, -0.0l});
|
||||
#endif
|
||||
|
||||
#ifndef KOKKOS_ENABLE_SYCL
|
||||
TEST_MATH_FUNCTION(nearbyint)({-3, -2, -1, 0, 1});
|
||||
TEST_MATH_FUNCTION(nearbyint)({-3l, -2l, -1l, 0l, 1l});
|
||||
@ -889,6 +918,43 @@ TEST(TEST_CATEGORY,
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(TEST_CATEGORY,
|
||||
mathematical_functions_floating_point_manipulation_functions) {
|
||||
TEST_MATH_FUNCTION(logb)({2, 3, 4, 56, 789});
|
||||
TEST_MATH_FUNCTION(logb)({2l, 3l, 4l, 56l, 789l});
|
||||
TEST_MATH_FUNCTION(logb)({2ll, 3ll, 4ll, 56ll, 789ll});
|
||||
TEST_MATH_FUNCTION(logb)({2u, 3u, 4u, 5u, 6u});
|
||||
TEST_MATH_FUNCTION(logb)({2ul, 3ul, 4ul, 5ul, 6ul});
|
||||
TEST_MATH_FUNCTION(logb)({2ull, 3ull, 4ull, 5ull, 6ull});
|
||||
TEST_MATH_FUNCTION(logb)({123.45f, 6789.0f});
|
||||
TEST_MATH_FUNCTION(logb)({123.45, 6789.0});
|
||||
#ifdef MATHEMATICAL_FUNCTIONS_HAVE_LONG_DOUBLE_OVERLOADS
|
||||
TEST_MATH_FUNCTION(logb)({123.45l, 6789.0l});
|
||||
#endif
|
||||
|
||||
do_test_math_binary_function<TEST_EXECSPACE, kk_nextafter>(0, 1.f);
|
||||
do_test_math_binary_function<TEST_EXECSPACE, kk_nextafter>(1, 2.f);
|
||||
do_test_math_binary_function<TEST_EXECSPACE, kk_nextafter>(0.1, 0);
|
||||
#ifdef MATHEMATICAL_FUNCTIONS_HAVE_LONG_DOUBLE_OVERLOADS
|
||||
do_test_math_binary_function<TEST_EXECSPACE, kk_nextafter>(1, 2.l);
|
||||
do_test_math_binary_function<TEST_EXECSPACE, kk_nextafter>(1.l, 2.l);
|
||||
#endif
|
||||
|
||||
do_test_math_binary_function<TEST_EXECSPACE, kk_copysign>(0, 1.f);
|
||||
do_test_math_binary_function<TEST_EXECSPACE, kk_copysign>(1, 2.f);
|
||||
do_test_math_binary_function<TEST_EXECSPACE, kk_copysign>(0.1, 0);
|
||||
do_test_math_binary_function<TEST_EXECSPACE, kk_copysign>(1.f, +2.f);
|
||||
do_test_math_binary_function<TEST_EXECSPACE, kk_copysign>(1.f, -2.f);
|
||||
do_test_math_binary_function<TEST_EXECSPACE, kk_copysign>(1., +2.);
|
||||
do_test_math_binary_function<TEST_EXECSPACE, kk_copysign>(1., -2.);
|
||||
#ifdef MATHEMATICAL_FUNCTIONS_HAVE_LONG_DOUBLE_OVERLOADS
|
||||
do_test_math_binary_function<TEST_EXECSPACE, kk_copysign>(1, +2.l);
|
||||
do_test_math_binary_function<TEST_EXECSPACE, kk_copysign>(1.l, +2);
|
||||
do_test_math_binary_function<TEST_EXECSPACE, kk_copysign>(1.l, +2.l);
|
||||
do_test_math_binary_function<TEST_EXECSPACE, kk_copysign>(1.l, -2.l);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class Space>
|
||||
struct TestAbsoluteValueFunction {
|
||||
TestAbsoluteValueFunction() { run(); }
|
||||
@ -898,7 +964,7 @@ struct TestAbsoluteValueFunction {
|
||||
ASSERT_EQ(errors, 0);
|
||||
}
|
||||
KOKKOS_FUNCTION void operator()(int, int& e) const {
|
||||
using Kokkos::Experimental::abs;
|
||||
using Kokkos::abs;
|
||||
if (abs(1) != 1 || abs(-1) != 1) {
|
||||
++e;
|
||||
KOKKOS_IMPL_DO_NOT_USE_PRINTF("failed abs(int)\n");
|
||||
@ -926,8 +992,8 @@ struct TestAbsoluteValueFunction {
|
||||
}
|
||||
#endif
|
||||
// special values
|
||||
using Kokkos::Experimental::isinf;
|
||||
using Kokkos::Experimental::isnan;
|
||||
using Kokkos::isinf;
|
||||
using Kokkos::isnan;
|
||||
if (abs(-0.) != 0.
|
||||
#ifndef KOKKOS_IMPL_WORKAROUND_INTEL_LLVM_DEFAULT_FLOATING_POINT_MODEL
|
||||
|| !isinf(abs(-INFINITY)) || !isnan(abs(-NAN))
|
||||
@ -962,7 +1028,7 @@ struct TestIsNaN {
|
||||
ASSERT_EQ(errors, 0);
|
||||
}
|
||||
KOKKOS_FUNCTION void operator()(int, int& e) const {
|
||||
using Kokkos::Experimental::isnan;
|
||||
using Kokkos::isnan;
|
||||
using Kokkos::Experimental::quiet_NaN;
|
||||
using Kokkos::Experimental::signaling_NaN;
|
||||
if (isnan(1) || isnan(INT_MAX)) {
|
||||
@ -1022,3 +1088,4 @@ struct TestIsNaN {
|
||||
TEST(TEST_CATEGORY, mathematical_functions_isnan) {
|
||||
TestIsNaN<TEST_EXECSPACE>();
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user