Skip to content

Commit fc25da1

Browse files
authored
Merge pull request #72 from cwpearson/fix/gtest-nvcc
Bump gtest to May 28,2024. Move unit test lambdas out to helper functions
2 parents 05ea6d7 + 0e3a3c6 commit fc25da1

File tree

4 files changed

+39
-33
lines changed

4 files changed

+39
-33
lines changed

unit_tests/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ endif()
1818

1919
FetchContent_Declare(
2020
googletest
21-
URL https://github.com/google/googletest/archive/530d5c8c84abd2a46f38583ee817743c9b3a42b4.zip # 12-18-2023
21+
URL https://github.com/google/googletest/archive/a7f443b80b105f940225332ed3c31f2790092f47.zip # 05-28-2024
2222
)
2323
# For Windows: Prevent overriding the parent project's compiler/linker settings
2424
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
25-
# FetchContent_MakeAvailable(googletest)
26-
# was making install install googletest as well
25+
# FetchContent_MakeAvailable(googletest) was making install install googletest as well
2726
# EXCLUDE_FROM_ALL here seems to be the magic
27+
FetchContent_GetProperties(googletest)
2828
if (NOT googletest_POPULATED)
2929
FetchContent_Populate(googletest)
3030
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)

unit_tests/test_allgather.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include "KokkosComm.hpp"
2020

21+
namespace {
22+
2123
template <typename T>
2224
class Allgather : public testing::Test {
2325
public:
@@ -27,17 +29,14 @@ class Allgather : public testing::Test {
2729
using ScalarTypes = ::testing::Types<int, int64_t, float, double, Kokkos::complex<float>, Kokkos::complex<double>>;
2830
TYPED_TEST_SUITE(Allgather, ScalarTypes);
2931

30-
TYPED_TEST(Allgather, 0D) {
31-
using TestScalar = typename TestFixture::Scalar;
32-
32+
template <typename Scalar>
33+
void test_allgather_0d() {
3334
int rank, size;
3435
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
3536
MPI_Comm_size(MPI_COMM_WORLD, &size);
3637

37-
const int nContrib = 10;
38-
39-
Kokkos::View<TestScalar> sv("sv");
40-
Kokkos::View<TestScalar *> rv("rv", size);
38+
Kokkos::View<Scalar> sv("sv");
39+
Kokkos::View<Scalar *> rv("rv", size);
4140

4241
// fill send buffer
4342
Kokkos::parallel_for(
@@ -51,17 +50,18 @@ TYPED_TEST(Allgather, 0D) {
5150
EXPECT_EQ(errs, 0);
5251
}
5352

54-
TYPED_TEST(Allgather, 1D_contig) {
55-
using TestScalar = typename TestFixture::Scalar;
53+
TYPED_TEST(Allgather, 0D) { test_allgather_0d<typename TestFixture::Scalar>(); }
5654

55+
template <typename Scalar>
56+
void test_allgather_1d_contig() {
5757
int rank, size;
5858
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
5959
MPI_Comm_size(MPI_COMM_WORLD, &size);
6060

6161
const int nContrib = 10;
6262

63-
Kokkos::View<TestScalar *> sv("sv", nContrib);
64-
Kokkos::View<TestScalar *> rv("rv", size * nContrib);
63+
Kokkos::View<Scalar *> sv("sv", nContrib);
64+
Kokkos::View<Scalar *> rv("rv", size * nContrib);
6565

6666
// fill send buffer
6767
Kokkos::parallel_for(
@@ -80,3 +80,7 @@ TYPED_TEST(Allgather, 1D_contig) {
8080
errs);
8181
EXPECT_EQ(errs, 0);
8282
}
83+
84+
TYPED_TEST(Allgather, 1D_contig) { test_allgather_1d_contig<typename TestFixture::Scalar>(); }
85+
86+
} // namespace

unit_tests/test_alltoall.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,16 @@ class Alltoall : public testing::Test {
2929
using ScalarTypes = ::testing::Types<int, int64_t, float, double, Kokkos::complex<float>, Kokkos::complex<double>>;
3030
TYPED_TEST_SUITE(Alltoall, ScalarTypes);
3131

32-
TYPED_TEST(Alltoall, 1D_contig) {
33-
using TestScalar = typename TestFixture::Scalar;
34-
32+
template <typename Scalar>
33+
void test_alltoall_1d_contig() {
3534
int rank, size;
3635
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
3736
MPI_Comm_size(MPI_COMM_WORLD, &size);
3837

3938
const int nContrib = 10;
4039

41-
Kokkos::View<TestScalar *> sv("sv", size * nContrib);
42-
Kokkos::View<TestScalar *> rv("rv", size * nContrib);
40+
Kokkos::View<Scalar *> sv("sv", size * nContrib);
41+
Kokkos::View<Scalar *> rv("rv", size * nContrib);
4342

4443
// fill send buffer
4544
Kokkos::parallel_for(
@@ -59,16 +58,17 @@ TYPED_TEST(Alltoall, 1D_contig) {
5958
EXPECT_EQ(errs, 0);
6059
}
6160

62-
TYPED_TEST(Alltoall, 1D_inplace_contig) {
63-
using TestScalar = typename TestFixture::Scalar;
61+
TYPED_TEST(Alltoall, 1D_contig) { test_alltoall_1d_contig<typename TestFixture::Scalar>(); }
6462

63+
template <typename Scalar>
64+
void test_alltoall_1d_inplace_contig() {
6565
int rank, size;
6666
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
6767
MPI_Comm_size(MPI_COMM_WORLD, &size);
6868

6969
const int nContrib = 10;
7070

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

7373
// fill send buffer
7474
Kokkos::parallel_for(
@@ -88,4 +88,6 @@ TYPED_TEST(Alltoall, 1D_inplace_contig) {
8888
EXPECT_EQ(errs, 0);
8989
}
9090

91+
TYPED_TEST(Alltoall, 1D_inplace_contig) { test_alltoall_1d_inplace_contig<typename TestFixture::Scalar>(); }
92+
9193
} // namespace

unit_tests/test_reduce.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include "KokkosComm.hpp"
2020

21+
namespace {
22+
2123
template <typename T>
2224
class Reduce : public testing::Test {
2325
public:
@@ -31,17 +33,15 @@ TYPED_TEST_SUITE(Reduce, ScalarTypes);
3133
Each rank fills its sendbuf[i] with `rank + i`
3234
3335
operation is sum, so recvbuf[i] should be sum(0..size) + i * size
34-
3536
*/
36-
TYPED_TEST(Reduce, 1D_contig) {
37-
using TestScalar = typename TestFixture::Scalar;
38-
37+
template <typename Scalar>
38+
void test_reduce_1d_contig() {
3939
int rank, size;
4040
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
4141
MPI_Comm_size(MPI_COMM_WORLD, &size);
4242

43-
Kokkos::View<TestScalar *> sendv("sendv", 10);
44-
Kokkos::View<TestScalar *> recvv;
43+
Kokkos::View<Scalar *> sendv("sendv", 10);
44+
Kokkos::View<Scalar *> recvv;
4545
if (0 == rank) {
4646
Kokkos::resize(recvv, sendv.extent(0));
4747
}
@@ -57,17 +57,17 @@ TYPED_TEST(Reduce, 1D_contig) {
5757
Kokkos::parallel_reduce(
5858
recvv.extent(0),
5959
KOKKOS_LAMBDA(const int &i, int &lsum) {
60-
TestScalar acc = 0;
60+
Scalar acc = 0;
6161
for (int r = 0; r < size; ++r) {
6262
acc += r + i;
6363
}
6464
lsum += recvv(i) != acc;
65-
// if (recvv(i) != acc) {
66-
// Kokkos::printf("%f != %f @ %lu\n", double(Kokkos::abs(recvv(i))),
67-
// double(Kokkos::abs(acc)), size_t(i));
68-
// }
6965
},
7066
errs);
7167
ASSERT_EQ(errs, 0);
7268
}
7369
}
70+
71+
TYPED_TEST(Reduce, 1D_contig) { test_reduce_1d_contig<typename TestFixture::Scalar>(); }
72+
73+
} // namespace

0 commit comments

Comments
 (0)