Update Kokkos library in LAMMPS to v3.2
This commit is contained in:
@ -54,8 +54,8 @@ namespace Test {
|
||||
template <typename ScalarType, class DeviceType>
|
||||
class ReduceFunctor {
|
||||
public:
|
||||
typedef DeviceType execution_space;
|
||||
typedef typename execution_space::size_type size_type;
|
||||
using execution_space = DeviceType;
|
||||
using size_type = typename execution_space::size_type;
|
||||
|
||||
struct value_type {
|
||||
ScalarType value[3];
|
||||
@ -97,7 +97,7 @@ class ReduceFunctor {
|
||||
template <class DeviceType>
|
||||
class ReduceFunctorFinal : public ReduceFunctor<int64_t, DeviceType> {
|
||||
public:
|
||||
typedef typename ReduceFunctor<int64_t, DeviceType>::value_type value_type;
|
||||
using value_type = typename ReduceFunctor<int64_t, DeviceType>::value_type;
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
ReduceFunctorFinal(const size_t n) : ReduceFunctor<int64_t, DeviceType>(n) {}
|
||||
@ -114,13 +114,13 @@ template <typename ScalarType, class DeviceType>
|
||||
class RuntimeReduceFunctor {
|
||||
public:
|
||||
// Required for functor:
|
||||
typedef DeviceType execution_space;
|
||||
typedef ScalarType value_type[];
|
||||
using execution_space = DeviceType;
|
||||
using value_type = ScalarType[];
|
||||
const unsigned value_count;
|
||||
|
||||
// Unit test details:
|
||||
|
||||
typedef typename execution_space::size_type size_type;
|
||||
using size_type = typename execution_space::size_type;
|
||||
|
||||
const size_type nwork;
|
||||
|
||||
@ -151,13 +151,13 @@ template <typename ScalarType, class DeviceType>
|
||||
class RuntimeReduceMinMax {
|
||||
public:
|
||||
// Required for functor:
|
||||
typedef DeviceType execution_space;
|
||||
typedef ScalarType value_type[];
|
||||
using execution_space = DeviceType;
|
||||
using value_type = ScalarType[];
|
||||
const unsigned value_count;
|
||||
|
||||
// Unit test details:
|
||||
|
||||
typedef typename execution_space::size_type size_type;
|
||||
using size_type = typename execution_space::size_type;
|
||||
|
||||
const size_type nwork;
|
||||
const ScalarType amin;
|
||||
@ -200,9 +200,9 @@ template <class DeviceType>
|
||||
class RuntimeReduceFunctorFinal
|
||||
: public RuntimeReduceFunctor<int64_t, DeviceType> {
|
||||
public:
|
||||
typedef RuntimeReduceFunctor<int64_t, DeviceType> base_type;
|
||||
typedef typename base_type::value_type value_type;
|
||||
typedef int64_t scalar_type;
|
||||
using base_type = RuntimeReduceFunctor<int64_t, DeviceType>;
|
||||
using value_type = typename base_type::value_type;
|
||||
using scalar_type = int64_t;
|
||||
|
||||
RuntimeReduceFunctorFinal(const size_t theNwork, const size_t count)
|
||||
: base_type(theNwork, count) {}
|
||||
@ -215,13 +215,38 @@ class RuntimeReduceFunctorFinal
|
||||
}
|
||||
};
|
||||
|
||||
template <class ValueType, class DeviceType>
|
||||
class CombinedReduceFunctorSameType {
|
||||
public:
|
||||
using execution_space = typename DeviceType::execution_space;
|
||||
using size_type = typename execution_space::size_type;
|
||||
|
||||
const size_type nwork;
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
constexpr explicit CombinedReduceFunctorSameType(const size_type& arg_nwork)
|
||||
: nwork(arg_nwork) {}
|
||||
|
||||
KOKKOS_DEFAULTED_FUNCTION
|
||||
constexpr CombinedReduceFunctorSameType(
|
||||
const CombinedReduceFunctorSameType& rhs) = default;
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator()(size_type iwork, ValueType& dst1, ValueType& dst2,
|
||||
ValueType& dst3) const {
|
||||
dst1 += 1;
|
||||
dst2 += iwork + 1;
|
||||
dst3 += nwork - iwork;
|
||||
}
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename ScalarType, class DeviceType>
|
||||
class TestReduce {
|
||||
public:
|
||||
typedef DeviceType execution_space;
|
||||
typedef typename execution_space::size_type size_type;
|
||||
using execution_space = DeviceType;
|
||||
using size_type = typename execution_space::size_type;
|
||||
|
||||
TestReduce(const size_type& nwork) {
|
||||
run_test(nwork);
|
||||
@ -229,8 +254,8 @@ class TestReduce {
|
||||
}
|
||||
|
||||
void run_test(const size_type& nwork) {
|
||||
typedef Test::ReduceFunctor<ScalarType, execution_space> functor_type;
|
||||
typedef typename functor_type::value_type value_type;
|
||||
using functor_type = Test::ReduceFunctor<ScalarType, execution_space>;
|
||||
using value_type = typename functor_type::value_type;
|
||||
|
||||
enum { Count = 3 };
|
||||
enum { Repeat = 100 };
|
||||
@ -253,8 +278,8 @@ class TestReduce {
|
||||
}
|
||||
|
||||
void run_test_final(const size_type& nwork) {
|
||||
typedef Test::ReduceFunctorFinal<execution_space> functor_type;
|
||||
typedef typename functor_type::value_type value_type;
|
||||
using functor_type = Test::ReduceFunctorFinal<execution_space>;
|
||||
using value_type = typename functor_type::value_type;
|
||||
|
||||
enum { Count = 3 };
|
||||
enum { Repeat = 100 };
|
||||
@ -285,8 +310,8 @@ class TestReduce {
|
||||
template <typename ScalarType, class DeviceType>
|
||||
class TestReduceDynamic {
|
||||
public:
|
||||
typedef DeviceType execution_space;
|
||||
typedef typename execution_space::size_type size_type;
|
||||
using execution_space = DeviceType;
|
||||
using size_type = typename execution_space::size_type;
|
||||
|
||||
TestReduceDynamic(const size_type nwork) {
|
||||
run_test_dynamic(nwork);
|
||||
@ -295,8 +320,8 @@ class TestReduceDynamic {
|
||||
}
|
||||
|
||||
void run_test_dynamic(const size_type nwork) {
|
||||
typedef Test::RuntimeReduceFunctor<ScalarType, execution_space>
|
||||
functor_type;
|
||||
using functor_type =
|
||||
Test::RuntimeReduceFunctor<ScalarType, execution_space>;
|
||||
|
||||
enum { Count = 3 };
|
||||
enum { Repeat = 100 };
|
||||
@ -324,7 +349,7 @@ class TestReduceDynamic {
|
||||
}
|
||||
|
||||
void run_test_dynamic_minmax(const size_type nwork) {
|
||||
typedef Test::RuntimeReduceMinMax<ScalarType, execution_space> functor_type;
|
||||
using functor_type = Test::RuntimeReduceMinMax<ScalarType, execution_space>;
|
||||
|
||||
enum { Count = 2 };
|
||||
enum { Repeat = 100 };
|
||||
@ -356,7 +381,7 @@ class TestReduceDynamic {
|
||||
}
|
||||
|
||||
void run_test_dynamic_final(const size_type nwork) {
|
||||
typedef Test::RuntimeReduceFunctorFinal<execution_space> functor_type;
|
||||
using functor_type = Test::RuntimeReduceFunctorFinal<execution_space>;
|
||||
|
||||
enum { Count = 3 };
|
||||
enum { Repeat = 100 };
|
||||
@ -387,17 +412,17 @@ class TestReduceDynamic {
|
||||
template <typename ScalarType, class DeviceType>
|
||||
class TestReduceDynamicView {
|
||||
public:
|
||||
typedef DeviceType execution_space;
|
||||
typedef typename execution_space::size_type size_type;
|
||||
using execution_space = DeviceType;
|
||||
using size_type = typename execution_space::size_type;
|
||||
|
||||
TestReduceDynamicView(const size_type nwork) { run_test_dynamic_view(nwork); }
|
||||
|
||||
void run_test_dynamic_view(const size_type nwork) {
|
||||
typedef Test::RuntimeReduceFunctor<ScalarType, execution_space>
|
||||
functor_type;
|
||||
using functor_type =
|
||||
Test::RuntimeReduceFunctor<ScalarType, execution_space>;
|
||||
|
||||
typedef Kokkos::View<ScalarType*, DeviceType> result_type;
|
||||
typedef typename result_type::HostMirror result_host_type;
|
||||
using result_type = Kokkos::View<ScalarType*, DeviceType>;
|
||||
using result_host_type = typename result_type::HostMirror;
|
||||
|
||||
const unsigned CountLimit = 23;
|
||||
|
||||
@ -455,4 +480,45 @@ TEST(TEST_CATEGORY, int64_t_reduce_dynamic_view) {
|
||||
TestReduceDynamicView<int64_t, TEST_EXECSPACE>(1000000);
|
||||
}
|
||||
|
||||
TEST(TEST_CATEGORY, int_combined_reduce) {
|
||||
using functor_type = CombinedReduceFunctorSameType<int64_t, TEST_EXECSPACE>;
|
||||
constexpr uint64_t nw = 1000;
|
||||
|
||||
uint64_t nsum = (nw / 2) * (nw + 1);
|
||||
|
||||
int64_t result1 = 0;
|
||||
int64_t result2 = 0;
|
||||
int64_t result3 = 0;
|
||||
|
||||
Kokkos::parallel_reduce("int_combined_reduce",
|
||||
Kokkos::RangePolicy<TEST_EXECSPACE>(0, nw),
|
||||
functor_type(nw), result1, result2, result3);
|
||||
|
||||
ASSERT_EQ(nw, result1);
|
||||
ASSERT_EQ(nsum, result2);
|
||||
ASSERT_EQ(nsum, result3);
|
||||
}
|
||||
|
||||
TEST(TEST_CATEGORY, int_combined_reduce_mixed) {
|
||||
using functor_type = CombinedReduceFunctorSameType<int64_t, TEST_EXECSPACE>;
|
||||
|
||||
constexpr uint64_t nw = 1000;
|
||||
|
||||
uint64_t nsum = (nw / 2) * (nw + 1);
|
||||
|
||||
auto result1_v = Kokkos::View<int64_t, Kokkos::HostSpace>{"result1_v"};
|
||||
|
||||
int64_t result2 = 0;
|
||||
|
||||
auto result3_v = Kokkos::View<int64_t, Kokkos::HostSpace>{"result3_v"};
|
||||
|
||||
Kokkos::parallel_reduce("int_combined-reduce_mixed",
|
||||
Kokkos::RangePolicy<TEST_EXECSPACE>(0, nw),
|
||||
functor_type(nw), result1_v, result2,
|
||||
Kokkos::Sum<int64_t, Kokkos::HostSpace>{result3_v});
|
||||
|
||||
ASSERT_EQ(nw, result1_v());
|
||||
ASSERT_EQ(nsum, result2);
|
||||
ASSERT_EQ(nsum, result3_v());
|
||||
}
|
||||
} // namespace Test
|
||||
|
||||
Reference in New Issue
Block a user