Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
Simplify the test verification of Views in TestMath
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala committed Sep 5, 2021
1 parent 28686fb commit 8f17c6f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 52 deletions.
73 changes: 23 additions & 50 deletions test/TestMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,102 +93,75 @@ void test_min(Kokkos::View<simd_t *> data, simd_t val) {
KOKKOS_LAMBDA(const int i) { data(i) = simd::min(data(i), val); });
}

void test_view_result(const std::string &test_name, Kokkos::View<simd_t *> data,
double expected) {
auto data_h = Kokkos::create_mirror_view(data);
Kokkos::deep_copy(data_h, data);

Kokkos::View<double *, Kokkos::HostSpace> scalar_view(
reinterpret_cast<double *>(data_h.data()),
data_h.extent(0) * simd_t::size());

for (int i = 0; i < scalar_view.extent(0); ++i) {
EXPECT_EQ(scalar_view(i), expected)
<< "Failure during " + test_name + " with i = " + std::to_string(i);
}
}

TEST(simd_math, test_abs) {
Kokkos::View<simd_t *> data("Test View", 8);
Kokkos::deep_copy(data, simd_t(-4.0));

test_abs(data);

auto data_h = Kokkos::create_mirror_view(data);
Kokkos::deep_copy(data_h, data);

for (int i = 0; i < data.extent(0); ++i) {
EXPECT_EQ(data_h(i).get(), 4.0);
}
test_view_result("test_abs", data, 1.0);
}

TEST(simd_math, test_sqrt) {
Kokkos::View<simd_t *> data("Test View", 8);
Kokkos::deep_copy(data, simd_t(16.0));

test_sqrt(data);

auto data_h = Kokkos::create_mirror_view(data);
Kokkos::deep_copy(data_h, data);

for (int i = 0; i < data.extent(0); ++i) {
EXPECT_EQ(data_h(i).get(), 4.0);
}
test_view_result("test_sqrt", data, 4.0);
}

TEST(simd_math, test_cbrt) {
Kokkos::View<simd_t *> data("Test View", 8);
Kokkos::deep_copy(data, simd_t(27.0));

test_cbrt(data);

auto data_h = Kokkos::create_mirror_view(data);
Kokkos::deep_copy(data_h, data);

for (int i = 0; i < data.extent(0); ++i) {
EXPECT_EQ(data_h(i).get(), 3.0);
}
test_view_result("test_cbrt", data, 3.0);
}

TEST(simd_math, test_exp) {
Kokkos::View<simd_t *> data("Test View", 8);
Kokkos::deep_copy(data, simd_t(-4.0));
Kokkos::deep_copy(data, simd_t(1.0));

test_exp(data);

auto data_h = Kokkos::create_mirror_view(data);
Kokkos::deep_copy(data_h, data);

for (int i = 0; i < data.extent(0); ++i) {
EXPECT_EQ(data_h(i).get(), 4.0);
}
test_view_result("test_exp", data, std::exp(1.0));
}

TEST(simd_math, test_fma) {
Kokkos::View<simd_t *> data("Test View", 8);
Kokkos::deep_copy(data, simd_t(-4.0));

test_fma(data, simd_t{2.0}, simd_t{5.0});

auto data_h = Kokkos::create_mirror_view(data);
Kokkos::deep_copy(data_h, data);

for (int i = 0; i < data.extent(0); ++i) {
EXPECT_EQ(data_h(i).get(), -3.0);
}
test_view_result("test_fma", data, -3.0);
}

TEST(simd_math, test_max) {
Kokkos::View<simd_t *> data("Test View", 8);
Kokkos::deep_copy(data, simd_t(-4.0));

test_max(data, simd_t{10.0});

auto data_h = Kokkos::create_mirror_view(data);
Kokkos::deep_copy(data_h, data);

for (int i = 0; i < data.extent(0); ++i) {
EXPECT_EQ(data_h(i).get(), 10.0);
}
test_view_result("test_max", data, 10.0);
}

TEST(simd_math, test_min) {
Kokkos::View<simd_t *> data("Test View", 8);
Kokkos::deep_copy(data, simd_t(4.0));

test_min(data, simd_t{1.0});

auto data_h = Kokkos::create_mirror_view(data);
Kokkos::deep_copy(data_h, data);

for (int i = 0; i < data.extent(0); ++i) {
EXPECT_EQ(data_h(i).get(), 1.0);
}
test_view_result("test_min", data, 1.0);
}

} // namespace Test
4 changes: 2 additions & 2 deletions test/TestSimdMask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ bool test_is_smaller(Kokkos::View<simd_t *> data) {
});

Kokkos::View<bool *> results_scalar((bool *)(results.data()),
results.extent(0) / simd_bool::size());
results.extent(0) * simd_bool::size());

int result = 0;
Kokkos::parallel_reduce(
Expand All @@ -99,7 +99,7 @@ bool test_is_smaller(Kokkos::View<simd_t *> data) {
return result == results_scalar.extent(0);
}

TEST(simd_math, simd_mask_less) {
TEST(simd_mask, simd_mask_less) {
constexpr int data_size = 10 * simd_t::size();
constexpr int simd_data_size = data_size / simd_t::size();

Expand Down

0 comments on commit 8f17c6f

Please sign in to comment.