Update Kokkos library in LAMMPS to v3.1
This commit is contained in:
@ -67,11 +67,17 @@ struct test_dualview_combinations {
|
||||
Scalar result;
|
||||
|
||||
template <typename ViewType>
|
||||
Scalar run_me(unsigned int n, unsigned int m) {
|
||||
Scalar run_me(unsigned int n, unsigned int m, bool with_init) {
|
||||
if (n < 10) n = 10;
|
||||
if (m < 3) m = 3;
|
||||
ViewType a("A", n, m);
|
||||
|
||||
ViewType a;
|
||||
|
||||
if (with_init) {
|
||||
a = ViewType("A", n, m);
|
||||
} else {
|
||||
a = ViewType(Kokkos::ViewAllocateWithoutInitializing("A"), n, m);
|
||||
}
|
||||
Kokkos::deep_copy(a.d_view, 1);
|
||||
|
||||
a.template modify<typename ViewType::execution_space>();
|
||||
@ -96,9 +102,9 @@ struct test_dualview_combinations {
|
||||
return count - a.d_view.extent(0) * a.d_view.extent(1) - 2 - 4 - 3 * 2;
|
||||
}
|
||||
|
||||
test_dualview_combinations(unsigned int size) {
|
||||
test_dualview_combinations(unsigned int size, bool with_init) {
|
||||
result = run_me<Kokkos::DualView<Scalar**, Kokkos::LayoutLeft, Device> >(
|
||||
size, 3);
|
||||
size, 3, with_init);
|
||||
}
|
||||
};
|
||||
|
||||
@ -124,18 +130,25 @@ struct test_dual_view_deep_copy {
|
||||
typedef Device execution_space;
|
||||
|
||||
template <typename ViewType>
|
||||
void run_me() {
|
||||
const unsigned int n = 10;
|
||||
const unsigned int m = 5;
|
||||
const unsigned int sum_total = n * m;
|
||||
|
||||
ViewType a("A", n, m);
|
||||
ViewType b("B", n, m);
|
||||
void run_me(int n, const int m, const bool use_templ_sync) {
|
||||
ViewType a, b;
|
||||
if (n >= 0) {
|
||||
a = ViewType("A", n, m);
|
||||
b = ViewType("B", n, m);
|
||||
} else {
|
||||
n = 0;
|
||||
}
|
||||
const scalar_type sum_total = scalar_type(n * m);
|
||||
|
||||
Kokkos::deep_copy(a.d_view, 1);
|
||||
|
||||
a.template modify<typename ViewType::execution_space>();
|
||||
a.template sync<typename ViewType::host_mirror_space>();
|
||||
if (use_templ_sync) {
|
||||
a.template modify<typename ViewType::execution_space>();
|
||||
a.template sync<typename ViewType::host_mirror_space>();
|
||||
} else {
|
||||
a.modify_device();
|
||||
a.sync_host();
|
||||
}
|
||||
|
||||
// Check device view is initialized as expected
|
||||
scalar_type a_d_sum = 0;
|
||||
@ -159,7 +172,11 @@ struct test_dual_view_deep_copy {
|
||||
|
||||
// Test deep_copy
|
||||
Kokkos::deep_copy(b, a);
|
||||
b.template sync<typename ViewType::host_mirror_space>();
|
||||
if (use_templ_sync) {
|
||||
b.template sync<typename ViewType::host_mirror_space>();
|
||||
} else {
|
||||
b.sync_host();
|
||||
}
|
||||
|
||||
// Perform same checks on b as done on a
|
||||
// Check device view is initialized as expected
|
||||
@ -183,6 +200,145 @@ struct test_dual_view_deep_copy {
|
||||
} // end run_me
|
||||
|
||||
test_dual_view_deep_copy() {
|
||||
run_me<Kokkos::DualView<Scalar**, Kokkos::LayoutLeft, Device> >(10, 5,
|
||||
true);
|
||||
run_me<Kokkos::DualView<Scalar**, Kokkos::LayoutLeft, Device> >(10, 5,
|
||||
false);
|
||||
// Test zero length but allocated (a.d_view.data!=nullptr but
|
||||
// a.d_view.span()==0)
|
||||
run_me<Kokkos::DualView<Scalar**, Kokkos::LayoutLeft, Device> >(0, 5, true);
|
||||
run_me<Kokkos::DualView<Scalar**, Kokkos::LayoutLeft, Device> >(0, 5,
|
||||
false);
|
||||
|
||||
// Test default constructed view
|
||||
run_me<Kokkos::DualView<Scalar**, Kokkos::LayoutLeft, Device> >(-1, 5,
|
||||
true);
|
||||
run_me<Kokkos::DualView<Scalar**, Kokkos::LayoutLeft, Device> >(-1, 5,
|
||||
false);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Scalar, class Device>
|
||||
struct test_dualview_resize {
|
||||
typedef Scalar scalar_type;
|
||||
typedef Device execution_space;
|
||||
|
||||
template <typename ViewType>
|
||||
void run_me() {
|
||||
const unsigned int n = 10;
|
||||
const unsigned int m = 5;
|
||||
const unsigned int factor = 2;
|
||||
|
||||
ViewType a("A", n, m);
|
||||
Kokkos::deep_copy(a.d_view, 1);
|
||||
|
||||
/* Covers case "Resize on Device" */
|
||||
a.modify_device();
|
||||
Kokkos::resize(a, factor * n, factor * m);
|
||||
ASSERT_EQ(a.extent(0), n * factor);
|
||||
ASSERT_EQ(a.extent(1), m * factor);
|
||||
|
||||
Kokkos::deep_copy(a.d_view, 1);
|
||||
a.sync_host();
|
||||
|
||||
// Check device view is initialized as expected
|
||||
scalar_type a_d_sum = 0;
|
||||
// Execute on the execution_space associated with t_dev's memory space
|
||||
typedef typename ViewType::t_dev::memory_space::execution_space
|
||||
t_dev_exec_space;
|
||||
Kokkos::parallel_reduce(
|
||||
Kokkos::RangePolicy<t_dev_exec_space>(0, a.d_view.extent(0)),
|
||||
SumViewEntriesFunctor<scalar_type, typename ViewType::t_dev>(a.d_view),
|
||||
a_d_sum);
|
||||
|
||||
// Check host view is synced as expected
|
||||
scalar_type a_h_sum = 0;
|
||||
for (size_t i = 0; i < a.h_view.extent(0); ++i)
|
||||
for (size_t j = 0; j < a.h_view.extent(1); ++j) {
|
||||
a_h_sum += a.h_view(i, j);
|
||||
}
|
||||
|
||||
// Check
|
||||
ASSERT_EQ(a_h_sum, a_d_sum);
|
||||
ASSERT_EQ(a_h_sum, a.extent(0) * a.extent(1));
|
||||
|
||||
/* Covers case "Resize on Host" */
|
||||
a.modify_host();
|
||||
|
||||
Kokkos::resize(a, n / factor, m / factor);
|
||||
ASSERT_EQ(a.extent(0), n / factor);
|
||||
ASSERT_EQ(a.extent(1), m / factor);
|
||||
|
||||
a.sync_device();
|
||||
|
||||
// Check device view is initialized as expected
|
||||
a_d_sum = 0;
|
||||
// Execute on the execution_space associated with t_dev's memory space
|
||||
typedef typename ViewType::t_dev::memory_space::execution_space
|
||||
t_dev_exec_space;
|
||||
Kokkos::parallel_reduce(
|
||||
Kokkos::RangePolicy<t_dev_exec_space>(0, a.d_view.extent(0)),
|
||||
SumViewEntriesFunctor<scalar_type, typename ViewType::t_dev>(a.d_view),
|
||||
a_d_sum);
|
||||
|
||||
// Check host view is synced as expected
|
||||
a_h_sum = 0;
|
||||
for (size_t i = 0; i < a.h_view.extent(0); ++i)
|
||||
for (size_t j = 0; j < a.h_view.extent(1); ++j) {
|
||||
a_h_sum += a.h_view(i, j);
|
||||
}
|
||||
|
||||
// Check
|
||||
ASSERT_EQ(a_h_sum, a.extent(0) * a.extent(1));
|
||||
ASSERT_EQ(a_h_sum, a_d_sum);
|
||||
|
||||
} // end run_me
|
||||
|
||||
test_dualview_resize() {
|
||||
run_me<Kokkos::DualView<Scalar**, Kokkos::LayoutLeft, Device> >();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Scalar, class Device>
|
||||
struct test_dualview_realloc {
|
||||
typedef Scalar scalar_type;
|
||||
typedef Device execution_space;
|
||||
|
||||
template <typename ViewType>
|
||||
void run_me() {
|
||||
const unsigned int n = 10;
|
||||
const unsigned int m = 5;
|
||||
|
||||
ViewType a("A", n, m);
|
||||
Kokkos::realloc(a, n, m);
|
||||
|
||||
Kokkos::deep_copy(a.d_view, 1);
|
||||
a.modify_device();
|
||||
a.sync_host();
|
||||
|
||||
// Check device view is initialized as expected
|
||||
scalar_type a_d_sum = 0;
|
||||
// Execute on the execution_space associated with t_dev's memory space
|
||||
typedef typename ViewType::t_dev::memory_space::execution_space
|
||||
t_dev_exec_space;
|
||||
Kokkos::parallel_reduce(
|
||||
Kokkos::RangePolicy<t_dev_exec_space>(0, a.d_view.extent(0)),
|
||||
SumViewEntriesFunctor<scalar_type, typename ViewType::t_dev>(a.d_view),
|
||||
a_d_sum);
|
||||
|
||||
// Check host view is synced as expected
|
||||
scalar_type a_h_sum = 0;
|
||||
for (size_t i = 0; i < a.h_view.extent(0); ++i)
|
||||
for (size_t j = 0; j < a.h_view.extent(1); ++j) {
|
||||
a_h_sum += a.h_view(i, j);
|
||||
}
|
||||
|
||||
// Check
|
||||
ASSERT_EQ(a_h_sum, a.extent(0) * a.extent(1));
|
||||
ASSERT_EQ(a_h_sum, a_d_sum);
|
||||
} // end run_me
|
||||
|
||||
test_dualview_realloc() {
|
||||
run_me<Kokkos::DualView<Scalar**, Kokkos::LayoutLeft, Device> >();
|
||||
}
|
||||
};
|
||||
@ -190,8 +346,8 @@ struct test_dual_view_deep_copy {
|
||||
} // namespace Impl
|
||||
|
||||
template <typename Scalar, typename Device>
|
||||
void test_dualview_combinations(unsigned int size) {
|
||||
Impl::test_dualview_combinations<Scalar, Device> test(size);
|
||||
void test_dualview_combinations(unsigned int size, bool with_init) {
|
||||
Impl::test_dualview_combinations<Scalar, Device> test(size, with_init);
|
||||
ASSERT_EQ(test.result, 0);
|
||||
}
|
||||
|
||||
@ -200,8 +356,22 @@ void test_dualview_deep_copy() {
|
||||
Impl::test_dual_view_deep_copy<Scalar, Device>();
|
||||
}
|
||||
|
||||
template <typename Scalar, typename Device>
|
||||
void test_dualview_realloc() {
|
||||
Impl::test_dualview_realloc<Scalar, Device>();
|
||||
}
|
||||
|
||||
template <typename Scalar, typename Device>
|
||||
void test_dualview_resize() {
|
||||
Impl::test_dualview_resize<Scalar, Device>();
|
||||
}
|
||||
|
||||
TEST(TEST_CATEGORY, dualview_combination) {
|
||||
test_dualview_combinations<int, TEST_EXECSPACE>(10);
|
||||
test_dualview_combinations<int, TEST_EXECSPACE>(10, true);
|
||||
}
|
||||
|
||||
TEST(TEST_CATEGORY, dualview_combinations_without_init) {
|
||||
test_dualview_combinations<int, TEST_EXECSPACE>(10, false);
|
||||
}
|
||||
|
||||
TEST(TEST_CATEGORY, dualview_deep_copy) {
|
||||
@ -209,6 +379,14 @@ TEST(TEST_CATEGORY, dualview_deep_copy) {
|
||||
test_dualview_deep_copy<double, TEST_EXECSPACE>();
|
||||
}
|
||||
|
||||
TEST(TEST_CATEGORY, dualview_realloc) {
|
||||
test_dualview_realloc<int, TEST_EXECSPACE>();
|
||||
}
|
||||
|
||||
TEST(TEST_CATEGORY, dualview_resize) {
|
||||
test_dualview_resize<int, TEST_EXECSPACE>();
|
||||
}
|
||||
|
||||
} // namespace Test
|
||||
|
||||
#endif // KOKKOS_TEST_UNORDERED_MAP_HPP
|
||||
#endif // KOKKOS_TEST_DUALVIEW_HPP
|
||||
|
||||
Reference in New Issue
Block a user