Update Kokkos library in LAMMPS to v4.0
This commit is contained in:
@ -1,46 +1,18 @@
|
||||
/*
|
||||
//@HEADER
|
||||
// ************************************************************************
|
||||
//
|
||||
// Kokkos v. 3.0
|
||||
// Copyright (2020) National Technology & Engineering
|
||||
// Kokkos v. 4.0
|
||||
// Copyright (2022) National Technology & Engineering
|
||||
// Solutions of Sandia, LLC (NTESS).
|
||||
//
|
||||
// Under the terms of Contract DE-NA0003525 with NTESS,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://kokkos.org/LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the Corporation nor the names of the
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NTESS OR THE
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Questions? Contact Christian R. Trott (crtrott@sandia.gov)
|
||||
//
|
||||
// ************************************************************************
|
||||
//@HEADER
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@ -224,6 +196,9 @@ template <> struct math_binary_function_return_type<unsigned long long, l
|
||||
template <class T, class U>
|
||||
using math_binary_function_return_type_t = typename math_binary_function_return_type<T, U>::type;
|
||||
// clang-format on
|
||||
template <class T, class U, class V>
|
||||
using math_ternary_function_return_type_t = math_binary_function_return_type_t<
|
||||
T, math_binary_function_return_type_t<U, V>>;
|
||||
|
||||
struct FloatingPointComparison {
|
||||
private:
|
||||
@ -292,29 +267,29 @@ struct FloatingPointComparison {
|
||||
template <class>
|
||||
struct math_function_name;
|
||||
|
||||
#define DEFINE_UNARY_FUNCTION_EVAL(FUNC, ULP_FACTOR) \
|
||||
struct MathUnaryFunction_##FUNC { \
|
||||
template <typename T> \
|
||||
static KOKKOS_FUNCTION auto eval(T x) { \
|
||||
static_assert(std::is_same<decltype(Kokkos::FUNC((T)0)), \
|
||||
math_unary_function_return_type_t<T>>::value, \
|
||||
""); \
|
||||
return Kokkos::FUNC(x); \
|
||||
} \
|
||||
template <typename T> \
|
||||
static auto eval_std(T x) { \
|
||||
static_assert(std::is_same<decltype(std::FUNC((T)0)), \
|
||||
math_unary_function_return_type_t<T>>::value, \
|
||||
""); \
|
||||
return std::FUNC(x); \
|
||||
} \
|
||||
static KOKKOS_FUNCTION double ulp_factor() { return ULP_FACTOR; } \
|
||||
}; \
|
||||
using kk_##FUNC = MathUnaryFunction_##FUNC; \
|
||||
template <> \
|
||||
struct math_function_name<MathUnaryFunction_##FUNC> { \
|
||||
static constexpr char name[] = #FUNC; \
|
||||
}; \
|
||||
#define DEFINE_UNARY_FUNCTION_EVAL(FUNC, ULP_FACTOR) \
|
||||
struct MathUnaryFunction_##FUNC { \
|
||||
template <typename T> \
|
||||
static KOKKOS_FUNCTION auto eval(T x) { \
|
||||
static_assert( \
|
||||
std::is_same<decltype(Kokkos::FUNC((T)0)), \
|
||||
math_unary_function_return_type_t<T>>::value); \
|
||||
return Kokkos::FUNC(x); \
|
||||
} \
|
||||
template <typename T> \
|
||||
static auto eval_std(T x) { \
|
||||
static_assert( \
|
||||
std::is_same<decltype(std::FUNC((T)0)), \
|
||||
math_unary_function_return_type_t<T>>::value); \
|
||||
return std::FUNC(x); \
|
||||
} \
|
||||
static KOKKOS_FUNCTION double ulp_factor() { return ULP_FACTOR; } \
|
||||
}; \
|
||||
using kk_##FUNC = MathUnaryFunction_##FUNC; \
|
||||
template <> \
|
||||
struct math_function_name<MathUnaryFunction_##FUNC> { \
|
||||
static constexpr char name[] = #FUNC; \
|
||||
}; \
|
||||
constexpr char math_function_name<MathUnaryFunction_##FUNC>::name[]
|
||||
|
||||
#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_1
|
||||
@ -380,31 +355,29 @@ DEFINE_UNARY_FUNCTION_EVAL(logb, 2);
|
||||
|
||||
#undef DEFINE_UNARY_FUNCTION_EVAL
|
||||
|
||||
#define DEFINE_BINARY_FUNCTION_EVAL(FUNC, ULP_FACTOR) \
|
||||
struct MathBinaryFunction_##FUNC { \
|
||||
template <typename T, typename U> \
|
||||
static KOKKOS_FUNCTION auto eval(T x, U y) { \
|
||||
static_assert( \
|
||||
std::is_same<decltype(Kokkos::FUNC((T)0, (U)0)), \
|
||||
math_binary_function_return_type_t<T, U>>::value, \
|
||||
""); \
|
||||
return Kokkos::FUNC(x, y); \
|
||||
} \
|
||||
template <typename T, typename U> \
|
||||
static auto eval_std(T x, U y) { \
|
||||
static_assert( \
|
||||
std::is_same<decltype(std::FUNC((T)0, (U)0)), \
|
||||
math_binary_function_return_type_t<T, U>>::value, \
|
||||
""); \
|
||||
return std::FUNC(x, y); \
|
||||
} \
|
||||
static KOKKOS_FUNCTION double ulp_factor() { return ULP_FACTOR; } \
|
||||
}; \
|
||||
using kk_##FUNC = MathBinaryFunction_##FUNC; \
|
||||
template <> \
|
||||
struct math_function_name<MathBinaryFunction_##FUNC> { \
|
||||
static constexpr char name[] = #FUNC; \
|
||||
}; \
|
||||
#define DEFINE_BINARY_FUNCTION_EVAL(FUNC, ULP_FACTOR) \
|
||||
struct MathBinaryFunction_##FUNC { \
|
||||
template <typename T, typename U> \
|
||||
static KOKKOS_FUNCTION auto eval(T x, U y) { \
|
||||
static_assert( \
|
||||
std::is_same<decltype(Kokkos::FUNC((T)0, (U)0)), \
|
||||
math_binary_function_return_type_t<T, U>>::value); \
|
||||
return Kokkos::FUNC(x, y); \
|
||||
} \
|
||||
template <typename T, typename U> \
|
||||
static auto eval_std(T x, U y) { \
|
||||
static_assert( \
|
||||
std::is_same<decltype(std::FUNC((T)0, (U)0)), \
|
||||
math_binary_function_return_type_t<T, U>>::value); \
|
||||
return std::FUNC(x, y); \
|
||||
} \
|
||||
static KOKKOS_FUNCTION double ulp_factor() { return ULP_FACTOR; } \
|
||||
}; \
|
||||
using kk_##FUNC = MathBinaryFunction_##FUNC; \
|
||||
template <> \
|
||||
struct math_function_name<MathBinaryFunction_##FUNC> { \
|
||||
static constexpr char name[] = #FUNC; \
|
||||
}; \
|
||||
constexpr char math_function_name<MathBinaryFunction_##FUNC>::name[]
|
||||
|
||||
#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_1
|
||||
@ -418,6 +391,38 @@ DEFINE_BINARY_FUNCTION_EVAL(copysign, 1);
|
||||
|
||||
#undef DEFINE_BINARY_FUNCTION_EVAL
|
||||
|
||||
#define DEFINE_TERNARY_FUNCTION_EVAL(FUNC, ULP_FACTOR) \
|
||||
struct MathTernaryFunction_##FUNC { \
|
||||
template <typename T, typename U, typename V> \
|
||||
static KOKKOS_FUNCTION auto eval(T x, U y, V z) { \
|
||||
static_assert( \
|
||||
std::is_same<decltype(Kokkos::FUNC((T)0, (U)0, (V)0)), \
|
||||
math_ternary_function_return_type_t<T, U, V>>::value); \
|
||||
return Kokkos::FUNC(x, y, z); \
|
||||
} \
|
||||
template <typename T, typename U, typename V> \
|
||||
static auto eval_std(T x, U y, V z) { \
|
||||
static_assert( \
|
||||
std::is_same<decltype(std::FUNC((T)0, (U)0, (V)0)), \
|
||||
math_ternary_function_return_type_t<T, U, V>>::value); \
|
||||
return std::FUNC(x, y, z); \
|
||||
} \
|
||||
static KOKKOS_FUNCTION double ulp_factor() { return ULP_FACTOR; } \
|
||||
}; \
|
||||
using kk3_##FUNC = MathTernaryFunction_##FUNC; \
|
||||
template <> \
|
||||
struct math_function_name<MathTernaryFunction_##FUNC> { \
|
||||
static constexpr char name[] = #FUNC; \
|
||||
}; \
|
||||
constexpr char math_function_name<MathTernaryFunction_##FUNC>::name[]
|
||||
|
||||
#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_1
|
||||
DEFINE_TERNARY_FUNCTION_EVAL(hypot, 2);
|
||||
DEFINE_TERNARY_FUNCTION_EVAL(fma, 2);
|
||||
#endif
|
||||
|
||||
#undef DEFINE_TERNARY_FUNCTION_EVAL
|
||||
|
||||
// clang-format off
|
||||
template <class>
|
||||
struct type_helper;
|
||||
@ -509,6 +514,49 @@ void do_test_math_binary_function(Arg1 arg1, Arg2 arg2) {
|
||||
(TestMathBinaryFunction<Space, Func, Arg1, Arg2>(arg1, arg2), 0)...};
|
||||
}
|
||||
|
||||
template <class Space, class Func, class Arg1, class Arg2, class Arg3,
|
||||
class Ret = math_ternary_function_return_type_t<Arg1, Arg2, Arg3>>
|
||||
struct TestMathTernaryFunction : FloatingPointComparison {
|
||||
Arg1 val1_;
|
||||
Arg2 val2_;
|
||||
Arg3 val3_;
|
||||
Ret res_;
|
||||
TestMathTernaryFunction(Arg1 val1, Arg2 val2, Arg3 val3)
|
||||
: val1_(val1),
|
||||
val2_(val2),
|
||||
val3_(val3),
|
||||
res_(Func::eval_std(val1, val2, val3)) {
|
||||
run();
|
||||
}
|
||||
void run() {
|
||||
int errors = 0;
|
||||
Kokkos::parallel_reduce(Kokkos::RangePolicy<Space>(0, 1), *this, errors);
|
||||
ASSERT_EQ(errors, 0) << "Failed check no error for "
|
||||
<< math_function_name<Func>::name << "("
|
||||
<< type_helper<Arg1>::name() << ", "
|
||||
<< type_helper<Arg1>::name() << ", "
|
||||
<< type_helper<Arg3>::name() << ")";
|
||||
}
|
||||
KOKKOS_FUNCTION void operator()(int, int& e) const {
|
||||
bool ar =
|
||||
compare(Func::eval(val1_, val2_, val3_), res_, Func::ulp_factor());
|
||||
if (!ar) {
|
||||
++e;
|
||||
KOKKOS_IMPL_DO_NOT_USE_PRINTF(
|
||||
"value at %f, %f, %f which is %f was expected to be %f\n",
|
||||
(double)val1_, (double)val2_, (double)val3_,
|
||||
(double)Func::eval(val1_, val2_, val3_), (double)res_);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Space, class... Func, class Arg1, class Arg2, class Arg3>
|
||||
void do_test_math_ternary_function(Arg1 arg1, Arg2 arg2, Arg3 arg3) {
|
||||
(void)std::initializer_list<int>{
|
||||
(TestMathTernaryFunction<Space, Func, Arg1, Arg2, Arg3>(arg1, arg2, arg3),
|
||||
0)...};
|
||||
}
|
||||
|
||||
#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_1
|
||||
|
||||
TEST(TEST_CATEGORY, mathematical_functions_trigonometric_functions) {
|
||||
@ -631,6 +679,24 @@ TEST(TEST_CATEGORY, mathematical_functions_power_functions) {
|
||||
#if !(defined(KOKKOS_ARCH_POWER8) || defined(KOKKOS_ARCH_POWER9))
|
||||
do_test_math_binary_function<TEST_EXECSPACE, kk_hypot>(2.l, 3.l);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
do_test_math_ternary_function<TEST_EXECSPACE, kk3_hypot>(2.f, 3.f, 4.f);
|
||||
do_test_math_ternary_function<TEST_EXECSPACE, kk3_hypot>(2., 3., 4.);
|
||||
do_test_math_ternary_function<TEST_EXECSPACE, kk3_hypot>(2, 3.f, 4.);
|
||||
#ifdef MATHEMATICAL_FUNCTIONS_HAVE_LONG_DOUBLE_OVERLOADS
|
||||
#if !(defined(KOKKOS_ARCH_POWER8) || defined(KOKKOS_ARCH_POWER9))
|
||||
do_test_math_ternary_function<TEST_EXECSPACE, kk3_hypot>(2.l, 3.l, 4.l);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(TEST_CATEGORY, mathematical_functions_fma) {
|
||||
do_test_math_ternary_function<TEST_EXECSPACE, kk3_fma>(2.f, 3.f, 4.f);
|
||||
do_test_math_ternary_function<TEST_EXECSPACE, kk3_fma>(2., 3., 4.);
|
||||
do_test_math_ternary_function<TEST_EXECSPACE, kk3_fma>(2, 3.f, 4.);
|
||||
#ifdef MATHEMATICAL_FUNCTIONS_HAVE_LONG_DOUBLE_OVERLOADS
|
||||
do_test_math_ternary_function<TEST_EXECSPACE, kk3_fma>(2.l, 3.l, 4.l);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1047,8 +1113,10 @@ struct TestIsNaN {
|
||||
}
|
||||
if (isnan(3.)
|
||||
#ifndef KOKKOS_IMPL_WORKAROUND_INTEL_LLVM_DEFAULT_FLOATING_POINT_MODEL
|
||||
#ifndef KOKKOS_COMPILER_NVHPC // FIXME_NVHPC
|
||||
|| !isnan(quiet_NaN<double>::value) ||
|
||||
!isnan(signaling_NaN<double>::value)
|
||||
#endif
|
||||
#endif
|
||||
) {
|
||||
++e;
|
||||
|
||||
Reference in New Issue
Block a user