Update Kokkos library in LAMMPS to v3.2

This commit is contained in:
Stan Moore
2020-08-25 20:21:48 -06:00
parent 450fd12d31
commit 4d90c2b74b
1410 changed files with 19364 additions and 71953 deletions

View File

@ -50,21 +50,22 @@
namespace Test {
template <typename DeviceType, typename Layout, int duplication,
int contribution, int op>
template <typename DeviceType, typename Layout, typename Duplication,
typename Contribution, typename Op, typename NumberType>
struct test_scatter_view_impl_cls;
template <typename DeviceType, typename Layout, int duplication,
int contribution>
struct test_scatter_view_impl_cls<DeviceType, Layout, duplication, contribution,
Kokkos::Experimental::ScatterSum> {
template <typename DeviceType, typename Layout, typename Duplication,
typename Contribution, typename NumberType>
struct test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
Kokkos::Experimental::ScatterSum,
NumberType> {
public:
typedef Kokkos::Experimental::ScatterView<double * [3], Layout, DeviceType,
Kokkos::Experimental::ScatterSum,
duplication, contribution>
scatter_view_type;
using scatter_view_type =
Kokkos::Experimental::ScatterView<NumberType * [12], Layout, DeviceType,
Kokkos::Experimental::ScatterSum,
Duplication, Contribution>;
typedef Kokkos::View<double * [3], Layout, DeviceType> orig_view_type;
using orig_view_type = Kokkos::View<NumberType * [12], Layout, DeviceType>;
scatter_view_type scatter_view;
int scatterSize;
@ -80,9 +81,18 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, duplication, contribution,
Kokkos::fence();
for (typename decltype(host_view)::size_type i = 0; i < host_view.extent(0);
++i) {
host_view(i, 0) = 0.0;
host_view(i, 1) = 0.0;
host_view(i, 2) = 0.0;
host_view(i, 0) = 0.0;
host_view(i, 1) = 0.0;
host_view(i, 2) = 0.0;
host_view(i, 3) = 0.0;
host_view(i, 4) = 0.0;
host_view(i, 5) = 0.0;
host_view(i, 6) = 0.0;
host_view(i, 7) = 0.0;
host_view(i, 8) = 0.0;
host_view(i, 9) = 0.0;
host_view(i, 10) = 0.0;
host_view(i, 11) = 0.0;
}
Kokkos::fence();
Kokkos::deep_copy(orig, host_view);
@ -102,9 +112,18 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, duplication, contribution,
scatter_view.template access<Kokkos::Experimental::ScatterAtomic>();
for (int j = 0; j < 10; ++j) {
auto k = (i + j) % scatterSize;
scatter_access(k, 0) += 4.2;
scatter_access_atomic(k, 1) += 2.0;
scatter_access(k, 2) += 1.0;
scatter_access(k, 0) += 4;
++scatter_access(k, 1);
--scatter_access(k, 2);
scatter_access(k, 3)++;
scatter_access(k, 4)--;
scatter_access(k, 5) -= 5;
scatter_access_atomic(k, 6) += 2;
scatter_access_atomic(k, 7)++;
scatter_access_atomic(k, 8)--;
--scatter_access_atomic(k, 9);
++scatter_access_atomic(k, 10);
scatter_access(k, 11) -= 3;
}
}
@ -114,27 +133,46 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, duplication, contribution,
Kokkos::fence();
for (typename decltype(host_view)::size_type i = 0; i < host_view.extent(0);
++i) {
auto val0 = host_view(i, 0);
auto val1 = host_view(i, 1);
auto val2 = host_view(i, 2);
EXPECT_TRUE(std::fabs((val0 - 84.0) / 84.0) < 1e-14);
EXPECT_TRUE(std::fabs((val1 - 40.0) / 40.0) < 1e-14);
EXPECT_TRUE(std::fabs((val2 - 20.0) / 20.0) < 1e-14);
auto val0 = host_view(i, 0);
auto val1 = host_view(i, 1);
auto val2 = host_view(i, 2);
auto val3 = host_view(i, 3);
auto val4 = host_view(i, 4);
auto val5 = host_view(i, 5);
auto val6 = host_view(i, 6);
auto val7 = host_view(i, 7);
auto val8 = host_view(i, 8);
auto val9 = host_view(i, 9);
auto val10 = host_view(i, 10);
auto val11 = host_view(i, 11);
EXPECT_NEAR(val0, NumberType(80), 1e-14);
EXPECT_NEAR(val1, NumberType(20), 1e-14);
EXPECT_NEAR(val2, NumberType(-20), 1e-14);
EXPECT_NEAR(val3, NumberType(20), 1e-14);
EXPECT_NEAR(val4, NumberType(-20), 1e-14);
EXPECT_NEAR(val5, NumberType(-100), 1e-14);
EXPECT_NEAR(val6, NumberType(40), 1e-14);
EXPECT_NEAR(val7, NumberType(20), 1e-14);
EXPECT_NEAR(val8, NumberType(-20), 1e-14);
EXPECT_NEAR(val9, NumberType(-20), 1e-14);
EXPECT_NEAR(val10, NumberType(20), 1e-14);
EXPECT_NEAR(val11, NumberType(-60), 1e-14);
}
}
};
template <typename DeviceType, typename Layout, int duplication,
int contribution>
struct test_scatter_view_impl_cls<DeviceType, Layout, duplication, contribution,
Kokkos::Experimental::ScatterProd> {
template <typename DeviceType, typename Layout, typename Duplication,
typename Contribution, typename NumberType>
struct test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
Kokkos::Experimental::ScatterProd,
NumberType> {
public:
typedef Kokkos::Experimental::ScatterView<double * [3], Layout, DeviceType,
Kokkos::Experimental::ScatterProd,
duplication, contribution>
scatter_view_type;
using scatter_view_type =
Kokkos::Experimental::ScatterView<NumberType * [3], Layout, DeviceType,
Kokkos::Experimental::ScatterProd,
Duplication, Contribution>;
typedef Kokkos::View<double * [3], Layout, DeviceType> orig_view_type;
using orig_view_type = Kokkos::View<NumberType * [3], Layout, DeviceType>;
scatter_view_type scatter_view;
int scatterSize;
@ -194,17 +232,18 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, duplication, contribution,
}
};
template <typename DeviceType, typename Layout, int duplication,
int contribution>
struct test_scatter_view_impl_cls<DeviceType, Layout, duplication, contribution,
Kokkos::Experimental::ScatterMin> {
template <typename DeviceType, typename Layout, typename Duplication,
typename Contribution, typename NumberType>
struct test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
Kokkos::Experimental::ScatterMin,
NumberType> {
public:
typedef Kokkos::Experimental::ScatterView<double * [3], Layout, DeviceType,
Kokkos::Experimental::ScatterMin,
duplication, contribution>
scatter_view_type;
using scatter_view_type =
Kokkos::Experimental::ScatterView<NumberType * [3], Layout, DeviceType,
Kokkos::Experimental::ScatterMin,
Duplication, Contribution>;
typedef Kokkos::View<double * [3], Layout, DeviceType> orig_view_type;
using orig_view_type = Kokkos::View<NumberType * [3], Layout, DeviceType>;
scatter_view_type scatter_view;
int scatterSize;
@ -242,9 +281,9 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, duplication, contribution,
scatter_view.template access<Kokkos::Experimental::ScatterAtomic>();
for (int j = 0; j < 4; ++j) {
auto k = (i + j) % scatterSize;
scatter_access(k, 0).update((double)(j + 1) * 4);
scatter_access_atomic(k, 1).update((double)(j + 1) * 2.0);
scatter_access(k, 2).update((double)(j + 1) * 1.0);
scatter_access(k, 0).update((NumberType)(j + 1) * 4);
scatter_access_atomic(k, 1).update((NumberType)(j + 1) * 2.0);
scatter_access(k, 2).update((NumberType)(j + 1) * 1.0);
}
}
@ -264,17 +303,18 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, duplication, contribution,
}
};
template <typename DeviceType, typename Layout, int duplication,
int contribution>
struct test_scatter_view_impl_cls<DeviceType, Layout, duplication, contribution,
Kokkos::Experimental::ScatterMax> {
template <typename DeviceType, typename Layout, typename Duplication,
typename Contribution, typename NumberType>
struct test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
Kokkos::Experimental::ScatterMax,
NumberType> {
public:
typedef Kokkos::Experimental::ScatterView<double * [3], Layout, DeviceType,
Kokkos::Experimental::ScatterMax,
duplication, contribution>
scatter_view_type;
using scatter_view_type =
Kokkos::Experimental::ScatterView<NumberType * [3], Layout, DeviceType,
Kokkos::Experimental::ScatterMax,
Duplication, Contribution>;
typedef Kokkos::View<double * [3], Layout, DeviceType> orig_view_type;
using orig_view_type = Kokkos::View<NumberType * [3], Layout, DeviceType>;
scatter_view_type scatter_view;
int scatterSize;
@ -311,9 +351,9 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, duplication, contribution,
scatter_view.template access<Kokkos::Experimental::ScatterAtomic>();
for (int j = 0; j < 4; ++j) {
auto k = (i + j) % scatterSize;
scatter_access(k, 0).update((double)(j + 1) * 4);
scatter_access_atomic(k, 1).update((double)(j + 1) * 2.0);
scatter_access(k, 2).update((double)(j + 1) * 1.0);
scatter_access(k, 0).update((NumberType)(j + 1) * 4);
scatter_access_atomic(k, 1).update((NumberType)(j + 1) * 2.0);
scatter_access(k, 2).update((NumberType)(j + 1) * 1.0);
}
}
@ -333,27 +373,126 @@ struct test_scatter_view_impl_cls<DeviceType, Layout, duplication, contribution,
}
};
template <typename DeviceType, typename Layout, int duplication,
int contribution, int op>
struct test_scatter_view_config {
template <typename DeviceType, typename Layout, typename Op,
typename NumberType>
struct test_default_scatter_view {
public:
typedef
typename test_scatter_view_impl_cls<DeviceType, Layout, duplication,
contribution, op>::scatter_view_type
scatter_view_def;
typedef typename test_scatter_view_impl_cls<DeviceType, Layout, duplication,
contribution, op>::orig_view_type
orig_view_def;
using default_duplication = Kokkos::Impl::Experimental::DefaultDuplication<
typename DeviceType::execution_space>;
using Duplication = typename default_duplication::type;
using Contribution = typename Kokkos::Impl::Experimental::DefaultContribution<
typename DeviceType::execution_space, Duplication>::type;
using scatter_view_def =
typename test_scatter_view_impl_cls<DeviceType, Layout, Duplication,
Contribution, Op,
NumberType>::scatter_view_type;
using orig_view_def =
typename test_scatter_view_impl_cls<DeviceType, Layout, Duplication,
Contribution, Op,
NumberType>::orig_view_type;
void run_test(int n) {
// Test creation via create_scatter_view overload 1
{
orig_view_def original_view("original_view", n);
scatter_view_def scatter_view =
Kokkos::Experimental::create_scatter_view(Op{}, original_view);
test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
Op, NumberType>
scatter_view_test_impl(scatter_view);
scatter_view_test_impl.initialize(original_view);
scatter_view_test_impl.run_parallel(n);
Kokkos::Experimental::contribute(original_view, scatter_view);
scatter_view.reset_except(original_view);
scatter_view_test_impl.run_parallel(n);
Kokkos::Experimental::contribute(original_view, scatter_view);
Kokkos::fence();
scatter_view_test_impl.validateResults(original_view);
{
scatter_view_def persistent_view("persistent", n);
auto result_view = persistent_view.subview();
contribute(result_view, persistent_view);
Kokkos::fence();
}
}
}
};
template <typename DeviceType, typename Layout, typename Duplication,
typename Contribution, typename Op, typename NumberType>
struct test_scatter_view_config {
public:
using scatter_view_def =
typename test_scatter_view_impl_cls<DeviceType, Layout, Duplication,
Contribution, Op,
NumberType>::scatter_view_type;
using orig_view_def =
typename test_scatter_view_impl_cls<DeviceType, Layout, Duplication,
Contribution, Op,
NumberType>::orig_view_type;
void run_test(int n) {
// test allocation
{
orig_view_def ov1("ov1", n);
scatter_view_def sv1;
ASSERT_FALSE(sv1.is_allocated());
sv1 = Kokkos::Experimental::create_scatter_view<Op, Duplication,
Contribution>(ov1);
scatter_view_def sv2(sv1);
scatter_view_def sv3("sv3", n);
ASSERT_TRUE(sv1.is_allocated());
ASSERT_TRUE(sv2.is_allocated());
ASSERT_TRUE(sv3.is_allocated());
}
// Test creation via create_scatter_view
{
orig_view_def original_view("original_view", n);
scatter_view_def scatter_view = Kokkos::Experimental::create_scatter_view<
op, duplication, contribution>(original_view);
Op, Duplication, Contribution>(original_view);
test_scatter_view_impl_cls<DeviceType, Layout, duplication, contribution,
op>
test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
Op, NumberType>
scatter_view_test_impl(scatter_view);
scatter_view_test_impl.initialize(original_view);
scatter_view_test_impl.run_parallel(n);
Kokkos::Experimental::contribute(original_view, scatter_view);
scatter_view.reset_except(original_view);
scatter_view_test_impl.run_parallel(n);
Kokkos::Experimental::contribute(original_view, scatter_view);
Kokkos::fence();
scatter_view_test_impl.validateResults(original_view);
{
scatter_view_def persistent_view("persistent", n);
auto result_view = persistent_view.subview();
contribute(result_view, persistent_view);
Kokkos::fence();
}
}
// Test creation via create_scatter_view overload 2
{
orig_view_def original_view("original_view", n);
scatter_view_def scatter_view = Kokkos::Experimental::create_scatter_view(
Op{}, Duplication{}, Contribution{}, original_view);
test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
Op, NumberType>
scatter_view_test_impl(scatter_view);
scatter_view_test_impl.initialize(original_view);
scatter_view_test_impl.run_parallel(n);
@ -380,8 +519,8 @@ struct test_scatter_view_config {
orig_view_def original_view("original_view", n);
scatter_view_def scatter_view(original_view);
test_scatter_view_impl_cls<DeviceType, Layout, duplication, contribution,
op>
test_scatter_view_impl_cls<DeviceType, Layout, Duplication, Contribution,
Op, NumberType>
scatter_view_test_impl(scatter_view);
scatter_view_test_impl.initialize(original_view);
scatter_view_test_impl.run_parallel(n);
@ -406,19 +545,19 @@ struct test_scatter_view_config {
}
};
template <typename DeviceType, int ScatterType>
template <typename DeviceType, typename ScatterType, typename NumberType>
struct TestDuplicatedScatterView {
TestDuplicatedScatterView(int n) {
// ScatterSum test
test_scatter_view_config<DeviceType, Kokkos::LayoutRight,
Kokkos::Experimental::ScatterDuplicated,
Kokkos::Experimental::ScatterNonAtomic,
ScatterType>
ScatterType, NumberType>
test_sv_right_config;
test_sv_right_config.run_test(n);
test_scatter_view_config<
DeviceType, Kokkos::LayoutLeft, Kokkos::Experimental::ScatterDuplicated,
Kokkos::Experimental::ScatterNonAtomic, ScatterType>
Kokkos::Experimental::ScatterNonAtomic, ScatterType, NumberType>
test_sv_left_config;
test_sv_left_config.run_test(n);
}
@ -427,18 +566,19 @@ struct TestDuplicatedScatterView {
#ifdef KOKKOS_ENABLE_CUDA
// disable duplicated instantiation with CUDA until
// UniqueToken can support it
template <int ScatterType>
struct TestDuplicatedScatterView<Kokkos::Cuda, ScatterType> {
template <typename ScatterType, typename NumberType>
struct TestDuplicatedScatterView<Kokkos::Cuda, ScatterType, NumberType> {
TestDuplicatedScatterView(int) {}
};
template <int ScatterType>
template <typename ScatterType, typename NumberType>
struct TestDuplicatedScatterView<
Kokkos::Device<Kokkos::Cuda, Kokkos::CudaSpace>, ScatterType> {
Kokkos::Device<Kokkos::Cuda, Kokkos::CudaSpace>, ScatterType, NumberType> {
TestDuplicatedScatterView(int) {}
};
template <int ScatterType>
template <typename ScatterType, typename NumberType>
struct TestDuplicatedScatterView<
Kokkos::Device<Kokkos::Cuda, Kokkos::CudaUVMSpace>, ScatterType> {
Kokkos::Device<Kokkos::Cuda, Kokkos::CudaUVMSpace>, ScatterType,
NumberType> {
TestDuplicatedScatterView(int) {}
};
#endif
@ -446,13 +586,14 @@ struct TestDuplicatedScatterView<
#ifdef KOKKOS_ENABLE_ROCM
// disable duplicated instantiation with ROCm until
// UniqueToken can support it
template <int ScatterType>
template <typename ScatterType>
struct TestDuplicatedScatterView<Kokkos::Experimental::ROCm, ScatterType> {
TestDuplicatedScatterView(int) {}
};
#endif
template <typename DeviceType, int ScatterType>
template <typename DeviceType, typename ScatterType,
typename NumberType = double>
void test_scatter_view(int n) {
using execution_space = typename DeviceType::execution_space;
@ -463,7 +604,7 @@ void test_scatter_view(int n) {
test_scatter_view_config<DeviceType, Kokkos::LayoutRight,
Kokkos::Experimental::ScatterNonDuplicated,
Kokkos::Experimental::ScatterNonAtomic,
ScatterType>
ScatterType, NumberType>
test_sv_config;
test_sv_config.run_test(n);
}
@ -472,30 +613,40 @@ void test_scatter_view(int n) {
#endif
test_scatter_view_config<DeviceType, Kokkos::LayoutRight,
Kokkos::Experimental::ScatterNonDuplicated,
Kokkos::Experimental::ScatterAtomic, ScatterType>
Kokkos::Experimental::ScatterAtomic, ScatterType,
NumberType>
test_sv_config;
test_sv_config.run_test(n);
#ifdef KOKKOS_ENABLE_SERIAL
}
#endif
// with hundreds of threads we were running out of memory.
// limit (n) so that duplication doesn't exceed 8GB
// limit (n) so that duplication doesn't exceed 4GB
constexpr std::size_t maximum_allowed_total_bytes =
8ull * 1024ull * 1024ull * 1024ull;
4ull * 1024ull * 1024ull * 1024ull;
std::size_t const maximum_allowed_copy_bytes =
maximum_allowed_total_bytes /
std::size_t(execution_space().concurrency());
constexpr std::size_t bytes_per_value = sizeof(double) * 3;
constexpr std::size_t bytes_per_value = sizeof(NumberType) * 12;
std::size_t const maximum_allowed_copy_values =
maximum_allowed_copy_bytes / bytes_per_value;
n = std::min(n, int(maximum_allowed_copy_values));
TestDuplicatedScatterView<DeviceType, ScatterType> duptest(n);
// if the default is duplicated, this needs to follow the limit
{
test_default_scatter_view<DeviceType, Kokkos::LayoutRight, ScatterType,
NumberType>
test_default_sv;
test_default_sv.run_test(n);
}
TestDuplicatedScatterView<DeviceType, ScatterType, NumberType> duptest(n);
}
// FIXME_HIP ScatterView requires UniqueToken
#ifndef KOKKOS_ENABLE_HIP
TEST(TEST_CATEGORY, scatterview) {
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterSum>(10);
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterSum, double>(
10);
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterSum,
unsigned int>(10);
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterProd>(10);
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterMin>(10);
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterMax>(10);
@ -512,7 +663,10 @@ TEST(TEST_CATEGORY, scatterview) {
#endif
#endif
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterSum>(big_n);
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterSum, double>(
big_n);
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterSum,
unsigned int>(big_n);
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterProd>(big_n);
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterMin>(big_n);
test_scatter_view<TEST_EXECSPACE, Kokkos::Experimental::ScatterMax>(big_n);
@ -522,7 +676,9 @@ TEST(TEST_CATEGORY, scatterview_devicetype) {
using device_type =
Kokkos::Device<TEST_EXECSPACE, typename TEST_EXECSPACE::memory_space>;
test_scatter_view<device_type, Kokkos::Experimental::ScatterSum>(10);
test_scatter_view<device_type, Kokkos::Experimental::ScatterSum, double>(10);
test_scatter_view<device_type, Kokkos::Experimental::ScatterSum,
unsigned int>(10);
test_scatter_view<device_type, Kokkos::Experimental::ScatterProd>(10);
test_scatter_view<device_type, Kokkos::Experimental::ScatterMin>(10);
test_scatter_view<device_type, Kokkos::Experimental::ScatterMax>(10);
@ -530,14 +686,19 @@ TEST(TEST_CATEGORY, scatterview_devicetype) {
#ifdef KOKKOS_ENABLE_CUDA
if (std::is_same<TEST_EXECSPACE, Kokkos::Cuda>::value) {
using cuda_device_type = Kokkos::Device<Kokkos::Cuda, Kokkos::CudaSpace>;
test_scatter_view<cuda_device_type, Kokkos::Experimental::ScatterSum>(10);
test_scatter_view<cuda_device_type, Kokkos::Experimental::ScatterSum,
double>(10);
test_scatter_view<cuda_device_type, Kokkos::Experimental::ScatterSum,
unsigned int>(10);
test_scatter_view<cuda_device_type, Kokkos::Experimental::ScatterProd>(10);
test_scatter_view<cuda_device_type, Kokkos::Experimental::ScatterMin>(10);
test_scatter_view<cuda_device_type, Kokkos::Experimental::ScatterMax>(10);
using cudauvm_device_type =
Kokkos::Device<Kokkos::Cuda, Kokkos::CudaUVMSpace>;
test_scatter_view<cudauvm_device_type, Kokkos::Experimental::ScatterSum>(
10);
test_scatter_view<cudauvm_device_type, Kokkos::Experimental::ScatterSum,
double>(10);
test_scatter_view<cudauvm_device_type, Kokkos::Experimental::ScatterSum,
unsigned int>(10);
test_scatter_view<cudauvm_device_type, Kokkos::Experimental::ScatterProd>(
10);
test_scatter_view<cudauvm_device_type, Kokkos::Experimental::ScatterMin>(
@ -547,7 +708,6 @@ TEST(TEST_CATEGORY, scatterview_devicetype) {
}
#endif
}
#endif
} // namespace Test