Skip to content

Commit

Permalink
Merge pull request #72 from cwpearson/fix/gtest-nvcc
Browse files Browse the repository at this point in the history
Bump gtest to May 28,2024. Move unit test lambdas out to helper functions
  • Loading branch information
cwpearson authored Jun 11, 2024
2 parents 05ea6d7 + 0e3a3c6 commit fc25da1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 33 deletions.
6 changes: 3 additions & 3 deletions unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ endif()

FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/530d5c8c84abd2a46f38583ee817743c9b3a42b4.zip # 12-18-2023
URL https://github.com/google/googletest/archive/a7f443b80b105f940225332ed3c31f2790092f47.zip # 05-28-2024
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# FetchContent_MakeAvailable(googletest)
# was making install install googletest as well
# FetchContent_MakeAvailable(googletest) was making install install googletest as well
# EXCLUDE_FROM_ALL here seems to be the magic
FetchContent_GetProperties(googletest)
if (NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
Expand Down
26 changes: 15 additions & 11 deletions unit_tests/test_allgather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "KokkosComm.hpp"

namespace {

template <typename T>
class Allgather : public testing::Test {
public:
Expand All @@ -27,17 +29,14 @@ class Allgather : public testing::Test {
using ScalarTypes = ::testing::Types<int, int64_t, float, double, Kokkos::complex<float>, Kokkos::complex<double>>;
TYPED_TEST_SUITE(Allgather, ScalarTypes);

TYPED_TEST(Allgather, 0D) {
using TestScalar = typename TestFixture::Scalar;

template <typename Scalar>
void test_allgather_0d() {
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);

const int nContrib = 10;

Kokkos::View<TestScalar> sv("sv");
Kokkos::View<TestScalar *> rv("rv", size);
Kokkos::View<Scalar> sv("sv");
Kokkos::View<Scalar *> rv("rv", size);

// fill send buffer
Kokkos::parallel_for(
Expand All @@ -51,17 +50,18 @@ TYPED_TEST(Allgather, 0D) {
EXPECT_EQ(errs, 0);
}

TYPED_TEST(Allgather, 1D_contig) {
using TestScalar = typename TestFixture::Scalar;
TYPED_TEST(Allgather, 0D) { test_allgather_0d<typename TestFixture::Scalar>(); }

template <typename Scalar>
void test_allgather_1d_contig() {
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);

const int nContrib = 10;

Kokkos::View<TestScalar *> sv("sv", nContrib);
Kokkos::View<TestScalar *> rv("rv", size * nContrib);
Kokkos::View<Scalar *> sv("sv", nContrib);
Kokkos::View<Scalar *> rv("rv", size * nContrib);

// fill send buffer
Kokkos::parallel_for(
Expand All @@ -80,3 +80,7 @@ TYPED_TEST(Allgather, 1D_contig) {
errs);
EXPECT_EQ(errs, 0);
}

TYPED_TEST(Allgather, 1D_contig) { test_allgather_1d_contig<typename TestFixture::Scalar>(); }

} // namespace
18 changes: 10 additions & 8 deletions unit_tests/test_alltoall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ class Alltoall : public testing::Test {
using ScalarTypes = ::testing::Types<int, int64_t, float, double, Kokkos::complex<float>, Kokkos::complex<double>>;
TYPED_TEST_SUITE(Alltoall, ScalarTypes);

TYPED_TEST(Alltoall, 1D_contig) {
using TestScalar = typename TestFixture::Scalar;

template <typename Scalar>
void test_alltoall_1d_contig() {
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);

const int nContrib = 10;

Kokkos::View<TestScalar *> sv("sv", size * nContrib);
Kokkos::View<TestScalar *> rv("rv", size * nContrib);
Kokkos::View<Scalar *> sv("sv", size * nContrib);
Kokkos::View<Scalar *> rv("rv", size * nContrib);

// fill send buffer
Kokkos::parallel_for(
Expand All @@ -59,16 +58,17 @@ TYPED_TEST(Alltoall, 1D_contig) {
EXPECT_EQ(errs, 0);
}

TYPED_TEST(Alltoall, 1D_inplace_contig) {
using TestScalar = typename TestFixture::Scalar;
TYPED_TEST(Alltoall, 1D_contig) { test_alltoall_1d_contig<typename TestFixture::Scalar>(); }

template <typename Scalar>
void test_alltoall_1d_inplace_contig() {
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);

const int nContrib = 10;

Kokkos::View<TestScalar *> rv("rv", size * nContrib);
Kokkos::View<Scalar *> rv("rv", size * nContrib);

// fill send buffer
Kokkos::parallel_for(
Expand All @@ -88,4 +88,6 @@ TYPED_TEST(Alltoall, 1D_inplace_contig) {
EXPECT_EQ(errs, 0);
}

TYPED_TEST(Alltoall, 1D_inplace_contig) { test_alltoall_1d_inplace_contig<typename TestFixture::Scalar>(); }

} // namespace
22 changes: 11 additions & 11 deletions unit_tests/test_reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "KokkosComm.hpp"

namespace {

template <typename T>
class Reduce : public testing::Test {
public:
Expand All @@ -31,17 +33,15 @@ TYPED_TEST_SUITE(Reduce, ScalarTypes);
Each rank fills its sendbuf[i] with `rank + i`
operation is sum, so recvbuf[i] should be sum(0..size) + i * size
*/
TYPED_TEST(Reduce, 1D_contig) {
using TestScalar = typename TestFixture::Scalar;

template <typename Scalar>
void test_reduce_1d_contig() {
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);

Kokkos::View<TestScalar *> sendv("sendv", 10);
Kokkos::View<TestScalar *> recvv;
Kokkos::View<Scalar *> sendv("sendv", 10);
Kokkos::View<Scalar *> recvv;
if (0 == rank) {
Kokkos::resize(recvv, sendv.extent(0));
}
Expand All @@ -57,17 +57,17 @@ TYPED_TEST(Reduce, 1D_contig) {
Kokkos::parallel_reduce(
recvv.extent(0),
KOKKOS_LAMBDA(const int &i, int &lsum) {
TestScalar acc = 0;
Scalar acc = 0;
for (int r = 0; r < size; ++r) {
acc += r + i;
}
lsum += recvv(i) != acc;
// if (recvv(i) != acc) {
// Kokkos::printf("%f != %f @ %lu\n", double(Kokkos::abs(recvv(i))),
// double(Kokkos::abs(acc)), size_t(i));
// }
},
errs);
ASSERT_EQ(errs, 0);
}
}

TYPED_TEST(Reduce, 1D_contig) { test_reduce_1d_contig<typename TestFixture::Scalar>(); }

} // namespace

0 comments on commit fc25da1

Please sign in to comment.